From f0cdf48d54fb73af7440744dd303aa8d0d6ff465 Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 21 Dec 2023 17:28:25 +0000 Subject: [PATCH] update ui changes --- .../nodes/tools/CustomTool/CustomTool.ts | 11 +-- .../components/nodes/tools/CustomTool/core.ts | 15 ++-- .../ui/src/assets/images/variables_empty.svg | 1 + packages/ui/src/menu-items/dashboard.js | 2 +- .../ui/src/views/canvas/NodeInputHandler.js | 7 +- .../src/views/tools/HowToUseFunctionDialog.js | 65 +++++++++++++++++ packages/ui/src/views/tools/ToolDialog.js | 13 ++++ .../views/variables/AddEditVariableDialog.js | 54 +++++++------- .../variables/HowToUseVariablesDialog.js | 72 +++++++++++++++++++ packages/ui/src/views/variables/index.js | 25 +++++-- 10 files changed, 223 insertions(+), 42 deletions(-) create mode 100644 packages/ui/src/assets/images/variables_empty.svg create mode 100644 packages/ui/src/views/tools/HowToUseFunctionDialog.js create mode 100644 packages/ui/src/views/variables/HowToUseVariablesDialog.js diff --git a/packages/components/nodes/tools/CustomTool/CustomTool.ts b/packages/components/nodes/tools/CustomTool/CustomTool.ts index 6b0397c84..9ceda9199 100644 --- a/packages/components/nodes/tools/CustomTool/CustomTool.ts +++ b/packages/components/nodes/tools/CustomTool/CustomTool.ts @@ -85,26 +85,29 @@ class CustomTool_Tools implements INode { // override variables defined in overrideConfig // nodeData.inputs.variables is an Object, check each property and override the variable - if (nodeData?.inputs?.envVars) { - for (const propertyName of Object.getOwnPropertyNames(nodeData.inputs.envVars)) { + if (nodeData?.inputs?.vars) { + for (const propertyName of Object.getOwnPropertyNames(nodeData.inputs.vars)) { const foundVar = variables.find((v) => v.name === propertyName) if (foundVar) { // even if the variable was defined as runtime, we override it with static value foundVar.type = 'static' - foundVar.value = nodeData.inputs.envVars[propertyName] + foundVar.value = nodeData.inputs.vars[propertyName] } else { // add it the variables, if not found locally in the db - variables.push({ name: propertyName, type: 'static', value: nodeData.inputs.envVars[propertyName] }) + variables.push({ name: propertyName, type: 'static', value: nodeData.inputs.vars[propertyName] }) } } } + const flow = { chatId: options.chatId, // id is uppercase (I) chatflowId: options.chatflowid // id is lowercase (i) } + let dynamicStructuredTool = new DynamicStructuredTool(obj) dynamicStructuredTool.setVariables(variables) dynamicStructuredTool.setFlowObject(flow) + return dynamicStructuredTool } catch (e) { throw new Error(e) diff --git a/packages/components/nodes/tools/CustomTool/core.ts b/packages/components/nodes/tools/CustomTool/core.ts index 77aa0e6b4..338b0ae9a 100644 --- a/packages/components/nodes/tools/CustomTool/core.ts +++ b/packages/components/nodes/tools/CustomTool/core.ts @@ -102,15 +102,19 @@ export class DynamicStructuredTool< sandbox[`$${item}`] = arg[item] } } - //inject variables - let env = {} + + // inject variables + let vars = {} if (this.variables) { for (const item of this.variables) { let value = item.value + + // read from .env file if (item.type === 'runtime') { value = process.env[item.name] } - Object.defineProperty(env, item.name, { + + Object.defineProperty(vars, item.name, { enumerable: true, configurable: true, writable: true, @@ -118,10 +122,13 @@ export class DynamicStructuredTool< }) } } - sandbox['$env'] = env + sandbox['$vars'] = vars + + // inject flow properties if (this.flowObj) { sandbox['$flow'] = { ...this.flowObj, sessionId: overrideSessionId } } + const defaultAllowBuiltInDep = [ 'assert', 'buffer', diff --git a/packages/ui/src/assets/images/variables_empty.svg b/packages/ui/src/assets/images/variables_empty.svg new file mode 100644 index 000000000..eb461e39f --- /dev/null +++ b/packages/ui/src/assets/images/variables_empty.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/packages/ui/src/menu-items/dashboard.js b/packages/ui/src/menu-items/dashboard.js index b0e5d66e6..793bc290c 100644 --- a/packages/ui/src/menu-items/dashboard.js +++ b/packages/ui/src/menu-items/dashboard.js @@ -53,7 +53,7 @@ const dashboard = { }, { id: 'variables', - title: 'Environment Variables', + title: 'Variables', type: 'item', url: '/variables', icon: icons.IconVariable, diff --git a/packages/ui/src/views/canvas/NodeInputHandler.js b/packages/ui/src/views/canvas/NodeInputHandler.js index 33e997362..617d1066c 100644 --- a/packages/ui/src/views/canvas/NodeInputHandler.js +++ b/packages/ui/src/views/canvas/NodeInputHandler.js @@ -369,7 +369,12 @@ const NodeInputHandler = ({ inputAnchor, inputParam, data, disabled = false, isA {inputParam?.acceptVariable && ( <> {dialogProps.type !== 'TEMPLATE' && ( { CredentialEmptySVG
No Variables Yet
@@ -267,7 +273,13 @@ const Variables = () => { {variable.value} - {variable.type === 'static' ? 'Static Variable' : 'Runtime Variable'} + + + {moment(variable.updatedDate).format('DD-MMM-YY')} {moment(variable.createdDate).format('DD-MMM-YY')} @@ -293,6 +305,7 @@ const Variables = () => { onCancel={() => setShowVariableDialog(false)} onConfirm={onConfirm} > + setShowHowToDialog(false)}> )