@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,67 @@
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 types_1 = require("@blocklet/ai-runtime/types");
8
+ const material_1 = require("@mui/material");
9
+ const react_1 = require("react");
10
+ const assistant_1 = require("../../state/assistant");
11
+ const session_1 = require("../../state/session");
12
+ const common_1 = require("../common");
13
+ const ParameterForm_1 = __importDefault(require("../form/ParameterForm"));
14
+ const layout_1 = __importDefault(require("../layout"));
15
+ const MessageListView_1 = __importDefault(require("../message/MessageListView"));
16
+ const PoweredBy_1 = __importDefault(require("../PoweredBy"));
17
+ const ScrollView_1 = require("../ScrollView");
18
+ const RuntimeChatHeader_1 = __importDefault(require("./RuntimeChatHeader"));
19
+ function RuntimeChatSession({ page }) {
20
+ const [assistant] = (0, assistant_1.useAssistantState)({ assistantId: page.assistantId });
21
+ return ((0, jsx_runtime_1.jsxs)(layout_1.default, { disableBottomPadding: true, containerProps: {
22
+ sx: {
23
+ display: 'flex',
24
+ flexDirection: 'column',
25
+ justifyContent: 'space-between',
26
+ height: '100%',
27
+ },
28
+ }, children: [(0, jsx_runtime_1.jsx)(RuntimeChatHeader_1.default, { assistant: assistant }), (0, jsx_runtime_1.jsx)(ChatForm, { page: page })] }));
29
+ }
30
+ exports.default = RuntimeChatSession;
31
+ function ChatForm({ page }) {
32
+ var _a, _b, _c, _d, _e, _f, _g;
33
+ const [session, state] = (0, session_1.useSessionState)({ sessionId: page.sessionId, required: true });
34
+ const [assistant] = (0, assistant_1.useAssistantState)({ assistantId: page.assistantId });
35
+ const lastMessage = (_a = state.messages) === null || _a === void 0 ? void 0 : _a.slice(-1)[0];
36
+ 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[types_1.RuntimeOutputVariable.suggestedQuestions];
37
+ const scrollToBottom = (0, ScrollView_1.useScrollToBottomModule)().useScrollToBottom();
38
+ const [error, setError] = (0, react_1.useState)();
39
+ const onSubmit = (parameters) => {
40
+ scrollToBottom({ behavior: 'smooth' });
41
+ if (!session)
42
+ return;
43
+ state
44
+ .execute({
45
+ assistantId: page.assistantId,
46
+ parameters: Object.assign({}, parameters),
47
+ })
48
+ .then(() => {
49
+ setError(undefined);
50
+ })
51
+ .catch((error) => {
52
+ setError(error);
53
+ });
54
+ };
55
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(MessageListView_1.default, { className: "ai-chat-message-list", my: 5, assistantId: page.assistantId, sessionId: page.sessionId }), !!(suggestedQuestions === null || suggestedQuestions === void 0 ? void 0 : suggestedQuestions.length) && ((0, jsx_runtime_1.jsx)(material_1.Box, { ml: 6.5, mr: 2.5, mt: -4, children: (0, jsx_runtime_1.jsx)(common_1.MessageSuggestedQuestions, { dataSource: suggestedQuestions, onClick: (item) => {
56
+ onSubmit(Object.assign(Object.assign({}, lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters), { question: item.question }));
57
+ } }) })), (0, jsx_runtime_1.jsx)(material_1.Box, { flex: 1 }), (0, jsx_runtime_1.jsxs)(material_1.Box, { className: "ai-chat-question-container", sx: {
58
+ pt: 1,
59
+ position: 'sticky',
60
+ bottom: 0,
61
+ // 从上透明到白色 0.72 的径向渐变
62
+ background: (theme) => `linear-gradient(180deg, ${(0, material_1.alpha)(theme.palette.background.default, 0.1)}, ${(0, material_1.alpha)(theme.palette.background.default, 1)} 5%)`,
63
+ '.ai-chat-question-bar > .MuiFormControl-root > .MuiInputBase-root': {
64
+ backdropFilter: 'blur(60px)',
65
+ },
66
+ }, children: [error && ((0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "error", sx: { mb: 1 }, children: error.message })), (0, jsx_runtime_1.jsx)(ParameterForm_1.default, { 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 }), (0, jsx_runtime_1.jsx)(PoweredBy_1.default, { assistantId: page.assistantId, sx: { my: 0.5 } })] })] }));
67
+ }
@@ -0,0 +1,15 @@
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 RuntimeChatHome_1 = __importDefault(require("./RuntimeChatHome"));
8
+ const RuntimeChatSession_1 = __importDefault(require("./RuntimeChatSession"));
9
+ function RuntimeChat({ page }) {
10
+ if (page.page === 'session') {
11
+ return (0, jsx_runtime_1.jsx)(RuntimeChatSession_1.default, { page: page });
12
+ }
13
+ return (0, jsx_runtime_1.jsx)(RuntimeChatHome_1.default, { page: page });
14
+ }
15
+ exports.default = RuntimeChat;
@@ -0,0 +1,103 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __rest = (this && this.__rest) || function (s, e) {
12
+ var t = {};
13
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
14
+ t[p] = s[p];
15
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
16
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
17
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
18
+ t[p[i]] = s[p[i]];
19
+ }
20
+ return t;
21
+ };
22
+ var __importDefault = (this && this.__importDefault) || function (mod) {
23
+ return (mod && mod.__esModule) ? mod : { "default": mod };
24
+ };
25
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ const jsx_runtime_1 = require("react/jsx-runtime");
27
+ const material_1 = require("@mui/material");
28
+ const react_1 = require("react");
29
+ const react_hook_form_1 = require("react-hook-form");
30
+ const locale_1 = require("../../../../locale");
31
+ const material_2 = require("../../../../mui/material");
32
+ const session_1 = require("../../../../session");
33
+ const session_2 = require("../../api/session");
34
+ const assistant_1 = require("../../state/assistant");
35
+ const session_3 = require("../../state/session");
36
+ const ParameterFormFields_1 = __importDefault(require("../form/ParameterFormFields"));
37
+ const RuntimeFormSubmit_1 = __importDefault(require("./RuntimeFormSubmit"));
38
+ function RuntimeFormForms(_a) {
39
+ var _b, _c, _d;
40
+ var { page } = _a, props = __rest(_a, ["page"]);
41
+ const { t } = (0, locale_1.useLocaleContext)();
42
+ const [agent] = (0, assistant_1.useAssistantState)({ assistantId: page.assistantId });
43
+ const lastParameters = (0, react_1.useMemo)(() => {
44
+ var _a;
45
+ if (page.sessionId) {
46
+ const { session, messages = [] } = (0, session_3.createSessionState)({ sessionId: page.sessionId }).getState();
47
+ const lastMessage = messages[messages.length - 1];
48
+ 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;
49
+ }
50
+ return undefined;
51
+ }, [page.sessionId]);
52
+ const defaultForm = (0, react_1.useMemo)(() => {
53
+ var _a, _b;
54
+ return Object.fromEntries((_b = (_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.map((parameter) => [
55
+ parameter.key,
56
+ (lastParameters === null || lastParameters === void 0 ? void 0 : lastParameters[parameter.key]) || parameter.defaultValue,
57
+ ])) !== null && _b !== void 0 ? _b : []);
58
+ }, [agent.parameters, lastParameters]);
59
+ const form = (0, react_hook_form_1.useForm)({ defaultValues: defaultForm });
60
+ const [error, setError] = (0, react_1.useState)();
61
+ const { session } = (0, session_1.useSessionContext)();
62
+ (0, react_1.useEffect)(() => {
63
+ form.reset(defaultForm);
64
+ }, [defaultForm]);
65
+ const onSubmit = (parameters) => __awaiter(this, void 0, void 0, function* () {
66
+ try {
67
+ const { created: session } = yield (0, session_2.createSession)({ assistantId: page.assistantId, parameters });
68
+ (0, session_3.createSessionState)({ sessionId: session.id, session });
69
+ page.navigate({ page: 'session', assistantId: page.assistantId, sessionId: session.id });
70
+ yield (0, session_3.createSessionState)({ sessionId: session.id })
71
+ .getState()
72
+ .execute({ assistantId: page.assistantId, parameters });
73
+ }
74
+ catch (error) {
75
+ setError(error);
76
+ throw error;
77
+ }
78
+ });
79
+ const handleSubmit = (e) => __awaiter(this, void 0, void 0, function* () {
80
+ e.preventDefault();
81
+ if (!session.user) {
82
+ yield new Promise((resolve) => {
83
+ session.login(() => resolve());
84
+ });
85
+ }
86
+ return form.handleSubmit(onSubmit)(e);
87
+ });
88
+ const openerMessage = (_b = agent.release) === null || _b === void 0 ? void 0 : _b.openerMessage;
89
+ return ((0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ gap: 10, component: "form" }, props, { onSubmit: handleSubmit, children: [(0, jsx_runtime_1.jsxs)(material_1.Stack, { gap: 2, children: [(0, jsx_runtime_1.jsx)(material_1.Stack, { sx: { fontSize: 32, py: 2.5, mb: -2 }, children: "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83D\uDCBB" }), openerMessage && (0, jsx_runtime_1.jsx)(material_1.Box, { sx: { color: 'text.secondary' }, children: openerMessage }), (0, jsx_runtime_1.jsx)(ParameterFormFields_1.default, { parameters: agent.parameters, form: form })] }), (0, jsx_runtime_1.jsx)(react_1.Suspense, { children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { sx: {
90
+ gap: 1,
91
+ position: 'sticky',
92
+ bottom: 0,
93
+ pb: 1,
94
+ pt: 1,
95
+ // 从上透明到白色 0.72 的径向渐变
96
+ background: (theme) => `linear-gradient(180deg, ${(0, material_2.alpha)(theme.palette.background.default, 0.1)}, ${(0, material_2.alpha)(theme.palette.background.default, 1)} 5%)`,
97
+ }, children: [error && (0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "error", children: error.message }), (0, jsx_runtime_1.jsx)(RuntimeFormSubmit_1.default, { page: page, type: "submit", variant: "contained", fullWidth: true, loading: form.formState.isSubmitting, sx: {
98
+ borderRadius: 100,
99
+ height: 44,
100
+ background: 'linear-gradient(90deg, rgb(69, 228, 250) 0%, rgb(138, 69, 250) 52.08%, rgb(250, 69, 188) 100%)',
101
+ }, children: ((_d = (_c = agent.release) === null || _c === void 0 ? void 0 : _c.submitButton) === null || _d === void 0 ? void 0 : _d.title) || t('submit') })] }) })] })));
102
+ }
103
+ exports.default = RuntimeFormForms;
@@ -0,0 +1,22 @@
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
+ const jsx_runtime_1 = require("react/jsx-runtime");
15
+ const material_1 = require("@mui/material");
16
+ const ux_1 = require("../../../../arcblock/ux");
17
+ function RuntimeFormHeader(_a) {
18
+ var _b, _c, _d;
19
+ var { agent } = _a, props = __rest(_a, ["agent"]);
20
+ return ((0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ direction: "row", justifyContent: "space-between", alignItems: "center", gap: 2, bgcolor: "rgb(246, 242, 255)" }, props, { children: [(0, jsx_runtime_1.jsxs)(material_1.Stack, { children: [(0, jsx_runtime_1.jsx)(material_1.Typography, { component: "h5", sx: { fontSize: 32, fontWeight: 700 }, children: ((_b = agent.release) === null || _b === void 0 ? void 0 : _b.title) || agent.name }), (0, jsx_runtime_1.jsx)(material_1.Typography, { sx: { fontSize: 16, color: 'rgb(147, 151, 161)' }, children: ((_c = agent.release) === null || _c === void 0 ? void 0 : _c.description) || agent.description })] }), (0, jsx_runtime_1.jsx)(material_1.Stack, { children: (0, jsx_runtime_1.jsx)(material_1.Box, { component: ux_1.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 }) })] })));
21
+ }
22
+ exports.default = RuntimeFormHeader;
@@ -0,0 +1,72 @@
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
+ const jsx_runtime_1 = require("react/jsx-runtime");
18
+ const react_1 = require("@iconify/react");
19
+ const material_1 = require("@mui/material");
20
+ const react_2 = require("react");
21
+ const react_share_1 = require("react-share");
22
+ const ufo_1 = require("ufo");
23
+ const locale_1 = require("../../../../locale");
24
+ const lottie_error_json_url_1 = __importDefault(require("../../assets/lottie/lottie-error.json?url"));
25
+ const lottie_loading_json_url_1 = __importDefault(require("../../assets/lottie/lottie-loading.json?url"));
26
+ const lottie_success_json_url_1 = __importDefault(require("../../assets/lottie/lottie-success.json?url"));
27
+ const lottie_welcome_json_url_1 = __importDefault(require("../../assets/lottie/lottie-welcome.json?url"));
28
+ const session_1 = require("../../state/session");
29
+ const ActionButton_1 = require("../ActionButton");
30
+ const common_1 = require("../common");
31
+ const lottie_1 = __importDefault(require("../lottie"));
32
+ const MarkdownRenderer_1 = __importDefault(require("../MarkdownRenderer"));
33
+ function RuntimeFormResult(_a) {
34
+ var { page } = _a, props = __rest(_a, ["page"]);
35
+ return ((0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({}, props, { children: [(0, jsx_runtime_1.jsx)(material_1.Stack, { sx: {
36
+ px: { xs: 2, sm: 3, md: 4 },
37
+ py: 2.5,
38
+ bgcolor: 'background.default',
39
+ position: { xs: 'unset', md: 'sticky' },
40
+ top: 0,
41
+ zIndex: 2,
42
+ fontSize: 32,
43
+ }, children: "\uD83E\uDD16" }), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: { px: { xs: 2, sm: 3, md: 4 } }, children: (0, jsx_runtime_1.jsx)(react_2.Suspense, { children: page.sessionId ? ((0, jsx_runtime_1.jsx)(ResultView, { sessionId: page.sessionId })) : ((0, jsx_runtime_1.jsx)(material_1.Box, { width: 300, height: 300, m: "auto", mt: "100px", children: (0, jsx_runtime_1.jsx)(lottie_1.default, { src: lottie_welcome_json_url_1.default }) })) }) })] })));
44
+ }
45
+ exports.default = RuntimeFormResult;
46
+ function ResultView({ sessionId }) {
47
+ var _a, _b, _c, _d;
48
+ const { t } = (0, locale_1.useLocaleContext)();
49
+ const [, _e] = (0, session_1.useSessionState)({ sessionId }), { messages = [] } = _e, state = __rest(_e, ["messages"]);
50
+ const message = messages[messages.length - 1];
51
+ const textContent = (_a = message === null || message === void 0 ? void 0 : message.result) === null || _a === void 0 ? void 0 : _a.content;
52
+ const error = state.error || (message === null || message === void 0 ? void 0 : message.error);
53
+ if (error) {
54
+ return ((0, jsx_runtime_1.jsxs)(material_1.Box, { width: 240, height: 240, m: "auto", mt: "100px", children: [(0, jsx_runtime_1.jsx)(lottie_1.default, { src: lottie_error_json_url_1.default }), (0, jsx_runtime_1.jsx)(material_1.Box, { textAlign: "center", color: "#25292F", children: error.message })] }));
55
+ }
56
+ if ((message === null || message === void 0 ? void 0 : message.loading) && !textContent) {
57
+ return ((0, jsx_runtime_1.jsx)(material_1.Box, { width: 240, height: 240, m: "auto", mt: "100px", children: (0, jsx_runtime_1.jsx)(lottie_1.default, { src: lottie_loading_json_url_1.default }) }));
58
+ }
59
+ if (!message) {
60
+ return ((0, jsx_runtime_1.jsx)(material_1.Box, { width: 300, height: 300, m: "auto", mt: "100px", children: (0, jsx_runtime_1.jsx)(lottie_1.default, { src: lottie_welcome_json_url_1.default }) }));
61
+ }
62
+ return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { gap: 2, children: [textContent && ((0, jsx_runtime_1.jsxs)(material_1.Box, { sx: {
63
+ border: 1,
64
+ borderColor: 'grey.200',
65
+ borderRadius: 1,
66
+ bgcolor: 'grey.100',
67
+ }, children: [(0, jsx_runtime_1.jsx)(material_1.Box, { sx: { p: 2 }, children: (0, jsx_runtime_1.jsx)(MarkdownRenderer_1.default, { className: (message === null || message === void 0 ? void 0 : message.loading) ? 'writing' : '', children: (_b = message === null || message === void 0 ? void 0 : message.result) === null || _b === void 0 ? void 0 : _b.content }) }), !(message === null || message === void 0 ? void 0 : message.loading) && textContent && ((0, jsx_runtime_1.jsxs)(material_1.Stack, { direction: "row", alignItems: "center", justifyContent: "flex-end", px: 2, pb: 1, gap: 1, children: [(0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(ActionButton_1.ActionButton, { autoReset: true, size: "small", variant: "text",
68
+ // @ts-ignore
69
+ color: "black", tip: t('copyToClipboard'), tipSucceed: t('copied'), title: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "tabler:copy", fontSize: 18 }), titleSucceed: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "tabler:copy-check-filled", fontSize: 18 }), sx: { p: 0.5, minWidth: 0, minHeight: 0, color: 'text.secondary' }, onClick: () => {
70
+ window.navigator.clipboard.writeText(textContent);
71
+ } }) }), (0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(material_1.Tooltip, { title: t('socialShare.shareToX'), placement: "top", disableInteractive: true, children: (0, jsx_runtime_1.jsx)(material_1.Button, { sx: { p: 0.5, minWidth: 0, minHeight: 0 }, target: "_blank", href: (0, ufo_1.withQuery)('https://twitter.com/intent/tweet', { text: textContent }), children: (0, jsx_runtime_1.jsx)(react_share_1.XIcon, { size: 18, borderRadius: 16 }) }) }) })] }))] })), (_d = (_c = message.result) === null || _c === void 0 ? void 0 : _c.objects) === null || _d === void 0 ? void 0 : _d.map((object) => (0, jsx_runtime_1.jsx)(common_1.MessageMetadataRenderer, { object: object.data }, object.taskId)), (0, jsx_runtime_1.jsx)(material_1.Box, { display: "flex", justifyContent: "flex-end", mb: "60px", mt: "40px", children: (0, jsx_runtime_1.jsx)(material_1.Box, { width: 120, height: 120, children: (0, jsx_runtime_1.jsx)(lottie_1.default, { src: lottie_success_json_url_1.default }) }) })] }));
72
+ }
@@ -0,0 +1,31 @@
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
+ const jsx_runtime_1 = require("react/jsx-runtime");
18
+ const subscribe_1 = require("../../hooks/subscribe");
19
+ const LoadingButton_1 = __importDefault(require("../LoadingButton"));
20
+ const PoweredBy_1 = __importDefault(require("../PoweredBy"));
21
+ function RuntimeFormSubmit(_a) {
22
+ var { page } = _a, props = __rest(_a, ["page"]);
23
+ const { subscribeLink } = (0, subscribe_1.useSubscribeLink)({ assistantId: page.assistantId });
24
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(LoadingButton_1.default, Object.assign({}, props, { onClick: (e) => {
25
+ if (subscribeLink) {
26
+ e.preventDefault();
27
+ window.location.href = subscribeLink;
28
+ }
29
+ } })), (0, jsx_runtime_1.jsx)(PoweredBy_1.default, { assistantId: page.assistantId })] }));
30
+ }
31
+ exports.default = RuntimeFormSubmit;
@@ -0,0 +1,22 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const jsx_runtime_1 = require("react/jsx-runtime");
7
+ const material_1 = require("@mui/material");
8
+ const assistant_1 = require("../../state/assistant");
9
+ const RuntimeFormForms_1 = __importDefault(require("./RuntimeFormForms"));
10
+ const RuntimeFormHeader_1 = __importDefault(require("./RuntimeFormHeader"));
11
+ const RuntimeFormResult_1 = __importDefault(require("./RuntimeFormResult"));
12
+ function RuntimeForm({ page }) {
13
+ const [agent] = (0, assistant_1.useAssistantState)({ assistantId: page.assistantId });
14
+ return ((0, jsx_runtime_1.jsxs)(material_1.Stack, { sx: { flexGrow: { xs: 'unset', md: 1 } }, children: [(0, jsx_runtime_1.jsx)(RuntimeFormHeader_1.default, { agent: agent, sx: {
15
+ position: 'sticky',
16
+ top: 64,
17
+ zIndex: 10,
18
+ px: { xs: 2, sm: 3, md: 8 },
19
+ py: { xs: 2, sm: 3, md: 5 },
20
+ } }), (0, jsx_runtime_1.jsxs)(material_1.Stack, { sx: { flexGrow: 1, flexDirection: { xs: 'column', md: 'row' } }, children: [(0, jsx_runtime_1.jsx)(material_1.Stack, { sx: { flex: 1, px: { xs: 2, sm: 3, md: 4 }, ml: { xs: 0, md: 4 } }, children: (0, jsx_runtime_1.jsx)(RuntimeFormForms_1.default, { page: page, sx: { position: 'sticky', top: 232 } }) }), (0, jsx_runtime_1.jsx)(material_1.Divider, { orientation: "vertical", sx: { borderColor: 'grey.200', my: { xs: 2, sm: 3, md: 0 } } }), (0, jsx_runtime_1.jsx)(material_1.Box, { sx: { flex: 2 }, children: (0, jsx_runtime_1.jsx)(RuntimeFormResult_1.default, { page: page }) })] })] }));
21
+ }
22
+ exports.default = RuntimeForm;
@@ -0,0 +1,62 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
12
+ const react_1 = require("react");
13
+ const session_1 = require("../../../../session");
14
+ const session_2 = require("../../api/session");
15
+ const assistant_1 = require("../../state/assistant");
16
+ const session_3 = require("../../state/session");
17
+ const utils_1 = require("../../utils");
18
+ const GlobalLoading_1 = require("../GlobalLoading");
19
+ function CheckSession({ assistantId, sessionId, autoCreateSession, children, navigate, }) {
20
+ (0, assistant_1.useAssistantState)({ assistantId });
21
+ const { session: authSession } = (0, session_1.useSessionContext)();
22
+ const [done, setDone] = (0, react_1.useState)(false);
23
+ const [error, setError] = (0, react_1.useState)();
24
+ (0, react_1.useEffect)(() => {
25
+ if (!authSession.user)
26
+ return;
27
+ GlobalLoading_1.globalLoadingState.getState().run(() => __awaiter(this, void 0, void 0, function* () {
28
+ var _a;
29
+ try {
30
+ if (!sessionId) {
31
+ if (authSession.user) {
32
+ const { sessions } = yield (0, session_2.getSessions)((0, utils_1.parseIdentity)(assistantId, { rejectWhenError: true }));
33
+ const session = (_a = sessions[0]) !== null && _a !== void 0 ? _a : (autoCreateSession ? (yield (0, session_2.createSession)({ assistantId })).created : undefined);
34
+ if (session) {
35
+ yield (0, session_3.createSessionState)({ sessionId: session.id, session }).getState().load();
36
+ navigate === null || navigate === void 0 ? void 0 : navigate({ page: 'session', assistantId, sessionId: session.id });
37
+ }
38
+ }
39
+ }
40
+ else {
41
+ const state = (0, session_3.createSessionState)({ sessionId });
42
+ yield state.getState().load();
43
+ }
44
+ setDone(true);
45
+ }
46
+ catch (error) {
47
+ if (sessionId) {
48
+ navigate === null || navigate === void 0 ? void 0 : navigate({ page: 'assistant', assistantId, sessionId: undefined }, { replace: true });
49
+ }
50
+ else {
51
+ setError(error);
52
+ }
53
+ }
54
+ }));
55
+ }, [assistantId, sessionId, authSession.user]);
56
+ if (error)
57
+ throw error;
58
+ if (authSession.loading)
59
+ return null;
60
+ return done && children;
61
+ }
62
+ exports.default = CheckSession;
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ // import { Box, CircularProgress, Stack, Typography } from '@mui/material';
3
+ // import { useEffect } from 'react';
4
+ // import { RelativeTime } from 'src/builtin/arcblock/ux';
5
+ // import { useLocaleContext } from 'src/builtin/locale';
6
+ // import { Session } from '../../api/session';
7
+ // import { useNavigateTo } from '../../hooks/navigate';
8
+ // import { createState } from '../../state';
9
+ // import Layout from '../layout';
10
+ // export default function SessionListView({ releaseId }: { releaseId: string }) {
11
+ // const { t } = useLocaleContext();
12
+ // const state = createState({ releaseId })();
13
+ // useEffect(() => {
14
+ // if (!state.sessions?.length) {
15
+ // state.getAssistant();
16
+ // } else {
17
+ // state.getSessions();
18
+ // }
19
+ // }, []);
20
+ // return (
21
+ // <Layout>
22
+ // <Typography
23
+ // component="h1"
24
+ // textAlign="center"
25
+ // sx={{
26
+ // fontWeight: 700,
27
+ // fontSize: 32,
28
+ // lineHeight: '44px',
29
+ // mt: 5,
30
+ // mb: 2.5,
31
+ // }}>
32
+ // {t('history')}
33
+ // </Typography>
34
+ // {!state.sessions?.length && (
35
+ // <Stack alignItems="center" gap={0.5} mt="10vh" mx={3}>
36
+ // {state.loading ? (
37
+ // <CircularProgress size={24} />
38
+ // ) : (
39
+ // <>
40
+ // <Typography fontSize={18}>💬</Typography>
41
+ // <Typography fontSize={12} sx={{ color: 'text.secondary' }}>
42
+ // {t('noData', { data: t('history') })}
43
+ // </Typography>
44
+ // </>
45
+ // )}
46
+ // </Stack>
47
+ // )}
48
+ // <Stack gap={2.5}>
49
+ // {state.sessions?.map((session) => <SessionItemView key={session.id} session={session} />)}
50
+ // </Stack>
51
+ // </Layout>
52
+ // );
53
+ // }
54
+ // function SessionItemView({ session }: { session: Session }) {
55
+ // const { locale } = useLocaleContext();
56
+ // const to = useNavigateTo();
57
+ // return (
58
+ // <Stack
59
+ // component={RouterLink}
60
+ // to={to({ page: 'session', sessionId: session.id })}
61
+ // gap={1.5}
62
+ // sx={{
63
+ // bgcolor: 'background.paper',
64
+ // p: 2.5,
65
+ // borderRadius: 1,
66
+ // boxShadow: 1,
67
+ // cursor: 'pointer',
68
+ // ':hover': {
69
+ // boxShadow: 2,
70
+ // },
71
+ // }}>
72
+ // <Box
73
+ // sx={{
74
+ // display: '-webkit-box',
75
+ // WebkitBoxOrient: 'vertical',
76
+ // WebkitLineClamp: 3,
77
+ // overflow: 'hidden',
78
+ // fontSize: 18,
79
+ // lineHeight: '32px',
80
+ // }}>
81
+ // {session.name || session.entry?.title}
82
+ // </Box>
83
+ // <Typography color="text.secondary">
84
+ // <RelativeTime locale={locale} value={session.updatedAt} relativeRange={600e3} />
85
+ // </Typography>
86
+ // </Stack>
87
+ // );
88
+ // }
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PAYMENT_KIT_DID = exports.AI_STUDIO_DID = void 0;
4
+ exports.AI_STUDIO_DID = 'z8iZpog7mcgcgBZzTiXJCWESvmnRrQmnd3XBB';
5
+ exports.PAYMENT_KIT_DID = 'z2qaCNvKMv5GjouKdcDWexv6WqtHbpNPQDnAk';
@@ -0,0 +1,32 @@
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.useSetHeader = void 0;
7
+ const jsx_runtime_1 = require("react/jsx-runtime");
8
+ const material_1 = require("@mui/material");
9
+ const react_1 = require("react");
10
+ const header_1 = require("../../../page/header");
11
+ const SocialShare_1 = __importDefault(require("../components/SocialShare"));
12
+ function useSetHeader({ assistant }) {
13
+ // set logo
14
+ (0, react_1.useEffect)(() => {
15
+ const { release } = assistant;
16
+ header_1.useHeaderState.setState((state) => {
17
+ state.logo = (release === null || release === void 0 ? void 0 : release.logo) && (0, jsx_runtime_1.jsx)(material_1.Box, { component: "img", src: release.logo, sx: { borderRadius: 1 } });
18
+ state.brand = (release === null || release === void 0 ? void 0 : release.title) || assistant.name;
19
+ const shareContent = `${(release === null || release === void 0 ? void 0 : release.title) || assistant.name}
20
+
21
+ ${release === null || release === void 0 ? void 0 : release.description}
22
+ `;
23
+ state.addons = (...exists) => [(0, jsx_runtime_1.jsx)(SocialShare_1.default, { content: shareContent }), ...exists];
24
+ });
25
+ return () => header_1.useHeaderState.setState((state) => {
26
+ state.logo = undefined;
27
+ state.brand = undefined;
28
+ state.addons = (...exists) => [...exists];
29
+ });
30
+ }, []);
31
+ }
32
+ exports.useSetHeader = useSetHeader;
@@ -0,0 +1,37 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useCurrentPage = exports.useNavigateWithQuery = exports.useNavigateTo = void 0;
4
+ const react_1 = require("react");
5
+ const react_router_dom_1 = require("react-router-dom");
6
+ const ufo_1 = require("ufo");
7
+ function useNavigateTo() {
8
+ const location = (0, react_router_dom_1.useLocation)();
9
+ return (0, react_1.useCallback)((query) => (0, ufo_1.withQuery)(`${location.pathname}${location.search}`, query), [location]);
10
+ }
11
+ exports.useNavigateTo = useNavigateTo;
12
+ function useNavigateWithQuery() {
13
+ const to = useNavigateTo();
14
+ const navigate = (0, react_router_dom_1.useNavigate)();
15
+ return (0, react_1.useCallback)((query, options) => {
16
+ navigate(to(Object.assign(Object.assign({}, query), { page: query.page === 'assistant' ? undefined : query.page })), options);
17
+ }, [navigate, to]);
18
+ }
19
+ exports.useNavigateWithQuery = useNavigateWithQuery;
20
+ const PAGES = ['assistant', 'session'];
21
+ function isCurrentPage(page) {
22
+ return PAGES.includes(page);
23
+ }
24
+ function useCurrentPage(page) {
25
+ const { search } = (0, react_router_dom_1.useLocation)();
26
+ const { page: pageParam, assistantId, sessionId, } = (0, react_1.useMemo)(() => (0, ufo_1.getQuery)(search), [search]);
27
+ const navigate = useNavigateWithQuery();
28
+ const currentPage = isCurrentPage(pageParam) ? pageParam : 'assistant';
29
+ if (page && page !== currentPage)
30
+ throw new Error('Invalid page state');
31
+ if (currentPage === 'assistant' && assistantId)
32
+ return { page: currentPage, assistantId, navigate };
33
+ if (currentPage === 'session' && assistantId && sessionId)
34
+ return { page: currentPage, assistantId, sessionId, navigate };
35
+ throw new Error('Not Found: missing required query');
36
+ }
37
+ exports.useCurrentPage = useCurrentPage;
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useSubscribeLink = void 0;
4
+ const ufo_1 = require("ufo");
5
+ const session_1 = require("../../../session");
6
+ const utils_1 = require("../../../utils");
7
+ const constants_1 = require("../constants");
8
+ const assistant_1 = require("../state/assistant");
9
+ const subscription_1 = require("../state/subscription");
10
+ function useSubscribeLink({ assistantId }) {
11
+ var _a, _b, _c;
12
+ const [, state] = (0, subscription_1.useSubscriptionState)({ aid: assistantId });
13
+ const [assistant] = (0, assistant_1.useAssistantState)({ assistantId });
14
+ const { session } = (0, session_1.useSessionContext)();
15
+ const requireSubscribe = ((_b = (_a = assistant.release) === null || _a === void 0 ? void 0 : _a.payment) === null || _b === void 0 ? void 0 : _b.enable) && !state.subscription;
16
+ const subscribeLink = requireSubscribe && session.user && ((_c = state.release) === null || _c === void 0 ? void 0 : _c.paymentLinkId)
17
+ ? getSubscribeLink({
18
+ aid: assistantId,
19
+ userId: session.user.did,
20
+ paymentLinkId: state.release.paymentLinkId,
21
+ })
22
+ : undefined;
23
+ return {
24
+ requireSubscribe,
25
+ subscribeLink,
26
+ };
27
+ }
28
+ exports.useSubscribeLink = useSubscribeLink;
29
+ function getSubscribeLink({ aid, userId, paymentLinkId }) {
30
+ return (0, ufo_1.withQuery)((0, ufo_1.joinURL)('/', (0, utils_1.getComponentMountPoint)(constants_1.PAYMENT_KIT_DID), '/checkout/pay', paymentLinkId), {
31
+ 'metadata.aid': aid,
32
+ 'metadata.userId': userId,
33
+ redirect: window.location.href,
34
+ });
35
+ }