@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.
Files changed (209) 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 +47 -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 +60 -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 +51 -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 +16 -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 +105 -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 +48 -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 +43 -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 +76 -0
  32. package/lib/cjs/builtin/async/ai-runtime/components/layout/index.js +15 -0
  33. package/lib/cjs/builtin/async/ai-runtime/components/lottie/index.js +34 -0
  34. package/lib/cjs/builtin/async/ai-runtime/components/message/MessageActions.js +38 -0
  35. package/lib/cjs/builtin/async/ai-runtime/components/message/MessageErrorView.js +30 -0
  36. package/lib/cjs/builtin/async/ai-runtime/components/message/MessageItemView.js +134 -0
  37. package/lib/cjs/builtin/async/ai-runtime/components/message/MessageListView.js +48 -0
  38. package/lib/cjs/builtin/async/ai-runtime/components/message/ReferenceLinks.js +11 -0
  39. package/lib/cjs/builtin/async/ai-runtime/components/parameters/LanguageField.js +55 -0
  40. package/lib/cjs/builtin/async/ai-runtime/components/parameters/NumberField.js +21 -0
  41. package/lib/cjs/builtin/async/ai-runtime/components/parameters/SelectField.js +24 -0
  42. package/lib/cjs/builtin/async/ai-runtime/components/parameters/StringField.js +21 -0
  43. package/lib/cjs/builtin/async/ai-runtime/components/parameters/index.js +37 -0
  44. package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/InitialForm.js +94 -0
  45. package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHeader.js +48 -0
  46. package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHome.js +21 -0
  47. package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +67 -0
  48. package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/index.js +15 -0
  49. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +103 -0
  50. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormHeader.js +22 -0
  51. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.js +72 -0
  52. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormSubmit.js +31 -0
  53. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/index.js +22 -0
  54. package/lib/cjs/builtin/async/ai-runtime/components/session/CheckSession.js +62 -0
  55. package/lib/cjs/builtin/async/ai-runtime/components/session/SessionListView.js +88 -0
  56. package/lib/cjs/builtin/async/ai-runtime/constants.js +5 -0
  57. package/lib/cjs/builtin/async/ai-runtime/hooks/header.js +32 -0
  58. package/lib/cjs/builtin/async/ai-runtime/hooks/navigate.js +37 -0
  59. package/lib/cjs/builtin/async/ai-runtime/hooks/subscribe.js +35 -0
  60. package/lib/cjs/builtin/async/ai-runtime/index.js +75 -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/session.js +217 -0
  65. package/lib/cjs/builtin/async/ai-runtime/state/subscription.js +52 -0
  66. package/lib/cjs/builtin/async/ai-runtime/utils.js +49 -0
  67. package/lib/cjs/builtin/async/react-scroll-to-bottom.js +1 -1
  68. package/lib/cjs/utils/builtin.js +1 -0
  69. package/lib/cjs/utils/inject-global-components.js +2 -0
  70. package/lib/esm/builtin/async/ai-runtime/api/assistant.js +22 -0
  71. package/lib/esm/builtin/async/ai-runtime/api/dataset.js +113 -0
  72. package/lib/esm/builtin/async/ai-runtime/api/message.js +28 -0
  73. package/lib/esm/builtin/async/ai-runtime/api/request.js +43 -0
  74. package/lib/esm/builtin/async/ai-runtime/api/session.js +112 -0
  75. package/lib/esm/builtin/async/ai-runtime/api/subscription.js +27 -0
  76. package/lib/esm/builtin/async/ai-runtime/components/ActionButton.js +56 -0
  77. package/lib/esm/builtin/async/ai-runtime/components/GlobalLoading.js +56 -0
  78. package/lib/esm/builtin/async/ai-runtime/components/LoadingButton.js +38 -0
  79. package/lib/esm/builtin/async/ai-runtime/components/LoadingListItemButton.js +48 -0
  80. package/lib/esm/builtin/async/ai-runtime/components/MarkdownRenderer.js +129 -0
  81. package/lib/esm/builtin/async/ai-runtime/components/MenuButton.js +40 -0
  82. package/lib/esm/builtin/async/ai-runtime/components/PoweredBy.js +27 -0
  83. package/lib/esm/builtin/async/ai-runtime/components/RuntimeProvider.js +10 -0
  84. package/lib/esm/builtin/async/ai-runtime/components/ScrollView.js +101 -0
  85. package/lib/esm/builtin/async/ai-runtime/components/SocialShare.js +93 -0
  86. package/lib/esm/builtin/async/ai-runtime/components/ThemeProvider.js +190 -0
  87. package/lib/esm/builtin/async/ai-runtime/components/collection/CollectionEditDialog.js +92 -0
  88. package/lib/esm/builtin/async/ai-runtime/components/collection/CollectionListView.js +197 -0
  89. package/lib/esm/builtin/async/ai-runtime/components/collection/CollectionView.js +122 -0
  90. package/lib/esm/builtin/async/ai-runtime/components/collection/DocumentListView.js +152 -0
  91. package/lib/esm/builtin/async/ai-runtime/components/collection/DocumentView.js +135 -0
  92. package/lib/esm/builtin/async/ai-runtime/components/common/ChatBot.js +99 -0
  93. package/lib/esm/builtin/async/ai-runtime/components/common/MessageMetadataRenderer.js +15 -0
  94. package/lib/esm/builtin/async/ai-runtime/components/common/MessageSuggestedQuestions.js +30 -0
  95. package/lib/esm/builtin/async/ai-runtime/components/common/index.js +3 -0
  96. package/lib/esm/builtin/async/ai-runtime/components/form/ParameterForm.js +42 -0
  97. package/lib/esm/builtin/async/ai-runtime/components/form/ParameterFormDialog.js +59 -0
  98. package/lib/esm/builtin/async/ai-runtime/components/form/ParameterFormFields.js +37 -0
  99. package/lib/esm/builtin/async/ai-runtime/components/form/QuestionField.js +38 -0
  100. package/lib/esm/builtin/async/ai-runtime/components/form/SettingButton.js +73 -0
  101. package/lib/esm/builtin/async/ai-runtime/components/layout/index.js +12 -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 +105 -0
  106. package/lib/esm/builtin/async/ai-runtime/components/message/MessageListView.js +42 -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 +88 -0
  114. package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHeader.js +22 -0
  115. package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHome.js +15 -0
  116. package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +61 -0
  117. package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/index.js +9 -0
  118. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +97 -0
  119. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormHeader.js +19 -0
  120. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.js +66 -0
  121. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormSubmit.js +25 -0
  122. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/index.js +16 -0
  123. package/lib/esm/builtin/async/ai-runtime/components/session/CheckSession.js +59 -0
  124. package/lib/esm/builtin/async/ai-runtime/components/session/SessionListView.js +88 -0
  125. package/lib/esm/builtin/async/ai-runtime/constants.js +2 -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 +31 -0
  128. package/lib/esm/builtin/async/ai-runtime/hooks/subscribe.js +31 -0
  129. package/lib/esm/builtin/async/ai-runtime/index.js +66 -0
  130. package/lib/esm/builtin/async/ai-runtime/locales/index.js +144 -0
  131. package/lib/esm/builtin/async/ai-runtime/state/assistant.js +54 -0
  132. package/lib/esm/builtin/async/ai-runtime/state/index.js +423 -0
  133. package/lib/esm/builtin/async/ai-runtime/state/session.js +209 -0
  134. package/lib/esm/builtin/async/ai-runtime/state/subscription.js +47 -0
  135. package/lib/esm/builtin/async/ai-runtime/utils.js +42 -0
  136. package/lib/esm/builtin/async/react-scroll-to-bottom.js +1 -1
  137. package/lib/esm/utils/builtin.js +1 -0
  138. package/lib/esm/utils/inject-global-components.js +2 -0
  139. package/lib/types/builtin/async/ai-runtime/api/assistant.d.ts +18 -0
  140. package/lib/types/builtin/async/ai-runtime/api/dataset.d.ts +39 -0
  141. package/lib/types/builtin/async/ai-runtime/api/message.d.ts +39 -0
  142. package/lib/types/builtin/async/ai-runtime/api/request.d.ts +5 -0
  143. package/lib/types/builtin/async/ai-runtime/api/session.d.ts +54 -0
  144. package/lib/types/builtin/async/ai-runtime/api/subscription.d.ts +15 -0
  145. package/lib/types/builtin/async/ai-runtime/components/ActionButton.d.ts +11 -0
  146. package/lib/types/builtin/async/ai-runtime/components/GlobalLoading.d.ts +33 -0
  147. package/lib/types/builtin/async/ai-runtime/components/LoadingButton.d.ts +3 -0
  148. package/lib/types/builtin/async/ai-runtime/components/LoadingListItemButton.d.ts +2 -0
  149. package/lib/types/builtin/async/ai-runtime/components/MarkdownRenderer.d.ts +2 -0
  150. package/lib/types/builtin/async/ai-runtime/components/MenuButton.d.ts +9 -0
  151. package/lib/types/builtin/async/ai-runtime/components/PoweredBy.d.ts +4 -0
  152. package/lib/types/builtin/async/ai-runtime/components/RuntimeProvider.d.ts +4 -0
  153. package/lib/types/builtin/async/ai-runtime/components/ScrollView.d.ts +61 -0
  154. package/lib/types/builtin/async/ai-runtime/components/SocialShare.d.ts +17 -0
  155. package/lib/types/builtin/async/ai-runtime/components/ThemeProvider.d.ts +6 -0
  156. package/lib/types/builtin/async/ai-runtime/components/collection/CollectionEditDialog.d.ts +0 -0
  157. package/lib/types/builtin/async/ai-runtime/components/collection/CollectionListView.d.ts +0 -0
  158. package/lib/types/builtin/async/ai-runtime/components/collection/CollectionView.d.ts +0 -0
  159. package/lib/types/builtin/async/ai-runtime/components/collection/DocumentListView.d.ts +0 -0
  160. package/lib/types/builtin/async/ai-runtime/components/collection/DocumentView.d.ts +0 -0
  161. package/lib/types/builtin/async/ai-runtime/components/common/ChatBot.d.ts +13 -0
  162. package/lib/types/builtin/async/ai-runtime/components/common/MessageMetadataRenderer.d.ts +4 -0
  163. package/lib/types/builtin/async/ai-runtime/components/common/MessageSuggestedQuestions.d.ts +7 -0
  164. package/lib/types/builtin/async/ai-runtime/components/common/index.d.ts +3 -0
  165. package/lib/types/builtin/async/ai-runtime/components/form/ParameterForm.d.ts +12 -0
  166. package/lib/types/builtin/async/ai-runtime/components/form/ParameterFormDialog.d.ts +28 -0
  167. package/lib/types/builtin/async/ai-runtime/components/form/ParameterFormFields.d.ts +8 -0
  168. package/lib/types/builtin/async/ai-runtime/components/form/QuestionField.d.ts +13 -0
  169. package/lib/types/builtin/async/ai-runtime/components/form/SettingButton.d.ts +4 -0
  170. package/lib/types/builtin/async/ai-runtime/components/layout/index.d.ts +7 -0
  171. package/lib/types/builtin/async/ai-runtime/components/lottie/index.d.ts +4 -0
  172. package/lib/types/builtin/async/ai-runtime/components/message/MessageActions.d.ts +4 -0
  173. package/lib/types/builtin/async/ai-runtime/components/message/MessageErrorView.d.ts +6 -0
  174. package/lib/types/builtin/async/ai-runtime/components/message/MessageItemView.d.ts +10 -0
  175. package/lib/types/builtin/async/ai-runtime/components/message/MessageListView.d.ts +5 -0
  176. package/lib/types/builtin/async/ai-runtime/components/message/ReferenceLinks.d.ts +4 -0
  177. package/lib/types/builtin/async/ai-runtime/components/parameters/LanguageField.d.ts +9 -0
  178. package/lib/types/builtin/async/ai-runtime/components/parameters/NumberField.d.ts +9 -0
  179. package/lib/types/builtin/async/ai-runtime/components/parameters/SelectField.d.ts +9 -0
  180. package/lib/types/builtin/async/ai-runtime/components/parameters/StringField.d.ts +9 -0
  181. package/lib/types/builtin/async/ai-runtime/components/parameters/index.d.ts +7 -0
  182. package/lib/types/builtin/async/ai-runtime/components/runtime-chat/InitialForm.d.ts +4 -0
  183. package/lib/types/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHeader.d.ts +4 -0
  184. package/lib/types/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHome.d.ts +4 -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 +4 -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 +9 -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/hooks/header.d.ts +4 -0
  196. package/lib/types/builtin/async/ai-runtime/hooks/navigate.d.ts +25 -0
  197. package/lib/types/builtin/async/ai-runtime/hooks/subscribe.d.ts +6 -0
  198. package/lib/types/builtin/async/ai-runtime/index.d.ts +17 -0
  199. package/lib/types/builtin/async/ai-runtime/locales/index.d.ts +126 -0
  200. package/lib/types/builtin/async/ai-runtime/state/assistant.d.ts +17 -0
  201. package/lib/types/builtin/async/ai-runtime/state/index.d.ts +0 -0
  202. package/lib/types/builtin/async/ai-runtime/state/session.d.ts +40 -0
  203. package/lib/types/builtin/async/ai-runtime/state/subscription.d.ts +15 -0
  204. package/lib/types/builtin/async/ai-runtime/utils.d.ts +20 -0
  205. package/lib/types/builtin/async/react-scroll-to-bottom.d.ts +3 -2
  206. package/lib/types/builtin/session.d.ts +11 -1
  207. package/lib/types/utils/builtin.d.ts +1 -0
  208. package/package.json +13 -8
  209. package/tsconfig.json +5 -1
@@ -0,0 +1,105 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import ImagePreview from '@blocklet/ai-kit/components/image-preview';
3
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
4
+ import { Box, Skeleton, Stack, Typography } from '@mui/material';
5
+ import dayjs from 'dayjs';
6
+ import React, { useMemo } from 'react';
7
+ import { Avatar, RelativeTime } from '../../../../arcblock/ux';
8
+ import { useLocaleContext } from '../../../../locale';
9
+ import { useSessionContext } from '../../../../session';
10
+ import { MessageMetadataRenderer } from '../common';
11
+ import MarkdownRenderer from '../MarkdownRenderer';
12
+ import MessageActions from './MessageActions';
13
+ import MessageErrorView from './MessageErrorView';
14
+ // if today, show time only, else show date and time
15
+ const formatTodayTime = (time) => {
16
+ const today = dayjs().format('YYYY-MM-DD');
17
+ const date = dayjs(time).format('YYYY-MM-DD');
18
+ return today === date ? dayjs(time).format('HH:mm') : dayjs(time).format('YYYY-MM-DD HH:mm');
19
+ };
20
+ export default function MessageItemView({ assistantId, assistant, message, previousMessageTime, messageTimeType = 'user', hideAvatar, }) {
21
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1;
22
+ const { session: authSession } = useSessionContext();
23
+ const { locale } = useLocaleContext();
24
+ const hasResult = !!(((_a = message.result) === null || _a === void 0 ? void 0 : _a.content) ||
25
+ ((_c = (_b = message.result) === null || _b === void 0 ? void 0 : _b.images) === null || _c === void 0 ? void 0 : _c.length) ||
26
+ ((_e = (_d = message.result) === null || _d === void 0 ? void 0 : _d.messages) === null || _e === void 0 ? void 0 : _e.length) ||
27
+ ((_g = (_f = message.result) === null || _f === void 0 ? void 0 : _f.objects) === null || _g === void 0 ? void 0 : _g.length));
28
+ const showPreviousTime = useMemo(() => {
29
+ if (messageTimeType !== 'previous')
30
+ return false;
31
+ if (!previousMessageTime)
32
+ return true;
33
+ const p = dayjs(previousMessageTime);
34
+ const c = dayjs(message.createdAt);
35
+ return c.valueOf() - p.valueOf() >= 300e3; // 和上一条消息时间间隔不超过 5 分钟,则不显示时间
36
+ }, [previousMessageTime, messageTimeType]);
37
+ const extraUserInfo = [
38
+ messageTimeType === 'user' && (message === null || message === void 0 ? void 0 : message.createdAt) && (_jsx(Typography, { sx: {
39
+ fontSize: 12,
40
+ lineHeight: '24px',
41
+ color: 'text.secondary',
42
+ }, children: formatTodayTime(message.createdAt) }, "user-time")),
43
+ ].filter(Boolean);
44
+ const commonMessageSx = {
45
+ position: 'relative',
46
+ borderRadius: 1,
47
+ py: 1,
48
+ px: 2,
49
+ mt: 0.5,
50
+ // without logo width
51
+ maxWidth: 'calc(100% - 40px)',
52
+ '.message-actions': {
53
+ position: 'absolute',
54
+ top: 0,
55
+ right: -40,
56
+ background: 'white',
57
+ border: 1,
58
+ borderRadius: 1,
59
+ borderColor: 'grey.300',
60
+ opacity: 0,
61
+ transition: 'opacity 0.2s',
62
+ },
63
+ };
64
+ const isMessageLoading = (message.loading || !message.result) && !message.error;
65
+ const showUserMessage = ((_h = assistant.release) === null || _h === void 0 ? void 0 : _h.template) !== 'form' && !!((_j = message.parameters) === null || _j === void 0 ? void 0 : _j.question);
66
+ return (_jsxs(Stack, { className: "ai-chat-message-item", gap: 2.5, overflow: "hidden", sx: {
67
+ '.message-question': Object.assign(Object.assign({}, commonMessageSx), { borderTopRightRadius: '2px', backgroundColor: 'rgba(239, 246, 255, 1)' }),
68
+ '.message-response': Object.assign(Object.assign({}, commonMessageSx), { borderTopLeftRadius: '2px', backgroundColor: 'rgba(229, 231, 235, 1)' }),
69
+ '.ai-chat-message-ai:hover': {
70
+ '.message-actions': {
71
+ opacity: 1,
72
+ },
73
+ },
74
+ }, children: [showPreviousTime && message.createdAt && (_jsx(Box, { className: "ai-chat-message-time", sx: { textAlign: 'center', fontSize: 13, color: 'text.secondary', mb: -1.5 }, children: _jsx(RelativeTime, { locale: locale, value: message.createdAt, relativeRange: 600e3 }) })), showUserMessage && (_jsxs(Stack, { className: "ai-chat-message-user", direction: "row", gap: 1.5, sx: {
75
+ display: 'flex',
76
+ flexDirection: 'row-reverse',
77
+ textAlign: 'right',
78
+ justifyContent: 'flex-end',
79
+ }, children: [_jsx(Box, { children: _jsx(Avatar, { size: 40, src: (_k = authSession.user) === null || _k === void 0 ? void 0 : _k.avatar, did: (_l = authSession.user) === null || _l === void 0 ? void 0 : _l.did, variant: "circle", shape: "circle" }) }), _jsxs(Stack, { flex: 1, overflow: "hidden", sx: {
80
+ display: 'flex',
81
+ flexDirection: 'column',
82
+ alignItems: 'flex-end',
83
+ }, children: [_jsxs(MessageUserName, { children: [(_m = authSession.user) === null || _m === void 0 ? void 0 : _m.fullName, extraUserInfo] }), _jsx(Box, { className: "message-question", sx: { whiteSpace: 'pre-wrap', wordBreak: 'break-word', textAlign: 'left' }, children: (_o = message.parameters) === null || _o === void 0 ? void 0 : _o.question })] })] })), _jsxs(Stack, { className: "ai-chat-message-ai", direction: "row", gap: 1.5, children: [!hideAvatar && (_jsx(Box, { children: _jsx(Avatar, { size: 40, did: (_p = globalThis.blocklet) === null || _p === void 0 ? void 0 : _p.appId, variant: "circle", shape: "circle", src: (_q = assistant.release) === null || _q === void 0 ? void 0 : _q.logo }) })), _jsxs(Box, { flex: 1, overflow: "hidden", children: [!hideAvatar && (_jsxs(MessageUserName, { children: [((_r = assistant.release) === null || _r === void 0 ? void 0 : _r.title) || assistant.name, extraUserInfo] })), _jsxs(React.Suspense, { children: [hasResult ? (_jsxs(Stack, { gap: 1, className: "message-response", children: [(_t = (_s = message.result) === null || _s === void 0 ? void 0 : _s.messages) === null || _t === void 0 ? void 0 : _t.map((childMsg, index) => {
84
+ var _a, _b, _c, _d, _e, _f, _g;
85
+ return ((_a = childMsg.result) === null || _a === void 0 ? void 0 : _a.content) ? (_jsx(MarkdownRenderer, { className: isMessageLoading &&
86
+ !((_b = message.result) === null || _b === void 0 ? void 0 : _b.content) &&
87
+ !((_d = (_c = message.result) === null || _c === void 0 ? void 0 : _c.images) === null || _d === void 0 ? void 0 : _d.length) &&
88
+ message.result.messages.length - 1 === index
89
+ ? 'writing'
90
+ : '', sx: childMsg.respondAs === 'systemMessage' ? { color: 'text.secondary' } : {}, children: (_e = childMsg.result) === null || _e === void 0 ? void 0 : _e.content }, childMsg.taskId)) : ((_g = (_f = childMsg.result) === null || _f === void 0 ? void 0 : _f.images) === null || _g === void 0 ? void 0 : _g.length) ? (_jsx(ImagePreview, { itemWidth: 100, spacing: 1, dataSource: childMsg.result.images.map((i) => ({ src: i.url })) }, childMsg.taskId)) : null;
91
+ }), ((_u = message.result) === null || _u === void 0 ? void 0 : _u.content) && (_jsx(MarkdownRenderer, { className: isMessageLoading ? 'writing' : '', children: message.result.content })), !!((_w = (_v = message.result) === null || _v === void 0 ? void 0 : _v.images) === null || _w === void 0 ? void 0 : _w.length) && (_jsx(ImagePreview, { itemWidth: 100, spacing: 1, dataSource: message.result.images.map((i) => ({ src: i.url })) })), !isMessageLoading && ((_x = message.result) === null || _x === void 0 ? void 0 : _x.content) && (_jsx(MessageActions, { className: "message-actions", content: message.result.content }))] })) : (isMessageLoading && (_jsx(Skeleton, { variant: "rectangular", height: 24 + 8 + 8,
92
+ // only response with loading
93
+ className: "message-response" }))), !!((_z = (_y = message.result) === null || _y === void 0 ? void 0 : _y.objects) === null || _z === void 0 ? void 0 : _z.length) &&
94
+ ((_1 = (_0 = message.result) === null || _0 === void 0 ? void 0 : _0.objects) === null || _1 === void 0 ? void 0 : _1.map((object) => (_jsx(MessageMetadataRenderer, { object: object.data }, object.taskId)))), message.error && (_jsx(MessageErrorView, { assistantId: assistantId, assistant: assistant, error: message.error }))] })] })] })] }));
95
+ }
96
+ function MessageUserName({ children }) {
97
+ return (_jsx(Typography, { component: "div", noWrap: true, sx: {
98
+ fontSize: 14,
99
+ lineHeight: '24px',
100
+ fontWeight: 500,
101
+ display: 'flex',
102
+ alignItems: 'center',
103
+ gap: 1,
104
+ }, children: children }));
105
+ }
@@ -0,0 +1,42 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { Stack } from '@mui/material';
14
+ import { useMemo } from 'react';
15
+ import { useAssistantState } from '../../state/assistant';
16
+ import { useSessionState } from '../../state/session';
17
+ import MessageItemView from './MessageItemView';
18
+ export default function MessageListView(_a) {
19
+ var { assistantId, sessionId } = _a, props = __rest(_a, ["assistantId", "sessionId"]);
20
+ const [assistant] = useAssistantState({ assistantId });
21
+ const [session, { messages = [] }] = useSessionState({ sessionId, required: true });
22
+ const opener = useMemo(() => {
23
+ var _a;
24
+ const { openerMessage } = (_a = assistant.release) !== null && _a !== void 0 ? _a : {};
25
+ if (openerMessage) {
26
+ return {
27
+ taskId: '',
28
+ sessionId: session.id,
29
+ createdAt: session.createdAt,
30
+ updatedAt: session.createdAt,
31
+ result: { content: openerMessage },
32
+ };
33
+ }
34
+ return undefined;
35
+ }, [assistant.release]);
36
+ if (!session)
37
+ return null;
38
+ return (_jsxs(Stack, Object.assign({ gap: 2.5 }, props, { children: [opener && _jsx(MessageItemView, { assistantId: assistantId, assistant: assistant, message: opener }), messages.map((message, index) => {
39
+ var _a, _b;
40
+ return (_jsx(MessageItemView, { assistantId: assistantId, assistant: assistant, message: message, previousMessageTime: (_b = (_a = messages[index - 1]) === null || _a === void 0 ? void 0 : _a.createdAt) !== null && _b !== void 0 ? _b : session.createdAt }, message.taskId));
41
+ })] })));
42
+ }
@@ -0,0 +1,8 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Link, Stack, Typography } from '@mui/material';
3
+ export default function ReferenceLinks({ links }) {
4
+ return (_jsxs(Stack, { sx: { wordBreak: 'break-word' }, children: [_jsx(Typography, { variant: "subtitle2", children: "References:" }), links === null || links === void 0 ? void 0 : links.map((item, index) => _jsx(ReferenceLinkItemView, { link: item }, index))] }));
5
+ }
6
+ function ReferenceLinkItemView({ link, }) {
7
+ return (_jsx(Stack, { children: _jsx(Link, { href: link.url, children: link.title || link.url }) }));
8
+ }
@@ -0,0 +1,53 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { MenuItem, TextField } from '@mui/material';
14
+ import { forwardRef } from 'react';
15
+ import { useLocaleContext } from '../../../../locale';
16
+ const LanguageField = forwardRef((_a, ref) => {
17
+ var { readOnly, parameter, onChange } = _a, props = __rest(_a, ["readOnly", "parameter", "onChange"]);
18
+ const { locale } = useLocaleContext();
19
+ return (_jsx(TextField, Object.assign({ ref: ref, select: true, onChange: (e) => onChange(e.target.value) }, props, { InputProps: Object.assign(Object.assign({}, props.InputProps), { readOnly }), children: languages.map((option) => (_jsx(MenuItem, { value: option.en, children: locale === 'zh' ? option.cn : option.en }, option.en))) })));
20
+ });
21
+ export default LanguageField;
22
+ const languages = [
23
+ { en: 'English', cn: '英语' },
24
+ { en: 'Simplified Chinese', cn: '中文-简体' },
25
+ { en: 'Traditional Chinese', cn: '中文-繁体' },
26
+ { en: 'Spanish', cn: '西班牙语' },
27
+ { en: 'French', cn: '法语' },
28
+ { en: 'German', cn: '德语' },
29
+ { en: 'Italian', cn: '意大利语' },
30
+ { en: 'Portuguese', cn: '葡萄牙语' },
31
+ { en: 'Japanese', cn: '日语' },
32
+ { en: 'Korean', cn: '韩语' },
33
+ { en: 'Russian', cn: '俄语' },
34
+ { en: 'Polish', cn: '波兰语' },
35
+ { en: 'Arabic', cn: '阿拉伯语' },
36
+ { en: 'Dutch', cn: '荷兰语' },
37
+ { en: 'Swedish', cn: '瑞典语' },
38
+ { en: 'Finnish', cn: '芬兰语' },
39
+ { en: 'Czech', cn: '捷克语' },
40
+ { en: 'Danish', cn: '丹麦语' },
41
+ { en: 'Greek', cn: '希腊语' },
42
+ { en: 'Romanian', cn: '罗马尼亚语' },
43
+ { en: 'Hungarian', cn: '匈牙利语' },
44
+ { en: 'Bulgarian', cn: '保加利亚语' },
45
+ { en: 'Slovak', cn: '斯洛伐克语' },
46
+ { en: 'Norwegian', cn: '挪威语' },
47
+ { en: 'Hebrew', cn: '希伯来语' },
48
+ { en: 'Turkish', cn: '土耳其语' },
49
+ { en: 'Thai', cn: '泰语' },
50
+ { en: 'Indonesian', cn: '印尼语' },
51
+ { en: 'Vietnamese', cn: '越南语' },
52
+ { en: 'Hindi', cn: '印地语' },
53
+ ];
@@ -0,0 +1,19 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { TextField } from '@mui/material';
14
+ import { forwardRef } from 'react';
15
+ const NumberField = forwardRef((_a, ref) => {
16
+ var { readOnly, parameter } = _a, props = __rest(_a, ["readOnly", "parameter"]);
17
+ return (_jsx(TextField, Object.assign({ ref: ref }, props, { InputProps: Object.assign(Object.assign({}, props.InputProps), { readOnly, inputProps: Object.assign({ type: 'number', inputMode: 'numeric', pattern: '[0-9]*', min: parameter === null || parameter === void 0 ? void 0 : parameter.min, max: parameter === null || parameter === void 0 ? void 0 : parameter.max }, props.inputProps) }), onChange: (e) => { var _a; return (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, Number(e.target.value)); } })));
18
+ });
19
+ export default NumberField;
@@ -0,0 +1,22 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { MenuItem, TextField } from '@mui/material';
14
+ import { forwardRef } from 'react';
15
+ const SelectField = forwardRef((_a, ref) => {
16
+ var _b, _c, _d, _e;
17
+ var { readOnly, parameter, onChange } = _a, props = __rest(_a, ["readOnly", "parameter", "onChange"]);
18
+ return (_jsx(TextField, Object.assign({ ref: ref, select: true, onChange: (e) => onChange(e.target.value) }, props, { InputProps: Object.assign(Object.assign({}, props.InputProps), { readOnly }), SelectProps: Object.assign(Object.assign({}, props.SelectProps), { MenuProps: Object.assign(Object.assign({}, (_b = props.SelectProps) === null || _b === void 0 ? void 0 : _b.MenuProps), { sx: Object.assign(Object.assign({}, (_d = (_c = props.SelectProps) === null || _c === void 0 ? void 0 : _c.MenuProps) === null || _d === void 0 ? void 0 : _d.sx), { '.MuiMenuItem-root': {
19
+ whiteSpace: 'pre-wrap',
20
+ } }) }) }), children: (_e = parameter === null || parameter === void 0 ? void 0 : parameter.options) === null || _e === void 0 ? void 0 : _e.map((option) => (_jsx(MenuItem, { value: option.value, children: option.label }, option.id))) })));
21
+ });
22
+ export default SelectField;
@@ -0,0 +1,19 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import { TextField } from '@mui/material';
14
+ import { forwardRef } from 'react';
15
+ const StringField = forwardRef((_a, ref) => {
16
+ var { readOnly, parameter, onChange } = _a, props = __rest(_a, ["readOnly", "parameter", "onChange"]);
17
+ return (_jsx(TextField, Object.assign({ ref: ref, multiline: parameter === null || parameter === void 0 ? void 0 : parameter.multiline, minRows: (parameter === null || parameter === void 0 ? void 0 : parameter.multiline) ? 2 : undefined, onChange: (e) => onChange(e.target.value) }, props, { InputProps: Object.assign(Object.assign({}, props.InputProps), { inputProps: Object.assign(Object.assign({}, props.inputProps), { maxLength: parameter === null || parameter === void 0 ? void 0 : parameter.maxLength }), readOnly }) })));
18
+ });
19
+ export default StringField;
@@ -0,0 +1,31 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx } from "react/jsx-runtime";
13
+ import LanguageField from './LanguageField';
14
+ import NumberField from './NumberField';
15
+ import SelectField from './SelectField';
16
+ import StringField from './StringField';
17
+ export default function ParameterField(_a) {
18
+ var { parameter } = _a, props = __rest(_a, ["parameter"]);
19
+ if (parameter.type === 'source')
20
+ return null;
21
+ if (parameter.key === 'datasetId') {
22
+ return null;
23
+ }
24
+ const Field = {
25
+ number: NumberField,
26
+ string: StringField,
27
+ select: SelectField,
28
+ language: LanguageField,
29
+ }[parameter.type || 'string'] || StringField;
30
+ return (_jsx(Field, Object.assign({ required: parameter === null || parameter === void 0 ? void 0 : parameter.required, label: parameter === null || parameter === void 0 ? void 0 : parameter.label, helperText: parameter === null || parameter === void 0 ? void 0 : parameter.helper, placeholder: parameter === null || parameter === void 0 ? void 0 : parameter.placeholder }, { parameter }, { size: "small" }, props)));
31
+ }
@@ -0,0 +1,88 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
11
+ import { Alert, Box, Stack } from '@mui/material';
12
+ import omit from 'lodash/omit';
13
+ import { useMemo, useState } from 'react';
14
+ import { useSessionContext } from '../../../../session';
15
+ import { createSession } from '../../api/session';
16
+ import { useCurrentPage } from '../../hooks/navigate';
17
+ import { useAssistantState } from '../../state/assistant';
18
+ import { createSessionState } from '../../state/session';
19
+ import { MessageSuggestedQuestion } from '../common/MessageSuggestedQuestions';
20
+ import ParameterForm from '../form/ParameterForm';
21
+ import { globalLoadingState } from '../GlobalLoading';
22
+ import MessageItemView from '../message/MessageItemView';
23
+ import PoweredBy from '../PoweredBy';
24
+ export default function InitialForm({ page }) {
25
+ var _a;
26
+ const { session: authSession } = useSessionContext();
27
+ const [assistant] = useAssistantState({ assistantId: page.assistantId });
28
+ const { parameters } = assistant;
29
+ const [error, setError] = useState();
30
+ const isChat = parameters === null || parameters === void 0 ? void 0 : parameters.some((i) => i.key === 'question');
31
+ const opener = useMemo(() => {
32
+ var _a;
33
+ const { openerMessage } = (_a = assistant.release) !== null && _a !== void 0 ? _a : {};
34
+ if (openerMessage) {
35
+ return {
36
+ taskId: '',
37
+ sessionId: '',
38
+ createdAt: new Date().toISOString(),
39
+ updatedAt: new Date().toISOString(),
40
+ result: { content: openerMessage },
41
+ };
42
+ }
43
+ return undefined;
44
+ }, [assistant.release]);
45
+ const { assistantId } = useCurrentPage();
46
+ const [creating, setCreating] = useState(false);
47
+ const onSubmit = (...args_1) => __awaiter(this, [...args_1], void 0, function* (parameters = {}, entry) {
48
+ if (!authSession.user) {
49
+ yield new Promise((resolve) => {
50
+ authSession.login(() => {
51
+ resolve();
52
+ });
53
+ });
54
+ }
55
+ if (creating)
56
+ return;
57
+ setCreating(true);
58
+ try {
59
+ yield globalLoadingState.getState().run(() => __awaiter(this, void 0, void 0, function* () {
60
+ const { created: session } = yield createSession({
61
+ assistantId,
62
+ name: parameters.question,
63
+ parameters: omit(parameters, isChat ? ['question'] : []),
64
+ entry,
65
+ });
66
+ createSessionState({ sessionId: session.id }).getState().execute({
67
+ assistantId,
68
+ parameters,
69
+ });
70
+ setError(undefined);
71
+ page.navigate({ page: 'session', assistantId, sessionId: session.id });
72
+ }));
73
+ }
74
+ catch (error) {
75
+ setError(error);
76
+ }
77
+ finally {
78
+ setCreating(false);
79
+ }
80
+ });
81
+ if (authSession.loading)
82
+ return null;
83
+ return (_jsxs(_Fragment, { children: [opener && (_jsx(Box, { my: 2, children: _jsx(MessageItemView, { assistantId: assistantId, hideAvatar: true, assistant: assistant, message: opener }) })), ((_a = assistant.entries) === null || _a === void 0 ? void 0 : _a.length) && (_jsx(EntryListView, { assistant: assistant, onEntryClick: (entry) => onSubmit(entry.parameters, { id: entry.id, title: entry.title }) })), _jsx(Box, { flex: 1 }), _jsxs(Box, { sx: { position: 'sticky', bottom: 0 }, children: [_jsx(ParameterForm, { assistant: assistant, onSubmit: onSubmit }), error && _jsx(Alert, { severity: "error", children: error.message }), _jsx(PoweredBy, { assistantId: page.assistantId, sx: { my: 1 } })] })] }));
84
+ }
85
+ function EntryListView({ assistant, onEntryClick, }) {
86
+ var _a;
87
+ return (_jsx(Stack, { gap: 1, alignItems: "flex-start", children: (_a = assistant.entries) === null || _a === void 0 ? void 0 : _a.map((entry) => entry.title && (_jsx(MessageSuggestedQuestion, { onClick: () => onEntryClick === null || onEntryClick === void 0 ? void 0 : onEntryClick(entry), children: entry.title }, entry.title))) }));
88
+ }
@@ -0,0 +1,22 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Box, Typography } from '@mui/material';
3
+ import Balancer, { Provider } from 'react-wrap-balancer';
4
+ import { Avatar } from '../../../../arcblock/ux';
5
+ export default function RuntimeChatHeader({ assistant }) {
6
+ var _a, _b, _c, _d, _e;
7
+ return (_jsx(Box, { className: "ai-chat-header", sx: { pt: 10 }, children: _jsxs(Provider, { children: [((_a = assistant.release) === null || _a === void 0 ? void 0 : _a.logo) && (_jsx(Box, { sx: { display: 'flex', justifyContent: 'center', alignItems: 'center' }, children: _jsx(Box, { component: Avatar, className: "logo", size: 100, did: (_b = globalThis.blocklet) === null || _b === void 0 ? void 0 : _b.appId, src: (_c = assistant.release) === null || _c === void 0 ? void 0 : _c.logo, sx: { borderRadius: 1 } }) })), _jsx(Typography, { component: "h1", sx: {
8
+ fontWeight: 'bold',
9
+ fontSize: 18,
10
+ mt: 1,
11
+ lineHeight: '28px',
12
+ textAlign: 'center',
13
+ color: '#010714',
14
+ }, children: _jsxs(Balancer, { children: ["\u200C\u200C\u200C\u200C\u200C\u200C", ((_d = assistant.release) === null || _d === void 0 ? void 0 : _d.title) || (assistant === null || assistant === void 0 ? void 0 : assistant.name)] }) }), _jsx(Typography, { component: "p", sx: {
15
+ mt: 2.5,
16
+ fontSize: 16,
17
+ lineHeight: '28px',
18
+ textAlign: 'center',
19
+ whiteSpace: 'pre-wrap',
20
+ color: '#465566',
21
+ }, children: _jsxs(Balancer, { children: ["\u200C\u200C\u200C\u200C\u200C\u200C\u200C", ((_e = assistant.release) === null || _e === void 0 ? void 0 : _e.description) || (assistant === null || assistant === void 0 ? void 0 : assistant.description)] }) })] }) }));
22
+ }
@@ -0,0 +1,15 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useAssistantState } from '../../state/assistant';
3
+ import Layout from '../layout';
4
+ import InitialForm from './InitialForm';
5
+ import RuntimeChatHeader from './RuntimeChatHeader';
6
+ export default function RuntimeChatHome({ page }) {
7
+ const [assistant] = useAssistantState({ assistantId: page.assistantId });
8
+ return (_jsxs(Layout, { disableBottomPadding: true, containerProps: {
9
+ sx: {
10
+ display: 'flex',
11
+ flexDirection: 'column',
12
+ height: '100%',
13
+ },
14
+ }, children: [_jsx(RuntimeChatHeader, { assistant: assistant }), _jsx(InitialForm, { page: page })] }));
15
+ }
@@ -0,0 +1,61 @@
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
+ import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
3
+ import { Alert, Box, alpha } from '@mui/material';
4
+ import { useState } from 'react';
5
+ import { useAssistantState } from '../../state/assistant';
6
+ import { useSessionState } from '../../state/session';
7
+ import { MessageSuggestedQuestions } from '../common';
8
+ import ParameterForm from '../form/ParameterForm';
9
+ import Layout from '../layout';
10
+ import MessageListView from '../message/MessageListView';
11
+ import PoweredBy from '../PoweredBy';
12
+ import { useScrollToBottomModule } from '../ScrollView';
13
+ import RuntimeChatHeader from './RuntimeChatHeader';
14
+ export default function RuntimeChatSession({ page }) {
15
+ const [assistant] = useAssistantState({ assistantId: page.assistantId });
16
+ return (_jsxs(Layout, { disableBottomPadding: true, containerProps: {
17
+ sx: {
18
+ display: 'flex',
19
+ flexDirection: 'column',
20
+ justifyContent: 'space-between',
21
+ height: '100%',
22
+ },
23
+ }, children: [_jsx(RuntimeChatHeader, { assistant: assistant }), _jsx(ChatForm, { page: page })] }));
24
+ }
25
+ function ChatForm({ page }) {
26
+ var _a, _b, _c, _d, _e, _f, _g;
27
+ const [session, state] = useSessionState({ sessionId: page.sessionId, required: true });
28
+ const [assistant] = useAssistantState({ assistantId: page.assistantId });
29
+ const lastMessage = (_a = state.messages) === null || _a === void 0 ? void 0 : _a.slice(-1)[0];
30
+ const suggestedQuestions = (_d = (_c = (_b = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.result) === null || _b === void 0 ? void 0 : _b.objects) === null || _c === void 0 ? void 0 : _c[0]) === null || _d === void 0 ? void 0 : _d.data[RuntimeOutputVariable.suggestedQuestions];
31
+ const scrollToBottom = useScrollToBottomModule().useScrollToBottom();
32
+ const [error, setError] = useState();
33
+ const onSubmit = (parameters) => {
34
+ scrollToBottom({ behavior: 'smooth' });
35
+ if (!session)
36
+ return;
37
+ state
38
+ .execute({
39
+ assistantId: page.assistantId,
40
+ parameters: Object.assign({}, parameters),
41
+ })
42
+ .then(() => {
43
+ setError(undefined);
44
+ })
45
+ .catch((error) => {
46
+ setError(error);
47
+ });
48
+ };
49
+ return (_jsxs(_Fragment, { children: [_jsx(MessageListView, { className: "ai-chat-message-list", my: 5, assistantId: page.assistantId, sessionId: page.sessionId }), !!(suggestedQuestions === null || suggestedQuestions === void 0 ? void 0 : suggestedQuestions.length) && (_jsx(Box, { ml: 6.5, mr: 2.5, mt: -4, children: _jsx(MessageSuggestedQuestions, { dataSource: suggestedQuestions, onClick: (item) => {
50
+ onSubmit(Object.assign(Object.assign({}, lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters), { question: item.question }));
51
+ } }) })), _jsx(Box, { flex: 1 }), _jsxs(Box, { className: "ai-chat-question-container", sx: {
52
+ pt: 1,
53
+ position: 'sticky',
54
+ bottom: 0,
55
+ // 从上透明到白色 0.72 的径向渐变
56
+ background: (theme) => `linear-gradient(180deg, ${alpha(theme.palette.background.default, 0.1)}, ${alpha(theme.palette.background.default, 1)} 5%)`,
57
+ '.ai-chat-question-bar > .MuiFormControl-root > .MuiInputBase-root': {
58
+ backdropFilter: 'blur(60px)',
59
+ },
60
+ }, children: [error && (_jsx(Alert, { severity: "error", sx: { mb: 1 }, children: error.message })), _jsx(ParameterForm, { sessionId: page.sessionId, defaultValues: (_e = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters) !== null && _e !== void 0 ? _e : session.parameters, assistant: assistant, onSubmit: onSubmit, isSubmitting: state.running, submitButtonTitle: (_g = (_f = assistant.release) === null || _f === void 0 ? void 0 : _f.submitButton) === null || _g === void 0 ? void 0 : _g.title }), _jsx(PoweredBy, { assistantId: page.assistantId, sx: { my: 0.5 } })] })] }));
61
+ }
@@ -0,0 +1,9 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import RuntimeChatHome from './RuntimeChatHome';
3
+ import RuntimeChatSession from './RuntimeChatSession';
4
+ export default function RuntimeChat({ page }) {
5
+ if (page.page === 'session') {
6
+ return _jsx(RuntimeChatSession, { page: page });
7
+ }
8
+ return _jsx(RuntimeChatHome, { page: page });
9
+ }
@@ -0,0 +1,97 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __rest = (this && this.__rest) || function (s, e) {
11
+ var t = {};
12
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
13
+ t[p] = s[p];
14
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
15
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
16
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
17
+ t[p[i]] = s[p[i]];
18
+ }
19
+ return t;
20
+ };
21
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
22
+ import { Alert, Box, Stack } from '@mui/material';
23
+ import { Suspense, useEffect, useMemo, useState } from 'react';
24
+ import { useForm } from 'react-hook-form';
25
+ import { useLocaleContext } from '../../../../locale';
26
+ import { alpha } from '../../../../mui/material';
27
+ import { useSessionContext } from '../../../../session';
28
+ import { createSession } from '../../api/session';
29
+ import { useAssistantState } from '../../state/assistant';
30
+ import { createSessionState } from '../../state/session';
31
+ import ParameterFormFields from '../form/ParameterFormFields';
32
+ import RuntimeFormSubmit from './RuntimeFormSubmit';
33
+ export default function RuntimeFormForms(_a) {
34
+ var _b, _c, _d;
35
+ var { page } = _a, props = __rest(_a, ["page"]);
36
+ const { t } = useLocaleContext();
37
+ const [agent] = useAssistantState({ assistantId: page.assistantId });
38
+ const lastParameters = useMemo(() => {
39
+ var _a;
40
+ if (page.sessionId) {
41
+ const { session, messages = [] } = createSessionState({ sessionId: page.sessionId }).getState();
42
+ const lastMessage = messages[messages.length - 1];
43
+ return (_a = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters) !== null && _a !== void 0 ? _a : session === null || session === void 0 ? void 0 : session.parameters;
44
+ }
45
+ return undefined;
46
+ }, [page.sessionId]);
47
+ const defaultForm = useMemo(() => {
48
+ var _a, _b;
49
+ return Object.fromEntries((_b = (_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.map((parameter) => [
50
+ parameter.key,
51
+ (lastParameters === null || lastParameters === void 0 ? void 0 : lastParameters[parameter.key]) || parameter.defaultValue,
52
+ ])) !== null && _b !== void 0 ? _b : []);
53
+ }, [agent.parameters, lastParameters]);
54
+ const form = useForm({ defaultValues: defaultForm });
55
+ const [error, setError] = useState();
56
+ const { session } = useSessionContext();
57
+ useEffect(() => {
58
+ form.reset(defaultForm);
59
+ }, [defaultForm]);
60
+ const onSubmit = (parameters) => __awaiter(this, void 0, void 0, function* () {
61
+ try {
62
+ const { created: session } = yield createSession({ assistantId: page.assistantId, parameters });
63
+ createSessionState({ sessionId: session.id, session });
64
+ page.navigate({ page: 'session', assistantId: page.assistantId, sessionId: session.id });
65
+ yield createSessionState({ sessionId: session.id })
66
+ .getState()
67
+ .execute({ assistantId: page.assistantId, parameters });
68
+ }
69
+ catch (error) {
70
+ setError(error);
71
+ throw error;
72
+ }
73
+ });
74
+ const handleSubmit = (e) => __awaiter(this, void 0, void 0, function* () {
75
+ e.preventDefault();
76
+ if (!session.user) {
77
+ yield new Promise((resolve) => {
78
+ session.login(() => resolve());
79
+ });
80
+ }
81
+ return form.handleSubmit(onSubmit)(e);
82
+ });
83
+ const openerMessage = (_b = agent.release) === null || _b === void 0 ? void 0 : _b.openerMessage;
84
+ return (_jsxs(Stack, Object.assign({ gap: 10, component: "form" }, props, { onSubmit: handleSubmit, children: [_jsxs(Stack, { gap: 2, children: [_jsx(Stack, { sx: { fontSize: 32, py: 2.5, mb: -2 }, children: "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83D\uDCBB" }), openerMessage && _jsx(Box, { sx: { color: 'text.secondary' }, children: openerMessage }), _jsx(ParameterFormFields, { parameters: agent.parameters, form: form })] }), _jsx(Suspense, { children: _jsxs(Stack, { sx: {
85
+ gap: 1,
86
+ position: 'sticky',
87
+ bottom: 0,
88
+ pb: 1,
89
+ pt: 1,
90
+ // 从上透明到白色 0.72 的径向渐变
91
+ background: (theme) => `linear-gradient(180deg, ${alpha(theme.palette.background.default, 0.1)}, ${alpha(theme.palette.background.default, 1)} 5%)`,
92
+ }, children: [error && _jsx(Alert, { severity: "error", children: error.message }), _jsx(RuntimeFormSubmit, { page: page, type: "submit", variant: "contained", fullWidth: true, loading: form.formState.isSubmitting, sx: {
93
+ borderRadius: 100,
94
+ height: 44,
95
+ background: 'linear-gradient(90deg, rgb(69, 228, 250) 0%, rgb(138, 69, 250) 52.08%, rgb(250, 69, 188) 100%)',
96
+ }, children: ((_d = (_c = agent.release) === null || _c === void 0 ? void 0 : _c.submitButton) === null || _d === void 0 ? void 0 : _d.title) || t('submit') })] }) })] })));
97
+ }
@@ -0,0 +1,19 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
12
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
+ import { Box, Stack, Typography } from '@mui/material';
14
+ import { Avatar } from '../../../../arcblock/ux';
15
+ export default function RuntimeFormHeader(_a) {
16
+ var _b, _c, _d;
17
+ var { agent } = _a, props = __rest(_a, ["agent"]);
18
+ return (_jsxs(Stack, Object.assign({ direction: "row", justifyContent: "space-between", alignItems: "center", gap: 2, bgcolor: "rgb(246, 242, 255)" }, props, { children: [_jsxs(Stack, { children: [_jsx(Typography, { component: "h5", sx: { fontSize: 32, fontWeight: 700 }, children: ((_b = agent.release) === null || _b === void 0 ? void 0 : _b.title) || agent.name }), _jsx(Typography, { sx: { fontSize: 16, color: 'rgb(147, 151, 161)' }, children: ((_c = agent.release) === null || _c === void 0 ? void 0 : _c.description) || agent.description })] }), _jsx(Stack, { children: _jsx(Box, { component: Avatar, size: 88, src: (_d = agent.release) === null || _d === void 0 ? void 0 : _d.logo, did: blocklet === null || blocklet === void 0 ? void 0 : blocklet.appId, borderRadius: 1 }) })] })));
19
+ }