@blocklet/pages-kit 0.2.304 → 0.2.306

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 (42) hide show
  1. package/lib/cjs/builtin/async/ai-runtime/components/ActionButton.js +6 -6
  2. package/lib/cjs/builtin/async/ai-runtime/components/ShareActions/index.js +153 -0
  3. package/lib/cjs/builtin/async/ai-runtime/index.js +5 -1
  4. package/lib/cjs/builtin/async/ai-runtime/locales/index.js +2 -0
  5. package/lib/cjs/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageItemView.js +11 -8
  6. package/lib/cjs/builtin/async/ai-runtime/runtime-components/PhotoGalleryItem/index.js +4 -3
  7. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +38 -2
  8. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleOutput/index.js +4 -2
  9. package/lib/cjs/builtin/async/ai-runtime/state/agent.js +3 -1
  10. package/lib/cjs/builtin/async/ai-runtime/state/runtime.js +1 -2
  11. package/lib/cjs/builtin/async/ai-runtime/utils/download-image.js +41 -0
  12. package/lib/cjs/components/CustomComponentRenderer/DevProvider.js +26 -0
  13. package/lib/cjs/components/CustomComponentRenderer/index.js +8 -5
  14. package/lib/cjs/utils/builtin.js +1 -0
  15. package/lib/cjs/utils/inject-global-components.js +5 -0
  16. package/lib/esm/builtin/async/ai-runtime/components/ActionButton.js +6 -6
  17. package/lib/esm/builtin/async/ai-runtime/components/ShareActions/index.js +124 -0
  18. package/lib/esm/builtin/async/ai-runtime/index.js +2 -0
  19. package/lib/esm/builtin/async/ai-runtime/locales/index.js +2 -0
  20. package/lib/esm/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageItemView.js +11 -8
  21. package/lib/esm/builtin/async/ai-runtime/runtime-components/PhotoGalleryItem/index.js +4 -3
  22. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +39 -3
  23. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleOutput/index.js +4 -2
  24. package/lib/esm/builtin/async/ai-runtime/state/agent.js +3 -1
  25. package/lib/esm/builtin/async/ai-runtime/state/runtime.js +1 -2
  26. package/lib/esm/builtin/async/ai-runtime/utils/download-image.js +36 -0
  27. package/lib/esm/components/CustomComponentRenderer/DevProvider.js +21 -0
  28. package/lib/esm/components/CustomComponentRenderer/index.js +8 -5
  29. package/lib/esm/utils/builtin.js +1 -0
  30. package/lib/esm/utils/inject-global-components.js +2 -0
  31. package/lib/types/builtin/async/ai-runtime/components/ActionButton.d.ts +2 -1
  32. package/lib/types/builtin/async/ai-runtime/components/ShareActions/index.d.ts +2 -0
  33. package/lib/types/builtin/async/ai-runtime/index.d.ts +2 -0
  34. package/lib/types/builtin/async/ai-runtime/locales/index.d.ts +2 -0
  35. package/lib/types/builtin/async/ai-runtime/utils/download-image.d.ts +4 -0
  36. package/lib/types/components/CustomComponentRenderer/DevProvider.d.ts +9 -0
  37. package/lib/types/components/CustomComponentRenderer/index.d.ts +1 -1
  38. package/lib/types/utils/builtin.d.ts +1 -0
  39. package/package.json +9 -6
  40. package/lib/cjs/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageActions.js +0 -72
  41. package/lib/esm/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageActions.js +0 -66
  42. package/lib/types/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageActions.d.ts +0 -4
@@ -0,0 +1,124 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
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
+ import { jsx as _jsx } from "react/jsx-runtime";
22
+ import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
23
+ import { Icon } from '@iconify/react';
24
+ import { Stack, styled } from '@mui/material';
25
+ import { saveAs } from 'file-saver';
26
+ import { useMemo } from 'react';
27
+ import { withQuery } from 'ufo';
28
+ import { useLocaleContext } from '../../../../locale';
29
+ import { useCurrentAgent } from '../../contexts/CurrentAgent';
30
+ import { useCurrentMessage } from '../../contexts/CurrentMessage';
31
+ import { useRuntimeState } from '../../state/runtime';
32
+ import { convertImageToBlob, downloadImage } from '../../utils/download-image';
33
+ import ActionButton from '../ActionButton';
34
+ export default function ShareActions(_a) {
35
+ var _b;
36
+ var props = __rest(_a, []);
37
+ const { agent } = useCurrentAgent();
38
+ const sharing = useMemo(() => {
39
+ var _a, _b;
40
+ 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;
41
+ }, [agent]);
42
+ const items = (_b = sharing === null || sharing === void 0 ? void 0 : sharing.items) === null || _b === void 0 ? void 0 : _b.map((item) => {
43
+ const C = ShareActionsMap[item.to];
44
+ if (!C)
45
+ return null;
46
+ return _jsx(C, {});
47
+ }).filter((i) => !!i);
48
+ if (!(items === null || items === void 0 ? void 0 : items.length))
49
+ return null;
50
+ return _jsx(Stack, Object.assign({}, props, { children: items }));
51
+ }
52
+ const ShareActionsMap = {
53
+ twitter: ShareTwitter,
54
+ copy: ShareCopy,
55
+ saveAs: ShareSave,
56
+ };
57
+ function ShareTwitter() {
58
+ var _a, _b, _c, _d, _e, _f;
59
+ const { t } = useLocaleContext();
60
+ const { message } = useCurrentMessage();
61
+ const content = ((_a = message.result) === null || _a === void 0 ? void 0 : _a.content) ||
62
+ ((_f = (_e = (_d = (_c = (_b = message.result) === null || _b === void 0 ? void 0 : _b.objects) === null || _c === void 0 ? void 0 : _c.find((i) => { var _a; return (_a = i.data[RuntimeOutputVariable.images]) === null || _a === void 0 ? void 0 : _a.length; })) === null || _d === void 0 ? void 0 : _d.data[RuntimeOutputVariable.images]) === null || _e === void 0 ? void 0 : _e.at(0)) === null || _f === void 0 ? void 0 : _f.url);
63
+ if (!content)
64
+ return null;
65
+ return (_jsx(StyledActionButton, { tip: t('socialShare.shareToX'), title: _jsx(Icon, { icon: "tabler:brand-x" }), href: withQuery('https://twitter.com/intent/tweet', {
66
+ text: content,
67
+ url: window.location.href,
68
+ }), target: '_blank' }));
69
+ }
70
+ function ShareCopy() {
71
+ var _a, _b, _c, _d, _e, _f;
72
+ const { t } = useLocaleContext();
73
+ const { message } = useCurrentMessage();
74
+ const content = (_a = message.result) === null || _a === void 0 ? void 0 : _a.content;
75
+ const image = (_f = (_e = (_d = (_c = (_b = message.result) === null || _b === void 0 ? void 0 : _b.objects) === null || _c === void 0 ? void 0 : _c.find((i) => { var _a; return (_a = i.data[RuntimeOutputVariable.images]) === null || _a === void 0 ? void 0 : _a.length; })) === null || _d === void 0 ? void 0 : _d.data[RuntimeOutputVariable.images]) === null || _e === void 0 ? void 0 : _e.at(0)) === null || _f === void 0 ? void 0 : _f.url;
76
+ if (!content && !image)
77
+ return null;
78
+ return (_jsx(StyledActionButton, { 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* () {
79
+ if (content) {
80
+ window.navigator.clipboard.writeText(content);
81
+ }
82
+ else if (image) {
83
+ const imageBlob = yield convertImageToBlob(yield downloadImage({ url: image }));
84
+ window.navigator.clipboard.write([new ClipboardItem({ 'image/png': imageBlob })]);
85
+ }
86
+ }) }));
87
+ }
88
+ function ShareSave() {
89
+ var _a, _b, _c, _d, _e, _f;
90
+ const { t } = useLocaleContext();
91
+ const { message } = useCurrentMessage();
92
+ const { agent, appearancePage } = useRuntimeState();
93
+ const content = (_a = message.result) === null || _a === void 0 ? void 0 : _a.content;
94
+ const image = (_f = (_e = (_d = (_c = (_b = message.result) === null || _b === void 0 ? void 0 : _b.objects) === null || _c === void 0 ? void 0 : _c.find((i) => { var _a; return (_a = i.data[RuntimeOutputVariable.images]) === null || _a === void 0 ? void 0 : _a.length; })) === null || _d === void 0 ? void 0 : _d.data[RuntimeOutputVariable.images]) === null || _e === void 0 ? void 0 : _e.at(0)) === null || _f === void 0 ? void 0 : _f.url;
95
+ if (!content && !image)
96
+ return null;
97
+ return (_jsx(StyledActionButton, { tip: t('save'), tipSucceed: t('saved'), title: _jsx(Icon, { icon: "tabler:file" }), titleSucceed: _jsx(Icon, { icon: "tabler:file-check" }), onClick: () => __awaiter(this, void 0, void 0, function* () {
98
+ // @ts-ignore
99
+ const { default: html2pdf } = yield import('html2pdf.js');
100
+ if (content) {
101
+ const element = document.createElement('div');
102
+ element.innerText = content;
103
+ yield html2pdf()
104
+ .set({
105
+ margin: 1,
106
+ filename: `${(appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.name) || agent.name || agent.id} - ${message.taskId}.pdf`,
107
+ image: { type: 'jpeg', quality: 0.98 },
108
+ html2canvas: { scale: 2 },
109
+ jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' },
110
+ })
111
+ .from(element)
112
+ .save();
113
+ }
114
+ else if (image) {
115
+ saveAs(image, `${(appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.name) || agent.name || agent.id}.png`);
116
+ }
117
+ }) }));
118
+ }
119
+ const StyledActionButton = styled(ActionButton)(({ theme }) => theme.unstable_sx({
120
+ fontSize: 'inherit',
121
+ p: 0.5,
122
+ minWidth: 0,
123
+ minHeight: 0,
124
+ }));
@@ -1,5 +1,7 @@
1
1
  export * from './contexts/CurrentAgent';
2
+ export { default as CurrentAgentProvider } from './contexts/CurrentAgent';
2
3
  export * from './contexts/CurrentMessage';
4
+ export { default as CurrentMessageProvider } from './contexts/CurrentMessage';
3
5
  export * from './state/runtime';
4
6
  export * from './state/session';
5
7
  export { default as Runtime } from './runtime/Runtime';
@@ -42,6 +42,7 @@ export const translations = {
42
42
  contentPlaceholder: 'Write anything...',
43
43
  cancel: 'Cancel',
44
44
  save: 'Save',
45
+ saved: 'Saved',
45
46
  edit: 'Edit',
46
47
  chat: 'Chat',
47
48
  subscribeNow: 'Subscribe Now',
@@ -135,6 +136,7 @@ export const translations = {
135
136
  contentPlaceholder: '写点什么吧...',
136
137
  cancel: '取消',
137
138
  save: '保存',
139
+ saved: '已保存',
138
140
  edit: '编辑',
139
141
  chat: '对话',
140
142
  subscribeNow: '立即订阅',
@@ -19,8 +19,8 @@ import React, { memo, useMemo, useState } from 'react';
19
19
  import { Avatar } from '../../../../arcblock/ux';
20
20
  import { useSessionContext } from '../../../../session';
21
21
  import MarkdownRenderer from '../../components/MarkdownRenderer';
22
+ import ShareActions from '../../components/ShareActions';
22
23
  import { useRuntimeState } from '../../state/runtime';
23
- import MessageActions from './MessageActions';
24
24
  import MessageErrorView from './MessageErrorView';
25
25
  import MessageMetadataRenderer from './MessageMetadataRenderer';
26
26
  const MessageItemView = memo((_a) => {
@@ -90,6 +90,7 @@ function AgentMessage({ message, hideAvatar }) {
90
90
  const isMobile = useMediaQuery(theme.breakpoints.down('sm'));
91
91
  return (_jsxs(Stack, { className: "ai-chat-message-ai", direction: "row", gap: 1.5, children: [!hideAvatar && (_jsx(Box, { children: _jsx(Avatar, { size: 40, did: (_d = globalThis.blocklet) === null || _d === void 0 ? void 0 : _d.appId, variant: "circle", shape: "circle", src: (_e = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.logo) === null || _e === void 0 ? void 0 : _e.url }) })), _jsxs(Box, { flex: 1, width: 0, children: [!hideAvatar && (_jsxs(MessageUserName, { children: [appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.name, _jsx(MessageTime, { time: message.createdAt })] })), _jsxs(React.Suspense, { children: [showMainMessage ? (_jsx(Tooltip, { placement: "right-start", slotProps: {
92
92
  popper: {
93
+ disablePortal: true,
93
94
  modifiers: [
94
95
  {
95
96
  name: 'offset',
@@ -100,14 +101,16 @@ function AgentMessage({ message, hideAvatar }) {
100
101
  ],
101
102
  },
102
103
  tooltip: {
103
- sx: {
104
- bgcolor: 'white',
105
- boxShadow: '0px 4px 8px 0px rgba(3, 7, 18, 0.08)',
106
- border: '1px solid rgba(229, 231, 235, 1)',
107
- p: 0.5,
108
- },
104
+ sx: { p: 0, bgcolor: 'white' },
109
105
  },
110
- }, title: !isMessageLoading && ((_f = message.result) === null || _f === void 0 ? void 0 : _f.content) && _jsx(MessageActions, { content: message.result.content }), children: _jsxs(Stack, { gap: 1, className: "message-response", children: [(_h = (_g = message.result) === null || _g === void 0 ? void 0 : _g.messages) === null || _h === void 0 ? void 0 : _h.map((childMsg, index) => {
106
+ }, title: !isMessageLoading &&
107
+ ((_f = message.result) === null || _f === void 0 ? void 0 : _f.content) && (_jsx(ShareActions, { sx: {
108
+ fontSize: '1rem',
109
+ boxShadow: '0px 4px 8px 0px rgba(3, 7, 18, 0.08)',
110
+ border: '1px solid rgba(229, 231, 235, 1)',
111
+ borderRadius: 1,
112
+ p: 0.25,
113
+ } })), children: _jsxs(Stack, { gap: 1, className: "message-response", children: [(_h = (_g = message.result) === null || _g === void 0 ? void 0 : _g.messages) === null || _h === void 0 ? void 0 : _h.map((childMsg, index) => {
111
114
  var _a, _b, _c, _d, _e, _f, _g;
112
115
  return ((_a = childMsg.result) === null || _a === void 0 ? void 0 : _a.content) ? (_jsx(MarkdownRenderer, { className: isMessageLoading &&
113
116
  !((_b = message.result) === null || _b === void 0 ? void 0 : _b.content) &&
@@ -18,6 +18,7 @@ import { RelativeTime } from '../../../../arcblock/ux';
18
18
  import { useLocaleContext } from '../../../../locale';
19
19
  import { useSessionContext } from '../../../../session';
20
20
  import ActionButton from '../../components/ActionButton';
21
+ import ShareActions from '../../components/ShareActions';
21
22
  import UserInfo from '../../components/UserInfo';
22
23
  import { useCurrentAgent } from '../../contexts/CurrentAgent';
23
24
  import { useCurrentMessage } from '../../contexts/CurrentMessage';
@@ -93,12 +94,12 @@ function PromptView() {
93
94
  const { agent } = useCurrentAgent();
94
95
  const params = useMemo(() => {
95
96
  var _a;
96
- return (_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.filter(isValidInput).map((i) => { var _a; return [i.label || i.key, (_a = message.parameters) === null || _a === void 0 ? void 0 : _a[i.key]]; }).filter((i) => i[1]);
97
+ 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.parameters) === null || _b === void 0 ? void 0 : _b[i.key]]; }).filter((i) => i[1]);
97
98
  }, [agent.parameters, message.parameters]);
98
99
  if ((params === null || params === void 0 ? void 0 : params.length) === 1) {
99
100
  return (_a = params[0]) === null || _a === void 0 ? void 0 : _a[1];
100
101
  }
101
- return params === null || params === void 0 ? void 0 : params.map(([key, value]) => (_jsxs(Typography, { sx: { wordWrap: 'break-word' }, children: [_jsxs(Box, { component: "span", sx: { color: 'text.secondary' }, children: [key, ":"] }), "\u00A0\u00A0", _jsx("span", { children: value })] }, key)));
102
+ return params === null || params === void 0 ? void 0 : params.map(([key, value]) => (_jsxs(Typography, { sx: { wordWrap: 'break-word' }, children: [_jsx(Box, { component: "span", sx: { color: 'text.secondary' }, children: key }), "\u00A0\u00A0", _jsx("span", { children: value })] }, key)));
102
103
  }
103
104
  function PromptDialog(_a) {
104
105
  var _b, _c, _d;
@@ -145,5 +146,5 @@ function PromptDialog(_a) {
145
146
  window.navigator.clipboard.writeText(parameters === null || parameters === void 0 ? void 0 : parameters.question);
146
147
  }, sx: {
147
148
  borderRadius,
148
- } }) })] })] }) })] })));
149
+ } }) }), _jsx(ShareActions, { direction: "row", justifyContent: "flex-end", sx: { mt: 2 } })] })] }) })] })));
149
150
  }
@@ -10,7 +10,7 @@ var __rest = (this && this.__rest) || function (s, e) {
10
10
  return t;
11
11
  };
12
12
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
13
- import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
13
+ import { RuntimeOutputVariable, } from '@blocklet/ai-runtime/types';
14
14
  import { Box, Stack, ThemeProvider, createTheme, useTheme } from '@mui/material';
15
15
  import { memo, useEffect, useMemo } from 'react';
16
16
  import { useScrollToBottom } from 'react-scroll-to-bottom';
@@ -18,13 +18,14 @@ import CustomComponentRenderer from '../../../../../components/CustomComponentRe
18
18
  import { useSessionContext } from '../../../../session';
19
19
  import SimpleHeader from '../../components/Header/SimpleHeader';
20
20
  import SimpleLayout from '../../components/Layout/SimpleLayout';
21
+ import MarkdownRenderer from '../../components/MarkdownRenderer';
21
22
  import ScrollView from '../../components/ScrollView';
22
23
  import UserInfo from '../../components/UserInfo';
23
24
  import CurrentAgentProvider, { useCurrentAgent } from '../../contexts/CurrentAgent';
24
25
  import CurrentMessageProvider from '../../contexts/CurrentMessage';
25
26
  import { useRuntimeState } from '../../state/runtime';
26
27
  import { useSessionState } from '../../state/session';
27
- import MessageSuggestedQuestions from '../ChatOutput/MessageSuggestedQuestions';
28
+ import MessageSuggestedQuestions, { MessageSuggestedQuestion } from '../ChatOutput/MessageSuggestedQuestions';
28
29
  export default function SimpleChat({ primaryColor, scrollViewProps = { scroll: 'window', initialScrollBehavior: 'auto' }, }) {
29
30
  useSessionState({ autoLoad: true });
30
31
  const inheritedTheme = useTheme();
@@ -68,8 +69,9 @@ function AgentInputRender(_a) {
68
69
  function OutputView(_a) {
69
70
  var props = __rest(_a, []);
70
71
  const messages = useSessionState()((s) => s.messages);
72
+ const loading = useSessionState()((s) => s.loading);
71
73
  const lastMessage = messages === null || messages === void 0 ? void 0 : messages.at(-1);
72
- return (_jsxs(Stack, Object.assign({ gap: 2 }, props, { children: [messages === null || messages === void 0 ? void 0 : messages.map((message) => _jsx(OutputItemView, { message: message }, message.taskId)), lastMessage && _jsx(SuggestedQuestionsView, { message: lastMessage })] })));
74
+ return (_jsxs(Stack, Object.assign({ gap: 2 }, props, { children: [_jsx(OpeningMessageView, {}), messages === null || messages === void 0 ? void 0 : messages.map((message) => _jsx(OutputItemView, { message: message }, message.taskId)), lastMessage && _jsx(SuggestedQuestionsView, { message: lastMessage }), !loading && !(messages === null || messages === void 0 ? void 0 : messages.length) && _jsx(OpeningQuestionsView, {})] })));
73
75
  }
74
76
  const OutputItemView = memo(({ message }) => {
75
77
  var _a, _b, _c, _d, _e;
@@ -95,3 +97,37 @@ function SuggestedQuestionsView({ message }) {
95
97
  execute({ aid, parameters: Object.assign(Object.assign({}, message.parameters), { question: item.question }) });
96
98
  } })) : null }));
97
99
  }
100
+ const OpeningMessageView = memo(() => {
101
+ var _a, _b;
102
+ const { childAgentId, appearancePage } = useRuntimeState();
103
+ const { agent } = useCurrentAgent({ agentId: childAgentId });
104
+ const openingMessage = useMemo(() => {
105
+ var _a, _b;
106
+ return (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.openingMessage)) === null || _b === void 0 ? void 0 : _b.initialValue;
107
+ }, [agent]);
108
+ if (!(openingMessage === null || openingMessage === void 0 ? void 0 : openingMessage.message))
109
+ return null;
110
+ return (_jsx(Box, { children: _jsx(UserInfo, { name: (appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.name) || agent.name, did: (_a = globalThis.blocklet) === null || _a === void 0 ? void 0 : _a.appId, avatar: (_b = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.logo) === null || _b === void 0 ? void 0 : _b.url, alignItems: "flex-start", children: _jsx(Box, { sx: {
111
+ bgcolor: 'rgba(229, 231, 235, 1)',
112
+ borderRadius: 1,
113
+ borderTopLeftRadius: 2,
114
+ px: 2,
115
+ py: 1,
116
+ mt: 0.5,
117
+ mr: 5,
118
+ }, children: _jsx(MarkdownRenderer, { children: openingMessage.message }) }) }) }));
119
+ });
120
+ function OpeningQuestionsView() {
121
+ const { childAgentId } = useRuntimeState();
122
+ const { execute } = useRuntimeState();
123
+ const { aid, agent } = useCurrentAgent({ agentId: childAgentId });
124
+ const openingQuestions = useMemo(() => {
125
+ var _a, _b, _c, _d;
126
+ return (_d = (_c = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.openingQuestions)) === null || _b === void 0 ? void 0 : _b.initialValue) === null || _c === void 0 ? void 0 : _c.items) === null || _d === void 0 ? void 0 : _d.filter((i) => !!i.title);
127
+ }, [agent]);
128
+ if (!(openingQuestions === null || openingQuestions === void 0 ? void 0 : openingQuestions.length))
129
+ return null;
130
+ return (_jsx(Box, { ml: 6.5, mr: 2.5, children: _jsx(Stack, { gap: 1, children: openingQuestions.map((item) => {
131
+ return (_jsx(MessageSuggestedQuestion, { onClick: () => execute({ aid, parameters: Object.assign(Object.assign({}, item.parameters), { question: item.parameters.question || item.title }) }), children: item.title }, item.id));
132
+ }) }) }));
133
+ }
@@ -1,13 +1,15 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Stack } from '@mui/material';
3
3
  import MarkdownRenderer from '../../components/MarkdownRenderer';
4
+ import ShareActions from '../../components/ShareActions';
4
5
  import { useCurrentMessage } from '../../contexts/CurrentMessage';
5
6
  import MessageErrorView from '../ChatOutput/MessageErrorView';
6
7
  import MessageMetadataRenderer from '../ChatOutput/MessageMetadataRenderer';
7
8
  export default function SimpleOutput() {
8
- var _a, _b;
9
+ var _a, _b, _c;
9
10
  const { message } = useCurrentMessage();
10
11
  const objects = (_a = message.result) === null || _a === void 0 ? void 0 : _a.objects;
11
12
  const { error } = message;
12
- return (_jsxs(Stack, { gap: 2, boxShadow: 1, borderRadius: 1, p: 2, children: [_jsx(MarkdownRenderer, { children: (_b = message.result) === null || _b === void 0 ? void 0 : _b.content }), error && _jsx(MessageErrorView, { error: error }), objects === null || objects === void 0 ? void 0 : objects.map((item) => _jsx(MessageMetadataRenderer, { object: item.data }))] }));
13
+ const isMessageLoading = (message.loading || !message.result) && !message.error;
14
+ return (_jsxs(Stack, { gap: 2, boxShadow: 1, borderRadius: 1, p: 2, children: [_jsx(MarkdownRenderer, { children: (_b = message.result) === null || _b === void 0 ? void 0 : _b.content }), error && _jsx(MessageErrorView, { error: error }), objects === null || objects === void 0 ? void 0 : objects.map((item) => _jsx(MessageMetadataRenderer, { object: item.data })), !isMessageLoading && ((_c = message.result) === null || _c === void 0 ? void 0 : _c.content) && (_jsx(ShareActions, { direction: "row", justifyContent: "flex-end", sx: { mt: 2 } }))] }));
13
15
  }
@@ -10,6 +10,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { create } from 'zustand';
11
11
  import { immer } from 'zustand/middleware/immer';
12
12
  import { getAgent } from '../api/agent';
13
+ import { useRuntimeContext } from '../contexts/Runtime';
13
14
  import { createCachedStore } from '../utils/zustand';
14
15
  export const createAgentState = ({ aid, working, agent }) => {
15
16
  const key = working ? `${aid}-working` : aid;
@@ -42,7 +43,8 @@ export const createAgentState = ({ aid, working, agent }) => {
42
43
  const LOADING_TASKS = {};
43
44
  export function useAgentState({ aid, working }) {
44
45
  var _a;
45
- const state = createAgentState({ aid, working })();
46
+ const runtimeState = useRuntimeContext();
47
+ const state = createAgentState({ aid, working: working !== null && working !== void 0 ? working : runtimeState.working })();
46
48
  if (!state.agent) {
47
49
  if (state.error)
48
50
  throw state.error;
@@ -41,8 +41,7 @@ export function useRuntimeState() {
41
41
  }), [authSession.user, exec, working, login]);
42
42
  const appearancePage = useMemo(() => {
43
43
  var _a, _b;
44
- const initialValue = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.appearancePage)) === null || _b === void 0 ? void 0 : _b.initialValue;
45
- return initialValue;
44
+ return (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.appearancePage)) === null || _b === void 0 ? void 0 : _b.initialValue;
46
45
  }, [agent]);
47
46
  const childAgentId = useMemo(() => {
48
47
  var _a, _b, _c, _d, _e, _f;
@@ -0,0 +1,36 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ export function downloadImage(_a) {
11
+ return __awaiter(this, arguments, void 0, function* ({ url }) {
12
+ return new Promise((resolve, reject) => {
13
+ const image = new Image();
14
+ image.src = url;
15
+ image.onload = () => resolve(image);
16
+ image.onerror = (e) => reject(e);
17
+ });
18
+ });
19
+ }
20
+ export function convertImageToBlob(image) {
21
+ return __awaiter(this, void 0, void 0, function* () {
22
+ return new Promise((resolve, reject) => {
23
+ const c = document.createElement('canvas');
24
+ const ctx = c.getContext('2d');
25
+ c.width = image.naturalWidth;
26
+ c.height = image.naturalHeight;
27
+ ctx.drawImage(image, 0, 0);
28
+ c.toBlob((blob) => {
29
+ if (blob)
30
+ resolve(blob);
31
+ else
32
+ reject(new Error('Failed to get image'));
33
+ }, 'image/png', 1);
34
+ });
35
+ });
36
+ }
@@ -0,0 +1,21 @@
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 { createContext, useContext } from 'react';
14
+ const devContext = createContext(undefined);
15
+ export function DevProvider(_a) {
16
+ var { dev } = _a, props = __rest(_a, ["dev"]);
17
+ return _jsx(devContext.Provider, Object.assign({ value: dev }, props));
18
+ }
19
+ export function useDev() {
20
+ return useContext(devContext);
21
+ }
@@ -13,23 +13,26 @@ import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import { Alert, Box } from '@mui/material';
14
14
  import { ErrorBoundary } from 'react-error-boundary';
15
15
  import { RenderNestedComponent } from '../../utils/property';
16
+ import { DevProvider, useDev } from './DevProvider';
16
17
  import { useComponent } from './state';
17
18
  export * from './state';
18
19
  const MAXIMUM_RENDER_STACK_SIZE = 20;
19
20
  export default function CustomComponentRenderer(_a) {
20
21
  var _b;
21
- var props = __rest(_a, []);
22
- return (_jsx(ErrorBoundary, { fallbackRender: ErrorView, resetKeys: [Date.now()], children: _jsx(ComponentRenderer, Object.assign({}, props, { instanceId: (_b = props.instanceId) !== null && _b !== void 0 ? _b : props.componentId })) }));
22
+ var { dev } = _a, props = __rest(_a, ["dev"]);
23
+ const inheritedDev = useDev();
24
+ return (_jsx(ErrorBoundary, { fallbackRender: ErrorView, resetKeys: [Date.now()], children: _jsx(DevProvider, { dev: dev !== null && dev !== void 0 ? dev : inheritedDev, children: _jsx(ComponentRenderer, Object.assign({}, props, { instanceId: (_b = props.instanceId) !== null && _b !== void 0 ? _b : props.componentId })) }) }));
23
25
  }
24
26
  function ErrorView({ error }) {
25
27
  return (_jsx(Box, { children: _jsx(Alert, { severity: "error", children: error.message }) }));
26
28
  }
27
29
  function ComponentRenderer(_a) {
28
30
  var { renderCount = 0 } = _a, props = __rest(_a, ["renderCount"]);
31
+ const dev = useDev();
29
32
  if (renderCount > MAXIMUM_RENDER_STACK_SIZE) {
30
33
  throw new Error('Maximum render stack size exceeded');
31
34
  }
32
- const component = useComponent(props);
35
+ const component = useComponent(Object.assign(Object.assign({}, props), { dev }));
33
36
  if (component === null || component === void 0 ? void 0 : component.error) {
34
37
  return _jsx(ErrorView, { error: component.error });
35
38
  }
@@ -38,11 +41,11 @@ function ComponentRenderer(_a) {
38
41
  }
39
42
  return null;
40
43
  }
41
- function Renderer({ renderCount, Component, locale, props, dev, }) {
44
+ function Renderer({ renderCount, Component, locale, props, }) {
42
45
  const componentProps = Object.fromEntries(Object.entries(props).map(([key, val]) => {
43
46
  return [
44
47
  key,
45
- (val === null || val === void 0 ? void 0 : val.type) === RenderNestedComponent ? (_jsx(ComponentRenderer, { locale: locale, renderCount: renderCount, componentId: val.componentId, properties: val.properties, props: val.props, dev: dev })) : (val),
48
+ (val === null || val === void 0 ? void 0 : val.type) === RenderNestedComponent ? (_jsx(ComponentRenderer, { locale: locale, renderCount: renderCount, componentId: val.componentId, properties: val.properties, props: val.props })) : (val),
46
49
  ];
47
50
  }));
48
51
  return _jsx(Component, Object.assign({ locale: locale }, componentProps));
@@ -14,6 +14,7 @@ import * as stream from '../builtin/stream';
14
14
  import * as utils from '../builtin/utils';
15
15
  import * as zustandMiddlewareImmer from '../builtin/zustand/middleware/immer';
16
16
  export const BuiltinModules = {
17
+ '@blocklet/pages-kit/builtin/pages-kit': {},
17
18
  '@blocklet/pages-kit/builtin/dayjs': dayjs,
18
19
  '@blocklet/pages-kit/builtin/utils': utils,
19
20
  '@blocklet/pages-kit/builtin/call': call,
@@ -22,11 +22,13 @@ import * as stream from '../builtin/stream';
22
22
  import * as utils from '../builtin/utils';
23
23
  import * as zustand from '../builtin/zustand';
24
24
  import * as zustandMiddlewareImmer from '../builtin/zustand/middleware/immer';
25
+ import CustomComponentRenderer from '../components/CustomComponentRenderer';
25
26
  import { BuiltinModulesGlobalVariableName } from '../types/builtin';
26
27
  function injectGlobalComponents() {
27
28
  const win = window;
28
29
  win[BuiltinModulesGlobalVariableName] = {
29
30
  modules: {
31
+ '@blocklet/pages-kit/builtin/pages-kit': { CustomComponentRenderer },
30
32
  '@blocklet/pages-kit/builtin/dayjs': dayjs,
31
33
  '@blocklet/pages-kit/builtin/utils': utils,
32
34
  '@blocklet/pages-kit/builtin/react': react,
@@ -1,4 +1,5 @@
1
1
  import { LoadingButtonProps } from '@mui/lab';
2
+ import { TooltipProps } from '@mui/material';
2
3
  import { ReactNode } from 'react';
3
4
  export default function ActionButton({ tip, tipSucceed, title, titleSucceed, icon, iconSucceed, autoReset, placement, ...props }: {
4
5
  tip?: ReactNode;
@@ -8,5 +9,5 @@ export default function ActionButton({ tip, tipSucceed, title, titleSucceed, ico
8
9
  icon?: ReactNode;
9
10
  iconSucceed?: ReactNode;
10
11
  autoReset?: boolean;
11
- placement?: 'top' | 'bottom' | 'left' | 'right' | 'top-start' | 'top-end' | 'bottom-start' | 'bottom-end' | 'right-start' | 'right-end' | 'left-start' | 'left-end';
12
+ placement?: TooltipProps['placement'];
12
13
  } & Omit<Partial<LoadingButtonProps>, 'title'>): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,2 @@
1
+ import { StackProps } from '@mui/material';
2
+ export default function ShareActions({ ...props }: StackProps): import("react/jsx-runtime").JSX.Element | null;
@@ -1,5 +1,7 @@
1
1
  export * from './contexts/CurrentAgent';
2
+ export { default as CurrentAgentProvider } from './contexts/CurrentAgent';
2
3
  export * from './contexts/CurrentMessage';
4
+ export { default as CurrentMessageProvider } from './contexts/CurrentMessage';
3
5
  export * from './state/runtime';
4
6
  export * from './state/session';
5
7
  export { default as Runtime } from './runtime/Runtime';
@@ -42,6 +42,7 @@ export declare const translations: {
42
42
  contentPlaceholder: string;
43
43
  cancel: string;
44
44
  save: string;
45
+ saved: string;
45
46
  edit: string;
46
47
  chat: string;
47
48
  subscribeNow: string;
@@ -123,6 +124,7 @@ export declare const translations: {
123
124
  contentPlaceholder: string;
124
125
  cancel: string;
125
126
  save: string;
127
+ saved: string;
126
128
  edit: string;
127
129
  chat: string;
128
130
  subscribeNow: string;
@@ -0,0 +1,4 @@
1
+ export declare function downloadImage({ url }: {
2
+ url: string;
3
+ }): Promise<HTMLImageElement>;
4
+ export declare function convertImageToBlob(image: HTMLImageElement): Promise<Blob>;
@@ -0,0 +1,9 @@
1
+ import { ReactNode } from 'react';
2
+ import type { CustomComponentRendererDevProps } from '.';
3
+ export interface DevContext extends CustomComponentRendererDevProps {
4
+ }
5
+ export declare function DevProvider({ dev, ...props }: {
6
+ dev?: DevContext;
7
+ children?: ReactNode;
8
+ }): import("react/jsx-runtime").JSX.Element;
9
+ export declare function useDev(): DevContext | undefined;
@@ -24,4 +24,4 @@ export interface CustomComponentRendererProps {
24
24
  };
25
25
  dev?: CustomComponentRendererDevProps;
26
26
  }
27
- export default function CustomComponentRenderer({ ...props }: CustomComponentRendererProps): import("react/jsx-runtime").JSX.Element;
27
+ export default function CustomComponentRenderer({ dev, ...props }: CustomComponentRendererProps): import("react/jsx-runtime").JSX.Element;
@@ -14,6 +14,7 @@ import * as stream from '../builtin/stream';
14
14
  import * as utils from '../builtin/utils';
15
15
  import * as zustandMiddlewareImmer from '../builtin/zustand/middleware/immer';
16
16
  export declare const BuiltinModules: {
17
+ '@blocklet/pages-kit/builtin/pages-kit': {};
17
18
  '@blocklet/pages-kit/builtin/dayjs': typeof dayjs;
18
19
  '@blocklet/pages-kit/builtin/utils': typeof utils;
19
20
  '@blocklet/pages-kit/builtin/call': typeof call;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/pages-kit",
3
- "version": "0.2.304",
3
+ "version": "0.2.306",
4
4
  "description": "Pages Kit components and utils",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -82,15 +82,18 @@
82
82
  },
83
83
  "dependencies": {
84
84
  "@arcblock/did-connect": "^2.9.77",
85
- "@blocklet/ai-kit": "^0.1.30",
86
- "@blocklet/ai-runtime": "^0.1.376",
85
+ "@blocklet/ai-kit": "^0.1.31",
86
+ "@blocklet/ai-runtime": "^0.1.381",
87
87
  "@blocklet/js-sdk": "1.16.26",
88
88
  "@blocklet/sdk": "^1.16.26",
89
89
  "@iconify/react": "^4.1.1",
90
90
  "@lottiefiles/lottie-player": "^1.7.1",
91
+ "@types/file-saver": "^2.0.7",
91
92
  "axios": "^1.6.8",
92
93
  "dayjs": "^1.11.11",
93
94
  "eventsource-parser": "^1.1.2",
95
+ "file-saver": "^2.0.5",
96
+ "html2pdf.js": "^0.10.1",
94
97
  "immer": "^10.1.1",
95
98
  "js-base64": "^3.7.7",
96
99
  "lodash": "^4.17.21",
@@ -134,7 +137,7 @@
134
137
  "@types/lodash": "^4.17.1",
135
138
  "@types/mustache": "^4.2.5",
136
139
  "@types/node-fetch": "^2.6.11",
137
- "@types/react": "^18.3.1",
140
+ "@types/react": "^18.3.2",
138
141
  "@types/react-helmet": "^6.1.11",
139
142
  "@types/react-scroll-to-bottom": "^4.2.5",
140
143
  "@types/react-syntax-highlighter": "^15.5.13",
@@ -142,8 +145,8 @@
142
145
  "npm-run-all": "^4.1.5",
143
146
  "react": "^18.3.1",
144
147
  "react-dom": "^18.3.1",
145
- "react-router-dom": "^6.23.0",
146
- "rimraf": "^5.0.5"
148
+ "react-router-dom": "^6.23.1",
149
+ "rimraf": "^5.0.6"
147
150
  },
148
151
  "scripts": {
149
152
  "lint": "eslint src --ext .mjs,.js,.jsx,.ts,.tsx",