@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.
- package/lib/cjs/builtin/async/ai-runtime/components/ActionButton.js +2 -2
- package/lib/cjs/builtin/async/ai-runtime/components/MenuButton.js +15 -3
- package/lib/cjs/builtin/async/ai-runtime/components/SocialShare.js +6 -9
- package/lib/cjs/builtin/async/ai-runtime/components/ThemeProvider.js +6 -0
- package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterForm.js +1 -1
- package/lib/cjs/builtin/async/ai-runtime/components/message/MessageActions.js +39 -8
- package/lib/cjs/builtin/async/ai-runtime/components/message/MessageErrorView.js +4 -10
- package/lib/cjs/builtin/async/ai-runtime/components/message/MessageItemView.js +52 -40
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +2 -2
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +39 -20
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormHeader.js +35 -1
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.js +9 -47
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormSubmit.js +1 -9
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/index.js +35 -7
- package/lib/cjs/builtin/async/ai-runtime/hooks/header.js +31 -4
- package/lib/cjs/builtin/async/ai-runtime/index.js +1 -1
- package/lib/cjs/builtin/async/ai-runtime/locales/index.js +10 -0
- package/lib/esm/builtin/async/ai-runtime/components/ActionButton.js +2 -2
- package/lib/esm/builtin/async/ai-runtime/components/MenuButton.js +15 -3
- package/lib/esm/builtin/async/ai-runtime/components/SocialShare.js +6 -9
- package/lib/esm/builtin/async/ai-runtime/components/ThemeProvider.js +6 -0
- package/lib/esm/builtin/async/ai-runtime/components/form/ParameterForm.js +1 -1
- package/lib/esm/builtin/async/ai-runtime/components/message/MessageActions.js +40 -9
- package/lib/esm/builtin/async/ai-runtime/components/message/MessageErrorView.js +4 -10
- package/lib/esm/builtin/async/ai-runtime/components/message/MessageItemView.js +53 -41
- package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +2 -2
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +34 -15
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormHeader.js +12 -1
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.js +10 -48
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormSubmit.js +2 -10
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/index.js +36 -8
- package/lib/esm/builtin/async/ai-runtime/hooks/header.js +33 -6
- package/lib/esm/builtin/async/ai-runtime/index.js +1 -1
- package/lib/esm/builtin/async/ai-runtime/locales/index.js +10 -0
- package/lib/types/builtin/async/ai-runtime/api/assistant.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/components/ActionButton.d.ts +2 -1
- package/lib/types/builtin/async/ai-runtime/components/MenuButton.d.ts +5 -4
- package/lib/types/builtin/async/ai-runtime/components/SocialShare.d.ts +5 -2
- package/lib/types/builtin/async/ai-runtime/hooks/header.d.ts +2 -1
- package/lib/types/builtin/async/ai-runtime/locales/index.d.ts +10 -0
- 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 {
|
|
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({
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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:
|
|
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
|
|
13
|
-
import {
|
|
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 {
|
|
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
|
|
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 (
|
|
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({
|
|
41
|
-
|
|
42
|
-
const {
|
|
43
|
-
const [,
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
|
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
|
-
|
|
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:
|
|
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) => [
|
|
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
|
};
|
|
@@ -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 {
|
|
1
|
+
import { IconButtonProps } from '@mui/material';
|
|
2
2
|
import React from 'react';
|
|
3
|
-
interface Props {
|
|
4
|
-
sx?:
|
|
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,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
|
};
|