@aiqa/sdk 0.0.0 → 0.0.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/README.md +116 -525
- package/dist/aiqa-sdk.browser.js +3617 -0
- package/dist/package.json +45 -0
- package/dist/src/index.d.ts +29 -0
- package/dist/src/index.js +245 -0
- package/dist/src/types.d.ts +60 -0
- package/dist/src/types.js +26 -0
- package/package.json +26 -5
- package/.vscode/launch.json +0 -20
- package/build/sdk.js +0 -37
- package/index.js +0 -3
- package/jest.config.js +0 -7
- package/src/README.md +0 -729
- package/src/config.ts +0 -29
- package/src/enum.ts +0 -16
- package/src/index.ts +0 -428
- package/src/logger.ts +0 -37
- package/src/service/index.ts +0 -139
- package/src/types.ts +0 -164
- package/tests/index.test.ts +0 -534
- package/tests/server.ts +0 -22
- package/tsconfig.json +0 -11
- package/win_create_ssh.sh +0 -50
package/README.md
CHANGED
|
@@ -19,27 +19,25 @@ A TypeScript/JavaScript SDK for interacting with the AIQA WebSocket service. Thi
|
|
|
19
19
|
|
|
20
20
|
## Installation
|
|
21
21
|
|
|
22
|
-
The SDK can be used directly in your project.
|
|
23
|
-
|
|
24
|
-
```html
|
|
25
|
-
<script src="https://cdn.socket.io/4.5.4/socket.io.min.js"></script>
|
|
26
|
-
```
|
|
22
|
+
The SDK can be used directly in your project. The Socket.IO client is bundled with the SDK.
|
|
27
23
|
|
|
28
24
|
## Getting Started
|
|
29
25
|
|
|
30
26
|
### Basic Setup
|
|
31
27
|
|
|
32
28
|
```typescript
|
|
33
|
-
import AiQaSdk from '
|
|
29
|
+
import AiQaSdk from '@aiqa/sdk';
|
|
34
30
|
|
|
35
31
|
// Initialize the SDK
|
|
36
|
-
const sdk = new AiQaSdk(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
32
|
+
const sdk = new AiQaSdk(
|
|
33
|
+
'app-id-123',
|
|
34
|
+
'app-secret-xyz',
|
|
35
|
+
'https://api.solutionson.ai/'
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
// Connect to the service, then attach listeners
|
|
39
|
+
sdk.connect();
|
|
41
40
|
|
|
42
|
-
// Set up event handlers
|
|
43
41
|
sdk.on('connect', () => {
|
|
44
42
|
console.log('Connected to AIQA service');
|
|
45
43
|
});
|
|
@@ -47,44 +45,14 @@ sdk.on('connect', () => {
|
|
|
47
45
|
sdk.on('error', (error) => {
|
|
48
46
|
console.error('Connection error:', error);
|
|
49
47
|
});
|
|
50
|
-
|
|
51
|
-
// Connect to the service
|
|
52
|
-
sdk.connect();
|
|
53
48
|
```
|
|
54
49
|
|
|
55
50
|
## Configuration
|
|
56
51
|
|
|
57
|
-
###
|
|
58
|
-
|
|
59
|
-
```typescript
|
|
60
|
-
interface SDKConfig {
|
|
61
|
-
url?: string; // WebSocket server URL (default: 'ws://localhost:3025')
|
|
62
|
-
jwtToken?: string; // JWT token for authentication
|
|
63
|
-
path?: string; // WebSocket path (default: '/ws')
|
|
64
|
-
enableLogging?: boolean; // Enable/disable logging (default: true)
|
|
65
|
-
}
|
|
66
|
-
```
|
|
67
|
-
|
|
68
|
-
### Configuration Methods
|
|
69
|
-
|
|
70
|
-
#### Constructor Configuration
|
|
71
|
-
|
|
72
|
-
```typescript
|
|
73
|
-
const sdk = new AiQaSdk({
|
|
74
|
-
url: 'ws://api.solutionson.ai/',
|
|
75
|
-
jwtToken: 'your-jwt-token',
|
|
76
|
-
path: '/ws',
|
|
77
|
-
enableLogging: false
|
|
78
|
-
});
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
#### Runtime Configuration
|
|
52
|
+
### SDK Initialization
|
|
82
53
|
|
|
83
54
|
```typescript
|
|
84
|
-
|
|
85
|
-
url: 'ws://api.solutionson.ai/',
|
|
86
|
-
enableLogging: true
|
|
87
|
-
});
|
|
55
|
+
new AiQaSdk(applicationId, applicationSecret, url?)
|
|
88
56
|
```
|
|
89
57
|
|
|
90
58
|
## API Reference
|
|
@@ -107,389 +75,106 @@ Closes the WebSocket connection.
|
|
|
107
75
|
sdk.disconnect();
|
|
108
76
|
```
|
|
109
77
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
Checks if the WebSocket connection is alive (callback-based).
|
|
113
|
-
|
|
114
|
-
```typescript
|
|
115
|
-
sdk.isAlive(({ isAlive, error }) => {
|
|
116
|
-
if (error) {
|
|
117
|
-
console.error('Error checking connection:', error);
|
|
118
|
-
} else {
|
|
119
|
-
console.log('Connection is alive:', isAlive);
|
|
120
|
-
}
|
|
121
|
-
});
|
|
122
|
-
```
|
|
78
|
+
### Application Management
|
|
123
79
|
|
|
124
|
-
#### `
|
|
80
|
+
#### `getApplication()`
|
|
125
81
|
|
|
126
|
-
|
|
82
|
+
Returns the cached application loaded during authentication.
|
|
83
|
+
If authentication hasn't completed yet, this throws. Use the `authenticated` event to know when it's ready.
|
|
127
84
|
|
|
128
85
|
```typescript
|
|
129
|
-
|
|
130
|
-
const isAlive = await sdk.isAliveAsync();
|
|
131
|
-
console.log('Connection is alive:', isAlive);
|
|
132
|
-
} catch (error) {
|
|
133
|
-
console.error('Error checking connection:', error);
|
|
134
|
-
}
|
|
86
|
+
const application = await sdk.getApplication();
|
|
135
87
|
```
|
|
136
88
|
|
|
137
|
-
###
|
|
89
|
+
### Fact Management
|
|
138
90
|
|
|
139
|
-
#### `
|
|
91
|
+
#### `addFact(fact)`
|
|
140
92
|
|
|
141
|
-
|
|
93
|
+
Adds a fact to the active application (Promise-based).
|
|
142
94
|
|
|
143
95
|
**Parameters:**
|
|
144
|
-
- `
|
|
96
|
+
- `fact: ApplicationFactInput`
|
|
145
97
|
```typescript
|
|
146
98
|
{
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
99
|
+
id: string;
|
|
100
|
+
question: string;
|
|
101
|
+
expected_answer: any;
|
|
102
|
+
answer_format: { type: 'STRING' };
|
|
151
103
|
}
|
|
152
104
|
```
|
|
153
|
-
- `callback: (response: TResponse) => void`
|
|
154
|
-
|
|
155
|
-
**Example:**
|
|
156
|
-
```typescript
|
|
157
|
-
sdk.createApplication({
|
|
158
|
-
policyNumber: 'POL-12345',
|
|
159
|
-
product: 'Insurance Product',
|
|
160
|
-
insuredPhone: '+1234567890',
|
|
161
|
-
clientName: 'John Doe'
|
|
162
|
-
}, ({ application, error }) => {
|
|
163
|
-
if (error) {
|
|
164
|
-
console.error('Error creating application:', error);
|
|
165
|
-
} else {
|
|
166
|
-
console.log('Application created:', application);
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
```
|
|
170
|
-
|
|
171
|
-
#### `createApplicationAsync(data)`
|
|
172
|
-
|
|
173
|
-
Creates a new application (Promise-based).
|
|
174
|
-
|
|
175
|
-
```typescript
|
|
176
|
-
try {
|
|
177
|
-
const application = await sdk.createApplicationAsync({
|
|
178
|
-
policyNumber: 'POL-12345',
|
|
179
|
-
product: 'Insurance Product',
|
|
180
|
-
insuredPhone: '+1234567890',
|
|
181
|
-
clientName: 'John Doe'
|
|
182
|
-
});
|
|
183
|
-
console.log('Application created:', application);
|
|
184
|
-
} catch (error) {
|
|
185
|
-
console.error('Error creating application:', error);
|
|
186
|
-
}
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
#### `getApplication(id, callback)`
|
|
190
|
-
|
|
191
|
-
Retrieves an application by ID (callback-based).
|
|
192
|
-
|
|
193
|
-
```typescript
|
|
194
|
-
sdk.getApplication('app-id-123', ({ application, error }) => {
|
|
195
|
-
if (error) {
|
|
196
|
-
console.error('Error getting application:', error);
|
|
197
|
-
} else {
|
|
198
|
-
console.log('Application:', application);
|
|
199
|
-
}
|
|
200
|
-
});
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
#### `getApplicationAsync(id)`
|
|
204
|
-
|
|
205
|
-
Retrieves an application by ID (Promise-based).
|
|
206
105
|
|
|
207
106
|
```typescript
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
}
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
#### `updateApplication(id, referenceId, callback)`
|
|
217
|
-
|
|
218
|
-
Updates an application with a reference ID (callback-based).
|
|
219
|
-
|
|
220
|
-
```typescript
|
|
221
|
-
sdk.updateApplication('app-id-123', 'ref-456', ({ application, error }) => {
|
|
222
|
-
if (error) {
|
|
223
|
-
console.error('Error updating application:', error);
|
|
224
|
-
} else {
|
|
225
|
-
console.log('Application updated:', application);
|
|
226
|
-
}
|
|
227
|
-
});
|
|
228
|
-
```
|
|
229
|
-
|
|
230
|
-
#### `updateApplicationAsync(id, referenceId)`
|
|
231
|
-
|
|
232
|
-
Updates an application with a reference ID (Promise-based).
|
|
233
|
-
|
|
234
|
-
```typescript
|
|
235
|
-
try {
|
|
236
|
-
const application = await sdk.updateApplicationAsync('app-id-123', 'ref-456');
|
|
237
|
-
console.log('Application updated:', application);
|
|
238
|
-
} catch (error) {
|
|
239
|
-
console.error('Error updating application:', error);
|
|
240
|
-
}
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
#### `setActiveApplication(applicationId, callback)`
|
|
244
|
-
|
|
245
|
-
Sets an application as active (callback-based).
|
|
246
|
-
|
|
247
|
-
```typescript
|
|
248
|
-
sdk.setActiveApplication('app-id-123', ({ applicationIsActive, error }) => {
|
|
249
|
-
if (error) {
|
|
250
|
-
console.error('Error setting active application:', error);
|
|
251
|
-
} else {
|
|
252
|
-
console.log('Application is active:', applicationIsActive);
|
|
253
|
-
}
|
|
107
|
+
const isMatched = await sdk.addFact({
|
|
108
|
+
id: 'fact-123',
|
|
109
|
+
question: 'Do you agree?',
|
|
110
|
+
expected_answer: 'Yes',
|
|
111
|
+
answer_format: { type: 'STRING' }
|
|
254
112
|
});
|
|
255
113
|
```
|
|
256
114
|
|
|
257
|
-
#### `
|
|
115
|
+
#### `getFacts()`
|
|
258
116
|
|
|
259
|
-
|
|
117
|
+
Retrieves all facts for the application (Promise-based).
|
|
260
118
|
|
|
261
119
|
```typescript
|
|
262
|
-
|
|
263
|
-
const isActive = await sdk.setActiveApplicationAsync('app-id-123');
|
|
264
|
-
console.log('Application is active:', isActive);
|
|
265
|
-
} catch (error) {
|
|
266
|
-
console.error('Error setting active application:', error);
|
|
267
|
-
}
|
|
268
|
-
```
|
|
269
|
-
|
|
270
|
-
#### `getActiveApplication(callback)`
|
|
271
|
-
|
|
272
|
-
Gets the currently active application (callback-based).
|
|
273
|
-
|
|
274
|
-
```typescript
|
|
275
|
-
sdk.getActiveApplication(({ application, error }) => {
|
|
276
|
-
if (error) {
|
|
277
|
-
console.error('Error getting active application:', error);
|
|
278
|
-
} else {
|
|
279
|
-
console.log('Active application:', application);
|
|
280
|
-
}
|
|
281
|
-
});
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
#### `getActiveApplicationAsync()`
|
|
285
|
-
|
|
286
|
-
Gets the currently active application (Promise-based).
|
|
287
|
-
|
|
288
|
-
```typescript
|
|
289
|
-
try {
|
|
290
|
-
const application = await sdk.getActiveApplicationAsync();
|
|
291
|
-
console.log('Active application:', application);
|
|
292
|
-
} catch (error) {
|
|
293
|
-
console.error('Error getting active application:', error);
|
|
294
|
-
}
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
#### `resetActiveApplication(callback)`
|
|
298
|
-
|
|
299
|
-
Resets (deactivates) the active application (callback-based).
|
|
300
|
-
|
|
301
|
-
```typescript
|
|
302
|
-
sdk.resetActiveApplication(({ applicationIsActive, error }) => {
|
|
303
|
-
if (error) {
|
|
304
|
-
console.error('Error resetting active application:', error);
|
|
305
|
-
} else {
|
|
306
|
-
console.log('Application is active:', applicationIsActive);
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
```
|
|
310
|
-
|
|
311
|
-
#### `resetActiveApplicationAsync()`
|
|
312
|
-
|
|
313
|
-
Resets (deactivates) the active application (Promise-based).
|
|
314
|
-
|
|
315
|
-
```typescript
|
|
316
|
-
try {
|
|
317
|
-
const isActive = await sdk.resetActiveApplicationAsync();
|
|
318
|
-
console.log('Application is active:', isActive);
|
|
319
|
-
} catch (error) {
|
|
320
|
-
console.error('Error resetting active application:', error);
|
|
321
|
-
}
|
|
120
|
+
const facts = await sdk.getFacts();
|
|
322
121
|
```
|
|
323
122
|
|
|
324
123
|
### Recording Management
|
|
325
124
|
|
|
326
|
-
#### `startRecording(
|
|
327
|
-
|
|
328
|
-
Starts audio recording (callback-based).
|
|
329
|
-
|
|
330
|
-
```typescript
|
|
331
|
-
sdk.startRecording(({ recordingIsStarted, error }) => {
|
|
332
|
-
if (error) {
|
|
333
|
-
console.error('Error starting recording:', error);
|
|
334
|
-
} else {
|
|
335
|
-
console.log('Recording started:', recordingIsStarted);
|
|
336
|
-
}
|
|
337
|
-
});
|
|
338
|
-
```
|
|
339
|
-
|
|
340
|
-
#### `startRecordingAsync()`
|
|
125
|
+
#### `startRecording()`
|
|
341
126
|
|
|
342
127
|
Starts audio recording (Promise-based).
|
|
343
128
|
|
|
344
129
|
```typescript
|
|
345
|
-
|
|
346
|
-
const started = await sdk.startRecordingAsync();
|
|
347
|
-
console.log('Recording started:', started);
|
|
348
|
-
} catch (error) {
|
|
349
|
-
console.error('Error starting recording:', error);
|
|
350
|
-
}
|
|
351
|
-
```
|
|
352
|
-
|
|
353
|
-
#### `stopRecording(callback)`
|
|
354
|
-
|
|
355
|
-
Stops audio recording (callback-based).
|
|
356
|
-
|
|
357
|
-
```typescript
|
|
358
|
-
sdk.stopRecording(({ recordingIsStopped, error }) => {
|
|
359
|
-
if (error) {
|
|
360
|
-
console.error('Error stopping recording:', error);
|
|
361
|
-
} else {
|
|
362
|
-
console.log('Recording stopped:', recordingIsStopped);
|
|
363
|
-
}
|
|
364
|
-
});
|
|
130
|
+
const started = await sdk.startRecording();
|
|
365
131
|
```
|
|
366
132
|
|
|
367
|
-
#### `
|
|
133
|
+
#### `stopRecording()`
|
|
368
134
|
|
|
369
135
|
Stops audio recording (Promise-based).
|
|
370
136
|
|
|
371
137
|
```typescript
|
|
372
|
-
|
|
373
|
-
const stopped = await sdk.stopRecordingAsync();
|
|
374
|
-
console.log('Recording stopped:', stopped);
|
|
375
|
-
} catch (error) {
|
|
376
|
-
console.error('Error stopping recording:', error);
|
|
377
|
-
}
|
|
138
|
+
const stopped = await sdk.stopRecording();
|
|
378
139
|
```
|
|
379
140
|
|
|
380
|
-
#### `isRecordingNow(
|
|
381
|
-
|
|
382
|
-
Checks if recording is currently active (callback-based).
|
|
383
|
-
|
|
384
|
-
```typescript
|
|
385
|
-
sdk.isRecordingNow(({ recordingIsActive, error }) => {
|
|
386
|
-
if (error) {
|
|
387
|
-
console.error('Error checking recording status:', error);
|
|
388
|
-
} else {
|
|
389
|
-
console.log('Recording is active:', recordingIsActive);
|
|
390
|
-
}
|
|
391
|
-
});
|
|
392
|
-
```
|
|
393
|
-
|
|
394
|
-
#### `isRecordingNowAsync()`
|
|
141
|
+
#### `isRecordingNow()`
|
|
395
142
|
|
|
396
143
|
Checks if recording is currently active (Promise-based).
|
|
397
144
|
|
|
398
145
|
```typescript
|
|
399
|
-
|
|
400
|
-
const isRecording = await sdk.isRecordingNowAsync();
|
|
401
|
-
console.log('Recording is active:', isRecording);
|
|
402
|
-
} catch (error) {
|
|
403
|
-
console.error('Error checking recording status:', error);
|
|
404
|
-
}
|
|
405
|
-
```
|
|
406
|
-
|
|
407
|
-
### Fact Management
|
|
408
|
-
|
|
409
|
-
#### `addFact(fact, callback)`
|
|
410
|
-
|
|
411
|
-
Adds a fact to the active application (callback-based).
|
|
412
|
-
|
|
413
|
-
**Parameters:**
|
|
414
|
-
- `fact: TApplicationFactPayload`
|
|
415
|
-
```typescript
|
|
416
|
-
{
|
|
417
|
-
fact: {
|
|
418
|
-
id: string;
|
|
419
|
-
expected_answer: string;
|
|
420
|
-
};
|
|
421
|
-
applicationId: string;
|
|
422
|
-
}
|
|
423
|
-
```
|
|
424
|
-
- `callback: (response: TResponse) => void`
|
|
425
|
-
|
|
426
|
-
**Example:**
|
|
427
|
-
```typescript
|
|
428
|
-
sdk.addFact({
|
|
429
|
-
fact: {
|
|
430
|
-
id: 'fact-123',
|
|
431
|
-
expected_answer: 'Yes'
|
|
432
|
-
},
|
|
433
|
-
applicationId: 'app-id-123'
|
|
434
|
-
}, ({ factIsMatched, error }) => {
|
|
435
|
-
if (error) {
|
|
436
|
-
console.error('Error adding fact:', error);
|
|
437
|
-
} else {
|
|
438
|
-
console.log('Fact matched:', factIsMatched);
|
|
439
|
-
}
|
|
440
|
-
});
|
|
441
|
-
```
|
|
442
|
-
|
|
443
|
-
#### `addFactAsync(fact)`
|
|
444
|
-
|
|
445
|
-
Adds a fact to the active application (Promise-based).
|
|
446
|
-
|
|
447
|
-
```typescript
|
|
448
|
-
try {
|
|
449
|
-
const isMatched = await sdk.addFactAsync({
|
|
450
|
-
fact: {
|
|
451
|
-
id: 'fact-123',
|
|
452
|
-
expected_answer: 'Yes'
|
|
453
|
-
},
|
|
454
|
-
applicationId: 'app-id-123'
|
|
455
|
-
});
|
|
456
|
-
console.log('Fact matched:', isMatched);
|
|
457
|
-
} catch (error) {
|
|
458
|
-
console.error('Error adding fact:', error);
|
|
459
|
-
}
|
|
146
|
+
const isRecording = await sdk.isRecordingNow();
|
|
460
147
|
```
|
|
461
148
|
|
|
462
149
|
### Event Handling
|
|
463
150
|
|
|
464
151
|
#### `on(eventName, callback)`
|
|
465
152
|
|
|
466
|
-
Registers an event listener.
|
|
153
|
+
Registers an event listener. Call `connect()` before `on()`.
|
|
467
154
|
|
|
468
155
|
**Available Events:**
|
|
469
|
-
- `connect` -
|
|
470
|
-
- `disconnect` -
|
|
471
|
-
- `close` -
|
|
472
|
-
- `error` -
|
|
473
|
-
- `reconnect_attempt` -
|
|
474
|
-
- `reconnect_error` -
|
|
475
|
-
- `reconnect_failed` -
|
|
476
|
-
|
|
477
|
-
|
|
156
|
+
- `connect` - Socket.IO connection established
|
|
157
|
+
- `disconnect` - Socket.IO connection closed
|
|
158
|
+
- `close` - Socket.IO connection closed
|
|
159
|
+
- `error` - Connection or socket error
|
|
160
|
+
- `reconnect_attempt` - Socket.IO reconnection attempt
|
|
161
|
+
- `reconnect_error` - Socket.IO reconnection error
|
|
162
|
+
- `reconnect_failed` - Socket.IO reconnection failed
|
|
163
|
+
- `authenticated` - Local event fired after successful authentication (provides Application object)
|
|
164
|
+
- `app_version` - Server event with version requirements `{ min, max }`
|
|
165
|
+
|
|
478
166
|
```typescript
|
|
167
|
+
sdk.connect();
|
|
479
168
|
sdk.on('connect', () => {
|
|
480
|
-
console.log('Connected
|
|
169
|
+
console.log('Connected');
|
|
481
170
|
});
|
|
482
171
|
|
|
483
|
-
sdk.on('
|
|
484
|
-
console.log('
|
|
485
|
-
});
|
|
486
|
-
|
|
487
|
-
sdk.on('error', (error) => {
|
|
488
|
-
console.error('Error occurred:', error);
|
|
172
|
+
sdk.on('authenticated', (application) => {
|
|
173
|
+
console.log('Authenticated:', application);
|
|
489
174
|
});
|
|
490
175
|
```
|
|
491
176
|
|
|
492
|
-
#### `off(eventName)`
|
|
177
|
+
#### `off(eventName, callback?)`
|
|
493
178
|
|
|
494
179
|
Removes an event listener.
|
|
495
180
|
|
|
@@ -499,87 +184,58 @@ sdk.off('connect');
|
|
|
499
184
|
|
|
500
185
|
## Types
|
|
501
186
|
|
|
502
|
-
###
|
|
187
|
+
### Application
|
|
503
188
|
|
|
504
189
|
```typescript
|
|
505
|
-
type
|
|
506
|
-
policyNumber: string;
|
|
507
|
-
product: string;
|
|
508
|
-
insuredPhone: string;
|
|
509
|
-
clientName: string;
|
|
510
|
-
}
|
|
511
|
-
```
|
|
512
|
-
|
|
513
|
-
### TApplication
|
|
514
|
-
|
|
515
|
-
```typescript
|
|
516
|
-
type TApplication = {
|
|
190
|
+
type Application = {
|
|
517
191
|
application_id: string;
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
insured_phone?: string;
|
|
524
|
-
client_name?: string;
|
|
525
|
-
utterances: TApplicationUtterance[];
|
|
526
|
-
facts: TApplicationFact[];
|
|
192
|
+
client_name: string;
|
|
193
|
+
client_phone_number: string;
|
|
194
|
+
agent_id: string;
|
|
195
|
+
agent_first_name: string;
|
|
196
|
+
agent_last_name: string;
|
|
527
197
|
}
|
|
528
198
|
```
|
|
529
199
|
|
|
530
|
-
###
|
|
200
|
+
### ApplicationFact
|
|
531
201
|
|
|
532
202
|
```typescript
|
|
533
|
-
type
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
order?: number;
|
|
538
|
-
is_agent?: boolean;
|
|
539
|
-
speaker?: number;
|
|
540
|
-
text?: string;
|
|
541
|
-
text_en?: string;
|
|
542
|
-
start_time?: number;
|
|
543
|
-
end_time?: number;
|
|
544
|
-
extra?: any;
|
|
203
|
+
type ApplicationFact = ApplicationFactInput & {
|
|
204
|
+
ai_answer?: any;
|
|
205
|
+
question_status: 'searching' | 'asked' | 'not_asked';
|
|
206
|
+
verification_status: 'processing' | 'matched' | 'unmatched';
|
|
545
207
|
}
|
|
546
208
|
```
|
|
547
209
|
|
|
548
|
-
###
|
|
210
|
+
### ApplicationFactInput
|
|
549
211
|
|
|
550
212
|
```typescript
|
|
551
|
-
type
|
|
213
|
+
type ApplicationFactInput = {
|
|
552
214
|
id: string;
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
### TApplicationFactPayload
|
|
560
|
-
|
|
561
|
-
```typescript
|
|
562
|
-
type TApplicationFactPayload = {
|
|
563
|
-
fact: {
|
|
564
|
-
id: string;
|
|
565
|
-
expected_answer: string;
|
|
215
|
+
question: string;
|
|
216
|
+
expected_answer: any;
|
|
217
|
+
answer_format: {
|
|
218
|
+
type: 'STRING' | 'NUMBER' | 'INT' | 'FLOAT' | 'BOOL' | 'LIST' | 'STRICT' | 'SINGLE_CHOICE' | 'MULTIPLE_CHOICES';
|
|
219
|
+
choices?: { key: string; text: string }[];
|
|
566
220
|
};
|
|
567
|
-
|
|
221
|
+
category_id?: string;
|
|
222
|
+
category_name?: string;
|
|
223
|
+
language?: string;
|
|
224
|
+
critical?: boolean;
|
|
225
|
+
is_skipped?: boolean;
|
|
568
226
|
}
|
|
569
227
|
```
|
|
570
228
|
|
|
571
|
-
###
|
|
229
|
+
### FactUpdateEvent
|
|
572
230
|
|
|
573
231
|
```typescript
|
|
574
|
-
type
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
recordingIsActive?: boolean;
|
|
582
|
-
error?: Error;
|
|
232
|
+
type FactUpdateEvent = {
|
|
233
|
+
fact_id: string;
|
|
234
|
+
question_id?: string;
|
|
235
|
+
status: 'asked' | 'answered_detected' | 'agent_answered' | 'verification_pending' | 'verified' | 'failed';
|
|
236
|
+
detectedAnswer?: any;
|
|
237
|
+
agentAnswer?: any;
|
|
238
|
+
verifiedAnswer?: any;
|
|
583
239
|
}
|
|
584
240
|
```
|
|
585
241
|
|
|
@@ -588,51 +244,44 @@ type TResponse = {
|
|
|
588
244
|
### Complete Example: Recording Session
|
|
589
245
|
|
|
590
246
|
```typescript
|
|
591
|
-
import AiQaSdk from '
|
|
247
|
+
import AiQaSdk from '@aiqa/sdk';
|
|
592
248
|
|
|
593
249
|
// Initialize SDK
|
|
594
|
-
const sdk = new AiQaSdk(
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
250
|
+
const sdk = new AiQaSdk(
|
|
251
|
+
'application-id-123',
|
|
252
|
+
'application-secret-xyz',
|
|
253
|
+
'https://api.solutionson.ai/'
|
|
254
|
+
);
|
|
255
|
+
|
|
256
|
+
sdk.connect();
|
|
598
257
|
|
|
599
|
-
// Set up event handlers
|
|
600
258
|
sdk.on('connect', async () => {
|
|
601
259
|
console.log('Connected!');
|
|
602
|
-
|
|
260
|
+
|
|
603
261
|
try {
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
product: 'Life Insurance',
|
|
608
|
-
insuredPhone: '+1234567890',
|
|
609
|
-
clientName: 'John Doe'
|
|
610
|
-
});
|
|
611
|
-
|
|
612
|
-
console.log('Application created:', application.application_id);
|
|
613
|
-
|
|
614
|
-
// Set as active
|
|
615
|
-
await sdk.setActiveApplicationAsync(application.application_id);
|
|
616
|
-
|
|
262
|
+
const application = await sdk.getApplication();
|
|
263
|
+
console.log('Application loaded:', application.application_id);
|
|
264
|
+
|
|
617
265
|
// Start recording
|
|
618
|
-
await sdk.
|
|
266
|
+
await sdk.startRecording();
|
|
619
267
|
console.log('Recording started');
|
|
620
|
-
|
|
268
|
+
|
|
621
269
|
// Add a fact
|
|
622
|
-
const factMatched = await sdk.
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
270
|
+
const factMatched = await sdk.addFact({
|
|
271
|
+
id: 'q1',
|
|
272
|
+
question: 'What is your name?',
|
|
273
|
+
expected_answer: '',
|
|
274
|
+
answer_format: {
|
|
275
|
+
type: 'STRING'
|
|
276
|
+
}
|
|
628
277
|
});
|
|
629
|
-
|
|
278
|
+
|
|
630
279
|
console.log('Fact matched:', factMatched);
|
|
631
|
-
|
|
280
|
+
|
|
632
281
|
// Stop recording
|
|
633
|
-
await sdk.
|
|
282
|
+
await sdk.stopRecording();
|
|
634
283
|
console.log('Recording stopped');
|
|
635
|
-
|
|
284
|
+
|
|
636
285
|
} catch (error) {
|
|
637
286
|
console.error('Error:', error);
|
|
638
287
|
}
|
|
@@ -641,74 +290,17 @@ sdk.on('connect', async () => {
|
|
|
641
290
|
sdk.on('error', (error) => {
|
|
642
291
|
console.error('SDK Error:', error);
|
|
643
292
|
});
|
|
644
|
-
|
|
645
|
-
// Connect
|
|
646
|
-
sdk.connect();
|
|
647
|
-
```
|
|
648
|
-
|
|
649
|
-
### Example: Using Callbacks
|
|
650
|
-
|
|
651
|
-
```typescript
|
|
652
|
-
const sdk = new AiQaSdk({
|
|
653
|
-
url: 'ws://localhost:3025'
|
|
654
|
-
});
|
|
655
|
-
|
|
656
|
-
sdk.on('connect', () => {
|
|
657
|
-
// Create application with callback
|
|
658
|
-
sdk.createApplication({
|
|
659
|
-
policyNumber: 'POL-12345',
|
|
660
|
-
product: 'Insurance',
|
|
661
|
-
insuredPhone: '+1234567890',
|
|
662
|
-
clientName: 'Jane Doe'
|
|
663
|
-
}, ({ application, error }) => {
|
|
664
|
-
if (error) {
|
|
665
|
-
console.error('Error:', error);
|
|
666
|
-
return;
|
|
667
|
-
}
|
|
668
|
-
|
|
669
|
-
// Set as active
|
|
670
|
-
sdk.setActiveApplication(application.application_id, ({ applicationIsActive, error }) => {
|
|
671
|
-
if (error) {
|
|
672
|
-
console.error('Error:', error);
|
|
673
|
-
return;
|
|
674
|
-
}
|
|
675
|
-
|
|
676
|
-
console.log('Application is active:', applicationIsActive);
|
|
677
|
-
});
|
|
678
|
-
});
|
|
679
|
-
});
|
|
680
|
-
|
|
681
|
-
sdk.connect();
|
|
682
293
|
```
|
|
683
294
|
|
|
684
295
|
## Error Handling
|
|
685
296
|
|
|
686
|
-
All methods
|
|
687
|
-
|
|
688
|
-
### Callback-based Error Handling
|
|
689
|
-
|
|
690
|
-
```typescript
|
|
691
|
-
sdk.createApplication(data, ({ application, error }) => {
|
|
692
|
-
if (error) {
|
|
693
|
-
// Handle error
|
|
694
|
-
console.error('Error:', error);
|
|
695
|
-
return;
|
|
696
|
-
}
|
|
697
|
-
|
|
698
|
-
// Handle success
|
|
699
|
-
console.log('Success:', application);
|
|
700
|
-
});
|
|
701
|
-
```
|
|
702
|
-
|
|
703
|
-
### Promise-based Error Handling
|
|
297
|
+
All methods are Promise-based. Use `try/catch` for errors.
|
|
704
298
|
|
|
705
299
|
```typescript
|
|
706
300
|
try {
|
|
707
|
-
const application = await sdk.
|
|
708
|
-
// Handle success
|
|
301
|
+
const application = await sdk.getApplication();
|
|
709
302
|
console.log('Success:', application);
|
|
710
303
|
} catch (error) {
|
|
711
|
-
// Handle error
|
|
712
304
|
console.error('Error:', error);
|
|
713
305
|
}
|
|
714
306
|
```
|
|
@@ -717,14 +309,13 @@ try {
|
|
|
717
309
|
|
|
718
310
|
1. **Connection Errors**: Fired through the `error` event
|
|
719
311
|
2. **Version Mismatch**: Thrown when the server version is incompatible
|
|
720
|
-
3. **Invalid Data**: Returned
|
|
312
|
+
3. **Invalid Data**: Returned as rejected promises
|
|
721
313
|
4. **Network Issues**: Handled through reconnection events
|
|
722
314
|
|
|
723
315
|
## Version Requirements
|
|
724
316
|
|
|
725
|
-
The
|
|
317
|
+
The server emits an `app_version` payload with `{ min, max }` supported SDK versions. If the current SDK version is outside that range, the SDK disconnects and emits an `error` event.
|
|
726
318
|
|
|
727
319
|
## License
|
|
728
320
|
|
|
729
321
|
[Add your license information here]
|
|
730
|
-
|