@difizen/magent-au
Version:
201 lines • 14 kB
JavaScript
var _dec, _dec2, _dec3, _class, _class2, _descriptor;
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
function _initializerDefineProperty(target, property, descriptor, context) { if (!descriptor) return; Object.defineProperty(target, property, { enumerable: descriptor.enumerable, configurable: descriptor.configurable, writable: descriptor.writable, value: descriptor.initializer ? descriptor.initializer.call(context) : void 0 }); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) { var desc = {}; Object.keys(descriptor).forEach(function (key) { desc[key] = descriptor[key]; }); desc.enumerable = !!desc.enumerable; desc.configurable = !!desc.configurable; if ('value' in desc || desc.initializer) { desc.writable = true; } desc = decorators.slice().reverse().reduce(function (desc, decorator) { return decorator(target, property, desc) || desc; }, desc); if (context && desc.initializer !== void 0) { desc.value = desc.initializer ? desc.initializer.call(context) : void 0; desc.initializer = undefined; } if (desc.initializer === void 0) { Object.defineProperty(target, property, desc); desc = null; } return desc; }
function _initializerWarningHelper(descriptor, context) { throw new Error('Decorating class property failed. Please ensure that ' + 'transform-class-properties is enabled and runs after the decorators transform.'); }
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread 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 _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
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 ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
import { LoadingOutlined, SaveOutlined } from '@ant-design/icons';
import { BaseView, ViewInstance, inject, prop, useInject, view, ViewOption, transient, ModalService } from '@difizen/mana-app';
import { Button, Flex, message } from 'antd';
import { forwardRef } from 'react';
import { AgentManager } from "../../agent/agent-manager.js";
import { KnowledgeIcon } from "../../knowledge/knowledge-icon.js";
import { ModelSelector } from "../../model/model-selector/index.js";
import { ToolIcon } from "../../tool/icon/index.js";
import { ToolsModalId } from "../../tool/protocol.js";
import { CharacterSetting } from "./components/character-setting/index.js";
import { ConfigList } from "./components/config-selector/index.js";
import { KnowledgeModal } from "./knowledge-modal/modal.js";
import "./index.less";
import { jsx as _jsx } from "react/jsx-runtime";
import { jsxs as _jsxs } from "react/jsx-runtime";
var viewId = 'magent-dev-config';
var AgentConfigViewComponent = /*#__PURE__*/forwardRef(function AgentConfigViewComponent(props, ref) {
var _agent$llm;
var instance = useInject(ViewInstance);
var modalService = useInject(ModalService);
var agent = instance.agent;
return /*#__PURE__*/_jsxs("div", {
ref: ref,
className: viewId,
children: [/*#__PURE__*/_jsxs(Flex, {
className: "".concat(viewId, "-header"),
align: "center",
justify: 'space-between',
children: [/*#__PURE__*/_jsx("h3", {
children: "\u7F16\u6392"
}), /*#__PURE__*/_jsx(Button, {
type: "text",
className: "".concat(viewId, "-header-save"),
onClick: function onClick() {
return agent.save().then(function (saved) {
if (saved) {
message.success('保存成功');
}
agent.fetchInfo(undefined, true);
return;
});
},
icon: agent.saving ? /*#__PURE__*/_jsx(LoadingOutlined, {}) : /*#__PURE__*/_jsx(SaveOutlined, {})
})]
}), /*#__PURE__*/_jsxs("div", {
className: "".concat(viewId, "-content"),
children: [/*#__PURE__*/_jsx("div", {
className: "".concat(viewId, "-content-left"),
children: /*#__PURE__*/_jsx(CharacterSetting, {})
}), /*#__PURE__*/_jsxs("div", {
className: "".concat(viewId, "-content-right"),
children: [/*#__PURE__*/_jsxs("div", {
className: "".concat(viewId, "-content-model"),
children: [/*#__PURE__*/_jsx("div", {
className: "".concat(viewId, "-content-model-title"),
children: "\u6A21\u578B"
}), /*#__PURE__*/_jsx(ModelSelector, {
value: agent.llm,
onChange: (_agent$llm = agent.llm) === null || _agent$llm === void 0 ? void 0 : _agent$llm.updateMeta
})]
}), /*#__PURE__*/_jsx(ConfigList, {
selector: [{
key: 'tool',
title: '能力',
options: agent.tool.map(function (item) {
return _objectSpread(_objectSpread({}, item), {}, {
description: item.description || '',
icon: /*#__PURE__*/_jsx(ToolIcon, {
data: item
})
});
}),
onAdd: function onAdd() {
if (agent) {
modalService.openModal(ToolsModalId, {
dataProvider: agent,
expandAll: true,
onChange: function onChange(val) {
agent.tool = val;
}
});
}
},
onDelete: function onDelete(item) {
if (!agent) {
return;
}
agent.tool = agent.tool.filter(function (i) {
return i.id !== item.id;
});
}
}, {
key: 'knowledge',
title: '知识',
options: (agent.knowledge || []).map(function (item) {
return _objectSpread(_objectSpread({}, item), {}, {
icon: /*#__PURE__*/_jsx(KnowledgeIcon, {
data: item
})
});
}),
onAdd: function onAdd() {
if (agent) {
modalService.openModal(KnowledgeModal, {
dataProvider: agent,
onChange: function onChange(knowledges) {
agent.knowledge = _toConsumableArray(knowledges);
}
});
}
},
onDelete: function onDelete(item) {
if (!agent || !agent.knowledge) {
return;
}
agent.knowledge = agent.knowledge.filter(function (i) {
return i.id !== item.id;
});
}
}]
})]
})]
})]
});
});
export var AgentConfigView = (_dec = transient(), _dec2 = view(viewId), _dec3 = prop(), _dec(_class = _dec2(_class = (_class2 = /*#__PURE__*/function (_BaseView) {
_inherits(AgentConfigView, _BaseView);
var _super = _createSuper(AgentConfigView);
function AgentConfigView(option, agentManager) {
var _this;
_classCallCheck(this, AgentConfigView);
_this = _super.call(this);
_this.agentId = void 0;
_this.view = AgentConfigViewComponent;
_initializerDefineProperty(_this, "agent", _descriptor, _assertThisInitialized(_this));
_this.agentManager = void 0;
_this.initAgent = function () {
var agentId = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _this.agentId;
if (agentId) {
var agent = _this.agentManager.getOrCreate({
id: agentId
});
agent.fetchInfo();
_this.agent = agent;
return agent;
}
return undefined;
};
_this.agentId = option.agentId;
_this.agentManager = agentManager;
_this.initAgent(option.agentId);
return _this;
}
AgentConfigView = inject(AgentManager)(AgentConfigView, undefined, 1) || AgentConfigView;
AgentConfigView = inject(ViewOption)(AgentConfigView, undefined, 0) || AgentConfigView;
_createClass(AgentConfigView, [{
key: "modelOptions",
get: function get() {
var _this$agent;
// TODO 大模型optios列表和对应存取值要怎么取?
return ((_this$agent = this.agent) === null || _this$agent === void 0 || (_this$agent = _this$agent.llm) === null || _this$agent === void 0 || (_this$agent = _this$agent.models) === null || _this$agent === void 0 ? void 0 : _this$agent.map(function (item) {
return {
label: item,
value: item
};
})) || [];
}
}]);
return AgentConfigView;
}(BaseView), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "agent", [_dec3], {
configurable: true,
enumerable: true,
writable: true,
initializer: null
})), _class2)) || _class) || _class);