@memori.ai/memori-react 8.26.0 → 8.27.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/CHANGELOG.md +13 -0
- package/dist/components/Header/Header.css +11 -3
- package/dist/components/MemoriWidget/MemoriWidget.js +49 -75
- package/dist/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/dist/components/layouts/website-assistant.css +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/esm/components/Header/Header.css +11 -3
- package/esm/components/MemoriWidget/MemoriWidget.js +49 -75
- package/esm/components/MemoriWidget/MemoriWidget.js.map +1 -1
- package/esm/components/layouts/website-assistant.css +1 -0
- package/esm/version.d.ts +1 -1
- package/esm/version.js +1 -1
- package/package.json +2 -2
- package/src/components/Header/Header.css +11 -3
- package/src/components/MemoriWidget/MemoriWidget.stories.tsx +11 -0
- package/src/components/MemoriWidget/MemoriWidget.tsx +64 -97
- package/src/components/layouts/website-assistant.css +1 -0
- package/src/version.ts +1 -1
package/esm/version.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const version = "8.
|
|
1
|
+
export declare const version = "8.27.0";
|
package/esm/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export const version = '8.
|
|
1
|
+
export const version = '8.27.0';
|
|
2
2
|
//# sourceMappingURL=version.js.map
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"version": "8.
|
|
2
|
+
"version": "8.27.0",
|
|
3
3
|
"name": "@memori.ai/memori-react",
|
|
4
4
|
"author": "Memori Srl",
|
|
5
5
|
"main": "dist/index.js",
|
|
@@ -294,7 +294,7 @@
|
|
|
294
294
|
},
|
|
295
295
|
"dependencies": {
|
|
296
296
|
"@headlessui/react": "1.7.4",
|
|
297
|
-
"@memori.ai/memori-api-client": "6.
|
|
297
|
+
"@memori.ai/memori-api-client": "6.20.0",
|
|
298
298
|
"@react-three/drei": "8.20.2",
|
|
299
299
|
"@react-three/fiber": "7.0.25",
|
|
300
300
|
"classnames": "2.5.1",
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
.memori-header {
|
|
2
2
|
position: relative;
|
|
3
3
|
z-index: 1000;
|
|
4
|
-
width: calc(50% - 1rem);
|
|
5
4
|
height: 50px;
|
|
6
5
|
padding: calc(var(--memori-inner-content-pad) / 4) calc(var(--memori-inner-content-pad) / 2);
|
|
7
6
|
border-radius: 10px;
|
|
@@ -85,8 +84,17 @@
|
|
|
85
84
|
|
|
86
85
|
.memori-header .memori-header--button--position,
|
|
87
86
|
.memori-header .memori-share-button,
|
|
88
|
-
.memori-header .memori-header--button-login
|
|
89
|
-
|
|
87
|
+
.memori-header .memori-header--button-login,
|
|
88
|
+
.memori-header .memori-header--button-settings,
|
|
89
|
+
.memori-header .memori-header--button--fullscreen,
|
|
90
|
+
.memori-header .memori-header--button--reload,
|
|
91
|
+
.memori-header .memori-header--button--clear,
|
|
92
|
+
.memori-header .memori-header--button--chat-history,
|
|
93
|
+
.memori-header .memori-header--button--knownfacts,
|
|
94
|
+
.memori-header .memori-header--button--experts,
|
|
95
|
+
.memori-header .memori-header--button--speaker,
|
|
96
|
+
.memori-header .memori-header--button--speaker-muted {
|
|
97
|
+
margin-left: 4px;
|
|
90
98
|
}
|
|
91
99
|
|
|
92
100
|
.memori-header .memori-header--button--position {
|
|
@@ -87,6 +87,17 @@ WithDates.args = {
|
|
|
87
87
|
tenant,
|
|
88
88
|
};
|
|
89
89
|
|
|
90
|
+
/** To test dateUTC/place in Enter Text: open DevTools → Network, start chat, set position (header position icon) if testing place, then send a message. Inspect the request to your backend/engine for body.dateUTC (ISO) and body.place (placeName, latitude, longitude, uncertaintyKm). */
|
|
91
|
+
export const WithDateAndPlaceForEnterText = Template.bind({});
|
|
92
|
+
WithDateAndPlaceForEnterText.args = {
|
|
93
|
+
memori: {
|
|
94
|
+
...memori,
|
|
95
|
+
needsDateTime: true,
|
|
96
|
+
needsPosition: true,
|
|
97
|
+
},
|
|
98
|
+
tenant,
|
|
99
|
+
};
|
|
100
|
+
|
|
90
101
|
export const WithPublicPageIntegration = Template.bind({});
|
|
91
102
|
WithPublicPageIntegration.args = {
|
|
92
103
|
memori,
|
|
@@ -115,6 +115,14 @@ const getMemoriState = (integrationId?: string): object | null => {
|
|
|
115
115
|
};
|
|
116
116
|
};
|
|
117
117
|
|
|
118
|
+
/** Place spec with all nulls for postTextEnteredEvent when position is not set or user chose "I don't want to provide my position". */
|
|
119
|
+
const NULL_PLACE_SPEC = {
|
|
120
|
+
placeName: null,
|
|
121
|
+
latitude: null,
|
|
122
|
+
longitude: null,
|
|
123
|
+
uncertaintyKm: null,
|
|
124
|
+
} as const;
|
|
125
|
+
|
|
118
126
|
type MemoriTextEnteredEvent = CustomEvent<{
|
|
119
127
|
text: string;
|
|
120
128
|
waitForPrevious?: boolean;
|
|
@@ -729,31 +737,60 @@ const MemoriWidget = ({
|
|
|
729
737
|
* Position drawer
|
|
730
738
|
*/
|
|
731
739
|
const [position, _setPosition] = useState<Venue>();
|
|
732
|
-
const applyPosition = async (venue?: Venue, sessionID?: string) => {
|
|
733
|
-
const session = sessionID ?? sessionId;
|
|
734
|
-
// Only apply position if memori.needsPosition is true
|
|
735
|
-
if (venue && session && memori.needsPosition) {
|
|
736
|
-
const { currentState, ...response } = await postPlaceChangedEvent({
|
|
737
|
-
sessionId: session,
|
|
738
|
-
placeName: venue.placeName,
|
|
739
|
-
latitude: venue.latitude,
|
|
740
|
-
longitude: venue.longitude,
|
|
741
|
-
uncertaintyKm: venue.uncertainty ?? 0,
|
|
742
|
-
});
|
|
743
740
|
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
741
|
+
/** True when the user has set a real position; false when position is missing or "I don't want to provide my position". */
|
|
742
|
+
const hasUserProvidedPosition = useCallback((venue: Venue | undefined) => {
|
|
743
|
+
if (!venue) return false;
|
|
744
|
+
if (
|
|
745
|
+
venue.placeName === 'Position' &&
|
|
746
|
+
venue.latitude === 0 &&
|
|
747
|
+
venue.longitude === 0
|
|
748
|
+
) {
|
|
749
|
+
return false;
|
|
751
750
|
}
|
|
752
|
-
|
|
751
|
+
return true;
|
|
752
|
+
}, []);
|
|
753
|
+
|
|
754
|
+
/** Build optional place for EnterTextSpecs (placeName and/or lat/lon; lat/lon must be together). */
|
|
755
|
+
const buildEnterTextPlace = useCallback((venue: Venue | undefined) => {
|
|
756
|
+
if (!venue) return undefined;
|
|
757
|
+
const place: {
|
|
758
|
+
placeName?: string;
|
|
759
|
+
latitude?: number;
|
|
760
|
+
longitude?: number;
|
|
761
|
+
uncertaintyKm?: number;
|
|
762
|
+
} = {};
|
|
763
|
+
if (
|
|
764
|
+
venue.latitude != null &&
|
|
765
|
+
venue.longitude != null
|
|
766
|
+
) {
|
|
767
|
+
place.latitude = venue.latitude;
|
|
768
|
+
place.longitude = venue.longitude;
|
|
769
|
+
if (venue.placeName) place.placeName = venue.placeName;
|
|
770
|
+
if (
|
|
771
|
+
venue.uncertainty != null &&
|
|
772
|
+
venue.uncertainty > 0
|
|
773
|
+
)
|
|
774
|
+
place.uncertaintyKm = venue.uncertainty;
|
|
775
|
+
} else if (venue.placeName) {
|
|
776
|
+
place.placeName = venue.placeName;
|
|
777
|
+
}
|
|
778
|
+
return Object.keys(place).length > 0 ? place : undefined;
|
|
779
|
+
}, []);
|
|
780
|
+
|
|
781
|
+
/** Place to send with postTextEnteredEvent: real place, nulls when no/declined position, or undefined when position not needed. */
|
|
782
|
+
const getPlaceSpecForEnterText = useCallback(
|
|
783
|
+
(venue: Venue | undefined) => {
|
|
784
|
+
if (!memori.needsPosition) return undefined;
|
|
785
|
+
return hasUserProvidedPosition(venue)
|
|
786
|
+
? buildEnterTextPlace(venue)
|
|
787
|
+
: NULL_PLACE_SPEC;
|
|
788
|
+
},
|
|
789
|
+
[memori.needsPosition, hasUserProvidedPosition, buildEnterTextPlace]
|
|
790
|
+
);
|
|
753
791
|
|
|
754
792
|
const setPosition = (venue?: Venue) => {
|
|
755
793
|
_setPosition(venue);
|
|
756
|
-
applyPosition(venue);
|
|
757
794
|
|
|
758
795
|
// Only save position to local config if memori.needsPosition is true
|
|
759
796
|
if (venue && memori.needsPosition) {
|
|
@@ -922,12 +959,14 @@ const MemoriWidget = ({
|
|
|
922
959
|
// '"></chat-reference>';
|
|
923
960
|
// }
|
|
924
961
|
|
|
962
|
+
const placeSpec = getPlaceSpecForEnterText(position);
|
|
925
963
|
const { currentState, ...response } = await postTextEnteredEvent({
|
|
926
964
|
sessionId: sessionID,
|
|
927
965
|
text: msg,
|
|
928
966
|
...(memori.needsDateTime && {
|
|
929
967
|
dateUTC: DateTime.utc().toISO() ?? undefined,
|
|
930
968
|
}),
|
|
969
|
+
...(placeSpec !== undefined && { place: placeSpec }),
|
|
931
970
|
});
|
|
932
971
|
if (response.resultCode === 0 && currentState) {
|
|
933
972
|
setChatLogID(undefined);
|
|
@@ -1404,16 +1443,6 @@ const MemoriWidget = ({
|
|
|
1404
1443
|
setInstruct(false);
|
|
1405
1444
|
}
|
|
1406
1445
|
|
|
1407
|
-
if (position && memori.needsPosition)
|
|
1408
|
-
applyPosition(position, session.sessionID);
|
|
1409
|
-
|
|
1410
|
-
if (memori.needsDateTime) {
|
|
1411
|
-
await sendDateChangedEvent({
|
|
1412
|
-
sessionID: session.sessionID,
|
|
1413
|
-
state: session?.currentState,
|
|
1414
|
-
});
|
|
1415
|
-
}
|
|
1416
|
-
|
|
1417
1446
|
setLoading(false);
|
|
1418
1447
|
return {
|
|
1419
1448
|
dialogState: session.currentState,
|
|
@@ -1637,16 +1666,6 @@ const MemoriWidget = ({
|
|
|
1637
1666
|
}
|
|
1638
1667
|
}
|
|
1639
1668
|
|
|
1640
|
-
// Apply position and date settings if needed
|
|
1641
|
-
if (position && memori.needsPosition) {
|
|
1642
|
-
// console.log('[REOPEN_SESSION] Applying position');
|
|
1643
|
-
applyPosition(position, sessionID);
|
|
1644
|
-
}
|
|
1645
|
-
if (memori.needsDateTime) {
|
|
1646
|
-
// console.log('[REOPEN_SESSION] Sending date changed event');
|
|
1647
|
-
sendDateChangedEvent({ sessionID: sessionID, state: currentState });
|
|
1648
|
-
}
|
|
1649
|
-
|
|
1650
1669
|
setLoading(false);
|
|
1651
1670
|
return {
|
|
1652
1671
|
dialogState: currentState,
|
|
@@ -1706,12 +1725,14 @@ const MemoriWidget = ({
|
|
|
1706
1725
|
pin &&
|
|
1707
1726
|
(currentState.state === 'X1a' || currentState.state === 'X1b')
|
|
1708
1727
|
) {
|
|
1728
|
+
const placeSpec = getPlaceSpecForEnterText(position);
|
|
1709
1729
|
const { resultCode: textResultCode } = await postTextEnteredEvent({
|
|
1710
1730
|
sessionId,
|
|
1711
1731
|
text: pin ?? '',
|
|
1712
1732
|
...(memori.needsDateTime && {
|
|
1713
1733
|
dateUTC: DateTime.utc().toISO() ?? undefined,
|
|
1714
1734
|
}),
|
|
1735
|
+
...(placeSpec !== undefined && { place: placeSpec }),
|
|
1715
1736
|
});
|
|
1716
1737
|
textResult = textResultCode;
|
|
1717
1738
|
}
|
|
@@ -1788,49 +1809,6 @@ const MemoriWidget = ({
|
|
|
1788
1809
|
return null;
|
|
1789
1810
|
};
|
|
1790
1811
|
|
|
1791
|
-
/**
|
|
1792
|
-
* Polling dates
|
|
1793
|
-
*/
|
|
1794
|
-
const sendDateChangedEvent = useCallback(
|
|
1795
|
-
async ({
|
|
1796
|
-
sessionID,
|
|
1797
|
-
date,
|
|
1798
|
-
state,
|
|
1799
|
-
}: {
|
|
1800
|
-
sessionID?: string;
|
|
1801
|
-
date?: string;
|
|
1802
|
-
state?: DialogState;
|
|
1803
|
-
}) => {
|
|
1804
|
-
const session = sessionID ?? sessionId;
|
|
1805
|
-
const dialogState = state ?? currentDialogState;
|
|
1806
|
-
|
|
1807
|
-
if (!session || !memori.needsDateTime || dialogState?.hints?.length) {
|
|
1808
|
-
return;
|
|
1809
|
-
}
|
|
1810
|
-
|
|
1811
|
-
const now = (date ? DateTime.fromISO(date) : DateTime.now())
|
|
1812
|
-
.toUTC()
|
|
1813
|
-
.toFormat('yyyy/MM/dd HH:mm:ss ZZ')
|
|
1814
|
-
.split(':')
|
|
1815
|
-
.slice(0, -1)
|
|
1816
|
-
.join(':');
|
|
1817
|
-
|
|
1818
|
-
const { currentState, ...response } = await postDateChangedEvent(
|
|
1819
|
-
session,
|
|
1820
|
-
now
|
|
1821
|
-
);
|
|
1822
|
-
|
|
1823
|
-
if (response.resultCode === 0 && currentState) {
|
|
1824
|
-
_setCurrentDialogState(cds => ({
|
|
1825
|
-
...cds,
|
|
1826
|
-
...currentState,
|
|
1827
|
-
hints: currentState.hints?.length ? currentState.hints : cds?.hints,
|
|
1828
|
-
}));
|
|
1829
|
-
}
|
|
1830
|
-
},
|
|
1831
|
-
[currentDialogState, memori.needsDateTime, sessionId]
|
|
1832
|
-
);
|
|
1833
|
-
|
|
1834
1812
|
/**
|
|
1835
1813
|
* Timeout conversazione
|
|
1836
1814
|
*/
|
|
@@ -2529,14 +2507,6 @@ const MemoriWidget = ({
|
|
|
2529
2507
|
// reset history
|
|
2530
2508
|
setHistory([]);
|
|
2531
2509
|
|
|
2532
|
-
// date and place events
|
|
2533
|
-
if (position && memori.needsPosition) {
|
|
2534
|
-
applyPosition(position, sessionID);
|
|
2535
|
-
}
|
|
2536
|
-
if (memori.needsDateTime) {
|
|
2537
|
-
sendDateChangedEvent({ sessionID: sessionID, state: currentState });
|
|
2538
|
-
}
|
|
2539
|
-
|
|
2540
2510
|
// Handle personification tag changes
|
|
2541
2511
|
if (
|
|
2542
2512
|
personification &&
|
|
@@ -2700,12 +2670,14 @@ const MemoriWidget = ({
|
|
|
2700
2670
|
setMemoriTyping(true);
|
|
2701
2671
|
|
|
2702
2672
|
// we have no chat history, we start by initial question
|
|
2673
|
+
const placeSpec = getPlaceSpecForEnterText(position);
|
|
2703
2674
|
const response = await postTextEnteredEvent({
|
|
2704
2675
|
sessionId: sessionID!,
|
|
2705
2676
|
text: initialQuestion,
|
|
2706
2677
|
...(memori.needsDateTime && {
|
|
2707
2678
|
dateUTC: DateTime.utc().toISO() ?? undefined,
|
|
2708
2679
|
}),
|
|
2680
|
+
...(placeSpec !== undefined && { place: placeSpec }),
|
|
2709
2681
|
});
|
|
2710
2682
|
|
|
2711
2683
|
// Handle 500 error from TextEnteredEvent
|
|
@@ -2734,10 +2706,6 @@ const MemoriWidget = ({
|
|
|
2734
2706
|
}
|
|
2735
2707
|
}
|
|
2736
2708
|
|
|
2737
|
-
// date and place events
|
|
2738
|
-
if (position && memori.needsPosition) {
|
|
2739
|
-
applyPosition(position, sessionID);
|
|
2740
|
-
}
|
|
2741
2709
|
}
|
|
2742
2710
|
// Default case - just translate and activate
|
|
2743
2711
|
else {
|
|
@@ -3330,8 +3298,7 @@ const MemoriWidget = ({
|
|
|
3330
3298
|
open={!!showPositionDrawer}
|
|
3331
3299
|
venue={position}
|
|
3332
3300
|
setVenue={setPosition}
|
|
3333
|
-
onClose={
|
|
3334
|
-
if (position) applyPosition(position);
|
|
3301
|
+
onClose={() => {
|
|
3335
3302
|
setShowPositionDrawer(false);
|
|
3336
3303
|
if (autoStart) {
|
|
3337
3304
|
onClickStart();
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// This file is auto-generated. Do not edit manually.
|
|
2
|
-
export const version = '8.
|
|
2
|
+
export const version = '8.27.0';
|