@blocklet/pages-kit 0.2.413 → 0.2.415
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/components/ShareActions/index.js +10 -4
- package/lib/cjs/builtin/async/ai-runtime/components/ThemeProvider.js +10 -4
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +1 -2
- package/lib/cjs/builtin/async/ai-runtime/state/runtime.js +2 -1
- package/lib/cjs/builtin/async/ai-runtime/state/session.js +39 -10
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/builtin/async/ai-runtime/components/ShareActions/index.js +10 -4
- package/lib/esm/builtin/async/ai-runtime/components/ThemeProvider.js +10 -4
- package/lib/esm/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +1 -2
- package/lib/esm/builtin/async/ai-runtime/state/runtime.js +2 -1
- package/lib/esm/builtin/async/ai-runtime/state/session.js +39 -10
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/types/builtin/async/ai-runtime/api/agent.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/api/session.d.ts +2 -2
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +2 -2
|
@@ -56,6 +56,7 @@ const isomorphic_dompurify_1 = __importDefault(require("isomorphic-dompurify"));
|
|
|
56
56
|
const react_2 = require("react");
|
|
57
57
|
const ufo_1 = require("ufo");
|
|
58
58
|
const locale_1 = require("../../../../locale");
|
|
59
|
+
const constants_1 = require("../../constants");
|
|
59
60
|
const CurrentAgent_1 = require("../../contexts/CurrentAgent");
|
|
60
61
|
const CurrentMessage_1 = require("../../contexts/CurrentMessage");
|
|
61
62
|
const use_appearances_1 = require("../../hooks/use-appearances");
|
|
@@ -122,7 +123,7 @@ function ShareTwitter({ inputs, shareAttach, }) {
|
|
|
122
123
|
text,
|
|
123
124
|
url: link,
|
|
124
125
|
};
|
|
125
|
-
}, []);
|
|
126
|
+
}, [message.outputs]);
|
|
126
127
|
if (!query)
|
|
127
128
|
return null;
|
|
128
129
|
return ((0, jsx_runtime_1.jsx)(StyledActionButton, { tip: t('socialShare.shareToX'), title: (0, jsx_runtime_1.jsx)(react_1.Icon, { icon: "tabler:brand-x" }), target: "_blank", href: (0, ufo_1.withQuery)('https://twitter.com/intent/tweet', query) }));
|
|
@@ -228,7 +229,7 @@ function ShareCommunity({ inputs, shareAttach, }) {
|
|
|
228
229
|
content,
|
|
229
230
|
labels: 'demo',
|
|
230
231
|
};
|
|
231
|
-
}, [inputs, shareAttach]);
|
|
232
|
+
}, [inputs, message.outputs, shareAttach]);
|
|
232
233
|
return ((0, jsx_runtime_1.jsx)(StyledActionButton, { tip: t('socialShare.shareToCommunity'), title: (0, jsx_runtime_1.jsx)(Community_1.default, {}), target: "_blank", href: (0, ufo_1.withQuery)('https://community.arcblock.io/discussions/add?', query) }));
|
|
233
234
|
}
|
|
234
235
|
const StyledActionButton = (0, material_1.styled)(ActionButton_1.default)(({ theme }) => theme.unstable_sx({
|
|
@@ -238,8 +239,13 @@ const StyledActionButton = (0, material_1.styled)(ActionButton_1.default)(({ the
|
|
|
238
239
|
minHeight: '0 !important',
|
|
239
240
|
}));
|
|
240
241
|
const useCurrentLink = () => {
|
|
241
|
-
var _a;
|
|
242
|
+
var _a, _b;
|
|
242
243
|
const { message } = (0, CurrentMessage_1.useCurrentMessage)();
|
|
243
|
-
const
|
|
244
|
+
const prefix = (_b = (_a = window.blocklet) === null || _a === void 0 ? void 0 : _a.componentMountPoints.find((i) => i.did === constants_1.AI_RUNTIME_DID)) === null || _b === void 0 ? void 0 : _b.mountPoint;
|
|
245
|
+
if (!prefix)
|
|
246
|
+
throw new Error('No aigne runtime prefix found');
|
|
247
|
+
const link = (0, ufo_1.withQuery)((0, ufo_1.joinURL)(window.origin, prefix, '/messages', message.id), {
|
|
248
|
+
agentUrl: window.location.href,
|
|
249
|
+
});
|
|
244
250
|
return { link };
|
|
245
251
|
};
|
|
@@ -31,7 +31,7 @@ function ThemeProvider({ children }) {
|
|
|
31
31
|
const headingFontFamily = (_c = (_b = appearance === null || appearance === void 0 ? void 0 : appearance.typography) === null || _b === void 0 ? void 0 : _b.heading) === null || _c === void 0 ? void 0 : _c.fontFamily;
|
|
32
32
|
const newTheme = (0, react_1.useMemo)(() => {
|
|
33
33
|
var _a, _b, _c, _d, _e, _f;
|
|
34
|
-
let { primary } = theme.palette;
|
|
34
|
+
let { primary, secondary } = theme.palette;
|
|
35
35
|
try {
|
|
36
36
|
if (appearance === null || appearance === void 0 ? void 0 : appearance.primaryColor) {
|
|
37
37
|
primary = theme.palette.augmentColor({ color: { main: appearance === null || appearance === void 0 ? void 0 : appearance.primaryColor } });
|
|
@@ -40,6 +40,14 @@ function ThemeProvider({ children }) {
|
|
|
40
40
|
catch (error) {
|
|
41
41
|
console.error('augment primary color error', { error });
|
|
42
42
|
}
|
|
43
|
+
try {
|
|
44
|
+
if (appearance === null || appearance === void 0 ? void 0 : appearance.secondaryColor) {
|
|
45
|
+
secondary = theme.palette.augmentColor({ color: { main: appearance === null || appearance === void 0 ? void 0 : appearance.secondaryColor } });
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
console.error('augment secondary color error', { error });
|
|
50
|
+
}
|
|
43
51
|
const { fontFamily } = theme.typography;
|
|
44
52
|
const headingFontFamily = [
|
|
45
53
|
((_b = (_a = appearance === null || appearance === void 0 ? void 0 : appearance.typography) === null || _a === void 0 ? void 0 : _a.heading) === null || _b === void 0 ? void 0 : _b.fontFamily) && JSON.stringify((_d = (_c = appearance === null || appearance === void 0 ? void 0 : appearance.typography) === null || _c === void 0 ? void 0 : _c.heading) === null || _d === void 0 ? void 0 : _d.fontFamily),
|
|
@@ -129,9 +137,7 @@ function ThemeProvider({ children }) {
|
|
|
129
137
|
} }),
|
|
130
138
|
palette: {
|
|
131
139
|
primary,
|
|
132
|
-
secondary
|
|
133
|
-
main: '#010714',
|
|
134
|
-
},
|
|
140
|
+
secondary,
|
|
135
141
|
},
|
|
136
142
|
});
|
|
137
143
|
return (0, material_1.createTheme)(theme, themeOptions, {
|
|
@@ -30,7 +30,6 @@ const CurrentAgent_1 = __importDefault(require("../../contexts/CurrentAgent"));
|
|
|
30
30
|
const CurrentMessage_1 = __importDefault(require("../../contexts/CurrentMessage"));
|
|
31
31
|
const use_appearances_1 = __importDefault(require("../../hooks/use-appearances"));
|
|
32
32
|
const session_1 = require("../../state/session");
|
|
33
|
-
const map_right_1 = __importDefault(require("../../utils/map-right"));
|
|
34
33
|
function PhotoGallery({ resultTitle }) {
|
|
35
34
|
const { activeAgentId } = (0, ActiveAgent_1.useActiveAgent)();
|
|
36
35
|
(0, session_1.useAutoLoadSessionState)();
|
|
@@ -56,7 +55,7 @@ function OutputView(_a) {
|
|
|
56
55
|
return ((0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ width: "100%", alignItems: "center", px: { xs: 2, sm: 3 }, mt: { xs: 2, sm: 3 } }, props, { children: [resultTitle && ((0, jsx_runtime_1.jsx)(material_1.Typography, { width: "100%", component: "h2", fontSize: 36, fontWeight: 700, textAlign: "center", children: (0, jsx_runtime_1.jsx)(react_wrap_balancer_1.default, { children: resultTitle }) })), loaded && !messages.length && (0, jsx_runtime_1.jsx)(NoOutputs, {}), (0, jsx_runtime_1.jsxs)(lab_1.Masonry, { ref: ref, columns: { xs: 2, sm: 3, md: 4, lg: 5 }, spacing: 1, sequential: true, sx: { width: '100%', overflow: 'hidden', '> *': { borderRadius: 1 } }, children: [running && ((0, jsx_runtime_1.jsx)(material_1.Skeleton, { variant: "rectangular", sx: {
|
|
57
56
|
// FIXME: default using history height
|
|
58
57
|
height: (_e = (_d = (_c = ref.current) === null || _c === void 0 ? void 0 : _c.querySelector('*')) === null || _d === void 0 ? void 0 : _d.clientHeight) !== null && _e !== void 0 ? _e : 200,
|
|
59
|
-
} })),
|
|
58
|
+
} })), messages.map((message) => ((0, jsx_runtime_1.jsx)(OutputItemView, { message: message }, message.id)))] }), (0, jsx_runtime_1.jsx)(material_1.Box, { my: 4, children: !!messages.length && !noMoreMessage && ((0, jsx_runtime_1.jsx)(LoadingButton_1.default, { variant: "outlined", onClick: () => loadMoreMessages(), children: t('loadMore') })) })] })));
|
|
60
59
|
}
|
|
61
60
|
const OutputItemView = (0, react_1.memo)(({ message }) => {
|
|
62
61
|
const { appearanceOutput } = (0, use_appearances_1.default)({ agentId: message.agentId });
|
|
@@ -38,7 +38,8 @@ function useRuntimeState() {
|
|
|
38
38
|
yield sessionState.getState().load();
|
|
39
39
|
}), [authSession, sessionState]);
|
|
40
40
|
const execute = (0, react_1.useCallback)((args) => __awaiter(this, void 0, void 0, function* () {
|
|
41
|
-
|
|
41
|
+
var _a;
|
|
42
|
+
if (!((_a = agent.access) === null || _a === void 0 ? void 0 : _a.noLoginRequired) && !authSession.user) {
|
|
42
43
|
yield login();
|
|
43
44
|
}
|
|
44
45
|
return exec(Object.assign(Object.assign({}, args), { blockletDid, working }));
|
|
@@ -105,7 +105,7 @@ const createSessionState = ({ aid }) => {
|
|
|
105
105
|
const s = (_a = state.sessionMap) === null || _a === void 0 ? void 0 : _a[state.currentSessionId];
|
|
106
106
|
if (!s)
|
|
107
107
|
return;
|
|
108
|
-
s.messages = messages
|
|
108
|
+
s.messages = messages;
|
|
109
109
|
s.noMoreMessage = messages.length < GET_MESSAGES_LIMIT;
|
|
110
110
|
});
|
|
111
111
|
}
|
|
@@ -210,7 +210,7 @@ const createSessionState = ({ aid }) => {
|
|
|
210
210
|
const s = (_a = state.sessionMap) === null || _a === void 0 ? void 0 : _a[sessionId];
|
|
211
211
|
if (!s)
|
|
212
212
|
return;
|
|
213
|
-
s.messages = ((_b = s.messages) !== null && _b !== void 0 ? _b : []).concat(result.messages
|
|
213
|
+
s.messages = ((_b = s.messages) !== null && _b !== void 0 ? _b : []).concat(result.messages);
|
|
214
214
|
s.noMoreMessage = result.messages.length < limit;
|
|
215
215
|
});
|
|
216
216
|
}
|
|
@@ -242,12 +242,10 @@ const createSessionState = ({ aid }) => {
|
|
|
242
242
|
}),
|
|
243
243
|
execute: (_a) => __awaiter(void 0, void 0, void 0, function* () {
|
|
244
244
|
var { blockletDid, aid, working, parameters, onResponseStart } = _a, args = __rest(_a, ["blockletDid", "aid", "working", "parameters", "onResponseStart"]);
|
|
245
|
-
const sessionId = args.sessionId ||
|
|
246
|
-
get().currentSessionId ||
|
|
247
|
-
(yield get().createSession({
|
|
248
|
-
name: parameters === null || parameters === void 0 ? void 0 : parameters.question,
|
|
249
|
-
})).id;
|
|
250
245
|
const identity = (0, aid_1.parseIdentity)(aid, { rejectWhenError: true });
|
|
246
|
+
let responseStarted = false;
|
|
247
|
+
let mainTaskId;
|
|
248
|
+
let sessionId = args.sessionId || get().currentSessionId;
|
|
251
249
|
let message;
|
|
252
250
|
set((state) => {
|
|
253
251
|
var _a;
|
|
@@ -266,8 +264,6 @@ const createSessionState = ({ aid }) => {
|
|
|
266
264
|
inputs: Object.assign(Object.assign({}, parameters), { $clientTime: new Date().toISOString() }),
|
|
267
265
|
responseType: 'stream',
|
|
268
266
|
});
|
|
269
|
-
let responseStarted = false;
|
|
270
|
-
let mainTaskId;
|
|
271
267
|
const reader = res.getReader();
|
|
272
268
|
for (;;) {
|
|
273
269
|
const { value, done } = yield reader.read();
|
|
@@ -279,7 +275,40 @@ const createSessionState = ({ aid }) => {
|
|
|
279
275
|
}
|
|
280
276
|
if ((value === null || value === void 0 ? void 0 : value.type) === 'CHUNK') {
|
|
281
277
|
if (!message) {
|
|
278
|
+
const isNewSession = sessionId !== value.sessionId;
|
|
282
279
|
mainTaskId = value.taskId;
|
|
280
|
+
sessionId = value.sessionId;
|
|
281
|
+
// set current session state for anonymous session
|
|
282
|
+
if (isNewSession) {
|
|
283
|
+
set((state) => {
|
|
284
|
+
var _a, _b;
|
|
285
|
+
state.sessions = [
|
|
286
|
+
...((_a = state.sessions) !== null && _a !== void 0 ? _a : []),
|
|
287
|
+
{
|
|
288
|
+
id: sessionId,
|
|
289
|
+
projectId: identity.projectId,
|
|
290
|
+
agentId: identity.agentId,
|
|
291
|
+
createdAt: new Date().toISOString(),
|
|
292
|
+
updatedAt: new Date().toISOString(),
|
|
293
|
+
},
|
|
294
|
+
];
|
|
295
|
+
state.currentSessionId = sessionId;
|
|
296
|
+
state.sessionMap = Object.fromEntries(state.sessions.map((i) => {
|
|
297
|
+
var _a;
|
|
298
|
+
return [
|
|
299
|
+
i.id,
|
|
300
|
+
Object.assign(Object.assign(Object.assign({}, (_a = state.sessionMap) === null || _a === void 0 ? void 0 : _a[i.id]), { session: i }), (i.id === sessionId ? { messages: [], loaded: true } : {})),
|
|
301
|
+
];
|
|
302
|
+
}));
|
|
303
|
+
const s = (_b = state.sessionMap) === null || _b === void 0 ? void 0 : _b[sessionId];
|
|
304
|
+
if (!s)
|
|
305
|
+
return;
|
|
306
|
+
s.running = true;
|
|
307
|
+
s.error = undefined;
|
|
308
|
+
s.noMoreMessage = true;
|
|
309
|
+
state.currentSessionId = sessionId;
|
|
310
|
+
});
|
|
311
|
+
}
|
|
283
312
|
message = {
|
|
284
313
|
id: value.messageId,
|
|
285
314
|
agentId: identity.agentId,
|
|
@@ -295,7 +324,7 @@ const createSessionState = ({ aid }) => {
|
|
|
295
324
|
if (!s)
|
|
296
325
|
return;
|
|
297
326
|
(_b = s.messages) !== null && _b !== void 0 ? _b : (s.messages = []);
|
|
298
|
-
s.messages.
|
|
327
|
+
s.messages.unshift(message);
|
|
299
328
|
});
|
|
300
329
|
}
|
|
301
330
|
if (mainTaskId === value.taskId) {
|