@blocklet/pages-kit 0.2.286 → 0.2.287
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/builtin/async/ai-runtime/api/assistant.js +26 -0
- package/lib/cjs/builtin/async/ai-runtime/api/dataset.js +127 -0
- package/lib/cjs/builtin/async/ai-runtime/api/message.js +33 -0
- package/lib/cjs/builtin/async/ai-runtime/api/request.js +47 -0
- package/lib/cjs/builtin/async/ai-runtime/api/session.js +121 -0
- package/lib/cjs/builtin/async/ai-runtime/api/subscription.js +32 -0
- package/lib/cjs/builtin/async/ai-runtime/components/ActionButton.js +63 -0
- package/lib/cjs/builtin/async/ai-runtime/components/GlobalLoading.js +60 -0
- package/lib/cjs/builtin/async/ai-runtime/components/LoadingButton.js +40 -0
- package/lib/cjs/builtin/async/ai-runtime/components/LoadingListItemButton.js +51 -0
- package/lib/cjs/builtin/async/ai-runtime/components/MarkdownRenderer.js +156 -0
- package/lib/cjs/builtin/async/ai-runtime/components/MenuButton.js +43 -0
- package/lib/cjs/builtin/async/ai-runtime/components/PoweredBy.js +30 -0
- package/lib/cjs/builtin/async/ai-runtime/components/RuntimeProvider.js +16 -0
- package/lib/cjs/builtin/async/ai-runtime/components/ScrollView.js +109 -0
- package/lib/cjs/builtin/async/ai-runtime/components/SocialShare.js +102 -0
- package/lib/cjs/builtin/async/ai-runtime/components/ThemeProvider.js +193 -0
- package/lib/cjs/builtin/async/ai-runtime/components/collection/CollectionEditDialog.js +92 -0
- package/lib/cjs/builtin/async/ai-runtime/components/collection/CollectionListView.js +197 -0
- package/lib/cjs/builtin/async/ai-runtime/components/collection/CollectionView.js +122 -0
- package/lib/cjs/builtin/async/ai-runtime/components/collection/DocumentListView.js +152 -0
- package/lib/cjs/builtin/async/ai-runtime/components/collection/DocumentView.js +135 -0
- package/lib/cjs/builtin/async/ai-runtime/components/common/ChatBot.js +105 -0
- package/lib/cjs/builtin/async/ai-runtime/components/common/MessageMetadataRenderer.js +21 -0
- package/lib/cjs/builtin/async/ai-runtime/components/common/MessageSuggestedQuestions.js +35 -0
- package/lib/cjs/builtin/async/ai-runtime/components/common/index.js +12 -0
- package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterForm.js +48 -0
- package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterFormDialog.js +66 -0
- package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterFormFields.js +43 -0
- package/lib/cjs/builtin/async/ai-runtime/components/form/QuestionField.js +44 -0
- package/lib/cjs/builtin/async/ai-runtime/components/form/SettingButton.js +76 -0
- package/lib/cjs/builtin/async/ai-runtime/components/layout/index.js +15 -0
- package/lib/cjs/builtin/async/ai-runtime/components/lottie/index.js +34 -0
- package/lib/cjs/builtin/async/ai-runtime/components/message/MessageActions.js +38 -0
- package/lib/cjs/builtin/async/ai-runtime/components/message/MessageErrorView.js +30 -0
- package/lib/cjs/builtin/async/ai-runtime/components/message/MessageItemView.js +134 -0
- package/lib/cjs/builtin/async/ai-runtime/components/message/MessageListView.js +48 -0
- package/lib/cjs/builtin/async/ai-runtime/components/message/ReferenceLinks.js +11 -0
- package/lib/cjs/builtin/async/ai-runtime/components/parameters/LanguageField.js +55 -0
- package/lib/cjs/builtin/async/ai-runtime/components/parameters/NumberField.js +21 -0
- package/lib/cjs/builtin/async/ai-runtime/components/parameters/SelectField.js +24 -0
- package/lib/cjs/builtin/async/ai-runtime/components/parameters/StringField.js +21 -0
- package/lib/cjs/builtin/async/ai-runtime/components/parameters/index.js +37 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/InitialForm.js +94 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHeader.js +48 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHome.js +21 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +67 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/index.js +15 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +103 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormHeader.js +22 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.js +72 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormSubmit.js +31 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/index.js +22 -0
- package/lib/cjs/builtin/async/ai-runtime/components/session/CheckSession.js +62 -0
- package/lib/cjs/builtin/async/ai-runtime/components/session/SessionListView.js +88 -0
- package/lib/cjs/builtin/async/ai-runtime/constants.js +5 -0
- package/lib/cjs/builtin/async/ai-runtime/hooks/header.js +32 -0
- package/lib/cjs/builtin/async/ai-runtime/hooks/navigate.js +37 -0
- package/lib/cjs/builtin/async/ai-runtime/hooks/subscribe.js +35 -0
- package/lib/cjs/builtin/async/ai-runtime/index.js +75 -0
- package/lib/cjs/builtin/async/ai-runtime/locales/index.js +147 -0
- package/lib/cjs/builtin/async/ai-runtime/state/assistant.js +59 -0
- package/lib/cjs/builtin/async/ai-runtime/state/index.js +423 -0
- package/lib/cjs/builtin/async/ai-runtime/state/session.js +217 -0
- package/lib/cjs/builtin/async/ai-runtime/state/subscription.js +52 -0
- package/lib/cjs/builtin/async/ai-runtime/utils.js +49 -0
- package/lib/cjs/builtin/async/react-scroll-to-bottom.js +1 -1
- package/lib/cjs/utils/builtin.js +1 -0
- package/lib/cjs/utils/inject-global-components.js +2 -0
- package/lib/esm/builtin/async/ai-runtime/api/assistant.js +22 -0
- package/lib/esm/builtin/async/ai-runtime/api/dataset.js +113 -0
- package/lib/esm/builtin/async/ai-runtime/api/message.js +28 -0
- package/lib/esm/builtin/async/ai-runtime/api/request.js +43 -0
- package/lib/esm/builtin/async/ai-runtime/api/session.js +112 -0
- package/lib/esm/builtin/async/ai-runtime/api/subscription.js +27 -0
- package/lib/esm/builtin/async/ai-runtime/components/ActionButton.js +56 -0
- package/lib/esm/builtin/async/ai-runtime/components/GlobalLoading.js +56 -0
- package/lib/esm/builtin/async/ai-runtime/components/LoadingButton.js +38 -0
- package/lib/esm/builtin/async/ai-runtime/components/LoadingListItemButton.js +48 -0
- package/lib/esm/builtin/async/ai-runtime/components/MarkdownRenderer.js +129 -0
- package/lib/esm/builtin/async/ai-runtime/components/MenuButton.js +40 -0
- package/lib/esm/builtin/async/ai-runtime/components/PoweredBy.js +27 -0
- package/lib/esm/builtin/async/ai-runtime/components/RuntimeProvider.js +10 -0
- package/lib/esm/builtin/async/ai-runtime/components/ScrollView.js +101 -0
- package/lib/esm/builtin/async/ai-runtime/components/SocialShare.js +93 -0
- package/lib/esm/builtin/async/ai-runtime/components/ThemeProvider.js +190 -0
- package/lib/esm/builtin/async/ai-runtime/components/collection/CollectionEditDialog.js +92 -0
- package/lib/esm/builtin/async/ai-runtime/components/collection/CollectionListView.js +197 -0
- package/lib/esm/builtin/async/ai-runtime/components/collection/CollectionView.js +122 -0
- package/lib/esm/builtin/async/ai-runtime/components/collection/DocumentListView.js +152 -0
- package/lib/esm/builtin/async/ai-runtime/components/collection/DocumentView.js +135 -0
- package/lib/esm/builtin/async/ai-runtime/components/common/ChatBot.js +99 -0
- package/lib/esm/builtin/async/ai-runtime/components/common/MessageMetadataRenderer.js +15 -0
- package/lib/esm/builtin/async/ai-runtime/components/common/MessageSuggestedQuestions.js +30 -0
- package/lib/esm/builtin/async/ai-runtime/components/common/index.js +3 -0
- package/lib/esm/builtin/async/ai-runtime/components/form/ParameterForm.js +42 -0
- package/lib/esm/builtin/async/ai-runtime/components/form/ParameterFormDialog.js +59 -0
- package/lib/esm/builtin/async/ai-runtime/components/form/ParameterFormFields.js +37 -0
- package/lib/esm/builtin/async/ai-runtime/components/form/QuestionField.js +38 -0
- package/lib/esm/builtin/async/ai-runtime/components/form/SettingButton.js +73 -0
- package/lib/esm/builtin/async/ai-runtime/components/layout/index.js +12 -0
- package/lib/esm/builtin/async/ai-runtime/components/lottie/index.js +8 -0
- package/lib/esm/builtin/async/ai-runtime/components/message/MessageActions.js +35 -0
- package/lib/esm/builtin/async/ai-runtime/components/message/MessageErrorView.js +24 -0
- package/lib/esm/builtin/async/ai-runtime/components/message/MessageItemView.js +105 -0
- package/lib/esm/builtin/async/ai-runtime/components/message/MessageListView.js +42 -0
- package/lib/esm/builtin/async/ai-runtime/components/message/ReferenceLinks.js +8 -0
- package/lib/esm/builtin/async/ai-runtime/components/parameters/LanguageField.js +53 -0
- package/lib/esm/builtin/async/ai-runtime/components/parameters/NumberField.js +19 -0
- package/lib/esm/builtin/async/ai-runtime/components/parameters/SelectField.js +22 -0
- package/lib/esm/builtin/async/ai-runtime/components/parameters/StringField.js +19 -0
- package/lib/esm/builtin/async/ai-runtime/components/parameters/index.js +31 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/InitialForm.js +88 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHeader.js +22 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHome.js +15 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +61 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/index.js +9 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +97 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormHeader.js +19 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.js +66 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormSubmit.js +25 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/index.js +16 -0
- package/lib/esm/builtin/async/ai-runtime/components/session/CheckSession.js +59 -0
- package/lib/esm/builtin/async/ai-runtime/components/session/SessionListView.js +88 -0
- package/lib/esm/builtin/async/ai-runtime/constants.js +2 -0
- package/lib/esm/builtin/async/ai-runtime/hooks/header.js +25 -0
- package/lib/esm/builtin/async/ai-runtime/hooks/navigate.js +31 -0
- package/lib/esm/builtin/async/ai-runtime/hooks/subscribe.js +31 -0
- package/lib/esm/builtin/async/ai-runtime/index.js +66 -0
- package/lib/esm/builtin/async/ai-runtime/locales/index.js +144 -0
- package/lib/esm/builtin/async/ai-runtime/state/assistant.js +54 -0
- package/lib/esm/builtin/async/ai-runtime/state/index.js +423 -0
- package/lib/esm/builtin/async/ai-runtime/state/session.js +209 -0
- package/lib/esm/builtin/async/ai-runtime/state/subscription.js +47 -0
- package/lib/esm/builtin/async/ai-runtime/utils.js +42 -0
- package/lib/esm/builtin/async/react-scroll-to-bottom.js +1 -1
- package/lib/esm/utils/builtin.js +1 -0
- package/lib/esm/utils/inject-global-components.js +2 -0
- package/lib/types/builtin/async/ai-runtime/api/assistant.d.ts +18 -0
- package/lib/types/builtin/async/ai-runtime/api/dataset.d.ts +39 -0
- package/lib/types/builtin/async/ai-runtime/api/message.d.ts +39 -0
- package/lib/types/builtin/async/ai-runtime/api/request.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/api/session.d.ts +54 -0
- package/lib/types/builtin/async/ai-runtime/api/subscription.d.ts +15 -0
- package/lib/types/builtin/async/ai-runtime/components/ActionButton.d.ts +11 -0
- package/lib/types/builtin/async/ai-runtime/components/GlobalLoading.d.ts +33 -0
- package/lib/types/builtin/async/ai-runtime/components/LoadingButton.d.ts +3 -0
- package/lib/types/builtin/async/ai-runtime/components/LoadingListItemButton.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/components/MarkdownRenderer.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/components/MenuButton.d.ts +9 -0
- package/lib/types/builtin/async/ai-runtime/components/PoweredBy.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/RuntimeProvider.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/ScrollView.d.ts +61 -0
- package/lib/types/builtin/async/ai-runtime/components/SocialShare.d.ts +17 -0
- package/lib/types/builtin/async/ai-runtime/components/ThemeProvider.d.ts +6 -0
- package/lib/types/builtin/async/ai-runtime/components/collection/CollectionEditDialog.d.ts +0 -0
- package/lib/types/builtin/async/ai-runtime/components/collection/CollectionListView.d.ts +0 -0
- package/lib/types/builtin/async/ai-runtime/components/collection/CollectionView.d.ts +0 -0
- package/lib/types/builtin/async/ai-runtime/components/collection/DocumentListView.d.ts +0 -0
- package/lib/types/builtin/async/ai-runtime/components/collection/DocumentView.d.ts +0 -0
- package/lib/types/builtin/async/ai-runtime/components/common/ChatBot.d.ts +13 -0
- package/lib/types/builtin/async/ai-runtime/components/common/MessageMetadataRenderer.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/common/MessageSuggestedQuestions.d.ts +7 -0
- package/lib/types/builtin/async/ai-runtime/components/common/index.d.ts +3 -0
- package/lib/types/builtin/async/ai-runtime/components/form/ParameterForm.d.ts +12 -0
- package/lib/types/builtin/async/ai-runtime/components/form/ParameterFormDialog.d.ts +28 -0
- package/lib/types/builtin/async/ai-runtime/components/form/ParameterFormFields.d.ts +8 -0
- package/lib/types/builtin/async/ai-runtime/components/form/QuestionField.d.ts +13 -0
- package/lib/types/builtin/async/ai-runtime/components/form/SettingButton.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/layout/index.d.ts +7 -0
- package/lib/types/builtin/async/ai-runtime/components/lottie/index.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/message/MessageActions.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/message/MessageErrorView.d.ts +6 -0
- package/lib/types/builtin/async/ai-runtime/components/message/MessageItemView.d.ts +10 -0
- package/lib/types/builtin/async/ai-runtime/components/message/MessageListView.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/components/message/ReferenceLinks.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/parameters/LanguageField.d.ts +9 -0
- package/lib/types/builtin/async/ai-runtime/components/parameters/NumberField.d.ts +9 -0
- package/lib/types/builtin/async/ai-runtime/components/parameters/SelectField.d.ts +9 -0
- package/lib/types/builtin/async/ai-runtime/components/parameters/StringField.d.ts +9 -0
- package/lib/types/builtin/async/ai-runtime/components/parameters/index.d.ts +7 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime-chat/InitialForm.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHeader.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHome.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.d.ts +6 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime-chat/index.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime-form/RuntimeFormHeader.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime-form/RuntimeFormSubmit.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime-form/index.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/session/CheckSession.d.ts +9 -0
- package/lib/types/builtin/async/ai-runtime/components/session/SessionListView.d.ts +0 -0
- package/lib/types/builtin/async/ai-runtime/constants.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/hooks/header.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/hooks/navigate.d.ts +25 -0
- package/lib/types/builtin/async/ai-runtime/hooks/subscribe.d.ts +6 -0
- package/lib/types/builtin/async/ai-runtime/index.d.ts +17 -0
- package/lib/types/builtin/async/ai-runtime/locales/index.d.ts +126 -0
- package/lib/types/builtin/async/ai-runtime/state/assistant.d.ts +17 -0
- package/lib/types/builtin/async/ai-runtime/state/index.d.ts +0 -0
- package/lib/types/builtin/async/ai-runtime/state/session.d.ts +40 -0
- package/lib/types/builtin/async/ai-runtime/state/subscription.d.ts +15 -0
- package/lib/types/builtin/async/ai-runtime/utils.d.ts +20 -0
- package/lib/types/builtin/async/react-scroll-to-bottom.d.ts +3 -2
- package/lib/types/builtin/session.d.ts +11 -1
- package/lib/types/utils/builtin.d.ts +1 -0
- package/package.json +12 -7
- package/tsconfig.json +5 -1
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { Icon } from '@iconify/react';
|
|
14
|
+
import { Box, Button, Stack, Tooltip } from '@mui/material';
|
|
15
|
+
import { Suspense } from 'react';
|
|
16
|
+
import { XIcon } from 'react-share';
|
|
17
|
+
import { withQuery } from 'ufo';
|
|
18
|
+
import { useLocaleContext } from '../../../../locale';
|
|
19
|
+
import lottieJsonErrorUrl from '../../assets/lottie/lottie-error.json?url';
|
|
20
|
+
import lottieJsonLoadingUrl from '../../assets/lottie/lottie-loading.json?url';
|
|
21
|
+
import lottieJsonSuccessUrl from '../../assets/lottie/lottie-success.json?url';
|
|
22
|
+
import lottieJsonWelcomeUrl from '../../assets/lottie/lottie-welcome.json?url';
|
|
23
|
+
import { useSessionState } from '../../state/session';
|
|
24
|
+
import { ActionButton } from '../ActionButton';
|
|
25
|
+
import { MessageMetadataRenderer } from '../common';
|
|
26
|
+
import Lottie from '../lottie';
|
|
27
|
+
import MarkdownRenderer from '../MarkdownRenderer';
|
|
28
|
+
export default function RuntimeFormResult(_a) {
|
|
29
|
+
var { page } = _a, props = __rest(_a, ["page"]);
|
|
30
|
+
return (_jsxs(Stack, Object.assign({}, props, { children: [_jsx(Stack, { sx: {
|
|
31
|
+
px: { xs: 2, sm: 3, md: 4 },
|
|
32
|
+
py: 2.5,
|
|
33
|
+
bgcolor: 'background.default',
|
|
34
|
+
position: { xs: 'unset', md: 'sticky' },
|
|
35
|
+
top: 0,
|
|
36
|
+
zIndex: 2,
|
|
37
|
+
fontSize: 32,
|
|
38
|
+
}, children: "\uD83E\uDD16" }), _jsx(Box, { sx: { px: { xs: 2, sm: 3, md: 4 } }, children: _jsx(Suspense, { children: page.sessionId ? (_jsx(ResultView, { sessionId: page.sessionId })) : (_jsx(Box, { width: 300, height: 300, m: "auto", mt: "100px", children: _jsx(Lottie, { src: lottieJsonWelcomeUrl }) })) }) })] })));
|
|
39
|
+
}
|
|
40
|
+
function ResultView({ sessionId }) {
|
|
41
|
+
var _a, _b, _c, _d;
|
|
42
|
+
const { t } = useLocaleContext();
|
|
43
|
+
const [, _e] = useSessionState({ sessionId }), { messages = [] } = _e, state = __rest(_e, ["messages"]);
|
|
44
|
+
const message = messages[messages.length - 1];
|
|
45
|
+
const textContent = (_a = message === null || message === void 0 ? void 0 : message.result) === null || _a === void 0 ? void 0 : _a.content;
|
|
46
|
+
const error = state.error || (message === null || message === void 0 ? void 0 : message.error);
|
|
47
|
+
if (error) {
|
|
48
|
+
return (_jsxs(Box, { width: 240, height: 240, m: "auto", mt: "100px", children: [_jsx(Lottie, { src: lottieJsonErrorUrl }), _jsx(Box, { textAlign: "center", color: "#25292F", children: error.message })] }));
|
|
49
|
+
}
|
|
50
|
+
if ((message === null || message === void 0 ? void 0 : message.loading) && !textContent) {
|
|
51
|
+
return (_jsx(Box, { width: 240, height: 240, m: "auto", mt: "100px", children: _jsx(Lottie, { src: lottieJsonLoadingUrl }) }));
|
|
52
|
+
}
|
|
53
|
+
if (!message) {
|
|
54
|
+
return (_jsx(Box, { width: 300, height: 300, m: "auto", mt: "100px", children: _jsx(Lottie, { src: lottieJsonWelcomeUrl }) }));
|
|
55
|
+
}
|
|
56
|
+
return (_jsxs(Stack, { gap: 2, children: [textContent && (_jsxs(Box, { sx: {
|
|
57
|
+
border: 1,
|
|
58
|
+
borderColor: 'grey.200',
|
|
59
|
+
borderRadius: 1,
|
|
60
|
+
bgcolor: 'grey.100',
|
|
61
|
+
}, children: [_jsx(Box, { sx: { p: 2 }, children: _jsx(MarkdownRenderer, { 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 && (_jsxs(Stack, { direction: "row", alignItems: "center", justifyContent: "flex-end", px: 2, pb: 1, gap: 1, children: [_jsx(Box, { children: _jsx(ActionButton, { autoReset: true, size: "small", variant: "text",
|
|
62
|
+
// @ts-ignore
|
|
63
|
+
color: "black", tip: t('copyToClipboard'), tipSucceed: t('copied'), title: _jsx(Icon, { icon: "tabler:copy", fontSize: 18 }), titleSucceed: _jsx(Icon, { icon: "tabler:copy-check-filled", fontSize: 18 }), sx: { p: 0.5, minWidth: 0, minHeight: 0, color: 'text.secondary' }, onClick: () => {
|
|
64
|
+
window.navigator.clipboard.writeText(textContent);
|
|
65
|
+
} }) }), _jsx(Box, { children: _jsx(Tooltip, { title: t('socialShare.shareToX'), placement: "top", disableInteractive: true, children: _jsx(Button, { sx: { p: 0.5, minWidth: 0, minHeight: 0 }, target: "_blank", href: withQuery('https://twitter.com/intent/tweet', { text: textContent }), children: _jsx(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) => _jsx(MessageMetadataRenderer, { object: object.data }, object.taskId)), _jsx(Box, { display: "flex", justifyContent: "flex-end", mb: "60px", mt: "40px", children: _jsx(Box, { width: 120, height: 120, children: _jsx(Lottie, { src: lottieJsonSuccessUrl }) }) })] }));
|
|
66
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { useSubscribeLink } from '../../hooks/subscribe';
|
|
14
|
+
import LoadingButton from '../LoadingButton';
|
|
15
|
+
import PoweredBy from '../PoweredBy';
|
|
16
|
+
export default function RuntimeFormSubmit(_a) {
|
|
17
|
+
var { page } = _a, props = __rest(_a, ["page"]);
|
|
18
|
+
const { subscribeLink } = useSubscribeLink({ assistantId: page.assistantId });
|
|
19
|
+
return (_jsxs(_Fragment, { children: [_jsx(LoadingButton, Object.assign({}, props, { onClick: (e) => {
|
|
20
|
+
if (subscribeLink) {
|
|
21
|
+
e.preventDefault();
|
|
22
|
+
window.location.href = subscribeLink;
|
|
23
|
+
}
|
|
24
|
+
} })), _jsx(PoweredBy, { assistantId: page.assistantId })] }));
|
|
25
|
+
}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Box, Divider, Stack } from '@mui/material';
|
|
3
|
+
import { useAssistantState } from '../../state/assistant';
|
|
4
|
+
import RuntimeFormForms from './RuntimeFormForms';
|
|
5
|
+
import RuntimeFormHeader from './RuntimeFormHeader';
|
|
6
|
+
import RuntimeFormResult from './RuntimeFormResult';
|
|
7
|
+
export default function RuntimeForm({ page }) {
|
|
8
|
+
const [agent] = useAssistantState({ assistantId: page.assistantId });
|
|
9
|
+
return (_jsxs(Stack, { sx: { flexGrow: { xs: 'unset', md: 1 } }, children: [_jsx(RuntimeFormHeader, { agent: agent, sx: {
|
|
10
|
+
position: 'sticky',
|
|
11
|
+
top: 64,
|
|
12
|
+
zIndex: 10,
|
|
13
|
+
px: { xs: 2, sm: 3, md: 8 },
|
|
14
|
+
py: { xs: 2, sm: 3, md: 5 },
|
|
15
|
+
} }), _jsxs(Stack, { sx: { flexGrow: 1, flexDirection: { xs: 'column', md: 'row' } }, children: [_jsx(Stack, { sx: { flex: 1, px: { xs: 2, sm: 3, md: 4 }, ml: { xs: 0, md: 4 } }, children: _jsx(RuntimeFormForms, { page: page, sx: { position: 'sticky', top: 232 } }) }), _jsx(Divider, { orientation: "vertical", sx: { borderColor: 'grey.200', my: { xs: 2, sm: 3, md: 0 } } }), _jsx(Box, { sx: { flex: 2 }, children: _jsx(RuntimeFormResult, { page: page }) })] })] }));
|
|
16
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { useEffect, useState } from 'react';
|
|
11
|
+
import { useSessionContext } from '../../../../session';
|
|
12
|
+
import { createSession, getSessions } from '../../api/session';
|
|
13
|
+
import { useAssistantState } from '../../state/assistant';
|
|
14
|
+
import { createSessionState } from '../../state/session';
|
|
15
|
+
import { parseIdentity } from '../../utils';
|
|
16
|
+
import { globalLoadingState } from '../GlobalLoading';
|
|
17
|
+
export default function CheckSession({ assistantId, sessionId, autoCreateSession, children, navigate, }) {
|
|
18
|
+
useAssistantState({ assistantId });
|
|
19
|
+
const { session: authSession } = useSessionContext();
|
|
20
|
+
const [done, setDone] = useState(false);
|
|
21
|
+
const [error, setError] = useState();
|
|
22
|
+
useEffect(() => {
|
|
23
|
+
if (!authSession.user)
|
|
24
|
+
return;
|
|
25
|
+
globalLoadingState.getState().run(() => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
var _a;
|
|
27
|
+
try {
|
|
28
|
+
if (!sessionId) {
|
|
29
|
+
if (authSession.user) {
|
|
30
|
+
const { sessions } = yield getSessions(parseIdentity(assistantId, { rejectWhenError: true }));
|
|
31
|
+
const session = (_a = sessions[0]) !== null && _a !== void 0 ? _a : (autoCreateSession ? (yield createSession({ assistantId })).created : undefined);
|
|
32
|
+
if (session) {
|
|
33
|
+
yield createSessionState({ sessionId: session.id, session }).getState().load();
|
|
34
|
+
navigate === null || navigate === void 0 ? void 0 : navigate({ page: 'session', assistantId, sessionId: session.id });
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
else {
|
|
39
|
+
const state = createSessionState({ sessionId });
|
|
40
|
+
yield state.getState().load();
|
|
41
|
+
}
|
|
42
|
+
setDone(true);
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
if (sessionId) {
|
|
46
|
+
navigate === null || navigate === void 0 ? void 0 : navigate({ page: 'assistant', assistantId, sessionId: undefined }, { replace: true });
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
setError(error);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}));
|
|
53
|
+
}, [assistantId, sessionId, authSession.user]);
|
|
54
|
+
if (error)
|
|
55
|
+
throw error;
|
|
56
|
+
if (authSession.loading)
|
|
57
|
+
return null;
|
|
58
|
+
return done && children;
|
|
59
|
+
}
|
|
@@ -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,25 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Box } from '@mui/material';
|
|
3
|
+
import { useEffect } from 'react';
|
|
4
|
+
import { useHeaderState } from '../../../page/header';
|
|
5
|
+
import SocialShare from '../components/SocialShare';
|
|
6
|
+
export function useSetHeader({ assistant }) {
|
|
7
|
+
// set logo
|
|
8
|
+
useEffect(() => {
|
|
9
|
+
const { release } = assistant;
|
|
10
|
+
useHeaderState.setState((state) => {
|
|
11
|
+
state.logo = (release === null || release === void 0 ? void 0 : release.logo) && _jsx(Box, { component: "img", src: release.logo, sx: { borderRadius: 1 } });
|
|
12
|
+
state.brand = (release === null || release === void 0 ? void 0 : release.title) || assistant.name;
|
|
13
|
+
const shareContent = `${(release === null || release === void 0 ? void 0 : release.title) || assistant.name}
|
|
14
|
+
|
|
15
|
+
${release === null || release === void 0 ? void 0 : release.description}
|
|
16
|
+
`;
|
|
17
|
+
state.addons = (...exists) => [_jsx(SocialShare, { content: shareContent }), ...exists];
|
|
18
|
+
});
|
|
19
|
+
return () => useHeaderState.setState((state) => {
|
|
20
|
+
state.logo = undefined;
|
|
21
|
+
state.brand = undefined;
|
|
22
|
+
state.addons = (...exists) => [...exists];
|
|
23
|
+
});
|
|
24
|
+
}, []);
|
|
25
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { useCallback, useMemo } from 'react';
|
|
2
|
+
import { useLocation, useNavigate } from 'react-router-dom';
|
|
3
|
+
import { getQuery, withQuery } from 'ufo';
|
|
4
|
+
export function useNavigateTo() {
|
|
5
|
+
const location = useLocation();
|
|
6
|
+
return useCallback((query) => withQuery(`${location.pathname}${location.search}`, query), [location]);
|
|
7
|
+
}
|
|
8
|
+
export function useNavigateWithQuery() {
|
|
9
|
+
const to = useNavigateTo();
|
|
10
|
+
const navigate = useNavigate();
|
|
11
|
+
return useCallback((query, options) => {
|
|
12
|
+
navigate(to(Object.assign(Object.assign({}, query), { page: query.page === 'assistant' ? undefined : query.page })), options);
|
|
13
|
+
}, [navigate, to]);
|
|
14
|
+
}
|
|
15
|
+
const PAGES = ['assistant', 'session'];
|
|
16
|
+
function isCurrentPage(page) {
|
|
17
|
+
return PAGES.includes(page);
|
|
18
|
+
}
|
|
19
|
+
export function useCurrentPage(page) {
|
|
20
|
+
const { search } = useLocation();
|
|
21
|
+
const { page: pageParam, assistantId, sessionId, } = useMemo(() => getQuery(search), [search]);
|
|
22
|
+
const navigate = useNavigateWithQuery();
|
|
23
|
+
const currentPage = isCurrentPage(pageParam) ? pageParam : 'assistant';
|
|
24
|
+
if (page && page !== currentPage)
|
|
25
|
+
throw new Error('Invalid page state');
|
|
26
|
+
if (currentPage === 'assistant' && assistantId)
|
|
27
|
+
return { page: currentPage, assistantId, navigate };
|
|
28
|
+
if (currentPage === 'session' && assistantId && sessionId)
|
|
29
|
+
return { page: currentPage, assistantId, sessionId, navigate };
|
|
30
|
+
throw new Error('Not Found: missing required query');
|
|
31
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { joinURL, withQuery } from 'ufo';
|
|
2
|
+
import { useSessionContext } from '../../../session';
|
|
3
|
+
import { getComponentMountPoint } from '../../../utils';
|
|
4
|
+
import { PAYMENT_KIT_DID } from '../constants';
|
|
5
|
+
import { useAssistantState } from '../state/assistant';
|
|
6
|
+
import { useSubscriptionState } from '../state/subscription';
|
|
7
|
+
export function useSubscribeLink({ assistantId }) {
|
|
8
|
+
var _a, _b, _c;
|
|
9
|
+
const [, state] = useSubscriptionState({ aid: assistantId });
|
|
10
|
+
const [assistant] = useAssistantState({ assistantId });
|
|
11
|
+
const { session } = useSessionContext();
|
|
12
|
+
const requireSubscribe = ((_b = (_a = assistant.release) === null || _a === void 0 ? void 0 : _a.payment) === null || _b === void 0 ? void 0 : _b.enable) && !state.subscription;
|
|
13
|
+
const subscribeLink = requireSubscribe && session.user && ((_c = state.release) === null || _c === void 0 ? void 0 : _c.paymentLinkId)
|
|
14
|
+
? getSubscribeLink({
|
|
15
|
+
aid: assistantId,
|
|
16
|
+
userId: session.user.did,
|
|
17
|
+
paymentLinkId: state.release.paymentLinkId,
|
|
18
|
+
})
|
|
19
|
+
: undefined;
|
|
20
|
+
return {
|
|
21
|
+
requireSubscribe,
|
|
22
|
+
subscribeLink,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function getSubscribeLink({ aid, userId, paymentLinkId }) {
|
|
26
|
+
return withQuery(joinURL('/', getComponentMountPoint(PAYMENT_KIT_DID), '/checkout/pay', paymentLinkId), {
|
|
27
|
+
'metadata.aid': aid,
|
|
28
|
+
'metadata.userId': userId,
|
|
29
|
+
redirect: window.location.href,
|
|
30
|
+
});
|
|
31
|
+
}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
import { Stack } from '@mui/material';
|
|
12
|
+
import { useCallback, useMemo, useState } from 'react';
|
|
13
|
+
import { getQuery } from '../../utils';
|
|
14
|
+
import { getAssistant } from './api/assistant';
|
|
15
|
+
import { ChatBot as ChatBotWrapper } from './components/common';
|
|
16
|
+
import RuntimeChat from './components/runtime-chat';
|
|
17
|
+
import RuntimeForm from './components/runtime-form';
|
|
18
|
+
import RuntimeProvider from './components/RuntimeProvider';
|
|
19
|
+
import ScrollView from './components/ScrollView';
|
|
20
|
+
import CheckSession from './components/session/CheckSession';
|
|
21
|
+
import { useSetHeader } from './hooks/header';
|
|
22
|
+
import { useCurrentPage, useNavigateWithQuery } from './hooks/navigate';
|
|
23
|
+
import { createAssistantState, useAssistantState } from './state/assistant';
|
|
24
|
+
import { parseIdentity } from './utils';
|
|
25
|
+
export function getServerSideProps() {
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
const query = getQuery(globalThis.location.href);
|
|
28
|
+
const assistantId = typeof query.assistantId === 'string' ? query.assistantId : undefined;
|
|
29
|
+
const identity = assistantId ? parseIdentity(assistantId) : undefined;
|
|
30
|
+
const assistant = identity && (yield getAssistant(identity));
|
|
31
|
+
return { props: { preload: assistantId ? { assistantId, assistant } : undefined } };
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
export default function AIRuntime({ preload }) {
|
|
35
|
+
const { assistantId, sessionId } = useCurrentPage();
|
|
36
|
+
const navigate = useNavigateWithQuery();
|
|
37
|
+
useMemo(() => {
|
|
38
|
+
// preload assistant from server side props
|
|
39
|
+
if (preload)
|
|
40
|
+
createAssistantState(preload);
|
|
41
|
+
}, []);
|
|
42
|
+
return (_jsx(RuntimeProvider, { children: _jsx(CheckSession, { assistantId: assistantId, sessionId: sessionId, navigate: navigate, children: _jsx(ScrollView, { scroller: "window", initialScrollBehavior: "auto", children: _jsx(Stack, { flexGrow: 1, height: "100%", className: "ai-runtime-root", children: _jsx(Main, {}) }) }) }) }));
|
|
43
|
+
}
|
|
44
|
+
function Main() {
|
|
45
|
+
var _a;
|
|
46
|
+
const page = useCurrentPage();
|
|
47
|
+
const [assistant] = useAssistantState({ assistantId: page.assistantId });
|
|
48
|
+
useSetHeader({ assistant });
|
|
49
|
+
if (((_a = assistant.release) === null || _a === void 0 ? void 0 : _a.template) === 'form') {
|
|
50
|
+
return _jsx(RuntimeForm, { page: page });
|
|
51
|
+
}
|
|
52
|
+
return _jsx(RuntimeChat, { page: page });
|
|
53
|
+
}
|
|
54
|
+
export function ChatBot(props) {
|
|
55
|
+
if (!props.assistantId)
|
|
56
|
+
throw new Error('Missing required parameter assistantId');
|
|
57
|
+
const navigate = useCallback((page) => {
|
|
58
|
+
setPage((state) => (Object.assign(Object.assign({}, state), page)));
|
|
59
|
+
}, []);
|
|
60
|
+
const [page, setPage] = useState({
|
|
61
|
+
page: 'assistant',
|
|
62
|
+
assistantId: props.assistantId,
|
|
63
|
+
navigate,
|
|
64
|
+
});
|
|
65
|
+
return (_jsx(RuntimeProvider, { children: _jsx(CheckSession, { assistantId: props.assistantId, autoCreateSession: true, navigate: page.navigate, children: _jsx(ChatBotWrapper, Object.assign({}, props, { children: _jsx(RuntimeChat, { page: page }) })) }) }));
|
|
66
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
export const translations = {
|
|
2
|
+
en: {
|
|
3
|
+
socialShare: {
|
|
4
|
+
shareToX: 'Share to X',
|
|
5
|
+
shareToTelegram: 'Share to Telegram',
|
|
6
|
+
shareToReddit: 'Share to Reddit',
|
|
7
|
+
shareToWeibo: 'Share to Weibo',
|
|
8
|
+
shareToFacebook: 'Share to Facebook',
|
|
9
|
+
shareToLinkedin: 'Share to Linkedin',
|
|
10
|
+
copyLink: 'Copy Link',
|
|
11
|
+
},
|
|
12
|
+
questionPlaceholder: 'Ask Anything...',
|
|
13
|
+
parameters: 'Parameters',
|
|
14
|
+
parametersTitle: 'Tell me what do you want?',
|
|
15
|
+
parametersSetting: 'Setting',
|
|
16
|
+
clearSession: 'Clear Session',
|
|
17
|
+
generate: 'Generate',
|
|
18
|
+
startChat: 'Start Chat',
|
|
19
|
+
collections: 'Collections',
|
|
20
|
+
collection: 'Collection',
|
|
21
|
+
collectionName: 'Collection Name',
|
|
22
|
+
document: 'Document',
|
|
23
|
+
rename: 'Rename',
|
|
24
|
+
delete: 'Delete',
|
|
25
|
+
confirmDelete: 'Confirm Delete?',
|
|
26
|
+
noData: 'No {data} yet',
|
|
27
|
+
createObject: 'Create {object}',
|
|
28
|
+
title: 'Title',
|
|
29
|
+
titlePlaceholder: 'Title',
|
|
30
|
+
content: 'Content',
|
|
31
|
+
contentPlaceholder: 'Write anything...',
|
|
32
|
+
cancel: 'Cancel',
|
|
33
|
+
save: 'Save',
|
|
34
|
+
edit: 'Edit',
|
|
35
|
+
chat: 'Chat',
|
|
36
|
+
subscribeNow: 'Subscribe Now',
|
|
37
|
+
requireNewSubscription: `Thank you for using our service!
|
|
38
|
+
|
|
39
|
+
To get more features and exclusive content, please subscribe to our service. After subscribing, you will enjoy the following privileges:
|
|
40
|
+
|
|
41
|
+
- Unlock all features and tools
|
|
42
|
+
- Support us to continue to provide quality services
|
|
43
|
+
|
|
44
|
+
Pricing: {price} ABT/Message
|
|
45
|
+
|
|
46
|
+
Subscribe now to unlock more possibilities!`,
|
|
47
|
+
requireNewSubscriptionFooter: 'You need to subscribe to access this feature:',
|
|
48
|
+
thanksForSubscription: 'Thanks for subscribing, now you can start enjoying it!',
|
|
49
|
+
clickTheButton: 'Click The Button 👉',
|
|
50
|
+
cleanSessionTip: 'Clean conversation messages',
|
|
51
|
+
poweredBy: 'Powered by',
|
|
52
|
+
selectPromptToStart: 'Select a prompt to get started',
|
|
53
|
+
history: 'History',
|
|
54
|
+
unnamed: 'Unnamed',
|
|
55
|
+
newObject: 'New {object}',
|
|
56
|
+
editObject: 'Edit {object}',
|
|
57
|
+
name: 'Name',
|
|
58
|
+
description: 'Description',
|
|
59
|
+
create: 'Create',
|
|
60
|
+
back: 'Back',
|
|
61
|
+
unauthorized: 'Unauthorized',
|
|
62
|
+
unauthorizedDescription: 'Please log in to visit this page',
|
|
63
|
+
login: 'Login',
|
|
64
|
+
copy: 'Copy',
|
|
65
|
+
copied: 'Copied',
|
|
66
|
+
copyToClipboard: 'Copy to clipboard',
|
|
67
|
+
saveToNoteTip: 'Save to collection',
|
|
68
|
+
saveToNote: 'Save',
|
|
69
|
+
savedToNote: 'Saved as a new document',
|
|
70
|
+
uploadFile: 'Upload File',
|
|
71
|
+
submit: 'Submit',
|
|
72
|
+
},
|
|
73
|
+
zh: {
|
|
74
|
+
socialShare: {
|
|
75
|
+
shareToX: '分享到 X',
|
|
76
|
+
shareToTelegram: '分享到 Telegram',
|
|
77
|
+
shareToReddit: '分享到 Reddit',
|
|
78
|
+
shareToWeibo: '分享到 微博',
|
|
79
|
+
shareToFacebook: '分享到 Facebook',
|
|
80
|
+
shareToLinkedin: '分享到 Linkedin',
|
|
81
|
+
copyLink: '复制链接',
|
|
82
|
+
},
|
|
83
|
+
questionPlaceholder: '问点什么...',
|
|
84
|
+
parameters: '参数',
|
|
85
|
+
parametersTitle: '告诉我你想要什么?',
|
|
86
|
+
parametersSetting: '设置',
|
|
87
|
+
clearSession: '清空对话',
|
|
88
|
+
generate: '生成',
|
|
89
|
+
startChat: '开始对话',
|
|
90
|
+
collections: '知识库',
|
|
91
|
+
collection: '知识库',
|
|
92
|
+
collectionName: '知识库名称',
|
|
93
|
+
document: '文档',
|
|
94
|
+
rename: '重命名',
|
|
95
|
+
delete: '删除',
|
|
96
|
+
confirmDelete: '确定删除?',
|
|
97
|
+
noData: '暂无{data}',
|
|
98
|
+
createObject: '创建{object}',
|
|
99
|
+
title: '标题',
|
|
100
|
+
titlePlaceholder: '标题',
|
|
101
|
+
content: '内容',
|
|
102
|
+
contentPlaceholder: '写点什么吧...',
|
|
103
|
+
cancel: '取消',
|
|
104
|
+
save: '保存',
|
|
105
|
+
edit: '编辑',
|
|
106
|
+
chat: '对话',
|
|
107
|
+
subscribeNow: '立即订阅',
|
|
108
|
+
requireNewSubscription: `感谢您使用我们的服务!
|
|
109
|
+
|
|
110
|
+
为了获得更多功能和专属内容,请订阅我们的服务。订阅后,您将享有以下特权:
|
|
111
|
+
|
|
112
|
+
- 解锁全部功能和工具
|
|
113
|
+
- 支持我们持续提供优质服务
|
|
114
|
+
|
|
115
|
+
价格: {price} ABT/次对话
|
|
116
|
+
|
|
117
|
+
立即订阅以解锁更多可能性!`,
|
|
118
|
+
requireNewSubscriptionFooter: '您需要订阅才能访问此功能:',
|
|
119
|
+
thanksForSubscription: '感谢您的订阅,现在,您可以开始尽情体验了!',
|
|
120
|
+
clickTheButton: '点我生成 👉',
|
|
121
|
+
cleanSessionTip: '清除会话消息记录',
|
|
122
|
+
poweredBy: '技术支持源自',
|
|
123
|
+
selectPromptToStart: '选择一个提示词开始吧',
|
|
124
|
+
history: '历史记录',
|
|
125
|
+
unnamed: '未命名',
|
|
126
|
+
newObject: '新建{object}',
|
|
127
|
+
editObject: '编辑{object}',
|
|
128
|
+
name: '名称',
|
|
129
|
+
description: '描述',
|
|
130
|
+
create: '创建',
|
|
131
|
+
back: '返回',
|
|
132
|
+
unauthorized: '未登录',
|
|
133
|
+
unauthorizedDescription: '请登录后访问该页面',
|
|
134
|
+
login: '登录',
|
|
135
|
+
copy: '复制',
|
|
136
|
+
copied: '已复制',
|
|
137
|
+
copyToClipboard: '复制到剪贴板',
|
|
138
|
+
saveToNoteTip: '保存到知识库',
|
|
139
|
+
saveToNote: '保存',
|
|
140
|
+
savedToNote: '已保存到知识库',
|
|
141
|
+
uploadFile: '上传文件',
|
|
142
|
+
submit: '提交',
|
|
143
|
+
},
|
|
144
|
+
};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
import { create } from 'zustand';
|
|
11
|
+
import { immer } from 'zustand/middleware/immer';
|
|
12
|
+
import { getAssistant } from '../api/assistant';
|
|
13
|
+
const STATES = {};
|
|
14
|
+
export const createAssistantState = ({ assistantId, assistant }) => {
|
|
15
|
+
var _a;
|
|
16
|
+
(_a = STATES[assistantId]) !== null && _a !== void 0 ? _a : (STATES[assistantId] = create()(immer((set) => ({
|
|
17
|
+
assistant,
|
|
18
|
+
load: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
set((state) => {
|
|
20
|
+
state.loading = true;
|
|
21
|
+
});
|
|
22
|
+
try {
|
|
23
|
+
const assistant = yield getAssistant({ assistantId });
|
|
24
|
+
set((state) => {
|
|
25
|
+
state.assistant = assistant;
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
catch (error) {
|
|
29
|
+
console.error(error);
|
|
30
|
+
set((state) => {
|
|
31
|
+
state.error = error;
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
finally {
|
|
35
|
+
set((state) => {
|
|
36
|
+
state.loading = false;
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
}),
|
|
40
|
+
}))));
|
|
41
|
+
return STATES[assistantId];
|
|
42
|
+
};
|
|
43
|
+
const LOADING_TASKS = {};
|
|
44
|
+
export function useAssistantState({ assistantId }) {
|
|
45
|
+
var _a;
|
|
46
|
+
const state = createAssistantState({ assistantId })();
|
|
47
|
+
if (!state.assistant) {
|
|
48
|
+
if (state.error)
|
|
49
|
+
throw state.error;
|
|
50
|
+
(_a = LOADING_TASKS[assistantId]) !== null && _a !== void 0 ? _a : (LOADING_TASKS[assistantId] = state.load());
|
|
51
|
+
throw LOADING_TASKS[assistantId];
|
|
52
|
+
}
|
|
53
|
+
return [state.assistant, state];
|
|
54
|
+
}
|