@blocklet/pages-kit 0.2.286 → 0.2.288

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/lib/cjs/builtin/async/ai-runtime/api/assistant.js +26 -0
  2. package/lib/cjs/builtin/async/ai-runtime/api/dataset.js +127 -0
  3. package/lib/cjs/builtin/async/ai-runtime/api/message.js +33 -0
  4. package/lib/cjs/builtin/async/ai-runtime/api/request.js +55 -0
  5. package/lib/cjs/builtin/async/ai-runtime/api/session.js +121 -0
  6. package/lib/cjs/builtin/async/ai-runtime/api/subscription.js +32 -0
  7. package/lib/cjs/builtin/async/ai-runtime/components/ActionButton.js +63 -0
  8. package/lib/cjs/builtin/async/ai-runtime/components/GlobalLoading.js +24 -0
  9. package/lib/cjs/builtin/async/ai-runtime/components/LoadingButton.js +40 -0
  10. package/lib/cjs/builtin/async/ai-runtime/components/LoadingListItemButton.js +49 -0
  11. package/lib/cjs/builtin/async/ai-runtime/components/MarkdownRenderer.js +156 -0
  12. package/lib/cjs/builtin/async/ai-runtime/components/MenuButton.js +43 -0
  13. package/lib/cjs/builtin/async/ai-runtime/components/PoweredBy.js +30 -0
  14. package/lib/cjs/builtin/async/ai-runtime/components/RuntimeProvider.js +22 -0
  15. package/lib/cjs/builtin/async/ai-runtime/components/ScrollView.js +109 -0
  16. package/lib/cjs/builtin/async/ai-runtime/components/SocialShare.js +102 -0
  17. package/lib/cjs/builtin/async/ai-runtime/components/ThemeProvider.js +193 -0
  18. package/lib/cjs/builtin/async/ai-runtime/components/collection/CollectionEditDialog.js +92 -0
  19. package/lib/cjs/builtin/async/ai-runtime/components/collection/CollectionListView.js +197 -0
  20. package/lib/cjs/builtin/async/ai-runtime/components/collection/CollectionView.js +122 -0
  21. package/lib/cjs/builtin/async/ai-runtime/components/collection/DocumentListView.js +152 -0
  22. package/lib/cjs/builtin/async/ai-runtime/components/collection/DocumentView.js +135 -0
  23. package/lib/cjs/builtin/async/ai-runtime/components/common/ChatBot.js +104 -0
  24. package/lib/cjs/builtin/async/ai-runtime/components/common/MessageMetadataRenderer.js +21 -0
  25. package/lib/cjs/builtin/async/ai-runtime/components/common/MessageSuggestedQuestions.js +35 -0
  26. package/lib/cjs/builtin/async/ai-runtime/components/common/index.js +12 -0
  27. package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterForm.js +89 -0
  28. package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterFormDialog.js +66 -0
  29. package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterFormFields.js +57 -0
  30. package/lib/cjs/builtin/async/ai-runtime/components/form/QuestionField.js +44 -0
  31. package/lib/cjs/builtin/async/ai-runtime/components/form/SettingButton.js +81 -0
  32. package/lib/cjs/builtin/async/ai-runtime/components/lottie/index.js +34 -0
  33. package/lib/cjs/builtin/async/ai-runtime/components/message/MessageActions.js +38 -0
  34. package/lib/cjs/builtin/async/ai-runtime/components/message/MessageErrorView.js +30 -0
  35. package/lib/cjs/builtin/async/ai-runtime/components/message/MessageItemView.js +129 -0
  36. package/lib/cjs/builtin/async/ai-runtime/components/message/MessageListView.js +47 -0
  37. package/lib/cjs/builtin/async/ai-runtime/components/message/ReferenceLinks.js +11 -0
  38. package/lib/cjs/builtin/async/ai-runtime/components/parameters/LanguageField.js +55 -0
  39. package/lib/cjs/builtin/async/ai-runtime/components/parameters/NumberField.js +21 -0
  40. package/lib/cjs/builtin/async/ai-runtime/components/parameters/SelectField.js +24 -0
  41. package/lib/cjs/builtin/async/ai-runtime/components/parameters/StringField.js +21 -0
  42. package/lib/cjs/builtin/async/ai-runtime/components/parameters/index.js +37 -0
  43. package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/InitialForm.js +111 -0
  44. package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHeader.js +60 -0
  45. package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +52 -0
  46. package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/index.js +28 -0
  47. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +120 -0
  48. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormHeader.js +22 -0
  49. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.js +72 -0
  50. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormSubmit.js +31 -0
  51. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/index.js +22 -0
  52. package/lib/cjs/builtin/async/ai-runtime/components/session/CheckSession.js +65 -0
  53. package/lib/cjs/builtin/async/ai-runtime/components/session/SessionListView.js +88 -0
  54. package/lib/cjs/builtin/async/ai-runtime/constants.js +5 -0
  55. package/lib/cjs/builtin/async/ai-runtime/error.js +10 -0
  56. package/lib/cjs/builtin/async/ai-runtime/hooks/header.js +32 -0
  57. package/lib/cjs/builtin/async/ai-runtime/hooks/navigate.js +38 -0
  58. package/lib/cjs/builtin/async/ai-runtime/hooks/subscribe.js +35 -0
  59. package/lib/cjs/builtin/async/ai-runtime/hooks/useAsync.js +32 -0
  60. package/lib/cjs/builtin/async/ai-runtime/index.js +81 -0
  61. package/lib/cjs/builtin/async/ai-runtime/locales/index.js +147 -0
  62. package/lib/cjs/builtin/async/ai-runtime/state/assistant.js +59 -0
  63. package/lib/cjs/builtin/async/ai-runtime/state/index.js +423 -0
  64. package/lib/cjs/builtin/async/ai-runtime/state/loading.js +39 -0
  65. package/lib/cjs/builtin/async/ai-runtime/state/session.js +217 -0
  66. package/lib/cjs/builtin/async/ai-runtime/state/subscription.js +52 -0
  67. package/lib/cjs/builtin/async/ai-runtime/utils.js +49 -0
  68. package/lib/cjs/builtin/async/react-scroll-to-bottom.js +1 -1
  69. package/lib/cjs/utils/builtin.js +1 -0
  70. package/lib/cjs/utils/inject-global-components.js +2 -0
  71. package/lib/esm/builtin/async/ai-runtime/api/assistant.js +22 -0
  72. package/lib/esm/builtin/async/ai-runtime/api/dataset.js +113 -0
  73. package/lib/esm/builtin/async/ai-runtime/api/message.js +28 -0
  74. package/lib/esm/builtin/async/ai-runtime/api/request.js +51 -0
  75. package/lib/esm/builtin/async/ai-runtime/api/session.js +112 -0
  76. package/lib/esm/builtin/async/ai-runtime/api/subscription.js +27 -0
  77. package/lib/esm/builtin/async/ai-runtime/components/ActionButton.js +56 -0
  78. package/lib/esm/builtin/async/ai-runtime/components/GlobalLoading.js +21 -0
  79. package/lib/esm/builtin/async/ai-runtime/components/LoadingButton.js +38 -0
  80. package/lib/esm/builtin/async/ai-runtime/components/LoadingListItemButton.js +46 -0
  81. package/lib/esm/builtin/async/ai-runtime/components/MarkdownRenderer.js +129 -0
  82. package/lib/esm/builtin/async/ai-runtime/components/MenuButton.js +40 -0
  83. package/lib/esm/builtin/async/ai-runtime/components/PoweredBy.js +27 -0
  84. package/lib/esm/builtin/async/ai-runtime/components/RuntimeProvider.js +16 -0
  85. package/lib/esm/builtin/async/ai-runtime/components/ScrollView.js +101 -0
  86. package/lib/esm/builtin/async/ai-runtime/components/SocialShare.js +93 -0
  87. package/lib/esm/builtin/async/ai-runtime/components/ThemeProvider.js +190 -0
  88. package/lib/esm/builtin/async/ai-runtime/components/collection/CollectionEditDialog.js +92 -0
  89. package/lib/esm/builtin/async/ai-runtime/components/collection/CollectionListView.js +197 -0
  90. package/lib/esm/builtin/async/ai-runtime/components/collection/CollectionView.js +122 -0
  91. package/lib/esm/builtin/async/ai-runtime/components/collection/DocumentListView.js +152 -0
  92. package/lib/esm/builtin/async/ai-runtime/components/collection/DocumentView.js +135 -0
  93. package/lib/esm/builtin/async/ai-runtime/components/common/ChatBot.js +98 -0
  94. package/lib/esm/builtin/async/ai-runtime/components/common/MessageMetadataRenderer.js +15 -0
  95. package/lib/esm/builtin/async/ai-runtime/components/common/MessageSuggestedQuestions.js +30 -0
  96. package/lib/esm/builtin/async/ai-runtime/components/common/index.js +3 -0
  97. package/lib/esm/builtin/async/ai-runtime/components/form/ParameterForm.js +60 -0
  98. package/lib/esm/builtin/async/ai-runtime/components/form/ParameterFormDialog.js +59 -0
  99. package/lib/esm/builtin/async/ai-runtime/components/form/ParameterFormFields.js +50 -0
  100. package/lib/esm/builtin/async/ai-runtime/components/form/QuestionField.js +38 -0
  101. package/lib/esm/builtin/async/ai-runtime/components/form/SettingButton.js +75 -0
  102. package/lib/esm/builtin/async/ai-runtime/components/lottie/index.js +8 -0
  103. package/lib/esm/builtin/async/ai-runtime/components/message/MessageActions.js +35 -0
  104. package/lib/esm/builtin/async/ai-runtime/components/message/MessageErrorView.js +24 -0
  105. package/lib/esm/builtin/async/ai-runtime/components/message/MessageItemView.js +100 -0
  106. package/lib/esm/builtin/async/ai-runtime/components/message/MessageListView.js +41 -0
  107. package/lib/esm/builtin/async/ai-runtime/components/message/ReferenceLinks.js +8 -0
  108. package/lib/esm/builtin/async/ai-runtime/components/parameters/LanguageField.js +53 -0
  109. package/lib/esm/builtin/async/ai-runtime/components/parameters/NumberField.js +19 -0
  110. package/lib/esm/builtin/async/ai-runtime/components/parameters/SelectField.js +22 -0
  111. package/lib/esm/builtin/async/ai-runtime/components/parameters/StringField.js +19 -0
  112. package/lib/esm/builtin/async/ai-runtime/components/parameters/index.js +31 -0
  113. package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/InitialForm.js +103 -0
  114. package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHeader.js +34 -0
  115. package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +46 -0
  116. package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/index.js +22 -0
  117. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +114 -0
  118. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormHeader.js +19 -0
  119. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.js +66 -0
  120. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormSubmit.js +25 -0
  121. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/index.js +16 -0
  122. package/lib/esm/builtin/async/ai-runtime/components/session/CheckSession.js +59 -0
  123. package/lib/esm/builtin/async/ai-runtime/components/session/SessionListView.js +88 -0
  124. package/lib/esm/builtin/async/ai-runtime/constants.js +2 -0
  125. package/lib/esm/builtin/async/ai-runtime/error.js +6 -0
  126. package/lib/esm/builtin/async/ai-runtime/hooks/header.js +25 -0
  127. package/lib/esm/builtin/async/ai-runtime/hooks/navigate.js +32 -0
  128. package/lib/esm/builtin/async/ai-runtime/hooks/subscribe.js +31 -0
  129. package/lib/esm/builtin/async/ai-runtime/hooks/useAsync.js +29 -0
  130. package/lib/esm/builtin/async/ai-runtime/index.js +72 -0
  131. package/lib/esm/builtin/async/ai-runtime/locales/index.js +144 -0
  132. package/lib/esm/builtin/async/ai-runtime/state/assistant.js +54 -0
  133. package/lib/esm/builtin/async/ai-runtime/state/index.js +423 -0
  134. package/lib/esm/builtin/async/ai-runtime/state/loading.js +36 -0
  135. package/lib/esm/builtin/async/ai-runtime/state/session.js +209 -0
  136. package/lib/esm/builtin/async/ai-runtime/state/subscription.js +47 -0
  137. package/lib/esm/builtin/async/ai-runtime/utils.js +42 -0
  138. package/lib/esm/builtin/async/react-scroll-to-bottom.js +1 -1
  139. package/lib/esm/utils/builtin.js +1 -0
  140. package/lib/esm/utils/inject-global-components.js +2 -0
  141. package/lib/types/builtin/async/ai-runtime/api/assistant.d.ts +18 -0
  142. package/lib/types/builtin/async/ai-runtime/api/dataset.d.ts +39 -0
  143. package/lib/types/builtin/async/ai-runtime/api/message.d.ts +39 -0
  144. package/lib/types/builtin/async/ai-runtime/api/request.d.ts +5 -0
  145. package/lib/types/builtin/async/ai-runtime/api/session.d.ts +54 -0
  146. package/lib/types/builtin/async/ai-runtime/api/subscription.d.ts +15 -0
  147. package/lib/types/builtin/async/ai-runtime/components/ActionButton.d.ts +11 -0
  148. package/lib/types/builtin/async/ai-runtime/components/GlobalLoading.d.ts +2 -0
  149. package/lib/types/builtin/async/ai-runtime/components/LoadingButton.d.ts +3 -0
  150. package/lib/types/builtin/async/ai-runtime/components/LoadingListItemButton.d.ts +5 -0
  151. package/lib/types/builtin/async/ai-runtime/components/MarkdownRenderer.d.ts +2 -0
  152. package/lib/types/builtin/async/ai-runtime/components/MenuButton.d.ts +9 -0
  153. package/lib/types/builtin/async/ai-runtime/components/PoweredBy.d.ts +4 -0
  154. package/lib/types/builtin/async/ai-runtime/components/RuntimeProvider.d.ts +4 -0
  155. package/lib/types/builtin/async/ai-runtime/components/ScrollView.d.ts +61 -0
  156. package/lib/types/builtin/async/ai-runtime/components/SocialShare.d.ts +17 -0
  157. package/lib/types/builtin/async/ai-runtime/components/ThemeProvider.d.ts +6 -0
  158. package/lib/types/builtin/async/ai-runtime/components/collection/CollectionEditDialog.d.ts +0 -0
  159. package/lib/types/builtin/async/ai-runtime/components/collection/CollectionListView.d.ts +0 -0
  160. package/lib/types/builtin/async/ai-runtime/components/collection/CollectionView.d.ts +0 -0
  161. package/lib/types/builtin/async/ai-runtime/components/collection/DocumentListView.d.ts +0 -0
  162. package/lib/types/builtin/async/ai-runtime/components/collection/DocumentView.d.ts +0 -0
  163. package/lib/types/builtin/async/ai-runtime/components/common/ChatBot.d.ts +13 -0
  164. package/lib/types/builtin/async/ai-runtime/components/common/MessageMetadataRenderer.d.ts +4 -0
  165. package/lib/types/builtin/async/ai-runtime/components/common/MessageSuggestedQuestions.d.ts +7 -0
  166. package/lib/types/builtin/async/ai-runtime/components/common/index.d.ts +3 -0
  167. package/lib/types/builtin/async/ai-runtime/components/form/ParameterForm.d.ts +12 -0
  168. package/lib/types/builtin/async/ai-runtime/components/form/ParameterFormDialog.d.ts +28 -0
  169. package/lib/types/builtin/async/ai-runtime/components/form/ParameterFormFields.d.ts +11 -0
  170. package/lib/types/builtin/async/ai-runtime/components/form/QuestionField.d.ts +13 -0
  171. package/lib/types/builtin/async/ai-runtime/components/form/SettingButton.d.ts +6 -0
  172. package/lib/types/builtin/async/ai-runtime/components/lottie/index.d.ts +4 -0
  173. package/lib/types/builtin/async/ai-runtime/components/message/MessageActions.d.ts +4 -0
  174. package/lib/types/builtin/async/ai-runtime/components/message/MessageErrorView.d.ts +6 -0
  175. package/lib/types/builtin/async/ai-runtime/components/message/MessageItemView.d.ts +8 -0
  176. package/lib/types/builtin/async/ai-runtime/components/message/MessageListView.d.ts +5 -0
  177. package/lib/types/builtin/async/ai-runtime/components/message/ReferenceLinks.d.ts +4 -0
  178. package/lib/types/builtin/async/ai-runtime/components/parameters/LanguageField.d.ts +9 -0
  179. package/lib/types/builtin/async/ai-runtime/components/parameters/NumberField.d.ts +9 -0
  180. package/lib/types/builtin/async/ai-runtime/components/parameters/SelectField.d.ts +9 -0
  181. package/lib/types/builtin/async/ai-runtime/components/parameters/StringField.d.ts +9 -0
  182. package/lib/types/builtin/async/ai-runtime/components/parameters/index.d.ts +7 -0
  183. package/lib/types/builtin/async/ai-runtime/components/runtime-chat/InitialForm.d.ts +10 -0
  184. package/lib/types/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHeader.d.ts +5 -0
  185. package/lib/types/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.d.ts +6 -0
  186. package/lib/types/builtin/async/ai-runtime/components/runtime-chat/index.d.ts +5 -0
  187. package/lib/types/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.d.ts +5 -0
  188. package/lib/types/builtin/async/ai-runtime/components/runtime-form/RuntimeFormHeader.d.ts +5 -0
  189. package/lib/types/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.d.ts +5 -0
  190. package/lib/types/builtin/async/ai-runtime/components/runtime-form/RuntimeFormSubmit.d.ts +5 -0
  191. package/lib/types/builtin/async/ai-runtime/components/runtime-form/index.d.ts +4 -0
  192. package/lib/types/builtin/async/ai-runtime/components/session/CheckSession.d.ts +8 -0
  193. package/lib/types/builtin/async/ai-runtime/components/session/SessionListView.d.ts +0 -0
  194. package/lib/types/builtin/async/ai-runtime/constants.d.ts +2 -0
  195. package/lib/types/builtin/async/ai-runtime/error.d.ts +4 -0
  196. package/lib/types/builtin/async/ai-runtime/hooks/header.d.ts +4 -0
  197. package/lib/types/builtin/async/ai-runtime/hooks/navigate.d.ts +25 -0
  198. package/lib/types/builtin/async/ai-runtime/hooks/subscribe.d.ts +6 -0
  199. package/lib/types/builtin/async/ai-runtime/hooks/useAsync.d.ts +1 -0
  200. package/lib/types/builtin/async/ai-runtime/index.d.ts +17 -0
  201. package/lib/types/builtin/async/ai-runtime/locales/index.d.ts +126 -0
  202. package/lib/types/builtin/async/ai-runtime/state/assistant.d.ts +17 -0
  203. package/lib/types/builtin/async/ai-runtime/state/index.d.ts +0 -0
  204. package/lib/types/builtin/async/ai-runtime/state/loading.d.ts +10 -0
  205. package/lib/types/builtin/async/ai-runtime/state/session.d.ts +40 -0
  206. package/lib/types/builtin/async/ai-runtime/state/subscription.d.ts +15 -0
  207. package/lib/types/builtin/async/ai-runtime/utils.d.ts +20 -0
  208. package/lib/types/builtin/async/react-scroll-to-bottom.d.ts +3 -2
  209. package/lib/types/builtin/page/header.d.ts +1 -6
  210. package/lib/types/builtin/session.d.ts +11 -1
  211. package/lib/types/components/CustomComponentRenderer/state.d.ts +1 -116
  212. package/lib/types/utils/builtin.d.ts +1 -0
  213. package/package.json +14 -9
  214. 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,104 @@
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: '80vh' };
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: 500 }, maxWidth: 600 }, 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)(material_1.Box, { sx: { position: 'fixed', bottom: bottom || 24, right: right || 24 }, children: [(0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
78
+ display: 'inline-flex',
79
+ flexDirection: 'column',
80
+ justifyContent: 'center',
81
+ alignItems: 'center',
82
+ boxShadow: '0px 2px 4px 0px rgba(3, 7, 18, 0.04)',
83
+ cursor: 'pointer',
84
+ zIndex: 1000,
85
+ transition: 'transform 0.3s',
86
+ ':hover': {
87
+ transform: 'scale(1.05)',
88
+ },
89
+ }, onClick: () => setOpenPopper(!openPopper), 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: {
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
+ '.ai-runtime-form-container': {
99
+ borderBottomLeftRadius: 8,
100
+ borderBottomRightRadius: 8,
101
+ },
102
+ }, children: (0, jsx_runtime_1.jsx)(react_2.Suspense, { fallback: (0, jsx_runtime_1.jsx)(material_1.Stack, { flexGrow: 1, alignItems: "center", justifyContent: "center", children: (0, jsx_runtime_1.jsx)(material_1.CircularProgress, { size: 24 }) }), children: children }) }) }))] }));
103
+ }
104
+ 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.jsx)(material_1.Stack, { gap: 1, children: (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,89 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __importDefault = (this && this.__importDefault) || function (mod) {
35
+ return (mod && mod.__esModule) ? mod : { "default": mod };
36
+ };
37
+ Object.defineProperty(exports, "__esModule", { value: true });
38
+ const jsx_runtime_1 = require("react/jsx-runtime");
39
+ const react_1 = require("@iconify/react");
40
+ const material_1 = require("@mui/material");
41
+ const isEmpty_1 = __importDefault(require("lodash/isEmpty"));
42
+ const omit_1 = __importDefault(require("lodash/omit"));
43
+ const react_2 = require("react");
44
+ const react_hook_form_1 = require("react-hook-form");
45
+ const locale_1 = require("../../../../locale");
46
+ const LoadingButton_1 = __importDefault(require("../LoadingButton"));
47
+ const ParameterFormFields_1 = __importStar(require("./ParameterFormFields"));
48
+ const QuestionField_1 = __importDefault(require("./QuestionField"));
49
+ const SettingButton_1 = __importDefault(require("./SettingButton"));
50
+ function ParameterForm(_a) {
51
+ var _b, _c, _d;
52
+ 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;
53
+ const { t } = (0, locale_1.useLocaleContext)();
54
+ const parameters = (0, react_2.useMemo)(() => {
55
+ var _a;
56
+ return (_a = assistant.parameters) === null || _a === void 0 ? void 0 : _a.filter((i) => i.key && !['question', 'datasetId'].includes(i.key) && ParameterFormFields_1.SUPPORTED_PARAMETER_TYPES.includes(i.type || 'string'));
57
+ }, [assistant.parameters]);
58
+ const isChat = (_d = assistant.parameters) === null || _d === void 0 ? void 0 : _d.some((i) => i.key === 'question');
59
+ const defaultForm = (0, react_2.useMemo)(() => {
60
+ var _a;
61
+ const values = (0, omit_1.default)(defaultValues, 'question');
62
+ if (!(0, isEmpty_1.default)(values))
63
+ return values;
64
+ return Object.fromEntries((_a = parameters === null || parameters === void 0 ? void 0 : parameters.map((parameter) => [parameter.key, parameter.defaultValue])) !== null && _a !== void 0 ? _a : []);
65
+ }, [defaultValues]);
66
+ const form = (0, react_hook_form_1.useForm)({ defaultValues: defaultForm, shouldFocusError: true });
67
+ (0, react_2.useEffect)(() => {
68
+ form.reset(defaultForm);
69
+ }, [defaultForm]);
70
+ const handleSubmit = (parameters) => __awaiter(this, void 0, void 0, function* () {
71
+ if (onSubmit) {
72
+ form.setFocus('question');
73
+ yield onSubmit(parameters);
74
+ form.reset((0, omit_1.default)(parameters, 'question'));
75
+ }
76
+ });
77
+ const [expand, setExpand] = (0, react_2.useState)(false);
78
+ return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { className: "ai-chat-form", component: "form", onSubmit: form.handleSubmit(handleSubmit, (e) => {
79
+ if (Object.keys(e).some((i) => i !== 'question')) {
80
+ setExpand(true);
81
+ }
82
+ }), children: [!!(parameters === null || parameters === void 0 ? void 0 : parameters.length) && ((0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsx)(material_1.Stack, { direction: "row", justifyContent: "center", children: (0, jsx_runtime_1.jsx)(material_1.Button, { sx: { minWidth: 0, px: 4, py: 0, opacity: 0.7, color: 'text.secondary' }, onClick: () => setExpand(!expand), children: (0, jsx_runtime_1.jsx)(material_1.Box, { component: react_1.Icon, icon: "tabler:chevron-compact-up", sx: {
83
+ fontSize: 24,
84
+ transform: `rotateX(${expand ? '180deg' : '0deg'})`,
85
+ transition: 'transform .3s ease-in-out',
86
+ } }) }) }), (0, jsx_runtime_1.jsx)(material_1.Collapse, { in: expand, orientation: "vertical", sx: { maxHeight: '40vh', overflowY: 'auto' }, children: (0, jsx_runtime_1.jsx)(ParameterFormFields_1.default, { autoFocus: !sessionId, disabled: disabled, readOnly: readOnly, parameters: parameters, form: form, sx: { pb: 2, px: 2 } }) })] })), (0, jsx_runtime_1.jsx)(material_1.Box, { px: 2, children: !hideSubmit &&
87
+ (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: !!sessionId })) : ((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, { form: form, 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') }) }) })] }))) })] }));
88
+ }
89
+ 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,57 @@
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
+ var __importDefault = (this && this.__importDefault) || function (mod) {
14
+ return (mod && mod.__esModule) ? mod : { "default": mod };
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.SUPPORTED_PARAMETER_TYPES = void 0;
18
+ const jsx_runtime_1 = require("react/jsx-runtime");
19
+ const material_1 = require("@mui/material");
20
+ const react_hook_form_1 = require("react-hook-form");
21
+ const parameters_1 = __importDefault(require("../parameters"));
22
+ exports.SUPPORTED_PARAMETER_TYPES = ['string', 'number', 'select', 'language'];
23
+ function ParameterFormFields(_a) {
24
+ var { autoFocus, disabled, readOnly, parameters, form } = _a, props = __rest(_a, ["autoFocus", "disabled", "readOnly", "parameters", "form"]);
25
+ let isFirstParameterRendered = false;
26
+ return ((0, jsx_runtime_1.jsx)(material_1.Stack, Object.assign({ gap: 1 }, props, { children: parameters === null || parameters === void 0 ? void 0 : parameters.map((parameter) => {
27
+ const { key, required } = parameter !== null && parameter !== void 0 ? parameter : {};
28
+ if (!key || !exports.SUPPORTED_PARAMETER_TYPES.includes(parameter.type || 'string'))
29
+ return null;
30
+ const isFirstParameter = !isFirstParameterRendered;
31
+ isFirstParameterRendered = true;
32
+ 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: {
33
+ required,
34
+ min: parameter.type === 'number' && typeof parameter.min === 'number'
35
+ ? { value: parameter.min, message: '' }
36
+ : undefined,
37
+ max: parameter.type === 'number' && typeof parameter.max === 'number'
38
+ ? { value: parameter.max, message: '' }
39
+ : undefined,
40
+ minLength: parameter.type === 'string' && typeof parameter.minLength === 'number'
41
+ ? { value: parameter.minLength, message: '' }
42
+ : undefined,
43
+ maxLength: parameter.type === 'string' && typeof parameter.maxLength === 'number'
44
+ ? { value: parameter.maxLength, message: '' }
45
+ : undefined,
46
+ }, render: ({ field, fieldState }) => {
47
+ var _a;
48
+ return ((0, jsx_runtime_1.jsxs)(material_1.Box, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { component: "div", sx: {
49
+ lineHeight: '24px',
50
+ mb: 0.5,
51
+ fontWeight: 500,
52
+ color: 'rgba(18, 22, 24, 1)',
53
+ }, children: (parameter === null || parameter === void 0 ? void 0 : parameter.label) || parameter.key }), (0, jsx_runtime_1.jsx)(parameters_1.default, { inputRef: field.ref, autoFocus: 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' } })] }));
54
+ } }) }, parameter.id));
55
+ }) })));
56
+ }
57
+ 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", 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, { form: form, 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;