@blocklet/pages-kit 0.2.285 → 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 +13 -8
- 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,105 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const Dialog_1 = __importDefault(require("@arcblock/ux/lib/Dialog"));
|
|
8
|
+
const react_1 = require("@iconify/react");
|
|
9
|
+
const ArrowBackIosNew_1 = __importDefault(require("@mui/icons-material/ArrowBackIosNew"));
|
|
10
|
+
const material_1 = require("@mui/material");
|
|
11
|
+
const react_2 = require("react");
|
|
12
|
+
const ux_1 = require("../../../../arcblock/ux");
|
|
13
|
+
const assistant_1 = require("../../state/assistant");
|
|
14
|
+
const ScrollView_1 = __importDefault(require("../ScrollView"));
|
|
15
|
+
function ChatBot({ assistantId, size, bottom, right, children, popperWidth, popperHeight, }) {
|
|
16
|
+
var _a, _b, _c;
|
|
17
|
+
const anchorEl = (0, react_2.useRef)(null);
|
|
18
|
+
const [assistant] = (0, assistant_1.useAssistantState)({ assistantId });
|
|
19
|
+
const [openPopper, setOpenPopper] = (0, react_2.useState)(false);
|
|
20
|
+
const theme = (0, material_1.useTheme)();
|
|
21
|
+
const isMobile = (0, material_1.useMediaQuery)(theme.breakpoints.down('sm'));
|
|
22
|
+
const chatViewSizeSx = isMobile
|
|
23
|
+
? { width: '100vw', height: 'calc(100vh - 72px)' }
|
|
24
|
+
: { width: '40vw', height: '70vh' };
|
|
25
|
+
if (popperWidth) {
|
|
26
|
+
chatViewSizeSx.width = popperWidth;
|
|
27
|
+
}
|
|
28
|
+
if (popperHeight) {
|
|
29
|
+
chatViewSizeSx.height = popperHeight;
|
|
30
|
+
}
|
|
31
|
+
const title = ((_a = assistant.release) === null || _a === void 0 ? void 0 : _a.title) || (assistant === null || assistant === void 0 ? void 0 : assistant.name);
|
|
32
|
+
const WrapperComponent = (0, react_2.useCallback)(({ children }) => {
|
|
33
|
+
if (isMobile) {
|
|
34
|
+
return ((0, jsx_runtime_1.jsx)(Dialog_1.default, { showCloseButton: false, sx: {
|
|
35
|
+
'.ux-dialog_header': {
|
|
36
|
+
borderBottom: '1px solid rgba(229, 231, 235, 1)',
|
|
37
|
+
},
|
|
38
|
+
'.MuiDialogContent-root': {
|
|
39
|
+
p: 0,
|
|
40
|
+
display: 'flex',
|
|
41
|
+
},
|
|
42
|
+
}, open: openPopper, title: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
43
|
+
display: 'flex',
|
|
44
|
+
alignItems: 'center',
|
|
45
|
+
gap: 1,
|
|
46
|
+
ml: -1,
|
|
47
|
+
}, children: [(0, jsx_runtime_1.jsx)(material_1.IconButton, { size: "small", onClick: () => setOpenPopper(false), children: (0, jsx_runtime_1.jsx)(ArrowBackIosNew_1.default, { fontSize: "inherit" }) }), (0, jsx_runtime_1.jsx)(material_1.Box, { children: title })] }), onClose: () => {
|
|
48
|
+
setOpenPopper(false);
|
|
49
|
+
}, children: children }));
|
|
50
|
+
}
|
|
51
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Popper, { anchorEl: anchorEl.current, open: openPopper, placement: "top-end", sx: Object.assign({ zIndex: 1200, minWidth: { sm: 400 } }, chatViewSizeSx), children: (0, jsx_runtime_1.jsx)(material_1.ClickAwayListener, { onClickAway: (e) => {
|
|
52
|
+
e.preventDefault();
|
|
53
|
+
e.stopPropagation();
|
|
54
|
+
setOpenPopper(false);
|
|
55
|
+
}, children: (0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
56
|
+
boxShadow: '0px 8px 16px 0px rgba(2, 7, 19, 0.08), 0px 0px 0px 1px rgba(2, 7, 19, 0.08)',
|
|
57
|
+
position: 'relative',
|
|
58
|
+
background: 'white',
|
|
59
|
+
borderRadius: 1,
|
|
60
|
+
}, children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
61
|
+
zIndex: 1200,
|
|
62
|
+
display: 'flex',
|
|
63
|
+
alignItems: 'center',
|
|
64
|
+
justifyContent: 'space-between',
|
|
65
|
+
borderBottom: '1px solid rgba(229, 231, 235, 1)',
|
|
66
|
+
px: 2,
|
|
67
|
+
py: 2,
|
|
68
|
+
height: 70,
|
|
69
|
+
}, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { component: "p", sx: {
|
|
70
|
+
fontSize: 18,
|
|
71
|
+
fontWeight: 600,
|
|
72
|
+
lineHeight: '28px',
|
|
73
|
+
}, children: title }), (0, jsx_runtime_1.jsx)(material_1.Button, { sx: { minWidth: 28, minHeight: 28 }, onClick: () => setOpenPopper(false), children: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "ic:round-close", fontSize: 24, color: "rgba(75, 85, 99, 1)" }) })] }), children] }) }) }));
|
|
74
|
+
}, [isMobile, openPopper]);
|
|
75
|
+
if (!assistant)
|
|
76
|
+
return null;
|
|
77
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
|
|
78
|
+
display: 'inline-flex',
|
|
79
|
+
flexDirection: 'column',
|
|
80
|
+
justifyContent: 'center',
|
|
81
|
+
alignItems: 'center',
|
|
82
|
+
position: 'fixed',
|
|
83
|
+
bottom: bottom || 24,
|
|
84
|
+
right: right || 24,
|
|
85
|
+
boxShadow: '0px 2px 4px 0px rgba(3, 7, 18, 0.04)',
|
|
86
|
+
cursor: 'pointer !important',
|
|
87
|
+
zIndex: 1000,
|
|
88
|
+
transition: 'transform 0.3s',
|
|
89
|
+
':hover': {
|
|
90
|
+
transform: 'scale(1.05)',
|
|
91
|
+
},
|
|
92
|
+
}, onClick: () => {
|
|
93
|
+
setOpenPopper(!openPopper);
|
|
94
|
+
}, children: [(0, jsx_runtime_1.jsx)(ux_1.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 }), (0, jsx_runtime_1.jsx)(material_1.Box, { width: "100%", ref: anchorEl })] }), anchorEl.current && ((0, jsx_runtime_1.jsx)(WrapperComponent, { children: (0, jsx_runtime_1.jsx)(ScrollView_1.default, { className: "ai-bot-scroll-container", initialScrollBehavior: "auto", component: material_1.Box, sx: {
|
|
95
|
+
overscrollBehavior: 'contain',
|
|
96
|
+
height: isMobile ? '100%' : `calc(${chatViewSizeSx.height} - 70px)`,
|
|
97
|
+
width: '100%',
|
|
98
|
+
overflowY: 'auto',
|
|
99
|
+
display: 'flex',
|
|
100
|
+
'.ai-chat-header': {
|
|
101
|
+
pt: 4,
|
|
102
|
+
},
|
|
103
|
+
}, children: children }) }))] }));
|
|
104
|
+
}
|
|
105
|
+
exports.default = ChatBot;
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const image_preview_1 = __importDefault(require("@blocklet/ai-kit/components/image-preview"));
|
|
8
|
+
const types_1 = require("@blocklet/ai-runtime/types");
|
|
9
|
+
const material_1 = require("@mui/material");
|
|
10
|
+
const react_1 = require("react");
|
|
11
|
+
const ReferenceLinks_1 = __importDefault(require("../message/ReferenceLinks"));
|
|
12
|
+
function MessageMetadataRenderer({ object }) {
|
|
13
|
+
const referenceLinks = object[types_1.RuntimeOutputVariable.referenceLinks];
|
|
14
|
+
const images = (0, react_1.useMemo)(() => {
|
|
15
|
+
const list = object[types_1.RuntimeOutputVariable.images];
|
|
16
|
+
const images = (Array.isArray(list) ? list.map((i) => ({ src: i.url })) : []).filter((i) => typeof i.src === 'string');
|
|
17
|
+
return images.length ? images : undefined;
|
|
18
|
+
}, [object]);
|
|
19
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [Array.isArray(referenceLinks) && referenceLinks.length ? (0, jsx_runtime_1.jsx)(ReferenceLinks_1.default, { links: referenceLinks }) : undefined, images && ((0, jsx_runtime_1.jsxs)(material_1.Stack, { gap: 1, children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { variant: "subtitle2", children: "Images:" }), (0, jsx_runtime_1.jsx)(image_preview_1.default, { dataSource: images, itemWidth: 100 })] }))] }));
|
|
20
|
+
}
|
|
21
|
+
exports.default = MessageMetadataRenderer;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.MessageSuggestedQuestion = void 0;
|
|
15
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
16
|
+
const material_1 = require("@mui/material");
|
|
17
|
+
function MessageSuggestedQuestions({ dataSource, onClick, }) {
|
|
18
|
+
const suggestedQuestions = dataSource;
|
|
19
|
+
if (suggestedQuestions === null || suggestedQuestions === void 0 ? void 0 : suggestedQuestions.length) {
|
|
20
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Stack, { gap: 1, children: suggestedQuestions.map((item) => {
|
|
21
|
+
return ((0, jsx_runtime_1.jsx)(MessageSuggestedQuestion, { onClick: () => onClick === null || onClick === void 0 ? void 0 : onClick(item), children: item.question }, item.question));
|
|
22
|
+
}) }));
|
|
23
|
+
}
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
exports.default = MessageSuggestedQuestions;
|
|
27
|
+
function MessageSuggestedQuestion(_a) {
|
|
28
|
+
var props = __rest(_a, []);
|
|
29
|
+
return ((0, jsx_runtime_1.jsx)(material_1.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,
|
|
30
|
+
// without logo width
|
|
31
|
+
maxWidth: 'calc(100% - 20px)', cursor: 'pointer', '&:hover': {
|
|
32
|
+
backgroundColor: 'rgba(239, 246, 255, 1)',
|
|
33
|
+
} }, props.sx) })));
|
|
34
|
+
}
|
|
35
|
+
exports.MessageSuggestedQuestion = MessageSuggestedQuestion;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ChatBot = exports.MessageSuggestedQuestions = exports.MessageMetadataRenderer = void 0;
|
|
7
|
+
var MessageMetadataRenderer_1 = require("./MessageMetadataRenderer");
|
|
8
|
+
Object.defineProperty(exports, "MessageMetadataRenderer", { enumerable: true, get: function () { return __importDefault(MessageMetadataRenderer_1).default; } });
|
|
9
|
+
var MessageSuggestedQuestions_1 = require("./MessageSuggestedQuestions");
|
|
10
|
+
Object.defineProperty(exports, "MessageSuggestedQuestions", { enumerable: true, get: function () { return __importDefault(MessageSuggestedQuestions_1).default; } });
|
|
11
|
+
var ChatBot_1 = require("./ChatBot");
|
|
12
|
+
Object.defineProperty(exports, "ChatBot", { enumerable: true, get: function () { return __importDefault(ChatBot_1).default; } });
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
16
|
+
const material_1 = require("@mui/material");
|
|
17
|
+
const omit_1 = __importDefault(require("lodash/omit"));
|
|
18
|
+
const react_1 = require("react");
|
|
19
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
20
|
+
const locale_1 = require("../../../../locale");
|
|
21
|
+
const LoadingButton_1 = __importDefault(require("../LoadingButton"));
|
|
22
|
+
const ParameterFormFields_1 = __importDefault(require("./ParameterFormFields"));
|
|
23
|
+
const QuestionField_1 = __importDefault(require("./QuestionField"));
|
|
24
|
+
const SettingButton_1 = __importDefault(require("./SettingButton"));
|
|
25
|
+
function ParameterForm(_a) {
|
|
26
|
+
var _b, _c, _d, _e;
|
|
27
|
+
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;
|
|
28
|
+
const { t } = (0, locale_1.useLocaleContext)();
|
|
29
|
+
const parameters = (_d = assistant.parameters) === null || _d === void 0 ? void 0 : _d.filter((i) => i.key && !['question', 'datasetId'].includes(i.key));
|
|
30
|
+
const isChat = (_e = assistant.parameters) === null || _e === void 0 ? void 0 : _e.some((i) => i.key === 'question');
|
|
31
|
+
const defaultForm = (0, react_1.useMemo)(() => {
|
|
32
|
+
var _a;
|
|
33
|
+
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 : []);
|
|
34
|
+
}, [defaultValues]);
|
|
35
|
+
const form = (0, react_hook_form_1.useForm)({ defaultValues: (0, omit_1.default)(defaultForm, isChat ? ['question'] : []) });
|
|
36
|
+
(0, react_1.useEffect)(() => {
|
|
37
|
+
form.reset((0, omit_1.default)(defaultForm, 'question'));
|
|
38
|
+
}, [defaultForm]);
|
|
39
|
+
const handleSubmit = (parameters) => __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
if (onSubmit) {
|
|
41
|
+
yield onSubmit(parameters);
|
|
42
|
+
form.reset((0, omit_1.default)(parameters, 'question'));
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-form", component: "form", onSubmit: form.handleSubmit(handleSubmit), gap: 2, children: [!!(parameters === null || parameters === void 0 ? void 0 : parameters.length) && ((0, jsx_runtime_1.jsx)(ParameterFormFields_1.default, { disabled: disabled, readOnly: readOnly, parameters: parameters, form: form })), !hideSubmit &&
|
|
46
|
+
(isChat ? ((0, jsx_runtime_1.jsx)(QuestionField_1.default, { 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) })) : ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-generation-bar", direction: "row", alignItems: "center", justifyContent: "flex-end", gap: 2, children: [sessionId && (0, jsx_runtime_1.jsx)(SettingButton_1.default, { sessionId: sessionId }), (0, jsx_runtime_1.jsx)(material_1.Box, { flex: 1 }), (0, jsx_runtime_1.jsx)(material_1.Tooltip, { title: submitButtonTitle, disableInteractive: true, placement: "top", children: (0, jsx_runtime_1.jsx)("span", { children: (0, jsx_runtime_1.jsx)(LoadingButton_1.default, { disabled: disabled, type: "submit", variant: "contained", color: "secondary", loading: form.formState.isSubmitting || isSubmitting, children: submitButtonTitle || t('submit') }) }) })] })))] }));
|
|
47
|
+
}
|
|
48
|
+
exports.default = ParameterForm;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.parameterFormDialogState = void 0;
|
|
16
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
17
|
+
const react_1 = require("@iconify/react");
|
|
18
|
+
const material_1 = require("@mui/material");
|
|
19
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
20
|
+
const zustand_1 = require("zustand");
|
|
21
|
+
const immer_1 = require("zustand/middleware/immer");
|
|
22
|
+
const locale_1 = require("../../../../locale");
|
|
23
|
+
const assistant_1 = require("../../state/assistant");
|
|
24
|
+
const session_1 = require("../../state/session");
|
|
25
|
+
const LoadingButton_1 = __importDefault(require("../LoadingButton"));
|
|
26
|
+
const ParameterFormFields_1 = __importDefault(require("./ParameterFormFields"));
|
|
27
|
+
function ParameterFormDialog({ assistantId, sessionId, DialogProps, }) {
|
|
28
|
+
const { t } = (0, locale_1.useLocaleContext)();
|
|
29
|
+
const theme = (0, material_1.useTheme)();
|
|
30
|
+
const fullScreen = (0, material_1.useMediaQuery)(theme.breakpoints.down('sm'));
|
|
31
|
+
const dialogState = (0, exports.parameterFormDialogState)();
|
|
32
|
+
const [assistant] = (0, assistant_1.useAssistantState)({ assistantId });
|
|
33
|
+
const { parameters } = assistant;
|
|
34
|
+
const [session, sessionState] = (0, session_1.useSessionState)({ sessionId, required: true });
|
|
35
|
+
const form = (0, react_hook_form_1.useForm)({ defaultValues: Object.assign({}, session.parameters) });
|
|
36
|
+
const onSubmit = (parameters) => __awaiter(this, void 0, void 0, function* () {
|
|
37
|
+
yield sessionState.updateSession({ parameters });
|
|
38
|
+
dialogState.close();
|
|
39
|
+
});
|
|
40
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Dialog, Object.assign({}, DialogProps, { open: dialogState.isOpen, onClose: dialogState.close, fullScreen: fullScreen, maxWidth: "sm", fullWidth: true, component: "form", onSubmit: form.handleSubmit(onSubmit), sx: {
|
|
41
|
+
zIndex: (theme) => theme.zIndex.modal + 1,
|
|
42
|
+
}, children: [(0, jsx_runtime_1.jsxs)(material_1.DialogTitle, { sx: { display: 'flex', alignItems: 'center', gap: 1 }, children: [(0, jsx_runtime_1.jsx)(material_1.Box, { flex: 1, children: t('parameters') }), (0, jsx_runtime_1.jsx)(material_1.Button, { sx: { minWidth: 28, minHeight: 28 }, onClick: dialogState.close, children: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "ic:round-close", fontSize: 24, color: "rgba(75, 85, 99, 1)" }) })] }), (0, jsx_runtime_1.jsx)(material_1.DialogContent, { dividers: true, children: (0, jsx_runtime_1.jsx)(ParameterFormFields_1.default, { parameters: parameters, form: form }) }), (0, jsx_runtime_1.jsxs)(material_1.DialogActions, { children: [(0, jsx_runtime_1.jsx)(material_1.Button, { variant: "outlined",
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
color: "black", size: "small", onClick: dialogState.close, children: t('cancel') }), (0, jsx_runtime_1.jsx)(LoadingButton_1.default, { variant: "contained", color: "black", type: "submit", size: "small", loading: form.formState.isSubmitting, children: t('save') })] })] })));
|
|
45
|
+
}
|
|
46
|
+
exports.default = ParameterFormDialog;
|
|
47
|
+
exports.parameterFormDialogState = (0, zustand_1.create)()((0, immer_1.immer)((set, get) => ({
|
|
48
|
+
isOpen: false,
|
|
49
|
+
callback: undefined,
|
|
50
|
+
open() {
|
|
51
|
+
return new Promise((resolve) => {
|
|
52
|
+
set((state) => {
|
|
53
|
+
state.isOpen = true;
|
|
54
|
+
state.callback = resolve;
|
|
55
|
+
});
|
|
56
|
+
});
|
|
57
|
+
},
|
|
58
|
+
close() {
|
|
59
|
+
var _a, _b;
|
|
60
|
+
(_b = (_a = get()).callback) === null || _b === void 0 ? void 0 : _b.call(_a);
|
|
61
|
+
set((state) => {
|
|
62
|
+
state.isOpen = false;
|
|
63
|
+
state.callback = undefined;
|
|
64
|
+
});
|
|
65
|
+
},
|
|
66
|
+
})));
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const material_1 = require("@mui/material");
|
|
8
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
9
|
+
const parameters_1 = __importDefault(require("../parameters"));
|
|
10
|
+
function ParameterFormFields({ disabled, readOnly, parameters, form, }) {
|
|
11
|
+
let isFirstParameterRendered = false;
|
|
12
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Stack, { gap: 2, children: parameters === null || parameters === void 0 ? void 0 : parameters.map((parameter) => {
|
|
13
|
+
const { key, required } = parameter !== null && parameter !== void 0 ? parameter : {};
|
|
14
|
+
if (!key)
|
|
15
|
+
return null;
|
|
16
|
+
const isFirstParameter = !isFirstParameterRendered;
|
|
17
|
+
isFirstParameterRendered = true;
|
|
18
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(react_hook_form_1.Controller, { disabled: disabled, control: form.control, name: key, rules: {
|
|
19
|
+
required,
|
|
20
|
+
min: parameter.type === 'number' && typeof parameter.min === 'number'
|
|
21
|
+
? { value: parameter.min, message: '' }
|
|
22
|
+
: undefined,
|
|
23
|
+
max: parameter.type === 'number' && typeof parameter.max === 'number'
|
|
24
|
+
? { value: parameter.max, message: '' }
|
|
25
|
+
: undefined,
|
|
26
|
+
minLength: parameter.type === 'string' && typeof parameter.minLength === 'number'
|
|
27
|
+
? { value: parameter.minLength, message: '' }
|
|
28
|
+
: undefined,
|
|
29
|
+
maxLength: parameter.type === 'string' && typeof parameter.maxLength === 'number'
|
|
30
|
+
? { value: parameter.maxLength, message: '' }
|
|
31
|
+
: undefined,
|
|
32
|
+
}, render: ({ field, fieldState }) => {
|
|
33
|
+
var _a;
|
|
34
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { component: "div", sx: {
|
|
35
|
+
lineHeight: '24px',
|
|
36
|
+
mb: 0.5,
|
|
37
|
+
fontWeight: 500,
|
|
38
|
+
color: 'rgba(18, 22, 24, 1)',
|
|
39
|
+
}, children: (parameter === null || parameter === void 0 ? void 0 : parameter.label) || parameter.key }), (0, jsx_runtime_1.jsx)(parameters_1.default, { 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' } })] }));
|
|
40
|
+
} }) }, parameter.id));
|
|
41
|
+
}) }));
|
|
42
|
+
}
|
|
43
|
+
exports.default = ParameterFormFields;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
+
const react_1 = require("@iconify/react");
|
|
8
|
+
const material_1 = require("@mui/material");
|
|
9
|
+
const react_2 = require("react");
|
|
10
|
+
const react_hook_form_1 = require("react-hook-form");
|
|
11
|
+
const locale_1 = require("../../../../locale");
|
|
12
|
+
const LoadingButton_1 = __importDefault(require("../LoadingButton"));
|
|
13
|
+
const SettingButton_1 = __importDefault(require("./SettingButton"));
|
|
14
|
+
function QuestionField({ sessionId, assistant, showSettingButton, form, isSubmitting, autoFocus, readOnly, disabled, submitButtonTitle, }) {
|
|
15
|
+
const { t } = (0, locale_1.useLocaleContext)();
|
|
16
|
+
const defaultPlaceholder = t('questionPlaceholder');
|
|
17
|
+
const placeholder = (0, react_2.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]);
|
|
18
|
+
const submitRef = (0, react_2.useRef)(null);
|
|
19
|
+
return ((0, jsx_runtime_1.jsx)(react_hook_form_1.Controller, { control: form.control, name: "question", rules: { required: true }, render: ({ field }) => ((0, jsx_runtime_1.jsx)(material_1.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) => {
|
|
20
|
+
var _a;
|
|
21
|
+
// NOTE: Pressing Enter in the IME will trigger the 229 event
|
|
22
|
+
if (e.keyCode === 229)
|
|
23
|
+
return;
|
|
24
|
+
if (e.key === 'Enter' && !e.shiftKey) {
|
|
25
|
+
e.preventDefault();
|
|
26
|
+
(_a = submitRef.current) === null || _a === void 0 ? void 0 : _a.click();
|
|
27
|
+
}
|
|
28
|
+
}, InputProps: {
|
|
29
|
+
readOnly,
|
|
30
|
+
sx: { p: 1, bgcolor: 'white', borderRadius: 1 },
|
|
31
|
+
startAdornment: showSettingButton && sessionId && ((0, jsx_runtime_1.jsx)(SettingButton_1.default, { sessionId: sessionId, sx: { minWidth: 32, minHeight: 32 }, tabIndex: -1 })),
|
|
32
|
+
className: 'ai-chat-question-field',
|
|
33
|
+
endAdornment: ((0, jsx_runtime_1.jsx)(material_1.Tooltip, { title: submitButtonTitle, disableInteractive: true, placement: "top", children: (0, jsx_runtime_1.jsx)("span", { children: (0, jsx_runtime_1.jsx)(LoadingButton_1.default, { disabled: disabled, id: "question-submit", ref: submitRef, type: "submit", variant: "contained",
|
|
34
|
+
// @ts-ignore
|
|
35
|
+
color: "black", sx: {
|
|
36
|
+
alignSelf: 'flex-end',
|
|
37
|
+
ml: 1,
|
|
38
|
+
p: 0.25,
|
|
39
|
+
minWidth: 32,
|
|
40
|
+
minHeight: 32,
|
|
41
|
+
}, loading: form.formState.isSubmitting || isSubmitting, children: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "tabler:arrow-up", fontSize: 26 }) }) }) })),
|
|
42
|
+
} })) }));
|
|
43
|
+
}
|
|
44
|
+
exports.default = QuestionField;
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
24
|
+
const react_1 = require("@iconify/react");
|
|
25
|
+
const material_1 = require("@mui/material");
|
|
26
|
+
const react_2 = require("react");
|
|
27
|
+
const locale_1 = require("../../../../locale");
|
|
28
|
+
const session_1 = require("../../state/session");
|
|
29
|
+
function SettingButton(_a) {
|
|
30
|
+
var { sessionId } = _a, props = __rest(_a, ["sessionId"]);
|
|
31
|
+
const { t } = (0, locale_1.useLocaleContext)();
|
|
32
|
+
const [, state] = (0, session_1.useSessionState)({ sessionId, required: true });
|
|
33
|
+
const [openSetting, setOpenSetting] = (0, react_2.useState)(false);
|
|
34
|
+
const settingOptions = [
|
|
35
|
+
// {
|
|
36
|
+
// key: 'parametersSetting',
|
|
37
|
+
// label: t('parametersSetting'),
|
|
38
|
+
// onClick: () => parametersDialogOpen(),
|
|
39
|
+
// icon: 'tabler:adjustments-horizontal',
|
|
40
|
+
// sx: {
|
|
41
|
+
// color: 'rgba(3, 7, 18, 1)',
|
|
42
|
+
// },
|
|
43
|
+
// },
|
|
44
|
+
{
|
|
45
|
+
key: 'clearSession',
|
|
46
|
+
label: t('clearSession'),
|
|
47
|
+
onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
yield state.clearSession({
|
|
49
|
+
sessionId,
|
|
50
|
+
});
|
|
51
|
+
}),
|
|
52
|
+
icon: 'tabler:eraser',
|
|
53
|
+
sx: {
|
|
54
|
+
color: 'rgba(225, 29, 72, 1)',
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
];
|
|
58
|
+
return [
|
|
59
|
+
(0, jsx_runtime_1.jsx)(material_1.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: (0, jsx_runtime_1.jsx)(material_1.Box, { component: react_1.Icon, icon: "tabler:menu-2", sx: { fontSize: 24, color: 'black.main' } }) }), "setting-button"),
|
|
60
|
+
(0, jsx_runtime_1.jsx)(material_1.Popper, { anchorEl: document.getElementById('setting-button'), open: openSetting, placement: "top-start", sx: { zIndex: (theme) => theme.zIndex.modal + 1 }, children: (0, jsx_runtime_1.jsx)(material_1.ClickAwayListener, { onClickAway: (e) => {
|
|
61
|
+
e.preventDefault();
|
|
62
|
+
e.stopPropagation();
|
|
63
|
+
setOpenSetting(false);
|
|
64
|
+
}, children: (0, jsx_runtime_1.jsx)(material_1.Paper, { sx: {
|
|
65
|
+
py: 0.5,
|
|
66
|
+
boxShadow: '0px 8px 16px 0px rgba(2, 7, 19, 0.08), 0px 0px 0px 1px rgba(2, 7, 19, 0.08)',
|
|
67
|
+
}, children: settingOptions.map((option) => {
|
|
68
|
+
const { key, label, onClick, icon, sx } = option;
|
|
69
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.MenuItem, { onClick: () => {
|
|
70
|
+
setOpenSetting(false);
|
|
71
|
+
onClick();
|
|
72
|
+
}, sx: Object.assign({ fontSize: 13, lineHeight: '22px', py: 0.75, px: 1.5, fontWeight: 400 }, sx), children: [(0, jsx_runtime_1.jsx)(material_1.Box, { component: react_1.Icon, icon: icon, sx: { fontSize: 16, mr: 1 } }), label] }, key));
|
|
73
|
+
}) }) }) }, "setting-popper"),
|
|
74
|
+
];
|
|
75
|
+
}
|
|
76
|
+
exports.default = SettingButton;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
|
+
const material_1 = require("@mui/material");
|
|
5
|
+
const utils_1 = require("../../utils");
|
|
6
|
+
function Layout({ children, disableBottomPadding, containerProps, }) {
|
|
7
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Stack, { className: "ai-chat-wrapper", mx: 2, flexGrow: 1, children: (0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: "ai-chat-container" }, containerProps, { sx: (0, utils_1.mergeSx)({
|
|
8
|
+
flexGrow: 1,
|
|
9
|
+
maxWidth: 720,
|
|
10
|
+
width: '100%',
|
|
11
|
+
mx: 'auto',
|
|
12
|
+
pb: disableBottomPadding ? 0 : 10,
|
|
13
|
+
}, containerProps === null || containerProps === void 0 ? void 0 : containerProps.sx), children: children })) }));
|
|
14
|
+
}
|
|
15
|
+
exports.default = Layout;
|