From 90bcfdb146aeb0faba65f9b424ded5bbde750161 Mon Sep 17 00:00:00 2001 From: shadowcz007 Date: Thu, 29 Jun 2023 10:51:05 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E9=87=8D=E6=9E=84=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/flow/Sidebar/index.tsx | 15 +- src/components/flow/index.tsx | 33 ++-- .../flow/nodeComponents/EmbeddingsNode.tsx | 150 ------------------ .../flow/nodeComponents/InputMergeNode.tsx | 1 + .../flow/nodeComponents/QueryInputNode.tsx | 2 +- src/components/flow/nodeComponents/index.tsx | 32 ++-- src/pages/options/index.tsx | 44 ++++- 7 files changed, 81 insertions(+), 196 deletions(-) delete mode 100644 src/components/flow/nodeComponents/EmbeddingsNode.tsx diff --git a/src/components/flow/Sidebar/index.tsx b/src/components/flow/Sidebar/index.tsx index 874461e..b0cd72e 100644 --- a/src/components/flow/Sidebar/index.tsx +++ b/src/components/flow/Sidebar/index.tsx @@ -1,10 +1,10 @@ -import React from 'react'; +import React, { useEffect } from 'react'; import { Collapse } from 'antd'; const { Panel } = Collapse; import getNodes from '../nodeComponents/index' import i18n from "i18next"; -export default () => { +export default (props: any) => { const onDragStart = (event: any, nodeType: string, dataType: string) => { event.dataTransfer.setData('application/reactflow', nodeType); event.dataTransfer.setData('application/dataType', dataType); @@ -13,7 +13,16 @@ export default () => { const onChange: any = (key: string) => { console.log(key); }; - const nodes = getNodes() + + const { newNodes } = props; + + const [nodes, setNodes] = React.useState(getNodes()); + + useEffect(() => { + console.log('sidebar newNodes:', newNodes) + if (newNodes && newNodes.length > 0) setNodes(newNodes) + }, [newNodes]) + // console.log(Array.from(nodes.filter((n: any) => n.open), n => n.title)) return ( {isLoaded ? <> - + - - {i18n.t("workflowName")} - + + {i18n.t("workflowName")} + { - const { debug, merge, loadData, isNew, saveCallback, deleteCallback, exportData } = props; + const { debug, merge, loadData, isNew, saveCallback, deleteCallback, exportData, newNodes } = props; return ( { exportData={exportData} saveCallback={saveCallback} deleteCallback={deleteCallback} + newNodes={newNodes} //自定义节点的动态开关 /> ) }; diff --git a/src/components/flow/nodeComponents/EmbeddingsNode.tsx b/src/components/flow/nodeComponents/EmbeddingsNode.tsx deleted file mode 100644 index 311cc83..0000000 --- a/src/components/flow/nodeComponents/EmbeddingsNode.tsx +++ /dev/null @@ -1,150 +0,0 @@ -import React from 'react' -import { Handle, Position } from 'reactflow'; -import { Card,Dropdown} from 'antd'; - -import {createCardTitle, createDebug, createText, nodeStyle, getI18n } from './Base' - -import i18n from "i18next"; - - - -function Main({ id, data, selected }: any) { - - // i18nInit(); - const { debugMenu, contextMenus } = getI18n(); - const [statusInputForDebug, setStatusInputForDebug] = React.useState(''); - const [debugInput, setDebugInput] = React.useState((data.merged ? JSON.stringify(data.merged, null, 2) : "")); - const [shouldRefresh, setShouldRefresh] = React.useState(true) - - // text - const [role, setRole] = React.useState(data.role); - - const updateData = (e: any) => { - // console.log(e) - let r = { ...role }; - if (e.key == 'text' || e.key == 'name' || e.key == 'avatar') { - r[e.key] = e.data; - setRole({ - ...r - }) - data.onChange({ id, data: { role: r, debugInput: "" } }); - - setShouldRefresh(true); - - }; - - if (e.key == "debug") data.onChange({ id, data: e.data }) - - if (e.key == 'draggable') data.onChange({ id, data: { draggable: e.data } }) - } - - - const createNode = (role: any, updateData: any) => { - // const items: any = Array.from(roleAvatars, (avatar: any) => { - // return { - // label: avatar.label, - // key: avatar.key, - // icon: , - // disabled: !!avatar.disabled, - // checked: avatar.key === role.avatar - // } - // }); - - // const handleMenuClick: any = (e: any) => { - // // console.log('roleAvatars click', e); - // updateData({ - // key: 'avatar', data: e.key - // }) - // }; - - // console.log(data.debugInput, debugInput) - if (data.debugInput != debugInput && shouldRefresh) { - setDebugInput(data.debugInput); - setShouldRefresh(false) - } - - return - - { - // createText('text', i18n.t('createRole'), i18n.t('inputTextPlaceholder'), role.text, '', updateData) - } - - {/* { - createDebug(debugMenu, id, - debugInput, - data.debugOutput, - (event: any) => { - if (event.key == 'input') { - const { data } = event; - setDebugInput(data) - let json: any; - try { - json = JSON.parse(data); - setStatusInputForDebug('') - } catch (error) { - setStatusInputForDebug('error') - } - }; - if (event.key == 'draggable') updateData(event) - }, - () => { - console.log('debugFun debugInput', debugInput) - if (debugInput != "" && debugInput.replace(/\s/ig, "") != "[]" && statusInputForDebug != 'error') { - let merged; - try { - merged = JSON.parse(debugInput) - } catch (error) { - - } - console.log('debugFun merged', merged) - data.merged = merged; - data.debugInput = JSON.stringify(merged, null, 2); - if (data.role) data.role.merged = merged.filter((f: any) => f.role == 'system'); - data.debug && data.debug(data); - } else if (debugInput == "" || debugInput.replace(/\s/ig, "") == "[]") { - data.merged = null; - data.debugInput = ""; - if (data.role) data.role.merged = null; - console.log('debugFun no merged', data) - data.debug && data.debug(data) - setShouldRefresh(true); - } - }, - () => data.merge && data.merge(data), - { - statusInput: statusInputForDebug, - statusOutput: "" - }) - } */} - - - } - - - return ( - -
- - {createNode(role, updateData)} - {/* */} - - - -
-
- ); -} - -export default Main; \ No newline at end of file diff --git a/src/components/flow/nodeComponents/InputMergeNode.tsx b/src/components/flow/nodeComponents/InputMergeNode.tsx index c9026e6..93bace2 100644 --- a/src/components/flow/nodeComponents/InputMergeNode.tsx +++ b/src/components/flow/nodeComponents/InputMergeNode.tsx @@ -124,6 +124,7 @@ function Main({ id, data, selected }: any) { {createText('output', i18n.t('mergeReg'), '', output, '', updateData)} +

{i18n.t('inputMergePlaceholderTips')}

diff --git a/src/components/flow/nodeComponents/QueryInputNode.tsx b/src/components/flow/nodeComponents/QueryInputNode.tsx index f31f179..650a0d1 100644 --- a/src/components/flow/nodeComponents/QueryInputNode.tsx +++ b/src/components/flow/nodeComponents/QueryInputNode.tsx @@ -30,7 +30,7 @@ const createUrl = (input: string, json: any, onChange: any) => { }}> { - createTextArea(i18n.t('selectQuery'), query, i18n.t('selectQuery'), "", (e: any) => { + createTextArea(i18n.t('selectQuery'), query, ".tag", "", (e: any) => { const data = { ...json, queryObj: { diff --git a/src/components/flow/nodeComponents/index.tsx b/src/components/flow/nodeComponents/index.tsx index ea08d73..b6012a5 100644 --- a/src/components/flow/nodeComponents/index.tsx +++ b/src/components/flow/nodeComponents/index.tsx @@ -2,6 +2,7 @@ import QueryDefaultNode from './QueryDefaultNode'; import QueryClickNode from './QueryClickNode' import QueryReadNode from './QueryReadNode'; import QueryInputNode from './QueryInputNode'; +import QueryScrollNode from "./QueryScrollNode"; import APINode from './APINode'; import RoleNode from './RoleNode'; import PromptNode from './PromptNode'; @@ -10,11 +11,11 @@ import UserInputTextNode from './UserInputTextNode' import FilePPTCreateNode from './FilePPTCreateNode' import InputMergeNode from './InputMergeNode' - import i18n from "i18next"; const getNodes = () => [{ + key: 'role', title: i18n.t('roleNodeTitle'), children: [ { @@ -27,6 +28,7 @@ const getNodes = () => [{ ] }, { + key: 'llm', title: i18n.t('llm'), children: [{ key: 'prompt', @@ -49,6 +51,7 @@ const getNodes = () => [{ open: true }, { + key: 'input', title: i18n.t('inputMenu'), children: [{ key: 'userInputText', @@ -65,6 +68,7 @@ const getNodes = () => [{ ], }, { + key: 'query', title: i18n.t('webAgent'), children: [ { @@ -79,6 +83,12 @@ const getNodes = () => [{ parent: 'query', name: i18n.t('queryClickNodeTitle') }, + // { + // key: 'queryScroll', + // component: QueryScrollNode, + // parent: 'query', + // name: i18n.t('queryScrollNodeTitle') + // }, { key: 'queryRead', component: QueryReadNode, @@ -95,6 +105,7 @@ const getNodes = () => [{ }, { + key: 'api', title: 'API', children: [ { @@ -106,6 +117,7 @@ const getNodes = () => [{ ] }, { + key: 'file', title: 'File', children: [ { @@ -115,24 +127,8 @@ const getNodes = () => [{ name: i18n.t('filePPTNodeTitle') } ] -}, - // { - // title: '翻译', - // children: [ - // { - // key: 'translate', - // component: TranslateNode, - // parent: 'translate', - - // name: '翻译' - // } - // ] - // } +} ] - - - - export default getNodes; diff --git a/src/pages/options/index.tsx b/src/pages/options/index.tsx index bfd5702..b7fd580 100644 --- a/src/pages/options/index.tsx +++ b/src/pages/options/index.tsx @@ -24,6 +24,46 @@ declare const window: Window & const config = getConfig(); + +// +import getNodes from '@components/flow/nodeComponents/index' + +const addNewNodes = (newNodes: any = []) => { + let nodes: any = getNodes(); + // const newNode = { + // key: 'queryScroll', + // component: QueryScrollNode, + // parent: 'query', + // name: "i18n.t('queryScrollNodeTitle')" + // } + for (const newNode of newNodes) { + for (const node of nodes) { + if (node.key == newNode.parent) { + node.children.push(newNode) + } + } + } + return { nodes, nodeTypes: updateNodeTypes(nodes) }; +} + +const updateNodeTypes = (nodes: any) => { + const nodeTypes = [] + for (const node of nodes) { + const children: any = node.children; + for (const n of children) { + nodeTypes[n.key] = n.component + } + } + return nodeTypes +} + +const initNodes = () => { + let nodes = getNodes() + return { nodes, nodeTypes: updateNodeTypes(nodes) } +} + + + // 保存combo function saveCombos(combos: any = []) { console.log('saveCombos', combos) @@ -67,7 +107,8 @@ function options() { const [loadData, setLoadData] = React.useState({}); const [isNew, setIsNew] = React.useState(true); - + const [newNodes, setNewNodes] = React.useState(initNodes()) + let exportDataToEarth: any; chrome.storage.local.onChanged.addListener((changes) => { @@ -179,6 +220,7 @@ function options() { width: flowWidth, height: '100%' }}> { From 71b9a379a07999066f0705411a581be68d11412c Mon Sep 17 00:00:00 2001 From: shadowcz007 Date: Thu, 29 Jun 2023 10:56:44 +0800 Subject: [PATCH 2/2] 0.3.7 --- README.md | 3 +++ package.json | 2 +- src/config/app.json | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 61e4633..eda0669 100644 --- a/README.md +++ b/README.md @@ -157,6 +157,9 @@ npm run build [browser] ## 版本记录 +#### v0.3.7 +- 新增节点:用户输入、合并输入 + #### v0.3.6 - 角色节点的升级,对话界面可以切换角色 diff --git a/package.json b/package.json index 558ace7..73c615f 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "Earth", "displayName": "Earth", - "version": "0.3.7.1", + "version": "0.3.7.2", "description": "AGIUI for Browser Extension", "license": "MIT", "repository": { diff --git a/src/config/app.json b/src/config/app.json index 884268e..cd3a46c 100644 --- a/src/config/app.json +++ b/src/config/app.json @@ -1 +1 @@ -{"app":"Earth","version":"0.3.7.0","browsers":["chrome"],"discord":"https://discord.gg/SGwA9anUrr","issues":"https://discord.gg/VtRmJCb8wh","chatGPT":{"token":"","apis":[{"value":"https://api.openai.com","label":"openai"}],"api":"https://api.openai.com","displayApiName":"openai","models":["gpt-3.5-turbo"],"model":"gpt-3.5-turbo","canImport":true},"dev":true} +{"app":"Earth","version":"0.3.7.2","browsers":["chrome"],"discord":"https://discord.gg/SGwA9anUrr","issues":"https://discord.gg/VtRmJCb8wh","chatGPT":{"token":"","apis":[{"value":"https://api.openai.com","label":"openai"}],"api":"https://api.openai.com","displayApiName":"openai","models":["gpt-3.5-turbo"],"model":"gpt-3.5-turbo","canImport":true},"dev":true}