kooby 1.0.2 → 1.0.3
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 +1 -1
- package/dist/cjs/index.js +29 -11
- package/dist/esm/index.js +29 -11
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -217,7 +217,7 @@ Kooby allows you to customize what gets rendered in the toolbar (at the top of t
|
|
|
217
217
|
```jsx
|
|
218
218
|
import { Kooby } from "kooby";
|
|
219
219
|
|
|
220
|
-
const CustomToolbar = ({ agent, conversation }) => {
|
|
220
|
+
const CustomToolbar = ({ agent, conversation, socketId }) => {
|
|
221
221
|
const copyConversation = () => {
|
|
222
222
|
const conversationJson = JSON.stringify(conversation, null, 2);
|
|
223
223
|
navigator.clipboard.writeText(conversationJson);
|
package/dist/cjs/index.js
CHANGED
|
@@ -88,7 +88,10 @@ function _iterableToArrayLimit(r, l) {
|
|
|
88
88
|
f = true,
|
|
89
89
|
o = false;
|
|
90
90
|
try {
|
|
91
|
-
if (i = (t = t.call(r)).next, 0 === l)
|
|
91
|
+
if (i = (t = t.call(r)).next, 0 === l) {
|
|
92
|
+
if (Object(t) !== t) return;
|
|
93
|
+
f = !1;
|
|
94
|
+
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
92
95
|
} catch (r) {
|
|
93
96
|
o = true, n = r;
|
|
94
97
|
} finally {
|
|
@@ -636,12 +639,14 @@ var Toolbar = function Toolbar(_ref5) {
|
|
|
636
639
|
agent = _useKooby3.agent,
|
|
637
640
|
conversation = _useKooby3.conversation,
|
|
638
641
|
toggleFocus = _useKooby3.toggleFocus,
|
|
639
|
-
resetConversation = _useKooby3.resetConversation
|
|
642
|
+
resetConversation = _useKooby3.resetConversation,
|
|
643
|
+
socketId = _useKooby3.socketId;
|
|
640
644
|
return /*#__PURE__*/React.createElement("div", {
|
|
641
645
|
className: "kooby-toolbar"
|
|
642
646
|
}, children ? children({
|
|
643
647
|
agent: agent,
|
|
644
|
-
conversation: conversation
|
|
648
|
+
conversation: conversation,
|
|
649
|
+
socketId: socketId
|
|
645
650
|
}) : null, reset && /*#__PURE__*/React.createElement(s2.ActionButton, {
|
|
646
651
|
"aria-label": "Reset",
|
|
647
652
|
onPress: resetConversation
|
|
@@ -684,6 +689,12 @@ var initializeConversation = function initializeConversation(_ref6) {
|
|
|
684
689
|
}
|
|
685
690
|
return [defaultGreetingMessage(agent)];
|
|
686
691
|
};
|
|
692
|
+
var createSocketId = function createSocketId() {
|
|
693
|
+
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
|
694
|
+
return crypto.randomUUID();
|
|
695
|
+
}
|
|
696
|
+
return "kooby-".concat(Date.now(), "-").concat(Math.random().toString(36).slice(2, 10));
|
|
697
|
+
};
|
|
687
698
|
var Kooby = function Kooby(_ref7) {
|
|
688
699
|
var debug = _ref7.debug,
|
|
689
700
|
url = _ref7.url,
|
|
@@ -730,14 +741,19 @@ var Kooby = function Kooby(_ref7) {
|
|
|
730
741
|
_useState12 = _slicedToArray(_useState11, 2),
|
|
731
742
|
isConnected = _useState12[0],
|
|
732
743
|
setIsConnected = _useState12[1];
|
|
733
|
-
var _useState13 = React.useState(
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
744
|
+
var _useState13 = React.useState(function () {
|
|
745
|
+
return createSocketId();
|
|
746
|
+
}),
|
|
747
|
+
_useState14 = _slicedToArray(_useState13, 1),
|
|
748
|
+
socketId = _useState14[0];
|
|
737
749
|
var _useState15 = React.useState(false),
|
|
738
750
|
_useState16 = _slicedToArray(_useState15, 2),
|
|
739
|
-
|
|
740
|
-
|
|
751
|
+
responding = _useState16[0],
|
|
752
|
+
setResponding = _useState16[1];
|
|
753
|
+
var _useState17 = React.useState(false),
|
|
754
|
+
_useState18 = _slicedToArray(_useState17, 2),
|
|
755
|
+
loading = _useState18[0],
|
|
756
|
+
setLoading = _useState18[1];
|
|
741
757
|
var socketManagerRef = React.useRef(null);
|
|
742
758
|
var metadataRef = React.useRef();
|
|
743
759
|
metadataRef.current = metadata;
|
|
@@ -799,6 +815,7 @@ var Kooby = function Kooby(_ref7) {
|
|
|
799
815
|
var history = initialConversation;
|
|
800
816
|
socketManagerRef.current.sendMessage({
|
|
801
817
|
handshake: true,
|
|
818
|
+
socketId: socketId,
|
|
802
819
|
history: history,
|
|
803
820
|
metadata: _objectSpread2({
|
|
804
821
|
user_agent: navigator.userAgent
|
|
@@ -822,7 +839,7 @@ var Kooby = function Kooby(_ref7) {
|
|
|
822
839
|
setIsConnected(false);
|
|
823
840
|
}
|
|
824
841
|
};
|
|
825
|
-
}, [url, agent, token]);
|
|
842
|
+
}, [url, agent, token, socketId]);
|
|
826
843
|
React.useEffect(function () {
|
|
827
844
|
if (socketManagerRef.current && context) {
|
|
828
845
|
console.log("Setting context", context);
|
|
@@ -851,6 +868,7 @@ var Kooby = function Kooby(_ref7) {
|
|
|
851
868
|
setConversation: setConversation,
|
|
852
869
|
resetConversation: resetConversation,
|
|
853
870
|
isConnected: isConnected,
|
|
871
|
+
socketId: socketId,
|
|
854
872
|
setIsConnected: setIsConnected,
|
|
855
873
|
socketManagerRef: socketManagerRef,
|
|
856
874
|
agent: agent,
|
|
@@ -860,7 +878,7 @@ var Kooby = function Kooby(_ref7) {
|
|
|
860
878
|
setLoading: setLoading,
|
|
861
879
|
loading: loading
|
|
862
880
|
};
|
|
863
|
-
}, [conversation, isConnected, agent, responding, context]);
|
|
881
|
+
}, [conversation, isConnected, socketId, agent, responding, context]);
|
|
864
882
|
if (apiRef) {
|
|
865
883
|
apiRef.current = {
|
|
866
884
|
resetConversation: resetConversation
|
package/dist/esm/index.js
CHANGED
|
@@ -86,7 +86,10 @@ function _iterableToArrayLimit(r, l) {
|
|
|
86
86
|
f = true,
|
|
87
87
|
o = false;
|
|
88
88
|
try {
|
|
89
|
-
if (i = (t = t.call(r)).next, 0 === l)
|
|
89
|
+
if (i = (t = t.call(r)).next, 0 === l) {
|
|
90
|
+
if (Object(t) !== t) return;
|
|
91
|
+
f = !1;
|
|
92
|
+
} else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
|
|
90
93
|
} catch (r) {
|
|
91
94
|
o = true, n = r;
|
|
92
95
|
} finally {
|
|
@@ -634,12 +637,14 @@ var Toolbar = function Toolbar(_ref5) {
|
|
|
634
637
|
agent = _useKooby3.agent,
|
|
635
638
|
conversation = _useKooby3.conversation,
|
|
636
639
|
toggleFocus = _useKooby3.toggleFocus,
|
|
637
|
-
resetConversation = _useKooby3.resetConversation
|
|
640
|
+
resetConversation = _useKooby3.resetConversation,
|
|
641
|
+
socketId = _useKooby3.socketId;
|
|
638
642
|
return /*#__PURE__*/React.createElement("div", {
|
|
639
643
|
className: "kooby-toolbar"
|
|
640
644
|
}, children ? children({
|
|
641
645
|
agent: agent,
|
|
642
|
-
conversation: conversation
|
|
646
|
+
conversation: conversation,
|
|
647
|
+
socketId: socketId
|
|
643
648
|
}) : null, reset && /*#__PURE__*/React.createElement(ActionButton, {
|
|
644
649
|
"aria-label": "Reset",
|
|
645
650
|
onPress: resetConversation
|
|
@@ -682,6 +687,12 @@ var initializeConversation = function initializeConversation(_ref6) {
|
|
|
682
687
|
}
|
|
683
688
|
return [defaultGreetingMessage(agent)];
|
|
684
689
|
};
|
|
690
|
+
var createSocketId = function createSocketId() {
|
|
691
|
+
if (typeof crypto !== "undefined" && crypto.randomUUID) {
|
|
692
|
+
return crypto.randomUUID();
|
|
693
|
+
}
|
|
694
|
+
return "kooby-".concat(Date.now(), "-").concat(Math.random().toString(36).slice(2, 10));
|
|
695
|
+
};
|
|
685
696
|
var Kooby = function Kooby(_ref7) {
|
|
686
697
|
var debug = _ref7.debug,
|
|
687
698
|
url = _ref7.url,
|
|
@@ -728,14 +739,19 @@ var Kooby = function Kooby(_ref7) {
|
|
|
728
739
|
_useState12 = _slicedToArray(_useState11, 2),
|
|
729
740
|
isConnected = _useState12[0],
|
|
730
741
|
setIsConnected = _useState12[1];
|
|
731
|
-
var _useState13 = useState(
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
742
|
+
var _useState13 = useState(function () {
|
|
743
|
+
return createSocketId();
|
|
744
|
+
}),
|
|
745
|
+
_useState14 = _slicedToArray(_useState13, 1),
|
|
746
|
+
socketId = _useState14[0];
|
|
735
747
|
var _useState15 = useState(false),
|
|
736
748
|
_useState16 = _slicedToArray(_useState15, 2),
|
|
737
|
-
|
|
738
|
-
|
|
749
|
+
responding = _useState16[0],
|
|
750
|
+
setResponding = _useState16[1];
|
|
751
|
+
var _useState17 = useState(false),
|
|
752
|
+
_useState18 = _slicedToArray(_useState17, 2),
|
|
753
|
+
loading = _useState18[0],
|
|
754
|
+
setLoading = _useState18[1];
|
|
739
755
|
var socketManagerRef = useRef(null);
|
|
740
756
|
var metadataRef = useRef();
|
|
741
757
|
metadataRef.current = metadata;
|
|
@@ -797,6 +813,7 @@ var Kooby = function Kooby(_ref7) {
|
|
|
797
813
|
var history = initialConversation;
|
|
798
814
|
socketManagerRef.current.sendMessage({
|
|
799
815
|
handshake: true,
|
|
816
|
+
socketId: socketId,
|
|
800
817
|
history: history,
|
|
801
818
|
metadata: _objectSpread2({
|
|
802
819
|
user_agent: navigator.userAgent
|
|
@@ -820,7 +837,7 @@ var Kooby = function Kooby(_ref7) {
|
|
|
820
837
|
setIsConnected(false);
|
|
821
838
|
}
|
|
822
839
|
};
|
|
823
|
-
}, [url, agent, token]);
|
|
840
|
+
}, [url, agent, token, socketId]);
|
|
824
841
|
useEffect(function () {
|
|
825
842
|
if (socketManagerRef.current && context) {
|
|
826
843
|
console.log("Setting context", context);
|
|
@@ -849,6 +866,7 @@ var Kooby = function Kooby(_ref7) {
|
|
|
849
866
|
setConversation: setConversation,
|
|
850
867
|
resetConversation: resetConversation,
|
|
851
868
|
isConnected: isConnected,
|
|
869
|
+
socketId: socketId,
|
|
852
870
|
setIsConnected: setIsConnected,
|
|
853
871
|
socketManagerRef: socketManagerRef,
|
|
854
872
|
agent: agent,
|
|
@@ -858,7 +876,7 @@ var Kooby = function Kooby(_ref7) {
|
|
|
858
876
|
setLoading: setLoading,
|
|
859
877
|
loading: loading
|
|
860
878
|
};
|
|
861
|
-
}, [conversation, isConnected, agent, responding, context]);
|
|
879
|
+
}, [conversation, isConnected, socketId, agent, responding, context]);
|
|
862
880
|
if (apiRef) {
|
|
863
881
|
apiRef.current = {
|
|
864
882
|
resetConversation: resetConversation
|