@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.
- 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 +55 -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 +24 -0
- package/lib/cjs/builtin/async/ai-runtime/components/LoadingButton.js +40 -0
- package/lib/cjs/builtin/async/ai-runtime/components/LoadingListItemButton.js +49 -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 +22 -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 +104 -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 +89 -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 +57 -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 +81 -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 +129 -0
- package/lib/cjs/builtin/async/ai-runtime/components/message/MessageListView.js +47 -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 +111 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHeader.js +60 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +52 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/index.js +28 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +120 -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 +65 -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/error.js +10 -0
- package/lib/cjs/builtin/async/ai-runtime/hooks/header.js +32 -0
- package/lib/cjs/builtin/async/ai-runtime/hooks/navigate.js +38 -0
- package/lib/cjs/builtin/async/ai-runtime/hooks/subscribe.js +35 -0
- package/lib/cjs/builtin/async/ai-runtime/hooks/useAsync.js +32 -0
- package/lib/cjs/builtin/async/ai-runtime/index.js +81 -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/loading.js +39 -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 +51 -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 +21 -0
- package/lib/esm/builtin/async/ai-runtime/components/LoadingButton.js +38 -0
- package/lib/esm/builtin/async/ai-runtime/components/LoadingListItemButton.js +46 -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 +16 -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 +98 -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 +60 -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 +50 -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 +75 -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 +100 -0
- package/lib/esm/builtin/async/ai-runtime/components/message/MessageListView.js +41 -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 +103 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHeader.js +34 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +46 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/index.js +22 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +114 -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/error.js +6 -0
- package/lib/esm/builtin/async/ai-runtime/hooks/header.js +25 -0
- package/lib/esm/builtin/async/ai-runtime/hooks/navigate.js +32 -0
- package/lib/esm/builtin/async/ai-runtime/hooks/subscribe.js +31 -0
- package/lib/esm/builtin/async/ai-runtime/hooks/useAsync.js +29 -0
- package/lib/esm/builtin/async/ai-runtime/index.js +72 -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/loading.js +36 -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 +2 -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 +5 -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 +11 -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 +6 -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 +8 -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 +10 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHeader.d.ts +5 -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 +5 -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 +8 -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/error.d.ts +4 -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/hooks/useAsync.d.ts +1 -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/loading.d.ts +10 -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/page/header.d.ts +1 -6
- package/lib/types/builtin/session.d.ts +11 -1
- package/lib/types/components/CustomComponentRenderer/state.d.ts +1 -116
- package/lib/types/utils/builtin.d.ts +1 -0
- package/package.json +14 -9
- package/tsconfig.json +5 -1
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
|
+
import { Alert, Box, Stack } from '@mui/material';
|
|
23
|
+
import { Suspense, useEffect, useMemo, useState } from 'react';
|
|
24
|
+
import { useForm } from 'react-hook-form';
|
|
25
|
+
import { useLocaleContext } from '../../../../locale';
|
|
26
|
+
import { alpha } from '../../../../mui/material';
|
|
27
|
+
import { useSessionContext } from '../../../../session';
|
|
28
|
+
import { createSession } from '../../api/session';
|
|
29
|
+
import { useAssistantState } from '../../state/assistant';
|
|
30
|
+
import { globalLoadingState } from '../../state/loading';
|
|
31
|
+
import { createSessionState } from '../../state/session';
|
|
32
|
+
import ParameterFormFields from '../form/ParameterFormFields';
|
|
33
|
+
import RuntimeFormSubmit from './RuntimeFormSubmit';
|
|
34
|
+
export default function RuntimeFormForms(_a) {
|
|
35
|
+
var _b, _c, _d;
|
|
36
|
+
var { page } = _a, props = __rest(_a, ["page"]);
|
|
37
|
+
const { t } = useLocaleContext();
|
|
38
|
+
const [agent] = useAssistantState({ assistantId: page.assistantId });
|
|
39
|
+
const lastParameters = useMemo(() => {
|
|
40
|
+
var _a;
|
|
41
|
+
if (page.sessionId) {
|
|
42
|
+
const { session, messages = [] } = createSessionState({ sessionId: page.sessionId }).getState();
|
|
43
|
+
const lastMessage = messages[messages.length - 1];
|
|
44
|
+
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;
|
|
45
|
+
}
|
|
46
|
+
return undefined;
|
|
47
|
+
}, [page.sessionId]);
|
|
48
|
+
const defaultForm = useMemo(() => {
|
|
49
|
+
var _a, _b;
|
|
50
|
+
return Object.fromEntries((_b = (_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.map((parameter) => [
|
|
51
|
+
parameter.key,
|
|
52
|
+
(lastParameters === null || lastParameters === void 0 ? void 0 : lastParameters[parameter.key]) || parameter.defaultValue,
|
|
53
|
+
])) !== null && _b !== void 0 ? _b : []);
|
|
54
|
+
}, [agent.parameters, lastParameters]);
|
|
55
|
+
const form = useForm({ defaultValues: defaultForm });
|
|
56
|
+
const [error, setError] = useState();
|
|
57
|
+
const { session } = useSessionContext();
|
|
58
|
+
const [submitting, setSubmitting] = useState(false);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
form.reset(defaultForm);
|
|
61
|
+
}, [defaultForm]);
|
|
62
|
+
const onSubmit = (parameters) => __awaiter(this, void 0, void 0, function* () {
|
|
63
|
+
try {
|
|
64
|
+
setSubmitting(true);
|
|
65
|
+
let { sessionId } = page;
|
|
66
|
+
if (!sessionId) {
|
|
67
|
+
const session = yield globalLoadingState.getState().run(() => __awaiter(this, void 0, void 0, function* () {
|
|
68
|
+
const { created: session } = yield createSession({ assistantId: page.assistantId, parameters });
|
|
69
|
+
yield createSessionState({ sessionId: session.id }).getState().load();
|
|
70
|
+
return session;
|
|
71
|
+
}));
|
|
72
|
+
sessionId = session.id;
|
|
73
|
+
page.navigate({ page: 'session', assistantId: page.assistantId, sessionId: session.id });
|
|
74
|
+
}
|
|
75
|
+
const sid = sessionId;
|
|
76
|
+
yield new Promise((resolve, reject) => {
|
|
77
|
+
setTimeout(() => {
|
|
78
|
+
const session = createSessionState({ sessionId: sid }).getState();
|
|
79
|
+
session.execute({ assistantId: page.assistantId, parameters }).then(resolve).catch(reject);
|
|
80
|
+
});
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
catch (error) {
|
|
84
|
+
setError(error);
|
|
85
|
+
throw error;
|
|
86
|
+
}
|
|
87
|
+
finally {
|
|
88
|
+
setSubmitting(false);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
const handleSubmit = (e) => __awaiter(this, void 0, void 0, function* () {
|
|
92
|
+
e.preventDefault();
|
|
93
|
+
if (!session.user) {
|
|
94
|
+
yield new Promise((resolve) => {
|
|
95
|
+
session.login(() => resolve());
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
return form.handleSubmit(onSubmit)(e);
|
|
99
|
+
});
|
|
100
|
+
const openerMessage = (_b = agent.release) === null || _b === void 0 ? void 0 : _b.openerMessage;
|
|
101
|
+
return (_jsxs(Stack, Object.assign({ gap: 10, component: "form" }, props, { onSubmit: handleSubmit, children: [_jsxs(Stack, { gap: 2, children: [_jsx(Stack, { sx: { fontSize: 32, py: 2.5, mb: -2 }, children: "\uD83D\uDC69\uD83C\uDFFB\u200D\uD83D\uDCBB" }), openerMessage && _jsx(Box, { sx: { color: 'text.secondary' }, children: openerMessage }), _jsx(ParameterFormFields, { parameters: agent.parameters, form: form })] }), _jsx(Suspense, { children: _jsxs(Stack, { sx: {
|
|
102
|
+
gap: 1,
|
|
103
|
+
position: 'sticky',
|
|
104
|
+
bottom: 0,
|
|
105
|
+
pb: 1,
|
|
106
|
+
pt: 1,
|
|
107
|
+
// 从上透明到白色 0.72 的径向渐变
|
|
108
|
+
background: (theme) => `linear-gradient(180deg, ${alpha(theme.palette.background.default, 0.1)}, ${alpha(theme.palette.background.default, 1)} 5%)`,
|
|
109
|
+
}, children: [error && _jsx(Alert, { severity: "error", children: error.message }), _jsx(RuntimeFormSubmit, { page: page, type: "submit", variant: "contained", fullWidth: true, loading: submitting, sx: {
|
|
110
|
+
borderRadius: 100,
|
|
111
|
+
height: 44,
|
|
112
|
+
background: 'linear-gradient(90deg, rgb(69, 228, 250) 0%, rgb(138, 69, 250) 52.08%, rgb(250, 69, 188) 100%)',
|
|
113
|
+
}, children: ((_d = (_c = agent.release) === null || _c === void 0 ? void 0 : _c.submitButton) === null || _d === void 0 ? void 0 : _d.title) || t('submit') })] }) })] })));
|
|
114
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { Box, Stack, Typography } from '@mui/material';
|
|
14
|
+
import { Avatar } from '../../../../arcblock/ux';
|
|
15
|
+
export default function RuntimeFormHeader(_a) {
|
|
16
|
+
var _b, _c, _d;
|
|
17
|
+
var { agent } = _a, props = __rest(_a, ["agent"]);
|
|
18
|
+
return (_jsxs(Stack, Object.assign({ direction: "row", justifyContent: "space-between", alignItems: "center", gap: 2, bgcolor: "rgb(246, 242, 255)" }, props, { children: [_jsxs(Stack, { children: [_jsx(Typography, { component: "h5", sx: { fontSize: 32, fontWeight: 700 }, children: ((_b = agent.release) === null || _b === void 0 ? void 0 : _b.title) || agent.name }), _jsx(Typography, { sx: { fontSize: 16, color: 'rgb(147, 151, 161)' }, children: ((_c = agent.release) === null || _c === void 0 ? void 0 : _c.description) || agent.description })] }), _jsx(Stack, { children: _jsx(Box, { component: Avatar, size: 88, src: (_d = agent.release) === null || _d === void 0 ? void 0 : _d.logo, did: blocklet === null || blocklet === void 0 ? void 0 : blocklet.appId, borderRadius: 1 }) })] })));
|
|
19
|
+
}
|
|
@@ -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 } from 'react';
|
|
11
|
+
import { createSession, getSessions } from '../../api/session';
|
|
12
|
+
import useAsync from '../../hooks/useAsync';
|
|
13
|
+
import { useAssistantState } from '../../state/assistant';
|
|
14
|
+
import { globalLoadingState } from '../../state/loading';
|
|
15
|
+
import { createSessionState } from '../../state/session';
|
|
16
|
+
import { parseIdentity } from '../../utils';
|
|
17
|
+
export default function CheckSession({ cacheId, page, autoCreateSession, children, }) {
|
|
18
|
+
const { assistantId, sessionId } = page;
|
|
19
|
+
useAssistantState({ assistantId });
|
|
20
|
+
const result = useAsync(() => {
|
|
21
|
+
if (sessionId && createSessionState({ sessionId }).getState().session)
|
|
22
|
+
return undefined;
|
|
23
|
+
return globalLoadingState.getState().run(() => __awaiter(this, void 0, void 0, function* () {
|
|
24
|
+
var _a;
|
|
25
|
+
if (!sessionId) {
|
|
26
|
+
try {
|
|
27
|
+
// get the last session or create a new session if `autoCreateSession` is enabled
|
|
28
|
+
const { sessions } = yield getSessions(parseIdentity(assistantId, { rejectWhenError: true }));
|
|
29
|
+
const session = (_a = sessions[0]) !== null && _a !== void 0 ? _a : (autoCreateSession ? (yield createSession({ assistantId })).created : undefined);
|
|
30
|
+
if (session) {
|
|
31
|
+
yield createSessionState({ sessionId: session.id, session }).getState().load();
|
|
32
|
+
return [{ page: 'session', assistantId, sessionId: session.id }];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
console.error('get first session or auto create a new session error', { error });
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
try {
|
|
41
|
+
const state = createSessionState({ sessionId });
|
|
42
|
+
yield state.getState().load();
|
|
43
|
+
}
|
|
44
|
+
catch (error) {
|
|
45
|
+
console.error('load session error', { error });
|
|
46
|
+
return [{ page: 'assistant', assistantId, sessionId: undefined }, { replace: true }];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return undefined;
|
|
50
|
+
}));
|
|
51
|
+
}, [sessionId, cacheId]);
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (result)
|
|
54
|
+
page.navigate(...result);
|
|
55
|
+
}, [result, page.navigate]);
|
|
56
|
+
if (result)
|
|
57
|
+
return null;
|
|
58
|
+
return 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,32 @@
|
|
|
1
|
+
import { useCallback, useMemo } from 'react';
|
|
2
|
+
import { useLocation, useNavigate } from 'react-router-dom';
|
|
3
|
+
import { getQuery, withQuery } from 'ufo';
|
|
4
|
+
import { CustomError } from '../error';
|
|
5
|
+
export function useNavigateTo() {
|
|
6
|
+
const location = useLocation();
|
|
7
|
+
return useCallback((query) => withQuery(`${location.pathname}${location.search}`, query), [location]);
|
|
8
|
+
}
|
|
9
|
+
export function useNavigateWithQuery() {
|
|
10
|
+
const to = useNavigateTo();
|
|
11
|
+
const navigate = useNavigate();
|
|
12
|
+
return useCallback((query, options) => {
|
|
13
|
+
navigate(to(Object.assign(Object.assign({}, query), { page: query.page === 'assistant' ? undefined : query.page })), options);
|
|
14
|
+
}, [navigate, to]);
|
|
15
|
+
}
|
|
16
|
+
const PAGES = ['assistant', 'session'];
|
|
17
|
+
function isCurrentPage(page) {
|
|
18
|
+
return PAGES.includes(page);
|
|
19
|
+
}
|
|
20
|
+
export function useCurrentPage(page) {
|
|
21
|
+
const { search } = useLocation();
|
|
22
|
+
const { page: pageParam, assistantId, sessionId, } = useMemo(() => getQuery(search), [search]);
|
|
23
|
+
const navigate = useNavigateWithQuery();
|
|
24
|
+
const currentPage = isCurrentPage(pageParam) ? pageParam : 'assistant';
|
|
25
|
+
if (page && page !== currentPage)
|
|
26
|
+
throw new Error('Invalid page state');
|
|
27
|
+
if (currentPage === 'assistant' && assistantId)
|
|
28
|
+
return { page: currentPage, assistantId, navigate };
|
|
29
|
+
if (currentPage === 'session' && assistantId && sessionId)
|
|
30
|
+
return { page: currentPage, assistantId, sessionId, navigate };
|
|
31
|
+
throw new CustomError(404, 'Missing required query parameters `assistantId`');
|
|
32
|
+
}
|
|
@@ -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,29 @@
|
|
|
1
|
+
const PROMISE_CACHE = {};
|
|
2
|
+
export default function useAsync(fn, keys) {
|
|
3
|
+
const key = keys.join('_');
|
|
4
|
+
let cache = PROMISE_CACHE[key];
|
|
5
|
+
if (!cache) {
|
|
6
|
+
const promise = fn();
|
|
7
|
+
const isPromise = promise instanceof Promise;
|
|
8
|
+
cache = {
|
|
9
|
+
promise: Promise.resolve(promise)
|
|
10
|
+
.then((result) => {
|
|
11
|
+
PROMISE_CACHE[key].result = result;
|
|
12
|
+
})
|
|
13
|
+
.catch((error) => {
|
|
14
|
+
PROMISE_CACHE[key].error = error;
|
|
15
|
+
})
|
|
16
|
+
.finally(() => {
|
|
17
|
+
PROMISE_CACHE[key].done = true;
|
|
18
|
+
}),
|
|
19
|
+
done: !isPromise,
|
|
20
|
+
result: isPromise ? undefined : promise,
|
|
21
|
+
};
|
|
22
|
+
PROMISE_CACHE[key] = cache;
|
|
23
|
+
}
|
|
24
|
+
if (cache.error)
|
|
25
|
+
throw cache.error;
|
|
26
|
+
if (cache.done)
|
|
27
|
+
return cache.result;
|
|
28
|
+
throw cache.promise;
|
|
29
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
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 { Suspense, useCallback, useEffect, useId, useMemo, useState } from 'react';
|
|
13
|
+
import { ErrorBoundary } from 'react-error-boundary';
|
|
14
|
+
import { Toast } from '../../arcblock/ux';
|
|
15
|
+
import { getQuery } from '../../utils';
|
|
16
|
+
import { getAssistant } from './api/assistant';
|
|
17
|
+
import { ChatBot as ChatBotWrapper } from './components/common';
|
|
18
|
+
import RuntimeChat from './components/runtime-chat';
|
|
19
|
+
import RuntimeForm from './components/runtime-form';
|
|
20
|
+
import RuntimeProvider from './components/RuntimeProvider';
|
|
21
|
+
import ScrollView from './components/ScrollView';
|
|
22
|
+
import CheckSession from './components/session/CheckSession';
|
|
23
|
+
import { useSetHeader } from './hooks/header';
|
|
24
|
+
import { useCurrentPage } from './hooks/navigate';
|
|
25
|
+
import { createAssistantState, useAssistantState } from './state/assistant';
|
|
26
|
+
import { parseIdentity } from './utils';
|
|
27
|
+
export function getServerSideProps() {
|
|
28
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
29
|
+
const query = getQuery(globalThis.location.href);
|
|
30
|
+
const assistantId = typeof query.assistantId === 'string' ? query.assistantId : undefined;
|
|
31
|
+
const identity = assistantId ? parseIdentity(assistantId) : undefined;
|
|
32
|
+
const assistant = identity && (yield getAssistant(identity));
|
|
33
|
+
return { props: { preload: assistantId ? { assistantId, assistant } : undefined } };
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
export default function App(props) {
|
|
37
|
+
const cacheId = useId();
|
|
38
|
+
return (_jsx(RuntimeProvider, { children: _jsx(AIRuntime, Object.assign({}, props, { cacheId: cacheId })) }));
|
|
39
|
+
}
|
|
40
|
+
function AIRuntime({ cacheId, preload }) {
|
|
41
|
+
var _a;
|
|
42
|
+
const page = useCurrentPage();
|
|
43
|
+
const { assistantId } = page;
|
|
44
|
+
const [assistant] = useAssistantState({ assistantId });
|
|
45
|
+
useSetHeader({ assistant });
|
|
46
|
+
useMemo(() => {
|
|
47
|
+
// preload assistant from server side props
|
|
48
|
+
if (preload)
|
|
49
|
+
createAssistantState(preload);
|
|
50
|
+
}, []);
|
|
51
|
+
return (_jsx(CheckSession, { cacheId: cacheId, page: page, children: _jsx(ScrollView, { scroller: "window", initialScrollBehavior: "auto", children: _jsx(Stack, { flexGrow: 1, height: "100%", className: "ai-runtime-root", children: ((_a = assistant.release) === null || _a === void 0 ? void 0 : _a.template) === 'form' ? _jsx(RuntimeForm, { page: page }) : _jsx(RuntimeChat, { page: page }) }) }) }));
|
|
52
|
+
}
|
|
53
|
+
export function ChatBot(props) {
|
|
54
|
+
if (!props.assistantId)
|
|
55
|
+
throw new Error('Missing required parameter assistantId');
|
|
56
|
+
const navigate = useCallback((page) => {
|
|
57
|
+
setPage((state) => (Object.assign(Object.assign({}, state), page)));
|
|
58
|
+
}, []);
|
|
59
|
+
const [page, setPage] = useState({
|
|
60
|
+
page: 'assistant',
|
|
61
|
+
assistantId: props.assistantId,
|
|
62
|
+
navigate,
|
|
63
|
+
});
|
|
64
|
+
const cacheId = useId();
|
|
65
|
+
return (_jsx(RuntimeProvider, { children: _jsx(ErrorBoundary, { FallbackComponent: ChatBotErrorView, children: _jsx(Suspense, { children: _jsx(ChatBotWrapper, Object.assign({}, props, { children: _jsx(CheckSession, { cacheId: cacheId, autoCreateSession: true, page: page, children: _jsx(RuntimeChat, { page: page }) }) })) }) }) }));
|
|
66
|
+
}
|
|
67
|
+
function ChatBotErrorView({ error }) {
|
|
68
|
+
useEffect(() => {
|
|
69
|
+
Toast.error(error.message);
|
|
70
|
+
}, [error]);
|
|
71
|
+
return null;
|
|
72
|
+
}
|