@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
@@ -19,11 +19,12 @@ var __rest = (this && this.__rest) || function (s, e) {
19
19
  return t;
20
20
  };
21
21
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
22
- import { Alert, Box, Stack } from '@mui/material';
22
+ import { Icon } from '@iconify/react';
23
+ import { Alert, Box, Button, Collapse, Stack, useMediaQuery, useTheme } from '@mui/material';
24
+ import isEmpty from 'lodash/isEmpty';
23
25
  import { Suspense, useEffect, useMemo, useState } from 'react';
24
26
  import { useForm } from 'react-hook-form';
25
27
  import { useLocaleContext } from '../../../../locale';
26
- import { alpha } from '../../../../mui/material';
27
28
  import { useSessionContext } from '../../../../session';
28
29
  import { createSession } from '../../api/session';
29
30
  import { useAssistantState } from '../../state/assistant';
@@ -35,7 +36,13 @@ export default function RuntimeFormForms(_a) {
35
36
  var _b, _c, _d;
36
37
  var { page } = _a, props = __rest(_a, ["page"]);
37
38
  const { t } = useLocaleContext();
39
+ const theme = useTheme();
40
+ const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
38
41
  const [agent] = useAssistantState({ assistantId: page.assistantId });
42
+ const spacing = {
43
+ md: 2.5,
44
+ xs: 2,
45
+ };
39
46
  const lastParameters = useMemo(() => {
40
47
  var _a;
41
48
  if (page.sessionId) {
@@ -54,6 +61,7 @@ export default function RuntimeFormForms(_a) {
54
61
  }, [agent.parameters, lastParameters]);
55
62
  const form = useForm({ defaultValues: defaultForm });
56
63
  const [error, setError] = useState();
64
+ const [expand, setExpand] = useState(false);
57
65
  const { session } = useSessionContext();
58
66
  const [submitting, setSubmitting] = useState(false);
59
67
  useEffect(() => {
@@ -89,26 +97,37 @@ export default function RuntimeFormForms(_a) {
89
97
  }
90
98
  });
91
99
  const handleSubmit = (e) => __awaiter(this, void 0, void 0, function* () {
100
+ var _e;
92
101
  e.preventDefault();
93
102
  if (!session.user) {
94
103
  yield new Promise((resolve) => {
95
104
  session.login(() => resolve());
96
105
  });
97
106
  }
107
+ (_e = agent.parameters) === null || _e === void 0 ? void 0 : _e.some((parameter) => {
108
+ if (parameter.required && isEmpty(form.getValues(parameter.key))) {
109
+ setExpand(true);
110
+ return true;
111
+ }
112
+ return false;
113
+ });
114
+ // focus the first error field
115
+ form.trigger();
98
116
  return form.handleSubmit(onSubmit)(e);
99
117
  });
100
118
  const openerMessage = (_b = agent.release) === null || _b === void 0 ? void 0 : _b.openerMessage;
101
- return (_jsxs(Stack, Object.assign({ gap: 10, component: "form" }, props, { onSubmit: handleSubmit, children: [_jsxs(Stack, { gap: 2, children: [_jsx(Stack, { sx: { fontSize: 32, py: 2.5, mb: -2 }, children: "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83D\uDCBB" }), openerMessage && _jsx(Box, { sx: { color: 'text.secondary' }, children: openerMessage }), _jsx(ParameterFormFields, { parameters: agent.parameters, form: form })] }), _jsx(Suspense, { children: _jsxs(Stack, { sx: {
102
- gap: 1,
103
- position: 'sticky',
104
- bottom: 0,
105
- pb: 1,
106
- pt: 1,
107
- // 从上透明到白色 0.72 的径向渐变
108
- background: (theme) => `linear-gradient(180deg, ${alpha(theme.palette.background.default, 0.1)}, ${alpha(theme.palette.background.default, 1)} 5%)`,
109
- }, children: [error && _jsx(Alert, { severity: "error", children: error.message }), _jsx(RuntimeFormSubmit, { page: page, type: "submit", variant: "contained", fullWidth: true, loading: submitting, sx: {
110
- borderRadius: 100,
111
- height: 44,
112
- background: 'linear-gradient(90deg, rgb(69, 228, 250) 0%, rgb(138, 69, 250) 52.08%, rgb(250, 69, 188) 100%)',
113
- }, children: ((_d = (_c = agent.release) === null || _c === void 0 ? void 0 : _c.submitButton) === null || _d === void 0 ? void 0 : _d.title) || t('submit') })] }) })] })));
119
+ return (_jsxs(Stack, Object.assign({ component: "form" }, props, { onSubmit: handleSubmit, children: [isMobile && (_jsx(Button, { sx: { minWidth: 0, px: 4, py: 0, opacity: 0.7, color: 'text.secondary' }, onClick: () => setExpand(!expand), children: _jsx(Box, { component: Icon, icon: "tabler:chevron-compact-up", sx: {
120
+ fontSize: 24,
121
+ transform: `rotateX(${expand ? '180deg' : '0deg'})`,
122
+ transition: 'transform .3s ease-in-out',
123
+ } }) })), _jsx(Collapse, { in: expand || !isMobile, orientation: "vertical", sx: {
124
+ maxHeight: isMobile ? undefined : '40vh',
125
+ overflowY: 'auto',
126
+ }, children: _jsxs(Stack, { gap: 2, children: [openerMessage && _jsx(Box, { sx: { color: 'text.secondary', px: spacing }, children: openerMessage }), _jsx(ParameterFormFields, { parameters: agent.parameters, form: form, sx: { pb: 2, px: spacing } })] }) }), _jsx(Suspense, { children: _jsxs(Stack, { gap: 2, sx: {
127
+ px: spacing,
128
+ }, children: [error && _jsx(Alert, { severity: "error", children: error.message }), _jsx(RuntimeFormSubmit, { page: page, type: "submit", variant: "contained", fullWidth: true, loading: submitting,
129
+ // @ts-ignore
130
+ color: "black", sx: {
131
+ height: 40,
132
+ }, children: ((_d = (_c = agent.release) === null || _c === void 0 ? void 0 : _c.submitButton) === null || _d === void 0 ? void 0 : _d.title) || t('send') })] }) })] })));
114
133
  }
@@ -11,9 +11,20 @@ var __rest = (this && this.__rest) || function (s, e) {
11
11
  };
12
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
13
  import { Box, Stack, Typography } from '@mui/material';
14
+ import Balancer, { Provider } from 'react-wrap-balancer';
14
15
  import { Avatar } from '../../../../arcblock/ux';
15
16
  export default function RuntimeFormHeader(_a) {
16
17
  var _b, _c, _d;
17
18
  var { agent } = _a, props = __rest(_a, ["agent"]);
18
- return (_jsxs(Stack, Object.assign({ direction: "row", justifyContent: "space-between", alignItems: "center", gap: 2, bgcolor: "rgb(246, 242, 255)" }, props, { children: [_jsxs(Stack, { children: [_jsx(Typography, { component: "h5", sx: { fontSize: 32, fontWeight: 700 }, children: ((_b = agent.release) === null || _b === void 0 ? void 0 : _b.title) || agent.name }), _jsx(Typography, { sx: { fontSize: 16, color: 'rgb(147, 151, 161)' }, children: ((_c = agent.release) === null || _c === void 0 ? void 0 : _c.description) || agent.description })] }), _jsx(Stack, { children: _jsx(Box, { component: Avatar, size: 88, src: (_d = agent.release) === null || _d === void 0 ? void 0 : _d.logo, did: blocklet === null || blocklet === void 0 ? void 0 : blocklet.appId, borderRadius: 1 }) })] })));
19
+ return (_jsxs(Stack, Object.assign({ direction: {
20
+ md: 'row',
21
+ xs: 'column',
22
+ }, justifyContent: "space-between", alignItems: "center", gap: 2 }, props, { children: [_jsx(Stack, { children: _jsx(Box, { component: Avatar, size: 120, src: (_b = agent.release) === null || _b === void 0 ? void 0 : _b.logo, did: blocklet === null || blocklet === void 0 ? void 0 : blocklet.appId, borderRadius: 1 }) }), _jsx(Provider, { children: _jsxs(Stack, { spacing: 1, sx: {
23
+ flex: 1,
24
+ lineHeight: '28px',
25
+ textAlign: {
26
+ md: 'left',
27
+ xs: 'center',
28
+ },
29
+ }, children: [_jsx(Typography, { component: "h5", sx: { fontSize: 18, fontWeight: 600 }, children: _jsx(Balancer, { children: ((_c = agent.release) === null || _c === void 0 ? void 0 : _c.title) || agent.name }) }), _jsx(Typography, { sx: { fontSize: 16, color: 'rgba(75, 85, 99, 1)' }, children: _jsx(Balancer, { children: ((_d = agent.release) === null || _d === void 0 ? void 0 : _d.description) || agent.description }) })] }) })] })));
19
30
  }
@@ -9,58 +9,20 @@ var __rest = (this && this.__rest) || function (s, e) {
9
9
  }
10
10
  return t;
11
11
  };
12
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
- import { Icon } from '@iconify/react';
14
- import { Box, Button, Stack, Tooltip } from '@mui/material';
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { Box, Stack } from '@mui/material';
15
14
  import { Suspense } from 'react';
16
- import { XIcon } from 'react-share';
17
- import { withQuery } from 'ufo';
18
- import { useLocaleContext } from '../../../../locale';
19
- import lottieJsonErrorUrl from '../../assets/lottie/lottie-error.json?url';
20
- import lottieJsonLoadingUrl from '../../assets/lottie/lottie-loading.json?url';
21
- import lottieJsonSuccessUrl from '../../assets/lottie/lottie-success.json?url';
22
- import lottieJsonWelcomeUrl from '../../assets/lottie/lottie-welcome.json?url';
15
+ import { useAssistantState } from '../../state/assistant';
23
16
  import { useSessionState } from '../../state/session';
24
- import { ActionButton } from '../ActionButton';
25
- import { MessageMetadataRenderer } from '../common';
26
- import Lottie from '../lottie';
27
- import MarkdownRenderer from '../MarkdownRenderer';
17
+ import MessageItemView from '../message/MessageItemView';
28
18
  export default function RuntimeFormResult(_a) {
29
19
  var { page } = _a, props = __rest(_a, ["page"]);
30
- return (_jsxs(Stack, Object.assign({}, props, { children: [_jsx(Stack, { sx: {
31
- px: { xs: 2, sm: 3, md: 4 },
32
- py: 2.5,
33
- bgcolor: 'background.default',
34
- position: { xs: 'unset', md: 'sticky' },
35
- top: 0,
36
- zIndex: 2,
37
- fontSize: 32,
38
- }, children: "\uD83E\uDD16" }), _jsx(Box, { sx: { px: { xs: 2, sm: 3, md: 4 } }, children: _jsx(Suspense, { children: page.sessionId ? (_jsx(ResultView, { sessionId: page.sessionId })) : (_jsx(Box, { width: 300, height: 300, m: "auto", mt: "100px", children: _jsx(Lottie, { src: lottieJsonWelcomeUrl }) })) }) })] })));
20
+ return (_jsx(Stack, Object.assign({}, props, { children: _jsx(Box, { children: _jsx(Suspense, { children: page.sessionId ? _jsx(ResultView, { page: page }) : null }) }) })));
39
21
  }
40
- function ResultView({ sessionId }) {
41
- var _a, _b, _c, _d;
42
- const { t } = useLocaleContext();
43
- const [, _e] = useSessionState({ sessionId }), { messages = [] } = _e, state = __rest(_e, ["messages"]);
22
+ function ResultView({ page }) {
23
+ const { sessionId, assistantId } = page;
24
+ const [assistant] = useAssistantState({ assistantId });
25
+ const [, { messages = [] }] = useSessionState({ sessionId });
44
26
  const message = messages[messages.length - 1];
45
- const textContent = (_a = message === null || message === void 0 ? void 0 : message.result) === null || _a === void 0 ? void 0 : _a.content;
46
- const error = state.error || (message === null || message === void 0 ? void 0 : message.error);
47
- if (error) {
48
- return (_jsxs(Box, { width: 240, height: 240, m: "auto", mt: "100px", children: [_jsx(Lottie, { src: lottieJsonErrorUrl }), _jsx(Box, { textAlign: "center", color: "#25292F", children: error.message })] }));
49
- }
50
- if ((message === null || message === void 0 ? void 0 : message.loading) && !textContent) {
51
- return (_jsx(Box, { width: 240, height: 240, m: "auto", mt: "100px", children: _jsx(Lottie, { src: lottieJsonLoadingUrl }) }));
52
- }
53
- if (!message) {
54
- return (_jsx(Box, { width: 300, height: 300, m: "auto", mt: "100px", children: _jsx(Lottie, { src: lottieJsonWelcomeUrl }) }));
55
- }
56
- return (_jsxs(Stack, { gap: 2, children: [textContent && (_jsxs(Box, { sx: {
57
- border: 1,
58
- borderColor: 'grey.200',
59
- borderRadius: 1,
60
- bgcolor: 'grey.100',
61
- }, children: [_jsx(Box, { sx: { p: 2 }, children: _jsx(MarkdownRenderer, { className: (message === null || message === void 0 ? void 0 : message.loading) ? 'writing' : '', children: (_b = message === null || message === void 0 ? void 0 : message.result) === null || _b === void 0 ? void 0 : _b.content }) }), !(message === null || message === void 0 ? void 0 : message.loading) && textContent && (_jsxs(Stack, { direction: "row", alignItems: "center", justifyContent: "flex-end", px: 2, pb: 1, gap: 1, children: [_jsx(Box, { children: _jsx(ActionButton, { autoReset: true, size: "small", variant: "text",
62
- // @ts-ignore
63
- color: "black", tip: t('copyToClipboard'), tipSucceed: t('copied'), title: _jsx(Icon, { icon: "tabler:copy", fontSize: 18 }), titleSucceed: _jsx(Icon, { icon: "tabler:copy-check-filled", fontSize: 18 }), sx: { p: 0.5, minWidth: 0, minHeight: 0, color: 'text.secondary' }, onClick: () => {
64
- window.navigator.clipboard.writeText(textContent);
65
- } }) }), _jsx(Box, { children: _jsx(Tooltip, { title: t('socialShare.shareToX'), placement: "top", disableInteractive: true, children: _jsx(Button, { sx: { p: 0.5, minWidth: 0, minHeight: 0 }, target: "_blank", href: withQuery('https://twitter.com/intent/tweet', { text: textContent }), children: _jsx(XIcon, { size: 18, borderRadius: 16 }) }) }) })] }))] })), (_d = (_c = message.result) === null || _c === void 0 ? void 0 : _c.objects) === null || _d === void 0 ? void 0 : _d.map((object) => _jsx(MessageMetadataRenderer, { object: object.data }, object.taskId)), _jsx(Box, { display: "flex", justifyContent: "flex-end", mb: "60px", mt: "40px", children: _jsx(Box, { width: 120, height: 120, children: _jsx(Lottie, { src: lottieJsonSuccessUrl }) }) })] }));
27
+ return (_jsx(Stack, { gap: 2, children: message && (_jsx(MessageItemView, { hideAvatar: true, assistantId: assistantId, assistant: assistant, message: message }, message.taskId)) }));
66
28
  }
@@ -9,17 +9,9 @@ var __rest = (this && this.__rest) || function (s, e) {
9
9
  }
10
10
  return t;
11
11
  };
12
- import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
13
- import { useSubscribeLink } from '../../hooks/subscribe';
12
+ import { jsx as _jsx } from "react/jsx-runtime";
14
13
  import LoadingButton from '../LoadingButton';
15
- import PoweredBy from '../PoweredBy';
16
14
  export default function RuntimeFormSubmit(_a) {
17
15
  var { page } = _a, props = __rest(_a, ["page"]);
18
- const { subscribeLink } = useSubscribeLink({ assistantId: page.assistantId });
19
- return (_jsxs(_Fragment, { children: [_jsx(LoadingButton, Object.assign({}, props, { onClick: (e) => {
20
- if (subscribeLink) {
21
- e.preventDefault();
22
- window.location.href = subscribeLink;
23
- }
24
- } })), _jsx(PoweredBy, { assistantId: page.assistantId })] }));
16
+ return _jsx(LoadingButton, Object.assign({}, props));
25
17
  }
@@ -1,16 +1,44 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Box, Divider, Stack } from '@mui/material';
2
+ import { Box, Divider, Stack, useMediaQuery, useTheme } from '@mui/material';
3
+ import { alpha } from '../../../../mui/material';
3
4
  import { useAssistantState } from '../../state/assistant';
5
+ import PoweredBy from '../PoweredBy';
4
6
  import RuntimeFormForms from './RuntimeFormForms';
5
7
  import RuntimeFormHeader from './RuntimeFormHeader';
6
8
  import RuntimeFormResult from './RuntimeFormResult';
7
9
  export default function RuntimeForm({ page }) {
8
10
  const [agent] = useAssistantState({ assistantId: page.assistantId });
9
- return (_jsxs(Stack, { sx: { flexGrow: { xs: 'unset', md: 1 } }, children: [_jsx(RuntimeFormHeader, { agent: agent, sx: {
10
- position: 'sticky',
11
- top: 64,
12
- zIndex: 10,
13
- px: { xs: 2, sm: 3, md: 8 },
14
- py: { xs: 2, sm: 3, md: 5 },
15
- } }), _jsxs(Stack, { sx: { flexGrow: 1, flexDirection: { xs: 'column', md: 'row' } }, children: [_jsx(Stack, { sx: { flex: 1, px: { xs: 2, sm: 3, md: 4 }, ml: { xs: 0, md: 4 } }, children: _jsx(RuntimeFormForms, { page: page, sx: { position: 'sticky', top: 232 } }) }), _jsx(Divider, { orientation: "vertical", sx: { borderColor: 'grey.200', my: { xs: 2, sm: 3, md: 0 } } }), _jsx(Box, { sx: { flex: 2 }, children: _jsx(RuntimeFormResult, { page: page }) })] })] }));
11
+ const theme = useTheme();
12
+ const isMobile = useMediaQuery(theme.breakpoints.down('md'));
13
+ const spacing = {
14
+ md: 5,
15
+ xs: 2,
16
+ };
17
+ return (_jsx(Box, { sx: {
18
+ flex: 1,
19
+ display: 'flex',
20
+ }, children: _jsxs(Stack, { divider: _jsx(Divider, { orientation: "vertical", flexItem: true }), direction: {
21
+ md: 'row',
22
+ xs: 'column',
23
+ }, sx: {
24
+ flex: 1,
25
+ }, children: [_jsxs(Box, { sx: {
26
+ flex: 2,
27
+ px: spacing,
28
+ py: isMobile ? 4 : spacing,
29
+ pb: '0 !important',
30
+ display: 'flex',
31
+ flexDirection: 'column',
32
+ justifyContent: 'space-between',
33
+ }, children: [_jsxs(Stack, { gap: isMobile ? spacing : 1, spacing: spacing, children: [_jsx(RuntimeFormHeader, { agent: agent }), _jsx(RuntimeFormResult, { page: page })] }), !isMobile && _jsx(PoweredBy, { assistantId: page.assistantId, sx: { mt: spacing, mb: 0.5, px: 2, pt: 0 } })] }), _jsxs(Box, { sx: {
34
+ flex: {
35
+ md: 1,
36
+ xs: 0,
37
+ },
38
+ pt: spacing,
39
+ position: 'sticky',
40
+ bottom: 0,
41
+ // 从上透明到白色 0.72 的径向渐变
42
+ background: (theme) => `linear-gradient(180deg, ${alpha(theme.palette.background.default, 0.1)}, ${alpha(theme.palette.background.default, 1)} 16px)`,
43
+ }, children: [_jsx(RuntimeFormForms, { page: page }), isMobile && _jsx(PoweredBy, { assistantId: page.assistantId, sx: { my: 0.5, px: 2 } })] })] }) }));
16
44
  }
@@ -1,25 +1,52 @@
1
- import { jsx as _jsx } from "react/jsx-runtime";
2
- import { Box } from '@mui/material';
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import DID from '@arcblock/ux/lib/DID';
3
+ import { Box, Button } from '@mui/material';
3
4
  import { useEffect } from 'react';
5
+ import { Avatar } from '../../../arcblock/ux';
6
+ import { useLocaleContext } from '../../../locale';
4
7
  import { useHeaderState } from '../../../page/header';
5
8
  import SocialShare from '../components/SocialShare';
6
- export function useSetHeader({ assistant }) {
9
+ import ThemeProvider from '../components/ThemeProvider';
10
+ import { useSubscribeLink } from './subscribe';
11
+ const logoSize = 44;
12
+ export function useSetHeader({ assistant, assistantId }) {
13
+ const { subscribeLink, requireSubscribe } = useSubscribeLink({ assistantId });
14
+ const { t, locale } = useLocaleContext();
7
15
  // set logo
8
16
  useEffect(() => {
9
17
  const { release } = assistant;
10
18
  useHeaderState.setState((state) => {
11
- state.logo = (release === null || release === void 0 ? void 0 : release.logo) && _jsx(Box, { component: "img", src: release.logo, sx: { borderRadius: 1 } });
19
+ state.logo = (release === null || release === void 0 ? void 0 : release.logo) && (_jsx(Box, { component: 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: {
20
+ width: logoSize,
21
+ height: logoSize,
22
+ } }));
12
23
  state.brand = (release === null || release === void 0 ? void 0 : release.title) || assistant.name;
24
+ state.description = assistant.createdBy && (_jsxs(Box, { sx: {
25
+ display: 'inline-flex',
26
+ alignItems: 'center',
27
+ gap: 0.5,
28
+ mt: 0.5,
29
+ }, children: [t('by'), " ", _jsx(DID, { did: assistant.createdBy, copyable: false })] }));
13
30
  const shareContent = `${(release === null || release === void 0 ? void 0 : release.title) || assistant.name}
14
31
 
15
32
  ${release === null || release === void 0 ? void 0 : release.description}
16
33
  `;
17
- state.addons = (...exists) => [_jsx(SocialShare, { content: shareContent }), ...exists];
34
+ state.addons = (...exists) => [
35
+ _jsx(ThemeProvider, { children: _jsx(Button, { disabled: !requireSubscribe, variant: "outlined", href: subscribeLink,
36
+ // @ts-ignore
37
+ color: "black", sx: {
38
+ // 字母不大写
39
+ textTransform: 'none',
40
+ }, children: subscribeLink ? t('subscribe') : t('subscribed') }) }),
41
+ _jsx(SocialShare, { content: shareContent }),
42
+ ...exists,
43
+ ].filter(Boolean);
18
44
  });
19
45
  return () => useHeaderState.setState((state) => {
20
46
  state.logo = undefined;
21
47
  state.brand = undefined;
48
+ state.description = undefined;
22
49
  state.addons = (...exists) => [...exists];
23
50
  });
24
- }, []);
51
+ }, [locale]);
25
52
  }
@@ -42,7 +42,7 @@ function AIRuntime({ cacheId, preload }) {
42
42
  const page = useCurrentPage();
43
43
  const { assistantId } = page;
44
44
  const [assistant] = useAssistantState({ assistantId });
45
- useSetHeader({ assistant });
45
+ useSetHeader({ assistant, assistantId });
46
46
  useMemo(() => {
47
47
  // preload assistant from server side props
48
48
  if (preload)
@@ -1,6 +1,8 @@
1
1
  export const translations = {
2
2
  en: {
3
+ by: 'By',
3
4
  socialShare: {
5
+ title: 'Share',
4
6
  shareToX: 'Share to X',
5
7
  shareToTelegram: 'Share to Telegram',
6
8
  shareToReddit: 'Share to Reddit',
@@ -34,6 +36,8 @@ export const translations = {
34
36
  edit: 'Edit',
35
37
  chat: 'Chat',
36
38
  subscribeNow: 'Subscribe Now',
39
+ subscribe: 'Subscribe',
40
+ subscribed: 'Subscribed',
37
41
  requireNewSubscription: `Thank you for using our service!
38
42
 
39
43
  To get more features and exclusive content, please subscribe to our service. After subscribing, you will enjoy the following privileges:
@@ -69,9 +73,12 @@ export const translations = {
69
73
  savedToNote: 'Saved as a new document',
70
74
  uploadFile: 'Upload File',
71
75
  submit: 'Submit',
76
+ send: 'Send',
72
77
  },
73
78
  zh: {
79
+ by: '来自',
74
80
  socialShare: {
81
+ title: '分享',
75
82
  shareToX: '分享到 X',
76
83
  shareToTelegram: '分享到 Telegram',
77
84
  shareToReddit: '分享到 Reddit',
@@ -105,6 +112,8 @@ export const translations = {
105
112
  edit: '编辑',
106
113
  chat: '对话',
107
114
  subscribeNow: '立即订阅',
115
+ subscribe: '订阅',
116
+ subscribed: '已订阅',
108
117
  requireNewSubscription: `感谢您使用我们的服务!
109
118
 
110
119
  为了获得更多功能和专属内容,请订阅我们的服务。订阅后,您将享有以下特权:
@@ -140,5 +149,6 @@ export const translations = {
140
149
  savedToNote: '已保存到知识库',
141
150
  uploadFile: '上传文件',
142
151
  submit: '提交',
152
+ send: '发送',
143
153
  },
144
154
  };
@@ -12,6 +12,7 @@ export interface Assistant {
12
12
  };
13
13
  }[];
14
14
  release?: AssistantBase['release'];
15
+ createdBy?: string;
15
16
  }
16
17
  export declare function getAssistant({ assistantId: id }: {
17
18
  assistantId: string;
@@ -1,6 +1,6 @@
1
1
  import { LoadingButtonProps } from '@mui/lab';
2
2
  import { ReactNode } from 'react';
3
- export declare function ActionButton({ tip, tipSucceed, title, titleSucceed, icon, iconSucceed, autoReset, ...props }: {
3
+ export declare function ActionButton({ tip, tipSucceed, title, titleSucceed, icon, iconSucceed, autoReset, placement, ...props }: {
4
4
  tip?: ReactNode;
5
5
  tipSucceed?: ReactNode;
6
6
  title?: ReactNode;
@@ -8,4 +8,5 @@ export declare function ActionButton({ tip, tipSucceed, title, titleSucceed, ico
8
8
  icon?: ReactNode;
9
9
  iconSucceed?: ReactNode;
10
10
  autoReset?: boolean;
11
+ placement?: 'top' | 'bottom' | 'left' | 'right' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end' | 'right-start' | 'right-end' | 'left-start' | 'left-end';
11
12
  } & Omit<Partial<LoadingButtonProps>, 'title'>): import("react/jsx-runtime").JSX.Element;
@@ -1,9 +1,10 @@
1
- import { BoxProps } from '@mui/material';
1
+ import { IconButtonProps } from '@mui/material';
2
2
  import React from 'react';
3
- interface Props {
4
- sx?: BoxProps;
3
+ interface Props extends IconButtonProps {
4
+ sx?: any;
5
5
  menus?: React.ReactNode | (() => React.ReactNode);
6
+ MenuProps?: any;
6
7
  children?: React.ReactNode;
7
8
  }
8
- export default function MenuButton({ sx, menus, children }: Props): import("react/jsx-runtime").JSX.Element;
9
+ export default function MenuButton({ sx, menus, children, MenuProps, ...restProps }: Props): import("react/jsx-runtime").JSX.Element;
9
10
  export {};
@@ -1,17 +1,20 @@
1
- import { BoxProps } from '@mui/material';
1
+ import { BoxProps, IconButtonProps } from '@mui/material';
2
2
  interface SocialShareMenuProps extends BoxProps {
3
3
  url?: string;
4
4
  content: string;
5
+ MenuProps?: any;
6
+ disableCopyLink?: boolean;
5
7
  }
6
8
  interface SocialShareButtonsProps extends SocialShareMenuProps {
7
9
  itemSx?: BoxProps['sx'];
8
10
  onClick?: () => void;
9
11
  bgFill?: string;
10
12
  iconFill?: string;
13
+ sx?: BoxProps['sx'];
11
14
  }
12
15
  export default function SocialShare(props: SocialShareMenuProps & SocialShareButtonsProps & {
13
16
  type?: 'menu' | 'buttons';
14
17
  }): import("react/jsx-runtime").JSX.Element;
15
- export declare function SocialShareMenu({ url, content, ...restProps }: SocialShareMenuProps): import("react/jsx-runtime").JSX.Element;
18
+ export declare function SocialShareMenu({ url, content, children, MenuProps, disableCopyLink, ...restProps }: SocialShareMenuProps & IconButtonProps): import("react/jsx-runtime").JSX.Element;
16
19
  export declare function SocialShareButtons({ url, content, sx, itemSx, onClick, bgFill, iconFill, ...rest }: SocialShareButtonsProps): import("react/jsx-runtime").JSX.Element;
17
20
  export {};
@@ -1,4 +1,5 @@
1
1
  import { Assistant } from '../api/assistant';
2
- export declare function useSetHeader({ assistant }: {
2
+ export declare function useSetHeader({ assistant, assistantId }: {
3
3
  assistant: Assistant;
4
+ assistantId: string;
4
5
  }): void;
@@ -1,6 +1,8 @@
1
1
  export declare const translations: {
2
2
  en: {
3
+ by: string;
3
4
  socialShare: {
5
+ title: string;
4
6
  shareToX: string;
5
7
  shareToTelegram: string;
6
8
  shareToReddit: string;
@@ -34,6 +36,8 @@ export declare const translations: {
34
36
  edit: string;
35
37
  chat: string;
36
38
  subscribeNow: string;
39
+ subscribe: string;
40
+ subscribed: string;
37
41
  requireNewSubscription: string;
38
42
  requireNewSubscriptionFooter: string;
39
43
  thanksForSubscription: string;
@@ -60,9 +64,12 @@ export declare const translations: {
60
64
  savedToNote: string;
61
65
  uploadFile: string;
62
66
  submit: string;
67
+ send: string;
63
68
  };
64
69
  zh: {
70
+ by: string;
65
71
  socialShare: {
72
+ title: string;
66
73
  shareToX: string;
67
74
  shareToTelegram: string;
68
75
  shareToReddit: string;
@@ -96,6 +103,8 @@ export declare const translations: {
96
103
  edit: string;
97
104
  chat: string;
98
105
  subscribeNow: string;
106
+ subscribe: string;
107
+ subscribed: string;
99
108
  requireNewSubscription: string;
100
109
  requireNewSubscriptionFooter: string;
101
110
  thanksForSubscription: string;
@@ -122,5 +131,6 @@ export declare const translations: {
122
131
  savedToNote: string;
123
132
  uploadFile: string;
124
133
  submit: string;
134
+ send: string;
125
135
  };
126
136
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/pages-kit",
3
- "version": "0.2.288",
3
+ "version": "0.2.290",
4
4
  "description": "Pages Kit components and utils",
5
5
  "publishConfig": {
6
6
  "access": "public"