@blocklet/pages-kit 0.2.340 → 0.2.342
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/api/agent.js +3 -5
- package/lib/cjs/builtin/async/ai-runtime/api/message.js +2 -4
- package/lib/cjs/builtin/async/ai-runtime/api/request.js +5 -1
- package/lib/cjs/builtin/async/ai-runtime/api/{subscription.js → secret.js} +7 -15
- package/lib/cjs/builtin/async/ai-runtime/api/session.js +9 -10
- package/lib/cjs/builtin/async/ai-runtime/components/AgentErrorBoundary.js +27 -0
- package/lib/cjs/builtin/async/ai-runtime/components/AgentSettings/AgentSettingsDialog.js +80 -0
- package/lib/cjs/builtin/async/ai-runtime/components/PopperMenuButton/LoadingMenuItem.js +1 -1
- package/lib/cjs/builtin/async/ai-runtime/components/ShareActions/index.js +10 -10
- package/lib/cjs/builtin/async/ai-runtime/constants.js +2 -1
- package/lib/cjs/builtin/async/ai-runtime/contexts/CurrentAgent.js +2 -2
- package/lib/cjs/builtin/async/ai-runtime/contexts/Runtime.js +4 -3
- package/lib/cjs/builtin/async/ai-runtime/hooks/use-agent-admin.js +11 -0
- package/lib/cjs/builtin/async/ai-runtime/hooks/use-header-menu.js +10 -2
- package/lib/cjs/builtin/async/ai-runtime/locales/index.js +4 -0
- package/lib/cjs/builtin/async/ai-runtime/runtime/Runtime/index.js +5 -4
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/AutoForm/index.js +26 -57
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageItemView.js +10 -19
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/ChatOutput/index.js +2 -2
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchRelatedQuestionsView.js +1 -1
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +3 -3
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/PhotoGalleryItem/index.js +5 -5
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/MessageView.js +5 -4
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/MessagesView.js +1 -1
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleChat/UserMessageView.js +2 -2
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimpleOutput/index.js +5 -4
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +2 -2
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/SuggestedQuestionsView/index.js +2 -2
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Input.js +1 -1
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Output.js +5 -5
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/Page.js +7 -7
- package/lib/cjs/builtin/async/ai-runtime/runtime-components/V0/components/CodePreview.js +8 -8
- package/lib/cjs/builtin/async/ai-runtime/state/agent.js +7 -8
- package/lib/cjs/builtin/async/ai-runtime/state/runtime.js +5 -5
- package/lib/cjs/builtin/async/ai-runtime/state/session.js +15 -17
- package/lib/cjs/builtin/page/header.js +3 -3
- package/lib/cjs/components/CustomComponentRenderer/index.js +1 -1
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/builtin/async/ai-runtime/api/agent.js +4 -6
- package/lib/esm/builtin/async/ai-runtime/api/message.js +3 -5
- package/lib/esm/builtin/async/ai-runtime/api/request.js +3 -0
- package/lib/esm/builtin/async/ai-runtime/api/{subscription.js → secret.js} +7 -14
- package/lib/esm/builtin/async/ai-runtime/api/session.js +10 -11
- package/lib/esm/builtin/async/ai-runtime/components/AgentErrorBoundary.js +22 -0
- package/lib/esm/builtin/async/ai-runtime/components/AgentSettings/AgentSettingsDialog.js +76 -0
- package/lib/esm/builtin/async/ai-runtime/components/PopperMenuButton/LoadingMenuItem.js +1 -1
- package/lib/esm/builtin/async/ai-runtime/components/ShareActions/index.js +10 -10
- package/lib/esm/builtin/async/ai-runtime/constants.js +1 -0
- package/lib/esm/builtin/async/ai-runtime/contexts/CurrentAgent.js +2 -2
- package/lib/esm/builtin/async/ai-runtime/contexts/Runtime.js +4 -3
- package/lib/esm/builtin/async/ai-runtime/hooks/use-agent-admin.js +7 -0
- package/lib/esm/builtin/async/ai-runtime/hooks/use-header-menu.js +11 -3
- package/lib/esm/builtin/async/ai-runtime/locales/index.js +4 -0
- package/lib/esm/builtin/async/ai-runtime/runtime/Runtime/index.js +5 -4
- package/lib/esm/builtin/async/ai-runtime/runtime-components/AutoForm/index.js +27 -58
- package/lib/esm/builtin/async/ai-runtime/runtime-components/ChatOutput/MessageItemView.js +10 -19
- package/lib/esm/builtin/async/ai-runtime/runtime-components/ChatOutput/index.js +2 -2
- package/lib/esm/builtin/async/ai-runtime/runtime-components/GoogleSearch/GoogleSearchRelatedQuestionsView.js +1 -1
- package/lib/esm/builtin/async/ai-runtime/runtime-components/PhotoGallery/index.js +3 -3
- package/lib/esm/builtin/async/ai-runtime/runtime-components/PhotoGalleryItem/index.js +5 -5
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/MessageView.js +5 -4
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/MessagesView.js +1 -1
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleChat/UserMessageView.js +2 -2
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimpleOutput/index.js +5 -4
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SimplePage/index.js +2 -2
- package/lib/esm/builtin/async/ai-runtime/runtime-components/SuggestedQuestionsView/index.js +2 -2
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Input.js +1 -1
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Output.js +5 -5
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/Page.js +7 -7
- package/lib/esm/builtin/async/ai-runtime/runtime-components/V0/components/CodePreview.js +8 -8
- package/lib/esm/builtin/async/ai-runtime/state/agent.js +6 -6
- package/lib/esm/builtin/async/ai-runtime/state/runtime.js +5 -5
- package/lib/esm/builtin/async/ai-runtime/state/session.js +15 -17
- package/lib/esm/builtin/page/header.js +3 -3
- package/lib/esm/components/CustomComponentRenderer/BlockletReactComponentRenderer.js +1 -1
- package/lib/esm/components/CustomComponentRenderer/index.js +1 -1
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/types/builtin/async/ai-runtime/api/agent.d.ts +10 -1
- package/lib/types/builtin/async/ai-runtime/api/message.d.ts +4 -15
- package/lib/types/builtin/async/ai-runtime/api/request.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/api/secret.d.ts +12 -0
- package/lib/types/builtin/async/ai-runtime/api/session.d.ts +5 -8
- package/lib/types/builtin/async/ai-runtime/components/AgentErrorBoundary.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/components/AgentSettings/AgentSettingsDialog.d.ts +10 -0
- package/lib/types/builtin/async/ai-runtime/constants.d.ts +1 -0
- package/lib/types/builtin/async/ai-runtime/contexts/Runtime.d.ts +3 -1
- package/lib/types/builtin/async/ai-runtime/hooks/use-agent-admin.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/locales/index.d.ts +4 -0
- package/lib/types/builtin/async/ai-runtime/runtime/Runtime/index.d.ts +2 -1
- package/lib/types/builtin/async/ai-runtime/state/agent.d.ts +2 -6
- package/lib/types/builtin/async/ai-runtime/state/runtime.d.ts +2 -0
- package/lib/types/builtin/async/ai-runtime/state/session.d.ts +1 -0
- package/lib/types/builtin/page/header.d.ts +2 -2
- package/lib/types/components/CustomComponentRenderer/index.d.ts +3 -0
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -7
- package/lib/types/builtin/async/ai-runtime/api/subscription.d.ts +0 -15
|
@@ -8,14 +8,12 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import { joinURL } from 'ufo';
|
|
11
|
-
import {
|
|
12
|
-
import { AI_STUDIO_DID } from '../constants';
|
|
13
|
-
import { request } from './request';
|
|
11
|
+
import { getAIRuntimeApiPrefix, request } from './request';
|
|
14
12
|
export function getAgent(_a) {
|
|
15
|
-
return __awaiter(this, arguments, void 0, function* ({ aid, working }) {
|
|
13
|
+
return __awaiter(this, arguments, void 0, function* ({ aid, blockletDid, working, }) {
|
|
16
14
|
return request({
|
|
17
|
-
url: joinURL(
|
|
18
|
-
query: { working },
|
|
15
|
+
url: joinURL(getAIRuntimeApiPrefix(), '/api/agents', aid),
|
|
16
|
+
query: { working, blockletDid },
|
|
19
17
|
});
|
|
20
18
|
});
|
|
21
19
|
}
|
|
@@ -19,14 +19,12 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
19
19
|
return t;
|
|
20
20
|
};
|
|
21
21
|
import { joinURL } from 'ufo';
|
|
22
|
-
import {
|
|
23
|
-
import { AI_STUDIO_DID } from '../constants';
|
|
24
|
-
import { request } from './request';
|
|
22
|
+
import { getAIRuntimeApiPrefix, request } from './request';
|
|
25
23
|
export function getMessages(_a) {
|
|
26
24
|
return __awaiter(this, void 0, void 0, function* () {
|
|
27
25
|
var { sessionId } = _a, query = __rest(_a, ["sessionId"]);
|
|
28
26
|
return request({
|
|
29
|
-
url: joinURL(
|
|
27
|
+
url: joinURL(getAIRuntimeApiPrefix(), '/api/sessions', sessionId, 'messages'),
|
|
30
28
|
query,
|
|
31
29
|
});
|
|
32
30
|
});
|
|
@@ -35,7 +33,7 @@ export function deleteMessages(_a) {
|
|
|
35
33
|
return __awaiter(this, arguments, void 0, function* ({ sessionId }) {
|
|
36
34
|
yield request({
|
|
37
35
|
method: 'DELETE',
|
|
38
|
-
url: joinURL(
|
|
36
|
+
url: joinURL(getAIRuntimeApiPrefix(), '/api/sessions', sessionId, 'messages'),
|
|
39
37
|
});
|
|
40
38
|
});
|
|
41
39
|
}
|
|
@@ -20,6 +20,8 @@ var __rest = (this && this.__rest) || function (s, e) {
|
|
|
20
20
|
};
|
|
21
21
|
import { createFetch } from '@blocklet/js-sdk';
|
|
22
22
|
import { withQuery } from 'ufo';
|
|
23
|
+
import { getComponentMountPoint } from '../../../utils';
|
|
24
|
+
import { AI_RUNTIME_DID } from '../constants';
|
|
23
25
|
import { CustomError } from '../error';
|
|
24
26
|
let isDEV = false;
|
|
25
27
|
try {
|
|
@@ -29,6 +31,7 @@ try {
|
|
|
29
31
|
catch (_a) {
|
|
30
32
|
// ignore
|
|
31
33
|
}
|
|
34
|
+
export const getAIRuntimeApiPrefix = () => window.AI_RUNTIME_API_PREFIX || getComponentMountPoint(AI_RUNTIME_DID);
|
|
32
35
|
export const fetch = createFetch({}, { lazy: isDEV, lazyTime: 1000 });
|
|
33
36
|
export function request(_a) {
|
|
34
37
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -7,21 +7,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
import { joinURL
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
export function getSubscription(_a) {
|
|
15
|
-
return __awaiter(this, arguments, void 0, function* ({ aid }) {
|
|
10
|
+
import { joinURL } from 'ufo';
|
|
11
|
+
import { getAIRuntimeApiPrefix, request } from './request';
|
|
12
|
+
export function createSecrets(_a) {
|
|
13
|
+
return __awaiter(this, arguments, void 0, function* ({ input }) {
|
|
16
14
|
return request({
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
}
|
|
21
|
-
export function getRelease(_a) {
|
|
22
|
-
return __awaiter(this, arguments, void 0, function* ({ aid }) {
|
|
23
|
-
return request({
|
|
24
|
-
url: withQuery(joinURL(getComponentMountPoint(AI_STUDIO_DID), '/api/releases/by-aid'), { aid }),
|
|
15
|
+
method: 'POST',
|
|
16
|
+
url: joinURL(getAIRuntimeApiPrefix(), '/api/secrets'),
|
|
17
|
+
body: input,
|
|
25
18
|
});
|
|
26
19
|
});
|
|
27
20
|
}
|
|
@@ -22,13 +22,11 @@ var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _ar
|
|
|
22
22
|
};
|
|
23
23
|
import { joinURL } from 'ufo';
|
|
24
24
|
import { EventSourceParserStream } from '../../../stream';
|
|
25
|
-
import {
|
|
26
|
-
import { AI_STUDIO_DID } from '../constants';
|
|
27
|
-
import { fetch, request } from './request';
|
|
25
|
+
import { fetch, getAIRuntimeApiPrefix, request } from './request';
|
|
28
26
|
export function getSessions(_a) {
|
|
29
27
|
return __awaiter(this, arguments, void 0, function* ({ aid }) {
|
|
30
28
|
return request({
|
|
31
|
-
url: joinURL(
|
|
29
|
+
url: joinURL(getAIRuntimeApiPrefix(), '/api/sessions'),
|
|
32
30
|
query: { aid },
|
|
33
31
|
});
|
|
34
32
|
});
|
|
@@ -36,7 +34,7 @@ export function getSessions(_a) {
|
|
|
36
34
|
export function getSession(_a) {
|
|
37
35
|
return __awaiter(this, arguments, void 0, function* ({ sessionId }) {
|
|
38
36
|
return request({
|
|
39
|
-
url: joinURL(
|
|
37
|
+
url: joinURL(getAIRuntimeApiPrefix(), '/api/sessions', sessionId),
|
|
40
38
|
});
|
|
41
39
|
});
|
|
42
40
|
}
|
|
@@ -44,7 +42,7 @@ export function createSession(_a) {
|
|
|
44
42
|
return __awaiter(this, arguments, void 0, function* ({ aid, name, }) {
|
|
45
43
|
return request({
|
|
46
44
|
method: 'POST',
|
|
47
|
-
url: joinURL(
|
|
45
|
+
url: joinURL(getAIRuntimeApiPrefix(), '/api/sessions'),
|
|
48
46
|
body: {
|
|
49
47
|
aid,
|
|
50
48
|
name,
|
|
@@ -56,7 +54,7 @@ export function clearSession(_a) {
|
|
|
56
54
|
return __awaiter(this, arguments, void 0, function* ({ sessionId }) {
|
|
57
55
|
return request({
|
|
58
56
|
method: 'POST',
|
|
59
|
-
url: joinURL(
|
|
57
|
+
url: joinURL(getAIRuntimeApiPrefix(), '/api/sessions', sessionId, '/clear'),
|
|
60
58
|
});
|
|
61
59
|
});
|
|
62
60
|
}
|
|
@@ -64,7 +62,7 @@ export function updateSession(_a) {
|
|
|
64
62
|
return __awaiter(this, arguments, void 0, function* ({ sessionId, name, }) {
|
|
65
63
|
return request({
|
|
66
64
|
method: 'PATCH',
|
|
67
|
-
url: joinURL(
|
|
65
|
+
url: joinURL(getAIRuntimeApiPrefix(), '/api/sessions', sessionId),
|
|
68
66
|
body: { name },
|
|
69
67
|
});
|
|
70
68
|
});
|
|
@@ -73,20 +71,21 @@ export function deleteSession(_a) {
|
|
|
73
71
|
return __awaiter(this, arguments, void 0, function* ({ sessionId, }) {
|
|
74
72
|
return request({
|
|
75
73
|
method: 'DELETE',
|
|
76
|
-
url: joinURL(
|
|
74
|
+
url: joinURL(getAIRuntimeApiPrefix(), '/api/sessions', sessionId),
|
|
77
75
|
});
|
|
78
76
|
});
|
|
79
77
|
}
|
|
80
78
|
export function runAgent(_a) {
|
|
81
|
-
return __asyncGenerator(this, arguments, function* runAgent_1({ aid, sessionId, working, parameters, }) {
|
|
79
|
+
return __asyncGenerator(this, arguments, function* runAgent_1({ aid, sessionId, blockletDid, working, parameters, }) {
|
|
82
80
|
var _b;
|
|
83
|
-
const res = yield __await(fetch(joinURL(
|
|
81
|
+
const res = yield __await(fetch(joinURL(getAIRuntimeApiPrefix(), '/api/ai/call'), {
|
|
84
82
|
method: 'POST',
|
|
85
83
|
headers: {
|
|
86
84
|
'Content-Type': 'application/json',
|
|
87
85
|
Accept: 'text/event-stream',
|
|
88
86
|
},
|
|
89
87
|
body: JSON.stringify({
|
|
88
|
+
blockletDid,
|
|
90
89
|
sessionId,
|
|
91
90
|
parameters: Object.assign(Object.assign({}, parameters), { $clientTime: new Date().toISOString() }),
|
|
92
91
|
aid,
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { Alert, Button, Stack, alertClasses } from '@mui/material';
|
|
3
|
+
import { ErrorBoundary } from 'react-error-boundary';
|
|
4
|
+
import { useLocaleContext } from '../../../locale';
|
|
5
|
+
import { useIsAgentAdmin } from '../hooks/use-agent-admin';
|
|
6
|
+
import { useRuntimeState } from '../state/runtime';
|
|
7
|
+
import { settingsDialogState } from './AgentSettings/AgentSettingsDialog';
|
|
8
|
+
export default function AgentErrorBoundary() {
|
|
9
|
+
return _jsx(ErrorBoundary, { FallbackComponent: AgentErrorView });
|
|
10
|
+
}
|
|
11
|
+
export function AgentErrorView({ error }) {
|
|
12
|
+
if (error.type === 'MissingSecretError') {
|
|
13
|
+
return _jsx(MissingSecretErrorView, {});
|
|
14
|
+
}
|
|
15
|
+
return _jsx(Alert, { severity: "error", children: String(error === null || error === void 0 ? void 0 : error.message) });
|
|
16
|
+
}
|
|
17
|
+
function MissingSecretErrorView() {
|
|
18
|
+
const { t } = useLocaleContext();
|
|
19
|
+
const { agent } = useRuntimeState();
|
|
20
|
+
const isAdmin = useIsAgentAdmin(agent);
|
|
21
|
+
return (_jsx(Alert, { severity: "error", sx: { [`.${alertClasses.message}`]: { flex: 1 } }, children: _jsxs(Stack, { width: "100%", children: ["Required configuration is missing. Please complete the setup before proceeding.", isAdmin && (_jsx(Stack, { alignItems: "flex-end", children: _jsx(Button, { size: "small", variant: "outlined", onClick: () => settingsDialogState.getState().open(), children: t('setup') }) }))] }) }));
|
|
22
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
+
});
|
|
9
|
+
};
|
|
10
|
+
var __rest = (this && this.__rest) || function (s, e) {
|
|
11
|
+
var t = {};
|
|
12
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
|
|
13
|
+
t[p] = s[p];
|
|
14
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function")
|
|
15
|
+
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
16
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
|
|
17
|
+
t[p[i]] = s[p[i]];
|
|
18
|
+
}
|
|
19
|
+
return t;
|
|
20
|
+
};
|
|
21
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
22
|
+
import { LoadingButton } from '@mui/lab';
|
|
23
|
+
import { Button, Dialog, DialogActions, DialogContent, DialogTitle, FormLabel, Stack, TextField, } from '@mui/material';
|
|
24
|
+
import { useForm } from 'react-hook-form';
|
|
25
|
+
import { create } from 'zustand';
|
|
26
|
+
import { immer } from 'zustand/middleware/immer';
|
|
27
|
+
import { Toast } from '../../../../arcblock/ux';
|
|
28
|
+
import { useLocaleContext } from '../../../../locale';
|
|
29
|
+
import { createSecrets } from '../../api/secret';
|
|
30
|
+
import { useAgentState } from '../../state/agent';
|
|
31
|
+
import { useRuntimeState } from '../../state/runtime';
|
|
32
|
+
export const settingsDialogState = create()(immer((set) => ({
|
|
33
|
+
isOpen: false,
|
|
34
|
+
open() {
|
|
35
|
+
set((state) => {
|
|
36
|
+
state.isOpen = true;
|
|
37
|
+
});
|
|
38
|
+
},
|
|
39
|
+
onClose() {
|
|
40
|
+
set((state) => {
|
|
41
|
+
state.isOpen = false;
|
|
42
|
+
});
|
|
43
|
+
},
|
|
44
|
+
})));
|
|
45
|
+
export default function AgentSettingsDialog(_a) {
|
|
46
|
+
var props = __rest(_a, []);
|
|
47
|
+
const { t } = useLocaleContext();
|
|
48
|
+
const isOpen = settingsDialogState((state) => state.isOpen);
|
|
49
|
+
const onClose = settingsDialogState((state) => state.onClose);
|
|
50
|
+
const { aid, blockletDid, working } = useRuntimeState();
|
|
51
|
+
const [agent, state] = useAgentState({ aid, blockletDid, working });
|
|
52
|
+
const form = useForm({
|
|
53
|
+
defaultValues: {
|
|
54
|
+
secrets: agent.config.secrets.map((i) => ({
|
|
55
|
+
projectId: agent.project.id,
|
|
56
|
+
targetProjectId: i.targetProjectId,
|
|
57
|
+
targetAgentId: i.targetAgentId,
|
|
58
|
+
targetInputKey: i.targetInput.key,
|
|
59
|
+
secret: '',
|
|
60
|
+
})),
|
|
61
|
+
},
|
|
62
|
+
});
|
|
63
|
+
const onSubmit = (input) => __awaiter(this, void 0, void 0, function* () {
|
|
64
|
+
try {
|
|
65
|
+
yield createSecrets({ input });
|
|
66
|
+
yield state.load();
|
|
67
|
+
Toast.success(t('saved'));
|
|
68
|
+
onClose();
|
|
69
|
+
}
|
|
70
|
+
catch (error) {
|
|
71
|
+
Toast.error(error.message);
|
|
72
|
+
throw error;
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
return (_jsxs(Dialog, Object.assign({ fullWidth: true, maxWidth: "md" }, props, { open: isOpen, onClose: onClose, component: "form", onSubmit: form.handleSubmit(onSubmit), children: [_jsx(DialogTitle, { children: t('settings') }), _jsx(DialogContent, { children: _jsx(Stack, { gap: 1, children: agent.config.secrets.map(({ targetInput, hasValue }, index) => (_jsxs(Stack, { gap: 0.5, children: [_jsx(FormLabel, { children: targetInput.label || targetInput.key }), _jsx(TextField, Object.assign({ type: "password", fullWidth: true, hiddenLabel: true, size: "small", inputProps: { maxLength: 100 }, placeholder: hasValue ? '******' : targetInput.placeholder }, form.register(`secrets.${index}.secret`, { required: true })))] }, targetInput.id))) }) }), _jsxs(DialogActions, { children: [_jsx(Button, { onClick: onClose, children: t('cancel') }), _jsx(LoadingButton, { type: "submit", variant: "contained", loading: form.formState.isSubmitting, children: t('save') })] })] })));
|
|
76
|
+
}
|
|
@@ -42,5 +42,5 @@ export default function LoadingMenuItem(_a) {
|
|
|
42
42
|
setLoading(false);
|
|
43
43
|
}
|
|
44
44
|
});
|
|
45
|
-
return (_jsxs(MenuItem, Object.assign({}, props, { onClick: handleClick, sx: Object.assign(Object.assign({}, props.sx), { display: 'flex', alignItems: 'center'
|
|
45
|
+
return (_jsxs(MenuItem, Object.assign({}, props, { onClick: handleClick, sx: Object.assign(Object.assign({}, props.sx), { display: 'flex', alignItems: 'center' }), children: [(clicked && confirmation) || children, _jsx(Stack, { direction: "row", alignItems: "center", justifyContent: "flex-end", sx: { width: 18 }, children: loading && _jsx(CircularProgress, { size: 14 }) })] })));
|
|
46
46
|
}
|
|
@@ -56,11 +56,11 @@ const ShareActionsMap = {
|
|
|
56
56
|
saveAs: ShareSave,
|
|
57
57
|
};
|
|
58
58
|
function ShareTwitter() {
|
|
59
|
-
var _a, _b, _c, _d, _e, _f;
|
|
59
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
60
60
|
const { t } = useLocaleContext();
|
|
61
61
|
const { message } = useCurrentMessage();
|
|
62
|
-
const content = ((_a = message.
|
|
63
|
-
((
|
|
62
|
+
const content = ((_c = (_b = (_a = message.outputs) === null || _a === void 0 ? void 0 : _a.objects) === null || _b === void 0 ? void 0 : _b.find((i) => i === null || i === void 0 ? void 0 : i[RuntimeOutputVariable.text])) === null || _c === void 0 ? void 0 : _c[RuntimeOutputVariable.text]) ||
|
|
63
|
+
((_h = (_g = (_f = (_e = (_d = message.outputs) === null || _d === void 0 ? void 0 : _d.objects) === null || _e === void 0 ? void 0 : _e.find((i) => { var _a; return (_a = i === null || i === void 0 ? void 0 : i[RuntimeOutputVariable.images]) === null || _a === void 0 ? void 0 : _a.length; })) === null || _f === void 0 ? void 0 : _f[RuntimeOutputVariable.images]) === null || _g === void 0 ? void 0 : _g.at(0)) === null || _h === void 0 ? void 0 : _h.url);
|
|
64
64
|
if (!content)
|
|
65
65
|
return null;
|
|
66
66
|
return (_jsx(StyledActionButton, { tip: t('socialShare.shareToX'), title: _jsx(Icon, { icon: "tabler:brand-x" }), href: withQuery('https://twitter.com/intent/tweet', {
|
|
@@ -69,11 +69,11 @@ function ShareTwitter() {
|
|
|
69
69
|
}), target: '_blank' }));
|
|
70
70
|
}
|
|
71
71
|
function ShareCopy() {
|
|
72
|
-
var _a, _b, _c, _d, _e, _f;
|
|
72
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
73
73
|
const { t } = useLocaleContext();
|
|
74
74
|
const { message } = useCurrentMessage();
|
|
75
|
-
const content = (_a = message.
|
|
76
|
-
const image = (
|
|
75
|
+
const content = (_c = (_b = (_a = message.outputs) === null || _a === void 0 ? void 0 : _a.objects) === null || _b === void 0 ? void 0 : _b.find((i) => i === null || i === void 0 ? void 0 : i[RuntimeOutputVariable.text])) === null || _c === void 0 ? void 0 : _c[RuntimeOutputVariable.text];
|
|
76
|
+
const image = (_h = (_g = (_f = (_e = (_d = message.outputs) === null || _d === void 0 ? void 0 : _d.objects) === null || _e === void 0 ? void 0 : _e.find((i) => { var _a; return (_a = i === null || i === void 0 ? void 0 : i[RuntimeOutputVariable.images]) === null || _a === void 0 ? void 0 : _a.length; })) === null || _f === void 0 ? void 0 : _f[RuntimeOutputVariable.images]) === null || _g === void 0 ? void 0 : _g.at(0)) === null || _h === void 0 ? void 0 : _h.url;
|
|
77
77
|
if (!content && !image)
|
|
78
78
|
return null;
|
|
79
79
|
return (_jsx(StyledActionButton, { autoReset: true, tip: t('copy'), tipSucceed: t('copied'), title: _jsx(Icon, { icon: "tabler:copy" }), titleSucceed: _jsx(Icon, { icon: "tabler:copy-check" }), onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -87,13 +87,13 @@ function ShareCopy() {
|
|
|
87
87
|
}) }));
|
|
88
88
|
}
|
|
89
89
|
function ShareSave() {
|
|
90
|
-
var _a, _b, _c, _d, _e, _f;
|
|
90
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
91
91
|
const { t } = useLocaleContext();
|
|
92
92
|
const { message } = useCurrentMessage();
|
|
93
93
|
const { aid, agent } = useRuntimeState();
|
|
94
94
|
const profile = useProfile({ aid });
|
|
95
|
-
const content = (_a = message.
|
|
96
|
-
const image = (
|
|
95
|
+
const content = (_c = (_b = (_a = message.outputs) === null || _a === void 0 ? void 0 : _a.objects) === null || _b === void 0 ? void 0 : _b.find((i) => i === null || i === void 0 ? void 0 : i[RuntimeOutputVariable.text])) === null || _c === void 0 ? void 0 : _c[RuntimeOutputVariable.text];
|
|
96
|
+
const image = (_h = (_g = (_f = (_e = (_d = message.outputs) === null || _d === void 0 ? void 0 : _d.objects) === null || _e === void 0 ? void 0 : _e.find((i) => { var _a; return (_a = i === null || i === void 0 ? void 0 : i[RuntimeOutputVariable.images]) === null || _a === void 0 ? void 0 : _a.length; })) === null || _f === void 0 ? void 0 : _f[RuntimeOutputVariable.images]) === null || _g === void 0 ? void 0 : _g.at(0)) === null || _h === void 0 ? void 0 : _h.url;
|
|
97
97
|
if (!content && !image)
|
|
98
98
|
return null;
|
|
99
99
|
return (_jsx(StyledActionButton, { tip: t('save'), tipSucceed: t('saved'), title: _jsx(Icon, { icon: "tabler:file-download" }), titleSucceed: _jsx(Icon, { icon: "tabler:file-check" }), onClick: () => __awaiter(this, void 0, void 0, function* () {
|
|
@@ -105,7 +105,7 @@ function ShareSave() {
|
|
|
105
105
|
yield html2pdf()
|
|
106
106
|
.set({
|
|
107
107
|
margin: 1,
|
|
108
|
-
filename: `${profile.name || agent.id} - ${message.
|
|
108
|
+
filename: `${profile.name || agent.id} - ${message.id}.pdf`,
|
|
109
109
|
image: { type: 'jpeg', quality: 0.98 },
|
|
110
110
|
html2canvas: { scale: 2 },
|
|
111
111
|
jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' },
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { RuntimeOutputVariable } from '@blocklet/ai-runtime/types';
|
|
2
2
|
export const AI_STUDIO_DID = 'z8iZpog7mcgcgBZzTiXJCWESvmnRrQmnd3XBB';
|
|
3
|
+
export const AI_RUNTIME_DID = 'z2qa5vnwATPJyAnBYm7SbLMMjfeXJgeBKkfMG';
|
|
3
4
|
export const PAYMENT_KIT_DID = 'z2qaCNvKMv5GjouKdcDWexv6WqtHbpNPQDnAk';
|
|
4
5
|
export const DEFAULT_PAGE_COMPONENT_ID = 'ctnxha29uu8cx4xv'; // Simple Layout
|
|
5
6
|
export const DEFAULT_INPUT_COMPONENT_ID = '1wwtemqcdio6nqf0'; // Auto Form
|
|
@@ -15,7 +15,7 @@ export default function CurrentAgentProvider({ agentId, children }) {
|
|
|
15
15
|
return _jsx(context.Provider, { value: state, children: children });
|
|
16
16
|
}
|
|
17
17
|
export function useCurrentAgent(args = {}) {
|
|
18
|
-
const { aid: runtimeAid, working } = useRuntimeState();
|
|
18
|
+
const { blockletDid, aid: runtimeAid, working } = useRuntimeState();
|
|
19
19
|
const aidFromParam = useMemo(() => args.aid ||
|
|
20
20
|
(args.agentId
|
|
21
21
|
? stringifyIdentity(Object.assign(Object.assign({}, parseIdentity(runtimeAid, { rejectWhenError: true })), { assistantId: args.agentId }))
|
|
@@ -25,6 +25,6 @@ export function useCurrentAgent(args = {}) {
|
|
|
25
25
|
if (!aid) {
|
|
26
26
|
throw new Error('No such current agent state. You should use `useCurrentAgent` within the `CurrentAgentProvider`');
|
|
27
27
|
}
|
|
28
|
-
const [agent] = useAgentState({ aid, working });
|
|
28
|
+
const [agent] = useAgentState({ blockletDid, aid, working });
|
|
29
29
|
return { aid, agent };
|
|
30
30
|
}
|
|
@@ -10,17 +10,18 @@ export function useRuntimeContext() {
|
|
|
10
10
|
}
|
|
11
11
|
return context;
|
|
12
12
|
}
|
|
13
|
-
export default function RuntimeProvider({ aid, working, children, }) {
|
|
13
|
+
export default function RuntimeProvider({ blockletDid, aid, working, children, }) {
|
|
14
14
|
if (!aid)
|
|
15
15
|
throw new Error('Missing required props `aid`');
|
|
16
|
-
const value = useMemo(() => ({ aid, working }), [aid, working]);
|
|
16
|
+
const value = useMemo(() => ({ blockletDid, aid, working }), [blockletDid, aid, working]);
|
|
17
17
|
return _jsx(runtimeContext.Provider, { value: value, children: children });
|
|
18
18
|
}
|
|
19
19
|
export function RuntimeProviderFromUrl({ children }) {
|
|
20
20
|
const [query] = useSearchParams();
|
|
21
21
|
const aid = query.get('aid');
|
|
22
|
+
const blockletDid = query.get('blockletDid') || undefined;
|
|
22
23
|
const working = query.get('working') === 'true';
|
|
23
24
|
if (!aid)
|
|
24
25
|
throw new CustomError(404, 'Missing required query parameters `aid`');
|
|
25
|
-
return (_jsx(RuntimeProvider, { aid: aid, working: working, children: children }));
|
|
26
|
+
return (_jsx(RuntimeProvider, { blockletDid: blockletDid, aid: aid, working: working, children: children }));
|
|
26
27
|
}
|
|
@@ -9,23 +9,31 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
11
|
import { Icon } from '@iconify/react';
|
|
12
|
-
import { IconButton, ListItemIcon } from '@mui/material';
|
|
12
|
+
import { IconButton, ListItemIcon, MenuItem } from '@mui/material';
|
|
13
13
|
import { useLocaleContext } from '../../../locale';
|
|
14
14
|
import { useHeader } from '../../../page/header';
|
|
15
|
+
import { settingsDialogState } from '../components/AgentSettings/AgentSettingsDialog';
|
|
15
16
|
import PopperMenuButton from '../components/PopperMenuButton';
|
|
16
17
|
import LoadingMenuItem from '../components/PopperMenuButton/LoadingMenuItem';
|
|
17
18
|
import { useComponentPreferences } from '../contexts/ComponentPreferences';
|
|
19
|
+
import { useRuntimeState } from '../state/runtime';
|
|
18
20
|
import { useSessionState } from '../state/session';
|
|
21
|
+
import { useIsAgentAdmin } from './use-agent-admin';
|
|
19
22
|
export function useHeaderMenu() {
|
|
20
23
|
var _a;
|
|
21
24
|
const { t, locale } = useLocaleContext();
|
|
22
25
|
const { hideHeaderMenuButton } = (_a = useComponentPreferences()) !== null && _a !== void 0 ? _a : {};
|
|
23
26
|
const clearSession = useSessionState((s) => s.clearSession);
|
|
27
|
+
const { agent } = useRuntimeState();
|
|
28
|
+
const isAdmin = useIsAgentAdmin(agent);
|
|
24
29
|
useHeader(() => hideHeaderMenuButton
|
|
25
30
|
? {}
|
|
26
31
|
: {
|
|
27
|
-
addons: (
|
|
28
|
-
_jsx(PopperMenuButton, { component: IconButton, PopperProps: { placement: 'bottom-end', sx: { zIndex: 'appBar' } }, menus:
|
|
32
|
+
addons: (exists) => [
|
|
33
|
+
_jsx(PopperMenuButton, { component: IconButton, PopperProps: { placement: 'bottom-end', sx: { zIndex: 'appBar' } }, menus: [
|
|
34
|
+
isAdmin && (_jsxs(MenuItem, { onClick: () => settingsDialogState.getState().open(), children: [_jsx(ListItemIcon, { children: _jsx(Icon, { icon: "tabler:settings" }) }), t('settings')] }, "settings")),
|
|
35
|
+
_jsxs(LoadingMenuItem, { onClick: () => __awaiter(this, void 0, void 0, function* () { return clearSession(); }), children: [_jsx(ListItemIcon, { children: _jsx(Icon, { icon: "mingcute:broom-line" }) }), t('clearSession')] }, "clearSession"),
|
|
36
|
+
], children: _jsx(Icon, { icon: "tabler:dots" }) }),
|
|
29
37
|
...exists,
|
|
30
38
|
],
|
|
31
39
|
}, [locale, hideHeaderMenuButton]);
|
|
@@ -110,6 +110,8 @@ export const translations = {
|
|
|
110
110
|
retry: 'Try Again',
|
|
111
111
|
errorCodeTip: 'Agent found some syntax errors in the code, and want to try again...',
|
|
112
112
|
},
|
|
113
|
+
settings: 'Settings',
|
|
114
|
+
setup: 'Setup',
|
|
113
115
|
},
|
|
114
116
|
zh: {
|
|
115
117
|
by: '作者',
|
|
@@ -222,5 +224,7 @@ export const translations = {
|
|
|
222
224
|
retry: '重试',
|
|
223
225
|
errorCodeTip: 'Agent 发现代码存在一些语法问题,请求重试...',
|
|
224
226
|
},
|
|
227
|
+
settings: '设置',
|
|
228
|
+
setup: '设置',
|
|
225
229
|
},
|
|
226
230
|
};
|
|
@@ -7,6 +7,7 @@ import { Avatar, DID } from '../../../../arcblock/ux';
|
|
|
7
7
|
import { useLocaleContext } from '../../../../locale';
|
|
8
8
|
import { useHeader } from '../../../../page/header';
|
|
9
9
|
import { getComponentMountPoint } from '../../../../utils';
|
|
10
|
+
import AgentSettingsDialog from '../../components/AgentSettings/AgentSettingsDialog';
|
|
10
11
|
import RuntimeCommonProvider, { RuntimeLocaleProvider } from '../../components/RuntimeCommonProvider';
|
|
11
12
|
import SocialShare from '../../components/SocialShare';
|
|
12
13
|
import ThemeProvider from '../../components/ThemeProvider';
|
|
@@ -20,9 +21,9 @@ function AgentCreatedBy({ did }) {
|
|
|
20
21
|
const { t } = useLocaleContext();
|
|
21
22
|
return (_jsxs(_Fragment, { children: [t('by'), " ", _jsx(Box, { component: DID, did: did, copyable: false, responsive: true })] }));
|
|
22
23
|
}
|
|
23
|
-
export default function Runtime({ aid, working }) {
|
|
24
|
+
export default function Runtime({ blockletDid, aid, working, }) {
|
|
24
25
|
const children = (_jsx(ThemeProvider, { children: _jsx(ActiveAgentProvider, { children: _jsx(RuntimeView, {}) }) }));
|
|
25
|
-
return (_jsx(RuntimeCommonProvider, { children: aid ? (_jsx(RuntimeProvider, { aid: aid, working: working, children: children })) : (_jsx(RuntimeProviderFromUrl, { children: children })) }));
|
|
26
|
+
return (_jsx(RuntimeCommonProvider, { children: aid ? (_jsx(RuntimeProvider, { blockletDid: blockletDid, aid: aid, working: working, children: children })) : (_jsx(RuntimeProviderFromUrl, { children: children })) }));
|
|
26
27
|
}
|
|
27
28
|
function RuntimeView() {
|
|
28
29
|
var _a;
|
|
@@ -54,9 +55,9 @@ ${agent === null || agent === void 0 ? void 0 : agent.description}
|
|
|
54
55
|
height: 12,
|
|
55
56
|
fontSize: 12,
|
|
56
57
|
}, children: _jsx(AgentCreatedBy, { did: agent.project.createdBy }) }) })) : undefined,
|
|
57
|
-
addons: (
|
|
58
|
+
addons: (exists) => [_jsx(SocialShare, { content: shareContent }), ...exists].filter(Boolean),
|
|
58
59
|
};
|
|
59
60
|
}, [locale, isMobile, agent]);
|
|
60
61
|
const componentId = (_a = appearancePage === null || appearancePage === void 0 ? void 0 : appearancePage.componentId) !== null && _a !== void 0 ? _a : DEFAULT_PAGE_COMPONENT_ID;
|
|
61
|
-
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 })] }));
|
|
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.componentProperties }), _jsx(AgentSettingsDialog, {})] }));
|
|
62
63
|
}
|
|
@@ -9,7 +9,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
11
11
|
import { cx } from '@emotion/css';
|
|
12
|
-
import { Box, FormLabel, InputAdornment, Stack,
|
|
12
|
+
import { Box, FormLabel, InputAdornment, Stack, formLabelClasses, styled } from '@mui/material';
|
|
13
13
|
import isEmpty from 'lodash/isEmpty';
|
|
14
14
|
import omit from 'lodash/omit';
|
|
15
15
|
import { useEffect, useMemo, useState } from 'react';
|
|
@@ -34,7 +34,6 @@ export default function AutoForm({ submitText, inlineLabel, autoFillLastForm = t
|
|
|
34
34
|
});
|
|
35
35
|
}, [agent.parameters]);
|
|
36
36
|
const defaultForm = useInitialFormValues();
|
|
37
|
-
const theme = useFormTheme();
|
|
38
37
|
const form = useForm({ defaultValues: defaultForm });
|
|
39
38
|
useEffect(() => {
|
|
40
39
|
if (autoFillLastForm && !form.formState.isSubmitted && !form.formState.isSubmitting) {
|
|
@@ -51,31 +50,31 @@ export default function AutoForm({ submitText, inlineLabel, autoFillLastForm = t
|
|
|
51
50
|
},
|
|
52
51
|
});
|
|
53
52
|
});
|
|
54
|
-
return (
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
53
|
+
return (_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) => {
|
|
54
|
+
const { key, required } = parameter !== null && parameter !== void 0 ? parameter : {};
|
|
55
|
+
return (_jsx(Box, { children: _jsx(Controller, { control: form.control, name: key, rules: {
|
|
56
|
+
required,
|
|
57
|
+
min: parameter.type === 'number' && typeof parameter.min === 'number'
|
|
58
|
+
? { value: parameter.min, message: '' }
|
|
59
|
+
: undefined,
|
|
60
|
+
max: parameter.type === 'number' && typeof parameter.max === 'number'
|
|
61
|
+
? { value: parameter.max, message: '' }
|
|
62
|
+
: undefined,
|
|
63
|
+
minLength: parameter.type === 'string' && typeof parameter.minLength === 'number'
|
|
64
|
+
? { value: parameter.minLength, message: '' }
|
|
65
|
+
: undefined,
|
|
66
|
+
maxLength: parameter.type === 'string' && typeof parameter.maxLength === 'number'
|
|
67
|
+
? { value: parameter.maxLength, message: '' }
|
|
68
|
+
: undefined,
|
|
69
|
+
}, render: ({ field, fieldState }) => {
|
|
70
|
+
var _a;
|
|
71
|
+
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
|
|
72
|
+
? {
|
|
73
|
+
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: 1.5 }, children: submitText }) })),
|
|
74
|
+
}
|
|
75
|
+
: undefined })] }));
|
|
76
|
+
} }) }, parameter.id));
|
|
77
|
+
}), !(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
78
|
}
|
|
80
79
|
function useInitialFormValues() {
|
|
81
80
|
const { agent } = useCurrentAgent();
|
|
@@ -83,7 +82,7 @@ function useInitialFormValues() {
|
|
|
83
82
|
const [lastInputs, setLastInputs] = useState();
|
|
84
83
|
useEffect(() => {
|
|
85
84
|
if (!lastInputs) {
|
|
86
|
-
const lastParameters = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.
|
|
85
|
+
const lastParameters = lastMessage === null || lastMessage === void 0 ? void 0 : lastMessage.inputs;
|
|
87
86
|
if (!isEmpty(lastParameters))
|
|
88
87
|
setLastInputs(lastParameters);
|
|
89
88
|
}
|
|
@@ -96,36 +95,6 @@ function useInitialFormValues() {
|
|
|
96
95
|
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
96
|
}, [lastInputs, agent]);
|
|
98
97
|
}
|
|
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
98
|
const Form = styled(Stack)(({ theme }) => theme.unstable_sx({
|
|
130
99
|
gap: 2,
|
|
131
100
|
'.form-item': {
|