From de0e86150f4d0615481e5ec3869465cfd1ce822f Mon Sep 17 00:00:00 2001 From: Charlie Kolb Date: Tue, 19 Nov 2024 13:11:12 +0100 Subject: [PATCH] feat(editor): Add Info Note to NDV Output Panel if no existing Tools were used during Execution (#11672) --- cypress/composables/ndv.ts | 4 + cypress/e2e/30-langchain.cy.ts | 100 ++++++++++++++++++ .../editor-ui/src/components/OutputPanel.vue | 32 +++++- packages/editor-ui/src/components/RunData.vue | 8 ++ .../__snapshots__/InputPanel.test.ts.snap | 1 + .../src/plugins/i18n/locales/en.json | 1 + 6 files changed, 145 insertions(+), 1 deletion(-) diff --git a/cypress/composables/ndv.ts b/cypress/composables/ndv.ts index 05d783ec5e..4819e7fccc 100644 --- a/cypress/composables/ndv.ts +++ b/cypress/composables/ndv.ts @@ -72,6 +72,10 @@ export function getOutputPanelTable() { return getOutputPanelDataContainer().get('table'); } +export function getRunDataInfoCallout() { + return cy.getByTestId('run-data-callout'); +} + export function getOutputPanelItemsCount() { return getOutputPanel().getByTestId('ndv-items-count'); } diff --git a/cypress/e2e/30-langchain.cy.ts b/cypress/e2e/30-langchain.cy.ts index 78934c3ce5..96a03be961 100644 --- a/cypress/e2e/30-langchain.cy.ts +++ b/cypress/e2e/30-langchain.cy.ts @@ -26,6 +26,8 @@ import { clickCreateNewCredential, clickExecuteNode, clickGetBackToCanvas, + getRunDataInfoCallout, + getOutputPanelTable, toggleParameterCheckboxInputByName, } from '../composables/ndv'; import { @@ -418,4 +420,102 @@ describe('Langchain Integration', () => { assertInputOutputText('Berlin', 'not.exist'); assertInputOutputText('Kyiv', 'not.exist'); }); + + it('should show tool info notice if no existing tools were used during execution', () => { + addNodeToCanvas(MANUAL_CHAT_TRIGGER_NODE_NAME, true); + addNodeToCanvas(AGENT_NODE_NAME, true); + + addLanguageModelNodeToParent( + AI_LANGUAGE_MODEL_OPENAI_CHAT_MODEL_NODE_NAME, + AGENT_NODE_NAME, + true, + ); + + clickCreateNewCredential(); + setCredentialValues({ + apiKey: 'sk_test_123', + }); + clickGetBackToCanvas(); + + addToolNodeToParent(AI_TOOL_CALCULATOR_NODE_NAME, AGENT_NODE_NAME); + clickGetBackToCanvas(); + openNode(AGENT_NODE_NAME); + + const inputMessage = 'Hello!'; + const outputMessage = 'Hi there! How can I assist you today?'; + + clickExecuteNode(); + + runMockWorkflowExecution({ + trigger: () => sendManualChatMessage(inputMessage), + runData: [ + createMockNodeExecutionData(AGENT_NODE_NAME, { + jsonData: { + main: { output: outputMessage }, + }, + metadata: { + subRun: [{ node: AI_LANGUAGE_MODEL_OPENAI_CHAT_MODEL_NODE_NAME, runIndex: 0 }], + }, + }), + ], + lastNodeExecuted: AGENT_NODE_NAME, + }); + closeManualChatModal(); + openNode(AGENT_NODE_NAME); + + getRunDataInfoCallout().should('exist'); + }); + + it('should not show tool info notice if tools were used during execution', () => { + addNodeToCanvas(MANUAL_CHAT_TRIGGER_NODE_NAME, true); + addNodeToCanvas(AGENT_NODE_NAME, true, true); + getRunDataInfoCallout().should('not.exist'); + clickGetBackToCanvas(); + + addLanguageModelNodeToParent( + AI_LANGUAGE_MODEL_OPENAI_CHAT_MODEL_NODE_NAME, + AGENT_NODE_NAME, + true, + ); + + clickCreateNewCredential(); + setCredentialValues({ + apiKey: 'sk_test_123', + }); + clickGetBackToCanvas(); + + addToolNodeToParent(AI_TOOL_CALCULATOR_NODE_NAME, AGENT_NODE_NAME); + clickGetBackToCanvas(); + openNode(AGENT_NODE_NAME); + + getRunDataInfoCallout().should('not.exist'); + + const inputMessage = 'Hello!'; + const outputMessage = 'Hi there! How can I assist you today?'; + + clickExecuteNode(); + + runMockWorkflowExecution({ + trigger: () => sendManualChatMessage(inputMessage), + runData: [ + createMockNodeExecutionData(AGENT_NODE_NAME, { + jsonData: { + main: { output: outputMessage }, + }, + metadata: { + subRun: [{ node: AI_LANGUAGE_MODEL_OPENAI_CHAT_MODEL_NODE_NAME, runIndex: 0 }], + }, + }), + createMockNodeExecutionData(AI_TOOL_CALCULATOR_NODE_NAME, {}), + ], + lastNodeExecuted: AGENT_NODE_NAME, + }); + + closeManualChatModal(); + openNode(AGENT_NODE_NAME); + // This waits to ensure the output panel is rendered + getOutputPanelTable(); + + getRunDataInfoCallout().should('not.exist'); + }); }); diff --git a/packages/editor-ui/src/components/OutputPanel.vue b/packages/editor-ui/src/components/OutputPanel.vue index 0ca7e3830e..aff304a3cf 100644 --- a/packages/editor-ui/src/components/OutputPanel.vue +++ b/packages/editor-ui/src/components/OutputPanel.vue @@ -1,6 +1,12 @@