@blocklet/pages-kit 0.2.287 → 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/request.js +9 -1
- package/lib/cjs/builtin/async/ai-runtime/components/GlobalLoading.js +2 -38
- package/lib/cjs/builtin/async/ai-runtime/components/LoadingListItemButton.js +3 -5
- package/lib/cjs/builtin/async/ai-runtime/components/RuntimeProvider.js +7 -1
- package/lib/cjs/builtin/async/ai-runtime/components/common/ChatBot.js +10 -11
- package/lib/cjs/builtin/async/ai-runtime/components/common/MessageMetadataRenderer.js +1 -1
- package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterForm.js +53 -12
- package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterFormFields.js +19 -5
- package/lib/cjs/builtin/async/ai-runtime/components/form/QuestionField.js +2 -2
- package/lib/cjs/builtin/async/ai-runtime/components/form/SettingButton.js +9 -4
- package/lib/cjs/builtin/async/ai-runtime/components/message/MessageItemView.js +70 -75
- package/lib/cjs/builtin/async/ai-runtime/components/message/MessageListView.js +2 -3
- package/lib/cjs/builtin/async/ai-runtime/components/message/ReferenceLinks.js +1 -1
- package/lib/cjs/builtin/async/ai-runtime/components/parameters/index.js +1 -1
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/InitialForm.js +26 -9
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHeader.js +16 -4
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +8 -23
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/index.js +19 -6
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +24 -7
- package/lib/cjs/builtin/async/ai-runtime/components/session/CheckSession.js +38 -35
- package/lib/cjs/builtin/async/ai-runtime/error.js +10 -0
- package/lib/cjs/builtin/async/ai-runtime/hooks/navigate.js +2 -1
- package/lib/cjs/builtin/async/ai-runtime/hooks/useAsync.js +32 -0
- package/lib/cjs/builtin/async/ai-runtime/index.js +22 -16
- package/lib/cjs/builtin/async/ai-runtime/locales/index.js +1 -1
- package/lib/cjs/builtin/async/ai-runtime/state/loading.js +39 -0
- package/lib/cjs/builtin/async/ai-runtime/state/session.js +1 -1
- package/lib/esm/builtin/async/ai-runtime/api/request.js +9 -1
- package/lib/esm/builtin/async/ai-runtime/components/GlobalLoading.js +1 -36
- package/lib/esm/builtin/async/ai-runtime/components/LoadingListItemButton.js +4 -6
- package/lib/esm/builtin/async/ai-runtime/components/RuntimeProvider.js +7 -1
- package/lib/esm/builtin/async/ai-runtime/components/common/ChatBot.js +13 -14
- package/lib/esm/builtin/async/ai-runtime/components/common/MessageMetadataRenderer.js +3 -3
- package/lib/esm/builtin/async/ai-runtime/components/form/ParameterForm.js +29 -11
- package/lib/esm/builtin/async/ai-runtime/components/form/ParameterFormFields.js +18 -5
- package/lib/esm/builtin/async/ai-runtime/components/form/QuestionField.js +2 -2
- package/lib/esm/builtin/async/ai-runtime/components/form/SettingButton.js +7 -5
- package/lib/esm/builtin/async/ai-runtime/components/message/MessageItemView.js +70 -75
- package/lib/esm/builtin/async/ai-runtime/components/message/MessageListView.js +2 -3
- package/lib/esm/builtin/async/ai-runtime/components/message/ReferenceLinks.js +3 -3
- package/lib/esm/builtin/async/ai-runtime/components/parameters/index.js +1 -1
- package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/InitialForm.js +24 -9
- package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHeader.js +16 -4
- package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +7 -22
- package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/index.js +20 -7
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +24 -7
- package/lib/esm/builtin/async/ai-runtime/components/session/CheckSession.js +34 -34
- package/lib/esm/builtin/async/ai-runtime/error.js +6 -0
- package/lib/esm/builtin/async/ai-runtime/hooks/navigate.js +2 -1
- package/lib/esm/builtin/async/ai-runtime/hooks/useAsync.js +29 -0
- package/lib/esm/builtin/async/ai-runtime/index.js +23 -17
- package/lib/esm/builtin/async/ai-runtime/locales/index.js +1 -1
- package/lib/esm/builtin/async/ai-runtime/state/loading.js +36 -0
- package/lib/esm/builtin/async/ai-runtime/state/session.js +1 -1
- package/lib/types/builtin/async/ai-runtime/components/GlobalLoading.d.ts +0 -31
- package/lib/types/builtin/async/ai-runtime/components/LoadingListItemButton.d.ts +4 -1
- package/lib/types/builtin/async/ai-runtime/components/form/ParameterFormDialog.d.ts +2 -2
- package/lib/types/builtin/async/ai-runtime/components/form/ParameterFormFields.d.ts +5 -2
- package/lib/types/builtin/async/ai-runtime/components/form/SettingButton.d.ts +4 -2
- package/lib/types/builtin/async/ai-runtime/components/message/MessageItemView.d.ts +1 -3
- package/lib/types/builtin/async/ai-runtime/components/runtime-chat/InitialForm.d.ts +6 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHeader.d.ts +3 -2
- package/lib/types/builtin/async/ai-runtime/components/runtime-chat/index.d.ts +3 -2
- package/lib/types/builtin/async/ai-runtime/components/session/CheckSession.d.ts +4 -5
- package/lib/types/builtin/async/ai-runtime/error.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/hooks/useAsync.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/index.d.ts +1 -1
- package/lib/types/builtin/async/ai-runtime/state/loading.d.ts +10 -0
- package/lib/types/builtin/page/header.d.ts +1 -6
- package/lib/types/components/CustomComponentRenderer/state.d.ts +1 -116
- package/package.json +9 -9
- package/lib/cjs/builtin/async/ai-runtime/components/layout/index.js +0 -15
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHome.js +0 -21
- package/lib/esm/builtin/async/ai-runtime/components/layout/index.js +0 -12
- package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHome.js +0 -15
- package/lib/types/builtin/async/ai-runtime/components/layout/index.d.ts +0 -7
- package/lib/types/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatHome.d.ts +0 -4
|
@@ -7,22 +7,33 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
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
|
+
};
|
|
10
21
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
11
|
-
import { Alert, Box, Stack } from '@mui/material';
|
|
22
|
+
import { Alert, Box, Stack, alpha } from '@mui/material';
|
|
12
23
|
import omit from 'lodash/omit';
|
|
13
24
|
import { useMemo, useState } from 'react';
|
|
14
25
|
import { useSessionContext } from '../../../../session';
|
|
15
26
|
import { createSession } from '../../api/session';
|
|
16
|
-
import { useCurrentPage } from '../../hooks/navigate';
|
|
17
27
|
import { useAssistantState } from '../../state/assistant';
|
|
28
|
+
import { globalLoadingState } from '../../state/loading';
|
|
18
29
|
import { createSessionState } from '../../state/session';
|
|
19
30
|
import { MessageSuggestedQuestion } from '../common/MessageSuggestedQuestions';
|
|
20
31
|
import ParameterForm from '../form/ParameterForm';
|
|
21
|
-
import { globalLoadingState } from '../GlobalLoading';
|
|
22
32
|
import MessageItemView from '../message/MessageItemView';
|
|
23
33
|
import PoweredBy from '../PoweredBy';
|
|
24
34
|
export default function InitialForm({ page }) {
|
|
25
35
|
var _a;
|
|
36
|
+
const { assistantId } = page;
|
|
26
37
|
const { session: authSession } = useSessionContext();
|
|
27
38
|
const [assistant] = useAssistantState({ assistantId: page.assistantId });
|
|
28
39
|
const { parameters } = assistant;
|
|
@@ -42,7 +53,6 @@ export default function InitialForm({ page }) {
|
|
|
42
53
|
}
|
|
43
54
|
return undefined;
|
|
44
55
|
}, [assistant.release]);
|
|
45
|
-
const { assistantId } = useCurrentPage();
|
|
46
56
|
const [creating, setCreating] = useState(false);
|
|
47
57
|
const onSubmit = (...args_1) => __awaiter(this, [...args_1], void 0, function* (parameters = {}, entry) {
|
|
48
58
|
if (!authSession.user) {
|
|
@@ -63,7 +73,7 @@ export default function InitialForm({ page }) {
|
|
|
63
73
|
parameters: omit(parameters, isChat ? ['question'] : []),
|
|
64
74
|
entry,
|
|
65
75
|
});
|
|
66
|
-
createSessionState({ sessionId: session.id }).getState().execute({
|
|
76
|
+
createSessionState({ sessionId: session.id, session }).getState().execute({
|
|
67
77
|
assistantId,
|
|
68
78
|
parameters,
|
|
69
79
|
});
|
|
@@ -80,9 +90,14 @@ export default function InitialForm({ page }) {
|
|
|
80
90
|
});
|
|
81
91
|
if (authSession.loading)
|
|
82
92
|
return null;
|
|
83
|
-
return (_jsxs(_Fragment, { children: [opener && (_jsx(Box, { my: 2, children: _jsx(MessageItemView, { assistantId: assistantId, hideAvatar: true, assistant: assistant, message: opener }) })), ((_a = assistant.entries) === null || _a === void 0 ? void 0 : _a.length) && (_jsx(EntryListView, { assistant: assistant, onEntryClick: (entry) => onSubmit(entry.parameters, { id: entry.id, title: entry.title })
|
|
93
|
+
return (_jsxs(_Fragment, { children: [opener && (_jsx(Box, { my: 2, mx: 2, children: _jsx(MessageItemView, { assistantId: assistantId, hideAvatar: true, assistant: assistant, message: opener }) })), ((_a = assistant.entries) === null || _a === void 0 ? void 0 : _a.length) && (_jsx(EntryListView, { assistant: assistant, onEntryClick: (entry) => onSubmit(entry.parameters, { id: entry.id, title: entry.title }), sx: { px: 2 } })), _jsx(Box, { flex: 1 }), _jsxs(Box, { className: "ai-runtime-form-container", sx: {
|
|
94
|
+
position: 'sticky',
|
|
95
|
+
bottom: 0,
|
|
96
|
+
background: (theme) => `linear-gradient(180deg, ${alpha(theme.palette.background.default, 0.1)}, ${alpha(theme.palette.background.default, 1)} 16px)`,
|
|
97
|
+
}, children: [_jsx(ParameterForm, { assistant: assistant, onSubmit: onSubmit }), error && _jsx(Alert, { severity: "error", children: error.message }), _jsx(PoweredBy, { assistantId: page.assistantId, sx: { my: 1, px: 2 } })] })] }));
|
|
84
98
|
}
|
|
85
|
-
function EntryListView(
|
|
86
|
-
var
|
|
87
|
-
|
|
99
|
+
export function EntryListView(_a) {
|
|
100
|
+
var _b;
|
|
101
|
+
var { assistant, onEntryClick } = _a, props = __rest(_a, ["assistant", "onEntryClick"]);
|
|
102
|
+
return (_jsx(Stack, Object.assign({ gap: 1, alignItems: "flex-start" }, props, { children: (_b = assistant.entries) === null || _b === void 0 ? void 0 : _b.map((entry) => entry.title && (_jsx(MessageSuggestedQuestion, { onClick: () => onEntryClick === null || onEntryClick === void 0 ? void 0 : onEntryClick(entry), children: entry.title }, entry.title))) })));
|
|
88
103
|
}
|
|
@@ -1,10 +1,22 @@
|
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
1
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
13
|
import { Box, Typography } from '@mui/material';
|
|
3
14
|
import Balancer, { Provider } from 'react-wrap-balancer';
|
|
4
15
|
import { Avatar } from '../../../../arcblock/ux';
|
|
5
|
-
export default function RuntimeChatHeader(
|
|
6
|
-
var
|
|
7
|
-
|
|
16
|
+
export default function RuntimeChatHeader(_a) {
|
|
17
|
+
var _b, _c, _d, _e;
|
|
18
|
+
var { assistant } = _a, props = __rest(_a, ["assistant"]);
|
|
19
|
+
return (_jsx(Box, Object.assign({ className: "ai-chat-header", pt: 10 }, props, { children: _jsxs(Provider, { children: [_jsx(Box, { sx: { display: 'flex', justifyContent: 'center', alignItems: 'center' }, children: _jsx(Box, { component: Avatar, className: "logo", size: 100, did: (_b = globalThis.blocklet) === null || _b === void 0 ? void 0 : _b.appId, src: (_c = assistant.release) === null || _c === void 0 ? void 0 : _c.logo, sx: { borderRadius: 1 } }) }), _jsx(Typography, { component: "h1", sx: {
|
|
8
20
|
fontWeight: 'bold',
|
|
9
21
|
fontSize: 18,
|
|
10
22
|
mt: 1,
|
|
@@ -18,5 +30,5 @@ export default function RuntimeChatHeader({ assistant }) {
|
|
|
18
30
|
textAlign: 'center',
|
|
19
31
|
whiteSpace: 'pre-wrap',
|
|
20
32
|
color: '#465566',
|
|
21
|
-
}, children: _jsxs(Balancer, { children: ["\u200C\u200C\u200C\u200C\u200C\u200C\u200C", ((_e = assistant.release) === null || _e === void 0 ? void 0 : _e.description) || (assistant === null || assistant === void 0 ? void 0 : assistant.description)] }) })] }) }));
|
|
33
|
+
}, children: _jsxs(Balancer, { children: ["\u200C\u200C\u200C\u200C\u200C\u200C\u200C", ((_e = assistant.release) === null || _e === void 0 ? void 0 : _e.description) || (assistant === null || assistant === void 0 ? void 0 : assistant.description)] }) })] }) })));
|
|
22
34
|
}
|
|
@@ -6,24 +6,12 @@ import { useAssistantState } from '../../state/assistant';
|
|
|
6
6
|
import { useSessionState } from '../../state/session';
|
|
7
7
|
import { MessageSuggestedQuestions } from '../common';
|
|
8
8
|
import ParameterForm from '../form/ParameterForm';
|
|
9
|
-
import Layout from '../layout';
|
|
10
9
|
import MessageListView from '../message/MessageListView';
|
|
11
10
|
import PoweredBy from '../PoweredBy';
|
|
12
11
|
import { useScrollToBottomModule } from '../ScrollView';
|
|
13
|
-
import
|
|
12
|
+
import { EntryListView } from './InitialForm';
|
|
14
13
|
export default function RuntimeChatSession({ page }) {
|
|
15
|
-
|
|
16
|
-
return (_jsxs(Layout, { disableBottomPadding: true, containerProps: {
|
|
17
|
-
sx: {
|
|
18
|
-
display: 'flex',
|
|
19
|
-
flexDirection: 'column',
|
|
20
|
-
justifyContent: 'space-between',
|
|
21
|
-
height: '100%',
|
|
22
|
-
},
|
|
23
|
-
}, children: [_jsx(RuntimeChatHeader, { assistant: assistant }), _jsx(ChatForm, { page: page })] }));
|
|
24
|
-
}
|
|
25
|
-
function ChatForm({ page }) {
|
|
26
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
14
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
27
15
|
const [session, state] = useSessionState({ sessionId: page.sessionId, required: true });
|
|
28
16
|
const [assistant] = useAssistantState({ assistantId: page.assistantId });
|
|
29
17
|
const lastMessage = (_a = state.messages) === null || _a === void 0 ? void 0 : _a.slice(-1)[0];
|
|
@@ -46,16 +34,13 @@ function ChatForm({ page }) {
|
|
|
46
34
|
setError(error);
|
|
47
35
|
});
|
|
48
36
|
};
|
|
49
|
-
return (_jsxs(_Fragment, { children: [_jsx(MessageListView, { className: "ai-chat-message-list", my: 5, assistantId: page.assistantId, sessionId: page.sessionId }),
|
|
37
|
+
return (_jsxs(_Fragment, { children: [_jsx(MessageListView, { className: "ai-chat-message-list", my: 5, px: 2, assistantId: page.assistantId, sessionId: page.sessionId }), _jsx(Box, { ml: 6.5, mr: 2.5, mt: -4, px: 2, children: (suggestedQuestions === null || suggestedQuestions === void 0 ? void 0 : suggestedQuestions.length) ? (_jsx(MessageSuggestedQuestions, { dataSource: suggestedQuestions, onClick: (item) => {
|
|
50
38
|
onSubmit(Object.assign(Object.assign({}, lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters), { question: item.question }));
|
|
51
|
-
} }) })), _jsx(Box, { flex: 1 }), _jsxs(Box, { className: "ai-
|
|
52
|
-
pt:
|
|
39
|
+
} })) : !((_e = state.messages) === null || _e === void 0 ? void 0 : _e.length) && ((_f = assistant.entries) === null || _f === void 0 ? void 0 : _f.length) ? (_jsx(EntryListView, { assistant: assistant, onEntryClick: (entry) => onSubmit(Object.assign(Object.assign({}, lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters), entry.parameters)) })) : null }), _jsx(Box, { flex: 1 }), error && (_jsx(Alert, { severity: "error", sx: { mb: 1, mx: 2 }, children: error.message })), _jsxs(Box, { className: "ai-runtime-form-container", sx: {
|
|
40
|
+
pt: 2,
|
|
53
41
|
position: 'sticky',
|
|
54
42
|
bottom: 0,
|
|
55
43
|
// 从上透明到白色 0.72 的径向渐变
|
|
56
|
-
background: (theme) => `linear-gradient(180deg, ${alpha(theme.palette.background.default, 0.1)}, ${alpha(theme.palette.background.default, 1)}
|
|
57
|
-
|
|
58
|
-
backdropFilter: 'blur(60px)',
|
|
59
|
-
},
|
|
60
|
-
}, children: [error && (_jsx(Alert, { severity: "error", sx: { mb: 1 }, children: error.message })), _jsx(ParameterForm, { sessionId: page.sessionId, defaultValues: (_e = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters) !== null && _e !== void 0 ? _e : session.parameters, assistant: assistant, onSubmit: onSubmit, isSubmitting: state.running, submitButtonTitle: (_g = (_f = assistant.release) === null || _f === void 0 ? void 0 : _f.submitButton) === null || _g === void 0 ? void 0 : _g.title }), _jsx(PoweredBy, { assistantId: page.assistantId, sx: { my: 0.5 } })] })] }));
|
|
44
|
+
background: (theme) => `linear-gradient(180deg, ${alpha(theme.palette.background.default, 0.1)}, ${alpha(theme.palette.background.default, 1)} 16px)`,
|
|
45
|
+
}, children: [_jsx(ParameterForm, { sessionId: page.sessionId, defaultValues: lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters, assistant: assistant, onSubmit: onSubmit, isSubmitting: state.running, submitButtonTitle: (_h = (_g = assistant.release) === null || _g === void 0 ? void 0 : _g.submitButton) === null || _h === void 0 ? void 0 : _h.title }), _jsx(PoweredBy, { assistantId: page.assistantId, sx: { my: 0.5, px: 2 } })] })] }));
|
|
61
46
|
}
|
|
@@ -1,9 +1,22 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
2
|
+
var t = {};
|
|
3
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
4
|
+
t[p] = s[p];
|
|
5
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
6
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
7
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
8
|
+
t[p[i]] = s[p[i]];
|
|
9
|
+
}
|
|
10
|
+
return t;
|
|
11
|
+
};
|
|
12
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
import { Stack } from '@mui/material';
|
|
14
|
+
import { useAssistantState } from '../../state/assistant';
|
|
15
|
+
import InitialForm from './InitialForm';
|
|
16
|
+
import RuntimeChatHeader from './RuntimeChatHeader';
|
|
3
17
|
import RuntimeChatSession from './RuntimeChatSession';
|
|
4
|
-
export default function RuntimeChat(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
return _jsx(RuntimeChatHome, { page: page });
|
|
18
|
+
export default function RuntimeChat(_a) {
|
|
19
|
+
var { page } = _a, props = __rest(_a, ["page"]);
|
|
20
|
+
const [assistant] = useAssistantState({ assistantId: page.assistantId });
|
|
21
|
+
return (_jsxs(Stack, Object.assign({ flexGrow: 1, width: "100%", height: "100%", maxWidth: 750, mx: "auto", justifyContent: page.page === 'session' ? 'space-between' : 'unset' }, props, { children: [_jsx(RuntimeChatHeader, { assistant: assistant, sx: { mx: 2 } }), page.page === 'session' ? _jsx(RuntimeChatSession, { page: page }) : _jsx(InitialForm, { page: page })] })));
|
|
9
22
|
}
|
|
@@ -27,6 +27,7 @@ import { alpha } from '../../../../mui/material';
|
|
|
27
27
|
import { useSessionContext } from '../../../../session';
|
|
28
28
|
import { createSession } from '../../api/session';
|
|
29
29
|
import { useAssistantState } from '../../state/assistant';
|
|
30
|
+
import { globalLoadingState } from '../../state/loading';
|
|
30
31
|
import { createSessionState } from '../../state/session';
|
|
31
32
|
import ParameterFormFields from '../form/ParameterFormFields';
|
|
32
33
|
import RuntimeFormSubmit from './RuntimeFormSubmit';
|
|
@@ -54,22 +55,38 @@ export default function RuntimeFormForms(_a) {
|
|
|
54
55
|
const form = useForm({ defaultValues: defaultForm });
|
|
55
56
|
const [error, setError] = useState();
|
|
56
57
|
const { session } = useSessionContext();
|
|
58
|
+
const [submitting, setSubmitting] = useState(false);
|
|
57
59
|
useEffect(() => {
|
|
58
60
|
form.reset(defaultForm);
|
|
59
61
|
}, [defaultForm]);
|
|
60
62
|
const onSubmit = (parameters) => __awaiter(this, void 0, void 0, function* () {
|
|
61
63
|
try {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
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
|
+
});
|
|
68
82
|
}
|
|
69
83
|
catch (error) {
|
|
70
84
|
setError(error);
|
|
71
85
|
throw error;
|
|
72
86
|
}
|
|
87
|
+
finally {
|
|
88
|
+
setSubmitting(false);
|
|
89
|
+
}
|
|
73
90
|
});
|
|
74
91
|
const handleSubmit = (e) => __awaiter(this, void 0, void 0, function* () {
|
|
75
92
|
e.preventDefault();
|
|
@@ -89,7 +106,7 @@ export default function RuntimeFormForms(_a) {
|
|
|
89
106
|
pt: 1,
|
|
90
107
|
// 从上透明到白色 0.72 的径向渐变
|
|
91
108
|
background: (theme) => `linear-gradient(180deg, ${alpha(theme.palette.background.default, 0.1)}, ${alpha(theme.palette.background.default, 1)} 5%)`,
|
|
92
|
-
}, children: [error && _jsx(Alert, { severity: "error", children: error.message }), _jsx(RuntimeFormSubmit, { page: page, type: "submit", variant: "contained", fullWidth: true, loading:
|
|
109
|
+
}, children: [error && _jsx(Alert, { severity: "error", children: error.message }), _jsx(RuntimeFormSubmit, { page: page, type: "submit", variant: "contained", fullWidth: true, loading: submitting, sx: {
|
|
93
110
|
borderRadius: 100,
|
|
94
111
|
height: 44,
|
|
95
112
|
background: 'linear-gradient(90deg, rgb(69, 228, 250) 0%, rgb(138, 69, 250) 52.08%, rgb(250, 69, 188) 100%)',
|
|
@@ -7,53 +7,53 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { useEffect
|
|
11
|
-
import { useSessionContext } from '../../../../session';
|
|
10
|
+
import { useEffect } from 'react';
|
|
12
11
|
import { createSession, getSessions } from '../../api/session';
|
|
12
|
+
import useAsync from '../../hooks/useAsync';
|
|
13
13
|
import { useAssistantState } from '../../state/assistant';
|
|
14
|
+
import { globalLoadingState } from '../../state/loading';
|
|
14
15
|
import { createSessionState } from '../../state/session';
|
|
15
16
|
import { parseIdentity } from '../../utils';
|
|
16
|
-
|
|
17
|
-
|
|
17
|
+
export default function CheckSession({ cacheId, page, autoCreateSession, children, }) {
|
|
18
|
+
const { assistantId, sessionId } = page;
|
|
18
19
|
useAssistantState({ assistantId });
|
|
19
|
-
const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
if (!authSession.user)
|
|
24
|
-
return;
|
|
25
|
-
globalLoadingState.getState().run(() => __awaiter(this, void 0, void 0, function* () {
|
|
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* () {
|
|
26
24
|
var _a;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
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 }];
|
|
36
33
|
}
|
|
37
34
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
yield state.getState().load();
|
|
35
|
+
catch (error) {
|
|
36
|
+
console.error('get first session or auto create a new session error', { error });
|
|
41
37
|
}
|
|
42
|
-
setDone(true);
|
|
43
38
|
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
39
|
+
else {
|
|
40
|
+
try {
|
|
41
|
+
const state = createSessionState({ sessionId });
|
|
42
|
+
yield state.getState().load();
|
|
47
43
|
}
|
|
48
|
-
|
|
49
|
-
|
|
44
|
+
catch (error) {
|
|
45
|
+
console.error('load session error', { error });
|
|
46
|
+
return [{ page: 'assistant', assistantId, sessionId: undefined }, { replace: true }];
|
|
50
47
|
}
|
|
51
48
|
}
|
|
49
|
+
return undefined;
|
|
52
50
|
}));
|
|
53
|
-
}, [
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
51
|
+
}, [sessionId, cacheId]);
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (result)
|
|
54
|
+
page.navigate(...result);
|
|
55
|
+
}, [result, page.navigate]);
|
|
56
|
+
if (result)
|
|
57
57
|
return null;
|
|
58
|
-
return
|
|
58
|
+
return children;
|
|
59
59
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useCallback, useMemo } from 'react';
|
|
2
2
|
import { useLocation, useNavigate } from 'react-router-dom';
|
|
3
3
|
import { getQuery, withQuery } from 'ufo';
|
|
4
|
+
import { CustomError } from '../error';
|
|
4
5
|
export function useNavigateTo() {
|
|
5
6
|
const location = useLocation();
|
|
6
7
|
return useCallback((query) => withQuery(`${location.pathname}${location.search}`, query), [location]);
|
|
@@ -27,5 +28,5 @@ export function useCurrentPage(page) {
|
|
|
27
28
|
return { page: currentPage, assistantId, navigate };
|
|
28
29
|
if (currentPage === 'session' && assistantId && sessionId)
|
|
29
30
|
return { page: currentPage, assistantId, sessionId, navigate };
|
|
30
|
-
throw new
|
|
31
|
+
throw new CustomError(404, 'Missing required query parameters `assistantId`');
|
|
31
32
|
}
|
|
@@ -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
|
+
}
|
|
@@ -9,7 +9,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
11
|
import { Stack } from '@mui/material';
|
|
12
|
-
import { useCallback, useMemo, useState } from 'react';
|
|
12
|
+
import { Suspense, useCallback, useEffect, useId, useMemo, useState } from 'react';
|
|
13
|
+
import { ErrorBoundary } from 'react-error-boundary';
|
|
14
|
+
import { Toast } from '../../arcblock/ux';
|
|
13
15
|
import { getQuery } from '../../utils';
|
|
14
16
|
import { getAssistant } from './api/assistant';
|
|
15
17
|
import { ChatBot as ChatBotWrapper } from './components/common';
|
|
@@ -19,7 +21,7 @@ import RuntimeProvider from './components/RuntimeProvider';
|
|
|
19
21
|
import ScrollView from './components/ScrollView';
|
|
20
22
|
import CheckSession from './components/session/CheckSession';
|
|
21
23
|
import { useSetHeader } from './hooks/header';
|
|
22
|
-
import { useCurrentPage
|
|
24
|
+
import { useCurrentPage } from './hooks/navigate';
|
|
23
25
|
import { createAssistantState, useAssistantState } from './state/assistant';
|
|
24
26
|
import { parseIdentity } from './utils';
|
|
25
27
|
export function getServerSideProps() {
|
|
@@ -31,25 +33,22 @@ export function getServerSideProps() {
|
|
|
31
33
|
return { props: { preload: assistantId ? { assistantId, assistant } : undefined } };
|
|
32
34
|
});
|
|
33
35
|
}
|
|
34
|
-
export default function
|
|
35
|
-
const
|
|
36
|
-
|
|
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 });
|
|
37
46
|
useMemo(() => {
|
|
38
47
|
// preload assistant from server side props
|
|
39
48
|
if (preload)
|
|
40
49
|
createAssistantState(preload);
|
|
41
50
|
}, []);
|
|
42
|
-
return (_jsx(
|
|
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 });
|
|
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 }) }) }) }));
|
|
53
52
|
}
|
|
54
53
|
export function ChatBot(props) {
|
|
55
54
|
if (!props.assistantId)
|
|
@@ -62,5 +61,12 @@ export function ChatBot(props) {
|
|
|
62
61
|
assistantId: props.assistantId,
|
|
63
62
|
navigate,
|
|
64
63
|
});
|
|
65
|
-
|
|
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;
|
|
66
72
|
}
|
|
@@ -119,7 +119,7 @@ export const translations = {
|
|
|
119
119
|
thanksForSubscription: '感谢您的订阅,现在,您可以开始尽情体验了!',
|
|
120
120
|
clickTheButton: '点我生成 👉',
|
|
121
121
|
cleanSessionTip: '清除会话消息记录',
|
|
122
|
-
poweredBy: '
|
|
122
|
+
poweredBy: '技术支持来自',
|
|
123
123
|
selectPromptToStart: '选择一个提示词开始吧',
|
|
124
124
|
history: '历史记录',
|
|
125
125
|
unnamed: '未命名',
|
|
@@ -0,0 +1,36 @@
|
|
|
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
|
+
export const globalLoadingState = create()(immer((set, get) => ({
|
|
13
|
+
loading: false,
|
|
14
|
+
count: 0,
|
|
15
|
+
run: (fn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
16
|
+
try {
|
|
17
|
+
get().start();
|
|
18
|
+
return (yield (typeof fn === 'function' ? fn() : fn));
|
|
19
|
+
}
|
|
20
|
+
finally {
|
|
21
|
+
get().end();
|
|
22
|
+
}
|
|
23
|
+
}),
|
|
24
|
+
start: () => {
|
|
25
|
+
set((state) => {
|
|
26
|
+
state.count += 1;
|
|
27
|
+
state.loading = true;
|
|
28
|
+
});
|
|
29
|
+
},
|
|
30
|
+
end: () => {
|
|
31
|
+
set((state) => {
|
|
32
|
+
state.count = Math.max(0, state.count - 1);
|
|
33
|
+
state.loading = state.count > 0;
|
|
34
|
+
});
|
|
35
|
+
},
|
|
36
|
+
})));
|
|
@@ -28,7 +28,7 @@ export const createSessionState = ({ sessionId, session }) => {
|
|
|
28
28
|
session,
|
|
29
29
|
clearSession: (_b) => __awaiter(void 0, [_b], void 0, function* ({ sessionId }) {
|
|
30
30
|
yield deleteMessages({ sessionId });
|
|
31
|
-
get().load();
|
|
31
|
+
yield get().load();
|
|
32
32
|
}),
|
|
33
33
|
updateSession: (_c) => __awaiter(void 0, [_c], void 0, function* ({ parameters }) {
|
|
34
34
|
const { updated } = yield updateSession({ sessionId, parameters });
|
|
@@ -1,33 +1,2 @@
|
|
|
1
1
|
import { LinearProgressProps } from '@mui/material';
|
|
2
2
|
export default function GlobalLoading({ ...props }: LinearProgressProps): import("react/jsx-runtime").JSX.Element | null;
|
|
3
|
-
interface Run<T = any> {
|
|
4
|
-
(fn: Promise<T> | (() => Promise<T>)): Promise<T>;
|
|
5
|
-
}
|
|
6
|
-
export declare const globalLoadingState: import("zustand").UseBoundStore<Omit<import("zustand").StoreApi<{
|
|
7
|
-
loading: boolean;
|
|
8
|
-
count: number;
|
|
9
|
-
run: Run;
|
|
10
|
-
start: () => void;
|
|
11
|
-
end: () => void;
|
|
12
|
-
}>, "setState"> & {
|
|
13
|
-
setState(nextStateOrUpdater: {
|
|
14
|
-
loading: boolean;
|
|
15
|
-
count: number;
|
|
16
|
-
run: Run;
|
|
17
|
-
start: () => void;
|
|
18
|
-
end: () => void;
|
|
19
|
-
} | Partial<{
|
|
20
|
-
loading: boolean;
|
|
21
|
-
count: number;
|
|
22
|
-
run: Run;
|
|
23
|
-
start: () => void;
|
|
24
|
-
end: () => void;
|
|
25
|
-
}> | ((state: {
|
|
26
|
-
loading: boolean;
|
|
27
|
-
count: number;
|
|
28
|
-
run: Run;
|
|
29
|
-
start: () => void;
|
|
30
|
-
end: () => void;
|
|
31
|
-
}) => void), shouldReplace?: boolean | undefined): void;
|
|
32
|
-
}>;
|
|
33
|
-
export {};
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import { ListItemButtonProps } from '@mui/material';
|
|
2
|
-
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
|
+
export default function LoadingListItemButton({ children, confirmation, ...props }: ListItemButtonProps & {
|
|
4
|
+
confirmation?: ReactNode;
|
|
5
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
@@ -19,10 +19,10 @@ export declare const parameterFormDialogState: import("zustand").UseBoundStore<O
|
|
|
19
19
|
callback?: (() => any) | undefined;
|
|
20
20
|
open: () => any;
|
|
21
21
|
close: () => void;
|
|
22
|
-
}> | ((state: {
|
|
22
|
+
}> | ((state: import("immer").WritableDraft<{
|
|
23
23
|
isOpen: boolean;
|
|
24
24
|
callback?: (() => any) | undefined;
|
|
25
25
|
open: () => any;
|
|
26
26
|
close: () => void;
|
|
27
|
-
}) => void), shouldReplace?: boolean | undefined): void;
|
|
27
|
+
}>) => void), shouldReplace?: boolean | undefined): void;
|
|
28
28
|
}>;
|
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { Parameter } from '@blocklet/ai-runtime/types';
|
|
2
|
+
import { StackProps } from '@mui/material';
|
|
2
3
|
import { UseFormReturn } from 'react-hook-form';
|
|
3
|
-
export
|
|
4
|
+
export declare const SUPPORTED_PARAMETER_TYPES: NonNullable<Parameter['type']>[];
|
|
5
|
+
export default function ParameterFormFields({ autoFocus, disabled, readOnly, parameters, form, ...props }: {
|
|
6
|
+
autoFocus?: boolean;
|
|
4
7
|
disabled?: boolean;
|
|
5
8
|
readOnly?: boolean;
|
|
6
9
|
parameters?: Parameter[];
|
|
7
10
|
form: UseFormReturn;
|
|
8
|
-
}): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
} & StackProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { ButtonProps } from '@mui/material';
|
|
2
|
-
|
|
2
|
+
import { UseFormReturn } from 'react-hook-form';
|
|
3
|
+
export default function SettingButton({ sessionId, form, ...props }: {
|
|
3
4
|
sessionId: string;
|
|
4
|
-
|
|
5
|
+
form: UseFormReturn<any>;
|
|
6
|
+
} & Omit<ButtonProps, 'form'>): import("react/jsx-runtime").JSX.Element[];
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
import { Assistant } from '../../api/assistant';
|
|
2
2
|
import { MessageItem } from '../../state/session';
|
|
3
|
-
export default function MessageItemView({ assistantId, assistant, message,
|
|
3
|
+
export default function MessageItemView({ assistantId, assistant, message, hideAvatar, }: {
|
|
4
4
|
assistantId: string;
|
|
5
5
|
assistant: Assistant;
|
|
6
6
|
message: MessageItem;
|
|
7
|
-
previousMessageTime?: string;
|
|
8
|
-
messageTimeType?: 'user' | 'previous';
|
|
9
7
|
hideAvatar?: boolean;
|
|
10
8
|
}): import("react/jsx-runtime").JSX.Element;
|