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