@difizen/magent-au
Version:
160 lines • 6.73 kB
JavaScript
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
import { ContactsTwoTone, HighlightTwoTone, ScheduleTwoTone, SoundTwoTone } from '@ant-design/icons';
import { PromptEditor } from '@difizen/ai-flow';
import { useInject, ViewInstance } from '@difizen/mana-app';
import { Collapse } from 'antd';
import { memo, useEffect, useState } from 'react';
import "./index.less";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var clsPrefix = 'character-settings';
export var CharacterSetting = /*#__PURE__*/memo(function CharacterSetting() {
var instance = useInject(ViewInstance);
var agent = instance.agent;
var prompt = agent.prompt;
var items = prompt ? [{
key: 'introduction',
label: /*#__PURE__*/_jsxs("div", {
className: "".concat(clsPrefix, "-label"),
children: [/*#__PURE__*/_jsx(ContactsTwoTone, {
style: {
marginRight: 8
}
}), "\u4EBA\u8BBE"]
}),
children: /*#__PURE__*/_jsx("div", {
className: "".concat(clsPrefix, "-body"),
children: /*#__PURE__*/_jsx(PromptEditor, {
placeholder: "\u8BF7\u8F93\u5165\u4EBA\u8BBE",
className: "".concat(clsPrefix, "-textarea"),
value: prompt === null || prompt === void 0 ? void 0 : prompt.introduction,
onChange: function onChange(value) {
if (prompt) {
prompt.introduction = value;
}
},
variableBlock: {
show: true,
variables: []
}
})
})
}, {
key: 'target',
label: /*#__PURE__*/_jsxs("div", {
className: "".concat(clsPrefix, "-label"),
children: [/*#__PURE__*/_jsx(ScheduleTwoTone, {
style: {
marginRight: 8
}
}), "\u76EE\u6807"]
}),
children: /*#__PURE__*/_jsx("div", {
className: "".concat(clsPrefix, "-body"),
children: /*#__PURE__*/_jsx(PromptEditor, {
placeholder: "\u8BF7\u8F93\u5165\u76EE\u6807",
className: "".concat(clsPrefix, "-textarea"),
value: prompt === null || prompt === void 0 ? void 0 : prompt.target,
onChange: function onChange(value) {
if (prompt) {
prompt.target = value;
}
},
variableBlock: {
show: true,
variables: []
}
})
})
}, {
key: 'instruction',
label: /*#__PURE__*/_jsxs("div", {
className: "".concat(clsPrefix, "-label"),
children: [/*#__PURE__*/_jsx(HighlightTwoTone, {
style: {
marginRight: 8
}
}), "\u8981\u6C42"]
}),
children: /*#__PURE__*/_jsx("div", {
className: "".concat(clsPrefix, "-body"),
children: /*#__PURE__*/_jsx(PromptEditor, {
placeholder: "\u8BF7\u8F93\u5165\u8981\u6C42",
className: "".concat(clsPrefix, "-textarea"),
value: prompt === null || prompt === void 0 ? void 0 : prompt.instruction,
onChange: function onChange(value) {
if (prompt) {
prompt.instruction = value;
}
},
variableBlock: {
show: true,
variables: []
}
})
})
}] : [];
items.push({
key: 'openingSpeech',
label: /*#__PURE__*/_jsxs("div", {
className: "".concat(clsPrefix, "-label"),
children: [/*#__PURE__*/_jsx(SoundTwoTone, {
style: {
marginRight: 8
}
}), "\u5F00\u573A\u767D"]
}),
children: /*#__PURE__*/_jsx("div", {
className: "".concat(clsPrefix, "-body"),
children: /*#__PURE__*/_jsx(PromptEditor, {
placeholder: "\u8BF7\u8F93\u5165\u5F00\u573A\u767D",
className: "".concat(clsPrefix, "-textarea"),
value: agent.openingSpeech,
onChange: function onChange(value) {
agent.openingSpeech = value;
},
variableBlock: {
show: true,
variables: []
}
})
})
});
var _useState = useState([]),
_useState2 = _slicedToArray(_useState, 2),
activeKey = _useState2[0],
setActiveKey = _useState2[1];
useEffect(function () {
var keys = [];
if ((prompt === null || prompt === void 0 ? void 0 : prompt.introduction) !== undefined) {
keys.push('introduction');
}
if ((prompt === null || prompt === void 0 ? void 0 : prompt.target) !== undefined) {
keys.push('target');
}
if ((prompt === null || prompt === void 0 ? void 0 : prompt.instruction) !== undefined) {
keys.push('instruction');
}
if (agent.openingSpeech !== undefined) {
keys.push('openingSpeech');
}
setActiveKey(keys);
}, [prompt === null || prompt === void 0 ? void 0 : prompt.introduction, prompt === null || prompt === void 0 ? void 0 : prompt.target, prompt === null || prompt === void 0 ? void 0 : prompt.instruction, agent.openingSpeech]);
return /*#__PURE__*/_jsx("div", {
className: "".concat(clsPrefix, "-container"),
children: /*#__PURE__*/_jsx(Collapse, {
className: "".concat(clsPrefix, "-container-collapse"),
activeKey: activeKey,
ghost: true,
items: items,
onChange: function onChange(key) {
return setActiveKey(typeof key === 'string' ? [key] : key);
}
})
});
});