@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.
- package/lib/cjs/builtin/async/ai-runtime/components/MarkdownRenderer.js +26 -2
- package/lib/cjs/builtin/async/ai-runtime/components/OutputFieldContainer/index.js +22 -0
- package/lib/cjs/builtin/async/ai-runtime/components/ShareActions/index.js +1 -1
- package/lib/cjs/builtin/async/ai-runtime/constants.js +34 -4
- package/lib/cjs/builtin/async/ai-runtime/contexts/ActiveAgent.js +28 -0
- package/lib/cjs/builtin/async/ai-runtime/contexts/ComponentPreferences.js +27 -0
- package/lib/cjs/builtin/async/ai-runtime/contexts/CurrentMessage.js +2 -2
- package/lib/cjs/builtin/async/ai-runtime/hooks/use-appearances.js +10 -5
- package/lib/cjs/builtin/async/ai-runtime/hooks/use-header-menu.js +39 -0
- package/lib/cjs/builtin/async/ai-runtime/index.js +17 -3
- package/lib/cjs/builtin/async/ai-runtime/runtime/ChatBotButton/index.js +3 -2
- package/lib/cjs/builtin/async/ai-runtime/runtime/Runtime/index.js +4 -6
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchRelatedQuestionsView.js +60 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchSourcesView.js +50 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/ImagesView/index.js +30 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/MarkdownView/index.js +13 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/OpeningQuestionsView/index.js +46 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/OutputFieldView/type.js +2 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +5 -5
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/ReferencedLinksView/index.js +26 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/ShareView/index.js +16 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/BackgroundImage.js +25 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/InputsView.js +73 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/MessageView.js +58 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/MessagesView.js +33 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningMessageView.js +23 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningQuestionsView.js +20 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/UserMessageView.js +26 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +28 -134
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleOutput/index.js +35 -9
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +5 -5
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SuggestedQuestionsView/index.js +54 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Page.js +5 -5
- package/lib/cjs/builtin/async/ai-runtime/state/runtime.js +1 -6
- package/lib/cjs/builtin/mui/material.js +4 -2
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/inject-global-components.js +2 -0
- package/lib/esm/builtin/async/ai-runtime/components/MarkdownRenderer.js +3 -2
- package/lib/esm/builtin/async/ai-runtime/components/OutputFieldContainer/index.js +19 -0
- package/lib/esm/builtin/async/ai-runtime/components/ShareActions/index.js +2 -2
- package/lib/esm/builtin/async/ai-runtime/constants.js +32 -3
- package/lib/esm/builtin/async/ai-runtime/contexts/ActiveAgent.js +23 -0
- package/lib/esm/builtin/async/ai-runtime/contexts/ComponentPreferences.js +22 -0
- package/lib/esm/builtin/async/ai-runtime/contexts/CurrentMessage.js +2 -2
- package/lib/esm/builtin/async/ai-runtime/hooks/use-appearances.js +10 -5
- package/lib/esm/builtin/async/ai-runtime/hooks/use-header-menu.js +32 -0
- package/lib/esm/builtin/async/ai-runtime/index.js +8 -1
- package/lib/esm/builtin/async/ai-runtime/runtime/ChatBotButton/index.js +3 -2
- package/lib/esm/builtin/async/ai-runtime/runtime/Runtime/index.js +4 -6
- package/lib/esm/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchRelatedQuestionsView.js +54 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchSourcesView.js +44 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/ImagesView/index.js +24 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/MarkdownView/index.js +7 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/OpeningQuestionsView/index.js +40 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/OutputFieldView/type.js +1 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +5 -5
- package/lib/esm/builtin/async/ai-runtime/runtime-components/ReferencedLinksView/index.js +20 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/ShareView/index.js +10 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/BackgroundImage.js +22 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/InputsView.js +44 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/MessageView.js +30 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/MessagesView.js +27 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningMessageView.js +18 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningQuestionsView.js +14 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/UserMessageView.js +20 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +25 -108
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleOutput/index.js +36 -10
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +5 -5
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SuggestedQuestionsView/index.js +48 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Page.js +5 -5
- package/lib/esm/builtin/async/ai-runtime/state/runtime.js +1 -6
- package/lib/esm/builtin/mui/material.js +1 -1
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/inject-global-components.js +2 -0
- package/lib/types/builtin/async/ai-runtime/components/OutputFieldContainer/index.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/constants.d.ts +14 -0
- package/lib/types/builtin/async/ai-runtime/contexts/ActiveAgent.d.ts +9 -0
- package/lib/types/builtin/async/ai-runtime/contexts/ComponentPreferences.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/contexts/CurrentMessage.d.ts +6 -1
- package/lib/types/builtin/async/ai-runtime/hooks/use-appearances.d.ts +4 -1
- package/lib/types/builtin/async/ai-runtime/hooks/use-header-menu.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/index.d.ts +8 -1
- package/lib/types/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchRelatedQuestionsView.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchSourcesView.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/ImagesView/index.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/MarkdownView/index.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/OpeningQuestionsView/index.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/OutputFieldView/type.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/ReferencedLinksView/index.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/ShareView/index.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/BackgroundImage.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/InputsView.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/MessageView.d.ts +6 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/MessagesView.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningMessageView.d.ts +3 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/OpeningQuestionsView.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/UserMessageView.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleChat/index.d.ts +13 -3
- package/lib/types/builtin/async/ai-runtime/runtime-components/SimpleOutput/index.d.ts +1 -1
- package/lib/types/builtin/async/ai-runtime/runtime-components/SuggestedQuestionsView/index.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/state/runtime.d.ts +0 -1
- package/lib/types/builtin/mui/material.d.ts +1 -1
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -8
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/MultiAgentsChat/index.js +0 -193
- package/lib/esm/builtin/async/ai-runtime/runtime-components/MultiAgentsChat/index.js +0 -164
- package/lib/types/builtin/async/ai-runtime/runtime-components/MultiAgentsChat/index.d.ts +0 -11
|
@@ -26,6 +26,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
26
26
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
27
27
|
};
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
|
+
const react_1 = __importDefault(require("react"));
|
|
29
30
|
const arcblockUx = __importStar(require("../builtin/arcblock/ux"));
|
|
30
31
|
const aiRuntime = __importStar(require("../builtin/async/ai-runtime"));
|
|
31
32
|
const imagePreview = __importStar(require("../builtin/async/image-preview"));
|
|
@@ -87,5 +88,6 @@ function injectGlobalComponents() {
|
|
|
87
88
|
return win[builtin_1.BuiltinModulesGlobalVariableName].modules[module];
|
|
88
89
|
},
|
|
89
90
|
};
|
|
91
|
+
win.React = react_1.default;
|
|
90
92
|
}
|
|
91
93
|
injectGlobalComponents();
|
|
@@ -12,7 +12,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
12
12
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
13
|
import { Icon } from '@iconify/react';
|
|
14
14
|
import { Box, Stack, styled } from '@mui/material';
|
|
15
|
-
import React from 'react';
|
|
15
|
+
import React, { Suspense } from 'react';
|
|
16
16
|
import Markdown from 'react-markdown';
|
|
17
17
|
import remarkGfm from 'remark-gfm';
|
|
18
18
|
import { useLocaleContext } from '../../../locale';
|
|
@@ -26,7 +26,7 @@ const MarkdownRenderer = styled((props) => (_jsx(Markdown, Object.assign({}, pro
|
|
|
26
26
|
if (!children)
|
|
27
27
|
return null;
|
|
28
28
|
const match = /language-(\w+)/.exec(className || '');
|
|
29
|
-
return !inline ? (_jsx(Box, Object.assign({ component: ReactSyntaxHighlighter, language: match === null || match === void 0 ? void 0 : match[1] }, props, { sx: { borderRadius: 1 }, children: String(children).replace(/\n$/, '') }))) : (_jsx(Box, Object.assign({ component: "code", className: className }, props, { children: children })));
|
|
29
|
+
return !inline ? (_jsx(Suspense, { children: _jsx(Box, Object.assign({ component: ReactSyntaxHighlighter, language: match === null || match === void 0 ? void 0 : match[1] }, props, { sx: { borderRadius: 1 }, children: String(children).replace(/\n$/, '') })) })) : (_jsx(Box, Object.assign({ component: "code", className: className }, props, { children: children })));
|
|
30
30
|
},
|
|
31
31
|
table: ({ className, children }) => {
|
|
32
32
|
return (_jsx(Box, { sx: { overflow: 'auto', my: 1 }, children: _jsx("table", { className: className, children: children }) }));
|
|
@@ -80,6 +80,7 @@ const MarkdownRenderer = styled((props) => (_jsx(Markdown, Object.assign({}, pro
|
|
|
80
80
|
}
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
&.writing:empty,
|
|
83
84
|
&.writing > *:last-child {
|
|
84
85
|
&:after {
|
|
85
86
|
content: '';
|
|
@@ -0,0 +1,19 @@
|
|
|
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 { Icon } from '@iconify/react';
|
|
14
|
+
import { Box, Stack, Typography } from '@mui/material';
|
|
15
|
+
export default function OutputFieldContainer(_a) {
|
|
16
|
+
var _b;
|
|
17
|
+
var { output } = _a, props = __rest(_a, ["output"]);
|
|
18
|
+
return (_jsxs(Stack, Object.assign({ gap: 1 }, props, { children: [((_b = output.appearance) === null || _b === void 0 ? void 0 : _b.title) && (_jsxs(Typography, { component: "h6", noWrap: true, sx: { display: 'flex', alignItems: 'center', gap: 1, fontSize: 18, fontWeight: 500 }, children: [output.appearance.icon && _jsx(Box, { component: Icon, icon: output.appearance.icon }), _jsx(Box, { component: "span", sx: { flex: 1, textOverflow: 'hidden' }, children: output.appearance.title })] })), props.children] })));
|
|
19
|
+
}
|
|
@@ -21,7 +21,7 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
21
21
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
22
22
|
import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
|
|
23
23
|
import { Icon } from '@iconify/react';
|
|
24
|
-
import { Stack, styled } from '@mui/material';
|
|
24
|
+
import { Box, Stack, styled } from '@mui/material';
|
|
25
25
|
import { saveAs } from 'file-saver';
|
|
26
26
|
import { useMemo } from 'react';
|
|
27
27
|
import { withQuery } from 'ufo';
|
|
@@ -44,7 +44,7 @@ export default function ShareActions(_a) {
|
|
|
44
44
|
const C = ShareActionsMap[item.to];
|
|
45
45
|
if (!C)
|
|
46
46
|
return null;
|
|
47
|
-
return _jsx(C, {});
|
|
47
|
+
return (_jsx(Box, { children: _jsx(C, {}) }));
|
|
48
48
|
}).filter((i) => !!i);
|
|
49
49
|
if (!(items === null || items === void 0 ? void 0 : items.length))
|
|
50
50
|
return null;
|
|
@@ -1,5 +1,34 @@
|
|
|
1
|
+
import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
|
|
1
2
|
export const AI_STUDIO_DID = 'z8iZpog7mcgcgBZzTiXJCWESvmnRrQmnd3XBB';
|
|
2
3
|
export const PAYMENT_KIT_DID = 'z2qaCNvKMv5GjouKdcDWexv6WqtHbpNPQDnAk';
|
|
3
|
-
export const DEFAULT_PAGE_COMPONENT_ID = 'ctnxha29uu8cx4xv';
|
|
4
|
-
export const DEFAULT_INPUT_COMPONENT_ID = '1wwtemqcdio6nqf0';
|
|
5
|
-
export const DEFAULT_OUTPUT_COMPONENT_ID = 'q0ckknkxph4hfwas';
|
|
4
|
+
export const DEFAULT_PAGE_COMPONENT_ID = 'ctnxha29uu8cx4xv'; // Simple Layout
|
|
5
|
+
export const DEFAULT_INPUT_COMPONENT_ID = '1wwtemqcdio6nqf0'; // Auto Form
|
|
6
|
+
export const DEFAULT_OUTPUT_COMPONENT_ID = 'q0ckknkxph4hfwas'; // Simple Output
|
|
7
|
+
export const MARKDOWN_VIEW_ID = 'a4oldpoxv7bikvpj';
|
|
8
|
+
export const SUGGESTED_QUESTIONS_VIEW_ID = '6u8m11ss7fvu8t7i';
|
|
9
|
+
export const REFERENCED_LINKS_VIEW_ID = 'baqmaoccdntqwayc';
|
|
10
|
+
export const SHARE_VIEW_ID = 'jfq3df9z8lkk9not';
|
|
11
|
+
export const IMAGES_VIEW_ID = 'txirtdgx8h2bmo7s';
|
|
12
|
+
export const DEFAULT_OUTPUT_COMPONENTS = {
|
|
13
|
+
[RuntimeOutputVariable.text]: {
|
|
14
|
+
componentId: MARKDOWN_VIEW_ID,
|
|
15
|
+
},
|
|
16
|
+
[RuntimeOutputVariable.images]: {
|
|
17
|
+
componentId: IMAGES_VIEW_ID,
|
|
18
|
+
},
|
|
19
|
+
[RuntimeOutputVariable.openingMessage]: {
|
|
20
|
+
componentId: MARKDOWN_VIEW_ID,
|
|
21
|
+
},
|
|
22
|
+
[RuntimeOutputVariable.suggestedQuestions]: {
|
|
23
|
+
componentId: SUGGESTED_QUESTIONS_VIEW_ID,
|
|
24
|
+
},
|
|
25
|
+
[RuntimeOutputVariable.referenceLinks]: {
|
|
26
|
+
componentId: REFERENCED_LINKS_VIEW_ID,
|
|
27
|
+
},
|
|
28
|
+
[RuntimeOutputVariable.share]: {
|
|
29
|
+
componentId: SHARE_VIEW_ID,
|
|
30
|
+
},
|
|
31
|
+
};
|
|
32
|
+
export function getDefaultOutputComponent(output) {
|
|
33
|
+
return DEFAULT_OUTPUT_COMPONENTS[output.name];
|
|
34
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
|
|
3
|
+
import { createContext, useContext, useMemo, useState } from 'react';
|
|
4
|
+
import { useRuntimeState } from '../state/runtime';
|
|
5
|
+
import { getOutputVariableInitialValue } from '../utils/runtime-output-schema';
|
|
6
|
+
const activeAgentContext = createContext(undefined);
|
|
7
|
+
export function useActiveAgent() {
|
|
8
|
+
const context = useContext(activeAgentContext);
|
|
9
|
+
if (!context) {
|
|
10
|
+
throw new Error('No such activeAgentContext. You should use `useActiveAgent` within the `ActiveAgentProvider`');
|
|
11
|
+
}
|
|
12
|
+
return context;
|
|
13
|
+
}
|
|
14
|
+
export default function ActiveAgentProvider({ children }) {
|
|
15
|
+
const { agent } = useRuntimeState();
|
|
16
|
+
const childAgentId = useMemo(() => {
|
|
17
|
+
var _a, _b, _c, _d;
|
|
18
|
+
return (_d = (_c = (_b = (_a = getOutputVariableInitialValue(agent, RuntimeOutputVariable.children)) === null || _a === void 0 ? void 0 : _a.agents) === null || _b === void 0 ? void 0 : _b[0]) === null || _c === void 0 ? void 0 : _c.id) !== null && _d !== void 0 ? _d : agent.id;
|
|
19
|
+
}, [agent]);
|
|
20
|
+
const [activeAgentId, setActiveAgentId] = useState(childAgentId);
|
|
21
|
+
const activeAgent = useMemo(() => ({ activeAgentId, setActiveAgentId }), [activeAgentId, setActiveAgentId]);
|
|
22
|
+
return _jsx(activeAgentContext.Provider, { value: activeAgent, children: children });
|
|
23
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
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, useMemo } from 'react';
|
|
14
|
+
const componentPreferencesContext = createContext(undefined);
|
|
15
|
+
export function ComponentPreferencesProvider(_a) {
|
|
16
|
+
var { children } = _a, preferences = __rest(_a, ["children"]);
|
|
17
|
+
const value = useMemo(() => (Object.assign({}, preferences)), Object.values(preferences));
|
|
18
|
+
return _jsx(componentPreferencesContext.Provider, { value: value, children: children });
|
|
19
|
+
}
|
|
20
|
+
export function useComponentPreferences() {
|
|
21
|
+
return useContext(componentPreferencesContext);
|
|
22
|
+
}
|
|
@@ -5,9 +5,9 @@ export default function CurrentMessageProvider({ message, children }) {
|
|
|
5
5
|
const state = useMemo(() => ({ message }), [message]);
|
|
6
6
|
return _jsx(context.Provider, { value: state, children: children });
|
|
7
7
|
}
|
|
8
|
-
export function useCurrentMessage() {
|
|
8
|
+
export function useCurrentMessage({ optional } = {}) {
|
|
9
9
|
const current = useContext(context);
|
|
10
|
-
if (!current) {
|
|
10
|
+
if (!optional && !current) {
|
|
11
11
|
throw new Error('No such message state. You should use `useCurrentMessage` within the `CurrentMessageProvider`');
|
|
12
12
|
}
|
|
13
13
|
return current;
|
|
@@ -10,14 +10,16 @@ export default function useAppearances(args) {
|
|
|
10
10
|
const { agent: runtimeAgent } = useRuntimeState();
|
|
11
11
|
const { agent } = useCurrentAgent(args);
|
|
12
12
|
const appearancePage = useMemo(() => {
|
|
13
|
-
|
|
13
|
+
var _a, _b;
|
|
14
|
+
const appearance = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.appearancePage)) === null || _b === void 0 ? void 0 : _b.appearance;
|
|
14
15
|
return Object.assign(Object.assign({}, appearance), { componentId: (appearance === null || appearance === void 0 ? void 0 : appearance.componentId) || DEFAULT_PAGE_COMPONENT_ID });
|
|
15
16
|
}, [agent]);
|
|
16
17
|
const appearanceInput = useMemo(() => {
|
|
17
|
-
|
|
18
|
+
var _a, _b, _c, _d;
|
|
19
|
+
const appearance = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.appearanceInput)) === null || _b === void 0 ? void 0 : _b.appearance;
|
|
18
20
|
if (appearance)
|
|
19
21
|
return appearance;
|
|
20
|
-
const runtimeAppearance =
|
|
22
|
+
const runtimeAppearance = (_d = (_c = runtimeAgent.outputVariables) === null || _c === void 0 ? void 0 : _c.find((i) => i.name === RuntimeOutputVariable.appearanceInput)) === null || _d === void 0 ? void 0 : _d.appearance;
|
|
21
23
|
if (runtimeAppearance)
|
|
22
24
|
return runtimeAppearance;
|
|
23
25
|
return {
|
|
@@ -25,10 +27,11 @@ export default function useAppearances(args) {
|
|
|
25
27
|
};
|
|
26
28
|
}, [agent, runtimeAgent]);
|
|
27
29
|
const appearanceOutput = useMemo(() => {
|
|
28
|
-
|
|
30
|
+
var _a, _b, _c, _d;
|
|
31
|
+
const appearance = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.appearanceOutput)) === null || _b === void 0 ? void 0 : _b.appearance;
|
|
29
32
|
if (appearance === null || appearance === void 0 ? void 0 : appearance.componentId)
|
|
30
33
|
return appearance;
|
|
31
|
-
const runtimeAppearance =
|
|
34
|
+
const runtimeAppearance = (_d = (_c = runtimeAgent.outputVariables) === null || _c === void 0 ? void 0 : _c.find((i) => i.name === RuntimeOutputVariable.appearanceOutput)) === null || _d === void 0 ? void 0 : _d.appearance;
|
|
32
35
|
if (runtimeAppearance)
|
|
33
36
|
return runtimeAppearance;
|
|
34
37
|
return {
|
|
@@ -61,6 +64,7 @@ export function useOpeningMessage(args) {
|
|
|
61
64
|
const agentOpening = getOutputVariableInitialValue(agent, RuntimeOutputVariable.openingMessage);
|
|
62
65
|
if (agentOpening === null || agentOpening === void 0 ? void 0 : agentOpening.message) {
|
|
63
66
|
return {
|
|
67
|
+
agent,
|
|
64
68
|
message: agentOpening.message,
|
|
65
69
|
profile,
|
|
66
70
|
};
|
|
@@ -68,6 +72,7 @@ export function useOpeningMessage(args) {
|
|
|
68
72
|
const runtimeOpening = getOutputVariableInitialValue(runtimeAgent, RuntimeOutputVariable.openingMessage);
|
|
69
73
|
if (runtimeOpening === null || runtimeOpening === void 0 ? void 0 : runtimeOpening.message) {
|
|
70
74
|
return {
|
|
75
|
+
agent: runtimeAgent,
|
|
71
76
|
message: runtimeOpening.message,
|
|
72
77
|
profile: runtimeProfile,
|
|
73
78
|
};
|
|
@@ -0,0 +1,32 @@
|
|
|
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
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { Icon } from '@iconify/react';
|
|
12
|
+
import { IconButton, ListItemIcon } from '@mui/material';
|
|
13
|
+
import { useLocaleContext } from '../../../locale';
|
|
14
|
+
import { useHeader } from '../../../page/header';
|
|
15
|
+
import PopperMenuButton from '../components/PopperMenuButton';
|
|
16
|
+
import LoadingMenuItem from '../components/PopperMenuButton/LoadingMenuItem';
|
|
17
|
+
import { useComponentPreferences } from '../contexts/ComponentPreferences';
|
|
18
|
+
import { useSessionState } from '../state/session';
|
|
19
|
+
export function useHeaderMenu() {
|
|
20
|
+
var _a;
|
|
21
|
+
const { t, locale } = useLocaleContext();
|
|
22
|
+
const { hideHeaderMenuButton } = (_a = useComponentPreferences()) !== null && _a !== void 0 ? _a : {};
|
|
23
|
+
const clearSession = useSessionState((s) => s.clearSession);
|
|
24
|
+
useHeader(() => hideHeaderMenuButton
|
|
25
|
+
? {}
|
|
26
|
+
: {
|
|
27
|
+
addons: (...exists) => [
|
|
28
|
+
_jsx(PopperMenuButton, { component: IconButton, PopperProps: { placement: 'bottom-end', sx: { zIndex: 'appBar' } }, menus: _jsxs(LoadingMenuItem, { onClick: () => __awaiter(this, void 0, void 0, function* () { return clearSession(); }), children: [_jsx(ListItemIcon, { children: _jsx(Icon, { icon: "mingcute:broom-line" }) }), t('clearSession')] }), children: _jsx(Icon, { icon: "tabler:dots" }) }),
|
|
29
|
+
...exists,
|
|
30
|
+
],
|
|
31
|
+
}, [locale, hideHeaderMenuButton]);
|
|
32
|
+
}
|
|
@@ -8,11 +8,18 @@ export { default as Runtime } from './runtime/Runtime';
|
|
|
8
8
|
export { default as ChatBotButton } from './runtime/ChatBotButton';
|
|
9
9
|
export { default as SimplePage } from './runtime-components/SimplePage';
|
|
10
10
|
export { default as SimpleChat } from './runtime-components/SimpleChat';
|
|
11
|
-
export { default as MultiAgentsChat } from './runtime-components/MultiAgentsChat';
|
|
12
11
|
export { default as PhotoGallery } from './runtime-components/PhotoGallery';
|
|
13
12
|
export { default as AutoForm } from './runtime-components/AutoForm';
|
|
14
13
|
export { default as SimpleOutput } from './runtime-components/SimpleOutput';
|
|
15
14
|
export { default as ChatOutput } from './runtime-components/ChatOutput';
|
|
16
15
|
export { default as PhotoGalleryItem } from './runtime-components/PhotoGalleryItem';
|
|
16
|
+
export { default as SuggestedQuestionsView } from './runtime-components/SuggestedQuestionsView';
|
|
17
|
+
export { default as ReferencedLinksView } from './runtime-components/ReferencedLinksView';
|
|
18
|
+
export { default as ShareView } from './runtime-components/ShareView';
|
|
19
|
+
export { default as OpeningQuestionsView } from './runtime-components/OpeningQuestionsView';
|
|
20
|
+
export { default as ImagesView } from './runtime-components/ImagesView';
|
|
21
|
+
export { default as GoogleSearchRelatedQuestionsView } from './runtime-components/GoogleSearch/GoogleSearchRelatedQuestionsView';
|
|
22
|
+
export { default as GoogleSearchSourcesView } from './runtime-components/GoogleSearch/GoogleSearchSourcesView';
|
|
23
|
+
export { default as MarkdownView } from './runtime-components/MarkdownView';
|
|
17
24
|
// only use to debug, should be removed when PR
|
|
18
25
|
export * from './runtime-components/V0';
|
|
@@ -20,12 +20,13 @@ import LoadingMenuItem from '../../components/PopperMenuButton/LoadingMenuItem';
|
|
|
20
20
|
import RuntimeCommonProvider from '../../components/RuntimeCommonProvider';
|
|
21
21
|
import ScrollView from '../../components/ScrollView';
|
|
22
22
|
import { DEFAULT_PAGE_COMPONENT_ID } from '../../constants';
|
|
23
|
+
import ActiveAgentProvider from '../../contexts/ActiveAgent';
|
|
23
24
|
import RuntimeProvider from '../../contexts/Runtime';
|
|
24
25
|
import useAppearances, { useProfile } from '../../hooks/use-appearances';
|
|
25
26
|
import { useRuntimeState } from '../../state/runtime';
|
|
26
27
|
import { useAutoLoadSessionState, useSessionState } from '../../state/session';
|
|
27
28
|
export default function ChatBotButton({ aid, working }) {
|
|
28
|
-
return (_jsx(RuntimeProvider, { aid: aid, working: working, children: _jsx(
|
|
29
|
+
return (_jsx(RuntimeCommonProvider, { children: _jsx(RuntimeProvider, { aid: aid, working: working, children: _jsx(ActiveAgentProvider, { children: _jsx(ChatBotContent, {}) }) }) }));
|
|
29
30
|
}
|
|
30
31
|
function ChatBotContent() {
|
|
31
32
|
var _a, _b;
|
|
@@ -44,7 +45,7 @@ function ChatBotContent() {
|
|
|
44
45
|
'.aigne-layout': {
|
|
45
46
|
px: 2,
|
|
46
47
|
},
|
|
47
|
-
}, children: _jsx(Suspense, { fallback: _jsx(Stack, { flexGrow: 1, alignItems: "center", justifyContent: "center", children: _jsx(CircularProgress, { size: 24 }) }), children: _jsx(CustomComponentRenderer, { componentId: componentId, properties: appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.
|
|
48
|
+
}, children: _jsx(Suspense, { fallback: _jsx(Stack, { flexGrow: 1, alignItems: "center", justifyContent: "center", children: _jsx(CircularProgress, { size: 24 }) }), children: _jsx(CustomComponentRenderer, { componentId: componentId, properties: appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.componentProperties, props: { scrollViewProps: { disabled: true }, hideHeaderMenuButton: true } }) }) }) }))] }));
|
|
48
49
|
}
|
|
49
50
|
function ResponsiveChatBotContainer({ open, anchorEl, children, onClose, }) {
|
|
50
51
|
const theme = useTheme();
|
|
@@ -10,6 +10,7 @@ import { getComponentMountPoint } from '../../../../utils';
|
|
|
10
10
|
import RuntimeCommonProvider, { RuntimeLocaleProvider } from '../../components/RuntimeCommonProvider';
|
|
11
11
|
import SocialShare from '../../components/SocialShare';
|
|
12
12
|
import { AI_STUDIO_DID, DEFAULT_PAGE_COMPONENT_ID } from '../../constants';
|
|
13
|
+
import ActiveAgentProvider from '../../contexts/ActiveAgent';
|
|
13
14
|
import RuntimeProvider, { RuntimeProviderFromUrl } from '../../contexts/Runtime';
|
|
14
15
|
import useAppearances from '../../hooks/use-appearances';
|
|
15
16
|
import { useRuntimeState } from '../../state/runtime';
|
|
@@ -19,11 +20,8 @@ function AgentCreatedBy({ did }) {
|
|
|
19
20
|
return (_jsxs(_Fragment, { children: [t('by'), " ", _jsx(Box, { component: DID, did: did, copyable: false, responsive: true })] }));
|
|
20
21
|
}
|
|
21
22
|
export default function Runtime({ aid, working }) {
|
|
22
|
-
const children = (_jsx(
|
|
23
|
-
|
|
24
|
-
return (_jsx(RuntimeProvider, { aid: aid, working: working, children: children }));
|
|
25
|
-
}
|
|
26
|
-
return _jsx(RuntimeProviderFromUrl, { children: children });
|
|
23
|
+
const children = (_jsx(ActiveAgentProvider, { children: _jsx(RuntimeView, {}) }));
|
|
24
|
+
return (_jsx(RuntimeCommonProvider, { children: aid ? (_jsx(RuntimeProvider, { aid: aid, working: working, children: children })) : (_jsx(RuntimeProviderFromUrl, { children: children })) }));
|
|
27
25
|
}
|
|
28
26
|
function RuntimeView() {
|
|
29
27
|
var _a;
|
|
@@ -59,5 +57,5 @@ ${agent === null || agent === void 0 ? void 0 : agent.description}
|
|
|
59
57
|
};
|
|
60
58
|
}, [locale, isMobile, agent]);
|
|
61
59
|
const componentId = (_a = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.componentId) !== null && _a !== void 0 ? _a : DEFAULT_PAGE_COMPONENT_ID;
|
|
62
|
-
return (_jsxs(_Fragment, { children: [_jsxs(Helmet, { children: [agent.project.name && _jsx("title", { children: agent.project.name }), agent.project.description && _jsx("meta", { name: "description", content: agent.project.description })] }), _jsx(CustomComponentRenderer, { componentId: componentId, properties: appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.
|
|
60
|
+
return (_jsxs(_Fragment, { children: [_jsxs(Helmet, { children: [agent.project.name && _jsx("title", { children: agent.project.name }), agent.project.description && _jsx("meta", { name: "description", content: agent.project.description })] }), _jsx(CustomComponentRenderer, { componentId: componentId, properties: appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.componentProperties })] }));
|
|
63
61
|
}
|
|
@@ -0,0 +1,54 @@
|
|
|
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
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
|
+
import { Divider, List, ListItemButton } from '@mui/material';
|
|
12
|
+
import Joi from 'joi';
|
|
13
|
+
import { useMemo, useState } from 'react';
|
|
14
|
+
import OutputFieldContainer from '../../components/OutputFieldContainer';
|
|
15
|
+
import { useCurrentAgent } from '../../contexts/CurrentAgent';
|
|
16
|
+
import { useCurrentMessage } from '../../contexts/CurrentMessage';
|
|
17
|
+
import { useRuntimeState } from '../../state/runtime';
|
|
18
|
+
import { useCurrentSessionState } from '../../state/session';
|
|
19
|
+
const searchResultSchema = Joi.object({
|
|
20
|
+
related_questions: Joi.array().items(Joi.object({
|
|
21
|
+
question: Joi.string().required(),
|
|
22
|
+
link: Joi.string().required(),
|
|
23
|
+
snippet: Joi.string().empty([null, '']),
|
|
24
|
+
title: Joi.string().required(),
|
|
25
|
+
})),
|
|
26
|
+
});
|
|
27
|
+
export default function GoogleSearchRelatedView({ output, outputValue, onlyLastMessage, }) {
|
|
28
|
+
var _a, _b;
|
|
29
|
+
const { aid } = useCurrentAgent();
|
|
30
|
+
const { message } = (_a = useCurrentMessage({ optional: true })) !== null && _a !== void 0 ? _a : {};
|
|
31
|
+
const lastMessage = useCurrentSessionState((s) => { var _a; return (_a = s === null || s === void 0 ? void 0 : s.messages) === null || _a === void 0 ? void 0 : _a.at(-1); });
|
|
32
|
+
const isLastMessage = !!message && (message === null || message === void 0 ? void 0 : message.taskId) === (lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.taskId);
|
|
33
|
+
const [submitting, setSubmitting] = useState(false);
|
|
34
|
+
const { execute } = useRuntimeState();
|
|
35
|
+
const result = useMemo(() => {
|
|
36
|
+
const result = searchResultSchema.validate(outputValue, { allowUnknown: true });
|
|
37
|
+
if (result.error)
|
|
38
|
+
return undefined;
|
|
39
|
+
return result.value;
|
|
40
|
+
}, [outputValue]);
|
|
41
|
+
if ((!isLastMessage && onlyLastMessage) || !((_b = result === null || result === void 0 ? void 0 : result.related_questions) === null || _b === void 0 ? void 0 : _b.length))
|
|
42
|
+
return null;
|
|
43
|
+
return (_jsx(OutputFieldContainer, { output: output, children: _jsx(List, { dense: true, disablePadding: true, children: result.related_questions.map((item) => (_jsxs(_Fragment, { children: [_jsx(ListItemButton, { onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
44
|
+
if (submitting)
|
|
45
|
+
return;
|
|
46
|
+
setSubmitting(true);
|
|
47
|
+
try {
|
|
48
|
+
yield execute({ aid, parameters: { question: item.question } });
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
setSubmitting(false);
|
|
52
|
+
}
|
|
53
|
+
}), children: item.question }, item.title), _jsx(Divider, {})] }))) }) }));
|
|
54
|
+
}
|
package/lib/esm/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchSourcesView.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Avatar, Box, Card, CardActionArea, Grid, Skeleton, Stack, Typography } from '@mui/material';
|
|
3
|
+
import Joi from 'joi';
|
|
4
|
+
import { useMemo } from 'react';
|
|
5
|
+
import OutputFieldContainer from '../../components/OutputFieldContainer';
|
|
6
|
+
import { useCurrentMessage } from '../../contexts/CurrentMessage';
|
|
7
|
+
const searchResultSchema = Joi.object({
|
|
8
|
+
organic_results: Joi.array().items(Joi.object({
|
|
9
|
+
title: Joi.string().required(),
|
|
10
|
+
link: Joi.string().required(),
|
|
11
|
+
snippet: Joi.string().required(),
|
|
12
|
+
favicon: Joi.string().empty([null, '']),
|
|
13
|
+
source: Joi.string().empty([null, '']),
|
|
14
|
+
})),
|
|
15
|
+
});
|
|
16
|
+
export default function GoogleSearchSourcesView({ output, outputValue }) {
|
|
17
|
+
var _a;
|
|
18
|
+
const { message } = (_a = useCurrentMessage({ optional: true })) !== null && _a !== void 0 ? _a : {};
|
|
19
|
+
const searchResult = useMemo(() => {
|
|
20
|
+
const result = searchResultSchema.validate(outputValue, { allowUnknown: true });
|
|
21
|
+
if (result.error)
|
|
22
|
+
return undefined;
|
|
23
|
+
return result.value;
|
|
24
|
+
}, [outputValue]);
|
|
25
|
+
if (!message || (!(searchResult === null || searchResult === void 0 ? void 0 : searchResult.organic_results.length) && !message.loading))
|
|
26
|
+
return null;
|
|
27
|
+
return (_jsx(OutputFieldContainer, { output: output, children: _jsxs(Grid, { container: true, spacing: 1.5, children: [message.loading && (_jsxs(_Fragment, { children: [_jsx(Grid, { item: true, xs: 4, sm: 3, md: 2, children: _jsx(ItemSkeleton, {}) }), _jsx(Grid, { item: true, xs: 4, sm: 3, md: 2, children: _jsx(ItemSkeleton, {}) }), _jsx(Grid, { item: true, xs: 4, sm: 3, md: 2, children: _jsx(ItemSkeleton, {}) })] })), searchResult === null || searchResult === void 0 ? void 0 : searchResult.organic_results.map((item) => (_jsx(Grid, { item: true, xs: 4, sm: 3, md: 2, children: _jsx(ItemView, { item: item }) }, item.link)))] }) }));
|
|
28
|
+
}
|
|
29
|
+
function ItemView({ item }) {
|
|
30
|
+
var _a;
|
|
31
|
+
return (_jsx(ItemContainer, { title: `${item.title} - ${item.source}`, favicon: _jsx(Avatar, { src: item.favicon, sx: { width: 18, height: 18 }, children: (_a = item.source) === null || _a === void 0 ? void 0 : _a.slice(0, 1) }), link: item.link }));
|
|
32
|
+
}
|
|
33
|
+
function ItemSkeleton() {
|
|
34
|
+
return (_jsx(ItemContainer, { title: _jsxs(_Fragment, { children: [_jsx(Skeleton, { width: "100%" }), _jsx(Skeleton, { width: "40%" })] }), favicon: _jsx(Skeleton, { width: 18, height: 18, variant: "circular" }), link: _jsx(Skeleton, { width: "70%" }) }));
|
|
35
|
+
}
|
|
36
|
+
function ItemContainer({ title, favicon, link }) {
|
|
37
|
+
return (_jsx(Card, { sx: { height: '100%' }, children: _jsx(CardActionArea, { component: "a", href: typeof link === 'string' ? link : undefined, target: "_blank", sx: { height: '100%' }, children: _jsxs(Stack, { sx: { p: 1, gap: 1, height: '100%' }, children: [_jsx(Box, { flexGrow: 1, children: _jsx(Typography, { variant: "body2", sx: {
|
|
38
|
+
display: '-webkit-box',
|
|
39
|
+
WebkitBoxOrient: 'vertical',
|
|
40
|
+
WebkitLineClamp: 2,
|
|
41
|
+
overflow: 'hidden',
|
|
42
|
+
fontWeight: 500,
|
|
43
|
+
}, children: title }) }), _jsxs(Stack, { flexDirection: "row", alignItems: "center", gap: 1, overflow: "hidden", children: [_jsx(Box, { width: 18, height: 18, children: favicon }), _jsx(Typography, { variant: "caption", noWrap: true, sx: { flex: 1, width: 1 }, children: link })] })] }) }) }));
|
|
44
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import ImagePreview from '@blocklet/ai-kit/components/image-preview';
|
|
3
|
+
import { Skeleton } from '@mui/material';
|
|
4
|
+
import Joi from 'joi';
|
|
5
|
+
import { useMemo } from 'react';
|
|
6
|
+
import OutputFieldContainer from '../../components/OutputFieldContainer';
|
|
7
|
+
import { useCurrentMessage } from '../../contexts/CurrentMessage';
|
|
8
|
+
const imagesSchema = Joi.array().items(Joi.object({
|
|
9
|
+
url: Joi.string().required(),
|
|
10
|
+
}));
|
|
11
|
+
export default function ImagesView({ output, outputValue }) {
|
|
12
|
+
var _a;
|
|
13
|
+
const { message } = (_a = useCurrentMessage({ optional: true })) !== null && _a !== void 0 ? _a : {};
|
|
14
|
+
const images = useMemo(() => {
|
|
15
|
+
var _a;
|
|
16
|
+
const result = imagesSchema.validate(outputValue, { allowUnknown: true });
|
|
17
|
+
if (result.error)
|
|
18
|
+
return undefined;
|
|
19
|
+
return (_a = result.value) === null || _a === void 0 ? void 0 : _a.map((i) => ({ src: i.url }));
|
|
20
|
+
}, [outputValue]);
|
|
21
|
+
if (!(images === null || images === void 0 ? void 0 : images.length) && !(message === null || message === void 0 ? void 0 : message.loading))
|
|
22
|
+
return null;
|
|
23
|
+
return (_jsx(OutputFieldContainer, { output: output, sx: { '.lazy-image-wrapper': { borderRadius: 1, img: { borderRadius: 1 } } }, children: (images === null || images === void 0 ? void 0 : images.length) ? (_jsx(ImagePreview, { dataSource: images, itemWidth: 200, spacing: 1 })) : (message === null || message === void 0 ? void 0 : message.loading) ? (_jsx(Skeleton, { width: 200, height: 200, variant: "rounded" })) : null }));
|
|
24
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { cx } from '@emotion/css';
|
|
3
|
+
import MarkdownRenderer from '../../components/MarkdownRenderer';
|
|
4
|
+
import OutputFieldContainer from '../../components/OutputFieldContainer';
|
|
5
|
+
export default function MarkdownView({ output, outputValue, fontSize, writing, }) {
|
|
6
|
+
return (_jsx(OutputFieldContainer, { output: output, children: _jsx(MarkdownRenderer, { className: cx(writing && 'writing'), sx: { fontSize: typeof fontSize === 'string' && /^\d+$/.test(fontSize) ? Number(fontSize) : fontSize }, children: outputValue }) }));
|
|
7
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
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
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
11
|
+
import { List, ListItemButton, listItemButtonClasses } from '@mui/material';
|
|
12
|
+
import { useState } from 'react';
|
|
13
|
+
import OutputFieldContainer from '../../components/OutputFieldContainer';
|
|
14
|
+
import { useCurrentAgent } from '../../contexts/CurrentAgent';
|
|
15
|
+
import { useOpeningQuestions } from '../../hooks/use-appearances';
|
|
16
|
+
import { useRuntimeState } from '../../state/runtime';
|
|
17
|
+
export default function OpeningQuestionsView({ output }) {
|
|
18
|
+
const { aid } = useCurrentAgent();
|
|
19
|
+
const { execute } = useRuntimeState();
|
|
20
|
+
const opening = useOpeningQuestions();
|
|
21
|
+
const [submitting, setSubmitting] = useState(false);
|
|
22
|
+
if (!(opening === null || opening === void 0 ? void 0 : opening.questions.length))
|
|
23
|
+
return null;
|
|
24
|
+
return (_jsx(OutputFieldContainer, { output: output, children: _jsx(List, { disablePadding: true, sx: { [`.${listItemButtonClasses.root}`]: { border: 1, borderColor: 'grey.200', borderRadius: 1, my: 1 } }, children: opening.questions.map((item) => {
|
|
25
|
+
return (_jsx(ListItemButton, { onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
26
|
+
if (submitting)
|
|
27
|
+
return;
|
|
28
|
+
try {
|
|
29
|
+
setSubmitting(true);
|
|
30
|
+
yield execute({
|
|
31
|
+
aid,
|
|
32
|
+
parameters: Object.assign(Object.assign({}, item.parameters), { question: item.parameters.question || item.title }),
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
finally {
|
|
36
|
+
setSubmitting(false);
|
|
37
|
+
}
|
|
38
|
+
}), children: item.title }, item.id));
|
|
39
|
+
}) }) }));
|
|
40
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -18,14 +18,14 @@ import CustomComponentRenderer from '../../../../../components/CustomComponentRe
|
|
|
18
18
|
import { useLocaleContext } from '../../../../locale';
|
|
19
19
|
import SimpleHeader from '../../components/Header/SimpleHeader';
|
|
20
20
|
import LoadingButton from '../../components/LoadingButton';
|
|
21
|
+
import { useActiveAgent } from '../../contexts/ActiveAgent';
|
|
21
22
|
import CurrentAgentProvider from '../../contexts/CurrentAgent';
|
|
22
23
|
import CurrentMessageProvider from '../../contexts/CurrentMessage';
|
|
23
24
|
import useAppearances from '../../hooks/use-appearances';
|
|
24
|
-
import { useRuntimeState } from '../../state/runtime';
|
|
25
25
|
import { useAutoLoadSessionState, useCurrentSessionState, useSessionState } from '../../state/session';
|
|
26
26
|
import mapRight from '../../utils/map-right';
|
|
27
27
|
export default function PhotoGallery({ resultTitle, primaryColor }) {
|
|
28
|
-
const {
|
|
28
|
+
const { activeAgentId } = useActiveAgent();
|
|
29
29
|
useAutoLoadSessionState();
|
|
30
30
|
const inheritedTheme = useTheme();
|
|
31
31
|
const theme = useMemo(() => {
|
|
@@ -45,14 +45,14 @@ export default function PhotoGallery({ resultTitle, primaryColor }) {
|
|
|
45
45
|
},
|
|
46
46
|
});
|
|
47
47
|
}, [inheritedTheme, primaryColor]);
|
|
48
|
-
return (_jsx(ThemeProvider, { theme: theme, children: _jsxs(Stack, { className: "aigne-layout aigne-photo-wall-layout", children: [_jsx(SimpleHeader, { TitleProps: { fontSize: 48 }, DescriptionProps: { fontSize: 20 }, maxWidth: "md", mx: "auto", width: "100%", px: { xs: 2, sm: 3 } }), _jsx(CurrentAgentProvider, { agentId:
|
|
48
|
+
return (_jsx(ThemeProvider, { theme: theme, children: _jsxs(Stack, { className: "aigne-layout aigne-photo-wall-layout", children: [_jsx(SimpleHeader, { TitleProps: { fontSize: 48 }, DescriptionProps: { fontSize: 20 }, maxWidth: "md", mx: "auto", width: "100%", px: { xs: 2, sm: 3 } }), _jsx(CurrentAgentProvider, { agentId: activeAgentId, children: _jsx(AgentInputRender, { className: "aigne-inputs aigne-photo-wall-inputs", maxWidth: "md", mx: "auto", width: "100%", px: { xs: 2, sm: 3 } }) }), _jsx(OutputView, { resultTitle: resultTitle, className: "aigne-outputs aigne-photo-wall-outputs", gap: 2 })] }) }));
|
|
49
49
|
}
|
|
50
50
|
function AgentInputRender(_a) {
|
|
51
51
|
var props = __rest(_a, []);
|
|
52
52
|
const { appearanceInput } = useAppearances();
|
|
53
53
|
if (!(appearanceInput === null || appearanceInput === void 0 ? void 0 : appearanceInput.componentId))
|
|
54
54
|
return null;
|
|
55
|
-
return (_jsx(Stack, Object.assign({}, props, { children: _jsx(CustomComponentRenderer, { componentId: appearanceInput.componentId, properties: appearanceInput.
|
|
55
|
+
return (_jsx(Stack, Object.assign({}, props, { children: _jsx(CustomComponentRenderer, { componentId: appearanceInput.componentId, properties: appearanceInput.componentProperties }) })));
|
|
56
56
|
}
|
|
57
57
|
function NoOutputs() {
|
|
58
58
|
return (_jsx(Stack, { mt: 10, children: _jsx(Typography, { color: "text.disabled", children: "You haven't generated any pictures yet." }) }));
|
|
@@ -73,5 +73,5 @@ const OutputItemView = memo(({ message }) => {
|
|
|
73
73
|
const { appearanceOutput } = useAppearances({ agentId: message.assistantId });
|
|
74
74
|
if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
|
|
75
75
|
return null;
|
|
76
|
-
return (_jsx(CurrentAgentProvider, { agentId: message.assistantId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsx(Suspense, { children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.
|
|
76
|
+
return (_jsx(CurrentAgentProvider, { agentId: message.assistantId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsx(Suspense, { children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProperties }) }) }) }, message.taskId));
|
|
77
77
|
});
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Link, Stack } from '@mui/material';
|
|
3
|
+
import Joi from 'joi';
|
|
4
|
+
import { useMemo } from 'react';
|
|
5
|
+
import OutputFieldContainer from '../../components/OutputFieldContainer';
|
|
6
|
+
const referencedLinksSchema = Joi.array().items(Joi.object({
|
|
7
|
+
title: Joi.string().required(),
|
|
8
|
+
url: Joi.string().required(),
|
|
9
|
+
}));
|
|
10
|
+
export default function SuggestedQuestionsView({ output, outputValue }) {
|
|
11
|
+
const links = useMemo(() => {
|
|
12
|
+
const result = referencedLinksSchema.validate(outputValue, { allowUnknown: true });
|
|
13
|
+
if (result.error)
|
|
14
|
+
return undefined;
|
|
15
|
+
return result.value;
|
|
16
|
+
}, [outputValue]);
|
|
17
|
+
if (!(links === null || links === void 0 ? void 0 : links.length))
|
|
18
|
+
return null;
|
|
19
|
+
return (_jsx(OutputFieldContainer, { output: output, children: _jsx(Stack, { gap: 1, children: links.map((item) => (_jsx(Link, { href: item.url, children: item.title }))) }) }));
|
|
20
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import OutputFieldContainer from '../../components/OutputFieldContainer';
|
|
3
|
+
import ShareActions from '../../components/ShareActions';
|
|
4
|
+
import { useCurrentMessage } from '../../contexts/CurrentMessage';
|
|
5
|
+
export default function ShareView({ output }) {
|
|
6
|
+
const message = useCurrentMessage({ optional: true });
|
|
7
|
+
if (message === null || message === void 0 ? void 0 : message.message.loading)
|
|
8
|
+
return null;
|
|
9
|
+
return (_jsx(OutputFieldContainer, { output: output, children: _jsx(ShareActions, { flexDirection: "row", justifyContent: "flex-end" }) }));
|
|
10
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Box } from '@mui/material';
|
|
3
|
+
import { useComponentPreferences } from '../../contexts/ComponentPreferences';
|
|
4
|
+
export default function BackgroundImage() {
|
|
5
|
+
var _a, _b;
|
|
6
|
+
const preferences = useComponentPreferences();
|
|
7
|
+
if (!((_a = preferences === null || preferences === void 0 ? void 0 : preferences.backgroundImage) === null || _a === void 0 ? void 0 : _a.url))
|
|
8
|
+
return null;
|
|
9
|
+
return (_jsx(Box, { sx: {
|
|
10
|
+
position: 'fixed',
|
|
11
|
+
left: 0,
|
|
12
|
+
top: 0,
|
|
13
|
+
right: 0,
|
|
14
|
+
bottom: 0,
|
|
15
|
+
backgroundImage: `url(${(_b = preferences.backgroundImage) === null || _b === void 0 ? void 0 : _b.url}) !important`,
|
|
16
|
+
backgroundRepeat: 'no-repeat',
|
|
17
|
+
backgroundSize: 'cover',
|
|
18
|
+
backgroundPosition: 'center',
|
|
19
|
+
pointerEvents: 'none',
|
|
20
|
+
zIndex: -1,
|
|
21
|
+
} }));
|
|
22
|
+
}
|