@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
|
@@ -27,6 +27,7 @@ import DOMPurify from 'isomorphic-dompurify';
|
|
|
27
27
|
import { useMemo } from 'react';
|
|
28
28
|
import { joinURL, withQuery } from 'ufo';
|
|
29
29
|
import { useLocaleContext } from '../../../../locale';
|
|
30
|
+
import { AI_RUNTIME_DID } from '../../constants';
|
|
30
31
|
import { useCurrentAgent } from '../../contexts/CurrentAgent';
|
|
31
32
|
import { useCurrentMessage } from '../../contexts/CurrentMessage';
|
|
32
33
|
import { useProfile } from '../../hooks/use-appearances';
|
|
@@ -93,7 +94,7 @@ function ShareTwitter({ inputs, shareAttach, }) {
|
|
|
93
94
|
text,
|
|
94
95
|
url: link,
|
|
95
96
|
};
|
|
96
|
-
}, []);
|
|
97
|
+
}, [message.outputs]);
|
|
97
98
|
if (!query)
|
|
98
99
|
return null;
|
|
99
100
|
return (_jsx(StyledActionButton, { tip: t('socialShare.shareToX'), title: _jsx(Icon, { icon: "tabler:brand-x" }), target: "_blank", href: withQuery('https://twitter.com/intent/tweet', query) }));
|
|
@@ -199,7 +200,7 @@ function ShareCommunity({ inputs, shareAttach, }) {
|
|
|
199
200
|
content,
|
|
200
201
|
labels: 'demo',
|
|
201
202
|
};
|
|
202
|
-
}, [inputs, shareAttach]);
|
|
203
|
+
}, [inputs, message.outputs, shareAttach]);
|
|
203
204
|
return (_jsx(StyledActionButton, { tip: t('socialShare.shareToCommunity'), title: _jsx(CommunityIcon, {}), target: "_blank", href: withQuery('https://community.arcblock.io/discussions/add?', query) }));
|
|
204
205
|
}
|
|
205
206
|
const StyledActionButton = styled(ActionButton)(({ theme }) => theme.unstable_sx({
|
|
@@ -209,8 +210,13 @@ const StyledActionButton = styled(ActionButton)(({ theme }) => theme.unstable_sx
|
|
|
209
210
|
minHeight: '0 !important',
|
|
210
211
|
}));
|
|
211
212
|
const useCurrentLink = () => {
|
|
212
|
-
var _a;
|
|
213
|
+
var _a, _b;
|
|
213
214
|
const { message } = useCurrentMessage();
|
|
214
|
-
const
|
|
215
|
+
const prefix = (_b = (_a = window.blocklet) === null || _a === void 0 ? void 0 : _a.componentMountPoints.find((i) => i.did === AI_RUNTIME_DID)) === null || _b === void 0 ? void 0 : _b.mountPoint;
|
|
216
|
+
if (!prefix)
|
|
217
|
+
throw new Error('No aigne runtime prefix found');
|
|
218
|
+
const link = withQuery(joinURL(window.origin, prefix, '/messages', message.id), {
|
|
219
|
+
agentUrl: window.location.href,
|
|
220
|
+
});
|
|
215
221
|
return { link };
|
|
216
222
|
};
|
|
@@ -25,7 +25,7 @@ export default function ThemeProvider({ children }) {
|
|
|
25
25
|
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;
|
|
26
26
|
const newTheme = useMemo(() => {
|
|
27
27
|
var _a, _b, _c, _d, _e, _f;
|
|
28
|
-
let { primary } = theme.palette;
|
|
28
|
+
let { primary, secondary } = theme.palette;
|
|
29
29
|
try {
|
|
30
30
|
if (appearance === null || appearance === void 0 ? void 0 : appearance.primaryColor) {
|
|
31
31
|
primary = theme.palette.augmentColor({ color: { main: appearance === null || appearance === void 0 ? void 0 : appearance.primaryColor } });
|
|
@@ -34,6 +34,14 @@ export default function ThemeProvider({ children }) {
|
|
|
34
34
|
catch (error) {
|
|
35
35
|
console.error('augment primary color error', { error });
|
|
36
36
|
}
|
|
37
|
+
try {
|
|
38
|
+
if (appearance === null || appearance === void 0 ? void 0 : appearance.secondaryColor) {
|
|
39
|
+
secondary = theme.palette.augmentColor({ color: { main: appearance === null || appearance === void 0 ? void 0 : appearance.secondaryColor } });
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
console.error('augment secondary color error', { error });
|
|
44
|
+
}
|
|
37
45
|
const { fontFamily } = theme.typography;
|
|
38
46
|
const headingFontFamily = [
|
|
39
47
|
((_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),
|
|
@@ -123,9 +131,7 @@ export default function ThemeProvider({ children }) {
|
|
|
123
131
|
} }),
|
|
124
132
|
palette: {
|
|
125
133
|
primary,
|
|
126
|
-
secondary
|
|
127
|
-
main: '#010714',
|
|
128
|
-
},
|
|
134
|
+
secondary,
|
|
129
135
|
},
|
|
130
136
|
});
|
|
131
137
|
return createTheme(theme, themeOptions, {
|
|
@@ -24,7 +24,6 @@ import CurrentAgentProvider from '../../contexts/CurrentAgent';
|
|
|
24
24
|
import CurrentMessageProvider from '../../contexts/CurrentMessage';
|
|
25
25
|
import useAppearances from '../../hooks/use-appearances';
|
|
26
26
|
import { useAutoLoadSessionState, useCurrentSessionState, useSessionState } from '../../state/session';
|
|
27
|
-
import mapRight from '../../utils/map-right';
|
|
28
27
|
export default function PhotoGallery({ resultTitle }) {
|
|
29
28
|
const { activeAgentId } = useActiveAgent();
|
|
30
29
|
useAutoLoadSessionState();
|
|
@@ -50,7 +49,7 @@ function OutputView(_a) {
|
|
|
50
49
|
return (_jsxs(Stack, Object.assign({ width: "100%", alignItems: "center", px: { xs: 2, sm: 3 }, mt: { xs: 2, sm: 3 } }, props, { children: [resultTitle && (_jsx(Typography, { width: "100%", component: "h2", fontSize: 36, fontWeight: 700, textAlign: "center", children: _jsx(Balancer, { children: resultTitle }) })), loaded && !messages.length && _jsx(NoOutputs, {}), _jsxs(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 && (_jsx(Skeleton, { variant: "rectangular", sx: {
|
|
51
50
|
// FIXME: default using history height
|
|
52
51
|
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,
|
|
53
|
-
} })),
|
|
52
|
+
} })), messages.map((message) => (_jsx(OutputItemView, { message: message }, message.id)))] }), _jsx(Box, { my: 4, children: !!messages.length && !noMoreMessage && (_jsx(LoadingButton, { variant: "outlined", onClick: () => loadMoreMessages(), children: t('loadMore') })) })] })));
|
|
54
53
|
}
|
|
55
54
|
const OutputItemView = memo(({ message }) => {
|
|
56
55
|
const { appearanceOutput } = useAppearances({ agentId: message.agentId });
|
|
@@ -35,7 +35,8 @@ export function useRuntimeState() {
|
|
|
35
35
|
yield sessionState.getState().load();
|
|
36
36
|
}), [authSession, sessionState]);
|
|
37
37
|
const execute = useCallback((args) => __awaiter(this, void 0, void 0, function* () {
|
|
38
|
-
|
|
38
|
+
var _a;
|
|
39
|
+
if (!((_a = agent.access) === null || _a === void 0 ? void 0 : _a.noLoginRequired) && !authSession.user) {
|
|
39
40
|
yield login();
|
|
40
41
|
}
|
|
41
42
|
return exec(Object.assign(Object.assign({}, args), { blockletDid, working }));
|
|
@@ -99,7 +99,7 @@ export const createSessionState = ({ aid }) => {
|
|
|
99
99
|
const s = (_a = state.sessionMap) === null || _a === void 0 ? void 0 : _a[state.currentSessionId];
|
|
100
100
|
if (!s)
|
|
101
101
|
return;
|
|
102
|
-
s.messages = messages
|
|
102
|
+
s.messages = messages;
|
|
103
103
|
s.noMoreMessage = messages.length < GET_MESSAGES_LIMIT;
|
|
104
104
|
});
|
|
105
105
|
}
|
|
@@ -204,7 +204,7 @@ export const createSessionState = ({ aid }) => {
|
|
|
204
204
|
const s = (_a = state.sessionMap) === null || _a === void 0 ? void 0 : _a[sessionId];
|
|
205
205
|
if (!s)
|
|
206
206
|
return;
|
|
207
|
-
s.messages = ((_b = s.messages) !== null && _b !== void 0 ? _b : []).concat(result.messages
|
|
207
|
+
s.messages = ((_b = s.messages) !== null && _b !== void 0 ? _b : []).concat(result.messages);
|
|
208
208
|
s.noMoreMessage = result.messages.length < limit;
|
|
209
209
|
});
|
|
210
210
|
}
|
|
@@ -236,12 +236,10 @@ export const createSessionState = ({ aid }) => {
|
|
|
236
236
|
}),
|
|
237
237
|
execute: (_a) => __awaiter(void 0, void 0, void 0, function* () {
|
|
238
238
|
var { blockletDid, aid, working, parameters, onResponseStart } = _a, args = __rest(_a, ["blockletDid", "aid", "working", "parameters", "onResponseStart"]);
|
|
239
|
-
const sessionId = args.sessionId ||
|
|
240
|
-
get().currentSessionId ||
|
|
241
|
-
(yield get().createSession({
|
|
242
|
-
name: parameters === null || parameters === void 0 ? void 0 : parameters.question,
|
|
243
|
-
})).id;
|
|
244
239
|
const identity = parseIdentity(aid, { rejectWhenError: true });
|
|
240
|
+
let responseStarted = false;
|
|
241
|
+
let mainTaskId;
|
|
242
|
+
let sessionId = args.sessionId || get().currentSessionId;
|
|
245
243
|
let message;
|
|
246
244
|
set((state) => {
|
|
247
245
|
var _a;
|
|
@@ -260,8 +258,6 @@ export const createSessionState = ({ aid }) => {
|
|
|
260
258
|
inputs: Object.assign(Object.assign({}, parameters), { $clientTime: new Date().toISOString() }),
|
|
261
259
|
responseType: 'stream',
|
|
262
260
|
});
|
|
263
|
-
let responseStarted = false;
|
|
264
|
-
let mainTaskId;
|
|
265
261
|
const reader = res.getReader();
|
|
266
262
|
for (;;) {
|
|
267
263
|
const { value, done } = yield reader.read();
|
|
@@ -273,7 +269,40 @@ export const createSessionState = ({ aid }) => {
|
|
|
273
269
|
}
|
|
274
270
|
if ((value === null || value === void 0 ? void 0 : value.type) === 'CHUNK') {
|
|
275
271
|
if (!message) {
|
|
272
|
+
const isNewSession = sessionId !== value.sessionId;
|
|
276
273
|
mainTaskId = value.taskId;
|
|
274
|
+
sessionId = value.sessionId;
|
|
275
|
+
// set current session state for anonymous session
|
|
276
|
+
if (isNewSession) {
|
|
277
|
+
set((state) => {
|
|
278
|
+
var _a, _b;
|
|
279
|
+
state.sessions = [
|
|
280
|
+
...((_a = state.sessions) !== null && _a !== void 0 ? _a : []),
|
|
281
|
+
{
|
|
282
|
+
id: sessionId,
|
|
283
|
+
projectId: identity.projectId,
|
|
284
|
+
agentId: identity.agentId,
|
|
285
|
+
createdAt: new Date().toISOString(),
|
|
286
|
+
updatedAt: new Date().toISOString(),
|
|
287
|
+
},
|
|
288
|
+
];
|
|
289
|
+
state.currentSessionId = sessionId;
|
|
290
|
+
state.sessionMap = Object.fromEntries(state.sessions.map((i) => {
|
|
291
|
+
var _a;
|
|
292
|
+
return [
|
|
293
|
+
i.id,
|
|
294
|
+
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 } : {})),
|
|
295
|
+
];
|
|
296
|
+
}));
|
|
297
|
+
const s = (_b = state.sessionMap) === null || _b === void 0 ? void 0 : _b[sessionId];
|
|
298
|
+
if (!s)
|
|
299
|
+
return;
|
|
300
|
+
s.running = true;
|
|
301
|
+
s.error = undefined;
|
|
302
|
+
s.noMoreMessage = true;
|
|
303
|
+
state.currentSessionId = sessionId;
|
|
304
|
+
});
|
|
305
|
+
}
|
|
277
306
|
message = {
|
|
278
307
|
id: value.messageId,
|
|
279
308
|
agentId: identity.agentId,
|
|
@@ -289,7 +318,7 @@ export const createSessionState = ({ aid }) => {
|
|
|
289
318
|
if (!s)
|
|
290
319
|
return;
|
|
291
320
|
(_b = s.messages) !== null && _b !== void 0 ? _b : (s.messages = []);
|
|
292
|
-
s.messages.
|
|
321
|
+
s.messages.unshift(message);
|
|
293
322
|
});
|
|
294
323
|
}
|
|
295
324
|
if (mainTaskId === value.taskId) {
|