@blocklet/pages-kit 0.2.345 → 0.2.347
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 +60 -12
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageItemView.js +1 -1
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/PhotoGalleryItem/index.js +1 -1
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Output.js +1 -1
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Page.js +5 -18
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/components/CodePreview.js +5 -5
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/builtin/async/ai-runtime/components/ShareActions/index.js +60 -12
- package/lib/esm/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageItemView.js +1 -1
- package/lib/esm/builtin/async/ai-runtime/runtime-components/PhotoGalleryItem/index.js +1 -1
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Output.js +1 -1
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Page.js +5 -18
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/components/CodePreview.js +5 -5
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/types/builtin/async/ai-runtime/components/ActionButton.d.ts +1 -0
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +5 -5
|
@@ -23,6 +23,7 @@ import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
|
|
|
23
23
|
import { Icon } from '@iconify/react';
|
|
24
24
|
import { Box, Stack, styled } from '@mui/material';
|
|
25
25
|
import { saveAs } from 'file-saver';
|
|
26
|
+
import _ from 'lodash';
|
|
26
27
|
import { useMemo } from 'react';
|
|
27
28
|
import { withQuery } from 'ufo';
|
|
28
29
|
import { useLocaleContext } from '../../../../locale';
|
|
@@ -30,21 +31,31 @@ import { useCurrentAgent } from '../../contexts/CurrentAgent';
|
|
|
30
31
|
import { useCurrentMessage } from '../../contexts/CurrentMessage';
|
|
31
32
|
import { useProfile } from '../../hooks/use-appearances';
|
|
32
33
|
import { useRuntimeState } from '../../state/runtime';
|
|
34
|
+
import { isValidInput } from '../../utils/agent-inputs';
|
|
33
35
|
import { convertImageToBlob, downloadImage } from '../../utils/download-image';
|
|
34
36
|
import ActionButton from '../ActionButton';
|
|
35
37
|
export default function ShareActions(_a) {
|
|
36
38
|
var _b;
|
|
37
39
|
var props = __rest(_a, []);
|
|
38
40
|
const { agent } = useCurrentAgent();
|
|
41
|
+
const { message } = useCurrentMessage();
|
|
39
42
|
const sharing = useMemo(() => {
|
|
40
43
|
var _a, _b;
|
|
41
44
|
return (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.share)) === null || _b === void 0 ? void 0 : _b.initialValue;
|
|
42
45
|
}, [agent]);
|
|
46
|
+
const params = useMemo(() => {
|
|
47
|
+
var _a;
|
|
48
|
+
return (_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.filter(isValidInput).map((i) => { var _a, _b; return [((_a = i.label) === null || _a === void 0 ? void 0 : _a.trim()) || i.key, (_b = message.inputs) === null || _b === void 0 ? void 0 : _b[i.key]]; }).filter((i) => i[1]);
|
|
49
|
+
}, [agent.parameters, message.inputs]);
|
|
43
50
|
const items = (_b = sharing === null || sharing === void 0 ? void 0 : sharing.items) === null || _b === void 0 ? void 0 : _b.map((item) => {
|
|
51
|
+
var _a, _b;
|
|
44
52
|
const C = ShareActionsMap[item.to];
|
|
45
53
|
if (!C)
|
|
46
54
|
return null;
|
|
47
|
-
return (_jsx(Box, { children: _jsx(C, {
|
|
55
|
+
return (_jsx(Box, { children: _jsx(C, { inputs: JSON.stringify(_.fromPairs(params), null, 2), shareAttach: {
|
|
56
|
+
shareAttachInputs: (_a = sharing === null || sharing === void 0 ? void 0 : sharing.shareAttachInputs) !== null && _a !== void 0 ? _a : false,
|
|
57
|
+
shareAttachUrl: (_b = sharing === null || sharing === void 0 ? void 0 : sharing.shareAttachUrl) !== null && _b !== void 0 ? _b : false,
|
|
58
|
+
} }) }));
|
|
48
59
|
}).filter((i) => !!i);
|
|
49
60
|
if (!(items === null || items === void 0 ? void 0 : items.length))
|
|
50
61
|
return null;
|
|
@@ -54,30 +65,40 @@ const ShareActionsMap = {
|
|
|
54
65
|
twitter: ShareTwitter,
|
|
55
66
|
copy: ShareCopy,
|
|
56
67
|
saveAs: ShareSave,
|
|
68
|
+
community: ShareCommunity,
|
|
57
69
|
};
|
|
58
|
-
function ShareTwitter() {
|
|
70
|
+
function ShareTwitter({ inputs, shareAttach, }) {
|
|
59
71
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
60
72
|
const { t } = useLocaleContext();
|
|
61
73
|
const { message } = useCurrentMessage();
|
|
62
|
-
|
|
74
|
+
let content = ((_c = (_b = (_a = message.outputs) === null || _a === void 0 ? void 0 : _a.objects) === null || _b === void 0 ? void 0 : _b.find((i) => i === null || i === void 0 ? void 0 : i[RuntimeOutputVariable.text])) === null || _c === void 0 ? void 0 : _c[RuntimeOutputVariable.text]) ||
|
|
63
75
|
((_h = (_g = (_f = (_e = (_d = message.outputs) === null || _d === void 0 ? void 0 : _d.objects) === null || _e === void 0 ? void 0 : _e.find((i) => { var _a; return (_a = i === null || i === void 0 ? void 0 : i[RuntimeOutputVariable.images]) === null || _a === void 0 ? void 0 : _a.length; })) === null || _f === void 0 ? void 0 : _f[RuntimeOutputVariable.images]) === null || _g === void 0 ? void 0 : _g.at(0)) === null || _h === void 0 ? void 0 : _h.url);
|
|
64
76
|
if (!content)
|
|
65
77
|
return null;
|
|
66
|
-
|
|
78
|
+
if (shareAttach.shareAttachInputs) {
|
|
79
|
+
content += `\nInputs: ${inputs}`;
|
|
80
|
+
}
|
|
81
|
+
return (_jsx(StyledActionButton, { tip: t('socialShare.shareToX'), title: _jsx(Icon, { icon: "tabler:brand-x" }), target: "_blank", href: withQuery('https://twitter.com/intent/tweet', {
|
|
67
82
|
text: content,
|
|
68
|
-
url: window.location.href,
|
|
69
|
-
})
|
|
83
|
+
url: shareAttach.shareAttachUrl ? window.location.href : undefined,
|
|
84
|
+
}) }));
|
|
70
85
|
}
|
|
71
|
-
function ShareCopy() {
|
|
86
|
+
function ShareCopy({ inputs, shareAttach, }) {
|
|
72
87
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
73
88
|
const { t } = useLocaleContext();
|
|
74
89
|
const { message } = useCurrentMessage();
|
|
75
|
-
|
|
90
|
+
let content = (_c = (_b = (_a = message.outputs) === null || _a === void 0 ? void 0 : _a.objects) === null || _b === void 0 ? void 0 : _b.find((i) => i === null || i === void 0 ? void 0 : i[RuntimeOutputVariable.text])) === null || _c === void 0 ? void 0 : _c[RuntimeOutputVariable.text];
|
|
76
91
|
const image = (_h = (_g = (_f = (_e = (_d = message.outputs) === null || _d === void 0 ? void 0 : _d.objects) === null || _e === void 0 ? void 0 : _e.find((i) => { var _a; return (_a = i === null || i === void 0 ? void 0 : i[RuntimeOutputVariable.images]) === null || _a === void 0 ? void 0 : _a.length; })) === null || _f === void 0 ? void 0 : _f[RuntimeOutputVariable.images]) === null || _g === void 0 ? void 0 : _g.at(0)) === null || _h === void 0 ? void 0 : _h.url;
|
|
77
92
|
if (!content && !image)
|
|
78
93
|
return null;
|
|
79
94
|
return (_jsx(StyledActionButton, { autoReset: true, tip: t('copy'), tipSucceed: t('copied'), title: _jsx(Icon, { icon: "tabler:copy" }), titleSucceed: _jsx(Icon, { icon: "tabler:copy-check" }), onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
80
95
|
if (content) {
|
|
96
|
+
if (shareAttach.shareAttachInputs) {
|
|
97
|
+
content += `\nInputs: ${inputs}`;
|
|
98
|
+
}
|
|
99
|
+
if (shareAttach.shareAttachUrl) {
|
|
100
|
+
content += `\nURL: ${window.location.href}`;
|
|
101
|
+
}
|
|
81
102
|
window.navigator.clipboard.writeText(content);
|
|
82
103
|
}
|
|
83
104
|
else if (image) {
|
|
@@ -86,7 +107,7 @@ function ShareCopy() {
|
|
|
86
107
|
}
|
|
87
108
|
}) }));
|
|
88
109
|
}
|
|
89
|
-
function ShareSave() {
|
|
110
|
+
function ShareSave({ inputs, shareAttach, }) {
|
|
90
111
|
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
91
112
|
const { t } = useLocaleContext();
|
|
92
113
|
const { message } = useCurrentMessage();
|
|
@@ -101,7 +122,13 @@ function ShareSave() {
|
|
|
101
122
|
const { default: html2pdf } = yield import('html2pdf.js');
|
|
102
123
|
if (content) {
|
|
103
124
|
const element = document.createElement('div');
|
|
104
|
-
element.
|
|
125
|
+
element.innerHTML = content;
|
|
126
|
+
if (shareAttach.shareAttachInputs) {
|
|
127
|
+
element.innerHTML += `<br/>Inputs: ${inputs}`;
|
|
128
|
+
}
|
|
129
|
+
if (shareAttach.shareAttachUrl) {
|
|
130
|
+
element.innerHTML += `<br/>URL: ${window.location.href}`;
|
|
131
|
+
}
|
|
105
132
|
yield html2pdf()
|
|
106
133
|
.set({
|
|
107
134
|
margin: 1,
|
|
@@ -118,9 +145,30 @@ function ShareSave() {
|
|
|
118
145
|
}
|
|
119
146
|
}) }));
|
|
120
147
|
}
|
|
148
|
+
function ShareCommunity({ inputs, shareAttach, }) {
|
|
149
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
|
|
150
|
+
const { t } = useLocaleContext();
|
|
151
|
+
const { message } = useCurrentMessage();
|
|
152
|
+
let content = (_d = (_c = (_b = (_a = message.outputs) === null || _a === void 0 ? void 0 : _a.objects) === null || _b === void 0 ? void 0 : _b.find((i) => i === null || i === void 0 ? void 0 : i[RuntimeOutputVariable.text])) === null || _c === void 0 ? void 0 : _c[RuntimeOutputVariable.text]) !== null && _d !== void 0 ? _d : '';
|
|
153
|
+
const image = ((_k = (_j = (_h = (_g = (_f = (_e = message.outputs) === null || _e === void 0 ? void 0 : _e.objects) === null || _f === void 0 ? void 0 : _f.find) === null || _g === void 0 ? void 0 : _g.call(_f, (i) => { var _a; return (_a = i === null || i === void 0 ? void 0 : i[RuntimeOutputVariable.images]) === null || _a === void 0 ? void 0 : _a.length; })) === null || _h === void 0 ? void 0 : _h[RuntimeOutputVariable.images]) === null || _j === void 0 ? void 0 : _j.map((i) => i.url)) !== null && _k !== void 0 ? _k : []).join(',');
|
|
154
|
+
if (!content && !image)
|
|
155
|
+
return null;
|
|
156
|
+
if (shareAttach.shareAttachInputs) {
|
|
157
|
+
content += `\nInputs: ${inputs}`;
|
|
158
|
+
}
|
|
159
|
+
if (shareAttach.shareAttachUrl) {
|
|
160
|
+
content += `\nURL: ${window.location.href}`;
|
|
161
|
+
}
|
|
162
|
+
return (_jsx(StyledActionButton, { tip: t('share to community'), title: _jsx(Icon, { icon: "tabler:share-2" }), target: "_blank", href: withQuery('https://community.arcblock.io/discussions/add?', {
|
|
163
|
+
boardId: 'aigne',
|
|
164
|
+
title: '[Share the generation from Aigne](Give your post a title...)',
|
|
165
|
+
content,
|
|
166
|
+
images: image,
|
|
167
|
+
}) }));
|
|
168
|
+
}
|
|
121
169
|
const StyledActionButton = styled(ActionButton)(({ theme }) => theme.unstable_sx({
|
|
122
170
|
fontSize: 'inherit',
|
|
123
171
|
p: 0.5,
|
|
124
|
-
minWidth: 0,
|
|
125
|
-
minHeight: 0,
|
|
172
|
+
minWidth: '0 !important',
|
|
173
|
+
minHeight: '0 !important',
|
|
126
174
|
}));
|
|
@@ -113,7 +113,7 @@ function AgentMessage({ message, hideAvatar }) {
|
|
|
113
113
|
p: 0.25,
|
|
114
114
|
} })), children: _jsx(Stack, { gap: 1, className: "message-response", children: ((_d = message.outputs) === null || _d === void 0 ? void 0 : _d.content) && (_jsx(MarkdownRenderer, { className: isMessageLoading ? 'writing' : '', children: message.outputs.content })) }) })) : (isMessageLoading && (_jsx(Skeleton, { variant: "rectangular", height: 24 + 8 + 8,
|
|
115
115
|
// only response with loading
|
|
116
|
-
className: "message-response" }))), (_f = (_e = message.outputs) === null || _e === void 0 ? void 0 : _e.objects) === null || _f === void 0 ? void 0 : _f.map((object) =>
|
|
116
|
+
className: "message-response" }))), (_f = (_e = message.outputs) === null || _e === void 0 ? void 0 : _e.objects) === null || _f === void 0 ? void 0 : _f.map((object, index) => _jsx(MessageMetadataRenderer, { object: object }, index)), message.error && _jsx(MessageErrorView, { error: message.error })] })] })] }));
|
|
117
117
|
}
|
|
118
118
|
export function MessageItemWrapper(_a) {
|
|
119
119
|
var _b;
|
|
@@ -37,7 +37,7 @@ export default function PhotoGalleryItem() {
|
|
|
37
37
|
const { message } = useCurrentMessage();
|
|
38
38
|
const [openDialog, setOpenDialog] = useState(false);
|
|
39
39
|
const objects = (_b = (_a = message.outputs) === null || _a === void 0 ? void 0 : _a.objects) !== null && _b !== void 0 ? _b : [];
|
|
40
|
-
const images = objects.flatMap((i) => { var _a; return (_a = i.data[RuntimeOutputVariable.images]) !== null &&
|
|
40
|
+
const images = objects.flatMap((i) => { var _a, _b; return (_b = (_a = i.data) === null || _a === void 0 ? void 0 : _a[RuntimeOutputVariable.images]) !== null && _b !== void 0 ? _b : []; });
|
|
41
41
|
if (!images.length && message.error) {
|
|
42
42
|
return (_jsx(Stack, { alignItems: "center", justifyContent: "center", sx: {
|
|
43
43
|
aspectRatio: 1,
|
|
@@ -225,7 +225,7 @@ export default function V0Output() {
|
|
|
225
225
|
overflowY: 'auto',
|
|
226
226
|
scrollbarWidth: 'thin',
|
|
227
227
|
scrollbarColor: 'grey transparent',
|
|
228
|
-
}, propertiesValueMap: propertiesValueMap }) }), objects === null || objects === void 0 ? void 0 : objects.map((item, index) => _jsx(MessageMetadataRenderer, { object: item
|
|
228
|
+
}, propertiesValueMap: propertiesValueMap }) }), objects === null || objects === void 0 ? void 0 : objects.map((item, index) => _jsx(MessageMetadataRenderer, { object: item }, index)), !isMessageLoading && ((_b = message.outputs) === null || _b === void 0 ? void 0 : _b.content) && (_jsx(ShareActions, { direction: "row", justifyContent: "flex-end", sx: { mt: 2 } })), _jsxs(Suspense, { fallback: _jsx(Loading, {}), children: [_jsx(Drawer, { anchor: isMobile ? 'bottom' : 'right', open: !!code, onClose: onCloseCode, children: _jsxs(Box, { sx: Object.assign({ p: 2, pt: 0 }, (isMobile ? { maxHeight: '70vh' } : { maxWidth: '70vw' })), children: [_jsxs(Box, { sx: {
|
|
229
229
|
py: 2,
|
|
230
230
|
position: 'sticky',
|
|
231
231
|
top: 0,
|
|
@@ -7,17 +7,6 @@ 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
|
-
};
|
|
21
10
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
11
|
import Empty from '@arcblock/ux/lib/Empty';
|
|
23
12
|
import RelativeTime from '@arcblock/ux/lib/RelativeTime';
|
|
@@ -291,19 +280,17 @@ function V0DetailRender() {
|
|
|
291
280
|
backgroundColor: 'background.block',
|
|
292
281
|
flex: 1,
|
|
293
282
|
maxWidth: isMobile ? '100%' : `calc(100% - ${sliderWidth}px - 16px)`,
|
|
294
|
-
}, children: _jsx(AgentOutputRender, { message: currentMessage }) })] }));
|
|
283
|
+
}, children: currentMessage && _jsx(AgentOutputRender, { message: currentMessage }) })] }));
|
|
295
284
|
}
|
|
296
|
-
function AgentInputRender(
|
|
297
|
-
var props = __rest(_a, []);
|
|
285
|
+
function AgentInputRender() {
|
|
298
286
|
const { appearanceInput } = useAppearances();
|
|
299
287
|
if (!(appearanceInput === null || appearanceInput === void 0 ? void 0 : appearanceInput.componentId))
|
|
300
288
|
return null;
|
|
301
|
-
return (_jsx(Suspense, { children: _jsx(CustomComponentRenderer, { componentId: appearanceInput.componentId, properties: appearanceInput.componentProperties
|
|
289
|
+
return (_jsx(Suspense, { children: _jsx(CustomComponentRenderer, { componentId: appearanceInput.componentId, properties: appearanceInput.componentProperties }) }));
|
|
302
290
|
}
|
|
303
|
-
function AgentOutputRender(
|
|
304
|
-
var { message } = _a, props = __rest(_a, ["message"]);
|
|
291
|
+
function AgentOutputRender({ message }) {
|
|
305
292
|
const { appearanceOutput } = useAppearances();
|
|
306
293
|
if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId) || !message)
|
|
307
294
|
return null;
|
|
308
|
-
return (_jsx(CurrentAgentProvider, { agentId: message.
|
|
295
|
+
return (_jsx(CurrentAgentProvider, { agentId: message.agentId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsx(Suspense, { children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProperties }) }) }) }));
|
|
309
296
|
}
|
|
@@ -127,11 +127,11 @@ export function CodeRenderByMessage({ zoom, message, minHeight = 200, sx, proper
|
|
|
127
127
|
return _jsx(RetryComponent, { message: message });
|
|
128
128
|
}
|
|
129
129
|
return (_d = (_c = message === null || message === void 0 ? void 0 : message.outputs) === null || _c === void 0 ? void 0 : _c.objects) === null || _d === void 0 ? void 0 : _d.map((item) => {
|
|
130
|
-
var _a, _b
|
|
130
|
+
var _a, _b;
|
|
131
131
|
const { taskId } = item;
|
|
132
132
|
// @ts-ignore
|
|
133
|
-
const code =
|
|
134
|
-
return (_jsx(CodePreviewMemo, { componentId: `code-preview-${taskId}`, code: code, propertiesValue: ((
|
|
133
|
+
const code = item === null || item === void 0 ? void 0 : item[codeField];
|
|
134
|
+
return (_jsx(CodePreviewMemo, { componentId: `code-preview-${taskId}`, code: code, propertiesValue: ((_a = propertiesValueMap === null || propertiesValueMap === void 0 ? void 0 : propertiesValueMap[taskId]) === null || _a === void 0 ? void 0 : _a[locale]) || ((_b = propertiesValueMap === null || propertiesValueMap === void 0 ? void 0 : propertiesValueMap[taskId]) === null || _b === void 0 ? void 0 : _b.en) || {}, message: message }, item.taskId));
|
|
135
135
|
});
|
|
136
136
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
137
137
|
}, [isMessageLoading, (_a = message === null || message === void 0 ? void 0 : message.outputs) === null || _a === void 0 ? void 0 : _a.objects, propertiesValueMap, locale]);
|
|
@@ -141,7 +141,7 @@ export function CodeRenderByMessage({ zoom, message, minHeight = 200, sx, proper
|
|
|
141
141
|
}
|
|
142
142
|
export const CodeRenderByMessageMemo = memo(CodeRenderByMessage);
|
|
143
143
|
export function getCurrentCodeByTaskId(message, taskId) {
|
|
144
|
-
var _a, _b, _c
|
|
144
|
+
var _a, _b, _c;
|
|
145
145
|
// @ts-ignore
|
|
146
|
-
return (
|
|
146
|
+
return (_c = (_b = (_a = message === null || message === void 0 ? void 0 : message.outputs) === null || _a === void 0 ? void 0 : _a.objects) === null || _b === void 0 ? void 0 : _b.find((item) => item.taskId === taskId)) === null || _c === void 0 ? void 0 : _c[codeField];
|
|
147
147
|
}
|