@memori.ai/memori-react 2.3.1 → 2.4.1

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.
@@ -42,11 +42,11 @@ import message from '../ui/Message';
42
42
  // Components
43
43
  import PositionDrawer from '../PositionDrawer/PositionDrawer';
44
44
  import MemoriAuth from '../Auth/Auth';
45
- import Chat from '../Chat/Chat';
46
- import StartPanel from '../StartPanel/StartPanel';
47
- import Avatar from '../Avatar/Avatar';
48
- import ChangeMode from '../ChangeMode/ChangeMode';
49
- import Header from '../Header/Header';
45
+ import Chat, { Props as ChatProps } from '../Chat/Chat';
46
+ import StartPanel, { Props as StartPanelProps } from '../StartPanel/StartPanel';
47
+ import Avatar, { Props as AvatarProps } from '../Avatar/Avatar';
48
+ import ChangeMode, { Props as ChangeModeProps } from '../ChangeMode/ChangeMode';
49
+ import Header, { Props as HeaderProps } from '../Header/Header';
50
50
  import AttachmentMediaModal from '../AttachmentMediaModal/AttachmentMediaModal';
51
51
  import AttachmentLinkModal from '../AttachmentLinkModal/AttachmentLinkModal';
52
52
  import PoweredBy from '../PoweredBy/PoweredBy';
@@ -147,13 +147,18 @@ let audioDestination: SpeakerAudioDestination;
147
147
  let audioContext: IAudioContext;
148
148
 
149
149
  export interface LayoutProps {
150
- header?: JSX.Element | null;
151
- avatar: JSX.Element;
152
- chat?: JSX.Element | null;
153
- startPanel: JSX.Element;
150
+ Header?: typeof Header;
151
+ headerProps?: HeaderProps;
152
+ Avatar: typeof Avatar;
153
+ avatarProps?: AvatarProps;
154
+ Chat?: typeof Chat;
155
+ chatProps?: ChatProps;
156
+ StartPanel: typeof StartPanel;
157
+ startPanelProps?: StartPanelProps;
154
158
  integrationStyle?: JSX.Element | null;
155
159
  integrationBackground?: JSX.Element | null;
156
- changeMode?: JSX.Element | null;
160
+ ChangeMode?: typeof ChangeMode;
161
+ changeModeProps?: ChangeModeProps;
157
162
  poweredBy?: JSX.Element | null;
158
163
  sessionId?: string;
159
164
  hasUserActivatedSpeak?: boolean;
@@ -257,8 +262,8 @@ const MemoriWidget = ({
257
262
  : null;
258
263
  const isMultilanguageEnabled = !!integrationConfig?.multilanguage;
259
264
  const [userLang, setUserLang] = useState(
260
- integrationConfig?.lang ??
261
- memoriLang ??
265
+ memoriLang ??
266
+ integrationConfig?.lang ??
262
267
  memori?.culture?.split('-')?.[0] ??
263
268
  language ??
264
269
  integrationConfig?.uiLang ??
@@ -2136,128 +2141,119 @@ const MemoriWidget = ({
2136
2141
  };
2137
2142
  }, []);
2138
2143
 
2139
- const header = (
2140
- <Header
2141
- memori={memori}
2142
- history={history}
2143
- showShare={showShare}
2144
- position={position}
2145
- setShowPositionDrawer={setShowPositionDrawer}
2146
- setShowSettingsDrawer={setShowSettingsDrawer}
2147
- showSpeaker={!!AZURE_COGNITIVE_SERVICES_TTS_KEY}
2148
- speakerMuted={muteSpeaker}
2149
- setSpeakerMuted={mute => {
2150
- setMuteSpeaker(mute);
2151
- if (mute) {
2152
- stopAudio();
2153
- } else {
2154
- audioContext = new AudioContext();
2155
- let buffer = audioContext.createBuffer(1, 10000, 22050);
2156
- let source = audioContext.createBufferSource();
2157
- source.buffer = buffer;
2158
- source.connect(audioContext.destination);
2159
- }
2160
- }}
2161
- showSettings={showSettings}
2162
- hasUserActivatedSpeak={hasUserActivatedSpeak}
2163
- showReload={selectedLayout === 'TOTEM'}
2164
- />
2165
- );
2144
+ const headerProps: HeaderProps = {
2145
+ memori,
2146
+ history,
2147
+ showShare,
2148
+ position,
2149
+ setShowPositionDrawer,
2150
+ setShowSettingsDrawer,
2151
+ showSpeaker: !!AZURE_COGNITIVE_SERVICES_TTS_KEY,
2152
+ speakerMuted: muteSpeaker,
2153
+ setSpeakerMuted: mute => {
2154
+ setMuteSpeaker(mute);
2155
+ if (mute) {
2156
+ stopAudio();
2157
+ } else {
2158
+ audioContext = new AudioContext();
2159
+ let buffer = audioContext.createBuffer(1, 10000, 22050);
2160
+ let source = audioContext.createBufferSource();
2161
+ source.buffer = buffer;
2162
+ source.connect(audioContext.destination);
2163
+ }
2164
+ },
2165
+ showSettings,
2166
+ hasUserActivatedSpeak,
2167
+ showReload: selectedLayout === 'TOTEM',
2168
+ };
2166
2169
 
2167
- const avatar = (
2168
- <Avatar
2169
- memori={memori}
2170
- integration={integration}
2171
- integrationConfig={integrationConfig}
2172
- tenant={tenant}
2173
- instruct={instruct}
2174
- avatar3dVisible={avatar3dVisible}
2175
- setAvatar3dVisible={setAvatar3dVisible}
2176
- hasUserActivatedSpeak={hasUserActivatedSpeak}
2177
- isPlayingAudio={isPlayingAudio}
2178
- loading={memoriTyping}
2179
- baseUrl={baseUrl}
2180
- apiUrl={apiUrl}
2181
- />
2182
- );
2170
+ const avatarProps: AvatarProps = {
2171
+ memori,
2172
+ integration,
2173
+ integrationConfig,
2174
+ tenant,
2175
+ instruct,
2176
+ avatar3dVisible,
2177
+ setAvatar3dVisible,
2178
+ hasUserActivatedSpeak,
2179
+ isPlayingAudio,
2180
+ loading: memoriTyping,
2181
+ baseUrl,
2182
+ apiUrl,
2183
+ };
2183
2184
 
2184
- const startPanel = (
2185
- <StartPanel
2186
- memori={memori}
2187
- tenant={tenant}
2188
- gamificationLevel={gamificationLevel}
2189
- language={language}
2190
- userLang={userLang}
2191
- setUserLang={setUserLang}
2192
- baseUrl={baseUrl}
2193
- apiUrl={apiUrl}
2194
- position={position}
2195
- openPositionDrawer={() => setShowPositionDrawer(true)}
2196
- integrationConfig={integrationConfig}
2197
- instruct={instruct}
2198
- sessionId={sessionId}
2199
- clickedStart={clickedStart}
2200
- onClickStart={onClickStart}
2201
- initializeTTS={initializeTTS}
2202
- />
2203
- );
2185
+ const startPanelProps: StartPanelProps = {
2186
+ memori: memori,
2187
+ tenant: tenant,
2188
+ gamificationLevel: gamificationLevel,
2189
+ language: language,
2190
+ userLang: userLang,
2191
+ setUserLang: setUserLang,
2192
+ baseUrl: baseUrl,
2193
+ apiUrl: apiUrl,
2194
+ position: position,
2195
+ openPositionDrawer: () => setShowPositionDrawer(true),
2196
+ integrationConfig: integrationConfig,
2197
+ instruct: instruct,
2198
+ sessionId: sessionId,
2199
+ clickedStart: clickedStart,
2200
+ onClickStart: onClickStart,
2201
+ initializeTTS: initializeTTS,
2202
+ };
2204
2203
 
2205
- const chat = sessionId ? (
2206
- <Chat
2207
- memori={memori}
2208
- sessionID={sessionId}
2209
- tenant={tenant}
2210
- translateTo={
2211
- isMultilanguageEnabled &&
2212
- userLang.toUpperCase() !==
2213
- (
2214
- memori.culture?.split('-')?.[0] ??
2215
- i18n.language ??
2216
- 'IT'
2217
- )?.toUpperCase()
2218
- ? userLang
2219
- : undefined
2220
- }
2221
- baseUrl={baseUrl}
2222
- apiUrl={apiUrl}
2223
- memoriTyping={memoriTyping}
2224
- history={layout === 'TOTEM' ? history.slice(-2) : history}
2225
- authToken={loginToken}
2226
- dialogState={currentDialogState}
2227
- setDialogState={setCurrentDialogState}
2228
- pushMessage={pushMessage}
2229
- simulateUserPrompt={simulateUserPrompt}
2230
- showDates={showDates}
2231
- showContextPerLine={showContextPerLine}
2232
- showAIicon={showAIicon}
2233
- client={client}
2234
- selectReceiverTag={selectReceiverTag}
2235
- preview={preview}
2236
- sendOnEnter={sendOnEnter}
2237
- microphoneMode={continuousSpeech ? 'CONTINUOUS' : 'HOLD_TO_TALK'}
2238
- setSendOnEnter={setSendOnEnter}
2239
- attachmentsMenuOpen={attachmentsMenuOpen}
2240
- setAttachmentsMenuOpen={setAttachmentsMenuOpen}
2241
- instruct={instruct}
2242
- showInputs={showInputs}
2243
- showMicrophone={!!AZURE_COGNITIVE_SERVICES_TTS_KEY}
2244
- userMessage={userMessage}
2245
- onChangeUserMessage={onChangeUserMessage}
2246
- sendMessage={(msg: string) => {
2247
- stopAudio();
2248
- stopListening();
2249
- sendMessage(msg);
2250
- setUserMessage('');
2251
- resetTranscript();
2252
- }}
2253
- stopListening={clearListening}
2254
- startListening={startListening}
2255
- stopAudio={stopAudio}
2256
- resetTranscript={resetTranscript}
2257
- listening={listening}
2258
- isPlayingAudio={isPlayingAudio}
2259
- />
2260
- ) : null;
2204
+ const chatProps: ChatProps = {
2205
+ memori,
2206
+ sessionID: sessionId || '',
2207
+ tenant,
2208
+ translateTo:
2209
+ isMultilanguageEnabled &&
2210
+ userLang.toUpperCase() !==
2211
+ (
2212
+ memori.culture?.split('-')?.[0] ??
2213
+ i18n.language ??
2214
+ 'IT'
2215
+ )?.toUpperCase()
2216
+ ? userLang
2217
+ : undefined,
2218
+ baseUrl,
2219
+ apiUrl,
2220
+ memoriTyping,
2221
+ history: layout === 'TOTEM' ? history.slice(-2) : history,
2222
+ authToken: loginToken,
2223
+ dialogState: currentDialogState,
2224
+ setDialogState: setCurrentDialogState,
2225
+ pushMessage,
2226
+ simulateUserPrompt,
2227
+ showDates,
2228
+ showContextPerLine,
2229
+ showAIicon,
2230
+ client,
2231
+ selectReceiverTag,
2232
+ preview,
2233
+ sendOnEnter,
2234
+ setSendOnEnter,
2235
+ microphoneMode: continuousSpeech ? 'CONTINUOUS' : 'HOLD_TO_TALK',
2236
+ attachmentsMenuOpen,
2237
+ setAttachmentsMenuOpen,
2238
+ instruct,
2239
+ showInputs,
2240
+ showMicrophone: !!AZURE_COGNITIVE_SERVICES_TTS_KEY,
2241
+ userMessage,
2242
+ onChangeUserMessage,
2243
+ sendMessage: (msg: string) => {
2244
+ stopAudio();
2245
+ stopListening();
2246
+ sendMessage(msg);
2247
+ setUserMessage('');
2248
+ resetTranscript();
2249
+ },
2250
+ stopListening: clearListening,
2251
+ startListening,
2252
+ stopAudio,
2253
+ resetTranscript,
2254
+ listening,
2255
+ isPlayingAudio,
2256
+ };
2261
2257
 
2262
2258
  const integrationBackground =
2263
2259
  integration && globalBackgroundUrl ? (
@@ -2280,13 +2276,11 @@ const MemoriWidget = ({
2280
2276
  setHasUserActivatedSpeak(false);
2281
2277
  setClickedStart(false);
2282
2278
  };
2283
- const changeMode = (
2284
- <ChangeMode
2285
- canInstruct={!!memori.giverTag}
2286
- instruct={instruct}
2287
- onChangeMode={onChangeMode}
2288
- />
2289
- );
2279
+ const changeModeProps: ChangeModeProps = {
2280
+ canInstruct: !!memori.giverTag,
2281
+ instruct: !!instruct,
2282
+ onChangeMode,
2283
+ };
2290
2284
 
2291
2285
  const poweredBy = <PoweredBy tenant={tenant} userLang={userLang} />;
2292
2286
 
@@ -2328,13 +2322,18 @@ const MemoriWidget = ({
2328
2322
  style={{ height }}
2329
2323
  >
2330
2324
  <Layout
2331
- header={header}
2332
- avatar={avatar}
2333
- chat={chat}
2334
- startPanel={startPanel}
2325
+ Header={Header}
2326
+ headerProps={headerProps}
2327
+ Avatar={Avatar}
2328
+ avatarProps={avatarProps}
2329
+ Chat={Chat}
2330
+ chatProps={chatProps}
2331
+ StartPanel={StartPanel}
2332
+ startPanelProps={startPanelProps}
2335
2333
  integrationStyle={integrationStyle}
2336
2334
  integrationBackground={integrationBackground}
2337
- changeMode={changeMode}
2335
+ ChangeMode={ChangeMode}
2336
+ changeModeProps={changeModeProps}
2338
2337
  poweredBy={poweredBy}
2339
2338
  sessionId={sessionId}
2340
2339
  hasUserActivatedSpeak={hasUserActivatedSpeak}
@@ -3,12 +3,16 @@ import Spin from '../ui/Spin';
3
3
  import { LayoutProps } from '../MemoriWidget/MemoriWidget';
4
4
 
5
5
  const ChatLayout: React.FC<LayoutProps> = ({
6
- header,
7
- chat,
8
- startPanel,
6
+ Header,
7
+ headerProps,
8
+ Chat,
9
+ chatProps,
10
+ StartPanel,
11
+ startPanelProps,
9
12
  integrationStyle,
10
13
  integrationBackground,
11
- changeMode,
14
+ ChangeMode,
15
+ changeModeProps,
12
16
  sessionId,
13
17
  hasUserActivatedSpeak,
14
18
  showInstruct = false,
@@ -21,12 +25,20 @@ const ChatLayout: React.FC<LayoutProps> = ({
21
25
 
22
26
  <Spin spinning={loading} className="memori-chat-layout">
23
27
  {poweredBy}
24
- {showInstruct && changeMode}
28
+ {showInstruct && ChangeMode && changeModeProps && (
29
+ <ChangeMode {...changeModeProps} />
30
+ )}
25
31
 
26
- <div className="memori-chat-layout--header">{header}</div>
32
+ <div className="memori-chat-layout--header">
33
+ {Header && headerProps && <Header {...headerProps} />}
34
+ </div>
27
35
 
28
36
  <div className="memori-chat-layout--controls">
29
- {sessionId && hasUserActivatedSpeak ? chat : startPanel}
37
+ {sessionId && hasUserActivatedSpeak && Chat && chatProps ? (
38
+ <Chat {...chatProps} />
39
+ ) : startPanelProps ? (
40
+ <StartPanel {...startPanelProps} />
41
+ ) : null}
30
42
  </div>
31
43
  </Spin>
32
44
  </>
@@ -3,13 +3,18 @@ import Spin from '../ui/Spin';
3
3
  import { LayoutProps } from '../MemoriWidget/MemoriWidget';
4
4
 
5
5
  const FullPageLayout: React.FC<LayoutProps> = ({
6
- header,
7
- avatar,
8
- chat,
9
- startPanel,
6
+ Header,
7
+ headerProps,
8
+ Avatar,
9
+ avatarProps,
10
+ Chat,
11
+ chatProps,
12
+ StartPanel,
13
+ startPanelProps,
10
14
  integrationStyle,
11
15
  integrationBackground,
12
- changeMode,
16
+ ChangeMode,
17
+ changeModeProps,
13
18
  sessionId,
14
19
  hasUserActivatedSpeak,
15
20
  showInstruct = false,
@@ -21,16 +26,22 @@ const FullPageLayout: React.FC<LayoutProps> = ({
21
26
  {integrationBackground}
22
27
 
23
28
  <Spin spinning={loading}>
24
- {showInstruct && changeMode}
29
+ {showInstruct && ChangeMode && changeModeProps && (
30
+ <ChangeMode {...changeModeProps} />
31
+ )}
25
32
 
26
- {header}
33
+ {Header && headerProps && <Header {...headerProps} />}
27
34
 
28
35
  <div className="memori--grid">
29
36
  <div className="memori--grid-column memori--grid-column-left">
30
- {avatar}
37
+ {Avatar && avatarProps && <Avatar {...avatarProps} />}
31
38
  </div>
32
39
  <div className="memori--grid-column memori--grid-column-right">
33
- {sessionId && hasUserActivatedSpeak ? chat : startPanel}
40
+ {sessionId && hasUserActivatedSpeak && Chat && chatProps ? (
41
+ <Chat {...chatProps} />
42
+ ) : startPanelProps ? (
43
+ <StartPanel {...startPanelProps} />
44
+ ) : null}
34
45
  </div>
35
46
 
36
47
  {poweredBy}
@@ -3,13 +3,18 @@ import Spin from '../ui/Spin';
3
3
  import { LayoutProps } from '../MemoriWidget/MemoriWidget';
4
4
 
5
5
  const TotemLayout: React.FC<LayoutProps> = ({
6
- header,
7
- avatar,
8
- chat,
9
- startPanel,
6
+ Header,
7
+ headerProps,
8
+ Avatar,
9
+ avatarProps,
10
+ Chat,
11
+ chatProps,
12
+ StartPanel,
13
+ startPanelProps,
10
14
  integrationStyle,
11
15
  integrationBackground,
12
- changeMode,
16
+ ChangeMode,
17
+ changeModeProps,
13
18
  sessionId,
14
19
  hasUserActivatedSpeak,
15
20
  showInstruct = false,
@@ -22,14 +27,24 @@ const TotemLayout: React.FC<LayoutProps> = ({
22
27
 
23
28
  <Spin spinning={loading} className="memori-totem-layout">
24
29
  {poweredBy}
25
- {showInstruct && changeMode}
30
+ {showInstruct && ChangeMode && changeModeProps && (
31
+ <ChangeMode {...changeModeProps} />
32
+ )}
26
33
 
27
- <div className="memori-totem-layout--header">{header}</div>
34
+ <div className="memori-totem-layout--header">
35
+ {Header && headerProps && <Header {...headerProps} />}
36
+ </div>
28
37
 
29
- <div className="memori-totem-layout--avatar">{avatar}</div>
38
+ <div className="memori-totem-layout--avatar">
39
+ {Avatar && avatarProps && <Avatar {...avatarProps} />}
40
+ </div>
30
41
 
31
42
  <div className="memori-totem-layout--controls">
32
- {sessionId && hasUserActivatedSpeak ? chat : startPanel}
43
+ {sessionId && hasUserActivatedSpeak && Chat && chatProps ? (
44
+ <Chat {...chatProps} />
45
+ ) : startPanelProps ? (
46
+ <StartPanel {...startPanelProps} />
47
+ ) : null}
33
48
  </div>
34
49
  </Spin>
35
50
  </>
@@ -23,13 +23,18 @@ const meta: Meta = {
23
23
  export default meta;
24
24
 
25
25
  const CustomLayout: React.FC<LayoutProps> = ({
26
- header,
27
- avatar,
28
- chat,
29
- startPanel,
26
+ Header,
27
+ headerProps,
28
+ Avatar,
29
+ avatarProps,
30
+ Chat,
31
+ chatProps,
32
+ StartPanel,
33
+ startPanelProps,
30
34
  integrationStyle,
31
35
  integrationBackground,
32
- changeMode,
36
+ ChangeMode,
37
+ changeModeProps,
33
38
  sessionId,
34
39
  hasUserActivatedSpeak,
35
40
  showInstruct = false,
@@ -44,7 +49,11 @@ const CustomLayout: React.FC<LayoutProps> = ({
44
49
  {poweredBy}
45
50
 
46
51
  <div className="memori-mycustom-layout--controls">
47
- {sessionId && hasUserActivatedSpeak ? chat : startPanel}
52
+ {sessionId && hasUserActivatedSpeak && Chat && chatProps ? (
53
+ <Chat {...chatProps} />
54
+ ) : startPanelProps ? (
55
+ <StartPanel {...startPanelProps} />
56
+ ) : null}
48
57
  </div>
49
58
  </Spin>
50
59
  </>