echo-ai-sdk-ts 2.7.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +842 -666
- package/dist/chunk-NZO6ZQRY.mjs +2092 -0
- package/dist/fileFromPath-4L47H5QG.mjs +127 -0
- package/dist/index.d.mts +1073 -0
- package/dist/index.d.ts +1073 -0
- package/dist/index.js +7168 -834
- package/dist/index.mjs +7110 -834
- package/package.json +72 -60
package/README.md
CHANGED
|
@@ -1,666 +1,842 @@
|
|
|
1
|
-
# Echo AI SDK
|
|
2
|
-
|
|
3
|
-
The all-in-one AI platform for chat, voice, agents, and **embeddable customer support chatbots**.
|
|
4
|
-
|
|
5
|
-

|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
await bot.knowledgeBase.
|
|
86
|
-
await bot.knowledgeBase.
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
#### 📊
|
|
90
|
-
Track
|
|
91
|
-
```typescript
|
|
92
|
-
const stats = bot.analytics.getSnapshot();
|
|
93
|
-
console.log(`
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
```
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
const
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
```
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
const
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
});
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
const
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
```
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
const
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
}
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
|
624
|
-
|
|
625
|
-
| `
|
|
626
|
-
| `
|
|
627
|
-
| `
|
|
628
|
-
| `
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
|
660
|
-
|
|
661
|
-
|
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
1
|
+
# Echo AI SDK
|
|
2
|
+
|
|
3
|
+
The all-in-one AI platform for chat, voice, agents, and **embeddable customer support chatbots**.
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+
|
|
9
|
+
## CI/CD Status
|
|
10
|
+
|
|
11
|
+
### Build & Test
|
|
12
|
+

|
|
13
|
+

|
|
14
|
+

|
|
15
|
+
|
|
16
|
+
### Quality & Security
|
|
17
|
+

|
|
18
|
+

|
|
19
|
+

|
|
20
|
+
|
|
21
|
+
### Release & Publishing
|
|
22
|
+

|
|
23
|
+

|
|
24
|
+

|
|
25
|
+
|
|
26
|
+
### Code Quality
|
|
27
|
+

|
|
28
|
+

|
|
29
|
+

|
|
30
|
+
|
|
31
|
+
### Performance
|
|
32
|
+

|
|
33
|
+

|
|
34
|
+
|
|
35
|
+
## 🚀 Deploy an AI Chatbot on Your Website in 5 Minutes
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm install echo-ai-sdk zod openai express cors
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Step 1: Create Your Server (3 lines)
|
|
42
|
+
|
|
43
|
+
```typescript
|
|
44
|
+
import { startChatServer, AIModelGateway, OpenAIProvider } from "echo-ai-sdk";
|
|
45
|
+
|
|
46
|
+
startChatServer({
|
|
47
|
+
gateway: new AIModelGateway([new OpenAIProvider(process.env.OPENAI_API_KEY!)]),
|
|
48
|
+
companyName: "Acme Inc",
|
|
49
|
+
companyDescription: "We sell premium widgets and gadgets.",
|
|
50
|
+
apiConnector: { // Optional: connect to your website API
|
|
51
|
+
baseUrl: "https://api.acme.com/v1",
|
|
52
|
+
authToken: process.env.API_TOKEN
|
|
53
|
+
},
|
|
54
|
+
port: 3456
|
|
55
|
+
});
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
### Step 2: Embed the Widget on Your Website (1 line)
|
|
59
|
+
|
|
60
|
+
```typescript
|
|
61
|
+
import { ChatWidget } from "echo-ai-sdk";
|
|
62
|
+
|
|
63
|
+
const embedCode = ChatWidget.generate({
|
|
64
|
+
serverEndpoint: "https://your-server.com",
|
|
65
|
+
title: "Acme Support",
|
|
66
|
+
subtitle: "We reply instantly ⚡",
|
|
67
|
+
enableVoice: true, // Enable microphone input
|
|
68
|
+
theme: {
|
|
69
|
+
primaryColor: "#6366f1",
|
|
70
|
+
position: "bottom-right"
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// Paste `embedCode` into your HTML, or serve it dynamically
|
|
75
|
+
console.log(embedCode);
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
### Step 3: Done! 🎉
|
|
79
|
+
|
|
80
|
+
Your website now has a fully functional AI chatbot with **Tier 1 Enterprise Features**:
|
|
81
|
+
|
|
82
|
+
#### 🧠 RAG Knowledge Base (Eliminate Hallucinations)
|
|
83
|
+
Ground your AI in your own data (PDFs, URLs, text).
|
|
84
|
+
```typescript
|
|
85
|
+
await bot.knowledgeBase.ingestURL("https://acme.com/shipping-policy");
|
|
86
|
+
await bot.knowledgeBase.ingestText("Our warranty lasts 2 years...");
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
#### 📊 Conversation Analytics
|
|
90
|
+
Track resolution rates, CSAT, token costs, and response times.
|
|
91
|
+
```typescript
|
|
92
|
+
const stats = bot.analytics.getSnapshot();
|
|
93
|
+
console.log(`Resolution Rate: ${stats.resolutionRate * 100}%`);
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
#### 🤝 Human Handoff
|
|
97
|
+
Auto-escalate to human agents when the bot detects frustration or explicit requests.
|
|
98
|
+
```typescript
|
|
99
|
+
const bot = new CustomerSupportBot({
|
|
100
|
+
handoff: {
|
|
101
|
+
webhookUrl: "https://your-helpdesk.com/handoff",
|
|
102
|
+
webhookSecret: "secure_token_123"
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
```
|
|
106
|
+
|
|
107
|
+
### 🌟 Tier 1 Perfection Features
|
|
108
|
+
|
|
109
|
+
#### 🧠 RAG Persistence
|
|
110
|
+
Ground your bot in your data and keep it there across restarts.
|
|
111
|
+
```typescript
|
|
112
|
+
await bot.knowledgeBase.ingestText("Your knowledge text here...");
|
|
113
|
+
await bot.knowledgeBase.save("./knowledge-base.json"); // Save to disk
|
|
114
|
+
await bot.knowledgeBase.load("./knowledge-base.json"); // Load back
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
#### 📊 High-Precision Analytics & Cost Control
|
|
118
|
+
Track every penny with accurate token estimation and pricing maps.
|
|
119
|
+
```typescript
|
|
120
|
+
const stats = bot.analytics.getSnapshot();
|
|
121
|
+
console.log(`Total Cost: $${stats.totalCostUsd}`);
|
|
122
|
+
console.log(`Handoff Rate: ${stats.handoffRate * 100}%`);
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
#### 🤝 Sentiment-Aware Human Handoff
|
|
126
|
+
Detect frustration before it's too late. The bot tracks "negative strikes" and auto-summarizes problems for human agents.
|
|
127
|
+
```typescript
|
|
128
|
+
const bot = new CustomerSupportBot({
|
|
129
|
+
handoff: {
|
|
130
|
+
webhookUrl: "https://your-helpdesk.com/webhook",
|
|
131
|
+
negativeSentimentThreshold: 3, // Escalates after 3 angry turns
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
#### 🔌 Middleware API
|
|
137
|
+
Hook into every chat turn to add custom logic, logging, or transformations.
|
|
138
|
+
```typescript
|
|
139
|
+
bot.use(async ({ sessionId, message }) => {
|
|
140
|
+
console.log(`[Turn] ${sessionId}: ${message}`);
|
|
141
|
+
});
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
### 🚀 Tier 2 Pro-Grade Features
|
|
146
|
+
|
|
147
|
+
#### 🌐 Omnichannel Sync
|
|
148
|
+
Connect your bot to Slack and Telegram while maintaining a single user context.
|
|
149
|
+
```typescript
|
|
150
|
+
import { TelegramAdapter, SlackAdapter } from "echo-ai-sdk";
|
|
151
|
+
|
|
152
|
+
const tg = new TelegramAdapter({ bot, token: "TG_TOKEN" });
|
|
153
|
+
await tg.start();
|
|
154
|
+
|
|
155
|
+
const slack = new SlackAdapter({ bot, signingSecret: "...", token: "..." });
|
|
156
|
+
await slack.start();
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
#### 💾 Persistent Session Store
|
|
160
|
+
Move beyond memory. Use `FileSessionStore` for local persistence or implement `SessionStore` for Redis.
|
|
161
|
+
```typescript
|
|
162
|
+
import { FileSessionStore } from "echo-ai-sdk";
|
|
163
|
+
const bot = new CustomerSupportBot({
|
|
164
|
+
sessionStore: new FileSessionStore("./sessions"),
|
|
165
|
+
});
|
|
166
|
+
```
|
|
167
|
+
|
|
168
|
+
#### 🧠 Honcho Memory — Semantic, Reasoning-Based Agent Memory
|
|
169
|
+
Replace simple in-memory chat history with [Honcho's](https://honcho.dev) production-grade memory system. Your agents gain **cross-session context**, **semantic search**, **entity understanding**, and **continual learning** — all as a drop-in `BaseMemoryStore`.
|
|
170
|
+
|
|
171
|
+
```typescript
|
|
172
|
+
import { HonchoMemoryStore, AgentExecutor } from "echo-ai-sdk";
|
|
173
|
+
|
|
174
|
+
// Drop-in replacement for InMemoryStore
|
|
175
|
+
const memory = new HonchoMemoryStore({
|
|
176
|
+
apiKey: process.env.HONCHO_API_KEY,
|
|
177
|
+
workspaceId: "my-app",
|
|
178
|
+
});
|
|
179
|
+
|
|
180
|
+
const agent = new AgentExecutor({ gateway, memory, tools });
|
|
181
|
+
|
|
182
|
+
// Agents now automatically persist and recall context across sessions!
|
|
183
|
+
```
|
|
184
|
+
|
|
185
|
+
**Semantic Search** — Find memories by meaning, not keywords:
|
|
186
|
+
```typescript
|
|
187
|
+
const results = await memory.searchMemory("user", "coding preferences", {
|
|
188
|
+
topK: 5,
|
|
189
|
+
maxDistance: 0.7,
|
|
190
|
+
});
|
|
191
|
+
// → Synthesized conclusions like "User prefers TypeScript with functional patterns"
|
|
192
|
+
```
|
|
193
|
+
|
|
194
|
+
**Peer Insights** — Ask Honcho what it knows about a user:
|
|
195
|
+
```typescript
|
|
196
|
+
const insight = await memory.getInsights("user", "What motivates this user?");
|
|
197
|
+
// → "The user is motivated by building AI products that help people..."
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
**Unified Semantic Search** — Combine Honcho reasoning with local vector stores:
|
|
201
|
+
```typescript
|
|
202
|
+
import { SemanticMemorySearch, HonchoMemoryStore } from "echo-ai-sdk";
|
|
203
|
+
|
|
204
|
+
const search = new SemanticMemorySearch(honchoStore, optionalVectorStore);
|
|
205
|
+
const results = await search.search("user", "project architecture");
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
#### 📈 Outcome-Based Billing & ROI
|
|
209
|
+
Track the *real value* of your AI by recording business outcomes.
|
|
210
|
+
```typescript
|
|
211
|
+
// Inside a tool or middleware
|
|
212
|
+
bot.trackOutcome(sessionId, "lead_captured", 50.0);
|
|
213
|
+
|
|
214
|
+
const stats = bot.analytics.getSnapshot();
|
|
215
|
+
console.log(`ROI: ${stats.roi * 100}%`);
|
|
216
|
+
console.log(`Value Generated: $${stats.totalValueGeneratedUsd}`);
|
|
217
|
+
```
|
|
218
|
+
|
|
219
|
+
---
|
|
220
|
+
|
|
221
|
+
### 🚀 Tier 3 Advanced Agent Capabilities
|
|
222
|
+
|
|
223
|
+
#### 🤖 Advanced Reasoning Agents
|
|
224
|
+
Go beyond simple tool execution with sophisticated reasoning patterns:
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
import { ReActAgent, CoTAgent, ToTAgent } from "echo-ai-sdk";
|
|
228
|
+
|
|
229
|
+
// ReAct with Reflection - Thinks before acting
|
|
230
|
+
const reactAgent = new ReActAgent({
|
|
231
|
+
gateway,
|
|
232
|
+
memory,
|
|
233
|
+
tools: [searchTool, calculatorTool],
|
|
234
|
+
reactOptions: {
|
|
235
|
+
enableReflection: true,
|
|
236
|
+
confidenceThreshold: 0.8
|
|
237
|
+
}
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
// Chain of Thought - Step-by-step reasoning
|
|
241
|
+
const cotAgent = new CoTAgent({
|
|
242
|
+
gateway,
|
|
243
|
+
memory,
|
|
244
|
+
tools: [analysisTool],
|
|
245
|
+
cotOptions: {
|
|
246
|
+
maxSteps: 10,
|
|
247
|
+
requireConclusions: true
|
|
248
|
+
}
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
// Tree of Thoughts - Explores multiple solution paths
|
|
252
|
+
const totAgent = new ToTAgent({
|
|
253
|
+
gateway,
|
|
254
|
+
memory,
|
|
255
|
+
tools: [creativeTool],
|
|
256
|
+
totOptions: {
|
|
257
|
+
maxDepth: 4,
|
|
258
|
+
breadth: 3,
|
|
259
|
+
evaluationMethod: "score"
|
|
260
|
+
}
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
// Stream reasoning process
|
|
264
|
+
for await (const event of reactAgent.executeStream(sessionId, task)) {
|
|
265
|
+
console.log(`${event.type}: ${event.content}`);
|
|
266
|
+
}
|
|
267
|
+
```
|
|
268
|
+
|
|
269
|
+
#### ⚡ Enhanced Parallel Execution
|
|
270
|
+
Execute tools simultaneously with dependency resolution:
|
|
271
|
+
|
|
272
|
+
```typescript
|
|
273
|
+
import { EnhancedAgentExecutor, ToolDependency } from "echo-ai-sdk";
|
|
274
|
+
|
|
275
|
+
const executor = new EnhancedAgentExecutor({
|
|
276
|
+
gateway,
|
|
277
|
+
memory,
|
|
278
|
+
tools: [searchTool, weatherTool, calculatorTool],
|
|
279
|
+
toolDependencies: [
|
|
280
|
+
{ toolName: "weather", dependsOn: ["search"] } // Weather needs search results first
|
|
281
|
+
],
|
|
282
|
+
executionOptions: {
|
|
283
|
+
enableParallel: true,
|
|
284
|
+
maxParallelTools: 5,
|
|
285
|
+
toolTimeout: 10000,
|
|
286
|
+
streamToolResults: true
|
|
287
|
+
}
|
|
288
|
+
});
|
|
289
|
+
|
|
290
|
+
// Tools execute in parallel when possible
|
|
291
|
+
const result = await executor.execute(sessionId, complexTask);
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
#### 🔄 Multi-Agent Collaboration
|
|
295
|
+
Coordinate multiple agents for complex workflows:
|
|
296
|
+
|
|
297
|
+
```typescript
|
|
298
|
+
import { AgentTeam, AgentOrchestrator, DynamicAgentSelector } from "echo-ai-sdk";
|
|
299
|
+
|
|
300
|
+
// Create an agent team
|
|
301
|
+
const team = new AgentTeam({
|
|
302
|
+
name: "ResearchTeam",
|
|
303
|
+
loadBalancingStrategy: "capability_based",
|
|
304
|
+
communicationProtocol: "direct"
|
|
305
|
+
}, memory);
|
|
306
|
+
|
|
307
|
+
// Register specialized agents
|
|
308
|
+
team.registerAgent({
|
|
309
|
+
id: "researcher",
|
|
310
|
+
name: "Research Specialist",
|
|
311
|
+
capabilities: [{
|
|
312
|
+
name: "research",
|
|
313
|
+
tools: ["search"],
|
|
314
|
+
reasoningPatterns: ["react"],
|
|
315
|
+
specialties: ["academic_research"]
|
|
316
|
+
}],
|
|
317
|
+
status: "active",
|
|
318
|
+
currentLoad: 0,
|
|
319
|
+
maxConcurrentTasks: 3
|
|
320
|
+
});
|
|
321
|
+
|
|
322
|
+
// Delegate tasks to best agent
|
|
323
|
+
const taskId = await team.delegateTask("coordinator", {
|
|
324
|
+
query: "Latest AI research papers",
|
|
325
|
+
analysis: "summarize"
|
|
326
|
+
}, {
|
|
327
|
+
capabilities: ["research"],
|
|
328
|
+
maxResponseTime: 5000
|
|
329
|
+
});
|
|
330
|
+
|
|
331
|
+
// Orchestrate complex workflows
|
|
332
|
+
const orchestrator = new AgentOrchestrator({}, memory);
|
|
333
|
+
const workflow = {
|
|
334
|
+
id: "research_pipeline",
|
|
335
|
+
steps: [
|
|
336
|
+
{ id: "collect", requiredCapabilities: ["research"] },
|
|
337
|
+
{ id: "analyze", requiredCapabilities: ["analysis"] },
|
|
338
|
+
{ id: "summarize", requiredCapabilities: ["summarization"] }
|
|
339
|
+
],
|
|
340
|
+
orchestrationPattern: "sequential"
|
|
341
|
+
};
|
|
342
|
+
|
|
343
|
+
const executionId = await orchestrator.executeWorkflow(
|
|
344
|
+
workflow.id,
|
|
345
|
+
{ topic: "quantum computing" }
|
|
346
|
+
);
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
#### 🎯 Dynamic Agent Selection
|
|
350
|
+
Automatically select the best agent based on capabilities, performance, and cost:
|
|
351
|
+
|
|
352
|
+
```typescript
|
|
353
|
+
const selector = new DynamicAgentSelector();
|
|
354
|
+
|
|
355
|
+
// Select best agent for task
|
|
356
|
+
const selection = selector.selectAgent(agents, {
|
|
357
|
+
requiredCapabilities: ["analysis", "computation"],
|
|
358
|
+
maxResponseTime: 3000,
|
|
359
|
+
costLimit: 0.10,
|
|
360
|
+
priority: "high"
|
|
361
|
+
}, "performance_first");
|
|
362
|
+
|
|
363
|
+
console.log(`Selected: ${selection.agentId} (score: ${selection.score})`);
|
|
364
|
+
console.log(`Reasoning: ${selection.reasoning}`);
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
---
|
|
368
|
+
|
|
369
|
+
## Installation
|
|
370
|
+
|
|
371
|
+
```sh
|
|
372
|
+
npm install echo-ai-sdk zod
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
You'll need the respective provider SDKs if you wish to utilize them:
|
|
376
|
+
|
|
377
|
+
```sh
|
|
378
|
+
npm install openai @anthropic-ai/sdk
|
|
379
|
+
```
|
|
380
|
+
|
|
381
|
+
## Quick Start (The Facade)
|
|
382
|
+
|
|
383
|
+
The quickest way to get started is by instantiating the `EchoAI` client. It automatically sniffs your `process.env` for `OPENAI_API_KEY` or `ANTHROPIC_API_KEY` and constructs the highly available gateway.
|
|
384
|
+
|
|
385
|
+
```typescript
|
|
386
|
+
import { EchoAI, calculatorTool } from "echo-ai-sdk";
|
|
387
|
+
|
|
388
|
+
// Assumes process.env.OPENAI_API_KEY is populated.
|
|
389
|
+
const ai = new EchoAI();
|
|
390
|
+
|
|
391
|
+
const agent = ai.createToolAgent([calculatorTool]);
|
|
392
|
+
|
|
393
|
+
async function run() {
|
|
394
|
+
const response = await agent.run("session_xyz", "What is 750 multiplied by 14?");
|
|
395
|
+
console.log(response); // AI answers via calculating transparently!
|
|
396
|
+
}
|
|
397
|
+
run();
|
|
398
|
+
```
|
|
399
|
+
|
|
400
|
+
## Advanced Usage
|
|
401
|
+
|
|
402
|
+
### Building Your Own Type-Safe Tools
|
|
403
|
+
|
|
404
|
+
Using standard Zod schemas, we expose `createTool` to automatically synthesize MCP-compliant JSON schemas out-of-the-box.
|
|
405
|
+
|
|
406
|
+
```typescript
|
|
407
|
+
import { z } from "zod";
|
|
408
|
+
import { createTool } from "echo-ai-sdk";
|
|
409
|
+
|
|
410
|
+
export const databaseTool = createTool({
|
|
411
|
+
name: "query_db",
|
|
412
|
+
description: "Execute read-only queries against the replica DB.",
|
|
413
|
+
schema: z.object({
|
|
414
|
+
sql: z.string().describe("The SQL Query syntax.")
|
|
415
|
+
}),
|
|
416
|
+
execute: async ({ sql }) => {
|
|
417
|
+
// Implement your database logic
|
|
418
|
+
return await db.query(sql);
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
```
|
|
422
|
+
|
|
423
|
+
### Direct Gateway Access (With Retry Backoff!)
|
|
424
|
+
|
|
425
|
+
If you don't need the Agent Loop and simply want resilient generation or streaming, the Gateway natively features 3-tier exponential backoff under the hood!
|
|
426
|
+
|
|
427
|
+
```typescript
|
|
428
|
+
import { AIModelGateway, OpenAIProvider, ChatRequest } from "echo-ai-sdk";
|
|
429
|
+
|
|
430
|
+
const gateway = new AIModelGateway([
|
|
431
|
+
new OpenAIProvider(process.env.OPENAI_API_KEY),
|
|
432
|
+
// Add AnthropicProvider to handle OpenAI 500 API errors sequentially
|
|
433
|
+
]);
|
|
434
|
+
|
|
435
|
+
const req: ChatRequest = {
|
|
436
|
+
messages: [{ role: "user", content: "Tell me a story." }],
|
|
437
|
+
model_family: "fast"
|
|
438
|
+
};
|
|
439
|
+
|
|
440
|
+
const stream = gateway.chatStream(req);
|
|
441
|
+
|
|
442
|
+
for await(const token of stream) {
|
|
443
|
+
process.stdout.write(token);
|
|
444
|
+
}
|
|
445
|
+
```
|
|
446
|
+
|
|
447
|
+
### Structured Outputs (Enforcing Zod Schemas)
|
|
448
|
+
Need the AI to respond in a strict format?
|
|
449
|
+
```typescript
|
|
450
|
+
import { z } from 'zod';
|
|
451
|
+
|
|
452
|
+
const myCustomSchema = z.object({
|
|
453
|
+
analysis: z.string(),
|
|
454
|
+
riskScore: z.number().min(1).max(10)
|
|
455
|
+
});
|
|
456
|
+
|
|
457
|
+
// Forces the agent to output the exact JSON object you requested!
|
|
458
|
+
const result = await agent.executeStructured("session123", "Analyze these financial docs...", myCustomSchema);
|
|
459
|
+
console.log(result.riskScore); // 100% Type-Safe Numbers!
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
### Telemetry & Tracking
|
|
463
|
+
Expose hooks to pipe your LLM metrics safely straight to platforms like Datadog, Grafana, or LangSmith.
|
|
464
|
+
|
|
465
|
+
```typescript
|
|
466
|
+
import { AgentExecutor } from "echo-ai-sdk";
|
|
467
|
+
|
|
468
|
+
const executor = new AgentExecutor({
|
|
469
|
+
gateway,
|
|
470
|
+
memory,
|
|
471
|
+
tools,
|
|
472
|
+
telemetry: {
|
|
473
|
+
onTokenUsage: (sessionId, provider, model, usage) => console.log(`Burned ${usage.total_tokens} tokens on ${model}!`),
|
|
474
|
+
onToolStart: (sessionId, toolName, args) => console.log(`Agent executing ${toolName}!`)
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
```
|
|
478
|
+
|
|
479
|
+
## Error Handling
|
|
480
|
+
|
|
481
|
+
Echo AI SDK embraces explicit semantic exceptions overriding generic javascript errors.
|
|
482
|
+
|
|
483
|
+
```typescript
|
|
484
|
+
import { GatewayRoutingError } from "echo-ai-sdk";
|
|
485
|
+
|
|
486
|
+
try {
|
|
487
|
+
await gateway.chatComplete(req);
|
|
488
|
+
} catch (e) {
|
|
489
|
+
if (e instanceof GatewayRoutingError) {
|
|
490
|
+
console.error("All providers went down. Terminal panic.");
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
### Prompt Templates & Registry
|
|
496
|
+
|
|
497
|
+
Version your prompts like code. Supports immutable registrations, semantic versioning, and instant A/B rollbacks.
|
|
498
|
+
|
|
499
|
+
```typescript
|
|
500
|
+
import { PromptTemplate, PromptRegistry } from "echo-ai-sdk";
|
|
501
|
+
|
|
502
|
+
const registry = new PromptRegistry();
|
|
503
|
+
|
|
504
|
+
registry.register(new PromptTemplate({
|
|
505
|
+
name: "greet",
|
|
506
|
+
version: "1.0.0",
|
|
507
|
+
template: "Hello {{name}}, welcome to {{product}}!",
|
|
508
|
+
requiredVars: ["name", "product"]
|
|
509
|
+
}));
|
|
510
|
+
|
|
511
|
+
const prompt = registry.getTemplate("greet");
|
|
512
|
+
console.log(prompt.render({ name: "Alex", product: "EchoMind" }));
|
|
513
|
+
// → "Hello Alex, welcome to EchoMind!"
|
|
514
|
+
```
|
|
515
|
+
|
|
516
|
+
### Gateway Middleware
|
|
517
|
+
|
|
518
|
+
Intercept, transform, or log every request and response flowing through the gateway.
|
|
519
|
+
|
|
520
|
+
```typescript
|
|
521
|
+
import { AIModelGateway } from "echo-ai-sdk";
|
|
522
|
+
|
|
523
|
+
const gateway = new AIModelGateway([...providers]);
|
|
524
|
+
|
|
525
|
+
gateway.use({
|
|
526
|
+
onRequest: (req) => {
|
|
527
|
+
console.log(`[Audit] Sending ${req.messages.length} messages`);
|
|
528
|
+
return req;
|
|
529
|
+
},
|
|
530
|
+
onResponse: (res, req) => {
|
|
531
|
+
console.log(`[Audit] Used ${res.usage?.total_tokens} tokens`);
|
|
532
|
+
return res;
|
|
533
|
+
},
|
|
534
|
+
onError: (err, provider) => {
|
|
535
|
+
console.error(`[Alert] ${provider} failed: ${err.message}`);
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
```
|
|
539
|
+
|
|
540
|
+
### Multi-Agent Orchestration
|
|
541
|
+
|
|
542
|
+
#### AgentPipeline — Sequential Chaining
|
|
543
|
+
Chain agents where each stage's output feeds into the next:
|
|
544
|
+
|
|
545
|
+
```typescript
|
|
546
|
+
import { AgentPipeline } from "echo-ai-sdk";
|
|
547
|
+
|
|
548
|
+
const pipeline = new AgentPipeline()
|
|
549
|
+
.addStage("summarize", summaryAgent)
|
|
550
|
+
.addStage("translate", translatorAgent)
|
|
551
|
+
.addStage("format", formatterAgent);
|
|
552
|
+
|
|
553
|
+
const result = await pipeline.run("session1", "Raw meeting transcript...");
|
|
554
|
+
```
|
|
555
|
+
|
|
556
|
+
#### AgentRouter — Intent-Based Dispatch
|
|
557
|
+
Route user input to specialized agents based on regex patterns:
|
|
558
|
+
|
|
559
|
+
```typescript
|
|
560
|
+
import { AgentRouter } from "echo-ai-sdk";
|
|
561
|
+
|
|
562
|
+
const router = new AgentRouter()
|
|
563
|
+
.addRoute("support", /help|issue|bug/i, supportAgent)
|
|
564
|
+
.addRoute("sales", /pricing|demo|buy/i, salesAgent)
|
|
565
|
+
.setFallback(generalAgent);
|
|
566
|
+
|
|
567
|
+
const answer = await router.route("session1", "I need help with billing");
|
|
568
|
+
```
|
|
569
|
+
|
|
570
|
+
### Response Caching
|
|
571
|
+
|
|
572
|
+
Eliminate redundant API calls with TTL-based caching:
|
|
573
|
+
|
|
574
|
+
```typescript
|
|
575
|
+
import { CachedGateway } from "echo-ai-sdk";
|
|
576
|
+
|
|
577
|
+
const cached = new CachedGateway(gateway, 120_000); // 2-minute TTL
|
|
578
|
+
const response = await cached.chatComplete(req); // Cache MISS → calls API
|
|
579
|
+
const again = await cached.chatComplete(req); // Cache HIT → instant!
|
|
580
|
+
```
|
|
581
|
+
|
|
582
|
+
## 🎤 Voice Features (v1.2.0)
|
|
583
|
+
|
|
584
|
+
Echo AI SDK provides plug-and-play **Speech-to-Text**, **Text-to-Speech**, and **Speaker Recognition** — all through a single unified client.
|
|
585
|
+
|
|
586
|
+
### Quick Start — EchoVoice
|
|
587
|
+
|
|
588
|
+
```typescript
|
|
589
|
+
import { EchoVoice } from "echo-ai-sdk";
|
|
590
|
+
import fs from "fs";
|
|
591
|
+
|
|
592
|
+
// Auto-detects OPENAI_API_KEY for Whisper STT & TTS
|
|
593
|
+
const voice = new EchoVoice();
|
|
594
|
+
```
|
|
595
|
+
|
|
596
|
+
---
|
|
597
|
+
|
|
598
|
+
### Speech-to-Text (STT)
|
|
599
|
+
|
|
600
|
+
Convert audio files to text using OpenAI Whisper:
|
|
601
|
+
|
|
602
|
+
```typescript
|
|
603
|
+
const audioBuffer = fs.readFileSync("meeting.wav");
|
|
604
|
+
|
|
605
|
+
// Basic transcription
|
|
606
|
+
const result = await voice.transcribe(audioBuffer);
|
|
607
|
+
console.log(result.text); // → "Welcome to today's meeting..."
|
|
608
|
+
|
|
609
|
+
// With language hint and timestamps
|
|
610
|
+
const detailed = await voice.transcribe(audioBuffer, {
|
|
611
|
+
language: "en",
|
|
612
|
+
timestamps: true,
|
|
613
|
+
temperature: 0.0
|
|
614
|
+
});
|
|
615
|
+
|
|
616
|
+
for (const segment of detailed.segments!) {
|
|
617
|
+
console.log(`[${segment.start}s → ${segment.end}s] ${segment.text}`);
|
|
618
|
+
}
|
|
619
|
+
```
|
|
620
|
+
|
|
621
|
+
#### STT Options Reference
|
|
622
|
+
|
|
623
|
+
| Option | Type | Description |
|
|
624
|
+
|---|---|---|
|
|
625
|
+
| `language` | `string` | ISO language code (e.g., `"en"`, `"es"`, `"ja"`) |
|
|
626
|
+
| `prompt` | `string` | Guide the model's style or vocabulary |
|
|
627
|
+
| `temperature` | `number` | 0.0 (deterministic) to 1.0 (creative) |
|
|
628
|
+
| `timestamps` | `boolean` | Enable word-level timing segments |
|
|
629
|
+
|
|
630
|
+
#### TranscriptionResult Type
|
|
631
|
+
|
|
632
|
+
```typescript
|
|
633
|
+
interface TranscriptionResult {
|
|
634
|
+
text: string; // Full transcribed text
|
|
635
|
+
language?: string; // Detected language
|
|
636
|
+
duration?: number; // Audio duration in seconds
|
|
637
|
+
segments?: { // Time-aligned segments
|
|
638
|
+
start: number;
|
|
639
|
+
end: number;
|
|
640
|
+
text: string;
|
|
641
|
+
confidence?: number;
|
|
642
|
+
}[];
|
|
643
|
+
}
|
|
644
|
+
```
|
|
645
|
+
|
|
646
|
+
---
|
|
647
|
+
|
|
648
|
+
### Text-to-Speech (TTS)
|
|
649
|
+
|
|
650
|
+
Convert text to lifelike audio:
|
|
651
|
+
|
|
652
|
+
```typescript
|
|
653
|
+
// Basic synthesis
|
|
654
|
+
const speech = await voice.speak("Hello, welcome to EchoMind!");
|
|
655
|
+
fs.writeFileSync("greeting.mp3", speech.audio);
|
|
656
|
+
|
|
657
|
+
// With voice selection and options
|
|
658
|
+
const custom = await voice.speak("Breaking news: AI is everywhere.", {
|
|
659
|
+
voice: "nova", // alloy | echo | fable | onyx | nova | shimmer
|
|
660
|
+
speed: 1.2, // 0.25x to 4.0x
|
|
661
|
+
format: "opus", // mp3 | opus | aac | flac | wav | pcm
|
|
662
|
+
model: "tts-1-hd" // tts-1 (fast) or tts-1-hd (quality)
|
|
663
|
+
});
|
|
664
|
+
fs.writeFileSync("news.opus", custom.audio);
|
|
665
|
+
```
|
|
666
|
+
|
|
667
|
+
#### TTS Options Reference
|
|
668
|
+
|
|
669
|
+
| Option | Type | Default | Description |
|
|
670
|
+
|---|---|---|---|
|
|
671
|
+
| `voice` | `TTSVoice` | `"alloy"` | Voice persona |
|
|
672
|
+
| `speed` | `number` | `1.0` | Playback speed (0.25–4.0) |
|
|
673
|
+
| `format` | `TTSFormat` | `"mp3"` | Output audio format |
|
|
674
|
+
| `model` | `string` | `"tts-1"` | `tts-1` (fast) or `tts-1-hd` (quality) |
|
|
675
|
+
|
|
676
|
+
#### Available Voices
|
|
677
|
+
|
|
678
|
+
| Voice | Tone |
|
|
679
|
+
|---|---|
|
|
680
|
+
| `alloy` | Balanced, neutral |
|
|
681
|
+
| `echo` | Warm, conversational |
|
|
682
|
+
| `fable` | British, narrative |
|
|
683
|
+
| `onyx` | Deep, authoritative |
|
|
684
|
+
| `nova` | Energetic, young |
|
|
685
|
+
| `shimmer` | Soft, gentle |
|
|
686
|
+
|
|
687
|
+
---
|
|
688
|
+
|
|
689
|
+
### Speaker Recognition
|
|
690
|
+
|
|
691
|
+
Enroll speakers, then identify or verify them from new audio samples. Powered by cosine similarity over voice embeddings.
|
|
692
|
+
|
|
693
|
+
#### Direct VoiceprintStore Usage (No API Required)
|
|
694
|
+
|
|
695
|
+
```typescript
|
|
696
|
+
import { VoiceprintStore } from "echo-ai-sdk";
|
|
697
|
+
|
|
698
|
+
const store = new VoiceprintStore(0.80); // 80% match threshold
|
|
699
|
+
|
|
700
|
+
// Enroll speakers with pre-computed embeddings
|
|
701
|
+
store.enroll("spk_001", "Alice", [0.12, 0.84, 0.33, ...]);
|
|
702
|
+
store.enroll("spk_002", "Bob", [0.91, 0.15, 0.67, ...]);
|
|
703
|
+
|
|
704
|
+
// Identify an unknown speaker
|
|
705
|
+
const match = store.identify(unknownEmbedding);
|
|
706
|
+
if (match.matched) {
|
|
707
|
+
console.log(`Identified: ${match.speakerName} (${(match.confidence * 100).toFixed(1)}%)`);
|
|
708
|
+
} else {
|
|
709
|
+
console.log("Unknown speaker");
|
|
710
|
+
}
|
|
711
|
+
|
|
712
|
+
// Verify a specific speaker
|
|
713
|
+
const verification = store.verify("spk_001", audioEmbedding);
|
|
714
|
+
console.log(`Verified: ${verification.verified}, Confidence: ${verification.confidence}`);
|
|
715
|
+
|
|
716
|
+
// Manage speakers
|
|
717
|
+
store.listSpeakers(); // → [SpeakerProfile, ...]
|
|
718
|
+
store.removeSpeaker("spk_001"); // Remove enrollment
|
|
719
|
+
```
|
|
720
|
+
|
|
721
|
+
#### With EchoVoice Facade (Automatic Embedding Extraction)
|
|
722
|
+
|
|
723
|
+
```typescript
|
|
724
|
+
import { EchoVoice, BaseSpeakerRecognizer } from "echo-ai-sdk";
|
|
725
|
+
|
|
726
|
+
// Implement your own embedding extractor
|
|
727
|
+
class MySpeakerModel extends BaseSpeakerRecognizer {
|
|
728
|
+
get providerName() { return "my-model"; }
|
|
729
|
+
async extractEmbedding(audio: Buffer): Promise<number[]> {
|
|
730
|
+
// Call your ML model, Azure Speaker API, or custom service
|
|
731
|
+
return [0.12, 0.84, 0.33, /* ... */];
|
|
732
|
+
}
|
|
733
|
+
}
|
|
734
|
+
|
|
735
|
+
const voice = new EchoVoice({ recognizer: new MySpeakerModel() });
|
|
736
|
+
|
|
737
|
+
// Enroll from raw audio
|
|
738
|
+
await voice.enrollSpeaker("spk_001", "Alice", aliceAudioBuffer);
|
|
739
|
+
|
|
740
|
+
// Identify from new audio
|
|
741
|
+
const who = await voice.identifySpeaker(unknownAudioBuffer);
|
|
742
|
+
console.log(who.speakerName); // → "Alice"
|
|
743
|
+
|
|
744
|
+
// Verify a specific person
|
|
745
|
+
const check = await voice.verifySpeaker("spk_001", testAudioBuffer);
|
|
746
|
+
console.log(check.verified); // → true
|
|
747
|
+
```
|
|
748
|
+
|
|
749
|
+
---
|
|
750
|
+
|
|
751
|
+
### Bring Your Own Provider
|
|
752
|
+
|
|
753
|
+
All voice components are fully pluggable. Implement the abstract base classes to use any provider:
|
|
754
|
+
|
|
755
|
+
```typescript
|
|
756
|
+
import { BaseSTTProvider, BaseTTSProvider, EchoVoice } from "echo-ai-sdk";
|
|
757
|
+
|
|
758
|
+
// Custom Deepgram STT
|
|
759
|
+
class DeepgramSTT extends BaseSTTProvider {
|
|
760
|
+
get providerName() { return "deepgram"; }
|
|
761
|
+
async transcribe(audio: Buffer, options?) {
|
|
762
|
+
// Your Deepgram integration
|
|
763
|
+
return { text: "transcribed text" };
|
|
764
|
+
}
|
|
765
|
+
}
|
|
766
|
+
|
|
767
|
+
// Custom ElevenLabs TTS
|
|
768
|
+
class ElevenLabsTTS extends BaseTTSProvider {
|
|
769
|
+
get providerName() { return "elevenlabs"; }
|
|
770
|
+
async synthesize(text: string, options?) {
|
|
771
|
+
// Your ElevenLabs integration
|
|
772
|
+
return { audio: Buffer.from([]), format: "mp3" as const };
|
|
773
|
+
}
|
|
774
|
+
}
|
|
775
|
+
|
|
776
|
+
// Plug them in
|
|
777
|
+
const voice = new EchoVoice({
|
|
778
|
+
stt: new DeepgramSTT(),
|
|
779
|
+
tts: new ElevenLabsTTS()
|
|
780
|
+
});
|
|
781
|
+
```
|
|
782
|
+
|
|
783
|
+
---
|
|
784
|
+
|
|
785
|
+
## Complete API Reference
|
|
786
|
+
|
|
787
|
+
### Core Classes
|
|
788
|
+
|
|
789
|
+
| Class | Description |
|
|
790
|
+
|---|---|
|
|
791
|
+
| `EchoAI` | Main client facade for LLM chat & agents |
|
|
792
|
+
| `EchoVoice` | Unified voice client (STT + TTS + Speaker Recognition) |
|
|
793
|
+
| `AIModelGateway` | Multi-provider gateway with failover & backoff |
|
|
794
|
+
| `AgentExecutor` | ReAct autonomous agent loop with tool execution |
|
|
795
|
+
| `CachedGateway` | TTL-based response caching wrapper |
|
|
796
|
+
|
|
797
|
+
### Agent Classes
|
|
798
|
+
|
|
799
|
+
| Class | Description |
|
|
800
|
+
|---|---|
|
|
801
|
+
| `ChatAgent` | Simple conversational agent |
|
|
802
|
+
| `ToolAgent` | Agent with tool-calling capabilities |
|
|
803
|
+
| `AgentPipeline` | Sequential multi-agent chaining |
|
|
804
|
+
| `AgentRouter` | Intent-based agent routing |
|
|
805
|
+
|
|
806
|
+
### Voice Classes
|
|
807
|
+
|
|
808
|
+
| Class | Description |
|
|
809
|
+
|---|---|
|
|
810
|
+
| `OpenAIWhisperSTT` | Whisper-based speech-to-text |
|
|
811
|
+
| `OpenAITTS` | OpenAI text-to-speech (6 voices) |
|
|
812
|
+
| `VoiceprintStore` | Speaker enrollment & cosine similarity matching |
|
|
813
|
+
| `BaseSTTProvider` | Abstract STT provider (extend for custom) |
|
|
814
|
+
| `BaseTTSProvider` | Abstract TTS provider (extend for custom) |
|
|
815
|
+
| `BaseSpeakerRecognizer` | Abstract speaker embedding extractor |
|
|
816
|
+
|
|
817
|
+
### Error Classes
|
|
818
|
+
|
|
819
|
+
| Exception | When It Fires |
|
|
820
|
+
|---|---|
|
|
821
|
+
| `GatewayRoutingError` | All providers exhausted |
|
|
822
|
+
| `ConfigurationError` | Missing API keys or invalid setup |
|
|
823
|
+
| `ValidationError` | Invalid inputs to any public API |
|
|
824
|
+
| `ToolExecutionError` | Tool fails during agent loop |
|
|
825
|
+
| `AgentIterationLimitError` | Agent exceeds max iterations |
|
|
826
|
+
| `StructuredOutputError` | LLM output fails JSON parsing |
|
|
827
|
+
| `PromptVersionError` | Invalid semver or duplicate prompt version |
|
|
828
|
+
|
|
829
|
+
### Utilities
|
|
830
|
+
|
|
831
|
+
| Class/Function | Description |
|
|
832
|
+
|---|---|
|
|
833
|
+
| `createTool` | Zod-to-MCP tool factory |
|
|
834
|
+
| `PromptTemplate` | Versioned prompt with mustache rendering |
|
|
835
|
+
| `PromptRegistry` | Prompt version management with A/B rollback |
|
|
836
|
+
| `InMemoryStore` | Session-based conversation memory |
|
|
837
|
+
| `HonchoMemoryStore` | Production-grade Honcho-powered semantic memory store |
|
|
838
|
+
| `SemanticMemorySearch` | Unified search across Honcho reasoning + local vectors |
|
|
839
|
+
| `AgentTelemetry` | Lifecycle hooks interface for APM integration |
|
|
840
|
+
|
|
841
|
+
## License
|
|
842
|
+
MIT © EchoMind Team
|