@hivegpt/hiveai-angular 0.0.479 → 0.0.481
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/bundles/hivegpt-hiveai-angular.umd.js +80 -92
- package/bundles/hivegpt-hiveai-angular.umd.js.map +1 -1
- package/bundles/hivegpt-hiveai-angular.umd.min.js +1 -1
- package/bundles/hivegpt-hiveai-angular.umd.min.js.map +1 -1
- package/esm2015/lib/components/voice-agent/services/voice-agent.service.js +80 -87
- package/fesm2015/hivegpt-hiveai-angular.js +79 -86
- package/fesm2015/hivegpt-hiveai-angular.js.map +1 -1
- package/hivegpt-hiveai-angular.metadata.json +1 -1
- package/lib/components/voice-agent/services/voice-agent.service.d.ts +4 -1
- package/lib/components/voice-agent/services/voice-agent.service.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -1646,31 +1646,62 @@
|
|
|
1646
1646
|
};
|
|
1647
1647
|
VoiceAgentService.prototype.connect = function (apiUrl, token, botId, conversationId, apiKey, eventToken, eventUrl, domainAuthority) {
|
|
1648
1648
|
return __awaiter(this, void 0, void 0, function () {
|
|
1649
|
-
var
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
switch (_a.label) {
|
|
1649
|
+
var _a, wsOk, error_1;
|
|
1650
|
+
return __generator(this, function (_b) {
|
|
1651
|
+
switch (_b.label) {
|
|
1653
1652
|
case 0:
|
|
1654
1653
|
if (this.callStateSubject.value !== 'idle') {
|
|
1655
1654
|
console.warn('Call already in progress');
|
|
1656
1655
|
return [2 /*return*/];
|
|
1657
1656
|
}
|
|
1658
|
-
|
|
1657
|
+
_b.label = 1;
|
|
1659
1658
|
case 1:
|
|
1660
|
-
|
|
1659
|
+
_b.trys.push([1, 3, , 5]);
|
|
1661
1660
|
this.callStateSubject.next('connecting');
|
|
1662
1661
|
this.statusTextSubject.next('Connecting...');
|
|
1663
|
-
|
|
1662
|
+
return [4 /*yield*/, Promise.all([
|
|
1663
|
+
this.connectWebSocketSignaling(token, botId, conversationId, apiKey, eventToken, eventUrl, domainAuthority),
|
|
1664
|
+
this.dailyClient.connect(STATIC_DAILY_ROOM_URL),
|
|
1665
|
+
])];
|
|
1666
|
+
case 2:
|
|
1667
|
+
_a = __read.apply(void 0, [_b.sent(), 1]), wsOk = _a[0];
|
|
1668
|
+
if (!wsOk) {
|
|
1669
|
+
throw new Error('No ws_url in response');
|
|
1670
|
+
}
|
|
1671
|
+
this.setupDailySubscriptions();
|
|
1672
|
+
return [3 /*break*/, 5];
|
|
1673
|
+
case 3:
|
|
1674
|
+
error_1 = _b.sent();
|
|
1675
|
+
console.error('Error connecting voice agent:', error_1);
|
|
1676
|
+
this.callStateSubject.next('ended');
|
|
1677
|
+
return [4 /*yield*/, this.disconnect()];
|
|
1678
|
+
case 4:
|
|
1679
|
+
_b.sent();
|
|
1680
|
+
this.statusTextSubject.next('Connection failed');
|
|
1681
|
+
throw error_1;
|
|
1682
|
+
case 5: return [2 /*return*/];
|
|
1683
|
+
}
|
|
1684
|
+
});
|
|
1685
|
+
});
|
|
1686
|
+
};
|
|
1687
|
+
/** POST for ws_url, wire transcript streams, connect WebSocket. Returns true if ws_url was found. */
|
|
1688
|
+
VoiceAgentService.prototype.connectWebSocketSignaling = function (token, botId, conversationId, apiKey, eventToken, eventUrl, domainAuthority) {
|
|
1689
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1690
|
+
var postUrl, headers, res, json, wsUrl;
|
|
1691
|
+
var _this = this;
|
|
1692
|
+
return __generator(this, function (_a) {
|
|
1693
|
+
switch (_a.label) {
|
|
1694
|
+
case 0:
|
|
1664
1695
|
postUrl = "https://0a19-2405-201-5c02-991e-2487-d56-2543-bda8.ngrok-free.app/ai/ask-voice";
|
|
1665
1696
|
headers = {
|
|
1666
1697
|
'Content-Type': 'application/json',
|
|
1667
1698
|
Authorization: "Bearer " + token,
|
|
1668
1699
|
'domain-authority': domainAuthority,
|
|
1669
|
-
|
|
1670
|
-
|
|
1700
|
+
eventtoken: eventToken,
|
|
1701
|
+
eventurl: eventUrl,
|
|
1671
1702
|
'hive-bot-id': botId,
|
|
1672
1703
|
'x-api-key': apiKey,
|
|
1673
|
-
|
|
1704
|
+
'ngrok-skip-browser-warning': 'true',
|
|
1674
1705
|
};
|
|
1675
1706
|
return [4 /*yield*/, fetch(postUrl, {
|
|
1676
1707
|
method: 'POST',
|
|
@@ -1681,109 +1712,66 @@
|
|
|
1681
1712
|
voice: 'alloy',
|
|
1682
1713
|
}),
|
|
1683
1714
|
})];
|
|
1684
|
-
case
|
|
1715
|
+
case 1:
|
|
1685
1716
|
res = _a.sent();
|
|
1686
1717
|
if (!res.ok) {
|
|
1687
1718
|
throw new Error("HTTP " + res.status);
|
|
1688
1719
|
}
|
|
1689
1720
|
return [4 /*yield*/, res.json()];
|
|
1690
|
-
case
|
|
1721
|
+
case 2:
|
|
1691
1722
|
json = _a.sent();
|
|
1692
1723
|
wsUrl = json === null || json === void 0 ? void 0 : json.rn_ws_url;
|
|
1693
1724
|
if (!wsUrl || typeof wsUrl !== 'string') {
|
|
1694
|
-
|
|
1725
|
+
return [2 /*return*/, false];
|
|
1695
1726
|
}
|
|
1696
|
-
// Forward transcripts from WebSocket
|
|
1697
1727
|
this.subscriptions.add(this.wsClient.userTranscript$
|
|
1698
1728
|
.pipe(operators.takeUntil(this.destroy$))
|
|
1699
1729
|
.subscribe(function (t) { return _this.userTranscriptSubject.next(t); }));
|
|
1700
1730
|
this.subscriptions.add(this.wsClient.botTranscript$
|
|
1701
1731
|
.pipe(operators.takeUntil(this.destroy$))
|
|
1702
1732
|
.subscribe(function (t) { return _this.botTranscriptSubject.next(t); }));
|
|
1703
|
-
// Connect signaling WebSocket (no audio over WS)
|
|
1704
1733
|
this.wsClient.connect(wsUrl);
|
|
1705
|
-
|
|
1706
|
-
case 4:
|
|
1707
|
-
_a.trys.push([4, 6, , 8]);
|
|
1708
|
-
return [4 /*yield*/, this.onRoomCreated(STATIC_DAILY_ROOM_URL)];
|
|
1709
|
-
case 5:
|
|
1710
|
-
_a.sent();
|
|
1711
|
-
return [3 /*break*/, 8];
|
|
1712
|
-
case 6:
|
|
1713
|
-
err_1 = _a.sent();
|
|
1714
|
-
console.error('Daily join failed:', err_1);
|
|
1715
|
-
this.callStateSubject.next('ended');
|
|
1716
|
-
this.statusTextSubject.next('Connection failed');
|
|
1717
|
-
return [4 /*yield*/, this.disconnect()];
|
|
1718
|
-
case 7:
|
|
1719
|
-
_a.sent();
|
|
1720
|
-
throw err_1;
|
|
1721
|
-
case 8: return [3 /*break*/, 11];
|
|
1722
|
-
case 9:
|
|
1723
|
-
error_1 = _a.sent();
|
|
1724
|
-
console.error('Error connecting voice agent:', error_1);
|
|
1725
|
-
this.callStateSubject.next('ended');
|
|
1726
|
-
return [4 /*yield*/, this.disconnect()];
|
|
1727
|
-
case 10:
|
|
1728
|
-
_a.sent();
|
|
1729
|
-
this.statusTextSubject.next('Connection failed');
|
|
1730
|
-
throw error_1;
|
|
1731
|
-
case 11: return [2 /*return*/];
|
|
1734
|
+
return [2 /*return*/, true];
|
|
1732
1735
|
}
|
|
1733
1736
|
});
|
|
1734
1737
|
});
|
|
1735
1738
|
};
|
|
1736
|
-
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
return [4 /*yield*/, this.dailyClient.connect(roomUrl)];
|
|
1744
|
-
case 1:
|
|
1745
|
-
// Connect Daily.js for WebRTC audio
|
|
1746
|
-
_a.sent();
|
|
1747
|
-
// Waveform: use local mic stream from Daily client
|
|
1748
|
-
this.dailyClient.localStream$
|
|
1749
|
-
.pipe(operators.filter(function (s) { return s != null; }), operators.take(1))
|
|
1750
|
-
.subscribe(function (stream) {
|
|
1751
|
-
_this.audioAnalyzer.start(stream);
|
|
1752
|
-
});
|
|
1753
|
-
this.subscriptions.add(this.dailyClient.userSpeaking$.subscribe(function (s) { return _this.isUserSpeakingSubject.next(s); }));
|
|
1754
|
-
this.subscriptions.add(rxjs.combineLatest([
|
|
1755
|
-
this.dailyClient.speaking$,
|
|
1756
|
-
this.dailyClient.userSpeaking$,
|
|
1757
|
-
]).subscribe(function (_a) {
|
|
1758
|
-
var _b = __read(_a, 2), bot = _b[0], user = _b[1];
|
|
1759
|
-
var current = _this.callStateSubject.value;
|
|
1760
|
-
if (current === 'connecting' && !bot) {
|
|
1761
|
-
return;
|
|
1762
|
-
}
|
|
1763
|
-
if (current === 'connecting' && bot) {
|
|
1764
|
-
console.log("[VoiceDebug] First bot audio arrived \u2014 transitioning to talking \u2014 " + new Date().toISOString());
|
|
1765
|
-
_this.callStartTime = Date.now();
|
|
1766
|
-
_this.startDurationTimer();
|
|
1767
|
-
_this.callStateSubject.next('talking');
|
|
1768
|
-
return;
|
|
1769
|
-
}
|
|
1770
|
-
if (user) {
|
|
1771
|
-
_this.callStateSubject.next('listening');
|
|
1772
|
-
}
|
|
1773
|
-
else if (bot) {
|
|
1774
|
-
_this.callStateSubject.next('talking');
|
|
1775
|
-
}
|
|
1776
|
-
else if (current === 'talking' || current === 'listening') {
|
|
1777
|
-
_this.callStateSubject.next('connected');
|
|
1778
|
-
}
|
|
1779
|
-
}));
|
|
1780
|
-
this.subscriptions.add(this.dailyClient.micMuted$.subscribe(function (muted) { return _this.isMicMutedSubject.next(muted); }));
|
|
1781
|
-
console.log("[VoiceDebug] Room joined, staying in connecting until bot speaks \u2014 " + new Date().toISOString());
|
|
1782
|
-
this.statusTextSubject.next('Connecting...');
|
|
1783
|
-
return [2 /*return*/];
|
|
1784
|
-
}
|
|
1785
|
-
});
|
|
1739
|
+
/** Wire Daily client to UI state (waveform, speaking, mic muted). Call after Daily is connected. */
|
|
1740
|
+
VoiceAgentService.prototype.setupDailySubscriptions = function () {
|
|
1741
|
+
var _this = this;
|
|
1742
|
+
this.dailyClient.localStream$
|
|
1743
|
+
.pipe(operators.filter(function (s) { return s != null; }), operators.take(1))
|
|
1744
|
+
.subscribe(function (stream) {
|
|
1745
|
+
_this.audioAnalyzer.start(stream);
|
|
1786
1746
|
});
|
|
1747
|
+
this.subscriptions.add(this.dailyClient.userSpeaking$.subscribe(function (s) { return _this.isUserSpeakingSubject.next(s); }));
|
|
1748
|
+
this.subscriptions.add(rxjs.combineLatest([
|
|
1749
|
+
this.dailyClient.speaking$,
|
|
1750
|
+
this.dailyClient.userSpeaking$,
|
|
1751
|
+
]).subscribe(function (_a) {
|
|
1752
|
+
var _b = __read(_a, 2), bot = _b[0], user = _b[1];
|
|
1753
|
+
var current = _this.callStateSubject.value;
|
|
1754
|
+
if (current === 'connecting' && !bot) {
|
|
1755
|
+
return;
|
|
1756
|
+
}
|
|
1757
|
+
if (current === 'connecting' && bot) {
|
|
1758
|
+
_this.callStartTime = Date.now();
|
|
1759
|
+
_this.startDurationTimer();
|
|
1760
|
+
_this.callStateSubject.next('talking');
|
|
1761
|
+
return;
|
|
1762
|
+
}
|
|
1763
|
+
if (user) {
|
|
1764
|
+
_this.callStateSubject.next('listening');
|
|
1765
|
+
}
|
|
1766
|
+
else if (bot) {
|
|
1767
|
+
_this.callStateSubject.next('talking');
|
|
1768
|
+
}
|
|
1769
|
+
else if (current === 'talking' || current === 'listening') {
|
|
1770
|
+
_this.callStateSubject.next('connected');
|
|
1771
|
+
}
|
|
1772
|
+
}));
|
|
1773
|
+
this.subscriptions.add(this.dailyClient.micMuted$.subscribe(function (muted) { return _this.isMicMutedSubject.next(muted); }));
|
|
1774
|
+
this.statusTextSubject.next('Connecting...');
|
|
1787
1775
|
};
|
|
1788
1776
|
VoiceAgentService.prototype.disconnect = function () {
|
|
1789
1777
|
return __awaiter(this, void 0, void 0, function () {
|