@blocklet/pages-kit 0.2.309 → 0.2.311
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/Header/SimpleHeader.js +3 -3
- package/lib/cjs/builtin/async/ai-runtime/components/ShareActions/index.js +5 -3
- package/lib/cjs/builtin/async/ai-runtime/contexts/CurrentAgent.js +6 -14
- package/lib/cjs/builtin/async/ai-runtime/hooks/use-appearances.js +94 -0
- package/lib/cjs/builtin/async/ai-runtime/index.js +5 -1
- package/lib/cjs/builtin/async/ai-runtime/runtime/ChatBotButton/index.js +33 -7
- package/lib/cjs/builtin/async/ai-runtime/runtime/Runtime/index.js +12 -9
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageItemView.js +13 -10
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageMetadataRenderer.js +8 -5
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/MultiAgentsChat/index.js +192 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +4 -26
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +18 -24
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +4 -26
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Input.js +152 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Output.js +79 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Page.js +147 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/index.js +12 -0
- package/lib/cjs/builtin/async/ai-runtime/state/runtime.js +1 -5
- package/lib/cjs/builtin/async/ai-runtime/utils/runtime-output-schema.js +8 -0
- package/lib/cjs/builtin/mui/material.js +3 -2
- package/lib/cjs/tsconfig.tsbuildinfo +1 -0
- package/lib/cjs/utils/inject-global-components-dump-json.js +1167 -0
- package/lib/esm/builtin/async/ai-runtime/components/Header/SimpleHeader.js +3 -3
- package/lib/esm/builtin/async/ai-runtime/components/ShareActions/index.js +5 -3
- package/lib/esm/builtin/async/ai-runtime/contexts/CurrentAgent.js +6 -14
- package/lib/esm/builtin/async/ai-runtime/hooks/use-appearances.js +87 -0
- package/lib/esm/builtin/async/ai-runtime/index.js +3 -0
- package/lib/esm/builtin/async/ai-runtime/runtime/ChatBotButton/index.js +10 -7
- package/lib/esm/builtin/async/ai-runtime/runtime/Runtime/index.js +13 -10
- package/lib/esm/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageItemView.js +13 -10
- package/lib/esm/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageMetadataRenderer.js +8 -5
- package/lib/esm/builtin/async/ai-runtime/runtime-components/MultiAgentsChat/index.js +163 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +4 -3
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/index.js +19 -25
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +4 -3
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Input.js +146 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Output.js +73 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Page.js +142 -0
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/index.js +3 -0
- package/lib/esm/builtin/async/ai-runtime/state/runtime.js +1 -5
- package/lib/esm/builtin/async/ai-runtime/utils/runtime-output-schema.js +4 -0
- package/lib/esm/builtin/mui/material.js +1 -1
- package/lib/esm/tsconfig.tsbuildinfo +1 -0
- package/lib/esm/utils/inject-global-components-dump-json.js +1165 -0
- package/lib/types/builtin/async/ai-runtime/api/agent.d.ts +8 -0
- package/lib/types/builtin/async/ai-runtime/contexts/CurrentAgent.d.ts +4 -5
- package/lib/types/builtin/async/ai-runtime/hooks/use-appearances.d.ts +45 -0
- package/lib/types/builtin/async/ai-runtime/index.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/MultiAgentsChat/index.d.ts +11 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/V0/Input.d.ts +7 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/V0/Output.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/V0/Page.d.ts +5 -0
- package/lib/types/builtin/async/ai-runtime/runtime-components/V0/index.d.ts +3 -0
- package/lib/types/builtin/async/ai-runtime/state/agent.d.ts +1 -1
- package/lib/types/builtin/async/ai-runtime/state/runtime.d.ts +1 -3
- package/lib/types/builtin/async/ai-runtime/utils/runtime-output-schema.d.ts +3 -0
- package/lib/types/builtin/mui/material.d.ts +1 -1
- package/lib/types/tsconfig.tsbuildinfo +1 -0
- package/lib/types/utils/inject-global-components-dump-json.d.ts +1 -0
- package/package.json +13 -9
|
@@ -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
|
|
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';
|
|
@@ -23,6 +23,7 @@ import ScrollView from '../../components/ScrollView';
|
|
|
23
23
|
import UserInfo from '../../components/UserInfo';
|
|
24
24
|
import CurrentAgentProvider, { useCurrentAgent } from '../../contexts/CurrentAgent';
|
|
25
25
|
import CurrentMessageProvider from '../../contexts/CurrentMessage';
|
|
26
|
+
import useAppearances, { useOpeningMessage, useOpeningQuestions, useProfile } from '../../hooks/use-appearances';
|
|
26
27
|
import { useRuntimeState } from '../../state/runtime';
|
|
27
28
|
import { useSessionState } from '../../state/session';
|
|
28
29
|
import MessageSuggestedQuestions, { MessageSuggestedQuestion } from '../ChatOutput/MessageSuggestedQuestions';
|
|
@@ -61,8 +62,8 @@ function SimpleChatView() {
|
|
|
61
62
|
}
|
|
62
63
|
function AgentInputRender(_a) {
|
|
63
64
|
var props = __rest(_a, []);
|
|
64
|
-
const { appearanceInput } =
|
|
65
|
-
if (!
|
|
65
|
+
const { appearanceInput } = useAppearances();
|
|
66
|
+
if (!appearanceInput.componentId)
|
|
66
67
|
return null;
|
|
67
68
|
return (_jsx(Stack, Object.assign({}, props, { children: _jsx(CustomComponentRenderer, { componentId: appearanceInput.componentId, properties: appearanceInput.componentProps }) })));
|
|
68
69
|
}
|
|
@@ -74,15 +75,15 @@ function OutputView(_a) {
|
|
|
74
75
|
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, {})] })));
|
|
75
76
|
}
|
|
76
77
|
const OutputItemView = memo(({ message }) => {
|
|
77
|
-
var _a, _b, _c, _d
|
|
78
|
-
const { appearanceOutput } = useCurrentAgent({ agentId: message.assistantId });
|
|
79
|
-
const { appearancePage } = useRuntimeState();
|
|
78
|
+
var _a, _b, _c, _d;
|
|
80
79
|
const { session: authSession } = useSessionContext();
|
|
80
|
+
const { appearanceOutput } = useAppearances({ agentId: message.assistantId });
|
|
81
|
+
const profile = useProfile({ agentId: message.assistantId });
|
|
81
82
|
if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
|
|
82
83
|
return null;
|
|
83
84
|
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: {
|
|
84
85
|
renderType: 'parameters',
|
|
85
|
-
} }) }) }), _jsx(Box, { children: _jsx(UserInfo, { name:
|
|
86
|
+
} }) }) }), _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: {
|
|
86
87
|
renderType: 'result',
|
|
87
88
|
} }) }) })] }) }) }));
|
|
88
89
|
});
|
|
@@ -98,16 +99,12 @@ function SuggestedQuestionsView({ message }) {
|
|
|
98
99
|
} })) : null }));
|
|
99
100
|
}
|
|
100
101
|
const OpeningMessageView = memo(() => {
|
|
101
|
-
var _a
|
|
102
|
-
const { childAgentId
|
|
103
|
-
const
|
|
104
|
-
|
|
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))
|
|
102
|
+
var _a;
|
|
103
|
+
const { childAgentId } = useRuntimeState();
|
|
104
|
+
const opening = useOpeningMessage({ agentId: childAgentId });
|
|
105
|
+
if (!(opening === null || opening === void 0 ? void 0 : opening.message))
|
|
109
106
|
return null;
|
|
110
|
-
return (_jsx(Box, { children: _jsx(UserInfo, { name:
|
|
107
|
+
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: {
|
|
111
108
|
bgcolor: 'rgba(229, 231, 235, 1)',
|
|
112
109
|
borderRadius: 1,
|
|
113
110
|
borderTopLeftRadius: 2,
|
|
@@ -115,19 +112,16 @@ const OpeningMessageView = memo(() => {
|
|
|
115
112
|
py: 1,
|
|
116
113
|
mt: 0.5,
|
|
117
114
|
mr: 5,
|
|
118
|
-
}, children: _jsx(MarkdownRenderer, { children:
|
|
115
|
+
}, children: _jsx(MarkdownRenderer, { children: opening.message }) }) }) }));
|
|
119
116
|
});
|
|
120
117
|
function OpeningQuestionsView() {
|
|
121
|
-
const { childAgentId } = useRuntimeState();
|
|
122
118
|
const { execute } = useRuntimeState();
|
|
123
|
-
const {
|
|
124
|
-
const
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
}, [agent]);
|
|
128
|
-
if (!(openingQuestions === null || openingQuestions === void 0 ? void 0 : openingQuestions.length))
|
|
119
|
+
const { childAgentId } = useRuntimeState();
|
|
120
|
+
const { aid } = useCurrentAgent({ agentId: childAgentId });
|
|
121
|
+
const opening = useOpeningQuestions({ aid });
|
|
122
|
+
if (!(opening === null || opening === void 0 ? void 0 : opening.questions.length))
|
|
129
123
|
return null;
|
|
130
|
-
return (_jsx(Box, { ml: 6.5, mr: 2.5, children: _jsx(Stack, { gap: 1, children:
|
|
124
|
+
return (_jsx(Box, { ml: 6.5, mr: 2.5, children: _jsx(Stack, { gap: 1, children: opening.questions.map((item) => {
|
|
131
125
|
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
126
|
}) }) }));
|
|
133
127
|
}
|
|
@@ -16,8 +16,9 @@ import Balancer from 'react-wrap-balancer';
|
|
|
16
16
|
import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
|
|
17
17
|
import SimpleHeader from '../../components/Header/SimpleHeader';
|
|
18
18
|
import SimpleLayout from '../../components/Layout/SimpleLayout';
|
|
19
|
-
import CurrentAgentProvider
|
|
19
|
+
import CurrentAgentProvider from '../../contexts/CurrentAgent';
|
|
20
20
|
import CurrentMessageProvider from '../../contexts/CurrentMessage';
|
|
21
|
+
import useAppearances from '../../hooks/use-appearances';
|
|
21
22
|
import { useRuntimeState } from '../../state/runtime';
|
|
22
23
|
import { useSessionState } from '../../state/session';
|
|
23
24
|
export default function SimplePage({ resultTitle, primaryColor }) {
|
|
@@ -45,7 +46,7 @@ export default function SimplePage({ resultTitle, primaryColor }) {
|
|
|
45
46
|
}
|
|
46
47
|
function AgentInputRender(_a) {
|
|
47
48
|
var props = __rest(_a, []);
|
|
48
|
-
const { appearanceInput } =
|
|
49
|
+
const { appearanceInput } = useAppearances();
|
|
49
50
|
if (!(appearanceInput === null || appearanceInput === void 0 ? void 0 : appearanceInput.componentId))
|
|
50
51
|
return null;
|
|
51
52
|
return (_jsx(Stack, Object.assign({}, props, { children: _jsx(CustomComponentRenderer, { componentId: appearanceInput.componentId, properties: appearanceInput.componentProps }) })));
|
|
@@ -56,7 +57,7 @@ function OutputView(_a) {
|
|
|
56
57
|
return (_jsx(Stack, Object.assign({ gap: 2, mt: 4 }, props, { children: lastMessage && (_jsxs(_Fragment, { children: [resultTitle && (_jsx(Typography, { width: "100%", component: "h5", fontSize: 36, fontWeight: 700, textAlign: "center", children: _jsx(Balancer, { children: resultTitle }) })), _jsx(Stack, { children: _jsx(OutputItemView, { message: lastMessage }) })] })) })));
|
|
57
58
|
}
|
|
58
59
|
const OutputItemView = memo(({ message }) => {
|
|
59
|
-
const { appearanceOutput } =
|
|
60
|
+
const { appearanceOutput } = useAppearances({ agentId: message.assistantId });
|
|
60
61
|
if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId))
|
|
61
62
|
return null;
|
|
62
63
|
return (_jsx(CurrentAgentProvider, { agentId: message.assistantId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsx(Suspense, { children: _jsx(CustomComponentRenderer, { componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProps }) }) }) }));
|
|
@@ -0,0 +1,146 @@
|
|
|
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 { cx } from '@emotion/css';
|
|
12
|
+
import { Box, FormLabel, InputAdornment, Stack, ThemeProvider, createTheme, formLabelClasses, outlinedInputClasses, styled, useTheme, } from '@mui/material';
|
|
13
|
+
import isEmpty from 'lodash/isEmpty';
|
|
14
|
+
import omit from 'lodash/omit';
|
|
15
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
16
|
+
import { Controller, useForm } from 'react-hook-form';
|
|
17
|
+
import { useLocaleContext } from '../../../../locale';
|
|
18
|
+
import AgentInputField from '../../components/AgentInputField';
|
|
19
|
+
import LoadingButton from '../../components/LoadingButton';
|
|
20
|
+
import { useCurrentAgent } from '../../contexts/CurrentAgent';
|
|
21
|
+
import { useRuntimeState } from '../../state/runtime';
|
|
22
|
+
import { useSessionState } from '../../state/session';
|
|
23
|
+
import { isValidInput } from '../../utils/agent-inputs';
|
|
24
|
+
export default function AutoForm({ submitText, inlineLabel, autoFillLastForm = true, submitInQuestionField, chatMode, }) {
|
|
25
|
+
const { t } = useLocaleContext();
|
|
26
|
+
const { aid, agent } = useCurrentAgent();
|
|
27
|
+
const { execute } = useRuntimeState();
|
|
28
|
+
const running = useSessionState()((s) => s.running);
|
|
29
|
+
const parameters = useMemo(() => {
|
|
30
|
+
var _a;
|
|
31
|
+
return (_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.filter(isValidInput).map((i) => {
|
|
32
|
+
var _a;
|
|
33
|
+
return (Object.assign(Object.assign({}, i), { label: ((_a = i.label) === null || _a === void 0 ? void 0 : _a.trim()) || undefined }));
|
|
34
|
+
});
|
|
35
|
+
}, [agent.parameters]);
|
|
36
|
+
const defaultForm = useInitialFormValues();
|
|
37
|
+
const theme = useFormTheme();
|
|
38
|
+
const form = useForm({ defaultValues: defaultForm });
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
if (autoFillLastForm && !form.formState.isSubmitted && !form.formState.isSubmitting) {
|
|
41
|
+
form.reset(chatMode ? omit(defaultForm, 'question') : defaultForm);
|
|
42
|
+
}
|
|
43
|
+
}, [defaultForm, autoFillLastForm, form, chatMode]);
|
|
44
|
+
const onSubmit = (parameters) => __awaiter(this, void 0, void 0, function* () {
|
|
45
|
+
yield execute({
|
|
46
|
+
aid,
|
|
47
|
+
parameters,
|
|
48
|
+
onResponseStart: () => {
|
|
49
|
+
if (chatMode)
|
|
50
|
+
form.resetField('question', { defaultValue: '' });
|
|
51
|
+
},
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
return (_jsx(ThemeProvider, { theme: theme, children: _jsxs(Form, { component: "form", className: cx('form', `label-position-${inlineLabel ? 'start' : 'top'}`), onSubmit: form.handleSubmit(onSubmit), children: [parameters === null || parameters === void 0 ? void 0 : parameters.map((parameter, index) => {
|
|
55
|
+
const { key, required } = parameter !== null && parameter !== void 0 ? parameter : {};
|
|
56
|
+
return (_jsx(Box, { children: _jsx(Controller, { control: form.control, name: key, rules: {
|
|
57
|
+
required,
|
|
58
|
+
min: parameter.type === 'number' && typeof parameter.min === 'number'
|
|
59
|
+
? { value: parameter.min, message: '' }
|
|
60
|
+
: undefined,
|
|
61
|
+
max: parameter.type === 'number' && typeof parameter.max === 'number'
|
|
62
|
+
? { value: parameter.max, message: '' }
|
|
63
|
+
: undefined,
|
|
64
|
+
minLength: parameter.type === 'string' && typeof parameter.minLength === 'number'
|
|
65
|
+
? { value: parameter.minLength, message: '' }
|
|
66
|
+
: undefined,
|
|
67
|
+
maxLength: parameter.type === 'string' && typeof parameter.maxLength === 'number'
|
|
68
|
+
? { value: parameter.maxLength, message: '' }
|
|
69
|
+
: undefined,
|
|
70
|
+
}, render: ({ field, fieldState }) => {
|
|
71
|
+
var _a;
|
|
72
|
+
return (_jsxs(Stack, { className: "form-item", children: [parameter.label && _jsx(FormLabel, { children: parameter.label }), _jsx(AgentInputField, { inputRef: field.ref, autoFocus: index === 0, size: "small", hiddenLabel: true, fullWidth: true, label: undefined, parameter: parameter, maxRows: !(parameter === null || parameter === void 0 ? void 0 : parameter.type) || (parameter === null || parameter === void 0 ? void 0 : parameter.type) === 'string' ? 5 : undefined, value: field.value || '', onChange: (value) => field.onChange({ target: { value } }), error: Boolean(fieldState.error), helperText: ((_a = fieldState.error) === null || _a === void 0 ? void 0 : _a.message) || (parameter === null || parameter === void 0 ? void 0 : parameter.helper), InputProps: parameter.key === 'question' && submitInQuestionField
|
|
73
|
+
? {
|
|
74
|
+
endAdornment: (_jsx(InputAdornment, { position: "end", sx: { py: 3, mr: -0.75, alignSelf: 'flex-end' }, children: _jsx(LoadingButton, { type: "submit", variant: "contained", loading: running, sx: { borderRadius: 100 }, children: submitText }) })),
|
|
75
|
+
}
|
|
76
|
+
: undefined })] }));
|
|
77
|
+
} }) }, parameter.id));
|
|
78
|
+
}), !(submitInQuestionField && (parameters === null || parameters === void 0 ? void 0 : parameters.some((i) => i.key === 'question'))) && (_jsx(LoadingButton, { type: "submit", variant: "contained", loading: running, sx: { height: 40 }, children: submitText || t('generate') }))] }) }));
|
|
79
|
+
}
|
|
80
|
+
function useInitialFormValues() {
|
|
81
|
+
const { agent } = useCurrentAgent();
|
|
82
|
+
const lastMessage = useSessionState()((s) => { var _a; return (_a = s.messages) === null || _a === void 0 ? void 0 : _a.at(-1); });
|
|
83
|
+
const [lastInputs, setLastInputs] = useState();
|
|
84
|
+
useEffect(() => {
|
|
85
|
+
if (!lastInputs) {
|
|
86
|
+
const lastParameters = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.parameters;
|
|
87
|
+
if (!isEmpty(lastParameters))
|
|
88
|
+
setLastInputs(lastParameters);
|
|
89
|
+
}
|
|
90
|
+
}, [lastMessage]);
|
|
91
|
+
return useMemo(() => {
|
|
92
|
+
var _a, _b;
|
|
93
|
+
if (lastInputs) {
|
|
94
|
+
return lastInputs;
|
|
95
|
+
}
|
|
96
|
+
return Object.fromEntries((_b = (_a = agent.parameters) === null || _a === void 0 ? void 0 : _a.map((parameter) => [parameter.key, parameter.defaultValue])) !== null && _b !== void 0 ? _b : []);
|
|
97
|
+
}, [lastInputs, agent]);
|
|
98
|
+
}
|
|
99
|
+
function useFormTheme() {
|
|
100
|
+
const theme = useTheme();
|
|
101
|
+
return useMemo(() => {
|
|
102
|
+
const themeOptions = {
|
|
103
|
+
shape: {
|
|
104
|
+
borderRadius: 8,
|
|
105
|
+
},
|
|
106
|
+
components: {
|
|
107
|
+
MuiTextField: {
|
|
108
|
+
styleOverrides: {
|
|
109
|
+
root: ({ theme }) => theme.unstable_sx({
|
|
110
|
+
[`.${outlinedInputClasses.root}`]: {
|
|
111
|
+
[`.${outlinedInputClasses.notchedOutline}`]: {
|
|
112
|
+
borderWidth: 2,
|
|
113
|
+
borderColor: 'primary.light',
|
|
114
|
+
},
|
|
115
|
+
':hover': {
|
|
116
|
+
[`.${outlinedInputClasses.notchedOutline}`]: {
|
|
117
|
+
borderColor: 'primary.main',
|
|
118
|
+
},
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
}),
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
},
|
|
125
|
+
};
|
|
126
|
+
return createTheme(theme, themeOptions);
|
|
127
|
+
}, [theme]);
|
|
128
|
+
}
|
|
129
|
+
const Form = styled(Stack)(({ theme }) => theme.unstable_sx({
|
|
130
|
+
gap: 2,
|
|
131
|
+
'.form-item': {
|
|
132
|
+
gap: 0.5,
|
|
133
|
+
[`.${formLabelClasses.root}`]: {
|
|
134
|
+
fontWeight: 500,
|
|
135
|
+
color: 'text.primary',
|
|
136
|
+
},
|
|
137
|
+
},
|
|
138
|
+
'&.label-position-start': {
|
|
139
|
+
'.form-item': {
|
|
140
|
+
display: 'flex',
|
|
141
|
+
flexDirection: 'row',
|
|
142
|
+
alignItems: 'center',
|
|
143
|
+
gap: 1,
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
}));
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Icon } from '@iconify/react';
|
|
3
|
+
import { Box, Drawer, IconButton, Skeleton, Stack } from '@mui/material';
|
|
4
|
+
import { useState } from 'react';
|
|
5
|
+
import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
|
|
6
|
+
import MarkdownRenderer from '../../components/MarkdownRenderer';
|
|
7
|
+
import ShareActions from '../../components/ShareActions';
|
|
8
|
+
import { useCurrentMessage } from '../../contexts/CurrentMessage';
|
|
9
|
+
import MessageErrorView from '../ChatOutput/MessageErrorView';
|
|
10
|
+
import MessageMetadataRenderer from '../ChatOutput/MessageMetadataRenderer';
|
|
11
|
+
const codeField = 'code';
|
|
12
|
+
export default function V0Output() {
|
|
13
|
+
var _a, _b;
|
|
14
|
+
const { message } = useCurrentMessage();
|
|
15
|
+
const objects = (_a = message.result) === null || _a === void 0 ? void 0 : _a.objects;
|
|
16
|
+
const { error } = message;
|
|
17
|
+
const isMessageLoading = (message.loading || !message.result) && !message.error;
|
|
18
|
+
return (_jsxs(Stack, { gap: 2, sx: {
|
|
19
|
+
py: 2,
|
|
20
|
+
}, children: [error && _jsx(MessageErrorView, { error: error }), isMessageLoading && (_jsx(Stack, { sx: {
|
|
21
|
+
flex: 1,
|
|
22
|
+
}, children: _jsx(Skeleton, { variant: "rectangular", sx: {
|
|
23
|
+
height: 400,
|
|
24
|
+
borderRadius: 1,
|
|
25
|
+
} }) })), objects === null || objects === void 0 ? void 0 : objects.map((item) => {
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
const code = item.data[codeField];
|
|
28
|
+
return (_jsx(Box, { flex: 1, sx: {
|
|
29
|
+
display: 'flex',
|
|
30
|
+
justifyContent: 'center',
|
|
31
|
+
alignItems: 'center',
|
|
32
|
+
}, children: _jsx(CodePreview, { code: code }) }));
|
|
33
|
+
}), objects === null || objects === void 0 ? void 0 : objects.map((item) => _jsx(MessageMetadataRenderer, { object: item.data })), !isMessageLoading && ((_b = message.result) === null || _b === void 0 ? void 0 : _b.content) && (_jsx(ShareActions, { direction: "row", justifyContent: "flex-end", sx: { mt: 2 } }))] }));
|
|
34
|
+
}
|
|
35
|
+
function CodePreview({ code }) {
|
|
36
|
+
const [showCode, setShowCode] = useState(false);
|
|
37
|
+
if (!code)
|
|
38
|
+
return null;
|
|
39
|
+
return (_jsxs(Stack, { sx: {
|
|
40
|
+
flex: 1,
|
|
41
|
+
}, children: [_jsx(Box, { sx: {
|
|
42
|
+
display: 'flex',
|
|
43
|
+
justifyContent: 'flex-end',
|
|
44
|
+
}, children: _jsx(IconButton, { onClick: () => setShowCode((prev) => !prev), sx: {
|
|
45
|
+
color: 'textColor',
|
|
46
|
+
}, children: _jsx(Icon, { icon: showCode ? 'tabler:layout-sidebar' : 'tabler:code' }) }) }), _jsx(Stack, { gap: 2, sx: {
|
|
47
|
+
display: 'flex',
|
|
48
|
+
flexDirection: 'row',
|
|
49
|
+
alignItems: 'center',
|
|
50
|
+
justifyContent: 'center',
|
|
51
|
+
}, children: _jsx(Box, { sx: {
|
|
52
|
+
display: 'flex',
|
|
53
|
+
justifyContent: 'center',
|
|
54
|
+
alignItems: 'center',
|
|
55
|
+
}, children: _jsx(CustomComponentRenderer, { componentId: "mock-dev-component", dev: {
|
|
56
|
+
components: {
|
|
57
|
+
'mock-dev-component': {
|
|
58
|
+
data: {
|
|
59
|
+
id: 'mock-dev-component',
|
|
60
|
+
createdAt: '',
|
|
61
|
+
updatedAt: '',
|
|
62
|
+
renderer: {
|
|
63
|
+
type: 'react-component',
|
|
64
|
+
script: code,
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
},
|
|
69
|
+
} }) }) }), _jsx(Drawer, { anchor: "right", open: showCode, onClose: () => setShowCode(false), children: _jsx(Box, { sx: {
|
|
70
|
+
p: 2,
|
|
71
|
+
maxWidth: '40vw',
|
|
72
|
+
}, children: _jsx(MarkdownRenderer, { children: `\`\`\`typescript\n${code}\n\`\`\`` }) }) })] }));
|
|
73
|
+
}
|
|
@@ -0,0 +1,142 @@
|
|
|
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 { Box, Card, CardContent, Container, Grid, Stack, ThemeProvider, Typography, createTheme, useTheme, } from '@mui/material';
|
|
14
|
+
import dayjs from 'dayjs';
|
|
15
|
+
// import { useRuntimeState } from '@blocklet/pages-kit/builtin/async/ai-runtime';
|
|
16
|
+
// import { Icon } from 'iconify/react';
|
|
17
|
+
import { Suspense, useCallback, useEffect, useMemo, useState } from 'react';
|
|
18
|
+
import CustomComponentRenderer from '../../../../../components/CustomComponentRenderer';
|
|
19
|
+
import CurrentAgentProvider from '../../contexts/CurrentAgent';
|
|
20
|
+
import CurrentMessageProvider from '../../contexts/CurrentMessage';
|
|
21
|
+
import useAppearances from '../../hooks/use-appearances';
|
|
22
|
+
import { useRuntimeState } from '../../state/runtime';
|
|
23
|
+
import { useSessionState } from '../../state/session';
|
|
24
|
+
const getLineClamp = (count) => {
|
|
25
|
+
return {
|
|
26
|
+
display: '-webkit-box',
|
|
27
|
+
WebkitLineClamp: count,
|
|
28
|
+
WebkitBoxOrient: 'vertical',
|
|
29
|
+
overflow: 'hidden',
|
|
30
|
+
textOverflow: 'ellipsis',
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
function V0Page({ textColor = '#333', primaryColor }) {
|
|
34
|
+
var _a;
|
|
35
|
+
const inheritedTheme = useTheme();
|
|
36
|
+
const theme = useMemo(() => {
|
|
37
|
+
let { primary } = inheritedTheme.palette;
|
|
38
|
+
try {
|
|
39
|
+
if (primaryColor) {
|
|
40
|
+
primary = inheritedTheme.palette.augmentColor({ color: { main: primaryColor } });
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
console.error('augment primary color error', { error });
|
|
45
|
+
}
|
|
46
|
+
return createTheme(inheritedTheme, {
|
|
47
|
+
palette: { primary, textColor },
|
|
48
|
+
shape: {
|
|
49
|
+
borderRadius: 8,
|
|
50
|
+
},
|
|
51
|
+
});
|
|
52
|
+
}, [inheritedTheme, primaryColor, textColor]);
|
|
53
|
+
const [sessionId] = useState('1');
|
|
54
|
+
const [message, setMessage] = useState();
|
|
55
|
+
const { childAgentId } = useRuntimeState();
|
|
56
|
+
const messagesList = useSessionState({
|
|
57
|
+
autoLoad: true,
|
|
58
|
+
})((s) => s.messages);
|
|
59
|
+
useEffect(() => {
|
|
60
|
+
if (messagesList === null || messagesList === void 0 ? void 0 : messagesList.length) {
|
|
61
|
+
const lastMessage = messagesList[messagesList.length - 1];
|
|
62
|
+
// @ts-ignore
|
|
63
|
+
setMessage(lastMessage);
|
|
64
|
+
}
|
|
65
|
+
}, [messagesList]);
|
|
66
|
+
const SliderRender = useCallback(({ message }) => {
|
|
67
|
+
// if is detail, return output
|
|
68
|
+
if (sessionId && (messagesList === null || messagesList === void 0 ? void 0 : messagesList.length)) {
|
|
69
|
+
return (_jsx(Box, { sx: {
|
|
70
|
+
width: 200,
|
|
71
|
+
p: 2,
|
|
72
|
+
position: 'sticky',
|
|
73
|
+
top: 64,
|
|
74
|
+
height: 'calc(100vh - 65px)',
|
|
75
|
+
overflowY: 'auto',
|
|
76
|
+
}, children: _jsx(Stack, { spacing: 2, justifyContent: "center", children: messagesList === null || messagesList === void 0 ? void 0 : messagesList.map((_, i) => {
|
|
77
|
+
var _a;
|
|
78
|
+
const isCurrent = _.taskId === (message === null || message === void 0 ? void 0 : message.taskId);
|
|
79
|
+
return (_jsxs(Box, { onClick: () => {
|
|
80
|
+
// @ts-ignore
|
|
81
|
+
setMessage(_);
|
|
82
|
+
}, sx: {
|
|
83
|
+
cursor: 'pointer',
|
|
84
|
+
backgroundColor: isCurrent ? 'primary.main' : 'rgba(0, 0, 0, 0.5)',
|
|
85
|
+
color: '#fff',
|
|
86
|
+
borderRadius: 1,
|
|
87
|
+
p: 1,
|
|
88
|
+
}, children: [_jsx(Typography, { variant: "caption", display: "block", sx: Object.assign({ color: 'rgba(255, 255, 255, 0.9)' }, getLineClamp(2)), children: (_a = _.parameters) === null || _a === void 0 ? void 0 : _a.question }), _jsx(Box, { children: _jsxs(Typography, { sx: {
|
|
89
|
+
textAlign: 'right',
|
|
90
|
+
fontWeight: 600,
|
|
91
|
+
fontSize: 12,
|
|
92
|
+
mt: 0.5,
|
|
93
|
+
display: 'flex',
|
|
94
|
+
justifyContent: 'space-between',
|
|
95
|
+
}, children: [_jsx("span", { style: {
|
|
96
|
+
color: 'rgba(255, 255, 255, 0.7)',
|
|
97
|
+
fontWeight: 400,
|
|
98
|
+
}, children: dayjs(_.updatedAt).format('MM-DD HH:mm') }), _jsx("span", { children: `V${i}` })] }) })] }, _.assistantId));
|
|
99
|
+
}) }) }, "slider"));
|
|
100
|
+
}
|
|
101
|
+
return null;
|
|
102
|
+
}, [JSON.stringify(messagesList)]);
|
|
103
|
+
const ContentRender = useCallback(() => {
|
|
104
|
+
// if is detail, return output
|
|
105
|
+
if (sessionId) {
|
|
106
|
+
return (_jsx(Box, { flex: 1, children: _jsx(AgentOutputRender, { message: message }) }));
|
|
107
|
+
}
|
|
108
|
+
return (_jsx(Box, { flex: 1, children: _jsx(Grid, { container: true, spacing: 2, justifyContent: "center", children: [...Array(3)].map((_, i) => (_jsx(Grid, { item: true, xs: 12, sm: 6, md: 4, children: _jsx(Card, { sx: { backgroundColor: 'rgba(0, 0, 0, 0.5)', color: '#fff' }, children: _jsxs(CardContent, { children: [_jsx(Typography, { variant: "body2", sx: { mb: 1 }, children: `Code Snippet ${i + 1}` }), _jsx(Typography, { variant: "caption", display: "block", sx: { color: 'rgba(255, 255, 255, 0.7)' }, children: `This is history requirement ${i + 1}` })] }) }) }, i))) }) }));
|
|
109
|
+
}, [JSON.stringify(message)]);
|
|
110
|
+
return (_jsx(ThemeProvider, { theme: theme, children: _jsx(CurrentAgentProvider, { agentId: childAgentId, children: _jsxs(Box, { sx: {
|
|
111
|
+
display: 'flex',
|
|
112
|
+
// background: 'linear-gradient(135deg, #1a237e 0%, #3c3f41 100%)',
|
|
113
|
+
}, children: [_jsx(SliderRender, { message: message }), _jsxs(Container, { sx: {
|
|
114
|
+
minHeight: 'calc(100vh - 64px - 1px)',
|
|
115
|
+
textAlign: 'center',
|
|
116
|
+
py: 2,
|
|
117
|
+
pt: 10,
|
|
118
|
+
gap: 2,
|
|
119
|
+
display: 'flex',
|
|
120
|
+
flexDirection: 'column',
|
|
121
|
+
}, children: [_jsx(Typography, { variant: "h2", color: "textColor", sx: { fontWeight: 'bold' }, children: "AIGNE V0" }), _jsx(Typography, { variant: "h5", color: "textColor", sx: Object.assign({}, getLineClamp(5)), children: ((_a = message === null || message === void 0 ? void 0 : message.parameters) === null || _a === void 0 ? void 0 : _a.question) || 'A v0 release to help you build code quickly' }), _jsx(ContentRender, {}), _jsx(Box, { sx: {
|
|
122
|
+
position: 'sticky',
|
|
123
|
+
bottom: 0,
|
|
124
|
+
backgroundColor: 'white',
|
|
125
|
+
pt: 4,
|
|
126
|
+
}, children: _jsx(AgentInputRender, {}) })] })] }) }) }));
|
|
127
|
+
}
|
|
128
|
+
export default V0Page;
|
|
129
|
+
function AgentInputRender(_a) {
|
|
130
|
+
var props = __rest(_a, []);
|
|
131
|
+
const { appearanceInput } = useAppearances();
|
|
132
|
+
if (!(appearanceInput === null || appearanceInput === void 0 ? void 0 : appearanceInput.componentId))
|
|
133
|
+
return null;
|
|
134
|
+
return (_jsx(Suspense, { children: _jsx(CustomComponentRenderer, Object.assign({ componentId: appearanceInput.componentId, properties: appearanceInput.componentProps }, props)) }));
|
|
135
|
+
}
|
|
136
|
+
function AgentOutputRender(_a) {
|
|
137
|
+
var { message } = _a, props = __rest(_a, ["message"]);
|
|
138
|
+
const { appearanceOutput } = useAppearances();
|
|
139
|
+
if (!(appearanceOutput === null || appearanceOutput === void 0 ? void 0 : appearanceOutput.componentId) || !message)
|
|
140
|
+
return null;
|
|
141
|
+
return (_jsx(CurrentAgentProvider, { agentId: message.assistantId, children: _jsx(CurrentMessageProvider, { message: message, children: _jsx(Suspense, { children: _jsx(CustomComponentRenderer, Object.assign({ componentId: appearanceOutput.componentId, properties: appearanceOutput.componentProps }, props)) }) }) }));
|
|
142
|
+
}
|
|
@@ -39,13 +39,9 @@ export function useRuntimeState() {
|
|
|
39
39
|
}
|
|
40
40
|
return exec(Object.assign(Object.assign({}, args), { working }));
|
|
41
41
|
}), [authSession.user, exec, working, login]);
|
|
42
|
-
const appearancePage = useMemo(() => {
|
|
43
|
-
var _a, _b;
|
|
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;
|
|
45
|
-
}, [agent]);
|
|
46
42
|
const childAgentId = useMemo(() => {
|
|
47
43
|
var _a, _b, _c, _d, _e, _f;
|
|
48
44
|
return ((_f = (_e = (_d = (_c = (_b = (_a = agent.outputVariables) === null || _a === void 0 ? void 0 : _a.find((i) => i.name === RuntimeOutputVariable.children)) === null || _b === void 0 ? void 0 : _b.initialValue) === null || _c === void 0 ? void 0 : _c.agents) === null || _d === void 0 ? void 0 : _d[0]) === null || _e === void 0 ? void 0 : _e.id) !== null && _f !== void 0 ? _f : agent.id);
|
|
49
45
|
}, [agent]);
|
|
50
|
-
return { aid, working, agent,
|
|
46
|
+
return { aid, working, agent, childAgentId, execute };
|
|
51
47
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { Alert, AlertTitle, Autocomplete, Avatar, Box, Button, ButtonGroup, Card, CardActionArea, CardActions, CardContent, CardHeader, CardMedia, CircularProgress, ClickAwayListener, Collapse, Container, Dialog, DialogActions, DialogContent, DialogTitle, Divider, Fade, GlobalStyles, Grid, Grow, LinearProgress, Link, List, ListItem, ListItemAvatar, ListItemButton, ListItemIcon, ListItemSecondaryAction, ListSubheader, Menu, MenuItem, MenuList, Paper, Popper, Slide, Stack, Switch, TextField, ThemeProvider, Tooltip, Typography, Zoom, alpha, createTheme, styled, useMediaQuery, useTheme, } from '@mui/material';
|
|
1
|
+
export { Alert, AlertTitle, Autocomplete, Avatar, Box, Button, IconButton, ButtonGroup, Card, CardActionArea, CardActions, CardContent, CardHeader, CardMedia, CircularProgress, ClickAwayListener, Collapse, Container, Dialog, DialogActions, DialogContent, DialogTitle, Divider, Fade, GlobalStyles, Grid, Grow, LinearProgress, Link, List, ListItem, ListItemAvatar, ListItemButton, ListItemIcon, ListItemSecondaryAction, ListSubheader, Menu, MenuItem, MenuList, Paper, Popper, Slide, Stack, Switch, TextField, ThemeProvider, Tooltip, Typography, Zoom, alpha, createTheme, styled, useMediaQuery, useTheme, } from '@mui/material';
|