@blocklet/pages-kit 0.2.286 → 0.2.288

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/lib/cjs/builtin/async/ai-runtime/api/assistant.js +26 -0
  2. package/lib/cjs/builtin/async/ai-runtime/api/dataset.js +127 -0
  3. package/lib/cjs/builtin/async/ai-runtime/api/message.js +33 -0
  4. package/lib/cjs/builtin/async/ai-runtime/api/request.js +55 -0
  5. package/lib/cjs/builtin/async/ai-runtime/api/session.js +121 -0
  6. package/lib/cjs/builtin/async/ai-runtime/api/subscription.js +32 -0
  7. package/lib/cjs/builtin/async/ai-runtime/components/ActionButton.js +63 -0
  8. package/lib/cjs/builtin/async/ai-runtime/components/GlobalLoading.js +24 -0
  9. package/lib/cjs/builtin/async/ai-runtime/components/LoadingButton.js +40 -0
  10. package/lib/cjs/builtin/async/ai-runtime/components/LoadingListItemButton.js +49 -0
  11. package/lib/cjs/builtin/async/ai-runtime/components/MarkdownRenderer.js +156 -0
  12. package/lib/cjs/builtin/async/ai-runtime/components/MenuButton.js +43 -0
  13. package/lib/cjs/builtin/async/ai-runtime/components/PoweredBy.js +30 -0
  14. package/lib/cjs/builtin/async/ai-runtime/components/RuntimeProvider.js +22 -0
  15. package/lib/cjs/builtin/async/ai-runtime/components/ScrollView.js +109 -0
  16. package/lib/cjs/builtin/async/ai-runtime/components/SocialShare.js +102 -0
  17. package/lib/cjs/builtin/async/ai-runtime/components/ThemeProvider.js +193 -0
  18. package/lib/cjs/builtin/async/ai-runtime/components/collection/CollectionEditDialog.js +92 -0
  19. package/lib/cjs/builtin/async/ai-runtime/components/collection/CollectionListView.js +197 -0
  20. package/lib/cjs/builtin/async/ai-runtime/components/collection/CollectionView.js +122 -0
  21. package/lib/cjs/builtin/async/ai-runtime/components/collection/DocumentListView.js +152 -0
  22. package/lib/cjs/builtin/async/ai-runtime/components/collection/DocumentView.js +135 -0
  23. package/lib/cjs/builtin/async/ai-runtime/components/common/ChatBot.js +104 -0
  24. package/lib/cjs/builtin/async/ai-runtime/components/common/MessageMetadataRenderer.js +21 -0
  25. package/lib/cjs/builtin/async/ai-runtime/components/common/MessageSuggestedQuestions.js +35 -0
  26. package/lib/cjs/builtin/async/ai-runtime/components/common/index.js +12 -0
  27. package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterForm.js +89 -0
  28. package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterFormDialog.js +66 -0
  29. package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterFormFields.js +57 -0
  30. package/lib/cjs/builtin/async/ai-runtime/components/form/QuestionField.js +44 -0
  31. package/lib/cjs/builtin/async/ai-runtime/components/form/SettingButton.js +81 -0
  32. package/lib/cjs/builtin/async/ai-runtime/components/lottie/index.js +34 -0
  33. package/lib/cjs/builtin/async/ai-runtime/components/message/MessageActions.js +38 -0
  34. package/lib/cjs/builtin/async/ai-runtime/components/message/MessageErrorView.js +30 -0
  35. package/lib/cjs/builtin/async/ai-runtime/components/message/MessageItemView.js +129 -0
  36. package/lib/cjs/builtin/async/ai-runtime/components/message/MessageListView.js +47 -0
  37. package/lib/cjs/builtin/async/ai-runtime/components/message/ReferenceLinks.js +11 -0
  38. package/lib/cjs/builtin/async/ai-runtime/components/parameters/LanguageField.js +55 -0
  39. package/lib/cjs/builtin/async/ai-runtime/components/parameters/NumberField.js +21 -0
  40. package/lib/cjs/builtin/async/ai-runtime/components/parameters/SelectField.js +24 -0
  41. package/lib/cjs/builtin/async/ai-runtime/components/parameters/StringField.js +21 -0
  42. package/lib/cjs/builtin/async/ai-runtime/components/parameters/index.js +37 -0
  43. package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/InitialForm.js +111 -0
  44. package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHeader.js +60 -0
  45. package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +52 -0
  46. package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/index.js +28 -0
  47. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +120 -0
  48. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormHeader.js +22 -0
  49. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.js +72 -0
  50. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormSubmit.js +31 -0
  51. package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/index.js +22 -0
  52. package/lib/cjs/builtin/async/ai-runtime/components/session/CheckSession.js +65 -0
  53. package/lib/cjs/builtin/async/ai-runtime/components/session/SessionListView.js +88 -0
  54. package/lib/cjs/builtin/async/ai-runtime/constants.js +5 -0
  55. package/lib/cjs/builtin/async/ai-runtime/error.js +10 -0
  56. package/lib/cjs/builtin/async/ai-runtime/hooks/header.js +32 -0
  57. package/lib/cjs/builtin/async/ai-runtime/hooks/navigate.js +38 -0
  58. package/lib/cjs/builtin/async/ai-runtime/hooks/subscribe.js +35 -0
  59. package/lib/cjs/builtin/async/ai-runtime/hooks/useAsync.js +32 -0
  60. package/lib/cjs/builtin/async/ai-runtime/index.js +81 -0
  61. package/lib/cjs/builtin/async/ai-runtime/locales/index.js +147 -0
  62. package/lib/cjs/builtin/async/ai-runtime/state/assistant.js +59 -0
  63. package/lib/cjs/builtin/async/ai-runtime/state/index.js +423 -0
  64. package/lib/cjs/builtin/async/ai-runtime/state/loading.js +39 -0
  65. package/lib/cjs/builtin/async/ai-runtime/state/session.js +217 -0
  66. package/lib/cjs/builtin/async/ai-runtime/state/subscription.js +52 -0
  67. package/lib/cjs/builtin/async/ai-runtime/utils.js +49 -0
  68. package/lib/cjs/builtin/async/react-scroll-to-bottom.js +1 -1
  69. package/lib/cjs/utils/builtin.js +1 -0
  70. package/lib/cjs/utils/inject-global-components.js +2 -0
  71. package/lib/esm/builtin/async/ai-runtime/api/assistant.js +22 -0
  72. package/lib/esm/builtin/async/ai-runtime/api/dataset.js +113 -0
  73. package/lib/esm/builtin/async/ai-runtime/api/message.js +28 -0
  74. package/lib/esm/builtin/async/ai-runtime/api/request.js +51 -0
  75. package/lib/esm/builtin/async/ai-runtime/api/session.js +112 -0
  76. package/lib/esm/builtin/async/ai-runtime/api/subscription.js +27 -0
  77. package/lib/esm/builtin/async/ai-runtime/components/ActionButton.js +56 -0
  78. package/lib/esm/builtin/async/ai-runtime/components/GlobalLoading.js +21 -0
  79. package/lib/esm/builtin/async/ai-runtime/components/LoadingButton.js +38 -0
  80. package/lib/esm/builtin/async/ai-runtime/components/LoadingListItemButton.js +46 -0
  81. package/lib/esm/builtin/async/ai-runtime/components/MarkdownRenderer.js +129 -0
  82. package/lib/esm/builtin/async/ai-runtime/components/MenuButton.js +40 -0
  83. package/lib/esm/builtin/async/ai-runtime/components/PoweredBy.js +27 -0
  84. package/lib/esm/builtin/async/ai-runtime/components/RuntimeProvider.js +16 -0
  85. package/lib/esm/builtin/async/ai-runtime/components/ScrollView.js +101 -0
  86. package/lib/esm/builtin/async/ai-runtime/components/SocialShare.js +93 -0
  87. package/lib/esm/builtin/async/ai-runtime/components/ThemeProvider.js +190 -0
  88. package/lib/esm/builtin/async/ai-runtime/components/collection/CollectionEditDialog.js +92 -0
  89. package/lib/esm/builtin/async/ai-runtime/components/collection/CollectionListView.js +197 -0
  90. package/lib/esm/builtin/async/ai-runtime/components/collection/CollectionView.js +122 -0
  91. package/lib/esm/builtin/async/ai-runtime/components/collection/DocumentListView.js +152 -0
  92. package/lib/esm/builtin/async/ai-runtime/components/collection/DocumentView.js +135 -0
  93. package/lib/esm/builtin/async/ai-runtime/components/common/ChatBot.js +98 -0
  94. package/lib/esm/builtin/async/ai-runtime/components/common/MessageMetadataRenderer.js +15 -0
  95. package/lib/esm/builtin/async/ai-runtime/components/common/MessageSuggestedQuestions.js +30 -0
  96. package/lib/esm/builtin/async/ai-runtime/components/common/index.js +3 -0
  97. package/lib/esm/builtin/async/ai-runtime/components/form/ParameterForm.js +60 -0
  98. package/lib/esm/builtin/async/ai-runtime/components/form/ParameterFormDialog.js +59 -0
  99. package/lib/esm/builtin/async/ai-runtime/components/form/ParameterFormFields.js +50 -0
  100. package/lib/esm/builtin/async/ai-runtime/components/form/QuestionField.js +38 -0
  101. package/lib/esm/builtin/async/ai-runtime/components/form/SettingButton.js +75 -0
  102. package/lib/esm/builtin/async/ai-runtime/components/lottie/index.js +8 -0
  103. package/lib/esm/builtin/async/ai-runtime/components/message/MessageActions.js +35 -0
  104. package/lib/esm/builtin/async/ai-runtime/components/message/MessageErrorView.js +24 -0
  105. package/lib/esm/builtin/async/ai-runtime/components/message/MessageItemView.js +100 -0
  106. package/lib/esm/builtin/async/ai-runtime/components/message/MessageListView.js +41 -0
  107. package/lib/esm/builtin/async/ai-runtime/components/message/ReferenceLinks.js +8 -0
  108. package/lib/esm/builtin/async/ai-runtime/components/parameters/LanguageField.js +53 -0
  109. package/lib/esm/builtin/async/ai-runtime/components/parameters/NumberField.js +19 -0
  110. package/lib/esm/builtin/async/ai-runtime/components/parameters/SelectField.js +22 -0
  111. package/lib/esm/builtin/async/ai-runtime/components/parameters/StringField.js +19 -0
  112. package/lib/esm/builtin/async/ai-runtime/components/parameters/index.js +31 -0
  113. package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/InitialForm.js +103 -0
  114. package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHeader.js +34 -0
  115. package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +46 -0
  116. package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/index.js +22 -0
  117. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +114 -0
  118. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormHeader.js +19 -0
  119. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.js +66 -0
  120. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormSubmit.js +25 -0
  121. package/lib/esm/builtin/async/ai-runtime/components/runtime-form/index.js +16 -0
  122. package/lib/esm/builtin/async/ai-runtime/components/session/CheckSession.js +59 -0
  123. package/lib/esm/builtin/async/ai-runtime/components/session/SessionListView.js +88 -0
  124. package/lib/esm/builtin/async/ai-runtime/constants.js +2 -0
  125. package/lib/esm/builtin/async/ai-runtime/error.js +6 -0
  126. package/lib/esm/builtin/async/ai-runtime/hooks/header.js +25 -0
  127. package/lib/esm/builtin/async/ai-runtime/hooks/navigate.js +32 -0
  128. package/lib/esm/builtin/async/ai-runtime/hooks/subscribe.js +31 -0
  129. package/lib/esm/builtin/async/ai-runtime/hooks/useAsync.js +29 -0
  130. package/lib/esm/builtin/async/ai-runtime/index.js +72 -0
  131. package/lib/esm/builtin/async/ai-runtime/locales/index.js +144 -0
  132. package/lib/esm/builtin/async/ai-runtime/state/assistant.js +54 -0
  133. package/lib/esm/builtin/async/ai-runtime/state/index.js +423 -0
  134. package/lib/esm/builtin/async/ai-runtime/state/loading.js +36 -0
  135. package/lib/esm/builtin/async/ai-runtime/state/session.js +209 -0
  136. package/lib/esm/builtin/async/ai-runtime/state/subscription.js +47 -0
  137. package/lib/esm/builtin/async/ai-runtime/utils.js +42 -0
  138. package/lib/esm/builtin/async/react-scroll-to-bottom.js +1 -1
  139. package/lib/esm/utils/builtin.js +1 -0
  140. package/lib/esm/utils/inject-global-components.js +2 -0
  141. package/lib/types/builtin/async/ai-runtime/api/assistant.d.ts +18 -0
  142. package/lib/types/builtin/async/ai-runtime/api/dataset.d.ts +39 -0
  143. package/lib/types/builtin/async/ai-runtime/api/message.d.ts +39 -0
  144. package/lib/types/builtin/async/ai-runtime/api/request.d.ts +5 -0
  145. package/lib/types/builtin/async/ai-runtime/api/session.d.ts +54 -0
  146. package/lib/types/builtin/async/ai-runtime/api/subscription.d.ts +15 -0
  147. package/lib/types/builtin/async/ai-runtime/components/ActionButton.d.ts +11 -0
  148. package/lib/types/builtin/async/ai-runtime/components/GlobalLoading.d.ts +2 -0
  149. package/lib/types/builtin/async/ai-runtime/components/LoadingButton.d.ts +3 -0
  150. package/lib/types/builtin/async/ai-runtime/components/LoadingListItemButton.d.ts +5 -0
  151. package/lib/types/builtin/async/ai-runtime/components/MarkdownRenderer.d.ts +2 -0
  152. package/lib/types/builtin/async/ai-runtime/components/MenuButton.d.ts +9 -0
  153. package/lib/types/builtin/async/ai-runtime/components/PoweredBy.d.ts +4 -0
  154. package/lib/types/builtin/async/ai-runtime/components/RuntimeProvider.d.ts +4 -0
  155. package/lib/types/builtin/async/ai-runtime/components/ScrollView.d.ts +61 -0
  156. package/lib/types/builtin/async/ai-runtime/components/SocialShare.d.ts +17 -0
  157. package/lib/types/builtin/async/ai-runtime/components/ThemeProvider.d.ts +6 -0
  158. package/lib/types/builtin/async/ai-runtime/components/collection/CollectionEditDialog.d.ts +0 -0
  159. package/lib/types/builtin/async/ai-runtime/components/collection/CollectionListView.d.ts +0 -0
  160. package/lib/types/builtin/async/ai-runtime/components/collection/CollectionView.d.ts +0 -0
  161. package/lib/types/builtin/async/ai-runtime/components/collection/DocumentListView.d.ts +0 -0
  162. package/lib/types/builtin/async/ai-runtime/components/collection/DocumentView.d.ts +0 -0
  163. package/lib/types/builtin/async/ai-runtime/components/common/ChatBot.d.ts +13 -0
  164. package/lib/types/builtin/async/ai-runtime/components/common/MessageMetadataRenderer.d.ts +4 -0
  165. package/lib/types/builtin/async/ai-runtime/components/common/MessageSuggestedQuestions.d.ts +7 -0
  166. package/lib/types/builtin/async/ai-runtime/components/common/index.d.ts +3 -0
  167. package/lib/types/builtin/async/ai-runtime/components/form/ParameterForm.d.ts +12 -0
  168. package/lib/types/builtin/async/ai-runtime/components/form/ParameterFormDialog.d.ts +28 -0
  169. package/lib/types/builtin/async/ai-runtime/components/form/ParameterFormFields.d.ts +11 -0
  170. package/lib/types/builtin/async/ai-runtime/components/form/QuestionField.d.ts +13 -0
  171. package/lib/types/builtin/async/ai-runtime/components/form/SettingButton.d.ts +6 -0
  172. package/lib/types/builtin/async/ai-runtime/components/lottie/index.d.ts +4 -0
  173. package/lib/types/builtin/async/ai-runtime/components/message/MessageActions.d.ts +4 -0
  174. package/lib/types/builtin/async/ai-runtime/components/message/MessageErrorView.d.ts +6 -0
  175. package/lib/types/builtin/async/ai-runtime/components/message/MessageItemView.d.ts +8 -0
  176. package/lib/types/builtin/async/ai-runtime/components/message/MessageListView.d.ts +5 -0
  177. package/lib/types/builtin/async/ai-runtime/components/message/ReferenceLinks.d.ts +4 -0
  178. package/lib/types/builtin/async/ai-runtime/components/parameters/LanguageField.d.ts +9 -0
  179. package/lib/types/builtin/async/ai-runtime/components/parameters/NumberField.d.ts +9 -0
  180. package/lib/types/builtin/async/ai-runtime/components/parameters/SelectField.d.ts +9 -0
  181. package/lib/types/builtin/async/ai-runtime/components/parameters/StringField.d.ts +9 -0
  182. package/lib/types/builtin/async/ai-runtime/components/parameters/index.d.ts +7 -0
  183. package/lib/types/builtin/async/ai-runtime/components/runtime-chat/InitialForm.d.ts +10 -0
  184. package/lib/types/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHeader.d.ts +5 -0
  185. package/lib/types/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.d.ts +6 -0
  186. package/lib/types/builtin/async/ai-runtime/components/runtime-chat/index.d.ts +5 -0
  187. package/lib/types/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.d.ts +5 -0
  188. package/lib/types/builtin/async/ai-runtime/components/runtime-form/RuntimeFormHeader.d.ts +5 -0
  189. package/lib/types/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.d.ts +5 -0
  190. package/lib/types/builtin/async/ai-runtime/components/runtime-form/RuntimeFormSubmit.d.ts +5 -0
  191. package/lib/types/builtin/async/ai-runtime/components/runtime-form/index.d.ts +4 -0
  192. package/lib/types/builtin/async/ai-runtime/components/session/CheckSession.d.ts +8 -0
  193. package/lib/types/builtin/async/ai-runtime/components/session/SessionListView.d.ts +0 -0
  194. package/lib/types/builtin/async/ai-runtime/constants.d.ts +2 -0
  195. package/lib/types/builtin/async/ai-runtime/error.d.ts +4 -0
  196. package/lib/types/builtin/async/ai-runtime/hooks/header.d.ts +4 -0
  197. package/lib/types/builtin/async/ai-runtime/hooks/navigate.d.ts +25 -0
  198. package/lib/types/builtin/async/ai-runtime/hooks/subscribe.d.ts +6 -0
  199. package/lib/types/builtin/async/ai-runtime/hooks/useAsync.d.ts +1 -0
  200. package/lib/types/builtin/async/ai-runtime/index.d.ts +17 -0
  201. package/lib/types/builtin/async/ai-runtime/locales/index.d.ts +126 -0
  202. package/lib/types/builtin/async/ai-runtime/state/assistant.d.ts +17 -0
  203. package/lib/types/builtin/async/ai-runtime/state/index.d.ts +0 -0
  204. package/lib/types/builtin/async/ai-runtime/state/loading.d.ts +10 -0
  205. package/lib/types/builtin/async/ai-runtime/state/session.d.ts +40 -0
  206. package/lib/types/builtin/async/ai-runtime/state/subscription.d.ts +15 -0
  207. package/lib/types/builtin/async/ai-runtime/utils.d.ts +20 -0
  208. package/lib/types/builtin/async/react-scroll-to-bottom.d.ts +3 -2
  209. package/lib/types/builtin/page/header.d.ts +1 -6
  210. package/lib/types/builtin/session.d.ts +11 -1
  211. package/lib/types/components/CustomComponentRenderer/state.d.ts +1 -116
  212. package/lib/types/utils/builtin.d.ts +1 -0
  213. package/package.json +14 -9
  214. package/tsconfig.json +5 -1
@@ -0,0 +1,111 @@
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
+ exports.EntryListView = void 0;
27
+ const jsx_runtime_1 = require("react/jsx-runtime");
28
+ const material_1 = require("@mui/material");
29
+ const omit_1 = __importDefault(require("lodash/omit"));
30
+ const react_1 = require("react");
31
+ const session_1 = require("../../../../session");
32
+ const session_2 = require("../../api/session");
33
+ const assistant_1 = require("../../state/assistant");
34
+ const loading_1 = require("../../state/loading");
35
+ const session_3 = require("../../state/session");
36
+ const MessageSuggestedQuestions_1 = require("../common/MessageSuggestedQuestions");
37
+ const ParameterForm_1 = __importDefault(require("../form/ParameterForm"));
38
+ const MessageItemView_1 = __importDefault(require("../message/MessageItemView"));
39
+ const PoweredBy_1 = __importDefault(require("../PoweredBy"));
40
+ function InitialForm({ page }) {
41
+ var _a;
42
+ const { assistantId } = page;
43
+ const { session: authSession } = (0, session_1.useSessionContext)();
44
+ const [assistant] = (0, assistant_1.useAssistantState)({ assistantId: page.assistantId });
45
+ const { parameters } = assistant;
46
+ const [error, setError] = (0, react_1.useState)();
47
+ const isChat = parameters === null || parameters === void 0 ? void 0 : parameters.some((i) => i.key === 'question');
48
+ const opener = (0, react_1.useMemo)(() => {
49
+ var _a;
50
+ const { openerMessage } = (_a = assistant.release) !== null && _a !== void 0 ? _a : {};
51
+ if (openerMessage) {
52
+ return {
53
+ taskId: '',
54
+ sessionId: '',
55
+ createdAt: new Date().toISOString(),
56
+ updatedAt: new Date().toISOString(),
57
+ result: { content: openerMessage },
58
+ };
59
+ }
60
+ return undefined;
61
+ }, [assistant.release]);
62
+ const [creating, setCreating] = (0, react_1.useState)(false);
63
+ const onSubmit = (...args_1) => __awaiter(this, [...args_1], void 0, function* (parameters = {}, entry) {
64
+ if (!authSession.user) {
65
+ yield new Promise((resolve) => {
66
+ authSession.login(() => {
67
+ resolve();
68
+ });
69
+ });
70
+ }
71
+ if (creating)
72
+ return;
73
+ setCreating(true);
74
+ try {
75
+ yield loading_1.globalLoadingState.getState().run(() => __awaiter(this, void 0, void 0, function* () {
76
+ const { created: session } = yield (0, session_2.createSession)({
77
+ assistantId,
78
+ name: parameters.question,
79
+ parameters: (0, omit_1.default)(parameters, isChat ? ['question'] : []),
80
+ entry,
81
+ });
82
+ (0, session_3.createSessionState)({ sessionId: session.id, session }).getState().execute({
83
+ assistantId,
84
+ parameters,
85
+ });
86
+ setError(undefined);
87
+ page.navigate({ page: 'session', assistantId, sessionId: session.id });
88
+ }));
89
+ }
90
+ catch (error) {
91
+ setError(error);
92
+ }
93
+ finally {
94
+ setCreating(false);
95
+ }
96
+ });
97
+ if (authSession.loading)
98
+ return null;
99
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [opener && ((0, jsx_runtime_1.jsx)(material_1.Box, { my: 2, mx: 2, children: (0, jsx_runtime_1.jsx)(MessageItemView_1.default, { assistantId: assistantId, hideAvatar: true, assistant: assistant, message: opener }) })), ((_a = assistant.entries) === null || _a === void 0 ? void 0 : _a.length) && ((0, jsx_runtime_1.jsx)(EntryListView, { assistant: assistant, onEntryClick: (entry) => onSubmit(entry.parameters, { id: entry.id, title: entry.title }), sx: { px: 2 } })), (0, jsx_runtime_1.jsx)(material_1.Box, { flex: 1 }), (0, jsx_runtime_1.jsxs)(material_1.Box, { className: "ai-runtime-form-container", sx: {
100
+ position: 'sticky',
101
+ bottom: 0,
102
+ background: (theme) => `linear-gradient(180deg, ${(0, material_1.alpha)(theme.palette.background.default, 0.1)}, ${(0, material_1.alpha)(theme.palette.background.default, 1)} 16px)`,
103
+ }, children: [(0, jsx_runtime_1.jsx)(ParameterForm_1.default, { assistant: assistant, onSubmit: onSubmit }), error && (0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "error", children: error.message }), (0, jsx_runtime_1.jsx)(PoweredBy_1.default, { assistantId: page.assistantId, sx: { my: 1, px: 2 } })] })] }));
104
+ }
105
+ exports.default = InitialForm;
106
+ function EntryListView(_a) {
107
+ var _b;
108
+ var { assistant, onEntryClick } = _a, props = __rest(_a, ["assistant", "onEntryClick"]);
109
+ return ((0, jsx_runtime_1.jsx)(material_1.Stack, Object.assign({ gap: 1, alignItems: "flex-start" }, props, { children: (_b = assistant.entries) === null || _b === void 0 ? void 0 : _b.map((entry) => entry.title && ((0, jsx_runtime_1.jsx)(MessageSuggestedQuestions_1.MessageSuggestedQuestion, { onClick: () => onEntryClick === null || onEntryClick === void 0 ? void 0 : onEntryClick(entry), children: entry.title }, entry.title))) })));
110
+ }
111
+ exports.EntryListView = EntryListView;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __rest = (this && this.__rest) || function (s, e) {
26
+ var t = {};
27
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
28
+ t[p] = s[p];
29
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
30
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
31
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
32
+ t[p[i]] = s[p[i]];
33
+ }
34
+ return t;
35
+ };
36
+ Object.defineProperty(exports, "__esModule", { value: true });
37
+ const jsx_runtime_1 = require("react/jsx-runtime");
38
+ const material_1 = require("@mui/material");
39
+ const react_wrap_balancer_1 = __importStar(require("react-wrap-balancer"));
40
+ const ux_1 = require("../../../../arcblock/ux");
41
+ function RuntimeChatHeader(_a) {
42
+ var _b, _c, _d, _e;
43
+ var { assistant } = _a, props = __rest(_a, ["assistant"]);
44
+ return ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: "ai-chat-header", pt: 10 }, props, { children: (0, jsx_runtime_1.jsxs)(react_wrap_balancer_1.Provider, { children: [(0, jsx_runtime_1.jsx)(material_1.Box, { sx: { display: 'flex', justifyContent: 'center', alignItems: 'center' }, children: (0, jsx_runtime_1.jsx)(material_1.Box, { component: ux_1.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 } }) }), (0, jsx_runtime_1.jsx)(material_1.Typography, { component: "h1", sx: {
45
+ fontWeight: 'bold',
46
+ fontSize: 18,
47
+ mt: 1,
48
+ lineHeight: '28px',
49
+ textAlign: 'center',
50
+ color: '#010714',
51
+ }, children: (0, jsx_runtime_1.jsxs)(react_wrap_balancer_1.default, { 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)] }) }), (0, jsx_runtime_1.jsx)(material_1.Typography, { component: "p", sx: {
52
+ mt: 2.5,
53
+ fontSize: 16,
54
+ lineHeight: '28px',
55
+ textAlign: 'center',
56
+ whiteSpace: 'pre-wrap',
57
+ color: '#465566',
58
+ }, children: (0, jsx_runtime_1.jsxs)(react_wrap_balancer_1.default, { 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)] }) })] }) })));
59
+ }
60
+ exports.default = RuntimeChatHeader;
@@ -0,0 +1,52 @@
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 MessageListView_1 = __importDefault(require("../message/MessageListView"));
15
+ const PoweredBy_1 = __importDefault(require("../PoweredBy"));
16
+ const ScrollView_1 = require("../ScrollView");
17
+ const InitialForm_1 = require("./InitialForm");
18
+ function RuntimeChatSession({ page }) {
19
+ var _a, _b, _c, _d, _e, _f, _g, _h;
20
+ const [session, state] = (0, session_1.useSessionState)({ sessionId: page.sessionId, required: true });
21
+ const [assistant] = (0, assistant_1.useAssistantState)({ assistantId: page.assistantId });
22
+ const lastMessage = (_a = state.messages) === null || _a === void 0 ? void 0 : _a.slice(-1)[0];
23
+ 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];
24
+ const scrollToBottom = (0, ScrollView_1.useScrollToBottomModule)().useScrollToBottom();
25
+ const [error, setError] = (0, react_1.useState)();
26
+ const onSubmit = (parameters) => {
27
+ scrollToBottom({ behavior: 'smooth' });
28
+ if (!session)
29
+ return;
30
+ state
31
+ .execute({
32
+ assistantId: page.assistantId,
33
+ parameters: Object.assign({}, parameters),
34
+ })
35
+ .then(() => {
36
+ setError(undefined);
37
+ })
38
+ .catch((error) => {
39
+ setError(error);
40
+ });
41
+ };
42
+ 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, px: 2, assistantId: page.assistantId, sessionId: page.sessionId }), (0, jsx_runtime_1.jsx)(material_1.Box, { ml: 6.5, mr: 2.5, mt: -4, px: 2, children: (suggestedQuestions === null || suggestedQuestions === void 0 ? void 0 : suggestedQuestions.length) ? ((0, jsx_runtime_1.jsx)(common_1.MessageSuggestedQuestions, { dataSource: suggestedQuestions, onClick: (item) => {
43
+ onSubmit(Object.assign(Object.assign({}, lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters), { question: item.question }));
44
+ } })) : !((_e = state.messages) === null || _e === void 0 ? void 0 : _e.length) && ((_f = assistant.entries) === null || _f === void 0 ? void 0 : _f.length) ? ((0, jsx_runtime_1.jsx)(InitialForm_1.EntryListView, { assistant: assistant, onEntryClick: (entry) => onSubmit(Object.assign(Object.assign({}, lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters), entry.parameters)) })) : null }), (0, jsx_runtime_1.jsx)(material_1.Box, { flex: 1 }), error && ((0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "error", sx: { mb: 1, mx: 2 }, children: error.message })), (0, jsx_runtime_1.jsxs)(material_1.Box, { className: "ai-runtime-form-container", sx: {
45
+ pt: 2,
46
+ position: 'sticky',
47
+ bottom: 0,
48
+ // 从上透明到白色 0.72 的径向渐变
49
+ background: (theme) => `linear-gradient(180deg, ${(0, material_1.alpha)(theme.palette.background.default, 0.1)}, ${(0, material_1.alpha)(theme.palette.background.default, 1)} 16px)`,
50
+ }, children: [(0, jsx_runtime_1.jsx)(ParameterForm_1.default, { sessionId: page.sessionId, defaultValues: lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters, assistant: assistant, onSubmit: onSubmit, isSubmitting: state.running, submitButtonTitle: (_h = (_g = assistant.release) === null || _g === void 0 ? void 0 : _g.submitButton) === null || _h === void 0 ? void 0 : _h.title }), (0, jsx_runtime_1.jsx)(PoweredBy_1.default, { assistantId: page.assistantId, sx: { my: 0.5, px: 2 } })] })] }));
51
+ }
52
+ exports.default = RuntimeChatSession;
@@ -0,0 +1,28 @@
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 material_1 = require("@mui/material");
19
+ const assistant_1 = require("../../state/assistant");
20
+ const InitialForm_1 = __importDefault(require("./InitialForm"));
21
+ const RuntimeChatHeader_1 = __importDefault(require("./RuntimeChatHeader"));
22
+ const RuntimeChatSession_1 = __importDefault(require("./RuntimeChatSession"));
23
+ function RuntimeChat(_a) {
24
+ var { page } = _a, props = __rest(_a, ["page"]);
25
+ const [assistant] = (0, assistant_1.useAssistantState)({ assistantId: page.assistantId });
26
+ return ((0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ flexGrow: 1, width: "100%", height: "100%", maxWidth: 750, mx: "auto", justifyContent: page.page === 'session' ? 'space-between' : 'unset' }, props, { children: [(0, jsx_runtime_1.jsx)(RuntimeChatHeader_1.default, { assistant: assistant, sx: { mx: 2 } }), page.page === 'session' ? (0, jsx_runtime_1.jsx)(RuntimeChatSession_1.default, { page: page }) : (0, jsx_runtime_1.jsx)(InitialForm_1.default, { page: page })] })));
27
+ }
28
+ exports.default = RuntimeChat;
@@ -0,0 +1,120 @@
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 loading_1 = require("../../state/loading");
36
+ const session_3 = require("../../state/session");
37
+ const ParameterFormFields_1 = __importDefault(require("../form/ParameterFormFields"));
38
+ const RuntimeFormSubmit_1 = __importDefault(require("./RuntimeFormSubmit"));
39
+ function RuntimeFormForms(_a) {
40
+ var _b, _c, _d;
41
+ var { page } = _a, props = __rest(_a, ["page"]);
42
+ const { t } = (0, locale_1.useLocaleContext)();
43
+ const [agent] = (0, assistant_1.useAssistantState)({ assistantId: page.assistantId });
44
+ const lastParameters = (0, react_1.useMemo)(() => {
45
+ var _a;
46
+ if (page.sessionId) {
47
+ const { session, messages = [] } = (0, session_3.createSessionState)({ sessionId: page.sessionId }).getState();
48
+ const lastMessage = messages[messages.length - 1];
49
+ 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;
50
+ }
51
+ return undefined;
52
+ }, [page.sessionId]);
53
+ const defaultForm = (0, react_1.useMemo)(() => {
54
+ var _a, _b;
55
+ return Object.fromEntries((_b = (_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.map((parameter) => [
56
+ parameter.key,
57
+ (lastParameters === null || lastParameters === void 0 ? void 0 : lastParameters[parameter.key]) || parameter.defaultValue,
58
+ ])) !== null && _b !== void 0 ? _b : []);
59
+ }, [agent.parameters, lastParameters]);
60
+ const form = (0, react_hook_form_1.useForm)({ defaultValues: defaultForm });
61
+ const [error, setError] = (0, react_1.useState)();
62
+ const { session } = (0, session_1.useSessionContext)();
63
+ const [submitting, setSubmitting] = (0, react_1.useState)(false);
64
+ (0, react_1.useEffect)(() => {
65
+ form.reset(defaultForm);
66
+ }, [defaultForm]);
67
+ const onSubmit = (parameters) => __awaiter(this, void 0, void 0, function* () {
68
+ try {
69
+ setSubmitting(true);
70
+ let { sessionId } = page;
71
+ if (!sessionId) {
72
+ const session = yield loading_1.globalLoadingState.getState().run(() => __awaiter(this, void 0, void 0, function* () {
73
+ const { created: session } = yield (0, session_2.createSession)({ assistantId: page.assistantId, parameters });
74
+ yield (0, session_3.createSessionState)({ sessionId: session.id }).getState().load();
75
+ return session;
76
+ }));
77
+ sessionId = session.id;
78
+ page.navigate({ page: 'session', assistantId: page.assistantId, sessionId: session.id });
79
+ }
80
+ const sid = sessionId;
81
+ yield new Promise((resolve, reject) => {
82
+ setTimeout(() => {
83
+ const session = (0, session_3.createSessionState)({ sessionId: sid }).getState();
84
+ session.execute({ assistantId: page.assistantId, parameters }).then(resolve).catch(reject);
85
+ });
86
+ });
87
+ }
88
+ catch (error) {
89
+ setError(error);
90
+ throw error;
91
+ }
92
+ finally {
93
+ setSubmitting(false);
94
+ }
95
+ });
96
+ const handleSubmit = (e) => __awaiter(this, void 0, void 0, function* () {
97
+ e.preventDefault();
98
+ if (!session.user) {
99
+ yield new Promise((resolve) => {
100
+ session.login(() => resolve());
101
+ });
102
+ }
103
+ return form.handleSubmit(onSubmit)(e);
104
+ });
105
+ const openerMessage = (_b = agent.release) === null || _b === void 0 ? void 0 : _b.openerMessage;
106
+ 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: {
107
+ gap: 1,
108
+ position: 'sticky',
109
+ bottom: 0,
110
+ pb: 1,
111
+ pt: 1,
112
+ // 从上透明到白色 0.72 的径向渐变
113
+ 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%)`,
114
+ }, 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: submitting, sx: {
115
+ borderRadius: 100,
116
+ height: 44,
117
+ background: 'linear-gradient(90deg, rgb(69, 228, 250) 0%, rgb(138, 69, 250) 52.08%, rgb(250, 69, 188) 100%)',
118
+ }, children: ((_d = (_c = agent.release) === null || _c === void 0 ? void 0 : _c.submitButton) === null || _d === void 0 ? void 0 : _d.title) || t('submit') })] }) })] })));
119
+ }
120
+ 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,65 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __importDefault = (this && this.__importDefault) || function (mod) {
12
+ return (mod && mod.__esModule) ? mod : { "default": mod };
13
+ };
14
+ Object.defineProperty(exports, "__esModule", { value: true });
15
+ const react_1 = require("react");
16
+ const session_1 = require("../../api/session");
17
+ const useAsync_1 = __importDefault(require("../../hooks/useAsync"));
18
+ const assistant_1 = require("../../state/assistant");
19
+ const loading_1 = require("../../state/loading");
20
+ const session_2 = require("../../state/session");
21
+ const utils_1 = require("../../utils");
22
+ function CheckSession({ cacheId, page, autoCreateSession, children, }) {
23
+ const { assistantId, sessionId } = page;
24
+ (0, assistant_1.useAssistantState)({ assistantId });
25
+ const result = (0, useAsync_1.default)(() => {
26
+ if (sessionId && (0, session_2.createSessionState)({ sessionId }).getState().session)
27
+ return undefined;
28
+ return loading_1.globalLoadingState.getState().run(() => __awaiter(this, void 0, void 0, function* () {
29
+ var _a;
30
+ if (!sessionId) {
31
+ try {
32
+ // get the last session or create a new session if `autoCreateSession` is enabled
33
+ const { sessions } = yield (0, session_1.getSessions)((0, utils_1.parseIdentity)(assistantId, { rejectWhenError: true }));
34
+ const session = (_a = sessions[0]) !== null && _a !== void 0 ? _a : (autoCreateSession ? (yield (0, session_1.createSession)({ assistantId })).created : undefined);
35
+ if (session) {
36
+ yield (0, session_2.createSessionState)({ sessionId: session.id, session }).getState().load();
37
+ return [{ page: 'session', assistantId, sessionId: session.id }];
38
+ }
39
+ }
40
+ catch (error) {
41
+ console.error('get first session or auto create a new session error', { error });
42
+ }
43
+ }
44
+ else {
45
+ try {
46
+ const state = (0, session_2.createSessionState)({ sessionId });
47
+ yield state.getState().load();
48
+ }
49
+ catch (error) {
50
+ console.error('load session error', { error });
51
+ return [{ page: 'assistant', assistantId, sessionId: undefined }, { replace: true }];
52
+ }
53
+ }
54
+ return undefined;
55
+ }));
56
+ }, [sessionId, cacheId]);
57
+ (0, react_1.useEffect)(() => {
58
+ if (result)
59
+ page.navigate(...result);
60
+ }, [result, page.navigate]);
61
+ if (result)
62
+ return null;
63
+ return children;
64
+ }
65
+ exports.default = CheckSession;