@bytexbyte/nxtlinq-ai-agent-sdk 1.2.3 → 1.2.5
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/README.md +424 -147
- package/dist/api/nxtlinq-api.d.ts.map +1 -1
- package/dist/api/nxtlinq-api.js +8 -2
- package/dist/components/context/ChatBotContext.d.ts.map +1 -1
- package/dist/components/context/ChatBotContext.js +188 -47
- package/dist/components/types/ChatBotTypes.d.ts +19 -2
- package/dist/components/types/ChatBotTypes.d.ts.map +1 -1
- package/dist/components/types/ChatBotTypes.js +14 -1
- package/dist/components/ui/ChatBotUI.d.ts.map +1 -1
- package/dist/components/ui/ChatBotUI.js +75 -9
- package/dist/components/ui/MessageInput.d.ts.map +1 -1
- package/dist/components/ui/MessageInput.js +7 -4
- package/dist/components/ui/MessageList.d.ts.map +1 -1
- package/dist/components/ui/MessageList.js +53 -17
- package/dist/components/ui/ModelSelector.d.ts +3 -0
- package/dist/components/ui/ModelSelector.d.ts.map +1 -0
- package/dist/components/ui/ModelSelector.js +65 -0
- package/dist/components/ui/PermissionForm.d.ts.map +1 -1
- package/dist/components/ui/PermissionForm.js +60 -23
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/types/ait-api.d.ts +32 -1
- package/dist/types/ait-api.d.ts.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,26 +1,37 @@
|
|
|
1
1
|
# Nxtlinq AI Agent SDK
|
|
2
2
|
|
|
3
|
-
A
|
|
3
|
+
A powerful AI Agent SDK that supports multiple AI model switching, wallet connection, permission management, and more.
|
|
4
4
|
|
|
5
|
-
## 🚀
|
|
5
|
+
## 🚀 What's New in v1.2.4
|
|
6
6
|
|
|
7
|
-
-
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
-
|
|
11
|
-
-
|
|
12
|
-
- **Type Safety**: Complete TypeScript type definitions
|
|
13
|
-
- **Responsive UI**: Modern user interface design
|
|
7
|
+
- **🎯 AI Model Switching**: Real-time switching between multiple AI models during conversations
|
|
8
|
+
- **🤖 Multi-Model Support**: Support for Nova, Claude, ChatGPT, Llama, and Gemini
|
|
9
|
+
- **🎨 Enhanced UI**: Model selector dropdown and model badges for messages
|
|
10
|
+
- **💾 Persistent Preferences**: Model selection saved in localStorage
|
|
11
|
+
- **🔧 Improved API**: Enhanced API client with dynamic model endpoints
|
|
14
12
|
|
|
15
|
-
##
|
|
13
|
+
## Features
|
|
14
|
+
|
|
15
|
+
- 🤖 **Multiple AI Models Support**: Supports Nova, Claude, ChatGPT, Llama, Gemini, and other AI models
|
|
16
|
+
- 🔄 **Real-time Model Switching**: Users can switch AI models at any time during conversations
|
|
17
|
+
- 👛 **Wallet Integration**: Supports MetaKeep wallet connection and verification
|
|
18
|
+
- 🔐 **Permission Management**: AIT (AI Identity Token) based permission control system
|
|
19
|
+
- 💬 **Real-time Chat**: Context-aware conversation functionality
|
|
20
|
+
- 🎨 **Customizable UI**: Complete UI components and style customization options
|
|
21
|
+
- 📱 **Responsive Design**: Works seamlessly across different screen sizes
|
|
22
|
+
- 🔒 **Type Safety**: Full TypeScript support with comprehensive type definitions
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
16
25
|
|
|
17
26
|
```bash
|
|
18
27
|
npm install @bytexbyte/nxtlinq-ai-agent-sdk
|
|
28
|
+
# or
|
|
29
|
+
yarn add @bytexbyte/nxtlinq-ai-agent-sdk
|
|
19
30
|
```
|
|
20
31
|
|
|
21
|
-
##
|
|
32
|
+
## Quick Start
|
|
22
33
|
|
|
23
|
-
### Basic
|
|
34
|
+
### Basic Configuration
|
|
24
35
|
|
|
25
36
|
```tsx
|
|
26
37
|
import { ChatBot } from '@bytexbyte/nxtlinq-ai-agent-sdk';
|
|
@@ -31,206 +42,472 @@ function App() {
|
|
|
31
42
|
serviceId="your-service-id"
|
|
32
43
|
apiKey="your-api-key"
|
|
33
44
|
apiSecret="your-api-secret"
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
45
|
+
/>
|
|
46
|
+
);
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
### AI Model Switching
|
|
51
|
+
|
|
52
|
+
```tsx
|
|
53
|
+
import { ChatBot, DEFAULT_AI_MODELS } from '@bytexbyte/nxtlinq-ai-agent-sdk';
|
|
54
|
+
|
|
55
|
+
function App() {
|
|
56
|
+
return (
|
|
57
|
+
<ChatBot
|
|
58
|
+
serviceId="your-service-id"
|
|
59
|
+
apiKey="your-api-key"
|
|
60
|
+
apiSecret="your-api-secret"
|
|
61
|
+
// Enable AI model switching
|
|
62
|
+
showModelSelector={true}
|
|
63
|
+
defaultModelIndex={0} // Start with Nova
|
|
64
|
+
onModelChange={(model) => {
|
|
65
|
+
console.log('Switched to:', model.label);
|
|
66
|
+
// Track model usage
|
|
67
|
+
analytics.track('model_changed', { model: model.value });
|
|
39
68
|
}}
|
|
40
69
|
/>
|
|
41
70
|
);
|
|
42
71
|
}
|
|
43
72
|
```
|
|
44
73
|
|
|
45
|
-
###
|
|
74
|
+
### Custom Model Configuration
|
|
46
75
|
|
|
47
76
|
```tsx
|
|
48
77
|
import { ChatBot } from '@bytexbyte/nxtlinq-ai-agent-sdk';
|
|
49
78
|
|
|
50
79
|
function App() {
|
|
80
|
+
// Custom available AI models
|
|
81
|
+
const customModels = [
|
|
82
|
+
{ label: 'Nova', value: 'nova' },
|
|
83
|
+
{ label: 'Claude', value: 'claude' },
|
|
84
|
+
{ label: 'ChatGPT', value: 'open-ai' },
|
|
85
|
+
// Add more models as needed
|
|
86
|
+
];
|
|
87
|
+
|
|
51
88
|
return (
|
|
52
89
|
<ChatBot
|
|
53
90
|
serviceId="your-service-id"
|
|
54
91
|
apiKey="your-api-key"
|
|
55
92
|
apiSecret="your-api-secret"
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
93
|
+
availableModels={customModels}
|
|
94
|
+
defaultModelIndex={1} // Default to Claude
|
|
95
|
+
showModelSelector={true}
|
|
96
|
+
onModelChange={(model) => {
|
|
97
|
+
console.log('Model changed to:', model.label);
|
|
98
|
+
}}
|
|
99
|
+
/>
|
|
100
|
+
);
|
|
101
|
+
}
|
|
102
|
+
```
|
|
103
|
+
|
|
104
|
+
### Advanced Configuration
|
|
105
|
+
|
|
106
|
+
```tsx
|
|
107
|
+
import { ChatBot, DEFAULT_AI_MODELS } from '@bytexbyte/nxtlinq-ai-agent-sdk';
|
|
108
|
+
|
|
109
|
+
function App() {
|
|
110
|
+
return (
|
|
111
|
+
<ChatBot
|
|
112
|
+
serviceId="your-service-id"
|
|
113
|
+
apiKey="your-api-key"
|
|
114
|
+
apiSecret="your-api-secret"
|
|
115
|
+
// AI Model configuration
|
|
116
|
+
availableModels={DEFAULT_AI_MODELS}
|
|
117
|
+
defaultModelIndex={0}
|
|
118
|
+
showModelSelector={true}
|
|
119
|
+
onModelChange={(model) => {
|
|
120
|
+
console.log('Model changed to:', model.label);
|
|
121
|
+
// Update user preferences
|
|
122
|
+
localStorage.setItem('preferred-model', model.value);
|
|
123
|
+
}}
|
|
124
|
+
// Preset messages
|
|
60
125
|
presetMessages={[
|
|
61
|
-
{ text:
|
|
62
|
-
{ text:
|
|
126
|
+
{ text: 'Hello, how can you help me?', autoSend: true },
|
|
127
|
+
{ text: 'I want to switch to a different AI model.', autoSend: false },
|
|
128
|
+
{ text: 'What are the differences between the available models?', autoSend: false }
|
|
63
129
|
]}
|
|
130
|
+
// Callback functions
|
|
131
|
+
onMessage={(message) => {
|
|
132
|
+
console.log('New message:', {
|
|
133
|
+
content: message.content,
|
|
134
|
+
role: message.role,
|
|
135
|
+
model: message.metadata?.model,
|
|
136
|
+
timestamp: message.timestamp
|
|
137
|
+
});
|
|
138
|
+
}}
|
|
139
|
+
onError={(error) => {
|
|
140
|
+
console.error('ChatBot error:', error);
|
|
141
|
+
// Add error reporting
|
|
142
|
+
errorReporting.captureException(error);
|
|
143
|
+
}}
|
|
144
|
+
onToolUse={async (toolUse) => {
|
|
145
|
+
console.log('Tool used:', toolUse);
|
|
146
|
+
// Handle tool calls
|
|
147
|
+
return {
|
|
148
|
+
id: Date.now().toString(),
|
|
149
|
+
content: 'Tool executed successfully',
|
|
150
|
+
role: 'assistant',
|
|
151
|
+
timestamp: new Date().toISOString()
|
|
152
|
+
};
|
|
153
|
+
}}
|
|
154
|
+
// Wallet verification
|
|
64
155
|
onVerifyWallet={async () => {
|
|
65
156
|
// Custom wallet verification logic
|
|
66
|
-
return { token:
|
|
157
|
+
return { token: 'your-token' };
|
|
67
158
|
}}
|
|
159
|
+
// Permission group
|
|
160
|
+
permissionGroup="default"
|
|
161
|
+
// UI configuration
|
|
162
|
+
placeholder="Type your message..."
|
|
163
|
+
className="custom-chatbot"
|
|
164
|
+
maxRetries={3}
|
|
165
|
+
retryDelay={1000}
|
|
68
166
|
/>
|
|
69
167
|
);
|
|
70
168
|
}
|
|
71
169
|
```
|
|
72
170
|
|
|
73
|
-
##
|
|
74
|
-
|
|
75
|
-
```
|
|
76
|
-
src/
|
|
77
|
-
├── components/ # React Components
|
|
78
|
-
│ ├── ChatBot.tsx # Main component entry
|
|
79
|
-
│ ├── context/ # Context and state management
|
|
80
|
-
│ │ └── ChatBotContext.tsx
|
|
81
|
-
│ ├── types/ # Type definitions
|
|
82
|
-
│ │ └── ChatBotTypes.ts
|
|
83
|
-
│ └── ui/ # UI Components
|
|
84
|
-
│ ├── ChatBotUI.tsx
|
|
85
|
-
│ ├── MessageList.tsx
|
|
86
|
-
│ ├── MessageInput.tsx
|
|
87
|
-
│ ├── PresetMessages.tsx
|
|
88
|
-
│ ├── PermissionForm.tsx
|
|
89
|
-
│ └── NotificationModal.tsx
|
|
90
|
-
├── api/ # API Layer
|
|
91
|
-
│ └── nxtlinq-api.ts # API Client
|
|
92
|
-
├── core/ # Core functionality
|
|
93
|
-
│ ├── metakeepClient.ts
|
|
94
|
-
│ ├── lib/ # Utility libraries
|
|
95
|
-
│ │ └── useLocalStorage.ts
|
|
96
|
-
│ └── utils/ # Utility functions
|
|
97
|
-
│ ├── walletUtils.ts
|
|
98
|
-
│ ├── aitUtils.ts
|
|
99
|
-
│ └── notificationUtils.ts
|
|
100
|
-
├── types/ # Global type definitions
|
|
101
|
-
│ ├── ait-api.ts
|
|
102
|
-
│ └── window.d.ts
|
|
103
|
-
└── index.ts # Main entry file
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
## 🔧 API Reference
|
|
171
|
+
## API Reference
|
|
107
172
|
|
|
108
173
|
### ChatBot Props
|
|
109
174
|
|
|
110
|
-
| Property | Type | Required | Description |
|
|
111
|
-
|
|
112
|
-
| `serviceId` | `string` | ✅ | Service ID |
|
|
113
|
-
| `apiKey` | `string` | ✅ | API Key |
|
|
114
|
-
| `apiSecret` | `string` | ✅ | API Secret |
|
|
115
|
-
| `
|
|
116
|
-
| `
|
|
117
|
-
| `
|
|
118
|
-
| `
|
|
119
|
-
| `
|
|
120
|
-
| `
|
|
121
|
-
| `
|
|
122
|
-
| `
|
|
123
|
-
| `
|
|
124
|
-
| `
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
175
|
+
| Property | Type | Default | Required | Description |
|
|
176
|
+
|----------|------|---------|----------|-------------|
|
|
177
|
+
| `serviceId` | `string` | - | ✅ | Service ID |
|
|
178
|
+
| `apiKey` | `string` | - | ✅ | API Key |
|
|
179
|
+
| `apiSecret` | `string` | - | ✅ | API Secret |
|
|
180
|
+
| `availableModels` | `AIModel[]` | `DEFAULT_AI_MODELS` | ❌ | Available AI models list |
|
|
181
|
+
| `defaultModelIndex` | `number` | `0` | ❌ | Default selected model index |
|
|
182
|
+
| `showModelSelector` | `boolean` | `true` | ❌ | Whether to show model selector |
|
|
183
|
+
| `onModelChange` | `(model: AIModel) => void` | - | ❌ | Model change callback |
|
|
184
|
+
| `presetMessages` | `PresetMessage[]` | `[]` | ❌ | Preset messages list |
|
|
185
|
+
| `placeholder` | `string` | `'Type a message...'` | ❌ | Input placeholder |
|
|
186
|
+
| `className` | `string` | `''` | ❌ | Custom CSS class name |
|
|
187
|
+
| `maxRetries` | `number` | `3` | ❌ | Maximum retry attempts |
|
|
188
|
+
| `retryDelay` | `number` | `1000` | ❌ | Retry delay (milliseconds) |
|
|
189
|
+
| `onMessage` | `(message: Message) => void` | - | ❌ | Message callback |
|
|
190
|
+
| `onError` | `(error: Error) => void` | - | ❌ | Error callback |
|
|
191
|
+
| `onToolUse` | `(toolUse: ToolUse) => Promise<Message \| void>` | - | ❌ | Tool use callback |
|
|
192
|
+
| `onVerifyWallet` | `() => Promise<{token: string} \| undefined>` | - | ❌ | Wallet verification callback |
|
|
193
|
+
| `permissionGroup` | `string` | - | ❌ | Permission group name |
|
|
194
|
+
|
|
195
|
+
### AIModel Type
|
|
196
|
+
|
|
197
|
+
```typescript
|
|
198
|
+
interface AIModel {
|
|
199
|
+
label: string; // Display name (e.g., "Nova", "Claude")
|
|
200
|
+
value: string; // Model identifier (e.g., "nova", "claude")
|
|
201
|
+
}
|
|
202
|
+
```
|
|
135
203
|
|
|
136
|
-
|
|
137
|
-
disconnectWallet();
|
|
204
|
+
### Default AI Models
|
|
138
205
|
|
|
139
|
-
|
|
140
|
-
const
|
|
206
|
+
```typescript
|
|
207
|
+
const DEFAULT_AI_MODELS = [
|
|
208
|
+
{ label: 'Nova', value: 'nova' },
|
|
209
|
+
{ label: 'Claude', value: 'claude' },
|
|
210
|
+
{ label: 'ChatGPT', value: 'open-ai' },
|
|
211
|
+
{ label: 'Llama', value: 'llama' },
|
|
212
|
+
{ label: 'Gemini', value: 'gemini' },
|
|
213
|
+
];
|
|
141
214
|
```
|
|
142
215
|
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
```
|
|
146
|
-
|
|
216
|
+
### Message Type with Model Metadata
|
|
217
|
+
|
|
218
|
+
```typescript
|
|
219
|
+
interface Message {
|
|
220
|
+
id: string;
|
|
221
|
+
content: string;
|
|
222
|
+
role: 'user' | 'assistant';
|
|
223
|
+
timestamp: string;
|
|
224
|
+
metadata?: {
|
|
225
|
+
model?: string; // AI model used
|
|
226
|
+
permissions?: string[]; // User permissions
|
|
227
|
+
issuedBy?: string; // Wallet address
|
|
228
|
+
toolUse?: { // Tool call information
|
|
229
|
+
name: string;
|
|
230
|
+
input: Record<string, any>;
|
|
231
|
+
};
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
```
|
|
147
235
|
|
|
148
|
-
|
|
149
|
-
const aitId = generateAITId(address);
|
|
236
|
+
## Component Usage
|
|
150
237
|
|
|
151
|
-
|
|
152
|
-
const metadata = createAITMetadata(permissions, address);
|
|
238
|
+
### Using Components Individually
|
|
153
239
|
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
240
|
+
```tsx
|
|
241
|
+
import {
|
|
242
|
+
ChatBotProvider,
|
|
243
|
+
ChatBotUI,
|
|
244
|
+
ModelSelector,
|
|
245
|
+
MessageList,
|
|
246
|
+
MessageInput
|
|
247
|
+
} from '@bytexbyte/nxtlinq-ai-agent-sdk';
|
|
248
|
+
|
|
249
|
+
function CustomChatBot() {
|
|
250
|
+
return (
|
|
251
|
+
<ChatBotProvider
|
|
252
|
+
serviceId="your-service-id"
|
|
253
|
+
apiKey="your-api-key"
|
|
254
|
+
apiSecret="your-api-secret"
|
|
255
|
+
>
|
|
256
|
+
<div className="custom-chatbot-container">
|
|
257
|
+
<ChatBotUI />
|
|
258
|
+
</div>
|
|
259
|
+
</ChatBotProvider>
|
|
260
|
+
);
|
|
261
|
+
}
|
|
160
262
|
```
|
|
161
263
|
|
|
162
|
-
|
|
264
|
+
### Custom Layout with Model Selector
|
|
163
265
|
|
|
164
266
|
```tsx
|
|
165
|
-
import {
|
|
267
|
+
import {
|
|
268
|
+
ChatBotProvider,
|
|
269
|
+
useChatBot,
|
|
270
|
+
ModelSelector,
|
|
271
|
+
MessageList,
|
|
272
|
+
MessageInput
|
|
273
|
+
} from '@bytexbyte/nxtlinq-ai-agent-sdk';
|
|
274
|
+
|
|
275
|
+
function CustomLayout() {
|
|
276
|
+
const { isOpen, setIsOpen } = useChatBot();
|
|
277
|
+
|
|
278
|
+
if (!isOpen) {
|
|
279
|
+
return (
|
|
280
|
+
<button onClick={() => setIsOpen(true)}>
|
|
281
|
+
Open AI Agent
|
|
282
|
+
</button>
|
|
283
|
+
);
|
|
284
|
+
}
|
|
166
285
|
|
|
167
|
-
|
|
168
|
-
|
|
286
|
+
return (
|
|
287
|
+
<div className="custom-layout">
|
|
288
|
+
<header>
|
|
289
|
+
<h3>AI Assistant</h3>
|
|
290
|
+
<ModelSelector />
|
|
291
|
+
<button onClick={() => setIsOpen(false)}>Close</button>
|
|
292
|
+
</header>
|
|
293
|
+
<MessageList />
|
|
294
|
+
<MessageInput />
|
|
295
|
+
</div>
|
|
296
|
+
);
|
|
297
|
+
}
|
|
169
298
|
|
|
170
|
-
|
|
171
|
-
|
|
299
|
+
function App() {
|
|
300
|
+
return (
|
|
301
|
+
<ChatBotProvider
|
|
302
|
+
serviceId="your-service-id"
|
|
303
|
+
apiKey="your-api-key"
|
|
304
|
+
apiSecret="your-api-secret"
|
|
305
|
+
>
|
|
306
|
+
<CustomLayout />
|
|
307
|
+
</ChatBotProvider>
|
|
308
|
+
);
|
|
309
|
+
}
|
|
172
310
|
```
|
|
173
311
|
|
|
174
|
-
##
|
|
312
|
+
## Style Customization
|
|
175
313
|
|
|
176
|
-
|
|
314
|
+
### CSS Classes
|
|
177
315
|
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
## 🎨 Custom Styling
|
|
316
|
+
```css
|
|
317
|
+
/* Main container */
|
|
318
|
+
.nxtlinq-chatbot-container {
|
|
319
|
+
/* Custom styles */
|
|
320
|
+
}
|
|
184
321
|
|
|
185
|
-
|
|
322
|
+
/* Message list */
|
|
323
|
+
.nxtlinq-message-list {
|
|
324
|
+
/* Custom styles */
|
|
325
|
+
}
|
|
186
326
|
|
|
187
|
-
|
|
188
|
-
.nxtlinq-
|
|
327
|
+
/* User message */
|
|
328
|
+
.nxtlinq-user-message {
|
|
189
329
|
/* Custom styles */
|
|
190
|
-
border-radius: 15px;
|
|
191
|
-
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.1);
|
|
192
330
|
}
|
|
193
|
-
```
|
|
194
331
|
|
|
195
|
-
|
|
332
|
+
/* AI message */
|
|
333
|
+
.nxtlinq-ai-message {
|
|
334
|
+
/* Custom styles */
|
|
335
|
+
}
|
|
196
336
|
|
|
197
|
-
|
|
337
|
+
/* Model selector */
|
|
338
|
+
.nxtlinq-model-selector {
|
|
339
|
+
/* Custom styles */
|
|
340
|
+
}
|
|
198
341
|
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
342
|
+
/* Model badge */
|
|
343
|
+
.nxtlinq-model-badge {
|
|
344
|
+
/* Custom styles */
|
|
345
|
+
}
|
|
346
|
+
```
|
|
202
347
|
|
|
203
|
-
|
|
204
|
-
- Ensure AIT permissions are correctly configured
|
|
205
|
-
- Check service ID and API keys
|
|
348
|
+
### Inline Style Override
|
|
206
349
|
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
350
|
+
```tsx
|
|
351
|
+
<ChatBot
|
|
352
|
+
serviceId="your-service-id"
|
|
353
|
+
apiKey="your-api-key"
|
|
354
|
+
apiSecret="your-api-secret"
|
|
355
|
+
className="my-custom-chatbot"
|
|
356
|
+
style={{
|
|
357
|
+
'--primary-color': '#007bff',
|
|
358
|
+
'--secondary-color': '#6c757d',
|
|
359
|
+
'--border-radius': '10px',
|
|
360
|
+
'--model-badge-bg': '#e3f2fd',
|
|
361
|
+
'--model-badge-color': '#1976d2'
|
|
362
|
+
}}
|
|
363
|
+
/>
|
|
364
|
+
```
|
|
210
365
|
|
|
211
|
-
|
|
366
|
+
## Event Handling
|
|
212
367
|
|
|
213
|
-
|
|
368
|
+
### Model Change Events
|
|
214
369
|
|
|
215
370
|
```tsx
|
|
216
371
|
<ChatBot
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
372
|
+
serviceId="your-service-id"
|
|
373
|
+
apiKey="your-api-key"
|
|
374
|
+
apiSecret="your-api-secret"
|
|
375
|
+
onModelChange={(model) => {
|
|
376
|
+
console.log('Model changed to:', model.label);
|
|
377
|
+
// Add analytics tracking
|
|
378
|
+
analytics.track('model_changed', {
|
|
379
|
+
model: model.value,
|
|
380
|
+
label: model.label,
|
|
381
|
+
timestamp: new Date().toISOString()
|
|
382
|
+
});
|
|
220
383
|
}}
|
|
221
384
|
/>
|
|
222
385
|
```
|
|
223
386
|
|
|
224
|
-
|
|
387
|
+
### Message Events with Model Information
|
|
225
388
|
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
389
|
+
```tsx
|
|
390
|
+
<ChatBot
|
|
391
|
+
serviceId="your-service-id"
|
|
392
|
+
apiKey="your-api-key"
|
|
393
|
+
apiSecret="your-api-secret"
|
|
394
|
+
onMessage={(message) => {
|
|
395
|
+
console.log('New message:', message);
|
|
396
|
+
// Track message with model info
|
|
397
|
+
if (message.role === 'user') {
|
|
398
|
+
analytics.track('user_message', {
|
|
399
|
+
content: message.content,
|
|
400
|
+
model: message.metadata?.model,
|
|
401
|
+
timestamp: message.timestamp
|
|
402
|
+
});
|
|
403
|
+
} else if (message.role === 'assistant') {
|
|
404
|
+
analytics.track('ai_response', {
|
|
405
|
+
model: message.metadata?.model,
|
|
406
|
+
hasToolUse: !!message.metadata?.toolUse,
|
|
407
|
+
timestamp: message.timestamp
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
}}
|
|
411
|
+
/>
|
|
412
|
+
```
|
|
229
413
|
|
|
230
|
-
|
|
414
|
+
## Error Handling
|
|
231
415
|
|
|
232
|
-
|
|
416
|
+
```tsx
|
|
417
|
+
<ChatBot
|
|
418
|
+
serviceId="your-service-id"
|
|
419
|
+
apiKey="your-api-key"
|
|
420
|
+
apiSecret="your-api-secret"
|
|
421
|
+
onError={(error) => {
|
|
422
|
+
console.error('ChatBot error:', error);
|
|
423
|
+
// Add error reporting
|
|
424
|
+
errorReporting.captureException(error);
|
|
425
|
+
|
|
426
|
+
// Track error with context
|
|
427
|
+
analytics.track('chatbot_error', {
|
|
428
|
+
error: error.message,
|
|
429
|
+
stack: error.stack,
|
|
430
|
+
timestamp: new Date().toISOString()
|
|
431
|
+
});
|
|
432
|
+
}}
|
|
433
|
+
/>
|
|
434
|
+
```
|
|
233
435
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
436
|
+
## Best Practices
|
|
437
|
+
|
|
438
|
+
### 1. Model Selection
|
|
439
|
+
- Choose appropriate AI models based on use cases
|
|
440
|
+
- Consider user preferences and requirements
|
|
441
|
+
- Monitor model performance and usage
|
|
442
|
+
|
|
443
|
+
### 2. Error Handling
|
|
444
|
+
- Always provide `onError` callback to handle errors
|
|
445
|
+
- Implement proper error reporting and monitoring
|
|
446
|
+
- Provide fallback mechanisms for failed requests
|
|
447
|
+
|
|
448
|
+
### 3. User Experience
|
|
449
|
+
- Use preset messages to guide users
|
|
450
|
+
- Provide clear model switching feedback
|
|
451
|
+
- Maintain conversation context across model switches
|
|
452
|
+
|
|
453
|
+
### 4. Performance Optimization
|
|
454
|
+
- Set reasonable retry counts and delays
|
|
455
|
+
- Implement proper loading states
|
|
456
|
+
- Optimize for different network conditions
|
|
457
|
+
|
|
458
|
+
### 5. Security
|
|
459
|
+
- Keep API keys secure and use environment variables
|
|
460
|
+
- Validate user permissions before tool calls
|
|
461
|
+
- Implement proper wallet verification
|
|
462
|
+
|
|
463
|
+
## Migration Guide
|
|
464
|
+
|
|
465
|
+
### From v1.2.3 to v1.2.4
|
|
466
|
+
|
|
467
|
+
1. **Update package version**:
|
|
468
|
+
```bash
|
|
469
|
+
npm install @bytexbyte/nxtlinq-ai-agent-sdk@1.2.4
|
|
470
|
+
```
|
|
471
|
+
|
|
472
|
+
2. **Add model switching props** (optional):
|
|
473
|
+
```tsx
|
|
474
|
+
<ChatBot
|
|
475
|
+
// ... existing props
|
|
476
|
+
showModelSelector={true}
|
|
477
|
+
onModelChange={(model) => console.log('Model:', model.label)}
|
|
478
|
+
/>
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
3. **Update message handling** (if needed):
|
|
482
|
+
```tsx
|
|
483
|
+
onMessage={(message) => {
|
|
484
|
+
// Now includes model information
|
|
485
|
+
console.log('Model used:', message.metadata?.model);
|
|
486
|
+
}}
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
## Changelog
|
|
490
|
+
|
|
491
|
+
### v1.2.4 (Latest)
|
|
492
|
+
- ✨ **NEW**: AI model switching functionality
|
|
493
|
+
- ✨ **NEW**: Support for 5 AI models (Nova, Claude, ChatGPT, Llama, Gemini)
|
|
494
|
+
- ✨ **NEW**: ModelSelector dropdown component
|
|
495
|
+
- ✨ **NEW**: Model badges in messages
|
|
496
|
+
- ✨ **NEW**: Persistent model preferences
|
|
497
|
+
- 🔧 **IMPROVED**: Enhanced API client with dynamic endpoints
|
|
498
|
+
- 🔧 **IMPROVED**: Better TypeScript types and interfaces
|
|
499
|
+
- 📚 **UPDATED**: Comprehensive documentation and examples
|
|
500
|
+
|
|
501
|
+
### v1.2.3
|
|
502
|
+
- Initial release with basic functionality
|
|
503
|
+
|
|
504
|
+
## Support
|
|
505
|
+
|
|
506
|
+
For questions, issues, or feature requests:
|
|
507
|
+
- 📧 Email: support@nxtlinq.ai
|
|
508
|
+
- 📖 Documentation: https://docs.nxtlinq.ai
|
|
509
|
+
- 🐛 Issues: https://github.com/bytexbyte/nxtlinq-ai-agent-sdk/issues
|
|
510
|
+
|
|
511
|
+
## License
|
|
512
|
+
|
|
513
|
+
MIT License - see [LICENSE](LICENSE) file for details.
|
|
@@ -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;AA6L1C,eAAO,MAAM,gBAAgB,GAAI,QAAQ,MAAM,EAAE,WAAW,MAAM,KAAG,MASpE,CAAC"}
|
package/dist/api/nxtlinq-api.js
CHANGED
|
@@ -71,12 +71,18 @@ const createAuthApi = (apiKey, apiSecret) => ({
|
|
|
71
71
|
const createAgentApi = () => ({
|
|
72
72
|
sendMessage: async (params) => {
|
|
73
73
|
try {
|
|
74
|
-
const
|
|
74
|
+
const model = params.model || 'nova';
|
|
75
|
+
const response = await fetch(`${AI_AGENT_API_HOST}/api/${model}`, {
|
|
75
76
|
method: 'POST',
|
|
76
77
|
headers: {
|
|
77
78
|
'Content-Type': 'application/json',
|
|
78
79
|
},
|
|
79
|
-
body: JSON.stringify(
|
|
80
|
+
body: JSON.stringify({
|
|
81
|
+
apiKey: params.apiKey,
|
|
82
|
+
apiSecret: params.apiSecret,
|
|
83
|
+
message: params.message,
|
|
84
|
+
context: params.context || []
|
|
85
|
+
}),
|
|
80
86
|
});
|
|
81
87
|
if (!response.ok) {
|
|
82
88
|
throw new Error('Failed to send message');
|