@aiqa/sdk 0.0.0 → 0.0.2
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 +118 -525
- package/dist/browser/browser.d.mts +2 -0
- package/dist/browser/browser.mjs +3398 -0
- package/dist/browser/browser.mjs.map +1 -0
- package/dist/node/node.d.mts +100 -0
- package/dist/node/node.mjs +302 -0
- package/dist/node/node.mjs.map +1 -0
- package/package.json +41 -10
- 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,10 +19,8 @@ A TypeScript/JavaScript SDK for interacting with the AIQA WebSocket service. Thi
|
|
|
19
19
|
|
|
20
20
|
## Installation
|
|
21
21
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
```html
|
|
25
|
-
<script src="https://cdn.socket.io/4.5.4/socket.io.min.js"></script>
|
|
22
|
+
```
|
|
23
|
+
npm install @aiqa/sdk
|
|
26
24
|
```
|
|
27
25
|
|
|
28
26
|
## Getting Started
|
|
@@ -30,16 +28,18 @@ The SDK can be used directly in your project. Make sure you have the SDK source
|
|
|
30
28
|
### Basic Setup
|
|
31
29
|
|
|
32
30
|
```typescript
|
|
33
|
-
import AiQaSdk from '
|
|
31
|
+
import AiQaSdk from '@aiqa/sdk';
|
|
34
32
|
|
|
35
33
|
// Initialize the SDK
|
|
36
|
-
const sdk = new AiQaSdk(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
34
|
+
const sdk = new AiQaSdk(
|
|
35
|
+
'app-id-123',
|
|
36
|
+
'app-secret-xyz',
|
|
37
|
+
'https://api.solutionson.ai/'
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
// Connect to the service, then attach listeners
|
|
41
|
+
sdk.connect();
|
|
41
42
|
|
|
42
|
-
// Set up event handlers
|
|
43
43
|
sdk.on('connect', () => {
|
|
44
44
|
console.log('Connected to AIQA service');
|
|
45
45
|
});
|
|
@@ -47,44 +47,14 @@ sdk.on('connect', () => {
|
|
|
47
47
|
sdk.on('error', (error) => {
|
|
48
48
|
console.error('Connection error:', error);
|
|
49
49
|
});
|
|
50
|
-
|
|
51
|
-
// Connect to the service
|
|
52
|
-
sdk.connect();
|
|
53
50
|
```
|
|
54
51
|
|
|
55
52
|
## Configuration
|
|
56
53
|
|
|
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
|
|
54
|
+
### SDK Initialization
|
|
82
55
|
|
|
83
56
|
```typescript
|
|
84
|
-
|
|
85
|
-
url: 'ws://api.solutionson.ai/',
|
|
86
|
-
enableLogging: true
|
|
87
|
-
});
|
|
57
|
+
new AiQaSdk(applicationId, applicationSecret, url?)
|
|
88
58
|
```
|
|
89
59
|
|
|
90
60
|
## API Reference
|
|
@@ -107,389 +77,106 @@ Closes the WebSocket connection.
|
|
|
107
77
|
sdk.disconnect();
|
|
108
78
|
```
|
|
109
79
|
|
|
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
|
-
```
|
|
80
|
+
### Application Management
|
|
123
81
|
|
|
124
|
-
#### `
|
|
82
|
+
#### `getApplication()`
|
|
125
83
|
|
|
126
|
-
|
|
84
|
+
Returns the cached application loaded during authentication.
|
|
85
|
+
If authentication hasn't completed yet, this throws. Use the `authenticated` event to know when it's ready.
|
|
127
86
|
|
|
128
87
|
```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
|
-
}
|
|
88
|
+
const application = await sdk.getApplication();
|
|
135
89
|
```
|
|
136
90
|
|
|
137
|
-
###
|
|
91
|
+
### Fact Management
|
|
138
92
|
|
|
139
|
-
#### `
|
|
93
|
+
#### `addFact(fact)`
|
|
140
94
|
|
|
141
|
-
|
|
95
|
+
Adds a fact to the active application (Promise-based).
|
|
142
96
|
|
|
143
97
|
**Parameters:**
|
|
144
|
-
- `
|
|
98
|
+
- `fact: ApplicationFactInput`
|
|
145
99
|
```typescript
|
|
146
100
|
{
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
101
|
+
id: string;
|
|
102
|
+
question: string;
|
|
103
|
+
expected_answer: any;
|
|
104
|
+
answer_format: { type: 'STRING' };
|
|
151
105
|
}
|
|
152
106
|
```
|
|
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
107
|
|
|
207
108
|
```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
|
-
}
|
|
109
|
+
const isMatched = await sdk.addFact({
|
|
110
|
+
id: 'fact-123',
|
|
111
|
+
question: 'Do you agree?',
|
|
112
|
+
expected_answer: 'Yes',
|
|
113
|
+
answer_format: { type: 'STRING' }
|
|
254
114
|
});
|
|
255
115
|
```
|
|
256
116
|
|
|
257
|
-
#### `
|
|
117
|
+
#### `getFacts()`
|
|
258
118
|
|
|
259
|
-
|
|
119
|
+
Retrieves all facts for the application (Promise-based).
|
|
260
120
|
|
|
261
121
|
```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
|
-
}
|
|
122
|
+
const facts = await sdk.getFacts();
|
|
322
123
|
```
|
|
323
124
|
|
|
324
125
|
### Recording Management
|
|
325
126
|
|
|
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()`
|
|
127
|
+
#### `startRecording()`
|
|
341
128
|
|
|
342
129
|
Starts audio recording (Promise-based).
|
|
343
130
|
|
|
344
131
|
```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
|
-
});
|
|
132
|
+
const started = await sdk.startRecording();
|
|
365
133
|
```
|
|
366
134
|
|
|
367
|
-
#### `
|
|
135
|
+
#### `stopRecording()`
|
|
368
136
|
|
|
369
137
|
Stops audio recording (Promise-based).
|
|
370
138
|
|
|
371
139
|
```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
|
-
}
|
|
140
|
+
const stopped = await sdk.stopRecording();
|
|
378
141
|
```
|
|
379
142
|
|
|
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()`
|
|
143
|
+
#### `isRecordingNow()`
|
|
395
144
|
|
|
396
145
|
Checks if recording is currently active (Promise-based).
|
|
397
146
|
|
|
398
147
|
```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
|
-
}
|
|
148
|
+
const isRecording = await sdk.isRecordingNow();
|
|
460
149
|
```
|
|
461
150
|
|
|
462
151
|
### Event Handling
|
|
463
152
|
|
|
464
153
|
#### `on(eventName, callback)`
|
|
465
154
|
|
|
466
|
-
Registers an event listener.
|
|
155
|
+
Registers an event listener. Call `connect()` before `on()`.
|
|
467
156
|
|
|
468
157
|
**Available Events:**
|
|
469
|
-
- `connect` -
|
|
470
|
-
- `disconnect` -
|
|
471
|
-
- `close` -
|
|
472
|
-
- `error` -
|
|
473
|
-
- `reconnect_attempt` -
|
|
474
|
-
- `reconnect_error` -
|
|
475
|
-
- `reconnect_failed` -
|
|
476
|
-
|
|
477
|
-
|
|
158
|
+
- `connect` - Socket.IO connection established
|
|
159
|
+
- `disconnect` - Socket.IO connection closed
|
|
160
|
+
- `close` - Socket.IO connection closed
|
|
161
|
+
- `error` - Connection or socket error
|
|
162
|
+
- `reconnect_attempt` - Socket.IO reconnection attempt
|
|
163
|
+
- `reconnect_error` - Socket.IO reconnection error
|
|
164
|
+
- `reconnect_failed` - Socket.IO reconnection failed
|
|
165
|
+
- `authenticated` - Local event fired after successful authentication (provides Application object)
|
|
166
|
+
- `app_version` - Server event with version requirements `{ min, max }`
|
|
167
|
+
|
|
478
168
|
```typescript
|
|
169
|
+
sdk.connect();
|
|
479
170
|
sdk.on('connect', () => {
|
|
480
|
-
console.log('Connected
|
|
171
|
+
console.log('Connected');
|
|
481
172
|
});
|
|
482
173
|
|
|
483
|
-
sdk.on('
|
|
484
|
-
console.log('
|
|
485
|
-
});
|
|
486
|
-
|
|
487
|
-
sdk.on('error', (error) => {
|
|
488
|
-
console.error('Error occurred:', error);
|
|
174
|
+
sdk.on('authenticated', (application) => {
|
|
175
|
+
console.log('Authenticated:', application);
|
|
489
176
|
});
|
|
490
177
|
```
|
|
491
178
|
|
|
492
|
-
#### `off(eventName)`
|
|
179
|
+
#### `off(eventName, callback?)`
|
|
493
180
|
|
|
494
181
|
Removes an event listener.
|
|
495
182
|
|
|
@@ -499,87 +186,58 @@ sdk.off('connect');
|
|
|
499
186
|
|
|
500
187
|
## Types
|
|
501
188
|
|
|
502
|
-
###
|
|
189
|
+
### Application
|
|
503
190
|
|
|
504
191
|
```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 = {
|
|
192
|
+
type Application = {
|
|
517
193
|
application_id: string;
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
insured_phone?: string;
|
|
524
|
-
client_name?: string;
|
|
525
|
-
utterances: TApplicationUtterance[];
|
|
526
|
-
facts: TApplicationFact[];
|
|
194
|
+
client_name: string;
|
|
195
|
+
client_phone_number: string;
|
|
196
|
+
agent_id: string;
|
|
197
|
+
agent_first_name: string;
|
|
198
|
+
agent_last_name: string;
|
|
527
199
|
}
|
|
528
200
|
```
|
|
529
201
|
|
|
530
|
-
###
|
|
202
|
+
### ApplicationFact
|
|
531
203
|
|
|
532
204
|
```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;
|
|
205
|
+
type ApplicationFact = ApplicationFactInput & {
|
|
206
|
+
ai_answer?: any;
|
|
207
|
+
question_status: 'searching' | 'asked' | 'not_asked';
|
|
208
|
+
verification_status: 'processing' | 'matched' | 'unmatched';
|
|
545
209
|
}
|
|
546
210
|
```
|
|
547
211
|
|
|
548
|
-
###
|
|
212
|
+
### ApplicationFactInput
|
|
549
213
|
|
|
550
214
|
```typescript
|
|
551
|
-
type
|
|
215
|
+
type ApplicationFactInput = {
|
|
552
216
|
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;
|
|
217
|
+
question: string;
|
|
218
|
+
expected_answer: any;
|
|
219
|
+
answer_format: {
|
|
220
|
+
type: 'STRING' | 'NUMBER' | 'INT' | 'FLOAT' | 'BOOL' | 'LIST' | 'STRICT' | 'SINGLE_CHOICE' | 'MULTIPLE_CHOICES';
|
|
221
|
+
choices?: { key: string; text: string }[];
|
|
566
222
|
};
|
|
567
|
-
|
|
223
|
+
category_id?: string;
|
|
224
|
+
category_name?: string;
|
|
225
|
+
language?: string;
|
|
226
|
+
critical?: boolean;
|
|
227
|
+
is_skipped?: boolean;
|
|
568
228
|
}
|
|
569
229
|
```
|
|
570
230
|
|
|
571
|
-
###
|
|
231
|
+
### FactUpdateEvent
|
|
572
232
|
|
|
573
233
|
```typescript
|
|
574
|
-
type
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
recordingIsActive?: boolean;
|
|
582
|
-
error?: Error;
|
|
234
|
+
type FactUpdateEvent = {
|
|
235
|
+
fact_id: string;
|
|
236
|
+
question_id?: string;
|
|
237
|
+
status: 'asked' | 'answered_detected' | 'agent_answered' | 'verification_pending' | 'verified' | 'failed';
|
|
238
|
+
detectedAnswer?: any;
|
|
239
|
+
agentAnswer?: any;
|
|
240
|
+
verifiedAnswer?: any;
|
|
583
241
|
}
|
|
584
242
|
```
|
|
585
243
|
|
|
@@ -588,51 +246,44 @@ type TResponse = {
|
|
|
588
246
|
### Complete Example: Recording Session
|
|
589
247
|
|
|
590
248
|
```typescript
|
|
591
|
-
import AiQaSdk from '
|
|
249
|
+
import AiQaSdk from '@aiqa/sdk';
|
|
592
250
|
|
|
593
251
|
// Initialize SDK
|
|
594
|
-
const sdk = new AiQaSdk(
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
252
|
+
const sdk = new AiQaSdk(
|
|
253
|
+
'application-id-123',
|
|
254
|
+
'application-secret-xyz',
|
|
255
|
+
'https://api.solutionson.ai/'
|
|
256
|
+
);
|
|
257
|
+
|
|
258
|
+
sdk.connect();
|
|
598
259
|
|
|
599
|
-
// Set up event handlers
|
|
600
260
|
sdk.on('connect', async () => {
|
|
601
261
|
console.log('Connected!');
|
|
602
|
-
|
|
262
|
+
|
|
603
263
|
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
|
-
|
|
264
|
+
const application = await sdk.getApplication();
|
|
265
|
+
console.log('Application loaded:', application.application_id);
|
|
266
|
+
|
|
617
267
|
// Start recording
|
|
618
|
-
await sdk.
|
|
268
|
+
await sdk.startRecording();
|
|
619
269
|
console.log('Recording started');
|
|
620
|
-
|
|
270
|
+
|
|
621
271
|
// Add a fact
|
|
622
|
-
const factMatched = await sdk.
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
272
|
+
const factMatched = await sdk.addFact({
|
|
273
|
+
id: 'q1',
|
|
274
|
+
question: 'What is your name?',
|
|
275
|
+
expected_answer: '',
|
|
276
|
+
answer_format: {
|
|
277
|
+
type: 'STRING'
|
|
278
|
+
}
|
|
628
279
|
});
|
|
629
|
-
|
|
280
|
+
|
|
630
281
|
console.log('Fact matched:', factMatched);
|
|
631
|
-
|
|
282
|
+
|
|
632
283
|
// Stop recording
|
|
633
|
-
await sdk.
|
|
284
|
+
await sdk.stopRecording();
|
|
634
285
|
console.log('Recording stopped');
|
|
635
|
-
|
|
286
|
+
|
|
636
287
|
} catch (error) {
|
|
637
288
|
console.error('Error:', error);
|
|
638
289
|
}
|
|
@@ -641,74 +292,17 @@ sdk.on('connect', async () => {
|
|
|
641
292
|
sdk.on('error', (error) => {
|
|
642
293
|
console.error('SDK Error:', error);
|
|
643
294
|
});
|
|
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
295
|
```
|
|
683
296
|
|
|
684
297
|
## Error Handling
|
|
685
298
|
|
|
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
|
|
299
|
+
All methods are Promise-based. Use `try/catch` for errors.
|
|
704
300
|
|
|
705
301
|
```typescript
|
|
706
302
|
try {
|
|
707
|
-
const application = await sdk.
|
|
708
|
-
// Handle success
|
|
303
|
+
const application = await sdk.getApplication();
|
|
709
304
|
console.log('Success:', application);
|
|
710
305
|
} catch (error) {
|
|
711
|
-
// Handle error
|
|
712
306
|
console.error('Error:', error);
|
|
713
307
|
}
|
|
714
308
|
```
|
|
@@ -717,14 +311,13 @@ try {
|
|
|
717
311
|
|
|
718
312
|
1. **Connection Errors**: Fired through the `error` event
|
|
719
313
|
2. **Version Mismatch**: Thrown when the server version is incompatible
|
|
720
|
-
3. **Invalid Data**: Returned
|
|
314
|
+
3. **Invalid Data**: Returned as rejected promises
|
|
721
315
|
4. **Network Issues**: Handled through reconnection events
|
|
722
316
|
|
|
723
317
|
## Version Requirements
|
|
724
318
|
|
|
725
|
-
The
|
|
319
|
+
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
320
|
|
|
727
321
|
## License
|
|
728
322
|
|
|
729
|
-
|
|
730
|
-
|
|
323
|
+
MIT
|