@blocklet/pages-kit 0.2.317 → 0.2.319

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.
Files changed (52) hide show
  1. package/lib/cjs/builtin/async/ai-runtime/locales/index.js +26 -0
  2. package/lib/cjs/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageErrorView.js +2 -2
  3. package/lib/cjs/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchSourcesView.js +1 -1
  4. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +13 -9
  5. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Input.js +66 -36
  6. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Output.js +190 -57
  7. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Page.js +236 -83
  8. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/components/CodePreview.js +101 -0
  9. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/components/ConfirmDialog.js +60 -0
  10. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/components/Loading.js +152 -0
  11. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/components/PropertiesSetting.js +80 -0
  12. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/components/UserQuestion.js +32 -0
  13. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/contexts/V0Runtime.js +54 -0
  14. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/utils.js +13 -0
  15. package/lib/cjs/builtin/async/ai-runtime/state/session.js +52 -23
  16. package/lib/cjs/components/CustomComponentRenderer/state.js +23 -4
  17. package/lib/cjs/tsconfig.tsbuildinfo +1 -1
  18. package/lib/cjs/utils/inject-global-components-dump-json.js +1 -1
  19. package/lib/esm/builtin/async/ai-runtime/locales/index.js +26 -0
  20. package/lib/esm/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageErrorView.js +2 -2
  21. package/lib/esm/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchSourcesView.js +1 -1
  22. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +16 -12
  23. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Input.js +60 -30
  24. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Output.js +191 -58
  25. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Page.js +236 -83
  26. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/components/CodePreview.js +92 -0
  27. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/components/ConfirmDialog.js +55 -0
  28. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/components/Loading.js +144 -0
  29. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/components/PropertiesSetting.js +75 -0
  30. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/components/UserQuestion.js +26 -0
  31. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/contexts/V0Runtime.js +49 -0
  32. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/utils.js +9 -0
  33. package/lib/esm/builtin/async/ai-runtime/state/session.js +52 -23
  34. package/lib/esm/components/CustomComponentRenderer/state.js +22 -4
  35. package/lib/esm/tsconfig.tsbuildinfo +1 -1
  36. package/lib/esm/utils/inject-global-components-dump-json.js +1 -1
  37. package/lib/types/builtin/async/ai-runtime/api/session.d.ts +1 -0
  38. package/lib/types/builtin/async/ai-runtime/locales/index.d.ts +26 -0
  39. package/lib/types/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageErrorView.d.ts +2 -1
  40. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/Input.d.ts +1 -1
  41. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/components/CodePreview.d.ts +20 -0
  42. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/components/ConfirmDialog.d.ts +6 -0
  43. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/components/Loading.d.ts +3 -0
  44. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/components/PropertiesSetting.d.ts +6 -0
  45. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/components/UserQuestion.d.ts +3 -0
  46. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/contexts/V0Runtime.d.ts +16 -0
  47. package/lib/types/builtin/async/ai-runtime/runtime-components/V0/utils.d.ts +7 -0
  48. package/lib/types/builtin/async/ai-runtime/state/session.d.ts +11 -3
  49. package/lib/types/components/CustomComponentRenderer/state.d.ts +1 -0
  50. package/lib/types/tsconfig.tsbuildinfo +1 -1
  51. package/lib/types/types/core.d.ts +2 -1
  52. package/package.json +7 -7
@@ -0,0 +1,144 @@
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 } from "react/jsx-runtime";
13
+ import Spinner from '@arcblock/ux/lib/Spinner';
14
+ import { Box, Skeleton } from '@mui/material';
15
+ export default function Loading(props) {
16
+ const { sx } = props, restProps = __rest(props, ["sx"]);
17
+ return (_jsx(Box, Object.assign({ sx: Object.assign({ flex: 1, display: 'flex', justifyContent: 'center', alignItems: 'center', position: 'fixed', top: 0, left: 0, width: '100vw', height: '100vh', backgroundColor: 'rgba(255, 255, 255, 0.8)' }, sx) }, restProps, { children: _jsx(Spinner, {}) })));
18
+ }
19
+ export function AIRunningLoading(props) {
20
+ const { sx } = props, restProps = __rest(props, ["sx"]);
21
+ const animationTimeList = [
22
+ {
23
+ time: 2,
24
+ width: 60,
25
+ height: 60,
26
+ extraProps: {
27
+ variant: 'circular',
28
+ sx: {
29
+ backgroundColor: 'grey.200',
30
+ },
31
+ },
32
+ },
33
+ {
34
+ time: 3,
35
+ width: 100,
36
+ height: 20,
37
+ extraProps: {
38
+ sx: {
39
+ backgroundColor: 'grey.100',
40
+ },
41
+ },
42
+ },
43
+ {
44
+ time: 2,
45
+ width: 250,
46
+ height: 10,
47
+ extraProps: {
48
+ sx: {
49
+ backgroundColor: 'grey.200',
50
+ },
51
+ },
52
+ },
53
+ {
54
+ time: 4,
55
+ width: 150,
56
+ height: 10,
57
+ extraProps: {
58
+ sx: {
59
+ backgroundColor: 'grey.200',
60
+ },
61
+ },
62
+ },
63
+ {
64
+ time: 8,
65
+ width: '100%',
66
+ height: '100%',
67
+ Component: Box,
68
+ extraProps: {
69
+ children: [
70
+ _jsx(Skeleton, { variant: "rectangular", sx: {
71
+ width: 60,
72
+ height: 50,
73
+ borderRadius: 1,
74
+ backgroundColor: 'grey.200',
75
+ } }),
76
+ _jsx(Skeleton, { variant: "rectangular", sx: {
77
+ width: 120,
78
+ height: 50,
79
+ borderRadius: 1,
80
+ backgroundColor: 'grey.200',
81
+ } }),
82
+ _jsx(Skeleton, { variant: "rectangular", sx: {
83
+ width: 180,
84
+ height: 50,
85
+ borderRadius: 1,
86
+ backgroundColor: 'grey.200',
87
+ } }),
88
+ ],
89
+ sx: {
90
+ p: 2,
91
+ display: 'flex',
92
+ gap: 1.5,
93
+ justifyContent: 'space-between',
94
+ },
95
+ },
96
+ },
97
+ {
98
+ time: 60,
99
+ width: 500,
100
+ height: 150,
101
+ extraProps: {
102
+ sx: {
103
+ backgroundColor: 'grey.200',
104
+ },
105
+ },
106
+ },
107
+ ];
108
+ return (_jsx(Box, Object.assign({ sx: Object.assign({ flex: 1, display: 'inline-flex', justifyContent: 'center', alignItems: 'center', backgroundColor: 'white', flexDirection: 'column', gap: 1.5, '@keyframes loading': {
109
+ '0%': {
110
+ transform: 'translateY(-8px) scaleX(1.3)',
111
+ opacity: 0,
112
+ height: '100%',
113
+ },
114
+ '50%': {
115
+ transform: 'translateY(0px)',
116
+ opacity: 0.5,
117
+ zoom: 1,
118
+ height: '100%',
119
+ },
120
+ '100%': {
121
+ transform: 'translateY(4px)',
122
+ opacity: 1,
123
+ zoom: 1,
124
+ height: '100%',
125
+ },
126
+ } }, sx) }, restProps, { children: animationTimeList.map((item, index) => {
127
+ // 计算 index 之前的累计时间之和,作为动画延迟时间
128
+ const delay = animationTimeList.slice(0, index).reduce((prev, current) => prev + current.time, 0);
129
+ const { time, width, height, Component = Skeleton } = item, _a = item.extraProps, _b = _a === void 0 ? {} : _a, { sx } = _b, restSkeletonProps = __rest(_b, ["sx"]);
130
+ const isLast = index === animationTimeList.length - 1;
131
+ return (_jsx(Box, { sx: {
132
+ animation: `loading ${time}s 1 ${delay}s forwards`,
133
+ borderRadius: 1,
134
+ overflow: 'hidden',
135
+ opacity: 0,
136
+ transition: 'all 0.3s',
137
+ }, children: _jsx(Component
138
+ // @ts-ignore
139
+ , Object.assign({
140
+ // @ts-ignore
141
+ variant: "rectangular", sx: Object.assign({ width,
142
+ height, animationIterationCount: isLast ? 'infinite' : 1, animationFillMode: isLast ? 'forwards' : 'none' }, sx) }, restSkeletonProps)) }, index));
143
+ }) })));
144
+ }
@@ -0,0 +1,75 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Alert, Box, Stack, Switch, TextField, Typography } from '@mui/material';
3
+ import { forwardRef, useEffect, useImperativeHandle, useRef } from 'react';
4
+ import { useLocaleContext } from '../../../../../locale';
5
+ import ConfirmDialog from './ConfirmDialog';
6
+ const FieldComponentMap = {
7
+ number: {
8
+ Filed: TextField,
9
+ extraProps: {
10
+ type: 'number',
11
+ },
12
+ },
13
+ boolean: {
14
+ Filed: Switch,
15
+ },
16
+ json: {
17
+ Filed: TextField,
18
+ extraProps: {
19
+ multiline: true,
20
+ minRows: 3,
21
+ maxRows: 5,
22
+ },
23
+ },
24
+ url: {
25
+ Filed: TextField,
26
+ },
27
+ string: {
28
+ Filed: TextField,
29
+ },
30
+ };
31
+ const PropertiesSetting = forwardRef((props, ref) => {
32
+ const { t, locale } = useLocaleContext();
33
+ const ConfirmDialogRef = useRef();
34
+ const valuesRef = useRef({});
35
+ const openParamsRef = useRef({});
36
+ const open = (params) => {
37
+ var _a;
38
+ if (!(ConfirmDialogRef === null || ConfirmDialogRef === void 0 ? void 0 : ConfirmDialogRef.current))
39
+ return;
40
+ openParamsRef.current = params;
41
+ ConfirmDialogRef.current.open({
42
+ title: t('v0.propertiesSetting'),
43
+ children: (_jsxs(Box, { children: [_jsx(Alert, { severity: "info", sx: { mb: 2 }, children: t('v0.propertiesSettingTip') }), _jsx(Stack, { spacing: 2, children: (_a = params === null || params === void 0 ? void 0 : params.schema) === null || _a === void 0 ? void 0 : _a.map((item) => {
44
+ var _a, _b;
45
+ const { id, key, type, locales } = item;
46
+ const { Filed, extraProps } = (FieldComponentMap[type] || FieldComponentMap.string);
47
+ const currentLocale = (locales === null || locales === void 0 ? void 0 : locales[locale]) || (locales === null || locales === void 0 ? void 0 : locales.en);
48
+ return (_jsxs(Box, { children: [_jsx(Typography, { variant: "subtitle2", sx: {
49
+ mb: 0.5,
50
+ }, children: currentLocale === null || currentLocale === void 0 ? void 0 : currentLocale.name }), _jsx(Filed, Object.assign({ fullWidth: true, variant: "outlined", defaultValue: ((_b = (_a = openParamsRef === null || openParamsRef === void 0 ? void 0 : openParamsRef.current) === null || _a === void 0 ? void 0 : _a.defaultValues) === null || _b === void 0 ? void 0 : _b[key]) || (currentLocale === null || currentLocale === void 0 ? void 0 : currentLocale.defaultValue), size: "small", onChange: (e) => {
51
+ // update value
52
+ valuesRef.current = Object.assign(Object.assign({}, valuesRef.current), { [key]: e.target.value });
53
+ } }, extraProps))] }, id));
54
+ }) })] })),
55
+ onConfirm: () => {
56
+ var _a;
57
+ (_a = params === null || params === void 0 ? void 0 : params.onSubmit) === null || _a === void 0 ? void 0 : _a.call(params, getValues());
58
+ },
59
+ onCancel: () => { },
60
+ });
61
+ };
62
+ const getValues = () => {
63
+ var _a;
64
+ return Object.assign(Object.assign({}, (_a = openParamsRef === null || openParamsRef === void 0 ? void 0 : openParamsRef.current) === null || _a === void 0 ? void 0 : _a.defaultValues), valuesRef.current);
65
+ };
66
+ useImperativeHandle(ref, () => ({
67
+ open,
68
+ getValues,
69
+ }));
70
+ useEffect(() => {
71
+ valuesRef.current = {};
72
+ }, [locale]);
73
+ return _jsx(ConfirmDialog, Object.assign({ ref: ConfirmDialogRef }, props));
74
+ });
75
+ export default PropertiesSetting;
@@ -0,0 +1,26 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import ClickToCopy from '@arcblock/ux/lib/ClickToCopy';
3
+ import { Box, Typography } from '@mui/material';
4
+ import { Avatar } from '../../../../../arcblock/ux';
5
+ import { useLocaleContext } from '../../../../../locale';
6
+ import { useSessionContext } from '../../../../../session';
7
+ import { getLineClamp } from '../utils';
8
+ export default function UserQuestion({ question }) {
9
+ var _a;
10
+ const { session: authSession } = useSessionContext();
11
+ const { user } = authSession;
12
+ const { locale } = useLocaleContext();
13
+ return (_jsxs(Box, { sx: {
14
+ display: 'flex',
15
+ alignItems: 'center',
16
+ gap: 1,
17
+ }, children: [((_a = authSession === null || authSession === void 0 ? void 0 : authSession.user) === null || _a === void 0 ? void 0 : _a.did) && (_jsx(Box, { sx: {
18
+ width: 30,
19
+ height: 30,
20
+ }, children: _jsx(Avatar, { size: 30, did: user === null || user === void 0 ? void 0 : user.did, variant: "circle", shape: "circle", src: user === null || user === void 0 ? void 0 : user.avatar }) })), _jsx(Box, { sx: {
21
+ padding: '6px 8px',
22
+ borderRadius: 1,
23
+ // borderTopLeftRadius: 0,
24
+ backgroundColor: 'grey.200',
25
+ }, children: _jsx(ClickToCopy, { locale: locale, unstyled: true, children: _jsx(Typography, { sx: Object.assign({ fontWeight: 500, fontSize: 13, maxWidth: 300, color: 'textColor' }, getLineClamp(1)), children: question }) }) })] }));
26
+ }
@@ -0,0 +1,49 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useMemo, useState } from 'react';
3
+ const context = createContext(undefined);
4
+ let cancelAutoScrollTimer;
5
+ export function V0RuntimeProvider({ children }) {
6
+ const [currentMessageTaskId, setCurrentMessageTaskId] = useState();
7
+ const [propertiesValueMap, setPropertiesValueMap] = useState({});
8
+ const state = useMemo(() => ({
9
+ setCurrentMessageTaskId: (taskId) => {
10
+ setCurrentMessageTaskId(taskId);
11
+ // auto scroll to the task
12
+ if (taskId) {
13
+ const scrollIntoView = () => {
14
+ const el = document.getElementById(taskId);
15
+ if (el) {
16
+ el.scrollIntoView({ behavior: 'smooth' });
17
+ // is first time to scroll
18
+ if (!currentMessageTaskId) {
19
+ const observer = new MutationObserver(() => {
20
+ if (cancelAutoScrollTimer)
21
+ clearTimeout(cancelAutoScrollTimer);
22
+ el === null || el === void 0 ? void 0 : el.scrollIntoView({ behavior: 'smooth' });
23
+ cancelAutoScrollTimer = setTimeout(() => {
24
+ observer.disconnect();
25
+ cancelAutoScrollTimer = null;
26
+ }, 1000);
27
+ });
28
+ observer.observe(el.parentElement, { attributes: true, childList: true, subtree: true });
29
+ }
30
+ }
31
+ };
32
+ setTimeout(scrollIntoView, 300);
33
+ }
34
+ },
35
+ currentMessageTaskId,
36
+ propertiesValueMap,
37
+ setPropertiesValueMap: (valueMap) => {
38
+ setPropertiesValueMap(Object.assign(Object.assign({}, propertiesValueMap), valueMap));
39
+ },
40
+ }), [setCurrentMessageTaskId, currentMessageTaskId, propertiesValueMap, setPropertiesValueMap]);
41
+ return _jsx(context.Provider, { value: state, children: children });
42
+ }
43
+ export function useV0RuntimeContext() {
44
+ const current = useContext(context);
45
+ if (!current) {
46
+ throw new Error('No such message state. You should use `V0RuntimeProvider` within the `CurrentMessageProvider`');
47
+ }
48
+ return current;
49
+ }
@@ -0,0 +1,9 @@
1
+ export const getLineClamp = (count) => {
2
+ return {
3
+ display: '-webkit-box',
4
+ WebkitLineClamp: count,
5
+ WebkitBoxOrient: 'vertical',
6
+ overflow: 'hidden',
7
+ textOverflow: 'ellipsis',
8
+ };
9
+ };
@@ -46,7 +46,14 @@ export const createSessionState = ({ aid }) => {
46
46
  state.currentSessionId = undefined;
47
47
  });
48
48
  },
49
- load: () => __awaiter(void 0, void 0, void 0, function* () {
49
+ reload: () => __awaiter(void 0, void 0, void 0, function* () {
50
+ const { load, reset } = get();
51
+ reset();
52
+ yield load({
53
+ autoSetCurrentSessionId: false,
54
+ });
55
+ }),
56
+ load: (...args_1) => __awaiter(void 0, [...args_1], void 0, function* ({ autoSetCurrentSessionId = true } = {}) {
50
57
  const { loading, loaded } = get();
51
58
  if (!loading && !loaded) {
52
59
  set((state) => {
@@ -57,8 +64,10 @@ export const createSessionState = ({ aid }) => {
57
64
  set((state) => {
58
65
  var _a;
59
66
  state.sessions = sessions;
60
- state.currentSessionId = (_a = sessions[0]) === null || _a === void 0 ? void 0 : _a.id;
61
67
  state.sessionMap = Object.fromEntries(sessions.map((i) => [i.id, { session: i }]));
68
+ if (autoSetCurrentSessionId) {
69
+ state.currentSessionId = (_a = sessions[0]) === null || _a === void 0 ? void 0 : _a.id;
70
+ }
62
71
  });
63
72
  }
64
73
  catch (error) {
@@ -128,8 +137,8 @@ export const createSessionState = ({ aid }) => {
128
137
  state.currentSessionId = sessionId;
129
138
  });
130
139
  },
131
- createSession: () => __awaiter(void 0, void 0, void 0, function* () {
132
- const { created, sessions } = yield createSession({ aid });
140
+ createSession: (...args_2) => __awaiter(void 0, [...args_2], void 0, function* ({ name } = {}) {
141
+ const { created, sessions } = yield createSession({ aid, name });
133
142
  set((state) => {
134
143
  state.sessions = sessions;
135
144
  state.currentSessionId = created.id;
@@ -143,19 +152,22 @@ export const createSessionState = ({ aid }) => {
143
152
  });
144
153
  return created;
145
154
  }),
146
- deleteSession: (...args_1) => __awaiter(void 0, [...args_1], void 0, function* (args = {}) {
155
+ deleteSession: (...args_3) => __awaiter(void 0, [...args_3], void 0, function* (args = {}) {
156
+ var _a;
147
157
  const sessionId = args.sessionId || get().currentSessionId;
158
+ const autoSetCurrentSessionId = (_a = args.autoSetCurrentSessionId) !== null && _a !== void 0 ? _a : true;
148
159
  if (!sessionId)
149
160
  return;
150
161
  const { sessions } = yield deleteSession({ sessionId });
151
162
  set((state) => {
152
163
  var _a;
153
164
  state.sessions = sessions;
154
- if (!sessions.some((i) => i.id === state.currentSessionId))
155
- state.currentSessionId = (_a = sessions[0]) === null || _a === void 0 ? void 0 : _a.id;
165
+ if (!sessions.some((i) => i.id === state.currentSessionId)) {
166
+ state.currentSessionId = autoSetCurrentSessionId ? (_a = sessions[0]) === null || _a === void 0 ? void 0 : _a.id : undefined;
167
+ }
156
168
  });
157
169
  }),
158
- clearSession: (...args_2) => __awaiter(void 0, [...args_2], void 0, function* (args = {}) {
170
+ clearSession: (...args_4) => __awaiter(void 0, [...args_4], void 0, function* (args = {}) {
159
171
  const sessionId = args.sessionId || get().currentSessionId;
160
172
  if (!sessionId)
161
173
  return;
@@ -170,9 +182,10 @@ export const createSessionState = ({ aid }) => {
170
182
  s.messageLoading = undefined;
171
183
  });
172
184
  }),
173
- loadMoreMessages: (...args_3) => __awaiter(void 0, [...args_3], void 0, function* (args = {}) {
174
- var _a, _b;
185
+ loadMoreMessages: (...args_5) => __awaiter(void 0, [...args_5], void 0, function* (args = {}) {
186
+ var _b, _c;
175
187
  const sessionId = args.sessionId || get().currentSessionId;
188
+ const limit = args.limit || GET_MESSAGES_LIMIT;
176
189
  if (!sessionId)
177
190
  return;
178
191
  set((state) => {
@@ -189,9 +202,9 @@ export const createSessionState = ({ aid }) => {
189
202
  try {
190
203
  const result = yield getMessages({
191
204
  sessionId: s.session.id,
192
- before: (_b = (_a = s.messages) === null || _a === void 0 ? void 0 : _a.slice(-1)[0]) === null || _b === void 0 ? void 0 : _b.id,
205
+ before: (_c = (_b = s.messages) === null || _b === void 0 ? void 0 : _b.slice(-1)[0]) === null || _c === void 0 ? void 0 : _c.id,
193
206
  orderDirection: GET_MESSAGES_ORDER_DIRECTION,
194
- limit: GET_MESSAGES_LIMIT,
207
+ limit,
195
208
  });
196
209
  set((state) => {
197
210
  var _a, _b;
@@ -199,7 +212,7 @@ export const createSessionState = ({ aid }) => {
199
212
  if (!s)
200
213
  return;
201
214
  s.messages = ((_b = s.messages) !== null && _b !== void 0 ? _b : []).concat(result.messages.toReversed());
202
- s.noMoreMessage = result.messages.length < GET_MESSAGES_LIMIT;
215
+ s.noMoreMessage = result.messages.length < limit;
203
216
  });
204
217
  }
205
218
  finally {
@@ -212,9 +225,25 @@ export const createSessionState = ({ aid }) => {
212
225
  });
213
226
  }
214
227
  }),
215
- execute: (_c) => __awaiter(void 0, void 0, void 0, function* () {
216
- var _d, e_1, _e, _f;
217
- var { aid, working, parameters, onResponseStart } = _c, args = __rest(_c, ["aid", "working", "parameters", "onResponseStart"]);
228
+ loadLatestMessagesForAllSessions: () => __awaiter(void 0, void 0, void 0, function* () {
229
+ const { sessions, sessionMap } = get();
230
+ // sessions 按顺序分为每 n 个为一组,每次请求一组请求
231
+ const groupSize = 12;
232
+ for (let i = 0; i < sessions.length; i += groupSize) {
233
+ const group = sessions.slice(i, i + groupSize);
234
+ // eslint-disable-next-line no-await-in-loop
235
+ yield Promise.all(group.map((_d) => __awaiter(void 0, [_d], void 0, function* ({ id: sessionId }) {
236
+ var _e, _f;
237
+ // if messages is empty, load latest message
238
+ if (!((_f = (_e = sessionMap === null || sessionMap === void 0 ? void 0 : sessionMap[sessionId]) === null || _e === void 0 ? void 0 : _e.messages) === null || _f === void 0 ? void 0 : _f.length)) {
239
+ yield get().loadMoreMessages({ sessionId, limit: 1 });
240
+ }
241
+ })));
242
+ }
243
+ }),
244
+ execute: (_g) => __awaiter(void 0, void 0, void 0, function* () {
245
+ var _h, e_1, _j, _k;
246
+ var { aid, working, parameters, onResponseStart } = _g, args = __rest(_g, ["aid", "working", "parameters", "onResponseStart"]);
218
247
  const sessionId = args.sessionId || get().currentSessionId || (yield get().createSession()).id;
219
248
  const identity = parseIdentity(aid, { rejectWhenError: true });
220
249
  let message;
@@ -235,10 +264,10 @@ export const createSessionState = ({ aid }) => {
235
264
  });
236
265
  let responseStarted = false;
237
266
  try {
238
- for (var _g = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = yield stream_1.next(), _d = stream_1_1.done, !_d; _g = true) {
239
- _f = stream_1_1.value;
240
- _g = false;
241
- const value = _f;
267
+ for (var _l = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = yield stream_1.next(), _h = stream_1_1.done, !_h; _l = true) {
268
+ _k = stream_1_1.value;
269
+ _l = false;
270
+ const value = _k;
242
271
  if (!responseStarted) {
243
272
  responseStarted = true;
244
273
  onResponseStart === null || onResponseStart === void 0 ? void 0 : onResponseStart();
@@ -305,7 +334,7 @@ export const createSessionState = ({ aid }) => {
305
334
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
306
335
  finally {
307
336
  try {
308
- if (!_g && !_d && (_e = stream_1.return)) yield _e.call(stream_1);
337
+ if (!_l && !_h && (_j = stream_1.return)) yield _j.call(stream_1);
309
338
  }
310
339
  finally { if (e_1) throw e_1.error; }
311
340
  }
@@ -336,12 +365,12 @@ export const createSessionState = ({ aid }) => {
336
365
  }),
337
366
  }))));
338
367
  };
339
- export function useAutoLoadSessionState() {
368
+ export function useAutoLoadSessionState(...args) {
340
369
  const { aid } = useRuntimeContext();
341
370
  const state = useMemo(() => createSessionState({ aid }), [aid]);
342
371
  const currentSessionId = state((s) => s.currentSessionId);
343
372
  useEffect(() => {
344
- state.getState().load();
373
+ state.getState().load(...args);
345
374
  }, [state, currentSessionId]);
346
375
  }
347
376
  export function useSessionState(selector) {
@@ -150,10 +150,17 @@ function usePreloadComponent({ instanceId, componentId, properties, locale, dev
150
150
  return null;
151
151
  }
152
152
  function useTranspileComponent({ componentId, locale, properties, dev: { defaultLocale, components } = {}, }) {
153
- const [{ error, Component }, setComponent] = useState({});
153
+ const [{ error, Component, propertiesFromCode }, setComponent] = useState({});
154
154
  const component = mergeComponent({
155
155
  componentId,
156
- getComponent: (componentId) => { var _a; return (_a = components === null || components === void 0 ? void 0 : components[componentId]) === null || _a === void 0 ? void 0 : _a.data; },
156
+ getComponent: (componentId) => {
157
+ var _a, _b, _c, _d;
158
+ // setting properties from code if it's not set from components props
159
+ if (propertiesFromCode && !((_b = (_a = components === null || components === void 0 ? void 0 : components[componentId]) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.properties)) {
160
+ return Object.assign(Object.assign({}, (_c = components === null || components === void 0 ? void 0 : components[componentId]) === null || _c === void 0 ? void 0 : _c.data), { properties: propertiesFromCode });
161
+ }
162
+ return (_d = components === null || components === void 0 ? void 0 : components[componentId]) === null || _d === void 0 ? void 0 : _d.data;
163
+ },
157
164
  locale,
158
165
  defaultLocale,
159
166
  properties,
@@ -163,7 +170,18 @@ function useTranspileComponent({ componentId, locale, properties, dev: { default
163
170
  if (script) {
164
171
  transpileAndLoadScript(script)
165
172
  .then((m) => {
166
- setComponent({ Component: m.default });
173
+ let propertiesFromCode;
174
+ // get properties from code
175
+ if (typeof (m === null || m === void 0 ? void 0 : m.PROPERTIES_SCHEMA) === 'object' && (m === null || m === void 0 ? void 0 : m.PROPERTIES_SCHEMA.length)) {
176
+ propertiesFromCode = {};
177
+ m.PROPERTIES_SCHEMA.forEach((data, index) => {
178
+ propertiesFromCode[data.id] = {
179
+ index,
180
+ data,
181
+ };
182
+ });
183
+ }
184
+ setComponent({ Component: m.default, propertiesFromCode });
167
185
  })
168
186
  .catch((error) => {
169
187
  setComponent({ error });
@@ -176,7 +194,7 @@ function useTranspileComponent({ componentId, locale, properties, dev: { default
176
194
  props: component === null || component === void 0 ? void 0 : component.properties,
177
195
  };
178
196
  }
179
- function transpileAndLoadScript(script) {
197
+ export function transpileAndLoadScript(script) {
180
198
  return __awaiter(this, void 0, void 0, function* () {
181
199
  const [ts, { createBuiltinModuleTransformer }] = yield Promise.all([
182
200
  import('typescript'),