@blocklet/pages-kit 0.2.286 → 0.2.287
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/api/assistant.js +26 -0
- package/lib/cjs/builtin/async/ai-runtime/api/dataset.js +127 -0
- package/lib/cjs/builtin/async/ai-runtime/api/message.js +33 -0
- package/lib/cjs/builtin/async/ai-runtime/api/request.js +47 -0
- package/lib/cjs/builtin/async/ai-runtime/api/session.js +121 -0
- package/lib/cjs/builtin/async/ai-runtime/api/subscription.js +32 -0
- package/lib/cjs/builtin/async/ai-runtime/components/ActionButton.js +63 -0
- package/lib/cjs/builtin/async/ai-runtime/components/GlobalLoading.js +60 -0
- package/lib/cjs/builtin/async/ai-runtime/components/LoadingButton.js +40 -0
- package/lib/cjs/builtin/async/ai-runtime/components/LoadingListItemButton.js +51 -0
- package/lib/cjs/builtin/async/ai-runtime/components/MarkdownRenderer.js +156 -0
- package/lib/cjs/builtin/async/ai-runtime/components/MenuButton.js +43 -0
- package/lib/cjs/builtin/async/ai-runtime/components/PoweredBy.js +30 -0
- package/lib/cjs/builtin/async/ai-runtime/components/RuntimeProvider.js +16 -0
- package/lib/cjs/builtin/async/ai-runtime/components/ScrollView.js +109 -0
- package/lib/cjs/builtin/async/ai-runtime/components/SocialShare.js +102 -0
- package/lib/cjs/builtin/async/ai-runtime/components/ThemeProvider.js +193 -0
- package/lib/cjs/builtin/async/ai-runtime/components/collection/CollectionEditDialog.js +92 -0
- package/lib/cjs/builtin/async/ai-runtime/components/collection/CollectionListView.js +197 -0
- package/lib/cjs/builtin/async/ai-runtime/components/collection/CollectionView.js +122 -0
- package/lib/cjs/builtin/async/ai-runtime/components/collection/DocumentListView.js +152 -0
- package/lib/cjs/builtin/async/ai-runtime/components/collection/DocumentView.js +135 -0
- package/lib/cjs/builtin/async/ai-runtime/components/common/ChatBot.js +105 -0
- package/lib/cjs/builtin/async/ai-runtime/components/common/MessageMetadataRenderer.js +21 -0
- package/lib/cjs/builtin/async/ai-runtime/components/common/MessageSuggestedQuestions.js +35 -0
- package/lib/cjs/builtin/async/ai-runtime/components/common/index.js +12 -0
- package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterForm.js +48 -0
- package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterFormDialog.js +66 -0
- package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterFormFields.js +43 -0
- package/lib/cjs/builtin/async/ai-runtime/components/form/QuestionField.js +44 -0
- package/lib/cjs/builtin/async/ai-runtime/components/form/SettingButton.js +76 -0
- package/lib/cjs/builtin/async/ai-runtime/components/layout/index.js +15 -0
- package/lib/cjs/builtin/async/ai-runtime/components/lottie/index.js +34 -0
- package/lib/cjs/builtin/async/ai-runtime/components/message/MessageActions.js +38 -0
- package/lib/cjs/builtin/async/ai-runtime/components/message/MessageErrorView.js +30 -0
- package/lib/cjs/builtin/async/ai-runtime/components/message/MessageItemView.js +134 -0
- package/lib/cjs/builtin/async/ai-runtime/components/message/MessageListView.js +48 -0
- package/lib/cjs/builtin/async/ai-runtime/components/message/ReferenceLinks.js +11 -0
- package/lib/cjs/builtin/async/ai-runtime/components/parameters/LanguageField.js +55 -0
- package/lib/cjs/builtin/async/ai-runtime/components/parameters/NumberField.js +21 -0
- package/lib/cjs/builtin/async/ai-runtime/components/parameters/SelectField.js +24 -0
- package/lib/cjs/builtin/async/ai-runtime/components/parameters/StringField.js +21 -0
- package/lib/cjs/builtin/async/ai-runtime/components/parameters/index.js +37 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/InitialForm.js +94 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHeader.js +48 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHome.js +21 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +67 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/index.js +15 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +103 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormHeader.js +22 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.js +72 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormSubmit.js +31 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/index.js +22 -0
- package/lib/cjs/builtin/async/ai-runtime/components/session/CheckSession.js +62 -0
- package/lib/cjs/builtin/async/ai-runtime/components/session/SessionListView.js +88 -0
- package/lib/cjs/builtin/async/ai-runtime/constants.js +5 -0
- package/lib/cjs/builtin/async/ai-runtime/hooks/header.js +32 -0
- package/lib/cjs/builtin/async/ai-runtime/hooks/navigate.js +37 -0
- package/lib/cjs/builtin/async/ai-runtime/hooks/subscribe.js +35 -0
- package/lib/cjs/builtin/async/ai-runtime/index.js +75 -0
- package/lib/cjs/builtin/async/ai-runtime/locales/index.js +147 -0
- package/lib/cjs/builtin/async/ai-runtime/state/assistant.js +59 -0
- package/lib/cjs/builtin/async/ai-runtime/state/index.js +423 -0
- package/lib/cjs/builtin/async/ai-runtime/state/session.js +217 -0
- package/lib/cjs/builtin/async/ai-runtime/state/subscription.js +52 -0
- package/lib/cjs/builtin/async/ai-runtime/utils.js +49 -0
- package/lib/cjs/builtin/async/react-scroll-to-bottom.js +1 -1
- package/lib/cjs/utils/builtin.js +1 -0
- package/lib/cjs/utils/inject-global-components.js +2 -0
- package/lib/esm/builtin/async/ai-runtime/api/assistant.js +22 -0
- package/lib/esm/builtin/async/ai-runtime/api/dataset.js +113 -0
- package/lib/esm/builtin/async/ai-runtime/api/message.js +28 -0
- package/lib/esm/builtin/async/ai-runtime/api/request.js +43 -0
- package/lib/esm/builtin/async/ai-runtime/api/session.js +112 -0
- package/lib/esm/builtin/async/ai-runtime/api/subscription.js +27 -0
- package/lib/esm/builtin/async/ai-runtime/components/ActionButton.js +56 -0
- package/lib/esm/builtin/async/ai-runtime/components/GlobalLoading.js +56 -0
- package/lib/esm/builtin/async/ai-runtime/components/LoadingButton.js +38 -0
- package/lib/esm/builtin/async/ai-runtime/components/LoadingListItemButton.js +48 -0
- package/lib/esm/builtin/async/ai-runtime/components/MarkdownRenderer.js +129 -0
- package/lib/esm/builtin/async/ai-runtime/components/MenuButton.js +40 -0
- package/lib/esm/builtin/async/ai-runtime/components/PoweredBy.js +27 -0
- package/lib/esm/builtin/async/ai-runtime/components/RuntimeProvider.js +10 -0
- package/lib/esm/builtin/async/ai-runtime/components/ScrollView.js +101 -0
- package/lib/esm/builtin/async/ai-runtime/components/SocialShare.js +93 -0
- package/lib/esm/builtin/async/ai-runtime/components/ThemeProvider.js +190 -0
- package/lib/esm/builtin/async/ai-runtime/components/collection/CollectionEditDialog.js +92 -0
- package/lib/esm/builtin/async/ai-runtime/components/collection/CollectionListView.js +197 -0
- package/lib/esm/builtin/async/ai-runtime/components/collection/CollectionView.js +122 -0
- package/lib/esm/builtin/async/ai-runtime/components/collection/DocumentListView.js +152 -0
- package/lib/esm/builtin/async/ai-runtime/components/collection/DocumentView.js +135 -0
- package/lib/esm/builtin/async/ai-runtime/components/common/ChatBot.js +99 -0
- package/lib/esm/builtin/async/ai-runtime/components/common/MessageMetadataRenderer.js +15 -0
- package/lib/esm/builtin/async/ai-runtime/components/common/MessageSuggestedQuestions.js +30 -0
- package/lib/esm/builtin/async/ai-runtime/components/common/index.js +3 -0
- package/lib/esm/builtin/async/ai-runtime/components/form/ParameterForm.js +42 -0
- package/lib/esm/builtin/async/ai-runtime/components/form/ParameterFormDialog.js +59 -0
- package/lib/esm/builtin/async/ai-runtime/components/form/ParameterFormFields.js +37 -0
- package/lib/esm/builtin/async/ai-runtime/components/form/QuestionField.js +38 -0
- package/lib/esm/builtin/async/ai-runtime/components/form/SettingButton.js +73 -0
- package/lib/esm/builtin/async/ai-runtime/components/layout/index.js +12 -0
- package/lib/esm/builtin/async/ai-runtime/components/lottie/index.js +8 -0
- package/lib/esm/builtin/async/ai-runtime/components/message/MessageActions.js +35 -0
- package/lib/esm/builtin/async/ai-runtime/components/message/MessageErrorView.js +24 -0
- package/lib/esm/builtin/async/ai-runtime/components/message/MessageItemView.js +105 -0
- package/lib/esm/builtin/async/ai-runtime/components/message/MessageListView.js +42 -0
- package/lib/esm/builtin/async/ai-runtime/components/message/ReferenceLinks.js +8 -0
- package/lib/esm/builtin/async/ai-runtime/components/parameters/LanguageField.js +53 -0
- package/lib/esm/builtin/async/ai-runtime/components/parameters/NumberField.js +19 -0
- package/lib/esm/builtin/async/ai-runtime/components/parameters/SelectField.js +22 -0
- package/lib/esm/builtin/async/ai-runtime/components/parameters/StringField.js +19 -0
- package/lib/esm/builtin/async/ai-runtime/components/parameters/index.js +31 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/InitialForm.js +88 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHeader.js +22 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHome.js +15 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +61 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/index.js +9 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +97 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormHeader.js +19 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.js +66 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormSubmit.js +25 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/index.js +16 -0
- package/lib/esm/builtin/async/ai-runtime/components/session/CheckSession.js +59 -0
- package/lib/esm/builtin/async/ai-runtime/components/session/SessionListView.js +88 -0
- package/lib/esm/builtin/async/ai-runtime/constants.js +2 -0
- package/lib/esm/builtin/async/ai-runtime/hooks/header.js +25 -0
- package/lib/esm/builtin/async/ai-runtime/hooks/navigate.js +31 -0
- package/lib/esm/builtin/async/ai-runtime/hooks/subscribe.js +31 -0
- package/lib/esm/builtin/async/ai-runtime/index.js +66 -0
- package/lib/esm/builtin/async/ai-runtime/locales/index.js +144 -0
- package/lib/esm/builtin/async/ai-runtime/state/assistant.js +54 -0
- package/lib/esm/builtin/async/ai-runtime/state/index.js +423 -0
- package/lib/esm/builtin/async/ai-runtime/state/session.js +209 -0
- package/lib/esm/builtin/async/ai-runtime/state/subscription.js +47 -0
- package/lib/esm/builtin/async/ai-runtime/utils.js +42 -0
- package/lib/esm/builtin/async/react-scroll-to-bottom.js +1 -1
- package/lib/esm/utils/builtin.js +1 -0
- package/lib/esm/utils/inject-global-components.js +2 -0
- package/lib/types/builtin/async/ai-runtime/api/assistant.d.ts +18 -0
- package/lib/types/builtin/async/ai-runtime/api/dataset.d.ts +39 -0
- package/lib/types/builtin/async/ai-runtime/api/message.d.ts +39 -0
- package/lib/types/builtin/async/ai-runtime/api/request.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/api/session.d.ts +54 -0
- package/lib/types/builtin/async/ai-runtime/api/subscription.d.ts +15 -0
- package/lib/types/builtin/async/ai-runtime/components/ActionButton.d.ts +11 -0
- package/lib/types/builtin/async/ai-runtime/components/GlobalLoading.d.ts +33 -0
- package/lib/types/builtin/async/ai-runtime/components/LoadingButton.d.ts +3 -0
- package/lib/types/builtin/async/ai-runtime/components/LoadingListItemButton.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/components/MarkdownRenderer.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/components/MenuButton.d.ts +9 -0
- package/lib/types/builtin/async/ai-runtime/components/PoweredBy.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/RuntimeProvider.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/ScrollView.d.ts +61 -0
- package/lib/types/builtin/async/ai-runtime/components/SocialShare.d.ts +17 -0
- package/lib/types/builtin/async/ai-runtime/components/ThemeProvider.d.ts +6 -0
- package/lib/types/builtin/async/ai-runtime/components/collection/CollectionEditDialog.d.ts +0 -0
- package/lib/types/builtin/async/ai-runtime/components/collection/CollectionListView.d.ts +0 -0
- package/lib/types/builtin/async/ai-runtime/components/collection/CollectionView.d.ts +0 -0
- package/lib/types/builtin/async/ai-runtime/components/collection/DocumentListView.d.ts +0 -0
- package/lib/types/builtin/async/ai-runtime/components/collection/DocumentView.d.ts +0 -0
- package/lib/types/builtin/async/ai-runtime/components/common/ChatBot.d.ts +13 -0
- package/lib/types/builtin/async/ai-runtime/components/common/MessageMetadataRenderer.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/common/MessageSuggestedQuestions.d.ts +7 -0
- package/lib/types/builtin/async/ai-runtime/components/common/index.d.ts +3 -0
- package/lib/types/builtin/async/ai-runtime/components/form/ParameterForm.d.ts +12 -0
- package/lib/types/builtin/async/ai-runtime/components/form/ParameterFormDialog.d.ts +28 -0
- package/lib/types/builtin/async/ai-runtime/components/form/ParameterFormFields.d.ts +8 -0
- package/lib/types/builtin/async/ai-runtime/components/form/QuestionField.d.ts +13 -0
- package/lib/types/builtin/async/ai-runtime/components/form/SettingButton.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/layout/index.d.ts +7 -0
- package/lib/types/builtin/async/ai-runtime/components/lottie/index.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/message/MessageActions.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/message/MessageErrorView.d.ts +6 -0
- package/lib/types/builtin/async/ai-runtime/components/message/MessageItemView.d.ts +10 -0
- package/lib/types/builtin/async/ai-runtime/components/message/MessageListView.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/components/message/ReferenceLinks.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/parameters/LanguageField.d.ts +9 -0
- package/lib/types/builtin/async/ai-runtime/components/parameters/NumberField.d.ts +9 -0
- package/lib/types/builtin/async/ai-runtime/components/parameters/SelectField.d.ts +9 -0
- package/lib/types/builtin/async/ai-runtime/components/parameters/StringField.d.ts +9 -0
- package/lib/types/builtin/async/ai-runtime/components/parameters/index.d.ts +7 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime-chat/InitialForm.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHeader.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHome.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.d.ts +6 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime-chat/index.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime-form/RuntimeFormHeader.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime-form/RuntimeFormSubmit.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime-form/index.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/session/CheckSession.d.ts +9 -0
- package/lib/types/builtin/async/ai-runtime/components/session/SessionListView.d.ts +0 -0
- package/lib/types/builtin/async/ai-runtime/constants.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/hooks/header.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/hooks/navigate.d.ts +25 -0
- package/lib/types/builtin/async/ai-runtime/hooks/subscribe.d.ts +6 -0
- package/lib/types/builtin/async/ai-runtime/index.d.ts +17 -0
- package/lib/types/builtin/async/ai-runtime/locales/index.d.ts +126 -0
- package/lib/types/builtin/async/ai-runtime/state/assistant.d.ts +17 -0
- package/lib/types/builtin/async/ai-runtime/state/index.d.ts +0 -0
- package/lib/types/builtin/async/ai-runtime/state/session.d.ts +40 -0
- package/lib/types/builtin/async/ai-runtime/state/subscription.d.ts +15 -0
- package/lib/types/builtin/async/ai-runtime/utils.d.ts +20 -0
- package/lib/types/builtin/async/react-scroll-to-bottom.d.ts +3 -2
- package/lib/types/builtin/session.d.ts +11 -1
- package/lib/types/utils/builtin.d.ts +1 -0
- package/package.json +12 -7
- package/tsconfig.json +5 -1
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// import { Icon } from '@iconify/react';
|
|
3
|
+
// import { Alert, Button, CircularProgress, Divider, Stack, TextField } from '@mui/material';
|
|
4
|
+
// import { useEffect, useRef, useState } from 'react';
|
|
5
|
+
// import { useForm } from 'react-hook-form';
|
|
6
|
+
// import { Result, Toast } from '../../../../arcblock/ux';
|
|
7
|
+
// import { useLocaleContext } from '../../../../locale';
|
|
8
|
+
// import { getDocument } from '../../api/dataset';
|
|
9
|
+
// import { useCurrentPage, useNavigateTo, useNavigateWithQuery } from '../../hooks/navigate';
|
|
10
|
+
// import { createDatasetDetailState } from '../../state';
|
|
11
|
+
// import Layout from '../layout';
|
|
12
|
+
// import LoadingButton from '../LoadingButton';
|
|
13
|
+
// export default function DocumentView() {
|
|
14
|
+
// const { t } = useLocaleContext();
|
|
15
|
+
// const to = useNavigateTo();
|
|
16
|
+
// const navigate = useNavigateWithQuery();
|
|
17
|
+
// const [loading, setLoading] = useState(false);
|
|
18
|
+
// const [error, setError] = useState();
|
|
19
|
+
// const { datasetId, documentId } = useCurrentPage();
|
|
20
|
+
// const datasetDetailState = createDatasetDetailState({ datasetId })();
|
|
21
|
+
// const form = useForm({});
|
|
22
|
+
// const hiddenSubmit = useRef();
|
|
23
|
+
// useEffect(() => {
|
|
24
|
+
// if (!documentId) {
|
|
25
|
+
// form.reset();
|
|
26
|
+
// return;
|
|
27
|
+
// }
|
|
28
|
+
// (async () => {
|
|
29
|
+
// setLoading(true);
|
|
30
|
+
// try {
|
|
31
|
+
// const { document } = await getDocument(datasetId, documentId);
|
|
32
|
+
// form.reset({
|
|
33
|
+
// name: document.name,
|
|
34
|
+
// content: document.content,
|
|
35
|
+
// });
|
|
36
|
+
// } catch (error) {
|
|
37
|
+
// setError(error);
|
|
38
|
+
// } finally {
|
|
39
|
+
// setLoading(false);
|
|
40
|
+
// }
|
|
41
|
+
// })();
|
|
42
|
+
// }, [documentId]);
|
|
43
|
+
// const onSubmit = async (input) => {
|
|
44
|
+
// try {
|
|
45
|
+
// if (documentId) {
|
|
46
|
+
// await datasetDetailState.updateDocument(documentId, 'text', input);
|
|
47
|
+
// } else {
|
|
48
|
+
// await datasetDetailState.createDocument('text', input);
|
|
49
|
+
// }
|
|
50
|
+
// navigate({ page: 'collection', datasetId });
|
|
51
|
+
// } catch (error) {
|
|
52
|
+
// Toast.error(error.message);
|
|
53
|
+
// console.error(error);
|
|
54
|
+
// }
|
|
55
|
+
// };
|
|
56
|
+
// if (error) {
|
|
57
|
+
// return <Result status="error" title={error.message} sx={{ bgcolor: 'transparent', my: 10 }} />;
|
|
58
|
+
// }
|
|
59
|
+
// return (
|
|
60
|
+
// <>
|
|
61
|
+
// <Stack
|
|
62
|
+
// direction="row"
|
|
63
|
+
// height={64}
|
|
64
|
+
// alignItems="center"
|
|
65
|
+
// justifyContent="space-between"
|
|
66
|
+
// sx={{
|
|
67
|
+
// position: 'sticky',
|
|
68
|
+
// top: 64,
|
|
69
|
+
// bgcolor: 'background.default',
|
|
70
|
+
// zIndex: 10,
|
|
71
|
+
// borderBottom: 1,
|
|
72
|
+
// borderColor: 'divider',
|
|
73
|
+
// px: 2.5,
|
|
74
|
+
// }}>
|
|
75
|
+
// <Button
|
|
76
|
+
// sx={{ minWidth: 32, minHeight: 32, px: 1, ml: -1 }}
|
|
77
|
+
// component={RouterLink}
|
|
78
|
+
// startIcon={<Icon icon="tabler:chevron-left" />}
|
|
79
|
+
// to={to({ page: 'collection', datasetId })}>
|
|
80
|
+
// {t('back')}
|
|
81
|
+
// </Button>
|
|
82
|
+
// <LoadingButton
|
|
83
|
+
// disabled={loading}
|
|
84
|
+
// size="small"
|
|
85
|
+
// variant="contained"
|
|
86
|
+
// color="secondary"
|
|
87
|
+
// startIcon={<Icon icon="tabler:book-2" />}
|
|
88
|
+
// loading={form.formState.isSubmitting}
|
|
89
|
+
// loadingPosition="start"
|
|
90
|
+
// onClick={() => hiddenSubmit.current.click()}>
|
|
91
|
+
// {t('save')}
|
|
92
|
+
// </LoadingButton>
|
|
93
|
+
// </Stack>
|
|
94
|
+
// <Layout>
|
|
95
|
+
// {loading || error ? (
|
|
96
|
+
// <Stack alignItems="center" gap={0.5} mt="10vh" mx={3}>
|
|
97
|
+
// {loading ? <CircularProgress size={24} /> : error ? <Alert severity="error">{error.message}</Alert> : null}
|
|
98
|
+
// </Stack>
|
|
99
|
+
// ) : (
|
|
100
|
+
// <Stack
|
|
101
|
+
// component="form"
|
|
102
|
+
// onSubmit={form.handleSubmit(onSubmit)}
|
|
103
|
+
// sx={{ bgcolor: 'background.paper', mt: 2.5, borderRadius: 1.5, border: 1, borderColor: 'divider' }}>
|
|
104
|
+
// <TextField
|
|
105
|
+
// multiline
|
|
106
|
+
// variant="standard"
|
|
107
|
+
// InputProps={{
|
|
108
|
+
// disableUnderline: true,
|
|
109
|
+
// sx: { fontSize: 32, fontWeight: 700, lineHeight: '44px', px: 2.5, pt: 2.5 },
|
|
110
|
+
// }}
|
|
111
|
+
// hiddenLabel
|
|
112
|
+
// placeholder={t('titlePlaceholder')}
|
|
113
|
+
// {...form.register('name')}
|
|
114
|
+
// />
|
|
115
|
+
// <Divider sx={{ my: 1.5, mx: 2.5 }} />
|
|
116
|
+
// <TextField
|
|
117
|
+
// variant="standard"
|
|
118
|
+
// InputProps={{
|
|
119
|
+
// disableUnderline: true,
|
|
120
|
+
// sx: { px: 2.5, pb: 2.5 },
|
|
121
|
+
// }}
|
|
122
|
+
// multiline
|
|
123
|
+
// minRows={20}
|
|
124
|
+
// hiddenLabel
|
|
125
|
+
// size="small"
|
|
126
|
+
// placeholder={t('contentPlaceholder')}
|
|
127
|
+
// {...form.register('content')}
|
|
128
|
+
// />
|
|
129
|
+
// <Button ref={hiddenSubmit} sx={{ display: 'none' }} type="submit" />
|
|
130
|
+
// </Stack>
|
|
131
|
+
// )}
|
|
132
|
+
// </Layout>
|
|
133
|
+
// </>
|
|
134
|
+
// );
|
|
135
|
+
// }
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import Dialog from '@arcblock/ux/lib/Dialog';
|
|
3
|
+
import { Icon } from '@iconify/react';
|
|
4
|
+
import ArrowBackIosNewIcon from '@mui/icons-material/ArrowBackIosNew';
|
|
5
|
+
import { Box, Button, ClickAwayListener, IconButton, Popper, Typography, useMediaQuery, useTheme } from '@mui/material';
|
|
6
|
+
import { useCallback, useRef, useState } from 'react';
|
|
7
|
+
import { Avatar } from '../../../../arcblock/ux';
|
|
8
|
+
import { useAssistantState } from '../../state/assistant';
|
|
9
|
+
import ScrollView from '../ScrollView';
|
|
10
|
+
export default function ChatBot({ assistantId, size, bottom, right, children, popperWidth, popperHeight, }) {
|
|
11
|
+
var _a, _b, _c;
|
|
12
|
+
const anchorEl = useRef(null);
|
|
13
|
+
const [assistant] = useAssistantState({ assistantId });
|
|
14
|
+
const [openPopper, setOpenPopper] = useState(false);
|
|
15
|
+
const theme = useTheme();
|
|
16
|
+
const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
|
|
17
|
+
const chatViewSizeSx = isMobile
|
|
18
|
+
? { width: '100vw', height: 'calc(100vh - 72px)' }
|
|
19
|
+
: { width: '40vw', height: '70vh' };
|
|
20
|
+
if (popperWidth) {
|
|
21
|
+
chatViewSizeSx.width = popperWidth;
|
|
22
|
+
}
|
|
23
|
+
if (popperHeight) {
|
|
24
|
+
chatViewSizeSx.height = popperHeight;
|
|
25
|
+
}
|
|
26
|
+
const title = ((_a = assistant.release) === null || _a === void 0 ? void 0 : _a.title) || (assistant === null || assistant === void 0 ? void 0 : assistant.name);
|
|
27
|
+
const WrapperComponent = useCallback(({ children }) => {
|
|
28
|
+
if (isMobile) {
|
|
29
|
+
return (_jsx(Dialog, { showCloseButton: false, sx: {
|
|
30
|
+
'.ux-dialog_header': {
|
|
31
|
+
borderBottom: '1px solid rgba(229, 231, 235, 1)',
|
|
32
|
+
},
|
|
33
|
+
'.MuiDialogContent-root': {
|
|
34
|
+
p: 0,
|
|
35
|
+
display: 'flex',
|
|
36
|
+
},
|
|
37
|
+
}, open: openPopper, title: _jsxs(Box, { sx: {
|
|
38
|
+
display: 'flex',
|
|
39
|
+
alignItems: 'center',
|
|
40
|
+
gap: 1,
|
|
41
|
+
ml: -1,
|
|
42
|
+
}, children: [_jsx(IconButton, { size: "small", onClick: () => setOpenPopper(false), children: _jsx(ArrowBackIosNewIcon, { fontSize: "inherit" }) }), _jsx(Box, { children: title })] }), onClose: () => {
|
|
43
|
+
setOpenPopper(false);
|
|
44
|
+
}, children: children }));
|
|
45
|
+
}
|
|
46
|
+
return (_jsx(Popper, { anchorEl: anchorEl.current, open: openPopper, placement: "top-end", sx: Object.assign({ zIndex: 1200, minWidth: { sm: 400 } }, chatViewSizeSx), children: _jsx(ClickAwayListener, { onClickAway: (e) => {
|
|
47
|
+
e.preventDefault();
|
|
48
|
+
e.stopPropagation();
|
|
49
|
+
setOpenPopper(false);
|
|
50
|
+
}, children: _jsxs(Box, { sx: {
|
|
51
|
+
boxShadow: '0px 8px 16px 0px rgba(2, 7, 19, 0.08), 0px 0px 0px 1px rgba(2, 7, 19, 0.08)',
|
|
52
|
+
position: 'relative',
|
|
53
|
+
background: 'white',
|
|
54
|
+
borderRadius: 1,
|
|
55
|
+
}, children: [_jsxs(Box, { sx: {
|
|
56
|
+
zIndex: 1200,
|
|
57
|
+
display: 'flex',
|
|
58
|
+
alignItems: 'center',
|
|
59
|
+
justifyContent: 'space-between',
|
|
60
|
+
borderBottom: '1px solid rgba(229, 231, 235, 1)',
|
|
61
|
+
px: 2,
|
|
62
|
+
py: 2,
|
|
63
|
+
height: 70,
|
|
64
|
+
}, children: [_jsx(Typography, { component: "p", sx: {
|
|
65
|
+
fontSize: 18,
|
|
66
|
+
fontWeight: 600,
|
|
67
|
+
lineHeight: '28px',
|
|
68
|
+
}, children: title }), _jsx(Button, { sx: { minWidth: 28, minHeight: 28 }, onClick: () => setOpenPopper(false), children: _jsx(Icon, { icon: "ic:round-close", fontSize: 24, color: "rgba(75, 85, 99, 1)" }) })] }), children] }) }) }));
|
|
69
|
+
}, [isMobile, openPopper]);
|
|
70
|
+
if (!assistant)
|
|
71
|
+
return null;
|
|
72
|
+
return (_jsxs(_Fragment, { children: [_jsxs(Box, { sx: {
|
|
73
|
+
display: 'inline-flex',
|
|
74
|
+
flexDirection: 'column',
|
|
75
|
+
justifyContent: 'center',
|
|
76
|
+
alignItems: 'center',
|
|
77
|
+
position: 'fixed',
|
|
78
|
+
bottom: bottom || 24,
|
|
79
|
+
right: right || 24,
|
|
80
|
+
boxShadow: '0px 2px 4px 0px rgba(3, 7, 18, 0.04)',
|
|
81
|
+
cursor: 'pointer !important',
|
|
82
|
+
zIndex: 1000,
|
|
83
|
+
transition: 'transform 0.3s',
|
|
84
|
+
':hover': {
|
|
85
|
+
transform: 'scale(1.05)',
|
|
86
|
+
},
|
|
87
|
+
}, onClick: () => {
|
|
88
|
+
setOpenPopper(!openPopper);
|
|
89
|
+
}, children: [_jsx(Avatar, { className: "logo", size: size || 48, did: (_b = globalThis.blocklet) === null || _b === void 0 ? void 0 : _b.appId, variant: "circle", shape: "circle", src: (_c = assistant.release) === null || _c === void 0 ? void 0 : _c.logo }), _jsx(Box, { width: "100%", ref: anchorEl })] }), anchorEl.current && (_jsx(WrapperComponent, { children: _jsx(ScrollView, { className: "ai-bot-scroll-container", initialScrollBehavior: "auto", component: Box, sx: {
|
|
90
|
+
overscrollBehavior: 'contain',
|
|
91
|
+
height: isMobile ? '100%' : `calc(${chatViewSizeSx.height} - 70px)`,
|
|
92
|
+
width: '100%',
|
|
93
|
+
overflowY: 'auto',
|
|
94
|
+
display: 'flex',
|
|
95
|
+
'.ai-chat-header': {
|
|
96
|
+
pt: 4,
|
|
97
|
+
},
|
|
98
|
+
}, children: children }) }))] }));
|
|
99
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
import ImagePreview from '@blocklet/ai-kit/components/image-preview';
|
|
3
|
+
import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
|
|
4
|
+
import { Stack, Typography } from '@mui/material';
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
import ReferenceLinks from '../message/ReferenceLinks';
|
|
7
|
+
export default function MessageMetadataRenderer({ object }) {
|
|
8
|
+
const referenceLinks = object[RuntimeOutputVariable.referenceLinks];
|
|
9
|
+
const images = useMemo(() => {
|
|
10
|
+
const list = object[RuntimeOutputVariable.images];
|
|
11
|
+
const images = (Array.isArray(list) ? list.map((i) => ({ src: i.url })) : []).filter((i) => typeof i.src === 'string');
|
|
12
|
+
return images.length ? images : undefined;
|
|
13
|
+
}, [object]);
|
|
14
|
+
return (_jsxs(_Fragment, { children: [Array.isArray(referenceLinks) && referenceLinks.length ? _jsx(ReferenceLinks, { links: referenceLinks }) : undefined, images && (_jsxs(Stack, { gap: 1, children: [_jsx(Typography, { variant: "subtitle2", children: "Images:" }), _jsx(ImagePreview, { dataSource: images, itemWidth: 100 })] }))] }));
|
|
15
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
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
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { Stack, Typography } from '@mui/material';
|
|
14
|
+
export default function MessageSuggestedQuestions({ dataSource, onClick, }) {
|
|
15
|
+
const suggestedQuestions = dataSource;
|
|
16
|
+
if (suggestedQuestions === null || suggestedQuestions === void 0 ? void 0 : suggestedQuestions.length) {
|
|
17
|
+
return (_jsx(Stack, { gap: 1, children: suggestedQuestions.map((item) => {
|
|
18
|
+
return (_jsx(MessageSuggestedQuestion, { onClick: () => onClick === null || onClick === void 0 ? void 0 : onClick(item), children: item.question }, item.question));
|
|
19
|
+
}) }));
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
export function MessageSuggestedQuestion(_a) {
|
|
24
|
+
var props = __rest(_a, []);
|
|
25
|
+
return (_jsx(Typography, Object.assign({ variant: "subtitle2" }, props, { sx: Object.assign({ display: 'inline-block', border: 1, borderColor: 'rgba(229, 231, 235, 1)', borderRadius: 1, py: 1, px: 2,
|
|
26
|
+
// without logo width
|
|
27
|
+
maxWidth: 'calc(100% - 20px)', cursor: 'pointer', '&:hover': {
|
|
28
|
+
backgroundColor: 'rgba(239, 246, 255, 1)',
|
|
29
|
+
} }, props.sx) })));
|
|
30
|
+
}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { Box, Stack, Tooltip } from '@mui/material';
|
|
12
|
+
import omit from 'lodash/omit';
|
|
13
|
+
import { useEffect, useMemo } from 'react';
|
|
14
|
+
import { useForm } from 'react-hook-form';
|
|
15
|
+
import { useLocaleContext } from '../../../../locale';
|
|
16
|
+
import LoadingButton from '../LoadingButton';
|
|
17
|
+
import ParameterFormFields from './ParameterFormFields';
|
|
18
|
+
import QuestionField from './QuestionField';
|
|
19
|
+
import SettingButton from './SettingButton';
|
|
20
|
+
export default function ParameterForm(_a) {
|
|
21
|
+
var _b, _c, _d, _e;
|
|
22
|
+
var { sessionId, disabled, readOnly, onSubmit, defaultValues, hideSubmit, isSubmitting, assistant, submitButtonTitle = (_c = (_b = assistant.release) === null || _b === void 0 ? void 0 : _b.submitButton) === null || _c === void 0 ? void 0 : _c.title, } = _a;
|
|
23
|
+
const { t } = useLocaleContext();
|
|
24
|
+
const parameters = (_d = assistant.parameters) === null || _d === void 0 ? void 0 : _d.filter((i) => i.key && !['question', 'datasetId'].includes(i.key));
|
|
25
|
+
const isChat = (_e = assistant.parameters) === null || _e === void 0 ? void 0 : _e.some((i) => i.key === 'question');
|
|
26
|
+
const defaultForm = useMemo(() => {
|
|
27
|
+
var _a;
|
|
28
|
+
return defaultValues !== null && defaultValues !== void 0 ? defaultValues : Object.fromEntries((_a = parameters === null || parameters === void 0 ? void 0 : parameters.map((parameter) => [parameter.key, parameter.defaultValue])) !== null && _a !== void 0 ? _a : []);
|
|
29
|
+
}, [defaultValues]);
|
|
30
|
+
const form = useForm({ defaultValues: omit(defaultForm, isChat ? ['question'] : []) });
|
|
31
|
+
useEffect(() => {
|
|
32
|
+
form.reset(omit(defaultForm, 'question'));
|
|
33
|
+
}, [defaultForm]);
|
|
34
|
+
const handleSubmit = (parameters) => __awaiter(this, void 0, void 0, function* () {
|
|
35
|
+
if (onSubmit) {
|
|
36
|
+
yield onSubmit(parameters);
|
|
37
|
+
form.reset(omit(parameters, 'question'));
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
return (_jsxs(Stack, { className: "ai-chat-form", component: "form", onSubmit: form.handleSubmit(handleSubmit), gap: 2, children: [!!(parameters === null || parameters === void 0 ? void 0 : parameters.length) && (_jsx(ParameterFormFields, { disabled: disabled, readOnly: readOnly, parameters: parameters, form: form })), !hideSubmit &&
|
|
41
|
+
(isChat ? (_jsx(QuestionField, { sessionId: sessionId, showSettingButton: !!sessionId, assistant: assistant, disabled: disabled, submitButtonTitle: submitButtonTitle, readOnly: readOnly, isSubmitting: isSubmitting, form: form, autoFocus: !(parameters === null || parameters === void 0 ? void 0 : parameters.length) })) : (_jsxs(Stack, { className: "ai-chat-generation-bar", direction: "row", alignItems: "center", justifyContent: "flex-end", gap: 2, children: [sessionId && _jsx(SettingButton, { 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') }) }) })] })))] }));
|
|
42
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { Icon } from '@iconify/react';
|
|
12
|
+
import { Box, Button, Dialog, DialogActions, DialogContent, DialogTitle, useMediaQuery, useTheme } from '@mui/material';
|
|
13
|
+
import { useForm } from 'react-hook-form';
|
|
14
|
+
import { create } from 'zustand';
|
|
15
|
+
import { immer } from 'zustand/middleware/immer';
|
|
16
|
+
import { useLocaleContext } from '../../../../locale';
|
|
17
|
+
import { useAssistantState } from '../../state/assistant';
|
|
18
|
+
import { useSessionState } from '../../state/session';
|
|
19
|
+
import LoadingButton from '../LoadingButton';
|
|
20
|
+
import ParameterFormFields from './ParameterFormFields';
|
|
21
|
+
export default function ParameterFormDialog({ assistantId, sessionId, DialogProps, }) {
|
|
22
|
+
const { t } = useLocaleContext();
|
|
23
|
+
const theme = useTheme();
|
|
24
|
+
const fullScreen = useMediaQuery(theme.breakpoints.down('sm'));
|
|
25
|
+
const dialogState = parameterFormDialogState();
|
|
26
|
+
const [assistant] = useAssistantState({ assistantId });
|
|
27
|
+
const { parameters } = assistant;
|
|
28
|
+
const [session, sessionState] = useSessionState({ sessionId, required: true });
|
|
29
|
+
const form = useForm({ defaultValues: Object.assign({}, session.parameters) });
|
|
30
|
+
const onSubmit = (parameters) => __awaiter(this, void 0, void 0, function* () {
|
|
31
|
+
yield sessionState.updateSession({ parameters });
|
|
32
|
+
dialogState.close();
|
|
33
|
+
});
|
|
34
|
+
return (_jsxs(Dialog, Object.assign({}, DialogProps, { open: dialogState.isOpen, onClose: dialogState.close, fullScreen: fullScreen, maxWidth: "sm", fullWidth: true, component: "form", onSubmit: form.handleSubmit(onSubmit), sx: {
|
|
35
|
+
zIndex: (theme) => theme.zIndex.modal + 1,
|
|
36
|
+
}, children: [_jsxs(DialogTitle, { sx: { display: 'flex', alignItems: 'center', gap: 1 }, children: [_jsx(Box, { flex: 1, children: t('parameters') }), _jsx(Button, { sx: { minWidth: 28, minHeight: 28 }, onClick: dialogState.close, children: _jsx(Icon, { icon: "ic:round-close", fontSize: 24, color: "rgba(75, 85, 99, 1)" }) })] }), _jsx(DialogContent, { dividers: true, children: _jsx(ParameterFormFields, { parameters: parameters, form: form }) }), _jsxs(DialogActions, { children: [_jsx(Button, { variant: "outlined",
|
|
37
|
+
// @ts-ignore
|
|
38
|
+
color: "black", size: "small", onClick: dialogState.close, children: t('cancel') }), _jsx(LoadingButton, { variant: "contained", color: "black", type: "submit", size: "small", loading: form.formState.isSubmitting, children: t('save') })] })] })));
|
|
39
|
+
}
|
|
40
|
+
export const parameterFormDialogState = create()(immer((set, get) => ({
|
|
41
|
+
isOpen: false,
|
|
42
|
+
callback: undefined,
|
|
43
|
+
open() {
|
|
44
|
+
return new Promise((resolve) => {
|
|
45
|
+
set((state) => {
|
|
46
|
+
state.isOpen = true;
|
|
47
|
+
state.callback = resolve;
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
},
|
|
51
|
+
close() {
|
|
52
|
+
var _a, _b;
|
|
53
|
+
(_b = (_a = get()).callback) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
54
|
+
set((state) => {
|
|
55
|
+
state.isOpen = false;
|
|
56
|
+
state.callback = undefined;
|
|
57
|
+
});
|
|
58
|
+
},
|
|
59
|
+
})));
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Stack, Typography } from '@mui/material';
|
|
3
|
+
import { Controller } from 'react-hook-form';
|
|
4
|
+
import ParameterField from '../parameters';
|
|
5
|
+
export default function ParameterFormFields({ disabled, readOnly, parameters, form, }) {
|
|
6
|
+
let isFirstParameterRendered = false;
|
|
7
|
+
return (_jsx(Stack, { gap: 2, children: parameters === null || parameters === void 0 ? void 0 : parameters.map((parameter) => {
|
|
8
|
+
const { key, required } = parameter !== null && parameter !== void 0 ? parameter : {};
|
|
9
|
+
if (!key)
|
|
10
|
+
return null;
|
|
11
|
+
const isFirstParameter = !isFirstParameterRendered;
|
|
12
|
+
isFirstParameterRendered = true;
|
|
13
|
+
return (_jsx(Box, { children: _jsx(Controller, { disabled: disabled, control: form.control, name: key, rules: {
|
|
14
|
+
required,
|
|
15
|
+
min: parameter.type === 'number' && typeof parameter.min === 'number'
|
|
16
|
+
? { value: parameter.min, message: '' }
|
|
17
|
+
: undefined,
|
|
18
|
+
max: parameter.type === 'number' && typeof parameter.max === 'number'
|
|
19
|
+
? { value: parameter.max, message: '' }
|
|
20
|
+
: undefined,
|
|
21
|
+
minLength: parameter.type === 'string' && typeof parameter.minLength === 'number'
|
|
22
|
+
? { value: parameter.minLength, message: '' }
|
|
23
|
+
: undefined,
|
|
24
|
+
maxLength: parameter.type === 'string' && typeof parameter.maxLength === 'number'
|
|
25
|
+
? { value: parameter.maxLength, message: '' }
|
|
26
|
+
: undefined,
|
|
27
|
+
}, render: ({ field, fieldState }) => {
|
|
28
|
+
var _a;
|
|
29
|
+
return (_jsxs(Box, { children: [_jsx(Typography, { component: "div", sx: {
|
|
30
|
+
lineHeight: '24px',
|
|
31
|
+
mb: 0.5,
|
|
32
|
+
fontWeight: 500,
|
|
33
|
+
color: 'rgba(18, 22, 24, 1)',
|
|
34
|
+
}, children: (parameter === null || parameter === void 0 ? void 0 : parameter.label) || parameter.key }), _jsx(ParameterField, { autoFocus: isFirstParameter, readOnly: readOnly, size: "small", hiddenLabel: true, fullWidth: true, label: undefined, parameter: parameter, maxRows: !(parameter === null || parameter === void 0 ? void 0 : parameter.type) || (parameter === null || parameter === void 0 ? void 0 : parameter.type) === 'string' ? 5 : undefined, value: field.value || '', onChange: (value) => field.onChange({ target: { value } }), error: Boolean(fieldState.error), helperText: ((_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message) || (parameter === null || parameter === void 0 ? void 0 : parameter.helper), sx: { bgcolor: 'background.paper' } })] }));
|
|
35
|
+
} }) }, parameter.id));
|
|
36
|
+
}) }));
|
|
37
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Icon } from '@iconify/react';
|
|
3
|
+
import { TextField, Tooltip } from '@mui/material';
|
|
4
|
+
import { useMemo, useRef } from 'react';
|
|
5
|
+
import { Controller } from 'react-hook-form';
|
|
6
|
+
import { useLocaleContext } from '../../../../locale';
|
|
7
|
+
import LoadingButton from '../LoadingButton';
|
|
8
|
+
import SettingButton from './SettingButton';
|
|
9
|
+
export default function QuestionField({ sessionId, assistant, showSettingButton, form, isSubmitting, autoFocus, readOnly, disabled, submitButtonTitle, }) {
|
|
10
|
+
const { t } = useLocaleContext();
|
|
11
|
+
const defaultPlaceholder = t('questionPlaceholder');
|
|
12
|
+
const placeholder = useMemo(() => { var _a, _b; return ((_b = (_a = assistant.parameters) === null || _a === void 0 ? void 0 : _a.find((i) => i.key === 'question')) === null || _b === void 0 ? void 0 : _b.placeholder) || defaultPlaceholder; }, [submitButtonTitle, assistant, defaultPlaceholder]);
|
|
13
|
+
const submitRef = useRef(null);
|
|
14
|
+
return (_jsx(Controller, { control: form.control, name: "question", rules: { required: true }, render: ({ field }) => (_jsx(TextField, { disabled: disabled, inputRef: field.ref, id: "question-input", required: true, size: "small", multiline: true, fullWidth: true, variant: "outlined", autoFocus: autoFocus, placeholder: placeholder, value: field.value || '', onChange: (e) => field.onChange(e), onKeyDownCapture: (e) => {
|
|
15
|
+
var _a;
|
|
16
|
+
// NOTE: Pressing Enter in the IME will trigger the 229 event
|
|
17
|
+
if (e.keyCode === 229)
|
|
18
|
+
return;
|
|
19
|
+
if (e.key === 'Enter' && !e.shiftKey) {
|
|
20
|
+
e.preventDefault();
|
|
21
|
+
(_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.click();
|
|
22
|
+
}
|
|
23
|
+
}, InputProps: {
|
|
24
|
+
readOnly,
|
|
25
|
+
sx: { p: 1, bgcolor: 'white', borderRadius: 1 },
|
|
26
|
+
startAdornment: showSettingButton && sessionId && (_jsx(SettingButton, { sessionId: sessionId, sx: { minWidth: 32, minHeight: 32 }, tabIndex: -1 })),
|
|
27
|
+
className: 'ai-chat-question-field',
|
|
28
|
+
endAdornment: (_jsx(Tooltip, { title: submitButtonTitle, disableInteractive: true, placement: "top", children: _jsx("span", { children: _jsx(LoadingButton, { disabled: disabled, id: "question-submit", ref: submitRef, type: "submit", variant: "contained",
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
color: "black", sx: {
|
|
31
|
+
alignSelf: 'flex-end',
|
|
32
|
+
ml: 1,
|
|
33
|
+
p: 0.25,
|
|
34
|
+
minWidth: 32,
|
|
35
|
+
minHeight: 32,
|
|
36
|
+
}, loading: form.formState.isSubmitting || isSubmitting, children: _jsx(Icon, { icon: "tabler:arrow-up", fontSize: 26 }) }) }) })),
|
|
37
|
+
} })) }));
|
|
38
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
|
+
import { Icon } from '@iconify/react';
|
|
23
|
+
import { Box, Button, ClickAwayListener, MenuItem, Paper, Popper } from '@mui/material';
|
|
24
|
+
import { useState } from 'react';
|
|
25
|
+
import { useLocaleContext } from '../../../../locale';
|
|
26
|
+
import { useSessionState } from '../../state/session';
|
|
27
|
+
export default function SettingButton(_a) {
|
|
28
|
+
var { sessionId } = _a, props = __rest(_a, ["sessionId"]);
|
|
29
|
+
const { t } = useLocaleContext();
|
|
30
|
+
const [, state] = useSessionState({ sessionId, required: true });
|
|
31
|
+
const [openSetting, setOpenSetting] = useState(false);
|
|
32
|
+
const settingOptions = [
|
|
33
|
+
// {
|
|
34
|
+
// key: 'parametersSetting',
|
|
35
|
+
// label: t('parametersSetting'),
|
|
36
|
+
// onClick: () => parametersDialogOpen(),
|
|
37
|
+
// icon: 'tabler:adjustments-horizontal',
|
|
38
|
+
// sx: {
|
|
39
|
+
// color: 'rgba(3, 7, 18, 1)',
|
|
40
|
+
// },
|
|
41
|
+
// },
|
|
42
|
+
{
|
|
43
|
+
key: 'clearSession',
|
|
44
|
+
label: t('clearSession'),
|
|
45
|
+
onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
46
|
+
yield state.clearSession({
|
|
47
|
+
sessionId,
|
|
48
|
+
});
|
|
49
|
+
}),
|
|
50
|
+
icon: 'tabler:eraser',
|
|
51
|
+
sx: {
|
|
52
|
+
color: 'rgba(225, 29, 72, 1)',
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
];
|
|
56
|
+
return [
|
|
57
|
+
_jsx(Button, Object.assign({ id: "setting-button", onClick: () => setOpenSetting(!openSetting) }, props, { sx: Object.assign({ minWidth: 40, minHeight: 40, p: 0, mr: 1, alignSelf: 'flex-end' }, props.sx), children: _jsx(Box, { component: Icon, icon: "tabler:menu-2", sx: { fontSize: 24, color: 'black.main' } }) }), "setting-button"),
|
|
58
|
+
_jsx(Popper, { anchorEl: document.getElementById('setting-button'), open: openSetting, placement: "top-start", sx: { zIndex: (theme) => theme.zIndex.modal + 1 }, children: _jsx(ClickAwayListener, { onClickAway: (e) => {
|
|
59
|
+
e.preventDefault();
|
|
60
|
+
e.stopPropagation();
|
|
61
|
+
setOpenSetting(false);
|
|
62
|
+
}, children: _jsx(Paper, { sx: {
|
|
63
|
+
py: 0.5,
|
|
64
|
+
boxShadow: '0px 8px 16px 0px rgba(2, 7, 19, 0.08), 0px 0px 0px 1px rgba(2, 7, 19, 0.08)',
|
|
65
|
+
}, children: settingOptions.map((option) => {
|
|
66
|
+
const { key, label, onClick, icon, sx } = option;
|
|
67
|
+
return (_jsxs(MenuItem, { onClick: () => {
|
|
68
|
+
setOpenSetting(false);
|
|
69
|
+
onClick();
|
|
70
|
+
}, sx: Object.assign({ fontSize: 13, lineHeight: '22px', py: 0.75, px: 1.5, fontWeight: 400 }, sx), children: [_jsx(Box, { component: Icon, icon: icon, sx: { fontSize: 16, mr: 1 } }), label] }, key));
|
|
71
|
+
}) }) }) }, "setting-popper"),
|
|
72
|
+
];
|
|
73
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Stack } from '@mui/material';
|
|
3
|
+
import { mergeSx } from '../../utils';
|
|
4
|
+
export default function Layout({ children, disableBottomPadding, containerProps, }) {
|
|
5
|
+
return (_jsx(Stack, { className: "ai-chat-wrapper", mx: 2, flexGrow: 1, children: _jsx(Box, Object.assign({ className: "ai-chat-container" }, containerProps, { sx: mergeSx({
|
|
6
|
+
flexGrow: 1,
|
|
7
|
+
maxWidth: 720,
|
|
8
|
+
width: '100%',
|
|
9
|
+
mx: 'auto',
|
|
10
|
+
pb: disableBottomPadding ? 0 : 10,
|
|
11
|
+
}, containerProps === null || containerProps === void 0 ? void 0 : containerProps.sx), children: children })) }));
|
|
12
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect } from 'react';
|
|
3
|
+
export default function Lottie({ src }) {
|
|
4
|
+
useEffect(() => {
|
|
5
|
+
import('@lottiefiles/lottie-player');
|
|
6
|
+
}, []);
|
|
7
|
+
return _jsx("lottie-player", { autoplay: true, loop: true, mode: "normal", src: src }, src);
|
|
8
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
};
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { Stack } from '@mui/material';
|
|
14
|
+
import { useLocaleContext } from '../../../../locale';
|
|
15
|
+
import { ActionButton } from '../ActionButton';
|
|
16
|
+
export default function MessageActions(_a) {
|
|
17
|
+
var { content } = _a, props = __rest(_a, ["content"]);
|
|
18
|
+
const { t } = useLocaleContext();
|
|
19
|
+
const commonActionButtonsSx = {
|
|
20
|
+
border: '0px !important',
|
|
21
|
+
minWidth: '32px',
|
|
22
|
+
color: 'rgba(75, 85, 99, 1)',
|
|
23
|
+
'.MuiButton-startIcon': {
|
|
24
|
+
marginRight: '0px !important',
|
|
25
|
+
},
|
|
26
|
+
};
|
|
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
|
+
} }) })));
|
|
35
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Alert, Box, Button } from '@mui/material';
|
|
3
|
+
import { useLocaleContext } from '../../../../locale';
|
|
4
|
+
import { useSubscribeLink } from '../../hooks/subscribe';
|
|
5
|
+
import MarkdownRenderer from '../MarkdownRenderer';
|
|
6
|
+
export default function MessageErrorView({ assistantId, assistant, error, }) {
|
|
7
|
+
var _a, _b, _c;
|
|
8
|
+
const { t } = useLocaleContext();
|
|
9
|
+
const { subscribeLink } = useSubscribeLink({ assistantId });
|
|
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', {
|
|
16
|
+
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') })) })] }));
|
|
22
|
+
}
|
|
23
|
+
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
|
+
}
|