@mitodl/smoot-design 3.5.0 → 3.6.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/dist/bundles/remoteAiChatDrawer.es.js +23 -20
- package/dist/bundles/remoteAiChatDrawer.umd.js +7 -7
- package/dist/cjs/bundles/RemoteAiChatDrawer/RemoteAiChatDrawer.d.ts +7 -1
- package/dist/cjs/bundles/RemoteAiChatDrawer/RemoteAiChatDrawer.js +5 -3
- package/dist/esm/bundles/RemoteAiChatDrawer/RemoteAiChatDrawer.d.ts +7 -1
- package/dist/esm/bundles/RemoteAiChatDrawer/RemoteAiChatDrawer.js +5 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
import { AiChatMessage } from "../../components/AiChat/types";
|
|
2
3
|
import type { AiChatProps } from "../../components/AiChat/AiChat";
|
|
3
4
|
type ChatInitMessage = {
|
|
4
5
|
type: "smoot-design::chat-open";
|
|
@@ -8,6 +9,7 @@ type ChatInitMessage = {
|
|
|
8
9
|
conversationStarters?: AiChatProps["conversationStarters"];
|
|
9
10
|
initialMessages: AiChatProps["initialMessages"];
|
|
10
11
|
apiUrl: AiChatProps["requestOpts"]["apiUrl"];
|
|
12
|
+
requestBody?: Record<string, unknown>;
|
|
11
13
|
};
|
|
12
14
|
};
|
|
13
15
|
type AiChatDrawerProps = {
|
|
@@ -19,9 +21,13 @@ type AiChatDrawerProps = {
|
|
|
19
21
|
messageOrigin: string;
|
|
20
22
|
/**
|
|
21
23
|
* Transform the body of the request before sending it to the server.
|
|
24
|
+
* Its result will be merged with the per-message requestBody opt, with
|
|
25
|
+
* transformBody taking precedence.
|
|
26
|
+
*
|
|
22
27
|
* *This cannot be supplied via message events since the function is not serializable.*
|
|
28
|
+
*
|
|
23
29
|
*/
|
|
24
|
-
transformBody?:
|
|
30
|
+
transformBody?: (messages: AiChatMessage[]) => Iterable<unknown>;
|
|
25
31
|
};
|
|
26
32
|
declare const AiChatDrawer: React.FC<AiChatDrawerProps>;
|
|
27
33
|
export { AiChatDrawer };
|
|
@@ -4,7 +4,8 @@ exports.AiChatDrawer = void 0;
|
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const AiChat_1 = require("../../components/AiChat/AiChat");
|
|
6
6
|
const Drawer_1 = require("@mui/material/Drawer");
|
|
7
|
-
const
|
|
7
|
+
const identity = (x) => x;
|
|
8
|
+
const AiChatDrawer = ({ messageOrigin, transformBody = identity, className, }) => {
|
|
8
9
|
const [open, setOpen] = React.useState(false);
|
|
9
10
|
const [chatSettings, setChatSettings] = React.useState(null);
|
|
10
11
|
React.useEffect(() => {
|
|
@@ -20,7 +21,6 @@ const AiChatDrawer = ({ messageOrigin, transformBody, className, }) => {
|
|
|
20
21
|
setChatSettings(event.data.payload);
|
|
21
22
|
}
|
|
22
23
|
};
|
|
23
|
-
console.log("Attaching listener");
|
|
24
24
|
window.addEventListener("message", cb);
|
|
25
25
|
return () => {
|
|
26
26
|
window.removeEventListener("message", cb);
|
|
@@ -37,7 +37,9 @@ const AiChatDrawer = ({ messageOrigin, transformBody, className, }) => {
|
|
|
37
37
|
},
|
|
38
38
|
},
|
|
39
39
|
}, anchor: "right", open: open, onClose: () => setOpen(false) }, chatSettings ? (React.createElement(AiChat_1.AiChat, Object.assign({}, chatSettings, { requestOpts: {
|
|
40
|
-
transformBody
|
|
40
|
+
transformBody: (messages) => {
|
|
41
|
+
return Object.assign(Object.assign({}, chatSettings.requestBody), transformBody === null || transformBody === void 0 ? void 0 : transformBody(messages));
|
|
42
|
+
},
|
|
41
43
|
apiUrl: chatSettings === null || chatSettings === void 0 ? void 0 : chatSettings.apiUrl,
|
|
42
44
|
}, onClose: () => setOpen(false) }))) : null));
|
|
43
45
|
};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
|
+
import { AiChatMessage } from "../../components/AiChat/types";
|
|
2
3
|
import type { AiChatProps } from "../../components/AiChat/AiChat";
|
|
3
4
|
type ChatInitMessage = {
|
|
4
5
|
type: "smoot-design::chat-open";
|
|
@@ -8,6 +9,7 @@ type ChatInitMessage = {
|
|
|
8
9
|
conversationStarters?: AiChatProps["conversationStarters"];
|
|
9
10
|
initialMessages: AiChatProps["initialMessages"];
|
|
10
11
|
apiUrl: AiChatProps["requestOpts"]["apiUrl"];
|
|
12
|
+
requestBody?: Record<string, unknown>;
|
|
11
13
|
};
|
|
12
14
|
};
|
|
13
15
|
type AiChatDrawerProps = {
|
|
@@ -19,9 +21,13 @@ type AiChatDrawerProps = {
|
|
|
19
21
|
messageOrigin: string;
|
|
20
22
|
/**
|
|
21
23
|
* Transform the body of the request before sending it to the server.
|
|
24
|
+
* Its result will be merged with the per-message requestBody opt, with
|
|
25
|
+
* transformBody taking precedence.
|
|
26
|
+
*
|
|
22
27
|
* *This cannot be supplied via message events since the function is not serializable.*
|
|
28
|
+
*
|
|
23
29
|
*/
|
|
24
|
-
transformBody?:
|
|
30
|
+
transformBody?: (messages: AiChatMessage[]) => Iterable<unknown>;
|
|
25
31
|
};
|
|
26
32
|
declare const AiChatDrawer: React.FC<AiChatDrawerProps>;
|
|
27
33
|
export { AiChatDrawer };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { AiChat } from "../../components/AiChat/AiChat";
|
|
3
3
|
import Drawer from "@mui/material/Drawer";
|
|
4
|
-
const
|
|
4
|
+
const identity = (x) => x;
|
|
5
|
+
const AiChatDrawer = ({ messageOrigin, transformBody = identity, className, }) => {
|
|
5
6
|
const [open, setOpen] = React.useState(false);
|
|
6
7
|
const [chatSettings, setChatSettings] = React.useState(null);
|
|
7
8
|
React.useEffect(() => {
|
|
@@ -17,7 +18,6 @@ const AiChatDrawer = ({ messageOrigin, transformBody, className, }) => {
|
|
|
17
18
|
setChatSettings(event.data.payload);
|
|
18
19
|
}
|
|
19
20
|
};
|
|
20
|
-
console.log("Attaching listener");
|
|
21
21
|
window.addEventListener("message", cb);
|
|
22
22
|
return () => {
|
|
23
23
|
window.removeEventListener("message", cb);
|
|
@@ -34,7 +34,9 @@ const AiChatDrawer = ({ messageOrigin, transformBody, className, }) => {
|
|
|
34
34
|
},
|
|
35
35
|
},
|
|
36
36
|
}, anchor: "right", open: open, onClose: () => setOpen(false) }, chatSettings ? (React.createElement(AiChat, Object.assign({}, chatSettings, { requestOpts: {
|
|
37
|
-
transformBody
|
|
37
|
+
transformBody: (messages) => {
|
|
38
|
+
return Object.assign(Object.assign({}, chatSettings.requestBody), transformBody === null || transformBody === void 0 ? void 0 : transformBody(messages));
|
|
39
|
+
},
|
|
38
40
|
apiUrl: chatSettings === null || chatSettings === void 0 ? void 0 : chatSettings.apiUrl,
|
|
39
41
|
}, onClose: () => setOpen(false) }))) : null));
|
|
40
42
|
};
|