@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
|
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
4
4
|
const material_1 = require("@mui/material");
|
|
5
5
|
function ReferenceLinks({ links }) {
|
|
6
|
-
return ((0, jsx_runtime_1.
|
|
6
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Stack, { sx: { wordBreak: 'break-word' }, children: links === null || links === void 0 ? void 0 : links.map((item) => (0, jsx_runtime_1.jsx)(ReferenceLinkItemView, { link: item }, item.url)) }));
|
|
7
7
|
}
|
|
8
8
|
exports.default = ReferenceLinks;
|
|
9
9
|
function ReferenceLinkItemView({ link, }) {
|
|
@@ -32,6 +32,6 @@ function ParameterField(_a) {
|
|
|
32
32
|
select: SelectField_1.default,
|
|
33
33
|
language: LanguageField_1.default,
|
|
34
34
|
}[parameter.type || 'string'] || StringField_1.default;
|
|
35
|
-
return ((0, jsx_runtime_1.jsx)(Field, Object.assign({
|
|
35
|
+
return ((0, jsx_runtime_1.jsx)(Field, Object.assign({ label: parameter === null || parameter === void 0 ? void 0 : parameter.label, helperText: parameter === null || parameter === void 0 ? void 0 : parameter.helper, placeholder: parameter === null || parameter === void 0 ? void 0 : parameter.placeholder }, { parameter }, { size: "small" }, props)));
|
|
36
36
|
}
|
|
37
37
|
exports.default = ParameterField;
|
|
@@ -8,26 +8,38 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
12
|
+
var t = {};
|
|
13
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
14
|
+
t[p] = s[p];
|
|
15
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
16
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
17
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
18
|
+
t[p[i]] = s[p[i]];
|
|
19
|
+
}
|
|
20
|
+
return t;
|
|
21
|
+
};
|
|
11
22
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
23
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
24
|
};
|
|
14
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.EntryListView = void 0;
|
|
15
27
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
16
28
|
const material_1 = require("@mui/material");
|
|
17
29
|
const omit_1 = __importDefault(require("lodash/omit"));
|
|
18
30
|
const react_1 = require("react");
|
|
19
31
|
const session_1 = require("../../../../session");
|
|
20
32
|
const session_2 = require("../../api/session");
|
|
21
|
-
const navigate_1 = require("../../hooks/navigate");
|
|
22
33
|
const assistant_1 = require("../../state/assistant");
|
|
34
|
+
const loading_1 = require("../../state/loading");
|
|
23
35
|
const session_3 = require("../../state/session");
|
|
24
36
|
const MessageSuggestedQuestions_1 = require("../common/MessageSuggestedQuestions");
|
|
25
37
|
const ParameterForm_1 = __importDefault(require("../form/ParameterForm"));
|
|
26
|
-
const GlobalLoading_1 = require("../GlobalLoading");
|
|
27
38
|
const MessageItemView_1 = __importDefault(require("../message/MessageItemView"));
|
|
28
39
|
const PoweredBy_1 = __importDefault(require("../PoweredBy"));
|
|
29
40
|
function InitialForm({ page }) {
|
|
30
41
|
var _a;
|
|
42
|
+
const { assistantId } = page;
|
|
31
43
|
const { session: authSession } = (0, session_1.useSessionContext)();
|
|
32
44
|
const [assistant] = (0, assistant_1.useAssistantState)({ assistantId: page.assistantId });
|
|
33
45
|
const { parameters } = assistant;
|
|
@@ -47,7 +59,6 @@ function InitialForm({ page }) {
|
|
|
47
59
|
}
|
|
48
60
|
return undefined;
|
|
49
61
|
}, [assistant.release]);
|
|
50
|
-
const { assistantId } = (0, navigate_1.useCurrentPage)();
|
|
51
62
|
const [creating, setCreating] = (0, react_1.useState)(false);
|
|
52
63
|
const onSubmit = (...args_1) => __awaiter(this, [...args_1], void 0, function* (parameters = {}, entry) {
|
|
53
64
|
if (!authSession.user) {
|
|
@@ -61,14 +72,14 @@ function InitialForm({ page }) {
|
|
|
61
72
|
return;
|
|
62
73
|
setCreating(true);
|
|
63
74
|
try {
|
|
64
|
-
yield
|
|
75
|
+
yield loading_1.globalLoadingState.getState().run(() => __awaiter(this, void 0, void 0, function* () {
|
|
65
76
|
const { created: session } = yield (0, session_2.createSession)({
|
|
66
77
|
assistantId,
|
|
67
78
|
name: parameters.question,
|
|
68
79
|
parameters: (0, omit_1.default)(parameters, isChat ? ['question'] : []),
|
|
69
80
|
entry,
|
|
70
81
|
});
|
|
71
|
-
(0, session_3.createSessionState)({ sessionId: session.id }).getState().execute({
|
|
82
|
+
(0, session_3.createSessionState)({ sessionId: session.id, session }).getState().execute({
|
|
72
83
|
assistantId,
|
|
73
84
|
parameters,
|
|
74
85
|
});
|
|
@@ -85,10 +96,16 @@ function InitialForm({ page }) {
|
|
|
85
96
|
});
|
|
86
97
|
if (authSession.loading)
|
|
87
98
|
return null;
|
|
88
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [opener && ((0, jsx_runtime_1.jsx)(material_1.Box, { my: 2, children: (0, jsx_runtime_1.jsx)(MessageItemView_1.default, { assistantId: assistantId, hideAvatar: true, assistant: assistant, message: opener }) })), ((_a = assistant.entries) === null || _a === void 0 ? void 0 : _a.length) && ((0, jsx_runtime_1.jsx)(EntryListView, { assistant: assistant, onEntryClick: (entry) => onSubmit(entry.parameters, { id: entry.id, title: entry.title })
|
|
99
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [opener && ((0, jsx_runtime_1.jsx)(material_1.Box, { my: 2, mx: 2, children: (0, jsx_runtime_1.jsx)(MessageItemView_1.default, { assistantId: assistantId, hideAvatar: true, assistant: assistant, message: opener }) })), ((_a = assistant.entries) === null || _a === void 0 ? void 0 : _a.length) && ((0, jsx_runtime_1.jsx)(EntryListView, { assistant: assistant, onEntryClick: (entry) => onSubmit(entry.parameters, { id: entry.id, title: entry.title }), sx: { px: 2 } })), (0, jsx_runtime_1.jsx)(material_1.Box, { flex: 1 }), (0, jsx_runtime_1.jsxs)(material_1.Box, { className: "ai-runtime-form-container", sx: {
|
|
100
|
+
position: 'sticky',
|
|
101
|
+
bottom: 0,
|
|
102
|
+
background: (theme) => `linear-gradient(180deg, ${(0, material_1.alpha)(theme.palette.background.default, 0.1)}, ${(0, material_1.alpha)(theme.palette.background.default, 1)} 16px)`,
|
|
103
|
+
}, children: [(0, jsx_runtime_1.jsx)(ParameterForm_1.default, { assistant: assistant, onSubmit: onSubmit }), error && (0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "error", children: error.message }), (0, jsx_runtime_1.jsx)(PoweredBy_1.default, { assistantId: page.assistantId, sx: { my: 1, px: 2 } })] })] }));
|
|
89
104
|
}
|
|
90
105
|
exports.default = InitialForm;
|
|
91
|
-
function EntryListView(
|
|
92
|
-
var
|
|
93
|
-
|
|
106
|
+
function EntryListView(_a) {
|
|
107
|
+
var _b;
|
|
108
|
+
var { assistant, onEntryClick } = _a, props = __rest(_a, ["assistant", "onEntryClick"]);
|
|
109
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Stack, Object.assign({ gap: 1, alignItems: "flex-start" }, props, { children: (_b = assistant.entries) === null || _b === void 0 ? void 0 : _b.map((entry) => entry.title && ((0, jsx_runtime_1.jsx)(MessageSuggestedQuestions_1.MessageSuggestedQuestion, { onClick: () => onEntryClick === null || onEntryClick === void 0 ? void 0 : onEntryClick(entry), children: entry.title }, entry.title))) })));
|
|
94
110
|
}
|
|
111
|
+
exports.EntryListView = EntryListView;
|
|
@@ -22,14 +22,26 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
22
22
|
__setModuleDefault(result, mod);
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
26
|
+
var t = {};
|
|
27
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
28
|
+
t[p] = s[p];
|
|
29
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
30
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
31
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
32
|
+
t[p[i]] = s[p[i]];
|
|
33
|
+
}
|
|
34
|
+
return t;
|
|
35
|
+
};
|
|
25
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
37
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
27
38
|
const material_1 = require("@mui/material");
|
|
28
39
|
const react_wrap_balancer_1 = __importStar(require("react-wrap-balancer"));
|
|
29
40
|
const ux_1 = require("../../../../arcblock/ux");
|
|
30
|
-
function RuntimeChatHeader(
|
|
31
|
-
var
|
|
32
|
-
|
|
41
|
+
function RuntimeChatHeader(_a) {
|
|
42
|
+
var _b, _c, _d, _e;
|
|
43
|
+
var { assistant } = _a, props = __rest(_a, ["assistant"]);
|
|
44
|
+
return ((0, jsx_runtime_1.jsx)(material_1.Box, Object.assign({ className: "ai-chat-header", pt: 10 }, props, { children: (0, jsx_runtime_1.jsxs)(react_wrap_balancer_1.Provider, { children: [(0, jsx_runtime_1.jsx)(material_1.Box, { sx: { display: 'flex', justifyContent: 'center', alignItems: 'center' }, children: (0, jsx_runtime_1.jsx)(material_1.Box, { component: ux_1.Avatar, className: "logo", size: 100, did: (_b = globalThis.blocklet) === null || _b === void 0 ? void 0 : _b.appId, src: (_c = assistant.release) === null || _c === void 0 ? void 0 : _c.logo, sx: { borderRadius: 1 } }) }), (0, jsx_runtime_1.jsx)(material_1.Typography, { component: "h1", sx: {
|
|
33
45
|
fontWeight: 'bold',
|
|
34
46
|
fontSize: 18,
|
|
35
47
|
mt: 1,
|
|
@@ -43,6 +55,6 @@ function RuntimeChatHeader({ assistant }) {
|
|
|
43
55
|
textAlign: 'center',
|
|
44
56
|
whiteSpace: 'pre-wrap',
|
|
45
57
|
color: '#465566',
|
|
46
|
-
}, children: (0, jsx_runtime_1.jsxs)(react_wrap_balancer_1.default, { children: ["\u200C\u200C\u200C\u200C\u200C\u200C\u200C", ((_e = assistant.release) === null || _e === void 0 ? void 0 : _e.description) || (assistant === null || assistant === void 0 ? void 0 : assistant.description)] }) })] }) }));
|
|
58
|
+
}, children: (0, jsx_runtime_1.jsxs)(react_wrap_balancer_1.default, { children: ["\u200C\u200C\u200C\u200C\u200C\u200C\u200C", ((_e = assistant.release) === null || _e === void 0 ? void 0 : _e.description) || (assistant === null || assistant === void 0 ? void 0 : assistant.description)] }) })] }) })));
|
|
47
59
|
}
|
|
48
60
|
exports.default = RuntimeChatHeader;
|
|
@@ -11,25 +11,12 @@ const assistant_1 = require("../../state/assistant");
|
|
|
11
11
|
const session_1 = require("../../state/session");
|
|
12
12
|
const common_1 = require("../common");
|
|
13
13
|
const ParameterForm_1 = __importDefault(require("../form/ParameterForm"));
|
|
14
|
-
const layout_1 = __importDefault(require("../layout"));
|
|
15
14
|
const MessageListView_1 = __importDefault(require("../message/MessageListView"));
|
|
16
15
|
const PoweredBy_1 = __importDefault(require("../PoweredBy"));
|
|
17
16
|
const ScrollView_1 = require("../ScrollView");
|
|
18
|
-
const
|
|
17
|
+
const InitialForm_1 = require("./InitialForm");
|
|
19
18
|
function RuntimeChatSession({ page }) {
|
|
20
|
-
|
|
21
|
-
return ((0, jsx_runtime_1.jsxs)(layout_1.default, { disableBottomPadding: true, containerProps: {
|
|
22
|
-
sx: {
|
|
23
|
-
display: 'flex',
|
|
24
|
-
flexDirection: 'column',
|
|
25
|
-
justifyContent: 'space-between',
|
|
26
|
-
height: '100%',
|
|
27
|
-
},
|
|
28
|
-
}, children: [(0, jsx_runtime_1.jsx)(RuntimeChatHeader_1.default, { assistant: assistant }), (0, jsx_runtime_1.jsx)(ChatForm, { page: page })] }));
|
|
29
|
-
}
|
|
30
|
-
exports.default = RuntimeChatSession;
|
|
31
|
-
function ChatForm({ page }) {
|
|
32
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
19
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
33
20
|
const [session, state] = (0, session_1.useSessionState)({ sessionId: page.sessionId, required: true });
|
|
34
21
|
const [assistant] = (0, assistant_1.useAssistantState)({ assistantId: page.assistantId });
|
|
35
22
|
const lastMessage = (_a = state.messages) === null || _a === void 0 ? void 0 : _a.slice(-1)[0];
|
|
@@ -52,16 +39,14 @@ function ChatForm({ page }) {
|
|
|
52
39
|
setError(error);
|
|
53
40
|
});
|
|
54
41
|
};
|
|
55
|
-
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(MessageListView_1.default, { className: "ai-chat-message-list", my: 5, assistantId: page.assistantId, sessionId: page.sessionId }),
|
|
42
|
+
return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(MessageListView_1.default, { className: "ai-chat-message-list", my: 5, px: 2, assistantId: page.assistantId, sessionId: page.sessionId }), (0, jsx_runtime_1.jsx)(material_1.Box, { ml: 6.5, mr: 2.5, mt: -4, px: 2, children: (suggestedQuestions === null || suggestedQuestions === void 0 ? void 0 : suggestedQuestions.length) ? ((0, jsx_runtime_1.jsx)(common_1.MessageSuggestedQuestions, { dataSource: suggestedQuestions, onClick: (item) => {
|
|
56
43
|
onSubmit(Object.assign(Object.assign({}, lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters), { question: item.question }));
|
|
57
|
-
} }) })), (0, jsx_runtime_1.jsx)(material_1.Box, { flex: 1 }), (0, jsx_runtime_1.jsxs)(material_1.Box, { className: "ai-
|
|
58
|
-
pt:
|
|
44
|
+
} })) : !((_e = state.messages) === null || _e === void 0 ? void 0 : _e.length) && ((_f = assistant.entries) === null || _f === void 0 ? void 0 : _f.length) ? ((0, jsx_runtime_1.jsx)(InitialForm_1.EntryListView, { assistant: assistant, onEntryClick: (entry) => onSubmit(Object.assign(Object.assign({}, lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters), entry.parameters)) })) : null }), (0, jsx_runtime_1.jsx)(material_1.Box, { flex: 1 }), error && ((0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "error", sx: { mb: 1, mx: 2 }, children: error.message })), (0, jsx_runtime_1.jsxs)(material_1.Box, { className: "ai-runtime-form-container", sx: {
|
|
45
|
+
pt: 2,
|
|
59
46
|
position: 'sticky',
|
|
60
47
|
bottom: 0,
|
|
61
48
|
// 从上透明到白色 0.72 的径向渐变
|
|
62
|
-
background: (theme) => `linear-gradient(180deg, ${(0, material_1.alpha)(theme.palette.background.default, 0.1)}, ${(0, material_1.alpha)(theme.palette.background.default, 1)}
|
|
63
|
-
|
|
64
|
-
backdropFilter: 'blur(60px)',
|
|
65
|
-
},
|
|
66
|
-
}, children: [error && ((0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "error", sx: { mb: 1 }, children: error.message })), (0, jsx_runtime_1.jsx)(ParameterForm_1.default, { sessionId: page.sessionId, defaultValues: (_e = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters) !== null && _e !== void 0 ? _e : session.parameters, assistant: assistant, onSubmit: onSubmit, isSubmitting: state.running, submitButtonTitle: (_g = (_f = assistant.release) === null || _f === void 0 ? void 0 : _f.submitButton) === null || _g === void 0 ? void 0 : _g.title }), (0, jsx_runtime_1.jsx)(PoweredBy_1.default, { assistantId: page.assistantId, sx: { my: 0.5 } })] })] }));
|
|
49
|
+
background: (theme) => `linear-gradient(180deg, ${(0, material_1.alpha)(theme.palette.background.default, 0.1)}, ${(0, material_1.alpha)(theme.palette.background.default, 1)} 16px)`,
|
|
50
|
+
}, children: [(0, jsx_runtime_1.jsx)(ParameterForm_1.default, { sessionId: page.sessionId, defaultValues: lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters, assistant: assistant, onSubmit: onSubmit, isSubmitting: state.running, submitButtonTitle: (_h = (_g = assistant.release) === null || _g === void 0 ? void 0 : _g.submitButton) === null || _h === void 0 ? void 0 : _h.title }), (0, jsx_runtime_1.jsx)(PoweredBy_1.default, { assistantId: page.assistantId, sx: { my: 0.5, px: 2 } })] })] }));
|
|
67
51
|
}
|
|
52
|
+
exports.default = RuntimeChatSession;
|
|
@@ -1,15 +1,28 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
3
|
+
var t = {};
|
|
4
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
5
|
+
t[p] = s[p];
|
|
6
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
7
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
8
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
9
|
+
t[p[i]] = s[p[i]];
|
|
10
|
+
}
|
|
11
|
+
return t;
|
|
12
|
+
};
|
|
2
13
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
14
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
15
|
};
|
|
5
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
17
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
7
|
-
const
|
|
18
|
+
const material_1 = require("@mui/material");
|
|
19
|
+
const assistant_1 = require("../../state/assistant");
|
|
20
|
+
const InitialForm_1 = __importDefault(require("./InitialForm"));
|
|
21
|
+
const RuntimeChatHeader_1 = __importDefault(require("./RuntimeChatHeader"));
|
|
8
22
|
const RuntimeChatSession_1 = __importDefault(require("./RuntimeChatSession"));
|
|
9
|
-
function RuntimeChat(
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
}
|
|
13
|
-
return (0, jsx_runtime_1.jsx)(RuntimeChatHome_1.default, { page: page });
|
|
23
|
+
function RuntimeChat(_a) {
|
|
24
|
+
var { page } = _a, props = __rest(_a, ["page"]);
|
|
25
|
+
const [assistant] = (0, assistant_1.useAssistantState)({ assistantId: page.assistantId });
|
|
26
|
+
return ((0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ flexGrow: 1, width: "100%", height: "100%", maxWidth: 750, mx: "auto", justifyContent: page.page === 'session' ? 'space-between' : 'unset' }, props, { children: [(0, jsx_runtime_1.jsx)(RuntimeChatHeader_1.default, { assistant: assistant, sx: { mx: 2 } }), page.page === 'session' ? (0, jsx_runtime_1.jsx)(RuntimeChatSession_1.default, { page: page }) : (0, jsx_runtime_1.jsx)(InitialForm_1.default, { page: page })] })));
|
|
14
27
|
}
|
|
15
28
|
exports.default = RuntimeChat;
|
|
@@ -32,6 +32,7 @@ const material_2 = require("../../../../mui/material");
|
|
|
32
32
|
const session_1 = require("../../../../session");
|
|
33
33
|
const session_2 = require("../../api/session");
|
|
34
34
|
const assistant_1 = require("../../state/assistant");
|
|
35
|
+
const loading_1 = require("../../state/loading");
|
|
35
36
|
const session_3 = require("../../state/session");
|
|
36
37
|
const ParameterFormFields_1 = __importDefault(require("../form/ParameterFormFields"));
|
|
37
38
|
const RuntimeFormSubmit_1 = __importDefault(require("./RuntimeFormSubmit"));
|
|
@@ -59,22 +60,38 @@ function RuntimeFormForms(_a) {
|
|
|
59
60
|
const form = (0, react_hook_form_1.useForm)({ defaultValues: defaultForm });
|
|
60
61
|
const [error, setError] = (0, react_1.useState)();
|
|
61
62
|
const { session } = (0, session_1.useSessionContext)();
|
|
63
|
+
const [submitting, setSubmitting] = (0, react_1.useState)(false);
|
|
62
64
|
(0, react_1.useEffect)(() => {
|
|
63
65
|
form.reset(defaultForm);
|
|
64
66
|
}, [defaultForm]);
|
|
65
67
|
const onSubmit = (parameters) => __awaiter(this, void 0, void 0, function* () {
|
|
66
68
|
try {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
69
|
+
setSubmitting(true);
|
|
70
|
+
let { sessionId } = page;
|
|
71
|
+
if (!sessionId) {
|
|
72
|
+
const session = yield loading_1.globalLoadingState.getState().run(() => __awaiter(this, void 0, void 0, function* () {
|
|
73
|
+
const { created: session } = yield (0, session_2.createSession)({ assistantId: page.assistantId, parameters });
|
|
74
|
+
yield (0, session_3.createSessionState)({ sessionId: session.id }).getState().load();
|
|
75
|
+
return session;
|
|
76
|
+
}));
|
|
77
|
+
sessionId = session.id;
|
|
78
|
+
page.navigate({ page: 'session', assistantId: page.assistantId, sessionId: session.id });
|
|
79
|
+
}
|
|
80
|
+
const sid = sessionId;
|
|
81
|
+
yield new Promise((resolve, reject) => {
|
|
82
|
+
setTimeout(() => {
|
|
83
|
+
const session = (0, session_3.createSessionState)({ sessionId: sid }).getState();
|
|
84
|
+
session.execute({ assistantId: page.assistantId, parameters }).then(resolve).catch(reject);
|
|
85
|
+
});
|
|
86
|
+
});
|
|
73
87
|
}
|
|
74
88
|
catch (error) {
|
|
75
89
|
setError(error);
|
|
76
90
|
throw error;
|
|
77
91
|
}
|
|
92
|
+
finally {
|
|
93
|
+
setSubmitting(false);
|
|
94
|
+
}
|
|
78
95
|
});
|
|
79
96
|
const handleSubmit = (e) => __awaiter(this, void 0, void 0, function* () {
|
|
80
97
|
e.preventDefault();
|
|
@@ -94,7 +111,7 @@ function RuntimeFormForms(_a) {
|
|
|
94
111
|
pt: 1,
|
|
95
112
|
// 从上透明到白色 0.72 的径向渐变
|
|
96
113
|
background: (theme) => `linear-gradient(180deg, ${(0, material_2.alpha)(theme.palette.background.default, 0.1)}, ${(0, material_2.alpha)(theme.palette.background.default, 1)} 5%)`,
|
|
97
|
-
}, children: [error && (0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "error", children: error.message }), (0, jsx_runtime_1.jsx)(RuntimeFormSubmit_1.default, { page: page, type: "submit", variant: "contained", fullWidth: true, loading:
|
|
114
|
+
}, children: [error && (0, jsx_runtime_1.jsx)(material_1.Alert, { severity: "error", children: error.message }), (0, jsx_runtime_1.jsx)(RuntimeFormSubmit_1.default, { page: page, type: "submit", variant: "contained", fullWidth: true, loading: submitting, sx: {
|
|
98
115
|
borderRadius: 100,
|
|
99
116
|
height: 44,
|
|
100
117
|
background: 'linear-gradient(90deg, rgb(69, 228, 250) 0%, rgb(138, 69, 250) 52.08%, rgb(250, 69, 188) 100%)',
|
|
@@ -8,55 +8,58 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
11
14
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
15
|
const react_1 = require("react");
|
|
13
|
-
const session_1 = require("
|
|
14
|
-
const
|
|
16
|
+
const session_1 = require("../../api/session");
|
|
17
|
+
const useAsync_1 = __importDefault(require("../../hooks/useAsync"));
|
|
15
18
|
const assistant_1 = require("../../state/assistant");
|
|
16
|
-
const
|
|
19
|
+
const loading_1 = require("../../state/loading");
|
|
20
|
+
const session_2 = require("../../state/session");
|
|
17
21
|
const utils_1 = require("../../utils");
|
|
18
|
-
|
|
19
|
-
|
|
22
|
+
function CheckSession({ cacheId, page, autoCreateSession, children, }) {
|
|
23
|
+
const { assistantId, sessionId } = page;
|
|
20
24
|
(0, assistant_1.useAssistantState)({ assistantId });
|
|
21
|
-
const
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (!authSession.user)
|
|
26
|
-
return;
|
|
27
|
-
GlobalLoading_1.globalLoadingState.getState().run(() => __awaiter(this, void 0, void 0, function* () {
|
|
25
|
+
const result = (0, useAsync_1.default)(() => {
|
|
26
|
+
if (sessionId && (0, session_2.createSessionState)({ sessionId }).getState().session)
|
|
27
|
+
return undefined;
|
|
28
|
+
return loading_1.globalLoadingState.getState().run(() => __awaiter(this, void 0, void 0, function* () {
|
|
28
29
|
var _a;
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
30
|
+
if (!sessionId) {
|
|
31
|
+
try {
|
|
32
|
+
// get the last session or create a new session if `autoCreateSession` is enabled
|
|
33
|
+
const { sessions } = yield (0, session_1.getSessions)((0, utils_1.parseIdentity)(assistantId, { rejectWhenError: true }));
|
|
34
|
+
const session = (_a = sessions[0]) !== null && _a !== void 0 ? _a : (autoCreateSession ? (yield (0, session_1.createSession)({ assistantId })).created : undefined);
|
|
35
|
+
if (session) {
|
|
36
|
+
yield (0, session_2.createSessionState)({ sessionId: session.id, session }).getState().load();
|
|
37
|
+
return [{ page: 'session', assistantId, sessionId: session.id }];
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
yield state.getState().load();
|
|
40
|
+
catch (error) {
|
|
41
|
+
console.error('get first session or auto create a new session error', { error });
|
|
43
42
|
}
|
|
44
|
-
setDone(true);
|
|
45
43
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
44
|
+
else {
|
|
45
|
+
try {
|
|
46
|
+
const state = (0, session_2.createSessionState)({ sessionId });
|
|
47
|
+
yield state.getState().load();
|
|
49
48
|
}
|
|
50
|
-
|
|
51
|
-
|
|
49
|
+
catch (error) {
|
|
50
|
+
console.error('load session error', { error });
|
|
51
|
+
return [{ page: 'assistant', assistantId, sessionId: undefined }, { replace: true }];
|
|
52
52
|
}
|
|
53
53
|
}
|
|
54
|
+
return undefined;
|
|
54
55
|
}));
|
|
55
|
-
}, [
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
56
|
+
}, [sessionId, cacheId]);
|
|
57
|
+
(0, react_1.useEffect)(() => {
|
|
58
|
+
if (result)
|
|
59
|
+
page.navigate(...result);
|
|
60
|
+
}, [result, page.navigate]);
|
|
61
|
+
if (result)
|
|
59
62
|
return null;
|
|
60
|
-
return
|
|
63
|
+
return children;
|
|
61
64
|
}
|
|
62
65
|
exports.default = CheckSession;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CustomError = void 0;
|
|
4
|
+
class CustomError extends Error {
|
|
5
|
+
constructor(status, message) {
|
|
6
|
+
super(message);
|
|
7
|
+
this.status = status;
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
exports.CustomError = CustomError;
|
|
@@ -4,6 +4,7 @@ exports.useCurrentPage = exports.useNavigateWithQuery = exports.useNavigateTo =
|
|
|
4
4
|
const react_1 = require("react");
|
|
5
5
|
const react_router_dom_1 = require("react-router-dom");
|
|
6
6
|
const ufo_1 = require("ufo");
|
|
7
|
+
const error_1 = require("../error");
|
|
7
8
|
function useNavigateTo() {
|
|
8
9
|
const location = (0, react_router_dom_1.useLocation)();
|
|
9
10
|
return (0, react_1.useCallback)((query) => (0, ufo_1.withQuery)(`${location.pathname}${location.search}`, query), [location]);
|
|
@@ -32,6 +33,6 @@ function useCurrentPage(page) {
|
|
|
32
33
|
return { page: currentPage, assistantId, navigate };
|
|
33
34
|
if (currentPage === 'session' && assistantId && sessionId)
|
|
34
35
|
return { page: currentPage, assistantId, sessionId, navigate };
|
|
35
|
-
throw new
|
|
36
|
+
throw new error_1.CustomError(404, 'Missing required query parameters `assistantId`');
|
|
36
37
|
}
|
|
37
38
|
exports.useCurrentPage = useCurrentPage;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const PROMISE_CACHE = {};
|
|
4
|
+
function useAsync(fn, keys) {
|
|
5
|
+
const key = keys.join('_');
|
|
6
|
+
let cache = PROMISE_CACHE[key];
|
|
7
|
+
if (!cache) {
|
|
8
|
+
const promise = fn();
|
|
9
|
+
const isPromise = promise instanceof Promise;
|
|
10
|
+
cache = {
|
|
11
|
+
promise: Promise.resolve(promise)
|
|
12
|
+
.then((result) => {
|
|
13
|
+
PROMISE_CACHE[key].result = result;
|
|
14
|
+
})
|
|
15
|
+
.catch((error) => {
|
|
16
|
+
PROMISE_CACHE[key].error = error;
|
|
17
|
+
})
|
|
18
|
+
.finally(() => {
|
|
19
|
+
PROMISE_CACHE[key].done = true;
|
|
20
|
+
}),
|
|
21
|
+
done: !isPromise,
|
|
22
|
+
result: isPromise ? undefined : promise,
|
|
23
|
+
};
|
|
24
|
+
PROMISE_CACHE[key] = cache;
|
|
25
|
+
}
|
|
26
|
+
if (cache.error)
|
|
27
|
+
throw cache.error;
|
|
28
|
+
if (cache.done)
|
|
29
|
+
return cache.result;
|
|
30
|
+
throw cache.promise;
|
|
31
|
+
}
|
|
32
|
+
exports.default = useAsync;
|
|
@@ -16,6 +16,8 @@ exports.ChatBot = exports.getServerSideProps = void 0;
|
|
|
16
16
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
17
17
|
const material_1 = require("@mui/material");
|
|
18
18
|
const react_1 = require("react");
|
|
19
|
+
const react_error_boundary_1 = require("react-error-boundary");
|
|
20
|
+
const ux_1 = require("../../arcblock/ux");
|
|
19
21
|
const utils_1 = require("../../utils");
|
|
20
22
|
const assistant_1 = require("./api/assistant");
|
|
21
23
|
const common_1 = require("./components/common");
|
|
@@ -38,26 +40,23 @@ function getServerSideProps() {
|
|
|
38
40
|
});
|
|
39
41
|
}
|
|
40
42
|
exports.getServerSideProps = getServerSideProps;
|
|
41
|
-
function
|
|
42
|
-
const
|
|
43
|
-
|
|
43
|
+
function App(props) {
|
|
44
|
+
const cacheId = (0, react_1.useId)();
|
|
45
|
+
return ((0, jsx_runtime_1.jsx)(RuntimeProvider_1.default, { children: (0, jsx_runtime_1.jsx)(AIRuntime, Object.assign({}, props, { cacheId: cacheId })) }));
|
|
46
|
+
}
|
|
47
|
+
exports.default = App;
|
|
48
|
+
function AIRuntime({ cacheId, preload }) {
|
|
49
|
+
var _a;
|
|
50
|
+
const page = (0, navigate_1.useCurrentPage)();
|
|
51
|
+
const { assistantId } = page;
|
|
52
|
+
const [assistant] = (0, assistant_2.useAssistantState)({ assistantId });
|
|
53
|
+
(0, header_1.useSetHeader)({ assistant });
|
|
44
54
|
(0, react_1.useMemo)(() => {
|
|
45
55
|
// preload assistant from server side props
|
|
46
56
|
if (preload)
|
|
47
57
|
(0, assistant_2.createAssistantState)(preload);
|
|
48
58
|
}, []);
|
|
49
|
-
return ((0, jsx_runtime_1.jsx)(
|
|
50
|
-
}
|
|
51
|
-
exports.default = AIRuntime;
|
|
52
|
-
function Main() {
|
|
53
|
-
var _a;
|
|
54
|
-
const page = (0, navigate_1.useCurrentPage)();
|
|
55
|
-
const [assistant] = (0, assistant_2.useAssistantState)({ assistantId: page.assistantId });
|
|
56
|
-
(0, header_1.useSetHeader)({ assistant });
|
|
57
|
-
if (((_a = assistant.release) === null || _a === void 0 ? void 0 : _a.template) === 'form') {
|
|
58
|
-
return (0, jsx_runtime_1.jsx)(runtime_form_1.default, { page: page });
|
|
59
|
-
}
|
|
60
|
-
return (0, jsx_runtime_1.jsx)(runtime_chat_1.default, { page: page });
|
|
59
|
+
return ((0, jsx_runtime_1.jsx)(CheckSession_1.default, { cacheId: cacheId, page: page, children: (0, jsx_runtime_1.jsx)(ScrollView_1.default, { scroller: "window", initialScrollBehavior: "auto", children: (0, jsx_runtime_1.jsx)(material_1.Stack, { flexGrow: 1, height: "100%", className: "ai-runtime-root", children: ((_a = assistant.release) === null || _a === void 0 ? void 0 : _a.template) === 'form' ? (0, jsx_runtime_1.jsx)(runtime_form_1.default, { page: page }) : (0, jsx_runtime_1.jsx)(runtime_chat_1.default, { page: page }) }) }) }));
|
|
61
60
|
}
|
|
62
61
|
function ChatBot(props) {
|
|
63
62
|
if (!props.assistantId)
|
|
@@ -70,6 +69,13 @@ function ChatBot(props) {
|
|
|
70
69
|
assistantId: props.assistantId,
|
|
71
70
|
navigate,
|
|
72
71
|
});
|
|
73
|
-
|
|
72
|
+
const cacheId = (0, react_1.useId)();
|
|
73
|
+
return ((0, jsx_runtime_1.jsx)(RuntimeProvider_1.default, { children: (0, jsx_runtime_1.jsx)(react_error_boundary_1.ErrorBoundary, { FallbackComponent: ChatBotErrorView, children: (0, jsx_runtime_1.jsx)(react_1.Suspense, { children: (0, jsx_runtime_1.jsx)(common_1.ChatBot, Object.assign({}, props, { children: (0, jsx_runtime_1.jsx)(CheckSession_1.default, { cacheId: cacheId, autoCreateSession: true, page: page, children: (0, jsx_runtime_1.jsx)(runtime_chat_1.default, { page: page }) }) })) }) }) }));
|
|
74
74
|
}
|
|
75
75
|
exports.ChatBot = ChatBot;
|
|
76
|
+
function ChatBotErrorView({ error }) {
|
|
77
|
+
(0, react_1.useEffect)(() => {
|
|
78
|
+
ux_1.Toast.error(error.message);
|
|
79
|
+
}, [error]);
|
|
80
|
+
return null;
|
|
81
|
+
}
|
|
@@ -122,7 +122,7 @@ exports.translations = {
|
|
|
122
122
|
thanksForSubscription: '感谢您的订阅,现在,您可以开始尽情体验了!',
|
|
123
123
|
clickTheButton: '点我生成 👉',
|
|
124
124
|
cleanSessionTip: '清除会话消息记录',
|
|
125
|
-
poweredBy: '
|
|
125
|
+
poweredBy: '技术支持来自',
|
|
126
126
|
selectPromptToStart: '选择一个提示词开始吧',
|
|
127
127
|
history: '历史记录',
|
|
128
128
|
unnamed: '未命名',
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.globalLoadingState = void 0;
|
|
13
|
+
const zustand_1 = require("zustand");
|
|
14
|
+
const immer_1 = require("zustand/middleware/immer");
|
|
15
|
+
exports.globalLoadingState = (0, zustand_1.create)()((0, immer_1.immer)((set, get) => ({
|
|
16
|
+
loading: false,
|
|
17
|
+
count: 0,
|
|
18
|
+
run: (fn) => __awaiter(void 0, void 0, void 0, function* () {
|
|
19
|
+
try {
|
|
20
|
+
get().start();
|
|
21
|
+
return (yield (typeof fn === 'function' ? fn() : fn));
|
|
22
|
+
}
|
|
23
|
+
finally {
|
|
24
|
+
get().end();
|
|
25
|
+
}
|
|
26
|
+
}),
|
|
27
|
+
start: () => {
|
|
28
|
+
set((state) => {
|
|
29
|
+
state.count += 1;
|
|
30
|
+
state.loading = true;
|
|
31
|
+
});
|
|
32
|
+
},
|
|
33
|
+
end: () => {
|
|
34
|
+
set((state) => {
|
|
35
|
+
state.count = Math.max(0, state.count - 1);
|
|
36
|
+
state.loading = state.count > 0;
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
})));
|
|
@@ -34,7 +34,7 @@ const createSessionState = ({ sessionId, session }) => {
|
|
|
34
34
|
session,
|
|
35
35
|
clearSession: (_b) => __awaiter(void 0, [_b], void 0, function* ({ sessionId }) {
|
|
36
36
|
yield (0, message_1.deleteMessages)({ sessionId });
|
|
37
|
-
get().load();
|
|
37
|
+
yield get().load();
|
|
38
38
|
}),
|
|
39
39
|
updateSession: (_c) => __awaiter(void 0, [_c], void 0, function* ({ parameters }) {
|
|
40
40
|
const { updated } = yield (0, session_1.updateSession)({ sessionId, parameters });
|
|
@@ -19,7 +19,15 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
19
19
|
return t;
|
|
20
20
|
};
|
|
21
21
|
import { createFetch } from '@blocklet/js-sdk';
|
|
22
|
-
|
|
22
|
+
let isDEV = false;
|
|
23
|
+
try {
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
isDEV = import.meta.env.DEV;
|
|
26
|
+
}
|
|
27
|
+
catch (_a) {
|
|
28
|
+
// ignore
|
|
29
|
+
}
|
|
30
|
+
export const fetch = createFetch({}, { lazy: isDEV, lazyTime: 1000 });
|
|
23
31
|
export function request(_a) {
|
|
24
32
|
return __awaiter(this, void 0, void 0, function* () {
|
|
25
33
|
var _b, _c, _d;
|