@blocklet/pages-kit 0.2.324 → 0.2.326
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/lib/cjs/builtin/async/ai-runtime/components/{MarkdownRenderer.js → MarkdownRenderer/index.js} +6 -12
- package/lib/cjs/builtin/async/ai-runtime/components/ShareActions/index.js +1 -1
- package/lib/cjs/builtin/async/ai-runtime/components/SocialShare.js +5 -2
- package/lib/cjs/builtin/async/ai-runtime/constants.js +5 -1
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/MessageView.js +24 -9
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/MessagesView.js +1 -2
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningMessageView.js +20 -7
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Output.js +4 -1
- package/lib/cjs/builtin/async/ai-runtime/state/runtime.js +8 -6
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/builtin/async/ai-runtime/components/{MarkdownRenderer.js → MarkdownRenderer/index.js} +6 -12
- package/lib/esm/builtin/async/ai-runtime/components/ShareActions/index.js +1 -1
- package/lib/esm/builtin/async/ai-runtime/components/SocialShare.js +5 -2
- package/lib/esm/builtin/async/ai-runtime/constants.js +4 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/MessageView.js +22 -9
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/MessagesView.js +1 -2
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningMessageView.js +22 -9
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Output.js +4 -1
- package/lib/esm/builtin/async/ai-runtime/state/runtime.js +8 -6
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/types/builtin/async/ai-runtime/constants.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/MessageView.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningMessageView.d.ts +3 -1
- package/lib/types/builtin/session.d.ts +1 -0
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +3 -3
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningQuestionsView.js +0 -20
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningQuestionsView.js +0 -14
- package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningQuestionsView.d.ts +0 -1
- /package/lib/types/builtin/async/ai-runtime/components/{MarkdownRenderer.d.ts → MarkdownRenderer/index.d.ts} +0 -0
|
@@ -43,19 +43,12 @@ const material_1 = require("@mui/material");
|
|
|
43
43
|
const react_2 = __importStar(require("react"));
|
|
44
44
|
const react_markdown_1 = __importDefault(require("react-markdown"));
|
|
45
45
|
const remark_gfm_1 = __importDefault(require("remark-gfm"));
|
|
46
|
-
const locale_1 = require("
|
|
47
|
-
const react_syntax_highlighter_1 = __importDefault(require("
|
|
48
|
-
const ActionButton_1 = __importDefault(require("
|
|
46
|
+
const locale_1 = require("../../../../locale");
|
|
47
|
+
const react_syntax_highlighter_1 = __importDefault(require("../../../react-syntax-highlighter"));
|
|
48
|
+
const ActionButton_1 = __importDefault(require("../ActionButton"));
|
|
49
49
|
const ReactSyntaxHighlighter = react_2.default.lazy(() => (0, react_syntax_highlighter_1.default)().then((m) => ({ default: m.Prism })));
|
|
50
50
|
const MarkdownRenderer = (0, material_1.styled)((props) => ((0, jsx_runtime_1.jsx)(react_markdown_1.default, Object.assign({}, props, { remarkPlugins: [remark_gfm_1.default], components: {
|
|
51
51
|
pre: MarkdownPre,
|
|
52
|
-
code: (_a) => {
|
|
53
|
-
var { node, inline, className, children } = _a, props = __rest(_a, ["node", "inline", "className", "children"]);
|
|
54
|
-
if (!children)
|
|
55
|
-
return null;
|
|
56
|
-
const match = /language-(\w+)/.exec(className || '');
|
|
57
|
-
return !inline ? ((0, jsx_runtime_1.jsx)(react_2.Suspense, { children: (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ component: ReactSyntaxHighlighter, language: match === null || match === void 0 ? void 0 : match[1] }, props, { sx: { borderRadius: 1 }, children: String(children).replace(/\n$/, '') })) })) : ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ component: "code", className: className }, props, { children: children })));
|
|
58
|
-
},
|
|
59
52
|
table: ({ className, children }) => {
|
|
60
53
|
return ((0, jsx_runtime_1.jsx)(material_1.Box, { sx: { overflow: 'auto', my: 1 }, children: (0, jsx_runtime_1.jsx)("table", { className: className, children: children }) }));
|
|
61
54
|
},
|
|
@@ -134,7 +127,8 @@ const MarkdownRenderer = (0, material_1.styled)((props) => ((0, jsx_runtime_1.js
|
|
|
134
127
|
}
|
|
135
128
|
`;
|
|
136
129
|
exports.default = MarkdownRenderer;
|
|
137
|
-
function MarkdownPre(
|
|
130
|
+
function MarkdownPre(_a) {
|
|
131
|
+
var { children } = _a, props = __rest(_a, ["children"]);
|
|
138
132
|
const { t } = (0, locale_1.useLocaleContext)();
|
|
139
133
|
const childrenProps = children === null || children === void 0 ? void 0 : children.props;
|
|
140
134
|
if (!(childrenProps === null || childrenProps === void 0 ? void 0 : childrenProps.children))
|
|
@@ -148,5 +142,5 @@ function MarkdownPre({ children }) {
|
|
|
148
142
|
'> pre': { mt: '0 !important' },
|
|
149
143
|
}, children: [(0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", alignItems: "center", p: 0.5, pl: 1.5, borderBottom: 1, borderColor: "grey.200", children: [(0, jsx_runtime_1.jsx)(material_1.Box, { children: language }), (0, jsx_runtime_1.jsx)(material_1.Box, { flex: 1 }), (0, jsx_runtime_1.jsx)(ActionButton_1.default, { autoReset: true, tip: t('copyToClipboard'), tipSucceed: t('copied'), title: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "tabler:copy" }), titleSucceed: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "tabler:copy-check" }), sx: { minWidth: 32, minHeight: 32, p: 0, fontSize: 18 }, onClick: () => {
|
|
150
144
|
window.navigator.clipboard.writeText(childrenProps.children);
|
|
151
|
-
} })] }), children] }));
|
|
145
|
+
} })] }), (0, jsx_runtime_1.jsx)(react_2.Suspense, { children: (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ component: ReactSyntaxHighlighter, language: match === null || match === void 0 ? void 0 : match[1] }, props, { sx: { borderRadius: 1, bgcolor: 'red' }, children: String(childrenProps.children).replace(/\n$/, '') })) })] }));
|
|
152
146
|
}
|
|
@@ -105,7 +105,7 @@ function ShareCopy() {
|
|
|
105
105
|
const image = (_f = (_e = (_d = (_c = (_b = message.result) === null || _b === void 0 ? void 0 : _b.objects) === null || _c === void 0 ? void 0 : _c.find((i) => { var _a; return (_a = i.data[types_1.RuntimeOutputVariable.images]) === null || _a === void 0 ? void 0 : _a.length; })) === null || _d === void 0 ? void 0 : _d.data[types_1.RuntimeOutputVariable.images]) === null || _e === void 0 ? void 0 : _e.at(0)) === null || _f === void 0 ? void 0 : _f.url;
|
|
106
106
|
if (!content && !image)
|
|
107
107
|
return null;
|
|
108
|
-
return ((0, jsx_runtime_1.jsx)(StyledActionButton, { tip: t('copy'), tipSucceed: t('copied'), title: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "tabler:copy" }), titleSucceed: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "tabler:copy-check" }), onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
108
|
+
return ((0, jsx_runtime_1.jsx)(StyledActionButton, { autoReset: true, tip: t('copy'), tipSucceed: t('copied'), title: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "tabler:copy" }), titleSucceed: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "tabler:copy-check" }), onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
109
109
|
if (content) {
|
|
110
110
|
window.navigator.clipboard.writeText(content);
|
|
111
111
|
}
|
|
@@ -64,6 +64,9 @@ function SocialShareMenu(_a) {
|
|
|
64
64
|
gap: 1.5,
|
|
65
65
|
minWidth: 120,
|
|
66
66
|
lineHeight: '1!important',
|
|
67
|
+
width: '100%',
|
|
68
|
+
border: 'none',
|
|
69
|
+
bgcolor: 'transparent',
|
|
67
70
|
};
|
|
68
71
|
const iconProps = {
|
|
69
72
|
bgStyle: { fill: '#fff' },
|
|
@@ -72,14 +75,14 @@ function SocialShareMenu(_a) {
|
|
|
72
75
|
borderRadius: '6px',
|
|
73
76
|
},
|
|
74
77
|
};
|
|
75
|
-
return ((0, jsx_runtime_1.jsx)(MenuButton_1.default, Object.assign({ MenuProps: MenuProps, menus: [
|
|
78
|
+
return ((0, jsx_runtime_1.jsx)(MenuButton_1.default, Object.assign({ MenuProps: Object.assign(Object.assign({}, MenuProps), { sx: { li: { p: 0, button: { px: '8px !important', py: '4px !important' } } } }), menus: [
|
|
76
79
|
(0, jsx_runtime_1.jsx)(material_1.MenuItem, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, { component: react_share_1.TwitterShareButton, url: url, title: content, sx: buttonSx, children: [(0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ component: react_share_1.XIcon, sx: itemIconSx, round: true }, iconProps)), (0, jsx_runtime_1.jsx)("span", { children: t('socialShare.shareToX') })] }) }, "shareOnX"),
|
|
77
80
|
(0, jsx_runtime_1.jsx)(material_1.MenuItem, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, { component: react_share_1.TelegramShareButton, url: url, title: content, sx: buttonSx, children: [(0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ component: react_share_1.TelegramIcon, sx: itemIconSx, round: true }, iconProps)), (0, jsx_runtime_1.jsx)("span", { children: t('socialShare.shareToTelegram') })] }) }, "shareOnTelegram"),
|
|
78
81
|
(0, jsx_runtime_1.jsx)(material_1.MenuItem, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, { component: react_share_1.RedditShareButton, url: url, title: content, sx: buttonSx, children: [(0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ component: react_share_1.RedditIcon, sx: itemIconSx, round: true }, iconProps)), (0, jsx_runtime_1.jsx)("span", { children: t('socialShare.shareToReddit') })] }) }, "shareOnReddit"),
|
|
79
82
|
(0, jsx_runtime_1.jsx)(material_1.MenuItem, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, { component: react_share_1.WeiboShareButton, url: url, title: content, sx: buttonSx, children: [(0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ component: react_share_1.WeiboIcon, sx: itemIconSx, round: true }, iconProps)), (0, jsx_runtime_1.jsx)("span", { children: t('socialShare.shareToWeibo') })] }) }, "shareOnWeibo"),
|
|
80
83
|
(0, jsx_runtime_1.jsx)(material_1.MenuItem, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, { component: react_share_1.FacebookShareButton, url: url, sx: buttonSx, children: [(0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ component: react_share_1.FacebookIcon, sx: itemIconSx, round: true }, iconProps)), (0, jsx_runtime_1.jsx)("span", { children: t('socialShare.shareToFacebook') })] }) }, "shareOnFacebook"),
|
|
81
84
|
(0, jsx_runtime_1.jsx)(material_1.MenuItem, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, { component: react_share_1.LinkedinShareButton, url: url, summary: content, sx: buttonSx, children: [(0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ component: react_share_1.LinkedinIcon, sx: itemIconSx, round: true }, iconProps)), (0, jsx_runtime_1.jsx)("span", { children: t('socialShare.shareToLinkedin') })] }) }, "shareOnLinkedin"),
|
|
82
|
-
!disableCopyLink && ((0, jsx_runtime_1.jsx)(material_1.MenuItem, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, { component: "
|
|
85
|
+
!disableCopyLink && ((0, jsx_runtime_1.jsx)(material_1.MenuItem, { children: (0, jsx_runtime_1.jsxs)(material_1.Box, { component: "button", sx: buttonSx, onClick: () => {
|
|
83
86
|
window.navigator.clipboard.writeText(url);
|
|
84
87
|
}, children: [(0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ sx: itemIconSx, round: true }, iconProps, { children: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "tabler:link" }) })), (0, jsx_runtime_1.jsx)("span", { children: t('socialShare.copyLink') })] }) }, "copyToClipboard")),
|
|
85
88
|
].filter(Boolean) }, restProps, { children: children })));
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getDefaultOutputComponent = exports.DEFAULT_OUTPUT_COMPONENTS = exports.IMAGES_VIEW_ID = exports.SHARE_VIEW_ID = exports.REFERENCED_LINKS_VIEW_ID = exports.SUGGESTED_QUESTIONS_VIEW_ID = exports.MARKDOWN_VIEW_ID = exports.DEFAULT_OUTPUT_COMPONENT_ID = exports.DEFAULT_INPUT_COMPONENT_ID = exports.DEFAULT_PAGE_COMPONENT_ID = exports.PAYMENT_KIT_DID = exports.AI_STUDIO_DID = void 0;
|
|
3
|
+
exports.getDefaultOutputComponent = exports.DEFAULT_OUTPUT_COMPONENTS = exports.OPENING_QUESTIONS_VIEW_ID = exports.IMAGES_VIEW_ID = exports.SHARE_VIEW_ID = exports.REFERENCED_LINKS_VIEW_ID = exports.SUGGESTED_QUESTIONS_VIEW_ID = exports.MARKDOWN_VIEW_ID = exports.DEFAULT_OUTPUT_COMPONENT_ID = exports.DEFAULT_INPUT_COMPONENT_ID = exports.DEFAULT_PAGE_COMPONENT_ID = exports.PAYMENT_KIT_DID = exports.AI_STUDIO_DID = void 0;
|
|
4
4
|
const types_1 = require("@blocklet/ai-runtime/types");
|
|
5
5
|
exports.AI_STUDIO_DID = 'z8iZpog7mcgcgBZzTiXJCWESvmnRrQmnd3XBB';
|
|
6
6
|
exports.PAYMENT_KIT_DID = 'z2qaCNvKMv5GjouKdcDWexv6WqtHbpNPQDnAk';
|
|
@@ -12,6 +12,7 @@ exports.SUGGESTED_QUESTIONS_VIEW_ID = '6u8m11ss7fvu8t7i';
|
|
|
12
12
|
exports.REFERENCED_LINKS_VIEW_ID = 'baqmaoccdntqwayc';
|
|
13
13
|
exports.SHARE_VIEW_ID = 'jfq3df9z8lkk9not';
|
|
14
14
|
exports.IMAGES_VIEW_ID = 'txirtdgx8h2bmo7s';
|
|
15
|
+
exports.OPENING_QUESTIONS_VIEW_ID = 'vgsgsvnhud0cq37v';
|
|
15
16
|
exports.DEFAULT_OUTPUT_COMPONENTS = {
|
|
16
17
|
[types_1.RuntimeOutputVariable.text]: {
|
|
17
18
|
componentId: exports.MARKDOWN_VIEW_ID,
|
|
@@ -31,6 +32,9 @@ exports.DEFAULT_OUTPUT_COMPONENTS = {
|
|
|
31
32
|
[types_1.RuntimeOutputVariable.share]: {
|
|
32
33
|
componentId: exports.SHARE_VIEW_ID,
|
|
33
34
|
},
|
|
35
|
+
[types_1.RuntimeOutputVariable.openingQuestions]: {
|
|
36
|
+
componentId: exports.OPENING_QUESTIONS_VIEW_ID,
|
|
37
|
+
},
|
|
34
38
|
};
|
|
35
39
|
function getDefaultOutputComponent(output) {
|
|
36
40
|
return exports.DEFAULT_OUTPUT_COMPONENTS[output.name];
|
|
@@ -22,10 +22,22 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
+
var t = {};
|
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
+
t[p] = s[p];
|
|
29
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
+
t[p[i]] = s[p[i]];
|
|
33
|
+
}
|
|
34
|
+
return t;
|
|
35
|
+
};
|
|
25
36
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
26
37
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
38
|
};
|
|
28
39
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.MessageBodyContainer = void 0;
|
|
29
41
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
30
42
|
const material_1 = require("@mui/material");
|
|
31
43
|
const react_1 = require("react");
|
|
@@ -45,14 +57,17 @@ const MessageView = (0, react_1.memo)(({ message }) => {
|
|
|
45
57
|
const { hideAgentAvatar, hideUserInputs } = (_a = (0, ComponentPreferences_1.useComponentPreferences)()) !== null && _a !== void 0 ? _a : {};
|
|
46
58
|
if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
|
|
47
59
|
return null;
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
borderTopRightRadius: '2px',
|
|
51
|
-
px: 2,
|
|
52
|
-
py: 1,
|
|
53
|
-
marginTop: 0.5,
|
|
54
|
-
maxWidth: 'calc(100% - 40px)',
|
|
55
|
-
bgcolor: 'rgba(239, 246, 255, 1)',
|
|
56
|
-
}, children: (0, jsx_runtime_1.jsx)(UserMessageView_1.default, {}) }) }) }) })), (0, jsx_runtime_1.jsx)(material_1.Box, { children: !hideAgentAvatar ? ((0, jsx_runtime_1.jsx)(UserInfo_1.default, { name: profile.name, did: (_e = globalThis.blocklet) === null || _e === void 0 ? void 0 : _e.appId, avatar: profile.avatar, time: message.createdAt, alignItems: "flex-start", children: (0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProperties }) })) : ((0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProperties })) })] }) }) }));
|
|
60
|
+
const agentMessage = ((0, jsx_runtime_1.jsx)(MessageBodyContainer, { messageRole: "assistant", children: (0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProperties }) }));
|
|
61
|
+
return ((0, jsx_runtime_1.jsx)(CurrentAgent_1.default, { agentId: message.assistantId, children: (0, jsx_runtime_1.jsx)(CurrentMessage_1.default, { message: message, children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { gap: 2, children: [!hideUserInputs && ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(UserInfo_1.default, { name: (_b = authSession.user) === null || _b === void 0 ? void 0 : _b.fullName, did: (_c = authSession.user) === null || _c === void 0 ? void 0 : _c.did, avatar: (_d = authSession.user) === null || _d === void 0 ? void 0 : _d.avatar, time: message.createdAt, reverse: true, alignItems: "flex-start", children: (0, jsx_runtime_1.jsx)(material_1.Stack, { sx: { alignItems: 'flex-end' }, children: (0, jsx_runtime_1.jsx)(MessageBodyContainer, { messageRole: "user", children: (0, jsx_runtime_1.jsx)(UserMessageView_1.default, {}) }) }) }) })), (0, jsx_runtime_1.jsx)(material_1.Box, { children: !hideAgentAvatar ? ((0, jsx_runtime_1.jsx)(UserInfo_1.default, { name: profile.name, did: (_e = globalThis.blocklet) === null || _e === void 0 ? void 0 : _e.appId, avatar: profile.avatar, time: message.createdAt, alignItems: "flex-start", children: agentMessage })) : (agentMessage) })] }) }) }));
|
|
57
62
|
});
|
|
58
63
|
exports.default = MessageView;
|
|
64
|
+
function MessageBodyContainer(_a) {
|
|
65
|
+
var _b;
|
|
66
|
+
var { messageRole } = _a, props = __rest(_a, ["messageRole"]);
|
|
67
|
+
const preferences = (0, ComponentPreferences_1.useComponentPreferences)();
|
|
68
|
+
const hasBg = !!((_b = preferences === null || preferences === void 0 ? void 0 : preferences.backgroundImage) === null || _b === void 0 ? void 0 : _b.url);
|
|
69
|
+
const hideUserMessage = preferences === null || preferences === void 0 ? void 0 : preferences.hideUserInputs;
|
|
70
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({}, props, { sx: hasBg
|
|
71
|
+
? Object.assign({ borderRadius: 1, borderTopRightRadius: messageRole === 'user' ? 2 : undefined, borderTopLeftRadius: messageRole !== 'user' ? 2 : undefined, px: 2, py: 1, marginTop: 0.5, maxWidth: hideUserMessage ? 'unset' : 'calc(100% - 40px)', bgcolor: 'rgba(239, 246, 255, 1)' }, props.sx) : Object.assign({}, props.sx) })));
|
|
72
|
+
}
|
|
73
|
+
exports.MessageBodyContainer = MessageBodyContainer;
|
|
@@ -20,7 +20,6 @@ const ComponentPreferences_1 = require("../../contexts/ComponentPreferences");
|
|
|
20
20
|
const session_1 = require("../../state/session");
|
|
21
21
|
const MessageView_1 = __importDefault(require("./MessageView"));
|
|
22
22
|
const OpeningMessageView_1 = __importDefault(require("./OpeningMessageView"));
|
|
23
|
-
const OpeningQuestionsView_1 = __importDefault(require("./OpeningQuestionsView"));
|
|
24
23
|
function MessagesView(_a) {
|
|
25
24
|
var _b;
|
|
26
25
|
var props = __rest(_a, []);
|
|
@@ -28,6 +27,6 @@ function MessagesView(_a) {
|
|
|
28
27
|
const loaded = (0, session_1.useSessionState)((s) => s.loaded);
|
|
29
28
|
const showOpening = (0, session_1.useCurrentSessionState)((s) => !s || (s === null || s === void 0 ? void 0 : s.loaded)) && loaded;
|
|
30
29
|
const divider = (_b = (0, ComponentPreferences_1.useComponentPreferences)()) === null || _b === void 0 ? void 0 : _b.divider;
|
|
31
|
-
return ((0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ gap: 2 }, props, { children: [showOpening && (0, jsx_runtime_1.jsx)(OpeningMessageView_1.default, {}), messages === null || messages === void 0 ? void 0 : messages.map((message, index) => ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(MessageView_1.default, { message: message }, message.taskId), divider && index !== messages.length - 1 ? (0, jsx_runtime_1.jsx)(material_1.Divider, { sx: { my: 2 } }) : undefined] })))
|
|
30
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ gap: 2 }, props, { children: [showOpening && (0, jsx_runtime_1.jsx)(OpeningMessageView_1.default, { isMessagesEmpty: !(messages === null || messages === void 0 ? void 0 : messages.length) }), messages === null || messages === void 0 ? void 0 : messages.map((message, index) => ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(MessageView_1.default, { message: message }, message.taskId), divider && index !== messages.length - 1 ? (0, jsx_runtime_1.jsx)(material_1.Divider, { sx: { my: 2 } }) : undefined] })))] })));
|
|
32
31
|
}
|
|
33
32
|
exports.default = MessagesView;
|
package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningMessageView.js
CHANGED
|
@@ -8,16 +8,29 @@ const types_1 = require("@blocklet/ai-runtime/types");
|
|
|
8
8
|
const react_1 = require("react");
|
|
9
9
|
const CustomComponentRenderer_1 = __importDefault(require("../../../../../components/CustomComponentRenderer"));
|
|
10
10
|
const UserInfo_1 = __importDefault(require("../../components/UserInfo"));
|
|
11
|
+
const constants_1 = require("../../constants");
|
|
11
12
|
const ComponentPreferences_1 = require("../../contexts/ComponentPreferences");
|
|
13
|
+
const CurrentAgent_1 = require("../../contexts/CurrentAgent");
|
|
12
14
|
const use_appearances_1 = require("../../hooks/use-appearances");
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
+
const MessageView_1 = require("./MessageView");
|
|
16
|
+
const OpeningMessageView = (0, react_1.memo)(({ isMessagesEmpty }) => {
|
|
17
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
15
18
|
const { hideAgentAvatar } = (_a = (0, ComponentPreferences_1.useComponentPreferences)()) !== null && _a !== void 0 ? _a : {};
|
|
16
|
-
const
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
19
|
+
const openingMessage = (0, use_appearances_1.useOpeningMessage)();
|
|
20
|
+
const openingMessageOutput = (0, react_1.useMemo)(() => { var _a; return (_a = openingMessage === null || openingMessage === void 0 ? void 0 : openingMessage.agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === types_1.RuntimeOutputVariable.openingMessage); }, [openingMessage === null || openingMessage === void 0 ? void 0 : openingMessage.agent]);
|
|
21
|
+
const openingMessageComponentId = ((_b = openingMessageOutput === null || openingMessageOutput === void 0 ? void 0 : openingMessageOutput.appearance) === null || _b === void 0 ? void 0 : _b.componentId) ||
|
|
22
|
+
((_c = constants_1.DEFAULT_OUTPUT_COMPONENTS[types_1.RuntimeOutputVariable.openingMessage]) === null || _c === void 0 ? void 0 : _c.componentId);
|
|
23
|
+
const profile = (0, use_appearances_1.useProfile)();
|
|
24
|
+
const { agent } = (0, CurrentAgent_1.useCurrentAgent)();
|
|
25
|
+
const openingQuestions = (0, use_appearances_1.useOpeningQuestions)();
|
|
26
|
+
const openingQuestionsOutput = (0, react_1.useMemo)(() => { var _a; return (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === types_1.RuntimeOutputVariable.openingQuestions); }, [agent.outputVariables]);
|
|
27
|
+
const openingQuestionsComponentId = ((_d = openingQuestionsOutput === null || openingQuestionsOutput === void 0 ? void 0 : openingQuestionsOutput.appearance) === null || _d === void 0 ? void 0 : _d.componentId) ||
|
|
28
|
+
((_e = constants_1.DEFAULT_OUTPUT_COMPONENTS[types_1.RuntimeOutputVariable.openingQuestions]) === null || _e === void 0 ? void 0 : _e.componentId);
|
|
29
|
+
if ((!(openingMessage === null || openingMessage === void 0 ? void 0 : openingMessage.message) || !openingMessageComponentId) &&
|
|
30
|
+
(!openingQuestionsComponentId || !(openingQuestions === null || openingQuestions === void 0 ? void 0 : openingQuestions.questions.length) || !isMessagesEmpty)) {
|
|
20
31
|
return null;
|
|
21
|
-
|
|
32
|
+
}
|
|
33
|
+
const children = ((0, jsx_runtime_1.jsxs)(MessageView_1.MessageBodyContainer, { children: [openingMessage && openingMessageOutput && openingMessageComponentId && ((0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { instanceId: openingMessageOutput.id, componentId: openingMessageComponentId, properties: (_f = openingMessageOutput.appearance) === null || _f === void 0 ? void 0 : _f.componentProperties, props: { output: openingMessageOutput, outputValue: openingMessage.message } })), isMessagesEmpty && openingQuestionsComponentId && ((0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { instanceId: agent.id, componentId: openingQuestionsComponentId, properties: (_g = openingQuestionsOutput === null || openingQuestionsOutput === void 0 ? void 0 : openingQuestionsOutput.appearance) === null || _g === void 0 ? void 0 : _g.componentProperties, props: { output: openingQuestionsOutput } }))] }));
|
|
34
|
+
return hideAgentAvatar ? (children) : ((0, jsx_runtime_1.jsx)(UserInfo_1.default, { name: ((_h = openingMessage === null || openingMessage === void 0 ? void 0 : openingMessage.profile) !== null && _h !== void 0 ? _h : profile).name, did: (_j = globalThis.blocklet) === null || _j === void 0 ? void 0 : _j.appId, avatar: ((_k = openingMessage === null || openingMessage === void 0 ? void 0 : openingMessage.profile) !== null && _k !== void 0 ? _k : profile).avatar, alignItems: "flex-start", children: children }));
|
|
22
35
|
});
|
|
23
36
|
exports.default = OpeningMessageView;
|
|
@@ -52,7 +52,7 @@ function V0Output() {
|
|
|
52
52
|
backgroundColor: 'white',
|
|
53
53
|
borderColor: 'rgba(0, 0, 0, 0.1) !important',
|
|
54
54
|
// rewrite disabled style
|
|
55
|
-
'&.Mui-disabled': {
|
|
55
|
+
'&.frame-button.Mui-disabled': {
|
|
56
56
|
backgroundColor: 'primary.main',
|
|
57
57
|
color: 'white',
|
|
58
58
|
},
|
|
@@ -62,6 +62,7 @@ function V0Output() {
|
|
|
62
62
|
key: 'Desktop',
|
|
63
63
|
icon: 'tabler:device-desktop',
|
|
64
64
|
props: {
|
|
65
|
+
className: 'frame-button',
|
|
65
66
|
disabled: (codePreviewExtraProps === null || codePreviewExtraProps === void 0 ? void 0 : codePreviewExtraProps.key) === 'Desktop',
|
|
66
67
|
sx: Object.assign({}, responsiveSx),
|
|
67
68
|
onClick: () => setCodePreviewExtraProps({
|
|
@@ -75,6 +76,7 @@ function V0Output() {
|
|
|
75
76
|
key: 'Tablet',
|
|
76
77
|
icon: 'tabler:device-tablet',
|
|
77
78
|
props: {
|
|
79
|
+
className: 'frame-button',
|
|
78
80
|
disabled: (codePreviewExtraProps === null || codePreviewExtraProps === void 0 ? void 0 : codePreviewExtraProps.key) === 'Tablet',
|
|
79
81
|
sx: Object.assign({}, responsiveSx),
|
|
80
82
|
onClick: () => setCodePreviewExtraProps({
|
|
@@ -91,6 +93,7 @@ function V0Output() {
|
|
|
91
93
|
key: 'Mobile',
|
|
92
94
|
icon: 'tabler:device-mobile',
|
|
93
95
|
props: {
|
|
96
|
+
className: 'frame-button',
|
|
94
97
|
disabled: (codePreviewExtraProps === null || codePreviewExtraProps === void 0 ? void 0 : codePreviewExtraProps.key) === 'Mobile',
|
|
95
98
|
sx: Object.assign({}, responsiveSx),
|
|
96
99
|
onClick: () => setCodePreviewExtraProps({
|
|
@@ -16,19 +16,21 @@ const Runtime_1 = require("../contexts/Runtime");
|
|
|
16
16
|
const agent_1 = require("./agent");
|
|
17
17
|
const session_2 = require("./session");
|
|
18
18
|
function useRuntimeState() {
|
|
19
|
-
var _a;
|
|
20
19
|
const { aid, working } = (0, Runtime_1.useRuntimeContext)();
|
|
21
20
|
const [agent] = (0, agent_1.useAgentState)({ aid, working });
|
|
22
|
-
const { session: authSession } = (0, session_1.useSessionContext)();
|
|
21
|
+
const { session: authSession, events } = (0, session_1.useSessionContext)();
|
|
23
22
|
const sessionState = (0, react_1.useMemo)(() => (0, session_2.createSessionState)({ aid }), [aid]);
|
|
24
23
|
const exec = sessionState((s) => s.execute);
|
|
25
24
|
// reset state after logged out
|
|
26
25
|
(0, react_1.useEffect)(() => {
|
|
27
|
-
|
|
28
|
-
if (!((_a = authSession.user) === null || _a === void 0 ? void 0 : _a.did)) {
|
|
26
|
+
const onLogout = () => {
|
|
29
27
|
sessionState.getState().reset();
|
|
30
|
-
}
|
|
31
|
-
|
|
28
|
+
};
|
|
29
|
+
events.on('logout', onLogout);
|
|
30
|
+
return () => {
|
|
31
|
+
events.off('logout', onLogout);
|
|
32
|
+
};
|
|
33
|
+
}, []);
|
|
32
34
|
const login = (0, react_1.useCallback)(() => __awaiter(this, void 0, void 0, function* () {
|
|
33
35
|
yield new Promise((resolve) => {
|
|
34
36
|
authSession.login(() => resolve());
|