@blocklet/pages-kit 0.2.316 → 0.2.317

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 (107) hide show
  1. package/lib/cjs/builtin/async/ai-runtime/components/MarkdownRenderer.js +26 -2
  2. package/lib/cjs/builtin/async/ai-runtime/components/OutputFieldContainer/index.js +22 -0
  3. package/lib/cjs/builtin/async/ai-runtime/components/ShareActions/index.js +1 -1
  4. package/lib/cjs/builtin/async/ai-runtime/constants.js +34 -4
  5. package/lib/cjs/builtin/async/ai-runtime/contexts/ActiveAgent.js +28 -0
  6. package/lib/cjs/builtin/async/ai-runtime/contexts/ComponentPreferences.js +27 -0
  7. package/lib/cjs/builtin/async/ai-runtime/contexts/CurrentMessage.js +2 -2
  8. package/lib/cjs/builtin/async/ai-runtime/hooks/use-appearances.js +10 -5
  9. package/lib/cjs/builtin/async/ai-runtime/hooks/use-header-menu.js +39 -0
  10. package/lib/cjs/builtin/async/ai-runtime/index.js +17 -3
  11. package/lib/cjs/builtin/async/ai-runtime/runtime/ChatBotButton/index.js +3 -2
  12. package/lib/cjs/builtin/async/ai-runtime/runtime/Runtime/index.js +4 -6
  13. package/lib/cjs/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchRelatedQuestionsView.js +60 -0
  14. package/lib/cjs/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchSourcesView.js +50 -0
  15. package/lib/cjs/builtin/async/ai-runtime/runtime-components/ImagesView/index.js +30 -0
  16. package/lib/cjs/builtin/async/ai-runtime/runtime-components/MarkdownView/index.js +13 -0
  17. package/lib/cjs/builtin/async/ai-runtime/runtime-components/OpeningQuestionsView/index.js +46 -0
  18. package/lib/cjs/builtin/async/ai-runtime/runtime-components/OutputFieldView/type.js +2 -0
  19. package/lib/cjs/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +5 -5
  20. package/lib/cjs/builtin/async/ai-runtime/runtime-components/ReferencedLinksView/index.js +26 -0
  21. package/lib/cjs/builtin/async/ai-runtime/runtime-components/ShareView/index.js +16 -0
  22. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/BackgroundImage.js +25 -0
  23. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/InputsView.js +73 -0
  24. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/MessageView.js +58 -0
  25. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/MessagesView.js +33 -0
  26. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningMessageView.js +23 -0
  27. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningQuestionsView.js +20 -0
  28. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/UserMessageView.js +26 -0
  29. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +28 -134
  30. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleOutput/index.js +35 -9
  31. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +5 -5
  32. package/lib/cjs/builtin/async/ai-runtime/runtime-components/SuggestedQuestionsView/index.js +54 -0
  33. package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Page.js +5 -5
  34. package/lib/cjs/builtin/async/ai-runtime/state/runtime.js +1 -6
  35. package/lib/cjs/builtin/mui/material.js +4 -2
  36. package/lib/cjs/tsconfig.tsbuildinfo +1 -1
  37. package/lib/cjs/utils/inject-global-components.js +2 -0
  38. package/lib/esm/builtin/async/ai-runtime/components/MarkdownRenderer.js +3 -2
  39. package/lib/esm/builtin/async/ai-runtime/components/OutputFieldContainer/index.js +19 -0
  40. package/lib/esm/builtin/async/ai-runtime/components/ShareActions/index.js +2 -2
  41. package/lib/esm/builtin/async/ai-runtime/constants.js +32 -3
  42. package/lib/esm/builtin/async/ai-runtime/contexts/ActiveAgent.js +23 -0
  43. package/lib/esm/builtin/async/ai-runtime/contexts/ComponentPreferences.js +22 -0
  44. package/lib/esm/builtin/async/ai-runtime/contexts/CurrentMessage.js +2 -2
  45. package/lib/esm/builtin/async/ai-runtime/hooks/use-appearances.js +10 -5
  46. package/lib/esm/builtin/async/ai-runtime/hooks/use-header-menu.js +32 -0
  47. package/lib/esm/builtin/async/ai-runtime/index.js +8 -1
  48. package/lib/esm/builtin/async/ai-runtime/runtime/ChatBotButton/index.js +3 -2
  49. package/lib/esm/builtin/async/ai-runtime/runtime/Runtime/index.js +4 -6
  50. package/lib/esm/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchRelatedQuestionsView.js +54 -0
  51. package/lib/esm/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchSourcesView.js +44 -0
  52. package/lib/esm/builtin/async/ai-runtime/runtime-components/ImagesView/index.js +24 -0
  53. package/lib/esm/builtin/async/ai-runtime/runtime-components/MarkdownView/index.js +7 -0
  54. package/lib/esm/builtin/async/ai-runtime/runtime-components/OpeningQuestionsView/index.js +40 -0
  55. package/lib/esm/builtin/async/ai-runtime/runtime-components/OutputFieldView/type.js +1 -0
  56. package/lib/esm/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +5 -5
  57. package/lib/esm/builtin/async/ai-runtime/runtime-components/ReferencedLinksView/index.js +20 -0
  58. package/lib/esm/builtin/async/ai-runtime/runtime-components/ShareView/index.js +10 -0
  59. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/BackgroundImage.js +22 -0
  60. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/InputsView.js +44 -0
  61. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/MessageView.js +30 -0
  62. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/MessagesView.js +27 -0
  63. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningMessageView.js +18 -0
  64. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningQuestionsView.js +14 -0
  65. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/UserMessageView.js +20 -0
  66. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +25 -108
  67. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleOutput/index.js +36 -10
  68. package/lib/esm/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +5 -5
  69. package/lib/esm/builtin/async/ai-runtime/runtime-components/SuggestedQuestionsView/index.js +48 -0
  70. package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Page.js +5 -5
  71. package/lib/esm/builtin/async/ai-runtime/state/runtime.js +1 -6
  72. package/lib/esm/builtin/mui/material.js +1 -1
  73. package/lib/esm/tsconfig.tsbuildinfo +1 -1
  74. package/lib/esm/utils/inject-global-components.js +2 -0
  75. package/lib/types/builtin/async/ai-runtime/components/OutputFieldContainer/index.d.ts +5 -0
  76. package/lib/types/builtin/async/ai-runtime/constants.d.ts +14 -0
  77. package/lib/types/builtin/async/ai-runtime/contexts/ActiveAgent.d.ts +9 -0
  78. package/lib/types/builtin/async/ai-runtime/contexts/ComponentPreferences.d.ts +5 -0
  79. package/lib/types/builtin/async/ai-runtime/contexts/CurrentMessage.d.ts +6 -1
  80. package/lib/types/builtin/async/ai-runtime/hooks/use-appearances.d.ts +4 -1
  81. package/lib/types/builtin/async/ai-runtime/hooks/use-header-menu.d.ts +1 -0
  82. package/lib/types/builtin/async/ai-runtime/index.d.ts +8 -1
  83. package/lib/types/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchRelatedQuestionsView.d.ts +4 -0
  84. package/lib/types/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchSourcesView.d.ts +2 -0
  85. package/lib/types/builtin/async/ai-runtime/runtime-components/ImagesView/index.d.ts +2 -0
  86. package/lib/types/builtin/async/ai-runtime/runtime-components/MarkdownView/index.d.ts +5 -0
  87. package/lib/types/builtin/async/ai-runtime/runtime-components/OpeningQuestionsView/index.d.ts +2 -0
  88. package/lib/types/builtin/async/ai-runtime/runtime-components/OutputFieldView/type.d.ts +5 -0
  89. package/lib/types/builtin/async/ai-runtime/runtime-components/ReferencedLinksView/index.d.ts +2 -0
  90. package/lib/types/builtin/async/ai-runtime/runtime-components/ShareView/index.d.ts +2 -0
  91. package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/BackgroundImage.d.ts +1 -0
  92. package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/InputsView.d.ts +2 -0
  93. package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/MessageView.d.ts +6 -0
  94. package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/MessagesView.d.ts +2 -0
  95. package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningMessageView.d.ts +3 -0
  96. package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningQuestionsView.d.ts +1 -0
  97. package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/UserMessageView.d.ts +1 -0
  98. package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/index.d.ts +13 -3
  99. package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleOutput/index.d.ts +1 -1
  100. package/lib/types/builtin/async/ai-runtime/runtime-components/SuggestedQuestionsView/index.d.ts +4 -0
  101. package/lib/types/builtin/async/ai-runtime/state/runtime.d.ts +0 -1
  102. package/lib/types/builtin/mui/material.d.ts +1 -1
  103. package/lib/types/tsconfig.tsbuildinfo +1 -1
  104. package/package.json +9 -8
  105. package/lib/cjs/builtin/async/ai-runtime/runtime-components/MultiAgentsChat/index.js +0 -193
  106. package/lib/esm/builtin/async/ai-runtime/runtime-components/MultiAgentsChat/index.js +0 -164
  107. package/lib/types/builtin/async/ai-runtime/runtime-components/MultiAgentsChat/index.d.ts +0 -11
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/pages-kit",
3
- "version": "0.2.316",
3
+ "version": "0.2.317",
4
4
  "description": "Pages Kit components and utils",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -85,29 +85,30 @@
85
85
  "url": "git+https://github.com/blocklet/pages-kit.git"
86
86
  },
87
87
  "dependencies": {
88
- "@arcblock/did-connect": "^2.9.80",
88
+ "@arcblock/did-connect": "^2.9.84",
89
89
  "@blocklet/ai-kit": "^0.1.33",
90
- "@blocklet/ai-runtime": "^0.1.397",
90
+ "@blocklet/ai-runtime": "^0.2.7",
91
91
  "@blocklet/js-sdk": "1.16.26",
92
92
  "@blocklet/sdk": "^1.16.26",
93
93
  "@iconify/react": "^4.1.1",
94
94
  "@lottiefiles/lottie-player": "^1.7.1",
95
95
  "@types/file-saver": "^2.0.7",
96
- "axios": "^1.7.1",
96
+ "axios": "^1.7.2",
97
97
  "dayjs": "^1.11.11",
98
98
  "eventsource-parser": "^1.1.2",
99
99
  "file-saver": "^2.0.5",
100
100
  "html2pdf.js": "^0.10.1",
101
101
  "immer": "^10.1.1",
102
+ "joi": "^17.13.1",
102
103
  "js-base64": "^3.7.7",
103
104
  "lodash": "^4.17.21",
104
- "material-ui-popup-state": "^5.1.1",
105
+ "material-ui-popup-state": "^5.1.2",
105
106
  "nanoid": "^3.3.7",
106
107
  "node-fetch": "^2.7.0",
107
108
  "react-error-boundary": "^4.0.13",
108
109
  "react-frame-component": "^5.2.6",
109
110
  "react-helmet": "^6.1.0",
110
- "react-hook-form": "^7.51.4",
111
+ "react-hook-form": "^7.51.5",
111
112
  "react-markdown": "^9.0.1",
112
113
  "react-scroll-to-bottom": "^4.2.0",
113
114
  "react-share": "^5.1.0",
@@ -132,7 +133,7 @@
132
133
  "react-router-dom": "^6.16.0"
133
134
  },
134
135
  "devDependencies": {
135
- "@arcblock/ux": "^2.9.80",
136
+ "@arcblock/ux": "^2.9.84",
136
137
  "@emotion/cache": "^11.11.0",
137
138
  "@emotion/css": "^11.11.2",
138
139
  "@emotion/react": "^11.11.4",
@@ -146,7 +147,7 @@
146
147
  "@types/react-helmet": "^6.1.11",
147
148
  "@types/react-scroll-to-bottom": "^4.2.5",
148
149
  "@types/react-syntax-highlighter": "^15.5.13",
149
- "axios": "^1.7.1",
150
+ "axios": "^1.7.2",
150
151
  "npm-run-all": "^4.1.5",
151
152
  "react": "^18.3.1",
152
153
  "react-dom": "^18.3.1",
@@ -1,193 +0,0 @@
1
- "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
- Object.defineProperty(o, "default", { enumerable: true, value: v });
15
- }) : function(o, v) {
16
- o["default"] = v;
17
- });
18
- var __importStar = (this && this.__importStar) || function (mod) {
19
- if (mod && mod.__esModule) return mod;
20
- var result = {};
21
- if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
- __setModuleDefault(result, mod);
23
- return result;
24
- };
25
- var __rest = (this && this.__rest) || function (s, e) {
26
- var t = {};
27
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
28
- t[p] = s[p];
29
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
30
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
31
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
32
- t[p[i]] = s[p[i]];
33
- }
34
- return t;
35
- };
36
- var __importDefault = (this && this.__importDefault) || function (mod) {
37
- return (mod && mod.__esModule) ? mod : { "default": mod };
38
- };
39
- Object.defineProperty(exports, "__esModule", { value: true });
40
- const jsx_runtime_1 = require("react/jsx-runtime");
41
- const types_1 = require("@blocklet/ai-runtime/types");
42
- const material_1 = require("@mui/material");
43
- const react_1 = require("react");
44
- const react_scroll_to_bottom_1 = require("react-scroll-to-bottom");
45
- const CustomComponentRenderer_1 = __importDefault(require("../../../../../components/CustomComponentRenderer"));
46
- const session_1 = require("../../../../session");
47
- const SimpleHeader_1 = __importDefault(require("../../components/Header/SimpleHeader"));
48
- const SimpleLayout_1 = __importDefault(require("../../components/Layout/SimpleLayout"));
49
- const MarkdownRenderer_1 = __importDefault(require("../../components/MarkdownRenderer"));
50
- const ScrollView_1 = __importDefault(require("../../components/ScrollView"));
51
- const UserInfo_1 = __importDefault(require("../../components/UserInfo"));
52
- const CurrentAgent_1 = __importStar(require("../../contexts/CurrentAgent"));
53
- const CurrentMessage_1 = __importDefault(require("../../contexts/CurrentMessage"));
54
- const use_appearances_1 = __importStar(require("../../hooks/use-appearances"));
55
- const runtime_1 = require("../../state/runtime");
56
- const session_2 = require("../../state/session");
57
- const runtime_output_schema_1 = require("../../utils/runtime-output-schema");
58
- const MessageSuggestedQuestions_1 = __importStar(require("../ChatOutput/MessageSuggestedQuestions"));
59
- function MultiAgentsChat({ primaryColor, scrollViewProps = { scroll: 'window', initialScrollBehavior: 'auto' }, backgroundImage, }) {
60
- (0, session_2.useAutoLoadSessionState)();
61
- const inheritedTheme = (0, material_1.useTheme)();
62
- const theme = (0, react_1.useMemo)(() => {
63
- let { primary } = inheritedTheme.palette;
64
- try {
65
- if (primaryColor) {
66
- primary = inheritedTheme.palette.augmentColor({ color: { main: primaryColor } });
67
- }
68
- }
69
- catch (error) {
70
- console.error('augment primary color error', { error });
71
- }
72
- return (0, material_1.createTheme)(inheritedTheme, {
73
- palette: { primary },
74
- shape: {
75
- borderRadius: 8,
76
- },
77
- });
78
- }, [inheritedTheme, primaryColor]);
79
- return ((0, jsx_runtime_1.jsx)(ScrollView_1.default, Object.assign({}, scrollViewProps, { children: (0, jsx_runtime_1.jsxs)(material_1.ThemeProvider, { theme: theme, children: [(0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
80
- position: 'fixed',
81
- left: 0,
82
- top: 0,
83
- right: 0,
84
- bottom: 0,
85
- backgroundImage: `url(${backgroundImage === null || backgroundImage === void 0 ? void 0 : backgroundImage.url}) !important`,
86
- backgroundRepeat: 'no-repeat',
87
- backgroundSize: 'cover',
88
- backgroundPosition: 'center',
89
- pointerEvents: 'none',
90
- zIndex: -1,
91
- } }), (0, jsx_runtime_1.jsx)(SimpleChatView, {})] }) })));
92
- }
93
- exports.default = MultiAgentsChat;
94
- function SimpleChatView() {
95
- // auto scroll to bottom when new message is sent
96
- const running = (0, session_2.useCurrentSessionState)((s) => s === null || s === void 0 ? void 0 : s.running);
97
- const scrollToBottom = (0, react_scroll_to_bottom_1.useScrollToBottom)();
98
- (0, react_1.useEffect)(() => {
99
- if (running)
100
- scrollToBottom({ behavior: 'smooth' });
101
- }, [scrollToBottom, running]);
102
- const { childAgentId } = (0, runtime_1.useRuntimeState)();
103
- const [currentAgentId, setCurrentAgentId] = (0, react_1.useState)(childAgentId);
104
- return ((0, jsx_runtime_1.jsxs)(SimpleLayout_1.default, { children: [(0, jsx_runtime_1.jsx)(SimpleHeader_1.default, { px: 2 }), (0, jsx_runtime_1.jsx)(OutputView, { className: "aigne-outputs aigne-simple-chat-outputs", flexGrow: 1, pb: 10, px: 2, currentAgentId: currentAgentId }), (0, jsx_runtime_1.jsx)(AgentInputRender, { className: "aigne-inputs aigne-simple-chat-inputs", currentAgentId: currentAgentId, onCurrentAgentIdChange: setCurrentAgentId, sx: {
105
- position: 'sticky',
106
- bottom: 0,
107
- p: 2,
108
- borderRadius: 1,
109
- bgcolor: (theme) => (0, material_1.alpha)(theme.palette.background.paper, 0.7),
110
- backdropFilter: 'blur(10px)',
111
- zIndex: 10,
112
- } })] }));
113
- }
114
- function AgentInputRender(_a) {
115
- var { currentAgentId, onCurrentAgentIdChange } = _a, props = __rest(_a, ["currentAgentId", "onCurrentAgentIdChange"]);
116
- const { agent } = (0, runtime_1.useRuntimeState)();
117
- const children = (0, react_1.useMemo)(() => { var _a, _b; return (_b = (_a = (0, runtime_output_schema_1.getOutputVariableInitialValue)(agent, types_1.RuntimeOutputVariable.children)) === null || _a === void 0 ? void 0 : _a.agents) === null || _b === void 0 ? void 0 : _b.filter((i) => !!i.id); }, [agent]);
118
- return ((0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ gap: 2 }, props, { children: [(0, jsx_runtime_1.jsx)(material_1.Stack, { direction: "row", gap: 2, children: children === null || children === void 0 ? void 0 : children.map((child) => ((0, jsx_runtime_1.jsx)(CurrentAgent_1.default, { agentId: child.id, children: (0, jsx_runtime_1.jsx)(AgentAvatar, { selected: currentAgentId === child.id, onClick: () => onCurrentAgentIdChange(child.id) }) }))) }), (0, jsx_runtime_1.jsx)(material_1.Stack, { children: (0, jsx_runtime_1.jsx)(CurrentAgent_1.default, { agentId: currentAgentId, children: (0, jsx_runtime_1.jsx)(AgentInput, {}) }) })] })));
119
- }
120
- function AgentAvatar(_a) {
121
- var _b;
122
- var { selected } = _a, props = __rest(_a, ["selected"]);
123
- const { appearanceInput } = (0, use_appearances_1.default)();
124
- const profile = (0, use_appearances_1.useProfile)();
125
- if (!(appearanceInput === null || appearanceInput === void 0 ? void 0 : appearanceInput.componentId))
126
- return null;
127
- return ((0, jsx_runtime_1.jsx)(material_1.IconButton, Object.assign({}, props, { sx: Object.assign({ p: 0, outline: selected ? 3 : 0, outlineColor: 'primary.light' }, props.sx), children: (0, jsx_runtime_1.jsx)(material_1.Avatar, { src: profile === null || profile === void 0 ? void 0 : profile.avatar, children: (_b = profile.name) === null || _b === void 0 ? void 0 : _b.slice(0, 1) }) })));
128
- }
129
- function AgentInput() {
130
- const { aid } = (0, CurrentAgent_1.useCurrentAgent)();
131
- const { appearanceInput } = (0, use_appearances_1.default)({ aid });
132
- if (!(appearanceInput === null || appearanceInput === void 0 ? void 0 : appearanceInput.componentId))
133
- return null;
134
- return ((0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: appearanceInput.componentId, properties: appearanceInput.componentProps }));
135
- }
136
- function OutputView(_a) {
137
- var { currentAgentId } = _a, props = __rest(_a, ["currentAgentId"]);
138
- const messages = (0, session_2.useCurrentSessionState)((s) => s === null || s === void 0 ? void 0 : s.messages);
139
- const loaded = (0, session_2.useSessionState)((s) => s.loaded);
140
- const showOpening = (0, session_2.useCurrentSessionState)((s) => !s || (s === null || s === void 0 ? void 0 : s.loaded)) && loaded;
141
- const lastMessage = messages === null || messages === void 0 ? void 0 : messages.at(-1);
142
- return ((0, jsx_runtime_1.jsxs)(material_1.Stack, Object.assign({ gap: 2 }, props, { children: [showOpening && ((0, jsx_runtime_1.jsx)(CurrentAgent_1.default, { agentId: currentAgentId, children: (0, jsx_runtime_1.jsx)(OpeningMessageView, {}) })), messages === null || messages === void 0 ? void 0 : messages.map((message) => (0, jsx_runtime_1.jsx)(OutputItemView, { message: message }, message.taskId)), lastMessage && lastMessage.assistantId === currentAgentId && (0, jsx_runtime_1.jsx)(SuggestedQuestionsView, { message: lastMessage }), showOpening && !(messages === null || messages === void 0 ? void 0 : messages.length) && ((0, jsx_runtime_1.jsx)(CurrentAgent_1.default, { agentId: currentAgentId, children: (0, jsx_runtime_1.jsx)(OpeningQuestionsView, {}) }))] })));
143
- }
144
- const OutputItemView = (0, react_1.memo)(({ message }) => {
145
- var _a, _b, _c, _d;
146
- const { aid } = (0, CurrentAgent_1.useCurrentAgent)({ agentId: message.assistantId });
147
- const { appearanceOutput } = (0, use_appearances_1.default)({ aid });
148
- const profile = (0, use_appearances_1.useProfile)({ aid });
149
- const { session: authSession } = (0, session_1.useSessionContext)();
150
- if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
151
- return null;
152
- return ((0, jsx_runtime_1.jsx)(CurrentAgent_1.default, { agentId: message.assistantId, children: (0, jsx_runtime_1.jsx)(CurrentMessage_1.default, { message: message, children: (0, jsx_runtime_1.jsxs)(material_1.Stack, { gap: 2, children: [(0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(UserInfo_1.default, { name: (_a = authSession.user) === null || _a === void 0 ? void 0 : _a.fullName, did: (_b = authSession.user) === null || _b === void 0 ? void 0 : _b.did, avatar: (_c = authSession.user) === null || _c === void 0 ? void 0 : _c.avatar, time: message.createdAt, reverse: true, alignItems: "flex-start", children: (0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProps, props: {
153
- renderType: 'parameters',
154
- } }) }) }), (0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(UserInfo_1.default, { name: profile.name, did: (_d = globalThis.blocklet) === null || _d === void 0 ? void 0 : _d.appId, avatar: profile.avatar, time: message.createdAt, alignItems: "flex-start", children: (0, jsx_runtime_1.jsx)(CustomComponentRenderer_1.default, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProps, props: {
155
- renderType: 'result',
156
- } }) }) })] }) }) }));
157
- });
158
- function SuggestedQuestionsView({ message }) {
159
- const { aid } = (0, CurrentAgent_1.useCurrentAgent)({ agentId: message.assistantId });
160
- const { execute } = (0, runtime_1.useRuntimeState)();
161
- const suggestedQuestions = (0, react_1.useMemo)(() => {
162
- var _a, _b, _c;
163
- return (_c = (_b = (_a = message === null || message === void 0 ? void 0 : message.result) === null || _a === void 0 ? void 0 : _a.objects) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.data[types_1.RuntimeOutputVariable.suggestedQuestions];
164
- }, [message]);
165
- return ((0, jsx_runtime_1.jsx)(material_1.Box, { ml: 6.5, mr: 2.5, children: (suggestedQuestions === null || suggestedQuestions === void 0 ? void 0 : suggestedQuestions.length) ? ((0, jsx_runtime_1.jsx)(MessageSuggestedQuestions_1.default, { dataSource: suggestedQuestions, onClick: (item) => {
166
- execute({ aid, parameters: Object.assign(Object.assign({}, message.parameters), { question: item.question }) });
167
- } })) : null }));
168
- }
169
- const OpeningMessageView = (0, react_1.memo)(() => {
170
- var _a;
171
- const opening = (0, use_appearances_1.useOpeningMessage)();
172
- if (!opening)
173
- return null;
174
- return ((0, jsx_runtime_1.jsx)(material_1.Box, { children: (0, jsx_runtime_1.jsx)(UserInfo_1.default, { name: opening.profile.name, did: (_a = globalThis.blocklet) === null || _a === void 0 ? void 0 : _a.appId, avatar: opening.profile.avatar, alignItems: "flex-start", children: (0, jsx_runtime_1.jsx)(material_1.Box, { sx: {
175
- bgcolor: 'rgba(229, 231, 235, 1)',
176
- borderRadius: 1,
177
- borderTopLeftRadius: 2,
178
- px: 2,
179
- py: 1,
180
- mt: 0.5,
181
- mr: 5,
182
- }, children: (0, jsx_runtime_1.jsx)(MarkdownRenderer_1.default, { children: opening.message }) }) }) }));
183
- });
184
- function OpeningQuestionsView() {
185
- const { execute } = (0, runtime_1.useRuntimeState)();
186
- const { aid } = (0, CurrentAgent_1.useCurrentAgent)();
187
- const opening = (0, use_appearances_1.useOpeningQuestions)({ aid });
188
- if (!(opening === null || opening === void 0 ? void 0 : opening.questions.length))
189
- return null;
190
- return ((0, jsx_runtime_1.jsx)(material_1.Box, { ml: 6.5, mr: 2.5, children: (0, jsx_runtime_1.jsx)(material_1.Stack, { gap: 1, children: opening.questions.map((item) => {
191
- return ((0, jsx_runtime_1.jsx)(MessageSuggestedQuestions_1.MessageSuggestedQuestion, { onClick: () => execute({ aid, parameters: Object.assign(Object.assign({}, item.parameters), { question: item.parameters.question || item.title }) }), children: item.title }, item.id));
192
- }) }) }));
193
- }
@@ -1,164 +0,0 @@
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, jsxs as _jsxs } from "react/jsx-runtime";
13
- import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
14
- import { Avatar, Box, IconButton, Stack, ThemeProvider, alpha, createTheme, useTheme, } from '@mui/material';
15
- import { memo, useEffect, useMemo, useState } from 'react';
16
- import { useScrollToBottom } from 'react-scroll-to-bottom';
17
- import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
18
- import { useSessionContext } from '../../../../session';
19
- import SimpleHeader from '../../components/Header/SimpleHeader';
20
- import SimpleLayout from '../../components/Layout/SimpleLayout';
21
- import MarkdownRenderer from '../../components/MarkdownRenderer';
22
- import ScrollView from '../../components/ScrollView';
23
- import UserInfo from '../../components/UserInfo';
24
- import CurrentAgentProvider, { useCurrentAgent } from '../../contexts/CurrentAgent';
25
- import CurrentMessageProvider from '../../contexts/CurrentMessage';
26
- import useAppearances, { useOpeningMessage, useOpeningQuestions, useProfile } from '../../hooks/use-appearances';
27
- import { useRuntimeState } from '../../state/runtime';
28
- import { useAutoLoadSessionState, useCurrentSessionState, useSessionState } from '../../state/session';
29
- import { getOutputVariableInitialValue } from '../../utils/runtime-output-schema';
30
- import MessageSuggestedQuestions, { MessageSuggestedQuestion } from '../ChatOutput/MessageSuggestedQuestions';
31
- export default function MultiAgentsChat({ primaryColor, scrollViewProps = { scroll: 'window', initialScrollBehavior: 'auto' }, backgroundImage, }) {
32
- useAutoLoadSessionState();
33
- const inheritedTheme = useTheme();
34
- const theme = useMemo(() => {
35
- let { primary } = inheritedTheme.palette;
36
- try {
37
- if (primaryColor) {
38
- primary = inheritedTheme.palette.augmentColor({ color: { main: primaryColor } });
39
- }
40
- }
41
- catch (error) {
42
- console.error('augment primary color error', { error });
43
- }
44
- return createTheme(inheritedTheme, {
45
- palette: { primary },
46
- shape: {
47
- borderRadius: 8,
48
- },
49
- });
50
- }, [inheritedTheme, primaryColor]);
51
- return (_jsx(ScrollView, Object.assign({}, scrollViewProps, { children: _jsxs(ThemeProvider, { theme: theme, children: [_jsx(Box, { sx: {
52
- position: 'fixed',
53
- left: 0,
54
- top: 0,
55
- right: 0,
56
- bottom: 0,
57
- backgroundImage: `url(${backgroundImage === null || backgroundImage === void 0 ? void 0 : backgroundImage.url}) !important`,
58
- backgroundRepeat: 'no-repeat',
59
- backgroundSize: 'cover',
60
- backgroundPosition: 'center',
61
- pointerEvents: 'none',
62
- zIndex: -1,
63
- } }), _jsx(SimpleChatView, {})] }) })));
64
- }
65
- function SimpleChatView() {
66
- // auto scroll to bottom when new message is sent
67
- const running = useCurrentSessionState((s) => s === null || s === void 0 ? void 0 : s.running);
68
- const scrollToBottom = useScrollToBottom();
69
- useEffect(() => {
70
- if (running)
71
- scrollToBottom({ behavior: 'smooth' });
72
- }, [scrollToBottom, running]);
73
- const { childAgentId } = useRuntimeState();
74
- const [currentAgentId, setCurrentAgentId] = useState(childAgentId);
75
- return (_jsxs(SimpleLayout, { children: [_jsx(SimpleHeader, { px: 2 }), _jsx(OutputView, { className: "aigne-outputs aigne-simple-chat-outputs", flexGrow: 1, pb: 10, px: 2, currentAgentId: currentAgentId }), _jsx(AgentInputRender, { className: "aigne-inputs aigne-simple-chat-inputs", currentAgentId: currentAgentId, onCurrentAgentIdChange: setCurrentAgentId, sx: {
76
- position: 'sticky',
77
- bottom: 0,
78
- p: 2,
79
- borderRadius: 1,
80
- bgcolor: (theme) => alpha(theme.palette.background.paper, 0.7),
81
- backdropFilter: 'blur(10px)',
82
- zIndex: 10,
83
- } })] }));
84
- }
85
- function AgentInputRender(_a) {
86
- var { currentAgentId, onCurrentAgentIdChange } = _a, props = __rest(_a, ["currentAgentId", "onCurrentAgentIdChange"]);
87
- const { agent } = useRuntimeState();
88
- const children = useMemo(() => { var _a, _b; return (_b = (_a = getOutputVariableInitialValue(agent, RuntimeOutputVariable.children)) === null || _a === void 0 ? void 0 : _a.agents) === null || _b === void 0 ? void 0 : _b.filter((i) => !!i.id); }, [agent]);
89
- return (_jsxs(Stack, Object.assign({ gap: 2 }, props, { children: [_jsx(Stack, { direction: "row", gap: 2, children: children === null || children === void 0 ? void 0 : children.map((child) => (_jsx(CurrentAgentProvider, { agentId: child.id, children: _jsx(AgentAvatar, { selected: currentAgentId === child.id, onClick: () => onCurrentAgentIdChange(child.id) }) }))) }), _jsx(Stack, { children: _jsx(CurrentAgentProvider, { agentId: currentAgentId, children: _jsx(AgentInput, {}) }) })] })));
90
- }
91
- function AgentAvatar(_a) {
92
- var _b;
93
- var { selected } = _a, props = __rest(_a, ["selected"]);
94
- const { appearanceInput } = useAppearances();
95
- const profile = useProfile();
96
- if (!(appearanceInput === null || appearanceInput === void 0 ? void 0 : appearanceInput.componentId))
97
- return null;
98
- return (_jsx(IconButton, Object.assign({}, props, { sx: Object.assign({ p: 0, outline: selected ? 3 : 0, outlineColor: 'primary.light' }, props.sx), children: _jsx(Avatar, { src: profile === null || profile === void 0 ? void 0 : profile.avatar, children: (_b = profile.name) === null || _b === void 0 ? void 0 : _b.slice(0, 1) }) })));
99
- }
100
- function AgentInput() {
101
- const { aid } = useCurrentAgent();
102
- const { appearanceInput } = useAppearances({ aid });
103
- if (!(appearanceInput === null || appearanceInput === void 0 ? void 0 : appearanceInput.componentId))
104
- return null;
105
- return (_jsx(CustomComponentRenderer, { componentId: appearanceInput.componentId, properties: appearanceInput.componentProps }));
106
- }
107
- function OutputView(_a) {
108
- var { currentAgentId } = _a, props = __rest(_a, ["currentAgentId"]);
109
- const messages = useCurrentSessionState((s) => s === null || s === void 0 ? void 0 : s.messages);
110
- const loaded = useSessionState((s) => s.loaded);
111
- const showOpening = useCurrentSessionState((s) => !s || (s === null || s === void 0 ? void 0 : s.loaded)) && loaded;
112
- const lastMessage = messages === null || messages === void 0 ? void 0 : messages.at(-1);
113
- return (_jsxs(Stack, Object.assign({ gap: 2 }, props, { children: [showOpening && (_jsx(CurrentAgentProvider, { agentId: currentAgentId, children: _jsx(OpeningMessageView, {}) })), messages === null || messages === void 0 ? void 0 : messages.map((message) => _jsx(OutputItemView, { message: message }, message.taskId)), lastMessage && lastMessage.assistantId === currentAgentId && _jsx(SuggestedQuestionsView, { message: lastMessage }), showOpening && !(messages === null || messages === void 0 ? void 0 : messages.length) && (_jsx(CurrentAgentProvider, { agentId: currentAgentId, children: _jsx(OpeningQuestionsView, {}) }))] })));
114
- }
115
- const OutputItemView = memo(({ message }) => {
116
- var _a, _b, _c, _d;
117
- const { aid } = useCurrentAgent({ agentId: message.assistantId });
118
- const { appearanceOutput } = useAppearances({ aid });
119
- const profile = useProfile({ aid });
120
- const { session: authSession } = useSessionContext();
121
- if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
122
- return null;
123
- return (_jsx(CurrentAgentProvider, { agentId: message.assistantId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsxs(Stack, { gap: 2, children: [_jsx(Box, { children: _jsx(UserInfo, { name: (_a = authSession.user) === null || _a === void 0 ? void 0 : _a.fullName, did: (_b = authSession.user) === null || _b === void 0 ? void 0 : _b.did, avatar: (_c = authSession.user) === null || _c === void 0 ? void 0 : _c.avatar, time: message.createdAt, reverse: true, alignItems: "flex-start", children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProps, props: {
124
- renderType: 'parameters',
125
- } }) }) }), _jsx(Box, { children: _jsx(UserInfo, { name: profile.name, did: (_d = globalThis.blocklet) === null || _d === void 0 ? void 0 : _d.appId, avatar: profile.avatar, time: message.createdAt, alignItems: "flex-start", children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProps, props: {
126
- renderType: 'result',
127
- } }) }) })] }) }) }));
128
- });
129
- function SuggestedQuestionsView({ message }) {
130
- const { aid } = useCurrentAgent({ agentId: message.assistantId });
131
- const { execute } = useRuntimeState();
132
- const suggestedQuestions = useMemo(() => {
133
- var _a, _b, _c;
134
- return (_c = (_b = (_a = message === null || message === void 0 ? void 0 : message.result) === null || _a === void 0 ? void 0 : _a.objects) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.data[RuntimeOutputVariable.suggestedQuestions];
135
- }, [message]);
136
- return (_jsx(Box, { ml: 6.5, mr: 2.5, children: (suggestedQuestions === null || suggestedQuestions === void 0 ? void 0 : suggestedQuestions.length) ? (_jsx(MessageSuggestedQuestions, { dataSource: suggestedQuestions, onClick: (item) => {
137
- execute({ aid, parameters: Object.assign(Object.assign({}, message.parameters), { question: item.question }) });
138
- } })) : null }));
139
- }
140
- const OpeningMessageView = memo(() => {
141
- var _a;
142
- const opening = useOpeningMessage();
143
- if (!opening)
144
- return null;
145
- return (_jsx(Box, { children: _jsx(UserInfo, { name: opening.profile.name, did: (_a = globalThis.blocklet) === null || _a === void 0 ? void 0 : _a.appId, avatar: opening.profile.avatar, alignItems: "flex-start", children: _jsx(Box, { sx: {
146
- bgcolor: 'rgba(229, 231, 235, 1)',
147
- borderRadius: 1,
148
- borderTopLeftRadius: 2,
149
- px: 2,
150
- py: 1,
151
- mt: 0.5,
152
- mr: 5,
153
- }, children: _jsx(MarkdownRenderer, { children: opening.message }) }) }) }));
154
- });
155
- function OpeningQuestionsView() {
156
- const { execute } = useRuntimeState();
157
- const { aid } = useCurrentAgent();
158
- const opening = useOpeningQuestions({ aid });
159
- if (!(opening === null || opening === void 0 ? void 0 : opening.questions.length))
160
- return null;
161
- return (_jsx(Box, { ml: 6.5, mr: 2.5, children: _jsx(Stack, { gap: 1, children: opening.questions.map((item) => {
162
- return (_jsx(MessageSuggestedQuestion, { onClick: () => execute({ aid, parameters: Object.assign(Object.assign({}, item.parameters), { question: item.parameters.question || item.title }) }), children: item.title }, item.id));
163
- }) }) }));
164
- }
@@ -1,11 +0,0 @@
1
- import { ComponentProps } from 'react';
2
- import ScrollView from '../../components/ScrollView';
3
- export default function MultiAgentsChat({ primaryColor, scrollViewProps, backgroundImage, }: {
4
- primaryColor?: string;
5
- scrollViewProps?: ComponentProps<typeof ScrollView>;
6
- backgroundImage?: {
7
- url?: string;
8
- width?: number;
9
- height?: number;
10
- };
11
- }): import("react/jsx-runtime").JSX.Element;