@blocklet/pages-kit 0.2.291 → 0.2.293
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 +2 -1
- package/lib/cjs/builtin/async/ai-runtime/api/message.js +14 -1
- package/lib/cjs/builtin/async/ai-runtime/api/request.js +5 -3
- package/lib/cjs/builtin/async/ai-runtime/api/session.js +2 -2
- package/lib/cjs/builtin/async/ai-runtime/components/PoweredBy.js +1 -9
- package/lib/cjs/builtin/async/ai-runtime/components/RuntimeProvider.js +1 -1
- package/lib/cjs/builtin/async/ai-runtime/components/ThemeProvider.js +1 -1
- package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterForm.js +4 -4
- package/lib/cjs/builtin/async/ai-runtime/components/form/ParameterFormFields.js +5 -1
- package/lib/cjs/builtin/async/ai-runtime/components/form/QuestionField.js +2 -2
- package/lib/cjs/builtin/async/ai-runtime/components/form/SettingButton.js +16 -9
- package/lib/cjs/builtin/async/ai-runtime/components/message/MessageErrorView.js +14 -3
- package/lib/cjs/builtin/async/ai-runtime/components/message/MessageItemView.js +65 -29
- package/lib/cjs/builtin/async/ai-runtime/components/message/MessageListView.js +6 -5
- package/lib/cjs/builtin/async/ai-runtime/components/parameters/RadioField.js +39 -0
- package/lib/cjs/builtin/async/ai-runtime/components/parameters/SelectField.js +1 -1
- package/lib/cjs/builtin/async/ai-runtime/components/parameters/index.js +5 -1
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/AutoForm/index.js +153 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageErrorView.js +19 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageItemView.js +179 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/ChatOutput/index.js +13 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/PhotoGallery/index.js +129 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/PhotoGalleryItem/index.js +117 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/SimpleChat/index.js +109 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/SimpleOutput/index.js +17 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/components/SimplePage/index.js +87 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/contexts/CurrentAgent.js +27 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/contexts/CurrentMessage.js +19 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/index.js +42 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/state/assistant.js +61 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/state/runtime.js +56 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/state/session.js +213 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime/utils/map-right.js +10 -0
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/InitialForm.js +42 -20
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +12 -5
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +5 -6
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.js +3 -6
- package/lib/cjs/builtin/async/ai-runtime/components/runtime-form/index.js +4 -0
- package/lib/cjs/builtin/async/ai-runtime/components/session/CheckSession.js +16 -7
- package/lib/cjs/builtin/async/ai-runtime/hooks/auth.js +31 -0
- package/lib/cjs/builtin/async/ai-runtime/hooks/header.js +29 -19
- package/lib/cjs/builtin/async/ai-runtime/hooks/subscribe.js +6 -4
- package/lib/cjs/builtin/async/ai-runtime/index.js +38 -30
- package/lib/cjs/builtin/async/ai-runtime/locales/index.js +28 -0
- package/lib/cjs/builtin/async/ai-runtime/state/session.js +15 -18
- package/lib/cjs/builtin/async/ai-runtime/state/subscription.js +4 -4
- package/lib/cjs/components/CustomComponentRenderer/index.js +0 -1
- package/lib/cjs/components/CustomComponentRenderer/state.js +64 -57
- package/lib/cjs/components/index.js +1 -0
- package/lib/esm/builtin/async/ai-runtime/api/assistant.js +2 -1
- package/lib/esm/builtin/async/ai-runtime/api/message.js +14 -1
- package/lib/esm/builtin/async/ai-runtime/api/request.js +5 -3
- package/lib/esm/builtin/async/ai-runtime/api/session.js +2 -2
- package/lib/esm/builtin/async/ai-runtime/components/PoweredBy.js +2 -10
- package/lib/esm/builtin/async/ai-runtime/components/RuntimeProvider.js +1 -1
- package/lib/esm/builtin/async/ai-runtime/components/ThemeProvider.js +2 -2
- package/lib/esm/builtin/async/ai-runtime/components/form/ParameterForm.js +4 -4
- package/lib/esm/builtin/async/ai-runtime/components/form/ParameterFormFields.js +5 -1
- package/lib/esm/builtin/async/ai-runtime/components/form/QuestionField.js +2 -2
- package/lib/esm/builtin/async/ai-runtime/components/form/SettingButton.js +16 -9
- package/lib/esm/builtin/async/ai-runtime/components/message/MessageErrorView.js +14 -3
- package/lib/esm/builtin/async/ai-runtime/components/message/MessageItemView.js +65 -31
- package/lib/esm/builtin/async/ai-runtime/components/message/MessageListView.js +6 -5
- package/lib/esm/builtin/async/ai-runtime/components/parameters/RadioField.js +37 -0
- package/lib/esm/builtin/async/ai-runtime/components/parameters/SelectField.js +1 -1
- package/lib/esm/builtin/async/ai-runtime/components/parameters/index.js +5 -1
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/AutoForm/index.js +146 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageErrorView.js +13 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageItemView.js +149 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/ChatOutput/index.js +7 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/PhotoGallery/index.js +100 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/PhotoGalleryItem/index.js +114 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/SimpleChat/index.js +80 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/SimpleOutput/index.js +11 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/components/SimplePage/index.js +58 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/contexts/CurrentAgent.js +22 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/contexts/CurrentMessage.js +14 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/index.js +36 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/state/assistant.js +56 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/state/runtime.js +52 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/state/session.js +209 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime/utils/map-right.js +7 -0
- package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/InitialForm.js +21 -22
- package/lib/esm/builtin/async/ai-runtime/components/runtime-chat/RuntimeChatSession.js +13 -6
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormForms.js +5 -6
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/RuntimeFormResult.js +3 -6
- package/lib/esm/builtin/async/ai-runtime/components/runtime-form/index.js +4 -0
- package/lib/esm/builtin/async/ai-runtime/components/session/CheckSession.js +9 -0
- package/lib/esm/builtin/async/ai-runtime/hooks/auth.js +27 -0
- package/lib/esm/builtin/async/ai-runtime/hooks/header.js +30 -20
- package/lib/esm/builtin/async/ai-runtime/hooks/subscribe.js +6 -4
- package/lib/esm/builtin/async/ai-runtime/index.js +15 -29
- package/lib/esm/builtin/async/ai-runtime/locales/index.js +28 -0
- package/lib/esm/builtin/async/ai-runtime/state/session.js +17 -20
- package/lib/esm/builtin/async/ai-runtime/state/subscription.js +2 -2
- package/lib/esm/components/CustomComponentRenderer/index.js +0 -1
- package/lib/esm/components/CustomComponentRenderer/state.js +63 -57
- package/lib/esm/components/index.js +1 -0
- package/lib/types/builtin/async/ai-runtime/api/assistant.d.ts +4 -2
- package/lib/types/builtin/async/ai-runtime/api/message.d.ts +9 -2
- package/lib/types/builtin/async/ai-runtime/api/request.d.ts +4 -1
- package/lib/types/builtin/async/ai-runtime/api/session.d.ts +2 -1
- package/lib/types/builtin/async/ai-runtime/components/form/ParameterForm.d.ts +3 -2
- package/lib/types/builtin/async/ai-runtime/components/form/QuestionField.d.ts +3 -2
- package/lib/types/builtin/async/ai-runtime/components/form/SettingButton.d.ts +5 -2
- package/lib/types/builtin/async/ai-runtime/components/message/MessageErrorView.d.ts +4 -5
- package/lib/types/builtin/async/ai-runtime/components/message/MessageItemView.d.ts +11 -4
- package/lib/types/builtin/async/ai-runtime/components/message/MessageListView.d.ts +5 -3
- package/lib/types/builtin/async/ai-runtime/components/parameters/RadioField.d.ts +9 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/AutoForm/index.d.ts +9 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageErrorView.d.ts +3 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/ChatOutput/MessageItemView.d.ts +12 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/ChatOutput/index.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/PhotoGallery/index.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/PhotoGalleryItem/index.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/SimpleChat/index.d.ts +3 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/SimpleOutput/index.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/components/SimplePage/index.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/contexts/CurrentAgent.d.ts +12 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/contexts/CurrentMessage.d.ts +10 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/index.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/state/assistant.d.ts +17 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/state/runtime.d.ts +14 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/state/session.d.ts +29 -0
- package/lib/types/builtin/async/ai-runtime/components/runtime/utils/map-right.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/hooks/auth.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/hooks/subscribe.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/index.d.ts +15 -8
- package/lib/types/builtin/async/ai-runtime/locales/index.d.ts +22 -0
- package/lib/types/builtin/async/ai-runtime/state/assistant.d.ts +0 -2
- package/lib/types/builtin/async/ai-runtime/state/session.d.ts +0 -3
- package/lib/types/builtin/async/ai-runtime/state/subscription.d.ts +1 -1
- package/lib/types/components/CustomComponentRenderer/index.d.ts +0 -1
- package/lib/types/components/CustomComponentRenderer/state.d.ts +2 -3
- package/lib/types/components/index.d.ts +1 -0
- package/lib/types/types/core.d.ts +1 -0
- package/package.json +9 -7
|
@@ -32,11 +32,7 @@ const createSessionState = ({ sessionId, session }) => {
|
|
|
32
32
|
var _a;
|
|
33
33
|
(_a = STATES[sessionId]) !== null && _a !== void 0 ? _a : (STATES[sessionId] = (0, zustand_1.create)()((0, immer_1.immer)((set, get) => ({
|
|
34
34
|
session,
|
|
35
|
-
|
|
36
|
-
yield (0, message_1.deleteMessages)({ sessionId });
|
|
37
|
-
yield get().load();
|
|
38
|
-
}),
|
|
39
|
-
updateSession: (_c) => __awaiter(void 0, [_c], void 0, function* ({ parameters }) {
|
|
35
|
+
updateSession: (_b) => __awaiter(void 0, [_b], void 0, function* ({ parameters }) {
|
|
40
36
|
const { updated } = yield (0, session_1.updateSession)({ sessionId, parameters });
|
|
41
37
|
set((state) => {
|
|
42
38
|
state.session = updated;
|
|
@@ -68,9 +64,9 @@ const createSessionState = ({ sessionId, session }) => {
|
|
|
68
64
|
});
|
|
69
65
|
}
|
|
70
66
|
}),
|
|
71
|
-
execute: (
|
|
72
|
-
var
|
|
73
|
-
var _h, _j, _k, _l
|
|
67
|
+
execute: (_c) => __awaiter(void 0, [_c], void 0, function* ({ assistantId, parameters, onResponseStart, includeSessionParameters, }) {
|
|
68
|
+
var _d, e_1, _e, _f;
|
|
69
|
+
var _g, _h, _j, _k, _l;
|
|
74
70
|
const identity = (0, utils_1.parseIdentity)(assistantId, { rejectWhenError: true });
|
|
75
71
|
let message;
|
|
76
72
|
const childMessages = [];
|
|
@@ -81,7 +77,7 @@ const createSessionState = ({ sessionId, session }) => {
|
|
|
81
77
|
});
|
|
82
78
|
let realParameters = Object.assign(Object.assign({}, parameters), { $clientTime: new Date().toISOString() });
|
|
83
79
|
if (includeSessionParameters) {
|
|
84
|
-
realParameters = Object.assign(Object.assign({}, (
|
|
80
|
+
realParameters = Object.assign(Object.assign({}, (_g = get().session) === null || _g === void 0 ? void 0 : _g.parameters), parameters);
|
|
85
81
|
}
|
|
86
82
|
try {
|
|
87
83
|
const stream = (0, session_1.runAssistant)({
|
|
@@ -91,10 +87,10 @@ const createSessionState = ({ sessionId, session }) => {
|
|
|
91
87
|
});
|
|
92
88
|
let responseStarted = false;
|
|
93
89
|
try {
|
|
94
|
-
for (var
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
const value =
|
|
90
|
+
for (var _m = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = yield stream_1.next(), _d = stream_1_1.done, !_d; _m = true) {
|
|
91
|
+
_f = stream_1_1.value;
|
|
92
|
+
_m = false;
|
|
93
|
+
const value = _f;
|
|
98
94
|
if (!responseStarted) {
|
|
99
95
|
responseStarted = true;
|
|
100
96
|
onResponseStart === null || onResponseStart === void 0 ? void 0 : onResponseStart();
|
|
@@ -104,6 +100,7 @@ const createSessionState = ({ sessionId, session }) => {
|
|
|
104
100
|
message = {
|
|
105
101
|
taskId: value.taskId,
|
|
106
102
|
sessionId,
|
|
103
|
+
assistantId: identity.assistantId,
|
|
107
104
|
parameters,
|
|
108
105
|
createdAt: new Date().toISOString(),
|
|
109
106
|
updatedAt: new Date().toISOString(),
|
|
@@ -132,7 +129,7 @@ const createSessionState = ({ sessionId, session }) => {
|
|
|
132
129
|
msg.result.objects.push({ taskId: value.taskId, data: value.delta.object });
|
|
133
130
|
if (value.delta.object) {
|
|
134
131
|
(_g = state.metadata) !== null && _g !== void 0 ? _g : (state.metadata = {});
|
|
135
|
-
(0, utils_1.deepMerge)(state.metadata, (0, pick_1.default)(value.delta.object, types_1.
|
|
132
|
+
(0, utils_1.deepMerge)(state.metadata, (0, pick_1.default)(value.delta.object, Object.values(types_1.RuntimeOutputVariable)));
|
|
136
133
|
}
|
|
137
134
|
}
|
|
138
135
|
});
|
|
@@ -147,10 +144,10 @@ const createSessionState = ({ sessionId, session }) => {
|
|
|
147
144
|
childMessagesMap[value.taskId] = childMessage;
|
|
148
145
|
childMessages.push(childMessage);
|
|
149
146
|
}
|
|
150
|
-
(
|
|
147
|
+
(_h = childMessage.result) !== null && _h !== void 0 ? _h : (childMessage.result = {});
|
|
151
148
|
childMessage.result.content = (childMessage.result.content || '') + (value.delta.content || '');
|
|
152
|
-
if ((
|
|
153
|
-
childMessage.result.images = ((
|
|
149
|
+
if ((_k = (_j = value.delta) === null || _j === void 0 ? void 0 : _j.images) === null || _k === void 0 ? void 0 : _k.length) {
|
|
150
|
+
childMessage.result.images = ((_l = childMessage.result.images) !== null && _l !== void 0 ? _l : []).concat(value.delta.images);
|
|
154
151
|
}
|
|
155
152
|
set((state) => {
|
|
156
153
|
var _a, _b;
|
|
@@ -177,7 +174,7 @@ const createSessionState = ({ sessionId, session }) => {
|
|
|
177
174
|
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
178
175
|
finally {
|
|
179
176
|
try {
|
|
180
|
-
if (!
|
|
177
|
+
if (!_m && !_d && (_e = stream_1.return)) yield _e.call(stream_1);
|
|
181
178
|
}
|
|
182
179
|
finally { if (e_1) throw e_1.error; }
|
|
183
180
|
}
|
|
@@ -9,12 +9,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
11
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.useSubscriptionState = exports.
|
|
12
|
+
exports.useSubscriptionState = exports.createSubscriptionState = void 0;
|
|
13
13
|
const zustand_1 = require("zustand");
|
|
14
14
|
const immer_1 = require("zustand/middleware/immer");
|
|
15
15
|
const subscription_1 = require("../api/subscription");
|
|
16
16
|
const STATES = {};
|
|
17
|
-
const
|
|
17
|
+
const createSubscriptionState = ({ aid }) => {
|
|
18
18
|
var _a;
|
|
19
19
|
(_a = STATES[aid]) !== null && _a !== void 0 ? _a : (STATES[aid] = (0, zustand_1.create)()((0, immer_1.immer)((set) => ({
|
|
20
20
|
load: () => __awaiter(void 0, void 0, void 0, function* () {
|
|
@@ -38,11 +38,11 @@ const createAssistantState = ({ aid }) => {
|
|
|
38
38
|
}))));
|
|
39
39
|
return STATES[aid];
|
|
40
40
|
};
|
|
41
|
-
exports.
|
|
41
|
+
exports.createSubscriptionState = createSubscriptionState;
|
|
42
42
|
const LOADING_TASKS = {};
|
|
43
43
|
function useSubscriptionState({ aid }) {
|
|
44
44
|
var _a;
|
|
45
|
-
const state = (0, exports.
|
|
45
|
+
const state = (0, exports.createSubscriptionState)({ aid })();
|
|
46
46
|
if (!state.loaded && !state.subscription) {
|
|
47
47
|
(_a = LOADING_TASKS[aid]) !== null && _a !== void 0 ? _a : (LOADING_TASKS[aid] = state.load());
|
|
48
48
|
throw LOADING_TASKS[aid];
|
|
@@ -26,7 +26,6 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
26
26
|
};
|
|
27
27
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
28
28
|
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
29
|
-
require("../../utils/inject-global-components");
|
|
30
29
|
const material_1 = require("@mui/material");
|
|
31
30
|
const react_error_boundary_1 = require("react-error-boundary");
|
|
32
31
|
const property_1 = require("../../utils/property");
|
|
@@ -52,61 +52,66 @@ const types_1 = require("../../types");
|
|
|
52
52
|
const preload_1 = require("../../types/preload");
|
|
53
53
|
const property_1 = require("../../utils/property");
|
|
54
54
|
const PRELOAD_COMPONENTS_STATE = window[preload_1.PreloadComponentsStateGlobalVariableName];
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
if (
|
|
63
|
-
|
|
55
|
+
let states;
|
|
56
|
+
const customComponentStates = () => {
|
|
57
|
+
states !== null && states !== void 0 ? states : (states = (0, zustand_1.create)()((0, immer_1.immer)((set, get) => ({
|
|
58
|
+
state: {
|
|
59
|
+
config: Object.assign({}, PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.config),
|
|
60
|
+
components: Object.fromEntries(Object.entries(Object.assign({}, PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.components)).map(([componentId, preload]) => {
|
|
61
|
+
let Component;
|
|
62
|
+
if (preload.componentModuleGlobalVariable) {
|
|
63
|
+
const m = window[preload.componentModuleGlobalVariable];
|
|
64
|
+
if (typeof m === 'function')
|
|
65
|
+
Component = m();
|
|
66
|
+
}
|
|
67
|
+
return [componentId, Object.assign(Object.assign({}, preload), { Component })];
|
|
68
|
+
})),
|
|
69
|
+
instances: Object.assign({}, PRELOAD_COMPONENTS_STATE === null || PRELOAD_COMPONENTS_STATE === void 0 ? void 0 : PRELOAD_COMPONENTS_STATE.instances),
|
|
70
|
+
},
|
|
71
|
+
getComponent({ instanceId, componentId, locale }) {
|
|
72
|
+
var _a, _b;
|
|
73
|
+
const { config: { supportedLocales }, components, instances, } = get().state;
|
|
74
|
+
if (!(supportedLocales === null || supportedLocales === void 0 ? void 0 : supportedLocales.some((i) => i.locale === locale)))
|
|
75
|
+
return null;
|
|
76
|
+
const c = components[componentId];
|
|
77
|
+
if (!c)
|
|
78
|
+
return null;
|
|
79
|
+
const { component, Component } = c;
|
|
80
|
+
if (!Component)
|
|
81
|
+
return null;
|
|
82
|
+
if (!instanceId) {
|
|
83
|
+
return { component, Component };
|
|
64
84
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (!props)
|
|
88
|
-
return null;
|
|
89
|
-
return { component, Component, props };
|
|
90
|
-
},
|
|
91
|
-
loadComponents(input) {
|
|
92
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
93
|
-
const result = yield loadComponents(input);
|
|
94
|
-
if (result) {
|
|
95
|
-
set((s) => {
|
|
96
|
-
s.state.config = result.config;
|
|
97
|
-
Object.assign(s.state.components, result.components);
|
|
98
|
-
Object.entries(result.instances).forEach(([instanceId, instance]) => {
|
|
99
|
-
var _a, _b;
|
|
100
|
-
var _c, _d;
|
|
101
|
-
(_a = (_c = s.state.instances)[instanceId]) !== null && _a !== void 0 ? _a : (_c[instanceId] = { componentId: instance.componentId });
|
|
102
|
-
(_b = (_d = s.state.instances[instanceId]).locales) !== null && _b !== void 0 ? _b : (_d.locales = {});
|
|
103
|
-
Object.assign(s.state.instances[instanceId].locales, instance.locales);
|
|
85
|
+
const instance = instances[instanceId];
|
|
86
|
+
if (!instance)
|
|
87
|
+
return null;
|
|
88
|
+
const props = (_b = (_a = instance.locales) === null || _a === void 0 ? void 0 : _a[locale]) === null || _b === void 0 ? void 0 : _b.props;
|
|
89
|
+
if (!props)
|
|
90
|
+
return null;
|
|
91
|
+
return { component, Component, props };
|
|
92
|
+
},
|
|
93
|
+
loadComponents(input) {
|
|
94
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
95
|
+
const result = yield loadComponents(input);
|
|
96
|
+
if (result) {
|
|
97
|
+
set((s) => {
|
|
98
|
+
s.state.config = result.config;
|
|
99
|
+
Object.assign(s.state.components, result.components);
|
|
100
|
+
Object.entries(result.instances).forEach(([instanceId, instance]) => {
|
|
101
|
+
var _a, _b;
|
|
102
|
+
var _c, _d;
|
|
103
|
+
(_a = (_c = s.state.instances)[instanceId]) !== null && _a !== void 0 ? _a : (_c[instanceId] = { componentId: instance.componentId });
|
|
104
|
+
(_b = (_d = s.state.instances[instanceId]).locales) !== null && _b !== void 0 ? _b : (_d.locales = {});
|
|
105
|
+
Object.assign(s.state.instances[instanceId].locales, instance.locales);
|
|
106
|
+
});
|
|
104
107
|
});
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
}
|
|
109
|
-
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
},
|
|
111
|
+
}))));
|
|
112
|
+
return states;
|
|
113
|
+
};
|
|
114
|
+
exports.customComponentStates = customComponentStates;
|
|
110
115
|
function loadComponents(input) {
|
|
111
116
|
return __awaiter(this, void 0, void 0, function* () {
|
|
112
117
|
const result = yield (0, api_1.preloadComponents)(Object.assign(Object.assign({}, input), { module: types_1.PreloadComponentScriptModule.ESM }));
|
|
@@ -150,17 +155,19 @@ const COMPONENT_LOADER_MAP = {};
|
|
|
150
155
|
function usePreloadComponent({ instanceId, componentId, properties, locale, dev }) {
|
|
151
156
|
var _a;
|
|
152
157
|
const previousRef = (0, react_1.useRef)();
|
|
153
|
-
const requestLocale = (0, exports.customComponentStates)((s) => { var _a; return ((_a = s.state.config.supportedLocales) === null || _a === void 0 ? void 0 : _a.some((i) => i.locale === locale)) ? locale : undefined; });
|
|
154
|
-
const defaultLocale = (0, exports.customComponentStates)((s) => s.state.config.defaultLocale);
|
|
158
|
+
const requestLocale = (0, exports.customComponentStates)()((s) => { var _a; return ((_a = s.state.config.supportedLocales) === null || _a === void 0 ? void 0 : _a.some((i) => i.locale === locale)) ? locale : undefined; });
|
|
159
|
+
const defaultLocale = (0, exports.customComponentStates)()((s) => s.state.config.defaultLocale);
|
|
155
160
|
const realLocale = requestLocale || defaultLocale;
|
|
156
|
-
const result = (0, exports.customComponentStates)((s) => realLocale ? s.getComponent({ instanceId, componentId, locale: realLocale }) : undefined);
|
|
161
|
+
const result = (0, exports.customComponentStates)()((s) => realLocale ? s.getComponent({ instanceId, componentId, locale: realLocale }) : undefined);
|
|
157
162
|
if (result) {
|
|
158
163
|
previousRef.current = result;
|
|
159
164
|
return result;
|
|
160
165
|
}
|
|
161
166
|
if (realLocale && instanceId) {
|
|
162
167
|
const key = [instanceId, realLocale].join('-');
|
|
163
|
-
(_a = COMPONENT_LOADER_MAP[key]) !== null && _a !== void 0 ? _a : (COMPONENT_LOADER_MAP[key] = exports.customComponentStates
|
|
168
|
+
(_a = COMPONENT_LOADER_MAP[key]) !== null && _a !== void 0 ? _a : (COMPONENT_LOADER_MAP[key] = (0, exports.customComponentStates)()
|
|
169
|
+
.getState()
|
|
170
|
+
.loadComponents({
|
|
164
171
|
mode: dev === null || dev === void 0 ? void 0 : dev.mode,
|
|
165
172
|
locale: realLocale,
|
|
166
173
|
instances: [{ id: instanceId, component: { id: componentId }, properties }],
|
|
@@ -18,6 +18,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
18
18
|
};
|
|
19
19
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
20
|
exports.CustomComponentRenderer = void 0;
|
|
21
|
+
require("../utils/inject-global-components");
|
|
21
22
|
var CustomComponentRenderer_1 = require("./CustomComponentRenderer");
|
|
22
23
|
Object.defineProperty(exports, "CustomComponentRenderer", { enumerable: true, get: function () { return __importDefault(CustomComponentRenderer_1).default; } });
|
|
23
24
|
__exportStar(require("./CustomComponentRenderer"), exports);
|
|
@@ -13,10 +13,11 @@ import { AI_STUDIO_DID } from '../constants';
|
|
|
13
13
|
import { parseIdentity } from '../utils';
|
|
14
14
|
import { request } from './request';
|
|
15
15
|
export function getAssistant(_a) {
|
|
16
|
-
return __awaiter(this, arguments, void 0, function* ({ assistantId: id }) {
|
|
16
|
+
return __awaiter(this, arguments, void 0, function* ({ assistantId: id, working, }) {
|
|
17
17
|
const { projectId, projectRef, assistantId } = parseIdentity(id, { rejectWhenError: true });
|
|
18
18
|
return request({
|
|
19
19
|
url: joinURL(getComponentMountPoint(AI_STUDIO_DID), '/api/projects', projectId, 'refs', projectRef, 'assistants', assistantId),
|
|
20
|
+
query: { working },
|
|
20
21
|
});
|
|
21
22
|
});
|
|
22
23
|
}
|
|
@@ -7,14 +7,27 @@ 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 { joinURL } from 'ufo';
|
|
11
22
|
import { getComponentMountPoint } from '../../../utils';
|
|
12
23
|
import { AI_STUDIO_DID } from '../constants';
|
|
13
24
|
import { request } from './request';
|
|
14
25
|
export function getMessages(_a) {
|
|
15
|
-
return __awaiter(this,
|
|
26
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
27
|
+
var { sessionId } = _a, query = __rest(_a, ["sessionId"]);
|
|
16
28
|
return request({
|
|
17
29
|
url: joinURL(getComponentMountPoint(AI_STUDIO_DID), '/api/sessions', sessionId, 'messages'),
|
|
30
|
+
query,
|
|
18
31
|
});
|
|
19
32
|
});
|
|
20
33
|
}
|
|
@@ -19,6 +19,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
19
19
|
return t;
|
|
20
20
|
};
|
|
21
21
|
import { createFetch } from '@blocklet/js-sdk';
|
|
22
|
+
import { withQuery } from 'ufo';
|
|
23
|
+
import { CustomError } from '../error';
|
|
22
24
|
let isDEV = false;
|
|
23
25
|
try {
|
|
24
26
|
// @ts-ignore
|
|
@@ -31,8 +33,8 @@ export const fetch = createFetch({}, { lazy: isDEV, lazyTime: 1000 });
|
|
|
31
33
|
export function request(_a) {
|
|
32
34
|
return __awaiter(this, void 0, void 0, function* () {
|
|
33
35
|
var _b, _c, _d;
|
|
34
|
-
var { url, body } = _a, init = __rest(_a, ["url", "body"]);
|
|
35
|
-
const result = yield fetch(url, Object.assign(Object.assign({}, init), { headers: {
|
|
36
|
+
var { url, query, body } = _a, init = __rest(_a, ["url", "query", "body"]);
|
|
37
|
+
const result = yield fetch(withQuery(url, query !== null && query !== void 0 ? query : {}), Object.assign(Object.assign({}, init), { headers: {
|
|
36
38
|
'Content-Type': 'application/json',
|
|
37
39
|
}, body: typeof body === 'object' ? JSON.stringify(body) : body }));
|
|
38
40
|
if (!(result.status >= 200 && result.status < 300)) {
|
|
@@ -44,7 +46,7 @@ export function request(_a) {
|
|
|
44
46
|
console.error('parse response error', error);
|
|
45
47
|
}
|
|
46
48
|
const message = (_d = (_c = (_b = json === null || json === void 0 ? void 0 : json.error) === null || _b === void 0 ? void 0 : _b.message) !== null && _c !== void 0 ? _c : json === null || json === void 0 ? void 0 : json.message) !== null && _d !== void 0 ? _d : json === null || json === void 0 ? void 0 : json.error;
|
|
47
|
-
throw new
|
|
49
|
+
throw new CustomError(result.status, typeof message === 'string' ? message : `request error ${result.status}`);
|
|
48
50
|
}
|
|
49
51
|
return result.json();
|
|
50
52
|
});
|
|
@@ -73,7 +73,7 @@ export function deleteSession(_a) {
|
|
|
73
73
|
});
|
|
74
74
|
}
|
|
75
75
|
export function runAssistant(_a) {
|
|
76
|
-
return __asyncGenerator(this, arguments, function* runAssistant_1({ sessionId, identity, parameters, }) {
|
|
76
|
+
return __asyncGenerator(this, arguments, function* runAssistant_1({ sessionId, identity, working, parameters, }) {
|
|
77
77
|
var _b;
|
|
78
78
|
const res = yield __await(fetch(joinURL(getComponentMountPoint(AI_STUDIO_DID), '/api/ai/call'), {
|
|
79
79
|
method: 'POST',
|
|
@@ -81,7 +81,7 @@ export function runAssistant(_a) {
|
|
|
81
81
|
'Content-Type': 'application/json',
|
|
82
82
|
Accept: 'text/event-stream',
|
|
83
83
|
},
|
|
84
|
-
body: JSON.stringify(Object.assign(Object.assign({ sessionId, parameters: Object.assign(Object.assign({}, parameters), { $clientTime: new Date().toISOString() }) }, identity), { ref: identity.projectRef, working
|
|
84
|
+
body: JSON.stringify(Object.assign(Object.assign({ sessionId, parameters: Object.assign(Object.assign({}, parameters), { $clientTime: new Date().toISOString() }) }, identity), { ref: identity.projectRef, working })),
|
|
85
85
|
}));
|
|
86
86
|
if (!(res.status >= 200 && res.status < 300)) {
|
|
87
87
|
let json;
|
|
@@ -9,19 +9,11 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
9
9
|
}
|
|
10
10
|
return t;
|
|
11
11
|
};
|
|
12
|
-
import {
|
|
12
|
+
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
13
13
|
import { Box, Link, Stack, Typography } from '@mui/material';
|
|
14
14
|
import { useLocaleContext } from '../../../locale';
|
|
15
|
-
import { useSubscribeLink } from '../hooks/subscribe';
|
|
16
15
|
export default function PoweredBy(_a) {
|
|
17
16
|
var { assistantId } = _a, props = __rest(_a, ["assistantId"]);
|
|
18
17
|
const { t } = useLocaleContext();
|
|
19
|
-
|
|
20
|
-
return (_jsxs(Stack, Object.assign({ py: 0.5 }, props, { children: [subscribeLink && (_jsxs(Box, { className: "ai-chat-require-subscribe-footer", sx: {
|
|
21
|
-
px: 2,
|
|
22
|
-
fontSize: 12,
|
|
23
|
-
lineHeight: '20px',
|
|
24
|
-
textAlign: 'center',
|
|
25
|
-
color: 'rgba(75, 85, 99, 1)',
|
|
26
|
-
}, children: [t('requireNewSubscriptionFooter'), _jsx(Link, { href: subscribeLink, sx: { ml: 0.5 }, children: t('subscribeNow') })] })), _jsx(Stack, { className: "ai-chat-powered-by", direction: "row", justifyContent: "center", children: _jsxs(Typography, { variant: "caption", sx: { display: 'inline-flex', alignItems: 'center', a: { display: 'inline-flex', alignItems: 'center' } }, children: [_jsxs(Typography, { component: "span", fontSize: 12, color: "text.poweredBy", children: [t('poweredBy'), ' '] }), "\u00A0", _jsxs(Link, { href: "https://www.arcblock.io", target: "_blank", color: "text.poweredBy", children: [_jsx(Box, { component: "img", src: "https://www.arcblock.io/.well-known/service/blocklet/logo", sx: { height: 16, verticalAlign: 'middle', mr: 0.5, borderRadius: 0.5 } }), "ArcBlock"] }), "\u00A0\u00B7\u00A0", _jsxs(Link, { href: "https://www.aigne.io", target: "_blank", color: "text.poweredBy", children: [_jsx(Box, { component: "img", src: "https://www.aigne.io/.well-known/service/blocklet/logo", sx: { height: 16, verticalAlign: 'middle', mr: 0.5, borderRadius: 0.5 } }), "AIGNE"] })] }) })] })));
|
|
18
|
+
return (_jsx(Stack, Object.assign({ py: 0.5 }, props, { children: _jsx(Stack, { className: "ai-chat-powered-by", direction: "row", justifyContent: "center", children: _jsxs(Typography, { variant: "caption", sx: { display: 'inline-flex', alignItems: 'center', a: { display: 'inline-flex', alignItems: 'center' } }, children: [_jsxs(Typography, { component: "span", fontSize: 12, color: "text.poweredBy", children: [t('poweredBy'), ' '] }), "\u00A0", _jsxs(Link, { href: "https://www.arcblock.io", target: "_blank", color: "text.poweredBy", children: [_jsx(Box, { component: "img", src: "https://www.arcblock.io/.well-known/service/blocklet/logo", sx: { height: 16, verticalAlign: 'middle', mr: 0.5, borderRadius: 0.5 } }), "ArcBlock"] }), "\u00A0\u00B7\u00A0", _jsxs(Link, { href: "https://www.aigne.io", target: "_blank", color: "text.poweredBy", children: [_jsx(Box, { component: "img", src: "https://www.aigne.io/.well-known/service/blocklet/logo", sx: { height: 16, verticalAlign: 'middle', mr: 0.5, borderRadius: 0.5 } }), "AIGNE"] })] }) }) })));
|
|
27
19
|
}
|
|
@@ -12,5 +12,5 @@ export default function RuntimeProvider({ children }) {
|
|
|
12
12
|
return (_jsx(LocaleProvider, { translations: translations, locale: locale, fallbackLocale: "en", children: _jsx(ThemeProvider, { children: _jsxs(ErrorBoundary, { FallbackComponent: ErrorRender, children: [_jsx(GlobalLoading, { sx: { position: 'fixed', left: 0, top: 0, width: '100%', zIndex: 'snackbar' } }), _jsx(React.Suspense, { fallback: _jsx(Stack, { flexGrow: 1, alignItems: "center", justifyContent: "center", children: _jsx(CircularProgress, { size: 24 }) }), children: children })] }) }) }));
|
|
13
13
|
}
|
|
14
14
|
function ErrorRender({ error }) {
|
|
15
|
-
return (_jsx(Result,
|
|
15
|
+
return (_jsx(Result, { status: error.status || 'error', description: error.message, sx: { bgcolor: 'transparent', mt: '20%' } }));
|
|
16
16
|
}
|
|
@@ -11,7 +11,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
11
11
|
};
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
import { ArrowDropDownRounded } from '@mui/icons-material';
|
|
14
|
-
import { GlobalStyles, ThemeProvider as MuiThemeProvider, alpha, createTheme, useTheme, } from '@mui/material';
|
|
14
|
+
import { GlobalStyles, ThemeProvider as MuiThemeProvider, alpha, createTheme, inputBaseClasses, useTheme, } from '@mui/material';
|
|
15
15
|
import { useMemo } from 'react';
|
|
16
16
|
export default function ThemeProvider({ children, template, transparentHeaderBg, }) {
|
|
17
17
|
const theme = useTheme();
|
|
@@ -52,7 +52,7 @@ export default function ThemeProvider({ children, template, transparentHeaderBg,
|
|
|
52
52
|
style: ({ theme }) => theme.unstable_sx({
|
|
53
53
|
'.MuiInputBase-root': {
|
|
54
54
|
fieldset: { borderColor: 'rgba(229, 231, 235, 1)' },
|
|
55
|
-
|
|
55
|
+
[`:not(.${inputBaseClasses.disabled}):hover`]: {
|
|
56
56
|
fieldset: {
|
|
57
57
|
border: 'none',
|
|
58
58
|
boxShadow: `0px 0px 0px 4px ${alpha(theme.palette.primary.main, 0.2)}, 0px 0px 0px 1px ${theme.palette.primary.main}`,
|
|
@@ -21,8 +21,9 @@ import QuestionField from './QuestionField';
|
|
|
21
21
|
import SettingButton from './SettingButton';
|
|
22
22
|
export default function ParameterForm(_a) {
|
|
23
23
|
var _b, _c, _d;
|
|
24
|
-
var {
|
|
24
|
+
var { page, disabled, readOnly, onSubmit, defaultValues, hideSubmit, isSubmitting, assistant, submitButtonTitle = (_c = (_b = assistant.release) === null || _b === void 0 ? void 0 : _b.submitButton) === null || _c === void 0 ? void 0 : _c.title, } = _a;
|
|
25
25
|
const { t } = useLocaleContext();
|
|
26
|
+
const { sessionId } = page;
|
|
26
27
|
const parameters = useMemo(() => {
|
|
27
28
|
var _a;
|
|
28
29
|
return (_a = assistant.parameters) === null || _a === void 0 ? void 0 : _a.filter((i) => i.key && !['question', 'datasetId'].includes(i.key) && SUPPORTED_PARAMETER_TYPES.includes(i.type || 'string'));
|
|
@@ -41,9 +42,8 @@ export default function ParameterForm(_a) {
|
|
|
41
42
|
}, [defaultForm]);
|
|
42
43
|
const handleSubmit = (parameters) => __awaiter(this, void 0, void 0, function* () {
|
|
43
44
|
if (onSubmit) {
|
|
44
|
-
form.setFocus('question');
|
|
45
45
|
yield onSubmit(parameters);
|
|
46
|
-
form.reset(
|
|
46
|
+
form.reset(Object.assign(Object.assign({}, parameters), { question: '' }));
|
|
47
47
|
}
|
|
48
48
|
});
|
|
49
49
|
const [expand, setExpand] = useState(false);
|
|
@@ -56,5 +56,5 @@ export default function ParameterForm(_a) {
|
|
|
56
56
|
transform: `rotateX(${expand ? '180deg' : '0deg'})`,
|
|
57
57
|
transition: 'transform .3s ease-in-out',
|
|
58
58
|
} }) }) }), _jsx(Collapse, { in: expand, orientation: "vertical", sx: { maxHeight: '40vh', overflowY: 'auto' }, children: _jsx(ParameterFormFields, { autoFocus: !sessionId, disabled: disabled, readOnly: readOnly, parameters: parameters, form: form, sx: { pb: 2, px: 2 } }) })] })), _jsx(Box, { px: 2, children: !hideSubmit &&
|
|
59
|
-
(isChat ? (_jsx(QuestionField, {
|
|
59
|
+
(isChat ? (_jsx(QuestionField, { page: page, showSettingButton: !!sessionId, assistant: assistant, disabled: disabled, submitButtonTitle: submitButtonTitle || t('send'), readOnly: readOnly, isSubmitting: isSubmitting, form: form, autoFocus: !!sessionId })) : (_jsxs(Stack, { className: "ai-chat-generation-bar", direction: "row", alignItems: "center", justifyContent: "flex-end", gap: 2, children: [page.page === 'session' && _jsx(SettingButton, { form: form, page: page }), _jsx(Box, { flex: 1 }), _jsx(Tooltip, { title: submitButtonTitle, disableInteractive: true, placement: "top", children: _jsx("span", { children: _jsx(LoadingButton, { disabled: disabled, type: "submit", variant: "contained", color: "secondary", loading: form.formState.isSubmitting || isSubmitting, children: submitButtonTitle || t('send') }) }) })] }))) })] }));
|
|
60
60
|
}
|
|
@@ -44,7 +44,11 @@ export default function ParameterFormFields(_a) {
|
|
|
44
44
|
mb: 0.5,
|
|
45
45
|
fontWeight: 500,
|
|
46
46
|
color: 'rgba(18, 22, 24, 1)',
|
|
47
|
-
}, children: (parameter === null || parameter === void 0 ? void 0 : parameter.label) || parameter.key }), _jsx(ParameterField, { inputRef: field.ref, autoFocus: autoFocus && isFirstParameter, readOnly: readOnly, size: "small", hiddenLabel: true, fullWidth: true, label: undefined, parameter: parameter, maxRows: !(parameter === null || parameter === void 0 ? void 0 : parameter.type) || (parameter === null || parameter === void 0 ? void 0 : parameter.type) === 'string' ? 5 : undefined, value: field.value || '', onChange: (value) => field.onChange({ target: { value } }), error: Boolean(fieldState.error), helperText: ((_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message) || (parameter === null || parameter === void 0 ? void 0 : parameter.helper), sx: {
|
|
47
|
+
}, children: (parameter === null || parameter === void 0 ? void 0 : parameter.label) || parameter.key }), _jsx(ParameterField, { inputRef: field.ref, autoFocus: autoFocus && isFirstParameter, readOnly: readOnly, size: "small", hiddenLabel: true, fullWidth: true, label: undefined, parameter: parameter, maxRows: !(parameter === null || parameter === void 0 ? void 0 : parameter.type) || (parameter === null || parameter === void 0 ? void 0 : parameter.type) === 'string' ? 5 : undefined, value: field.value || '', onChange: (value) => field.onChange({ target: { value } }), error: Boolean(fieldState.error), helperText: ((_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message) || (parameter === null || parameter === void 0 ? void 0 : parameter.helper), sx: {
|
|
48
|
+
'& .MuiInputBase-root': {
|
|
49
|
+
bgcolor: 'background.paper',
|
|
50
|
+
},
|
|
51
|
+
} })] }));
|
|
48
52
|
} }) }, parameter.id));
|
|
49
53
|
}) })));
|
|
50
54
|
}
|
|
@@ -6,7 +6,7 @@ import { Controller } from 'react-hook-form';
|
|
|
6
6
|
import { useLocaleContext } from '../../../../locale';
|
|
7
7
|
import LoadingButton from '../LoadingButton';
|
|
8
8
|
import SettingButton from './SettingButton';
|
|
9
|
-
export default function QuestionField({
|
|
9
|
+
export default function QuestionField({ page, assistant, showSettingButton, form, isSubmitting, autoFocus, readOnly, disabled, submitButtonTitle, }) {
|
|
10
10
|
const { t } = useLocaleContext();
|
|
11
11
|
const defaultPlaceholder = t('questionPlaceholder');
|
|
12
12
|
const placeholder = useMemo(() => { var _a, _b; return ((_b = (_a = assistant.parameters) === null || _a === void 0 ? void 0 : _a.find((i) => i.key === 'question')) === null || _b === void 0 ? void 0 : _b.placeholder) || defaultPlaceholder; }, [submitButtonTitle, assistant, defaultPlaceholder]);
|
|
@@ -23,7 +23,7 @@ export default function QuestionField({ sessionId, assistant, showSettingButton,
|
|
|
23
23
|
}, InputProps: {
|
|
24
24
|
readOnly,
|
|
25
25
|
sx: { p: 1, bgcolor: 'white', borderRadius: 1 },
|
|
26
|
-
startAdornment: showSettingButton &&
|
|
26
|
+
startAdornment: showSettingButton && page.page === 'session' && (_jsx(SettingButton, { form: form, page: page, sx: { minWidth: 32, minHeight: 32 }, tabIndex: -1 })),
|
|
27
27
|
className: 'ai-chat-question-field',
|
|
28
28
|
endAdornment: (_jsx(Tooltip, { title: submitButtonTitle, disableInteractive: true, placement: "top", children: _jsx("span", { children: _jsx(LoadingButton, { disabled: disabled, id: "question-submit", ref: submitRef, type: "submit", variant: "contained",
|
|
29
29
|
// @ts-ignore
|
|
@@ -23,12 +23,12 @@ import { Icon } from '@iconify/react';
|
|
|
23
23
|
import { Box, Button, ClickAwayListener, Paper, Popper } from '@mui/material';
|
|
24
24
|
import { useState } from 'react';
|
|
25
25
|
import { useLocaleContext } from '../../../../locale';
|
|
26
|
-
import {
|
|
26
|
+
import { createSession } from '../../api/session';
|
|
27
|
+
import { globalLoadingState } from '../../state/loading';
|
|
27
28
|
import LoadingListItemButton from '../LoadingListItemButton';
|
|
28
29
|
export default function SettingButton(_a) {
|
|
29
|
-
var {
|
|
30
|
+
var { page, form } = _a, props = __rest(_a, ["page", "form"]);
|
|
30
31
|
const { t } = useLocaleContext();
|
|
31
|
-
const [, state] = useSessionState({ sessionId, required: true });
|
|
32
32
|
const [openSetting, setOpenSetting] = useState(false);
|
|
33
33
|
const settingOptions = [
|
|
34
34
|
// {
|
|
@@ -41,15 +41,22 @@ export default function SettingButton(_a) {
|
|
|
41
41
|
// },
|
|
42
42
|
// },
|
|
43
43
|
{
|
|
44
|
-
key: '
|
|
45
|
-
label: t('
|
|
44
|
+
key: 'newSession',
|
|
45
|
+
label: t('newObject', { object: t('session') }),
|
|
46
46
|
onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
47
47
|
form.setFocus('question');
|
|
48
|
-
yield
|
|
49
|
-
|
|
50
|
-
|
|
48
|
+
yield globalLoadingState.getState().run(() => __awaiter(this, void 0, void 0, function* () {
|
|
49
|
+
const { created: session } = yield createSession({
|
|
50
|
+
assistantId: page.assistantId,
|
|
51
|
+
});
|
|
52
|
+
page.navigate({
|
|
53
|
+
page: 'session',
|
|
54
|
+
assistantId: page.assistantId,
|
|
55
|
+
sessionId: session.id,
|
|
56
|
+
});
|
|
57
|
+
}));
|
|
51
58
|
}),
|
|
52
|
-
icon: 'tabler:
|
|
59
|
+
icon: 'tabler:plus',
|
|
53
60
|
sx: {
|
|
54
61
|
color: 'rgba(225, 29, 72, 1)',
|
|
55
62
|
},
|
|
@@ -1,12 +1,18 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { Alert, Box, Button } from '@mui/material';
|
|
3
3
|
import { useLocaleContext } from '../../../../locale';
|
|
4
|
+
import { useLogin } from '../../hooks/auth';
|
|
4
5
|
import { useSubscribeLink } from '../../hooks/subscribe';
|
|
6
|
+
import { useAssistantState } from '../../state/assistant';
|
|
5
7
|
import MarkdownRenderer from '../MarkdownRenderer';
|
|
6
|
-
export default function MessageErrorView({
|
|
8
|
+
export default function MessageErrorView({ page, error }) {
|
|
7
9
|
var _a, _b, _c;
|
|
8
10
|
const { t } = useLocaleContext();
|
|
9
|
-
const
|
|
11
|
+
const [assistant] = useAssistantState(page);
|
|
12
|
+
const { subscribeLink } = useSubscribeLink(page);
|
|
13
|
+
const login = useLogin({ page });
|
|
14
|
+
if (!error)
|
|
15
|
+
return null;
|
|
10
16
|
if (error.type === 'InvalidSubscriptionError') {
|
|
11
17
|
return (_jsxs(Box, { className: "ai-chat-message-error", children: [_jsx(Box, { className: "message-response", children: _jsx(MarkdownRenderer, { children: t('requireNewSubscription', {
|
|
12
18
|
price: (_b = (_a = assistant.release) === null || _a === void 0 ? void 0 : _a.payment) === null || _b === void 0 ? void 0 : _b.price,
|
|
@@ -14,5 +20,10 @@ export default function MessageErrorView({ assistantId, assistant, error, }) {
|
|
|
14
20
|
// @ts-ignore
|
|
15
21
|
_jsx(Button, { variant: "contained", color: "black", href: subscribeLink, children: t('subscribeNow') })) : (_jsx(Box, { className: "message-response", children: t('thanksForSubscription') })) })] }));
|
|
16
22
|
}
|
|
17
|
-
|
|
23
|
+
if (error.status === 401) {
|
|
24
|
+
return (_jsxs(Box, { className: "ai-chat-message-error", children: [_jsx(Box, { className: "message-response", children: _jsx(MarkdownRenderer, { children: t('requireLogin') }) }), _jsx(Box, { mt: 1, children: _jsx(Button, { variant: "contained",
|
|
25
|
+
// @ts-ignore
|
|
26
|
+
color: "black", onClick: login, children: t('loginNow') }) })] }));
|
|
27
|
+
}
|
|
28
|
+
return (_jsx(Alert, { className: "ai-chat-message-error", severity: "error", sx: { mr: 5 }, children: (error.type === 'ReachMaxRoundLimitError' && ((_c = assistant === null || assistant === void 0 ? void 0 : assistant.release) === null || _c === void 0 ? void 0 : _c.reachMaxRoundLimitTip)) || error.message }));
|
|
18
29
|
}
|