@blocklet/pages-kit 0.2.288 → 0.2.290

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.
Files changed (41) hide show
  1. package/lib/cjs/builtin/async/ai-runtime/components/ActionButton.js +2 -2
  2. package/lib/cjs/builtin/async/ai-runtime/components/MenuButton.js +15 -3
  3. package/lib/cjs/builtin/async/ai-runtime/components/SocialShare.js +6 -9
  4. package/lib/cjs/builtin/async/ai-runtime/components/ThemeProvider.js +6 -0
  5. package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterForm.js +1 -1
  6. package/lib/cjs/builtin/async/ai-runtime/components/message/MessageActions.js +39 -8
  7. package/lib/cjs/builtin/async/ai-runtime/components/message/MessageErrorView.js +4 -10
  8. package/lib/cjs/builtin/async/ai-runtime/components/message/MessageItemView.js +52 -40
  9. package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +2 -2
  10. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +39 -20
  11. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormHeader.js +35 -1
  12. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.js +9 -47
  13. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormSubmit.js +1 -9
  14. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/index.js +35 -7
  15. package/lib/cjs/builtin/async/ai-runtime/hooks/header.js +31 -4
  16. package/lib/cjs/builtin/async/ai-runtime/index.js +1 -1
  17. package/lib/cjs/builtin/async/ai-runtime/locales/index.js +10 -0
  18. package/lib/esm/builtin/async/ai-runtime/components/ActionButton.js +2 -2
  19. package/lib/esm/builtin/async/ai-runtime/components/MenuButton.js +15 -3
  20. package/lib/esm/builtin/async/ai-runtime/components/SocialShare.js +6 -9
  21. package/lib/esm/builtin/async/ai-runtime/components/ThemeProvider.js +6 -0
  22. package/lib/esm/builtin/async/ai-runtime/components/form/ParameterForm.js +1 -1
  23. package/lib/esm/builtin/async/ai-runtime/components/message/MessageActions.js +40 -9
  24. package/lib/esm/builtin/async/ai-runtime/components/message/MessageErrorView.js +4 -10
  25. package/lib/esm/builtin/async/ai-runtime/components/message/MessageItemView.js +53 -41
  26. package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +2 -2
  27. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +34 -15
  28. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormHeader.js +12 -1
  29. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.js +10 -48
  30. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormSubmit.js +2 -10
  31. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/index.js +36 -8
  32. package/lib/esm/builtin/async/ai-runtime/hooks/header.js +33 -6
  33. package/lib/esm/builtin/async/ai-runtime/index.js +1 -1
  34. package/lib/esm/builtin/async/ai-runtime/locales/index.js +10 -0
  35. package/lib/types/builtin/async/ai-runtime/api/assistant.d.ts +1 -0
  36. package/lib/types/builtin/async/ai-runtime/components/ActionButton.d.ts +2 -1
  37. package/lib/types/builtin/async/ai-runtime/components/MenuButton.d.ts +5 -4
  38. package/lib/types/builtin/async/ai-runtime/components/SocialShare.d.ts +5 -2
  39. package/lib/types/builtin/async/ai-runtime/hooks/header.d.ts +2 -1
  40. package/lib/types/builtin/async/ai-runtime/locales/index.d.ts +10 -0
  41. package/package.json +1 -1
@@ -15,17 +15,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  const jsx_runtime_1 = require("react/jsx-runtime");
18
- const subscribe_1 = require("../../hooks/subscribe");
19
18
  const LoadingButton_1 = __importDefault(require("../LoadingButton"));
20
- const PoweredBy_1 = __importDefault(require("../PoweredBy"));
21
19
  function RuntimeFormSubmit(_a) {
22
20
  var { page } = _a, props = __rest(_a, ["page"]);
23
- const { subscribeLink } = (0, subscribe_1.useSubscribeLink)({ assistantId: page.assistantId });
24
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(LoadingButton_1.default, Object.assign({}, props, { onClick: (e) => {
25
- if (subscribeLink) {
26
- e.preventDefault();
27
- window.location.href = subscribeLink;
28
- }
29
- } })), (0, jsx_runtime_1.jsx)(PoweredBy_1.default, { assistantId: page.assistantId })] }));
21
+ return (0, jsx_runtime_1.jsx)(LoadingButton_1.default, Object.assign({}, props));
30
22
  }
31
23
  exports.default = RuntimeFormSubmit;
@@ -5,18 +5,46 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const jsx_runtime_1 = require("react/jsx-runtime");
7
7
  const material_1 = require("@mui/material");
8
+ const material_2 = require("../../../../mui/material");
8
9
  const assistant_1 = require("../../state/assistant");
10
+ const PoweredBy_1 = __importDefault(require("../PoweredBy"));
9
11
  const RuntimeFormForms_1 = __importDefault(require("./RuntimeFormForms"));
10
12
  const RuntimeFormHeader_1 = __importDefault(require("./RuntimeFormHeader"));
11
13
  const RuntimeFormResult_1 = __importDefault(require("./RuntimeFormResult"));
12
14
  function RuntimeForm({ page }) {
13
15
  const [agent] = (0, assistant_1.useAssistantState)({ assistantId: page.assistantId });
14
- return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { sx: { flexGrow: { xs: 'unset', md: 1 } }, children: [(0, jsx_runtime_1.jsx)(RuntimeFormHeader_1.default, { agent: agent, sx: {
15
- position: 'sticky',
16
- top: 64,
17
- zIndex: 10,
18
- px: { xs: 2, sm: 3, md: 8 },
19
- py: { xs: 2, sm: 3, md: 5 },
20
- } }), (0, jsx_runtime_1.jsxs)(material_1.Stack, { sx: { flexGrow: 1, flexDirection: { xs: 'column', md: 'row' } }, children: [(0, jsx_runtime_1.jsx)(material_1.Stack, { sx: { flex: 1, px: { xs: 2, sm: 3, md: 4 }, ml: { xs: 0, md: 4 } }, children: (0, jsx_runtime_1.jsx)(RuntimeFormForms_1.default, { page: page, sx: { position: 'sticky', top: 232 } }) }), (0, jsx_runtime_1.jsx)(material_1.Divider, { orientation: "vertical", sx: { borderColor: 'grey.200', my: { xs: 2, sm: 3, md: 0 } } }), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: { flex: 2 }, children: (0, jsx_runtime_1.jsx)(RuntimeFormResult_1.default, { page: page }) })] })] }));
16
+ const theme = (0, material_1.useTheme)();
17
+ const isMobile = (0, material_1.useMediaQuery)(theme.breakpoints.down('md'));
18
+ const spacing = {
19
+ md: 5,
20
+ xs: 2,
21
+ };
22
+ return ((0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
23
+ flex: 1,
24
+ display: 'flex',
25
+ }, children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { divider: (0, jsx_runtime_1.jsx)(material_1.Divider, { orientation: "vertical", flexItem: true }), direction: {
26
+ md: 'row',
27
+ xs: 'column',
28
+ }, sx: {
29
+ flex: 1,
30
+ }, children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
31
+ flex: 2,
32
+ px: spacing,
33
+ py: isMobile ? 4 : spacing,
34
+ pb: '0 !important',
35
+ display: 'flex',
36
+ flexDirection: 'column',
37
+ justifyContent: 'space-between',
38
+ }, children: [(0, jsx_runtime_1.jsxs)(material_1.Stack, { gap: isMobile ? spacing : 1, spacing: spacing, children: [(0, jsx_runtime_1.jsx)(RuntimeFormHeader_1.default, { agent: agent }), (0, jsx_runtime_1.jsx)(RuntimeFormResult_1.default, { page: page })] }), !isMobile && (0, jsx_runtime_1.jsx)(PoweredBy_1.default, { assistantId: page.assistantId, sx: { mt: spacing, mb: 0.5, px: 2, pt: 0 } })] }), (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
39
+ flex: {
40
+ md: 1,
41
+ xs: 0,
42
+ },
43
+ pt: spacing,
44
+ position: 'sticky',
45
+ bottom: 0,
46
+ // 从上透明到白色 0.72 的径向渐变
47
+ background: (theme) => `linear-gradient(180deg, ${(0, material_2.alpha)(theme.palette.background.default, 0.1)}, ${(0, material_2.alpha)(theme.palette.background.default, 1)} 16px)`,
48
+ }, children: [(0, jsx_runtime_1.jsx)(RuntimeFormForms_1.default, { page: page }), isMobile && (0, jsx_runtime_1.jsx)(PoweredBy_1.default, { assistantId: page.assistantId, sx: { my: 0.5, px: 2 } })] })] }) }));
21
49
  }
22
50
  exports.default = RuntimeForm;
@@ -5,28 +5,55 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.useSetHeader = void 0;
7
7
  const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const DID_1 = __importDefault(require("@arcblock/ux/lib/DID"));
8
9
  const material_1 = require("@mui/material");
9
10
  const react_1 = require("react");
11
+ const ux_1 = require("../../../arcblock/ux");
12
+ const locale_1 = require("../../../locale");
10
13
  const header_1 = require("../../../page/header");
11
14
  const SocialShare_1 = __importDefault(require("../components/SocialShare"));
12
- function useSetHeader({ assistant }) {
15
+ const ThemeProvider_1 = __importDefault(require("../components/ThemeProvider"));
16
+ const subscribe_1 = require("./subscribe");
17
+ const logoSize = 44;
18
+ function useSetHeader({ assistant, assistantId }) {
19
+ const { subscribeLink, requireSubscribe } = (0, subscribe_1.useSubscribeLink)({ assistantId });
20
+ const { t, locale } = (0, locale_1.useLocaleContext)();
13
21
  // set logo
14
22
  (0, react_1.useEffect)(() => {
15
23
  const { release } = assistant;
16
24
  header_1.useHeaderState.setState((state) => {
17
- state.logo = (release === null || release === void 0 ? void 0 : release.logo) && (0, jsx_runtime_1.jsx)(material_1.Box, { component: "img", src: release.logo, sx: { borderRadius: 1 } });
25
+ state.logo = (release === null || release === void 0 ? void 0 : release.logo) && ((0, jsx_runtime_1.jsx)(material_1.Box, { component: ux_1.Avatar, size: logoSize, src: release === null || release === void 0 ? void 0 : release.logo, did: blocklet === null || blocklet === void 0 ? void 0 : blocklet.appId, borderRadius: 1, sx: {
26
+ width: logoSize,
27
+ height: logoSize,
28
+ } }));
18
29
  state.brand = (release === null || release === void 0 ? void 0 : release.title) || assistant.name;
30
+ state.description = assistant.createdBy && ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
31
+ display: 'inline-flex',
32
+ alignItems: 'center',
33
+ gap: 0.5,
34
+ mt: 0.5,
35
+ }, children: [t('by'), " ", (0, jsx_runtime_1.jsx)(DID_1.default, { did: assistant.createdBy, copyable: false })] }));
19
36
  const shareContent = `${(release === null || release === void 0 ? void 0 : release.title) || assistant.name}
20
37
 
21
38
  ${release === null || release === void 0 ? void 0 : release.description}
22
39
  `;
23
- state.addons = (...exists) => [(0, jsx_runtime_1.jsx)(SocialShare_1.default, { content: shareContent }), ...exists];
40
+ state.addons = (...exists) => [
41
+ (0, jsx_runtime_1.jsx)(ThemeProvider_1.default, { children: (0, jsx_runtime_1.jsx)(material_1.Button, { disabled: !requireSubscribe, variant: "outlined", href: subscribeLink,
42
+ // @ts-ignore
43
+ color: "black", sx: {
44
+ // 字母不大写
45
+ textTransform: 'none',
46
+ }, children: subscribeLink ? t('subscribe') : t('subscribed') }) }),
47
+ (0, jsx_runtime_1.jsx)(SocialShare_1.default, { content: shareContent }),
48
+ ...exists,
49
+ ].filter(Boolean);
24
50
  });
25
51
  return () => header_1.useHeaderState.setState((state) => {
26
52
  state.logo = undefined;
27
53
  state.brand = undefined;
54
+ state.description = undefined;
28
55
  state.addons = (...exists) => [...exists];
29
56
  });
30
- }, []);
57
+ }, [locale]);
31
58
  }
32
59
  exports.useSetHeader = useSetHeader;
@@ -50,7 +50,7 @@ function AIRuntime({ cacheId, preload }) {
50
50
  const page = (0, navigate_1.useCurrentPage)();
51
51
  const { assistantId } = page;
52
52
  const [assistant] = (0, assistant_2.useAssistantState)({ assistantId });
53
- (0, header_1.useSetHeader)({ assistant });
53
+ (0, header_1.useSetHeader)({ assistant, assistantId });
54
54
  (0, react_1.useMemo)(() => {
55
55
  // preload assistant from server side props
56
56
  if (preload)
@@ -3,7 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.translations = void 0;
4
4
  exports.translations = {
5
5
  en: {
6
+ by: 'By',
6
7
  socialShare: {
8
+ title: 'Share',
7
9
  shareToX: 'Share to X',
8
10
  shareToTelegram: 'Share to Telegram',
9
11
  shareToReddit: 'Share to Reddit',
@@ -37,6 +39,8 @@ exports.translations = {
37
39
  edit: 'Edit',
38
40
  chat: 'Chat',
39
41
  subscribeNow: 'Subscribe Now',
42
+ subscribe: 'Subscribe',
43
+ subscribed: 'Subscribed',
40
44
  requireNewSubscription: `Thank you for using our service!
41
45
 
42
46
  To get more features and exclusive content, please subscribe to our service. After subscribing, you will enjoy the following privileges:
@@ -72,9 +76,12 @@ exports.translations = {
72
76
  savedToNote: 'Saved as a new document',
73
77
  uploadFile: 'Upload File',
74
78
  submit: 'Submit',
79
+ send: 'Send',
75
80
  },
76
81
  zh: {
82
+ by: '来自',
77
83
  socialShare: {
84
+ title: '分享',
78
85
  shareToX: '分享到 X',
79
86
  shareToTelegram: '分享到 Telegram',
80
87
  shareToReddit: '分享到 Reddit',
@@ -108,6 +115,8 @@ exports.translations = {
108
115
  edit: '编辑',
109
116
  chat: '对话',
110
117
  subscribeNow: '立即订阅',
118
+ subscribe: '订阅',
119
+ subscribed: '已订阅',
111
120
  requireNewSubscription: `感谢您使用我们的服务!
112
121
 
113
122
  为了获得更多功能和专属内容,请订阅我们的服务。订阅后,您将享有以下特权:
@@ -143,5 +152,6 @@ exports.translations = {
143
152
  savedToNote: '已保存到知识库',
144
153
  uploadFile: '上传文件',
145
154
  submit: '提交',
155
+ send: '发送',
146
156
  },
147
157
  };
@@ -24,7 +24,7 @@ import { Box, Tooltip } from '@mui/material';
24
24
  import { useRef, useState } from 'react';
25
25
  import LoadingButton from './LoadingButton';
26
26
  export function ActionButton(_a) {
27
- var { tip, tipSucceed, title, titleSucceed, icon, iconSucceed, autoReset } = _a, props = __rest(_a, ["tip", "tipSucceed", "title", "titleSucceed", "icon", "iconSucceed", "autoReset"]);
27
+ var { tip, tipSucceed, title, titleSucceed, icon, iconSucceed, autoReset, placement = 'top' } = _a, props = __rest(_a, ["tip", "tipSucceed", "title", "titleSucceed", "icon", "iconSucceed", "autoReset", "placement"]);
28
28
  const [copied, setCopied] = useState(false);
29
29
  const [error, setError] = useState();
30
30
  const timer = useRef();
@@ -42,7 +42,7 @@ export function ActionButton(_a) {
42
42
  const realIcon = copied ? iconSucceed : icon;
43
43
  const toolTipTitleText = error ? _jsx(Box, { color: "error", children: error.message }) : (copied && tipSucceed) || tip;
44
44
  const buttonText = copied ? titleSucceed : title;
45
- return (_jsx(Tooltip, { title: toolTipTitleText, disableInteractive: true, placement: "top", onClose: onClose, onOpen: onOpen, children: _jsx("span", { children: _jsx(LoadingButton, Object.assign({ startIcon: realIcon && (typeof realIcon === 'string' ? _jsx(Icon, { icon: realIcon }) : realIcon), loadingPosition: realIcon ? 'start' : undefined }, props, { onClick: (e) => __awaiter(this, void 0, void 0, function* () {
45
+ return (_jsx(Tooltip, { title: toolTipTitleText, disableInteractive: true, placement: placement, onClose: onClose, onOpen: onOpen, children: _jsx("span", { children: _jsx(LoadingButton, Object.assign({ startIcon: realIcon && (typeof realIcon === 'string' ? _jsx(Icon, { icon: realIcon }) : realIcon), loadingPosition: realIcon ? 'start' : undefined }, props, { onClick: (e) => __awaiter(this, void 0, void 0, function* () {
46
46
  if (!props.onClick)
47
47
  return;
48
48
  try {
@@ -1,8 +1,20 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
1
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
13
  import { MoreHoriz as MoreHorizIcon } from '@mui/icons-material';
3
14
  import { Box, IconButton, Menu } from '@mui/material';
4
15
  import { useState } from 'react';
5
- export default function MenuButton({ sx, menus, children }) {
16
+ export default function MenuButton(_a) {
17
+ var { sx, menus, children, MenuProps } = _a, restProps = __rest(_a, ["sx", "menus", "children", "MenuProps"]);
6
18
  const [anchorEl, setAnchorEl] = useState(null);
7
19
  const open = Boolean(anchorEl);
8
20
  const handleClick = (event) => {
@@ -11,7 +23,7 @@ export default function MenuButton({ sx, menus, children }) {
11
23
  const handleClose = () => {
12
24
  setAnchorEl(null);
13
25
  };
14
- return (_jsxs(Box, { sx: sx, children: [_jsx(IconButton, { onClick: handleClick, children: children || _jsx(MoreHorizIcon, {}) }), _jsx(Menu, { disableScrollLock: true, MenuListProps: {
26
+ return (_jsxs(Box, { sx: sx, children: [_jsx(IconButton, Object.assign({ onClick: handleClick }, restProps, { children: children || _jsx(MoreHorizIcon, {}) })), _jsx(Menu, Object.assign({ disableScrollLock: true, MenuListProps: {
15
27
  sx: {
16
28
  p: 0.5,
17
29
  '.MuiMenuItem-root': {
@@ -36,5 +48,5 @@ export default function MenuButton({ sx, menus, children }) {
36
48
  }, transformOrigin: {
37
49
  vertical: 'top',
38
50
  horizontal: 'right',
39
- }, open: open, onClick: handleClose, onClose: handleClose, children: typeof menus === 'function' ? menus() : menus })] }));
51
+ }, open: open, onClick: handleClose, onClose: handleClose }, MenuProps, { children: typeof menus === 'function' ? menus() : menus }))] }));
40
52
  }
@@ -33,12 +33,13 @@ export default function SocialShare(props) {
33
33
  if (type === 'buttons') {
34
34
  return _jsx(SocialShareButtons, Object.assign({}, restProps));
35
35
  }
36
+ // @ts-ignore
36
37
  return _jsx(SocialShareMenu, Object.assign({}, restProps));
37
38
  }, [type, restProps]);
38
39
  return (_jsx(LocaleProvider, { translations: translations, locale: locale, fallbackLocale: "en", children: renderContent() }));
39
40
  }
40
41
  export function SocialShareMenu(_a) {
41
- var { url = getFormattedUrl(window.location.href), content } = _a, restProps = __rest(_a, ["url", "content"]);
42
+ var { url = getFormattedUrl(window.location.href), content, children = _jsx(Icon, { icon: "tabler:share" }), MenuProps, disableCopyLink = false } = _a, restProps = __rest(_a, ["url", "content", "children", "MenuProps", "disableCopyLink"]);
42
43
  const theme = useTheme();
43
44
  const { t } = useLocaleContext();
44
45
  const itemIconSx = {
@@ -65,21 +66,17 @@ export function SocialShareMenu(_a) {
65
66
  borderRadius: '6px',
66
67
  },
67
68
  };
68
- const renderShareIcon = () => {
69
- // eslint-disable-next-line react/no-unstable-nested-components
70
- return _jsx(Box, Object.assign({ component: () => _jsx(Icon, { icon: "tabler:share" }) }, restProps));
71
- };
72
- return (_jsx(MenuButton, { menus: [
69
+ return (_jsx(MenuButton, Object.assign({ MenuProps: MenuProps, menus: [
73
70
  _jsx(MenuItem, { children: _jsxs(Box, { component: XShareButton, url: url, title: content, sx: buttonSx, children: [_jsx(Box, Object.assign({ component: XIcon, sx: itemIconSx, round: true }, iconProps)), _jsx("span", { children: t('socialShare.shareToX') })] }) }, "shareOnX"),
74
71
  _jsx(MenuItem, { children: _jsxs(Box, { component: TelegramShareButton, url: url, title: content, sx: buttonSx, children: [_jsx(Box, Object.assign({ component: TelegramIcon, sx: itemIconSx, round: true }, iconProps)), _jsx("span", { children: t('socialShare.shareToTelegram') })] }) }, "shareOnTelegram"),
75
72
  _jsx(MenuItem, { children: _jsxs(Box, { component: RedditShareButton, url: url, title: content, sx: buttonSx, children: [_jsx(Box, Object.assign({ component: RedditIcon, sx: itemIconSx, round: true }, iconProps)), _jsx("span", { children: t('socialShare.shareToReddit') })] }) }, "shareOnReddit"),
76
73
  _jsx(MenuItem, { children: _jsxs(Box, { component: WeiboShareButton, url: url, title: content, sx: buttonSx, children: [_jsx(Box, Object.assign({ component: WeiboIcon, sx: itemIconSx, round: true }, iconProps)), _jsx("span", { children: t('socialShare.shareToWeibo') })] }) }, "shareOnWeibo"),
77
74
  _jsx(MenuItem, { children: _jsxs(Box, { component: FacebookShareButton, url: url, sx: buttonSx, children: [_jsx(Box, Object.assign({ component: FacebookIcon, sx: itemIconSx, round: true }, iconProps)), _jsx("span", { children: t('socialShare.shareToFacebook') })] }) }, "shareOnFacebook"),
78
75
  _jsx(MenuItem, { children: _jsxs(Box, { component: LinkedinShareButton, url: url, summary: content, sx: buttonSx, children: [_jsx(Box, Object.assign({ component: LinkedinIcon, sx: itemIconSx, round: true }, iconProps)), _jsx("span", { children: t('socialShare.shareToLinkedin') })] }) }, "shareOnLinkedin"),
79
- _jsx(MenuItem, { children: _jsxs(Box, { component: "div", sx: buttonSx, onClick: () => {
76
+ !disableCopyLink && (_jsx(MenuItem, { children: _jsxs(Box, { component: "div", sx: buttonSx, onClick: () => {
80
77
  window.navigator.clipboard.writeText(url);
81
- }, children: [_jsx(Box, { sx: itemIconSx, round: true, children: _jsx(Icon, Object.assign({ icon: "tabler:link" }, iconProps)) }), _jsx("span", { children: t('socialShare.copyLink') })] }) }, "copyToClipboard"),
82
- ], children: renderShareIcon() }));
78
+ }, children: [_jsx(Box, Object.assign({ sx: itemIconSx, round: true }, iconProps, { children: _jsx(Icon, { icon: "tabler:link" }) })), _jsx("span", { children: t('socialShare.copyLink') })] }) }, "copyToClipboard")),
79
+ ].filter(Boolean) }, restProps, { children: children })));
83
80
  }
84
81
  export function SocialShareButtons(_a) {
85
82
  var { url = getFormattedUrl(window.location.href), content, sx, itemSx, onClick, bgFill, iconFill } = _a, rest = __rest(_a, ["url", "content", "sx", "itemSx", "onClick", "bgFill", "iconFill"]);
@@ -186,5 +186,11 @@ export default function ThemeProvider({ children, template, transparentHeaderBg,
186
186
  zIndex: -1,
187
187
  },
188
188
  },
189
+ '.white-tooltip .MuiTooltip-tooltip': {
190
+ background: 'white !important',
191
+ boxShadow: '0px 4px 8px 0px rgba(3, 7, 18, 0.08)',
192
+ border: '1px solid rgba(229, 231, 235, 1)',
193
+ padding: 4,
194
+ },
189
195
  } }), children] }));
190
196
  }
@@ -56,5 +56,5 @@ export default function ParameterForm(_a) {
56
56
  transform: `rotateX(${expand ? '180deg' : '0deg'})`,
57
57
  transition: 'transform .3s ease-in-out',
58
58
  } }) }) }), _jsx(Collapse, { in: expand, orientation: "vertical", sx: { maxHeight: '40vh', overflowY: 'auto' }, children: _jsx(ParameterFormFields, { autoFocus: !sessionId, disabled: disabled, readOnly: readOnly, parameters: parameters, form: form, sx: { pb: 2, px: 2 } }) })] })), _jsx(Box, { px: 2, children: !hideSubmit &&
59
- (isChat ? (_jsx(QuestionField, { sessionId: sessionId, showSettingButton: !!sessionId, assistant: assistant, disabled: disabled, submitButtonTitle: submitButtonTitle, readOnly: readOnly, isSubmitting: isSubmitting, form: form, autoFocus: !!sessionId })) : (_jsxs(Stack, { className: "ai-chat-generation-bar", direction: "row", alignItems: "center", justifyContent: "flex-end", gap: 2, children: [sessionId && _jsx(SettingButton, { form: form, sessionId: sessionId }), _jsx(Box, { flex: 1 }), _jsx(Tooltip, { title: submitButtonTitle, disableInteractive: true, placement: "top", children: _jsx("span", { children: _jsx(LoadingButton, { disabled: disabled, type: "submit", variant: "contained", color: "secondary", loading: form.formState.isSubmitting || isSubmitting, children: submitButtonTitle || t('submit') }) }) })] }))) })] }));
59
+ (isChat ? (_jsx(QuestionField, { sessionId: sessionId, showSettingButton: !!sessionId, assistant: assistant, disabled: disabled, submitButtonTitle: submitButtonTitle || t('send'), readOnly: readOnly, isSubmitting: isSubmitting, form: form, autoFocus: !!sessionId })) : (_jsxs(Stack, { className: "ai-chat-generation-bar", direction: "row", alignItems: "center", justifyContent: "flex-end", gap: 2, children: [sessionId && _jsx(SettingButton, { form: form, sessionId: sessionId }), _jsx(Box, { flex: 1 }), _jsx(Tooltip, { title: submitButtonTitle, disableInteractive: true, placement: "top", children: _jsx("span", { children: _jsx(LoadingButton, { disabled: disabled, type: "submit", variant: "contained", color: "secondary", loading: form.formState.isSubmitting || isSubmitting, children: submitButtonTitle || t('send') }) }) })] }))) })] }));
60
60
  }
@@ -9,27 +9,58 @@ var __rest = (this && this.__rest) || function (s, e) {
9
9
  }
10
10
  return t;
11
11
  };
12
- import { jsx as _jsx } from "react/jsx-runtime";
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
13
  import { Stack } from '@mui/material';
14
14
  import { useLocaleContext } from '../../../../locale';
15
15
  import { ActionButton } from '../ActionButton';
16
+ import { SocialShareMenu } from '../SocialShare';
16
17
  export default function MessageActions(_a) {
17
18
  var { content } = _a, props = __rest(_a, ["content"]);
18
19
  const { t } = useLocaleContext();
19
20
  const commonActionButtonsSx = {
20
21
  border: '0px !important',
22
+ borderRadius: '4px !important',
21
23
  minWidth: '32px',
22
24
  color: 'rgba(75, 85, 99, 1)',
23
25
  '.MuiButton-startIcon': {
24
26
  marginRight: '0px !important',
25
27
  },
26
28
  };
27
- return (_jsx(Stack, Object.assign({ direction: "row", gap: 1 }, props, { children: _jsx(ActionButton, { autoReset: true, size: "small", variant: "outlined",
28
- // @ts-ignore
29
- color: "black", tip: t('copyToClipboard'),
30
- // title={t('copy')}
31
- // titleSucceed={t('copied')}
32
- icon: "tabler:copy", iconSucceed: "tabler:copy-check-filled", sx: Object.assign({}, commonActionButtonsSx), onClick: () => {
33
- window.navigator.clipboard.writeText(content);
34
- } }) })));
29
+ return (_jsxs(Stack, Object.assign({ direction: "column", gap: 0.5 }, props, { children: [_jsx(ActionButton, { autoReset: true, size: "small", variant: "outlined", placement: "right",
30
+ // @ts-ignore
31
+ color: "black", tip: t('copyToClipboard'),
32
+ // title={t('copy')}
33
+ // titleSucceed={t('copied')}
34
+ icon: "tabler:copy", iconSucceed: "tabler:copy-check-filled", sx: Object.assign({}, commonActionButtonsSx), onClick: () => {
35
+ window.navigator.clipboard.writeText(content);
36
+ } }), _jsx(SocialShareMenu, { content: content, disableCopyLink: true, size: "small", disableRipple: true, MenuProps: {
37
+ anchorOrigin: {
38
+ vertical: 'center',
39
+ horizontal: 'right',
40
+ },
41
+ transformOrigin: {
42
+ vertical: 'top',
43
+ horizontal: 'left',
44
+ },
45
+ slotProps: {
46
+ paper: {
47
+ sx: {
48
+ ml: 1.5,
49
+ mt: -2,
50
+ border: 1,
51
+ borderColor: 'divider',
52
+ boxShadow: '0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1)',
53
+ },
54
+ },
55
+ },
56
+ sx: {
57
+ zIndex: 9999,
58
+ },
59
+ }, sx: {
60
+ '.MuiIconButton-root': {
61
+ p: 0,
62
+ },
63
+ }, children: _jsx(ActionButton, { autoReset: true, size: "small", variant: "outlined", placement: "right",
64
+ // @ts-ignore
65
+ color: "black", tip: t('socialShare.title'), icon: "tabler:share", iconSucceed: "tabler:share", sx: Object.assign({}, commonActionButtonsSx) }) })] })));
35
66
  }
@@ -8,17 +8,11 @@ export default function MessageErrorView({ assistantId, assistant, error, }) {
8
8
  const { t } = useLocaleContext();
9
9
  const { subscribeLink } = useSubscribeLink({ assistantId });
10
10
  if (error.type === 'InvalidSubscriptionError') {
11
- return (_jsxs(Box, { className: "ai-chat-message-error", children: [_jsx(Box, { sx: {
12
- bgcolor: 'grey.100',
13
- p: 1.5,
14
- borderRadius: 1,
15
- }, children: _jsx(MarkdownRenderer, { children: t('requireNewSubscription', {
11
+ return (_jsxs(Box, { className: "ai-chat-message-error", children: [_jsx(Box, { className: "message-response", children: _jsx(MarkdownRenderer, { children: t('requireNewSubscription', {
16
12
  price: (_b = (_a = assistant.release) === null || _a === void 0 ? void 0 : _a.payment) === null || _b === void 0 ? void 0 : _b.price,
17
- }) }) }), _jsx(Box, { mt: 1, children: subscribeLink ? (_jsx(Button, { variant: "contained", href: subscribeLink, children: t('subscribeNow') })) : (_jsx(Box, { sx: {
18
- bgcolor: 'grey.100',
19
- p: 1.5,
20
- borderRadius: 1,
21
- }, children: t('thanksForSubscription') })) })] }));
13
+ }) }) }), _jsx(Box, { mt: 1, children: subscribeLink ? (
14
+ // @ts-ignore
15
+ _jsx(Button, { variant: "contained", color: "black", href: subscribeLink, children: t('subscribeNow') })) : (_jsx(Box, { className: "message-response", children: t('thanksForSubscription') })) })] }));
22
16
  }
23
17
  return (_jsx(Alert, { className: "ai-chat-message-error", severity: "error", children: (error.type === 'ReachMaxRoundLimitError' && ((_c = assistant === null || assistant === void 0 ? void 0 : assistant.release) === null || _c === void 0 ? void 0 : _c.reachMaxRoundLimitTip)) || error.message }));
24
18
  }
@@ -1,6 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import ImagePreview from '@blocklet/ai-kit/components/image-preview';
3
- import { Box, Skeleton, Stack, Typography } from '@mui/material';
3
+ import { Box, Skeleton, Stack, Tooltip, Typography, useMediaQuery, useTheme } from '@mui/material';
4
4
  import dayjs from 'dayjs';
5
5
  import React, { useMemo } from 'react';
6
6
  import { Avatar } from '../../../../arcblock/ux';
@@ -12,36 +12,30 @@ import MessageErrorView from './MessageErrorView';
12
12
  export default function MessageItemView({ assistantId, assistant, message, hideAvatar, }) {
13
13
  var _a, _b;
14
14
  const showUserMessage = ((_a = assistant.release) === null || _a === void 0 ? void 0 : _a.template) !== 'form' && !!((_b = message.parameters) === null || _b === void 0 ? void 0 : _b.question);
15
- return (_jsxs(Stack, { className: "ai-chat-message-item", gap: 2.5, overflow: "hidden", sx: {
16
- '.message-question': Object.assign(Object.assign({}, commonMessageSx), { borderTopRightRadius: '2px', backgroundColor: 'rgba(239, 246, 255, 1)' }),
17
- '.message-response': Object.assign(Object.assign({}, commonMessageSx), { borderTopLeftRadius: '2px', backgroundColor: 'rgba(229, 231, 235, 1)' }),
18
- '.ai-chat-message-ai:hover': {
19
- '.message-actions': {
20
- opacity: 1,
21
- },
22
- },
15
+ const commonMessageSx = {
16
+ position: 'relative',
17
+ borderRadius: 1,
18
+ py: 1,
19
+ px: 2,
20
+ mt: 0.5,
21
+ // without logo width
22
+ maxWidth: 'calc(100% - 40px)',
23
+ };
24
+ return (_jsxs(Stack, { className: "ai-chat-message-item", gap: 2.5, overflow: "hidden",
25
+ // @ts-ignore
26
+ sx: {
27
+ '.message-question': Object.assign(Object.assign(Object.assign({}, commonMessageSx), (!hideAvatar
28
+ ? {
29
+ borderTopRightRadius: '2px',
30
+ }
31
+ : {})), { borderTopRightRadius: !hideAvatar && '2px', backgroundColor: 'rgba(239, 246, 255, 1)' }),
32
+ '.message-response': Object.assign(Object.assign(Object.assign({}, commonMessageSx), (!hideAvatar
33
+ ? {
34
+ borderTopLeftRadius: '2px',
35
+ }
36
+ : {})), { backgroundColor: 'rgba(229, 231, 235, 1)' }),
23
37
  }, children: [showUserMessage && _jsx(UserMessage, { message: message }), _jsx(AgentMessage, { assistantId: assistantId, assistant: assistant, message: message, hideAvatar: hideAvatar })] }));
24
38
  }
25
- const commonMessageSx = {
26
- position: 'relative',
27
- borderRadius: 1,
28
- py: 1,
29
- px: 2,
30
- mt: 0.5,
31
- // without logo width
32
- maxWidth: 'calc(100% - 40px)',
33
- '.message-actions': {
34
- position: 'absolute',
35
- top: 0,
36
- right: -40,
37
- background: 'white',
38
- border: 1,
39
- borderRadius: 1,
40
- borderColor: 'grey.300',
41
- opacity: 0,
42
- transition: 'opacity 0.2s',
43
- },
44
- };
45
39
  function UserMessage({ message }) {
46
40
  var _a, _b, _c, _d;
47
41
  const { session: authSession } = useSessionContext();
@@ -57,21 +51,39 @@ function UserMessage({ message }) {
57
51
  }, children: [_jsxs(MessageUserName, { children: [(_c = authSession.user) === null || _c === void 0 ? void 0 : _c.fullName, _jsx(MessageTime, { time: message.createdAt })] }), _jsx(Box, { className: "message-question", sx: { whiteSpace: 'pre-wrap', wordBreak: 'break-word', textAlign: 'left' }, children: (_d = message.parameters) === null || _d === void 0 ? void 0 : _d.question })] })] }));
58
52
  }
59
53
  function AgentMessage({ assistantId, assistant, message, hideAvatar, }) {
60
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p;
54
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q;
61
55
  const showMainMessage = !!(((_a = message.result) === null || _a === void 0 ? void 0 : _a.content) || ((_c = (_b = message.result) === null || _b === void 0 ? void 0 : _b.messages) === null || _c === void 0 ? void 0 : _c.length));
62
56
  const isMessageLoading = (message.loading || !message.result) && !message.error;
63
- return (_jsxs(Stack, { className: "ai-chat-message-ai", direction: "row", gap: 1.5, children: [!hideAvatar && (_jsx(Box, { children: _jsx(Avatar, { size: 40, did: (_d = globalThis.blocklet) === null || _d === void 0 ? void 0 : _d.appId, variant: "circle", shape: "circle", src: (_e = assistant.release) === null || _e === void 0 ? void 0 : _e.logo }) })), _jsxs(Box, { flex: 1, overflow: "hidden", children: [!hideAvatar && (_jsxs(MessageUserName, { children: [((_f = assistant.release) === null || _f === void 0 ? void 0 : _f.title) || assistant.name, _jsx(MessageTime, { time: message.createdAt })] })), _jsxs(React.Suspense, { children: [showMainMessage ? (_jsxs(Stack, { gap: 1, className: "message-response", children: [(_h = (_g = message.result) === null || _g === void 0 ? void 0 : _g.messages) === null || _h === void 0 ? void 0 : _h.map((childMsg, index) => {
64
- var _a, _b, _c, _d, _e, _f, _g;
65
- return ((_a = childMsg.result) === null || _a === void 0 ? void 0 : _a.content) ? (_jsx(MarkdownRenderer, { className: isMessageLoading &&
66
- !((_b = message.result) === null || _b === void 0 ? void 0 : _b.content) &&
67
- !((_d = (_c = message.result) === null || _c === void 0 ? void 0 : _c.images) === null || _d === void 0 ? void 0 : _d.length) &&
68
- message.result.messages.length - 1 === index
69
- ? 'writing'
70
- : '', sx: childMsg.respondAs === 'systemMessage' ? { color: 'text.secondary' } : {}, children: (_e = childMsg.result) === null || _e === void 0 ? void 0 : _e.content }, childMsg.taskId)) : ((_g = (_f = childMsg.result) === null || _f === void 0 ? void 0 : _f.images) === null || _g === void 0 ? void 0 : _g.length) ? (_jsx(ImagePreview, { itemWidth: 100, spacing: 1, dataSource: childMsg.result.images.map((i) => ({ src: i.url })) }, childMsg.taskId)) : null;
71
- }), ((_j = message.result) === null || _j === void 0 ? void 0 : _j.content) && (_jsx(MarkdownRenderer, { className: isMessageLoading ? 'writing' : '', children: message.result.content })), !isMessageLoading && ((_k = message.result) === null || _k === void 0 ? void 0 : _k.content) && (_jsx(MessageActions, { className: "message-actions", content: message.result.content }))] })) : (isMessageLoading && (_jsx(Skeleton, { variant: "rectangular", height: 24 + 8 + 8,
57
+ const theme = useTheme();
58
+ const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
59
+ const isFormTemplate = ((_d = assistant.release) === null || _d === void 0 ? void 0 : _d.template) === 'form';
60
+ return (_jsxs(Stack, { className: "ai-chat-message-ai", direction: "row", gap: 1.5, children: [!hideAvatar && (_jsx(Box, { children: _jsx(Avatar, { size: 40, did: (_e = globalThis.blocklet) === null || _e === void 0 ? void 0 : _e.appId, variant: "circle", shape: "circle", src: (_f = assistant.release) === null || _f === void 0 ? void 0 : _f.logo }) })), _jsxs(Box, { flex: 1, overflow: "hidden", children: [!hideAvatar && (_jsxs(MessageUserName, { children: [((_g = assistant.release) === null || _g === void 0 ? void 0 : _g.title) || assistant.name, _jsx(MessageTime, { time: message.createdAt })] })), _jsxs(React.Suspense, { children: [showMainMessage ? (_jsx(Tooltip, Object.assign({}, (isFormTemplate && {
61
+ open: true,
62
+ }), { placement: "right-start", PopperProps: {
63
+ className: 'white-tooltip',
64
+ }, slotProps: {
65
+ popper: {
66
+ modifiers: [
67
+ {
68
+ name: 'offset',
69
+ options: {
70
+ offset: [-3, isMobile ? (!hideAvatar ? -18 : -8) : -6],
71
+ },
72
+ },
73
+ ],
74
+ },
75
+ }, title: !isMessageLoading && ((_h = message.result) === null || _h === void 0 ? void 0 : _h.content) && _jsx(MessageActions, { content: message.result.content }), children: _jsxs(Stack, { gap: 1, className: "message-response", children: [(_k = (_j = message.result) === null || _j === void 0 ? void 0 : _j.messages) === null || _k === void 0 ? void 0 : _k.map((childMsg, index) => {
76
+ var _a, _b, _c, _d, _e, _f, _g;
77
+ return ((_a = childMsg.result) === null || _a === void 0 ? void 0 : _a.content) ? (_jsx(MarkdownRenderer, { className: isMessageLoading &&
78
+ !((_b = message.result) === null || _b === void 0 ? void 0 : _b.content) &&
79
+ !((_d = (_c = message.result) === null || _c === void 0 ? void 0 : _c.images) === null || _d === void 0 ? void 0 : _d.length) &&
80
+ message.result.messages.length - 1 === index
81
+ ? 'writing'
82
+ : '', sx: childMsg.respondAs === 'systemMessage' ? { color: 'text.secondary' } : {}, children: (_e = childMsg.result) === null || _e === void 0 ? void 0 : _e.content }, childMsg.taskId)) : ((_g = (_f = childMsg.result) === null || _f === void 0 ? void 0 : _f.images) === null || _g === void 0 ? void 0 : _g.length) ? (_jsx(ImagePreview, { itemWidth: 100, spacing: 1, dataSource: childMsg.result.images.map((i) => ({ src: i.url })) }, childMsg.taskId)) : null;
83
+ }), ((_l = message.result) === null || _l === void 0 ? void 0 : _l.content) && (_jsx(MarkdownRenderer, { className: isMessageLoading ? 'writing' : '', children: message.result.content }))] }) }))) : (isMessageLoading && (_jsx(Skeleton, { variant: "rectangular", height: 24 + 8 + 8,
72
84
  // only response with loading
73
- className: "message-response" }))), !!((_m = (_l = message.result) === null || _l === void 0 ? void 0 : _l.objects) === null || _m === void 0 ? void 0 : _m.length) &&
74
- ((_p = (_o = message.result) === null || _o === void 0 ? void 0 : _o.objects) === null || _p === void 0 ? void 0 : _p.map((object) => (_jsx(MessageMetadataRenderer, { object: object.data }, object.taskId)))), message.error && _jsx(MessageErrorView, { assistantId: assistantId, assistant: assistant, error: message.error })] })] })] }));
85
+ className: "message-response" }))), !!((_o = (_m = message.result) === null || _m === void 0 ? void 0 : _m.objects) === null || _o === void 0 ? void 0 : _o.length) &&
86
+ ((_q = (_p = message.result) === null || _p === void 0 ? void 0 : _p.objects) === null || _q === void 0 ? void 0 : _q.map((object) => (_jsx(MessageMetadataRenderer, { object: object.data }, object.taskId)))), message.error && _jsx(MessageErrorView, { assistantId: assistantId, assistant: assistant, error: message.error })] })] })] }));
75
87
  }
76
88
  function MessageUserName({ children }) {
77
89
  return (_jsx(Typography, { component: "div", noWrap: true, sx: {
@@ -11,7 +11,7 @@ import PoweredBy from '../PoweredBy';
11
11
  import { useScrollToBottomModule } from '../ScrollView';
12
12
  import { EntryListView } from './InitialForm';
13
13
  export default function RuntimeChatSession({ page }) {
14
- var _a, _b, _c, _d, _e, _f, _g, _h;
14
+ var _a, _b, _c, _d, _e, _f;
15
15
  const [session, state] = useSessionState({ sessionId: page.sessionId, required: true });
16
16
  const [assistant] = useAssistantState({ assistantId: page.assistantId });
17
17
  const lastMessage = (_a = state.messages) === null || _a === void 0 ? void 0 : _a.slice(-1)[0];
@@ -42,5 +42,5 @@ export default function RuntimeChatSession({ page }) {
42
42
  bottom: 0,
43
43
  // 从上透明到白色 0.72 的径向渐变
44
44
  background: (theme) => `linear-gradient(180deg, ${alpha(theme.palette.background.default, 0.1)}, ${alpha(theme.palette.background.default, 1)} 16px)`,
45
- }, children: [_jsx(ParameterForm, { sessionId: page.sessionId, defaultValues: lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters, assistant: assistant, onSubmit: onSubmit, isSubmitting: state.running, submitButtonTitle: (_h = (_g = assistant.release) === null || _g === void 0 ? void 0 : _g.submitButton) === null || _h === void 0 ? void 0 : _h.title }), _jsx(PoweredBy, { assistantId: page.assistantId, sx: { my: 0.5, px: 2 } })] })] }));
45
+ }, children: [_jsx(ParameterForm, { sessionId: page.sessionId, defaultValues: lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters, assistant: assistant, onSubmit: onSubmit, isSubmitting: state.running }), _jsx(PoweredBy, { assistantId: page.assistantId, sx: { my: 0.5, px: 2 } })] })] }));
46
46
  }