@bytexbyte/nxtlinq-ai-agent-sdk 1.2.9 → 1.3.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/api/nxtlinq-api.d.ts.map +1 -1
- package/dist/api/nxtlinq-api.js +27 -1
- package/dist/components/context/ChatBotContext.d.ts.map +1 -1
- package/dist/components/context/ChatBotContext.js +53 -20
- package/dist/components/types/ChatBotTypes.d.ts +6 -1
- package/dist/components/types/ChatBotTypes.d.ts.map +1 -1
- package/dist/components/ui/MessageInput.d.ts.map +1 -1
- package/dist/components/ui/MessageInput.js +7 -2
- package/dist/core/lib/useSpeechToTextFromMic/helper.d.ts +23 -0
- package/dist/core/lib/useSpeechToTextFromMic/helper.d.ts.map +1 -0
- package/dist/core/lib/useSpeechToTextFromMic/helper.js +77 -0
- package/dist/core/lib/useSpeechToTextFromMic/index.d.ts +13 -0
- package/dist/core/lib/useSpeechToTextFromMic/index.d.ts.map +1 -0
- package/dist/core/lib/useSpeechToTextFromMic/index.js +41 -0
- package/dist/core/utils/aitUtils.d.ts +5 -1
- package/dist/core/utils/aitUtils.d.ts.map +1 -1
- package/dist/core/utils/aitUtils.js +4 -2
- package/dist/core/utils/index.d.ts +2 -0
- package/dist/core/utils/index.d.ts.map +1 -0
- package/dist/core/utils/index.js +3 -0
- package/dist/types/ait-api.d.ts +10 -0
- package/dist/types/ait-api.d.ts.map +1 -1
- package/package.json +9 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"nxtlinq-api.d.ts","sourceRoot":"","sources":["../../src/api/nxtlinq-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;
|
|
1
|
+
{"version":3,"file":"nxtlinq-api.d.ts","sourceRoot":"","sources":["../../src/api/nxtlinq-api.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAC;AAyN1C,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,EAAE,WAAW,MAAM,KAAG,MAUpE,CAAC"}
|
package/dist/api/nxtlinq-api.js
CHANGED
|
@@ -123,6 +123,31 @@ const createPermissionsApi = (apiKey, apiSecret) => ({
|
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
125
|
});
|
|
126
|
+
// Cognitive API Module
|
|
127
|
+
const createCognitiveApi = (apiKey, apiSecret) => ({
|
|
128
|
+
getCognitiveToken: async () => {
|
|
129
|
+
try {
|
|
130
|
+
const url = new URL(`${AI_AGENT_API_HOST}/api/cognitive/token`);
|
|
131
|
+
const response = await fetch(url.toString(), {
|
|
132
|
+
method: 'GET',
|
|
133
|
+
headers: {
|
|
134
|
+
'X-API-Key': apiKey,
|
|
135
|
+
'X-API-Secret': apiSecret,
|
|
136
|
+
'Content-Type': 'application/json',
|
|
137
|
+
...getAuthHeader()
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
if (!response.ok) {
|
|
141
|
+
throw new Error('Failed to fetch permissions');
|
|
142
|
+
}
|
|
143
|
+
return await response.json();
|
|
144
|
+
}
|
|
145
|
+
catch (error) {
|
|
146
|
+
console.error('Failed to fetch cognitive token:', error);
|
|
147
|
+
return { error: error instanceof Error ? error.message : 'Failed to fetch cognitive token' };
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
});
|
|
126
151
|
// Main API factory
|
|
127
152
|
export const createNxtlinqApi = (apiKey, apiSecret) => {
|
|
128
153
|
return {
|
|
@@ -131,6 +156,7 @@ export const createNxtlinqApi = (apiKey, apiSecret) => {
|
|
|
131
156
|
metadata: createMetadataApi(apiKey, apiSecret),
|
|
132
157
|
auth: createAuthApi(apiKey, apiSecret),
|
|
133
158
|
agent: createAgentApi(),
|
|
134
|
-
permissions: createPermissionsApi(apiKey, apiSecret)
|
|
159
|
+
permissions: createPermissionsApi(apiKey, apiSecret),
|
|
160
|
+
cognitive: createCognitiveApi(apiKey, apiSecret)
|
|
135
161
|
};
|
|
136
162
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatBotContext.d.ts","sourceRoot":"","sources":["../../../src/components/context/ChatBotContext.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"ChatBotContext.d.ts","sourceRoot":"","sources":["../../../src/components/context/ChatBotContext.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAO/B,OAAO,EACL,kBAAkB,EAClB,YAAY,EAGb,MAAM,uBAAuB,CAAC;AAI/B,eAAO,MAAM,UAAU,0BAMtB,CAAC;AAEF,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,YAAY,CAs5ClD,CAAC"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import * as React from 'react';
|
|
3
2
|
import { ethers } from 'ethers';
|
|
4
|
-
import { createNxtlinqApi } from '../../api/nxtlinq-api';
|
|
5
3
|
import stringify from 'fast-json-stable-stringify';
|
|
6
|
-
import
|
|
4
|
+
import * as React from 'react';
|
|
5
|
+
import { createNxtlinqApi } from '../../api/nxtlinq-api';
|
|
7
6
|
import useLocalStorage from '../../core/lib/useLocalStorage';
|
|
7
|
+
import { useSpeechToTextFromMic } from '../../core/lib/useSpeechToTextFromMic';
|
|
8
|
+
import metakeepClient from '../../core/metakeepClient';
|
|
9
|
+
import { sleep } from '../../core/utils';
|
|
8
10
|
import { DEFAULT_AI_MODELS } from '../types/ChatBotTypes';
|
|
9
11
|
const ChatBotContext = React.createContext(undefined);
|
|
10
12
|
export const useChatBot = () => {
|
|
@@ -17,6 +19,12 @@ export const useChatBot = () => {
|
|
|
17
19
|
export const ChatBotProvider = ({ onMessage, onError, onToolUse, presetMessages = [], placeholder = 'Type a message...', className = '', maxRetries = 3, retryDelay = 2000, serviceId, apiKey, apiSecret, onVerifyWallet, permissionGroup, children,
|
|
18
20
|
// AI Model related attributes
|
|
19
21
|
availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector = true, onModelChange }) => {
|
|
22
|
+
const nxtlinqApi = React.useMemo(() => createNxtlinqApi(apiKey, apiSecret), [apiKey, apiSecret]);
|
|
23
|
+
// Custom hook
|
|
24
|
+
const { isRecording, transcript, start: startRecording, stop: stopRecording } = useSpeechToTextFromMic({
|
|
25
|
+
apiKey,
|
|
26
|
+
apiSecret
|
|
27
|
+
});
|
|
20
28
|
// State
|
|
21
29
|
const [messages, setMessages] = React.useState([]);
|
|
22
30
|
const [inputValue, setInputValue] = React.useState('');
|
|
@@ -42,6 +50,9 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
|
|
|
42
50
|
const permissionsRef = React.useRef(permissions);
|
|
43
51
|
const nxtlinqAITServiceAccessTokenRef = React.useRef(nxtlinqAITServiceAccessToken);
|
|
44
52
|
const signerRef = React.useRef(signer);
|
|
53
|
+
// Refs for input value and recording state
|
|
54
|
+
const isRecordingRef = React.useRef(false);
|
|
55
|
+
const textInputRef = React.useRef(null);
|
|
45
56
|
// Update refs when state changes
|
|
46
57
|
React.useEffect(() => {
|
|
47
58
|
hitAddressRef.current = hitAddress;
|
|
@@ -58,6 +69,15 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
|
|
|
58
69
|
React.useEffect(() => {
|
|
59
70
|
signerRef.current = signer;
|
|
60
71
|
}, [signer]);
|
|
72
|
+
React.useEffect(() => {
|
|
73
|
+
if (!transcript) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
setInputValue(transcript);
|
|
77
|
+
}, [transcript]);
|
|
78
|
+
React.useEffect(() => {
|
|
79
|
+
isRecordingRef.current = isRecording;
|
|
80
|
+
}, [isRecording]);
|
|
61
81
|
const [notification, setNotification] = React.useState({
|
|
62
82
|
show: false,
|
|
63
83
|
type: 'info',
|
|
@@ -68,7 +88,6 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
|
|
|
68
88
|
// AI Model related state
|
|
69
89
|
const [selectedModelIndex, setSelectedModelIndex] = useLocalStorage('selectedAIModelIndex', defaultModelIndex);
|
|
70
90
|
const [showModelSelectorState, setShowModelSelectorState] = React.useState(showModelSelector);
|
|
71
|
-
const nxtlinqApi = React.useMemo(() => createNxtlinqApi(apiKey, apiSecret), [apiKey, apiSecret]);
|
|
72
91
|
// Notification functions
|
|
73
92
|
const showNotification = (type, message, duration = 5000) => {
|
|
74
93
|
setNotification({
|
|
@@ -659,13 +678,7 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
|
|
|
659
678
|
content: `You don't have the required AIT permission: ${toolName}. Would you like to enable AIT permissions?`,
|
|
660
679
|
role: 'assistant',
|
|
661
680
|
timestamp: new Date().toISOString(),
|
|
662
|
-
button: 'enableAIT'
|
|
663
|
-
metadata: {
|
|
664
|
-
model: 'gpt-4',
|
|
665
|
-
permissions: currentPermissions,
|
|
666
|
-
issuedBy: currentHitAddress || '',
|
|
667
|
-
toolName: toolName
|
|
668
|
-
}
|
|
681
|
+
button: 'enableAIT'
|
|
669
682
|
}]);
|
|
670
683
|
return false;
|
|
671
684
|
}
|
|
@@ -900,7 +913,13 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
|
|
|
900
913
|
// Handle submit
|
|
901
914
|
const handleSubmit = async (e) => {
|
|
902
915
|
e.preventDefault();
|
|
903
|
-
|
|
916
|
+
while (isRecordingRef.current) {
|
|
917
|
+
stopRecording();
|
|
918
|
+
await sleep(1000);
|
|
919
|
+
}
|
|
920
|
+
if (!textInputRef.current)
|
|
921
|
+
return;
|
|
922
|
+
if (!textInputRef.current.value.trim() || isLoading)
|
|
904
923
|
return;
|
|
905
924
|
// Show loading message if AIT is still loading
|
|
906
925
|
if (isAITLoading) {
|
|
@@ -919,7 +938,7 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
|
|
|
919
938
|
return;
|
|
920
939
|
}
|
|
921
940
|
try {
|
|
922
|
-
await sendMessage(
|
|
941
|
+
await sendMessage(textInputRef.current.value);
|
|
923
942
|
}
|
|
924
943
|
catch (error) {
|
|
925
944
|
console.error('Failed to send message:', error);
|
|
@@ -962,12 +981,16 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
|
|
|
962
981
|
}
|
|
963
982
|
};
|
|
964
983
|
// Generate and register AIT
|
|
965
|
-
const generateAndRegisterAIT = async (newPermissions) => {
|
|
984
|
+
const generateAndRegisterAIT = async (newPermissions, isFromAIAgent = false) => {
|
|
966
985
|
if (!signer || !hitAddress) {
|
|
967
986
|
throw new Error('Missing signer or wallet address');
|
|
968
987
|
}
|
|
988
|
+
// If AI Agent is creating, must check if user has existing AIT
|
|
989
|
+
if (isFromAIAgent && !ait) {
|
|
990
|
+
throw new Error('You must have an existing AIT before AI Agent can create new AITs');
|
|
991
|
+
}
|
|
969
992
|
const timestamp = Math.floor(Date.now() / 1000);
|
|
970
|
-
const aitId = `did:polygon:
|
|
993
|
+
const aitId = `did:polygon:nxtlinq:${hitAddress}:${timestamp}`;
|
|
971
994
|
const metadata = {
|
|
972
995
|
model: 'gpt-4',
|
|
973
996
|
permissions: newPermissions || permissions,
|
|
@@ -980,13 +1003,17 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
|
|
|
980
1003
|
throw new Error(`Failed to upload metadata: ${uploadResponse.error}`);
|
|
981
1004
|
}
|
|
982
1005
|
const { metadataCid } = uploadResponse;
|
|
983
|
-
const
|
|
1006
|
+
const createAITParams = {
|
|
984
1007
|
aitId,
|
|
985
1008
|
controller: hitAddress,
|
|
986
1009
|
serviceId,
|
|
987
1010
|
metadataHash,
|
|
988
1011
|
metadataCid,
|
|
989
|
-
|
|
1012
|
+
isFromAIAgent: isFromAIAgent,
|
|
1013
|
+
parentAITId: isFromAIAgent ? ait?.aitId : undefined,
|
|
1014
|
+
};
|
|
1015
|
+
console.log('createAIT params:', createAITParams);
|
|
1016
|
+
const createAITResponse = await nxtlinqApi.ait.createAIT(createAITParams, nxtlinqAITServiceAccessToken || '');
|
|
990
1017
|
if ('error' in createAITResponse) {
|
|
991
1018
|
throw new Error(`Failed to create AIT: ${createAITResponse.error}`);
|
|
992
1019
|
}
|
|
@@ -1002,6 +1029,7 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
|
|
|
1002
1029
|
};
|
|
1003
1030
|
// Auto enable AIT permissions
|
|
1004
1031
|
const autoEnableAIT = async (toolName) => {
|
|
1032
|
+
console.log('autoEnableAIT called with toolName:', toolName, 'isFromAIAgent will be set to true');
|
|
1005
1033
|
if (!signer || !hitAddress) {
|
|
1006
1034
|
showError('Please connect your wallet first');
|
|
1007
1035
|
return false;
|
|
@@ -1018,8 +1046,8 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
|
|
|
1018
1046
|
if (!newPermissions.includes(toolName)) {
|
|
1019
1047
|
newPermissions.push(toolName);
|
|
1020
1048
|
}
|
|
1021
|
-
// Generate and register AIT with new permissions
|
|
1022
|
-
await generateAndRegisterAIT(newPermissions);
|
|
1049
|
+
// Generate and register AIT with new permissions (AI Agent creation)
|
|
1050
|
+
await generateAndRegisterAIT(newPermissions, true);
|
|
1023
1051
|
showSuccess('AIT permissions enabled successfully! You can now use the AI agent.');
|
|
1024
1052
|
await refreshAIT(true);
|
|
1025
1053
|
return true;
|
|
@@ -1039,7 +1067,7 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
|
|
|
1039
1067
|
const savePermissions = async (newPermissions) => {
|
|
1040
1068
|
setIsDisabled(true);
|
|
1041
1069
|
try {
|
|
1042
|
-
await generateAndRegisterAIT(newPermissions);
|
|
1070
|
+
await generateAndRegisterAIT(newPermissions, false); // user creation
|
|
1043
1071
|
showSuccess('AIT permissions saved successfully! You can now use the AI agent with your configured permissions.');
|
|
1044
1072
|
setShowPermissionForm(false);
|
|
1045
1073
|
setIsPermissionFormOpen(false);
|
|
@@ -1223,6 +1251,9 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
|
|
|
1223
1251
|
isWalletLoading,
|
|
1224
1252
|
isAutoConnecting,
|
|
1225
1253
|
notification,
|
|
1254
|
+
isRecording,
|
|
1255
|
+
transcript,
|
|
1256
|
+
textInputRef,
|
|
1226
1257
|
// AI Model related state
|
|
1227
1258
|
availableModels,
|
|
1228
1259
|
selectedModelIndex,
|
|
@@ -1253,6 +1284,8 @@ availableModels = DEFAULT_AI_MODELS, defaultModelIndex = 0, showModelSelector =
|
|
|
1253
1284
|
showWarning,
|
|
1254
1285
|
showInfo,
|
|
1255
1286
|
refreshAIT,
|
|
1287
|
+
startRecording,
|
|
1288
|
+
stopRecording,
|
|
1256
1289
|
// AI Model related functions
|
|
1257
1290
|
handleModelChange,
|
|
1258
1291
|
getCurrentModel,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AIT, AITApi, Message, ServicePermission } from '../../types/ait-api';
|
|
2
2
|
export interface PresetMessage {
|
|
3
3
|
text: string;
|
|
4
4
|
autoSend?: boolean;
|
|
@@ -76,6 +76,9 @@ export interface ChatBotContextType {
|
|
|
76
76
|
autoHide?: boolean;
|
|
77
77
|
duration?: number;
|
|
78
78
|
};
|
|
79
|
+
isRecording: boolean;
|
|
80
|
+
transcript: string;
|
|
81
|
+
textInputRef: React.RefObject<HTMLInputElement>;
|
|
79
82
|
availableModels: AIModel[];
|
|
80
83
|
selectedModelIndex: number;
|
|
81
84
|
showModelSelector: boolean;
|
|
@@ -102,6 +105,8 @@ export interface ChatBotContextType {
|
|
|
102
105
|
showWarning: (message: string) => void;
|
|
103
106
|
showInfo: (message: string) => void;
|
|
104
107
|
refreshAIT: (forceUpdatePermissions?: boolean) => Promise<void>;
|
|
108
|
+
startRecording: () => Promise<void>;
|
|
109
|
+
stopRecording: () => void;
|
|
105
110
|
handleModelChange: (modelIndex: number) => void;
|
|
106
111
|
getCurrentModel: () => AIModel;
|
|
107
112
|
onSave: (newPermissions?: string[]) => Promise<void>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ChatBotTypes.d.ts","sourceRoot":"","sources":["../../../src/components/types/ChatBotTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"ChatBotTypes.d.ts","sourceRoot":"","sources":["../../../src/components/types/ChatBotTypes.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,qBAAqB,CAAC;AAE9E,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,KAAK,EAAE,MAAM,CAAC;IACd,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;AAED,eAAO,MAAM,iBAAiB,EAAE,OAAO,EAMtC,CAAC;AAEF,eAAO,MAAM,YAAY,EAAE,MAAM,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C,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IAChD,eAAe,EAAE,MAAM,OAAO,CAAC;IAG/B,MAAM,EAAE,CAAC,cAAc,CAAC,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACrD,eAAe,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IACnD,QAAQ,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,sBAAsB,EAAE,OAAO,CAAC;IAChC,cAAc,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IACpC,SAAS,EAAE,MAAM,CAAC;IAClB,eAAe,CAAC,EAAE,MAAM,CAAC;IAGzB,KAAK,EAAE,YAAY,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MessageInput.d.ts","sourceRoot":"","sources":["../../../src/components/ui/MessageInput.tsx"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"MessageInput.d.ts","sourceRoot":"","sources":["../../../src/components/ui/MessageInput.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAG/B,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAmGhC,CAAC"}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import MicIcon from '@mui/icons-material/Mic';
|
|
3
|
+
import MicOffIcon from '@mui/icons-material/MicOff';
|
|
4
|
+
import { IconButton, InputBase } from '@mui/material';
|
|
2
5
|
import { useChatBot } from '../context/ChatBotContext';
|
|
3
6
|
export const MessageInput = () => {
|
|
4
|
-
const { inputValue, setInputValue, isLoading, isAITLoading, handleSubmit, props: { placeholder = 'Type a message...' } } = useChatBot();
|
|
7
|
+
const { inputValue, setInputValue, isLoading, isAITLoading, handleSubmit, isRecording, startRecording, stopRecording, textInputRef, props: { placeholder = 'Type a message...' } } = useChatBot();
|
|
5
8
|
const isDisabled = isLoading || isAITLoading;
|
|
6
9
|
const inputPlaceholder = isAITLoading ? 'Loading wallet configuration...' : placeholder;
|
|
7
10
|
const handleKeyPress = (e) => {
|
|
@@ -15,7 +18,9 @@ export const MessageInput = () => {
|
|
|
15
18
|
display: 'flex',
|
|
16
19
|
gap: '10px',
|
|
17
20
|
borderTop: '1px solid #eee'
|
|
18
|
-
}, children: [_jsx(
|
|
21
|
+
}, children: [_jsx(InputBase, { value: inputValue, onChange: (e) => setInputValue(e.target.value), onKeyPress: handleKeyPress, placeholder: inputPlaceholder, disabled: isDisabled, fullWidth: true, inputProps: {
|
|
22
|
+
ref: textInputRef
|
|
23
|
+
}, endAdornment: _jsx(IconButton, { onClick: () => isRecording ? stopRecording() : startRecording(), disabled: isDisabled, children: isRecording ? _jsx(MicIcon, {}) : _jsx(MicOffIcon, {}) }), onFocus: () => stopRecording(), style: {
|
|
19
24
|
flex: 1,
|
|
20
25
|
padding: '10px',
|
|
21
26
|
border: '1px solid #ddd',
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { SpeechRecognizer } from 'microsoft-cognitiveservices-speech-sdk';
|
|
2
|
+
import { Dispatch, SetStateAction } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* 啟動語音辨識,會不斷更新 speechToTextArray(每段句子為一個陣列元素)
|
|
5
|
+
*/
|
|
6
|
+
export declare const startSpeechToTextFromMic: (setSpeechToTextArray: Dispatch<SetStateAction<string[]>>, config: {
|
|
7
|
+
apiKey: string;
|
|
8
|
+
apiSecret: string;
|
|
9
|
+
}) => Promise<SpeechRecognizer | undefined>;
|
|
10
|
+
/**
|
|
11
|
+
* 停止語音辨識
|
|
12
|
+
*/
|
|
13
|
+
export declare const stopRecognition: (recognizer: SpeechRecognizer | undefined) => void;
|
|
14
|
+
export declare function getTokenOrRefresh(apiKey: string, apiSecret: string): Promise<{
|
|
15
|
+
authToken: null;
|
|
16
|
+
error: string;
|
|
17
|
+
region?: undefined;
|
|
18
|
+
} | {
|
|
19
|
+
authToken: any;
|
|
20
|
+
region: any;
|
|
21
|
+
error?: undefined;
|
|
22
|
+
}>;
|
|
23
|
+
//# sourceMappingURL=helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../../../src/core/lib/useSpeechToTextFromMic/helper.ts"],"names":[],"mappings":"AACA,OAAO,EAML,gBAAgB,EACjB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAMjD;;GAEG;AACH,eAAO,MAAM,wBAAwB,GACnC,sBAAsB,QAAQ,CAAC,cAAc,CAAC,MAAM,EAAE,CAAC,CAAC,EACxD,QAAQ;IAAE,MAAM,EAAE,MAAM,CAAC;IAAC,SAAS,EAAE,MAAM,CAAA;CAAE,KAC5C,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAyCtC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,eAAe,GAAI,YAAY,gBAAgB,GAAG,SAAS,SAIvE,CAAC;AAEF,wBAAsB,iBAAiB,CAAC,MAAM,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM;;;;;;;;GAyBxE"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { AudioConfig, CancellationReason, PropertyId, ResultReason, SpeechConfig, SpeechRecognizer, } from 'microsoft-cognitiveservices-speech-sdk';
|
|
2
|
+
import Cookie from 'universal-cookie';
|
|
3
|
+
import { createNxtlinqApi } from '../../../api/nxtlinq-api';
|
|
4
|
+
let recognizer;
|
|
5
|
+
/**
|
|
6
|
+
* 啟動語音辨識,會不斷更新 speechToTextArray(每段句子為一個陣列元素)
|
|
7
|
+
*/
|
|
8
|
+
export const startSpeechToTextFromMic = async (setSpeechToTextArray, config) => {
|
|
9
|
+
const tokenRes = await getTokenOrRefresh(config.apiKey, config.apiSecret);
|
|
10
|
+
const speechConfig = SpeechConfig.fromAuthorizationToken(tokenRes.authToken, tokenRes.region);
|
|
11
|
+
speechConfig.speechRecognitionLanguage = 'en-US';
|
|
12
|
+
speechConfig.setProperty(PropertyId.SpeechServiceConnection_InitialSilenceTimeoutMs, '10000');
|
|
13
|
+
speechConfig.setProperty(PropertyId.SpeechServiceConnection_EndSilenceTimeoutMs, '86400000');
|
|
14
|
+
speechConfig.setProperty(PropertyId.Speech_SegmentationSilenceTimeoutMs, '2500');
|
|
15
|
+
const audioConfig = AudioConfig.fromDefaultMicrophoneInput();
|
|
16
|
+
recognizer = new SpeechRecognizer(speechConfig, audioConfig);
|
|
17
|
+
const conversationHistory = [];
|
|
18
|
+
let index = 0;
|
|
19
|
+
recognizer.recognizing = (_s, e) => {
|
|
20
|
+
console.log(`RECOGNIZING: Text=${e.result.text}`);
|
|
21
|
+
conversationHistory[index] = e.result.text;
|
|
22
|
+
setSpeechToTextArray([...conversationHistory]);
|
|
23
|
+
};
|
|
24
|
+
recognizer.recognized = (_s, e) => {
|
|
25
|
+
if (e.result.reason === ResultReason.RecognizedSpeech) {
|
|
26
|
+
console.log(`RECOGNIZED: Text=${e.result.text}`);
|
|
27
|
+
conversationHistory[index] = e.result.text;
|
|
28
|
+
setSpeechToTextArray([...conversationHistory]);
|
|
29
|
+
index += 1;
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
recognizer.canceled = (_s, e) => {
|
|
33
|
+
console.log(`CANCELED: Reason=${e.reason}`);
|
|
34
|
+
if (e.reason === CancellationReason.Error) {
|
|
35
|
+
console.error(`CANCELED: ErrorCode=${e.errorCode}`);
|
|
36
|
+
console.error(`CANCELED: ErrorDetails=${e.errorDetails}`);
|
|
37
|
+
console.error('CANCELED: Did you set the speech resource key and region values?');
|
|
38
|
+
}
|
|
39
|
+
stopRecognition(recognizer);
|
|
40
|
+
};
|
|
41
|
+
recognizer.startContinuousRecognitionAsync();
|
|
42
|
+
return recognizer;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* 停止語音辨識
|
|
46
|
+
*/
|
|
47
|
+
export const stopRecognition = (recognizer) => {
|
|
48
|
+
if (recognizer) {
|
|
49
|
+
recognizer.stopContinuousRecognitionAsync();
|
|
50
|
+
}
|
|
51
|
+
};
|
|
52
|
+
export async function getTokenOrRefresh(apiKey, apiSecret) {
|
|
53
|
+
const nxtlinqApi = createNxtlinqApi(apiKey, apiSecret);
|
|
54
|
+
const cookie = new Cookie();
|
|
55
|
+
const speechToken = cookie.get('speech-token');
|
|
56
|
+
if (speechToken === undefined) {
|
|
57
|
+
try {
|
|
58
|
+
const res = await nxtlinqApi.cognitive.getCognitiveToken();
|
|
59
|
+
if ('error' in res) {
|
|
60
|
+
throw new Error(res.error);
|
|
61
|
+
}
|
|
62
|
+
const token = res.token;
|
|
63
|
+
const region = res.region;
|
|
64
|
+
cookie.set('speech-token', region + ':' + token, { maxAge: 540, path: '/' });
|
|
65
|
+
return { authToken: token, region: region };
|
|
66
|
+
}
|
|
67
|
+
catch (e) {
|
|
68
|
+
const err = e;
|
|
69
|
+
console.log(err.response.data);
|
|
70
|
+
return { authToken: null, error: err.response.data };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
const idx = speechToken.indexOf(':');
|
|
75
|
+
return { authToken: speechToken.slice(idx + 1), region: speechToken.slice(0, idx) };
|
|
76
|
+
}
|
|
77
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
apiKey: string;
|
|
3
|
+
apiSecret: string;
|
|
4
|
+
}
|
|
5
|
+
type UseSpeechToTextFromMicResult = {
|
|
6
|
+
start: () => Promise<void>;
|
|
7
|
+
stop: () => void;
|
|
8
|
+
isRecording: boolean;
|
|
9
|
+
transcript: string;
|
|
10
|
+
};
|
|
11
|
+
export declare function useSpeechToTextFromMic({ apiKey, apiSecret }: Props): UseSpeechToTextFromMicResult;
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/lib/useSpeechToTextFromMic/index.ts"],"names":[],"mappings":"AAIA,UAAU,KAAK;IACb,MAAM,EAAE,MAAM,CAAC;IACf,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,KAAK,4BAA4B,GAAG;IAClC,KAAK,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;IAC3B,IAAI,EAAE,MAAM,IAAI,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;CACpB,CAAC;AAEF,wBAAgB,sBAAsB,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,EAAE,KAAK,GAAG,4BAA4B,CA0CjG"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { useRef, useState } from 'react';
|
|
2
|
+
import { startSpeechToTextFromMic, stopRecognition } from './helper';
|
|
3
|
+
export function useSpeechToTextFromMic({ apiKey, apiSecret }) {
|
|
4
|
+
const [isRecording, setIsRecording] = useState(false);
|
|
5
|
+
const [transcriptArray, setTranscriptArray] = useState([]);
|
|
6
|
+
const [recognizer, setRecognizer] = useState();
|
|
7
|
+
const wakelock = useRef();
|
|
8
|
+
const canWakeLock = () => 'wakeLock' in navigator;
|
|
9
|
+
async function lockWakeState() {
|
|
10
|
+
if (!canWakeLock())
|
|
11
|
+
return;
|
|
12
|
+
try {
|
|
13
|
+
wakelock.current = await navigator.wakeLock.request('screen');
|
|
14
|
+
wakelock.current.addEventListener('release', () => {
|
|
15
|
+
console.log('Wake lock released');
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
console.error('Wake lock error:', err);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const start = async () => {
|
|
23
|
+
await lockWakeState();
|
|
24
|
+
setIsRecording(true);
|
|
25
|
+
const recognizerInstance = await startSpeechToTextFromMic(setTranscriptArray, { apiKey, apiSecret });
|
|
26
|
+
setRecognizer(recognizerInstance);
|
|
27
|
+
};
|
|
28
|
+
const stop = () => {
|
|
29
|
+
wakelock.current?.release();
|
|
30
|
+
stopRecognition(recognizer);
|
|
31
|
+
setIsRecording(false);
|
|
32
|
+
setRecognizer(undefined);
|
|
33
|
+
};
|
|
34
|
+
const transcript = transcriptArray.join(' ');
|
|
35
|
+
return {
|
|
36
|
+
start,
|
|
37
|
+
stop,
|
|
38
|
+
isRecording,
|
|
39
|
+
transcript,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
@@ -9,11 +9,13 @@ export interface CreateAITParams {
|
|
|
9
9
|
serviceId: string;
|
|
10
10
|
metadataHash: string;
|
|
11
11
|
metadataCid: string;
|
|
12
|
+
isFromAIAgent?: boolean;
|
|
13
|
+
parentAITId?: string;
|
|
12
14
|
}
|
|
13
15
|
export declare const generateAITId: (address: string) => string;
|
|
14
16
|
export declare const createAITMetadata: (permissions: string[], issuedBy: string) => AITMetadata;
|
|
15
17
|
export declare const generateMetadataHash: (metadata: AITMetadata) => string;
|
|
16
|
-
export declare const prepareAITCreation: (address: string, permissions: string[], serviceId: string) => {
|
|
18
|
+
export declare const prepareAITCreation: (address: string, permissions: string[], serviceId: string, isFromAIAgent?: boolean, parentAITId?: string) => {
|
|
17
19
|
aitId: string;
|
|
18
20
|
metadata: AITMetadata;
|
|
19
21
|
metadataHash: string;
|
|
@@ -23,6 +25,8 @@ export declare const prepareAITCreation: (address: string, permissions: string[]
|
|
|
23
25
|
serviceId: string;
|
|
24
26
|
metadataHash: string;
|
|
25
27
|
metadataCid: string;
|
|
28
|
+
isFromAIAgent: boolean;
|
|
29
|
+
parentAITId: string | undefined;
|
|
26
30
|
};
|
|
27
31
|
};
|
|
28
32
|
//# sourceMappingURL=aitUtils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"aitUtils.d.ts","sourceRoot":"","sources":["../../../src/core/utils/aitUtils.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"aitUtils.d.ts","sourceRoot":"","sources":["../../../src/core/utils/aitUtils.ts"],"names":[],"mappings":"AAGA,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,eAAe;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,eAAO,MAAM,aAAa,GAAI,SAAS,MAAM,KAAG,MAG/C,CAAC;AAEF,eAAO,MAAM,iBAAiB,GAAI,aAAa,MAAM,EAAE,EAAE,UAAU,MAAM,KAAG,WAM3E,CAAC;AAEF,eAAO,MAAM,oBAAoB,GAAI,UAAU,WAAW,KAAG,MAG5D,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,SAAS,MAAM,EAAE,aAAa,MAAM,EAAE,EAAE,WAAW,MAAM,EAAE,uBAAqB,EAAE,cAAc,MAAM;;;;;;;;;;;;;CAmBxI,CAAC"}
|
|
@@ -2,7 +2,7 @@ import { ethers } from 'ethers';
|
|
|
2
2
|
import stringify from 'fast-json-stable-stringify';
|
|
3
3
|
export const generateAITId = (address) => {
|
|
4
4
|
const timestamp = Math.floor(Date.now() / 1000);
|
|
5
|
-
return `did:polygon:
|
|
5
|
+
return `did:polygon:nxtlinq:${address}:${timestamp}`;
|
|
6
6
|
};
|
|
7
7
|
export const createAITMetadata = (permissions, issuedBy) => {
|
|
8
8
|
return {
|
|
@@ -15,7 +15,7 @@ export const generateMetadataHash = (metadata) => {
|
|
|
15
15
|
const metadataStr = stringify(metadata);
|
|
16
16
|
return ethers.utils.keccak256(ethers.utils.toUtf8Bytes(metadataStr));
|
|
17
17
|
};
|
|
18
|
-
export const prepareAITCreation = (address, permissions, serviceId) => {
|
|
18
|
+
export const prepareAITCreation = (address, permissions, serviceId, isFromAIAgent = false, parentAITId) => {
|
|
19
19
|
const aitId = generateAITId(address);
|
|
20
20
|
const metadata = createAITMetadata(permissions, address);
|
|
21
21
|
const metadataHash = generateMetadataHash(metadata);
|
|
@@ -29,6 +29,8 @@ export const prepareAITCreation = (address, permissions, serviceId) => {
|
|
|
29
29
|
serviceId,
|
|
30
30
|
metadataHash,
|
|
31
31
|
metadataCid: '', // Will be set after metadata upload
|
|
32
|
+
isFromAIAgent,
|
|
33
|
+
parentAITId,
|
|
32
34
|
}
|
|
33
35
|
};
|
|
34
36
|
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/utils/index.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK,GAAI,IAAI,MAAM,qBAE/B,CAAA"}
|
package/dist/types/ait-api.d.ts
CHANGED
|
@@ -59,6 +59,8 @@ export interface CreateAITParams {
|
|
|
59
59
|
serviceId: string;
|
|
60
60
|
metadataHash: string;
|
|
61
61
|
metadataCid: string;
|
|
62
|
+
isFromAIAgent?: boolean;
|
|
63
|
+
parentAITId?: string;
|
|
62
64
|
}
|
|
63
65
|
export interface CreateMetadataParams extends AITMetadata {
|
|
64
66
|
}
|
|
@@ -178,5 +180,13 @@ export interface AITApi {
|
|
|
178
180
|
error: string;
|
|
179
181
|
}>;
|
|
180
182
|
};
|
|
183
|
+
cognitive: {
|
|
184
|
+
getCognitiveToken: () => Promise<{
|
|
185
|
+
token: string;
|
|
186
|
+
region: string;
|
|
187
|
+
} | {
|
|
188
|
+
error: string;
|
|
189
|
+
}>;
|
|
190
|
+
};
|
|
181
191
|
}
|
|
182
192
|
//# sourceMappingURL=ait-api.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ait-api.d.ts","sourceRoot":"","sources":["../../src/types/ait-api.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,OAAO;IACtB,EAAE,EAAE,MAAM,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,GAAG,WAAW,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,QAAQ,CAAC,EAAE;QACT,KAAK,CAAC,EAAE,MAAM,CAAC;QACf,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;QACvB,QAAQ,CAAC,EAAE,MAAM,CAAC;QAClB,OAAO,CAAC,EAAE;YACR,IAAI,EAAE,MAAM,CAAC;YACb,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;SAC5B,CAAC;QACF,OAAO,CAAC,EAAE,OAAO,CAAC;QAClB,QAAQ,CAAC,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED,MAAM,WAAW,GAAG;IAClB,KAAK,EAAE,MAAM,CAAC;IACd,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,WAAW,CAAC;IACtB,YAAY,EAAE,MAAM,CAAC;IACrB,WAAW,EAAE,MAAM,CAAC;CACrB;AAED,MAAM,WAAW,WAAW;IAC1B,KAAK,EAAE,MAAM,CAAC;IACd,WAAW,EAAE,MAAM,EAAE,CA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|
2
2
|
"name": "@bytexbyte/nxtlinq-ai-agent-sdk",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.3.1",
|
|
4
4
|
"description": "Nxtlinq AI Agent SDK - Proprietary Software with enhanced async operation handling",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -34,8 +34,14 @@
|
|
|
34
34
|
"typescript": "^5.4.2"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
+
"@emotion/react": "^11.14.0",
|
|
38
|
+
"@emotion/styled": "^11.14.1",
|
|
39
|
+
"@mui/icons-material": "^7.2.0",
|
|
40
|
+
"@mui/material": "^7.2.0",
|
|
37
41
|
"ethers": "5.7.0",
|
|
38
42
|
"json-stable-stringify": "^1.0.2",
|
|
39
|
-
"metakeep": "^2.2.8"
|
|
43
|
+
"metakeep": "^2.2.8",
|
|
44
|
+
"microsoft-cognitiveservices-speech-sdk": "^1.45.0",
|
|
45
|
+
"universal-cookie": "^8.0.1"
|
|
40
46
|
}
|
|
41
|
-
}
|
|
47
|
+
}
|