From d960777293cbab648a3eff3941846f6b4cb93358 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Wed, 6 Nov 2024 17:02:24 +0100 Subject: [PATCH 1/8] ci: Fix the release workflow (no-changelog) --- .github/workflows/release-publish.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release-publish.yml b/.github/workflows/release-publish.yml index e8d5fdc714..c7e34ea67a 100644 --- a/.github/workflows/release-publish.yml +++ b/.github/workflows/release-publish.yml @@ -147,7 +147,7 @@ jobs: continue-on-error: true with: projects: ${{ secrets.SENTRY_FRONTEND_PROJECT }} - version: {{ needs.publish-to-npm.outputs.release }} + version: ${{ needs.publish-to-npm.outputs.release }} sourcemaps: packages/editor-ui/dist - name: Create a backend release @@ -155,7 +155,7 @@ jobs: continue-on-error: true with: projects: ${{ secrets.SENTRY_BACKEND_PROJECT }} - version: {{ needs.publish-to-npm.outputs.release }} + version: ${{ needs.publish-to-npm.outputs.release }} sourcemaps: packages/cli/dist packages/core/dist packages/nodes-base/dist packages/@n8n/n8n-nodes-langchain/dist trigger-release-note: From 3dc0904a6c65fa37e52e1ea379f482676ee715e4 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Wed, 6 Nov 2024 11:09:56 -0500 Subject: [PATCH 2/8] :rocket: Release 1.67.0 (#11599) Co-authored-by: RicardoE105 <16496553+RicardoE105@users.noreply.github.com> --- CHANGELOG.md | 36 ++++++++++++++++++++++ package.json | 2 +- packages/@n8n/chat/package.json | 2 +- packages/@n8n/config/package.json | 2 +- packages/@n8n/nodes-langchain/package.json | 2 +- packages/@n8n/task-runner/package.json | 2 +- packages/cli/package.json | 2 +- packages/core/package.json | 2 +- packages/design-system/package.json | 2 +- packages/editor-ui/package.json | 2 +- packages/node-dev/package.json | 2 +- packages/nodes-base/package.json | 2 +- packages/workflow/package.json | 2 +- 13 files changed, 48 insertions(+), 12 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4a380fa531..f85ab264be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,39 @@ +# [1.67.0](https://github.com/n8n-io/n8n/compare/n8n@1.66.0...n8n@1.67.0) (2024-11-06) + + +### Bug Fixes + +* Bring back nodes panel telemetry events ([#11456](https://github.com/n8n-io/n8n/issues/11456)) ([130c942](https://github.com/n8n-io/n8n/commit/130c942f633788d1b2f937d6fea342d4450c6e3d)) +* **core:** Account for double quotes in instance base URL ([#11495](https://github.com/n8n-io/n8n/issues/11495)) ([c5191e6](https://github.com/n8n-io/n8n/commit/c5191e697a9a9ebfa2b67587cd01b5835ebf6ea8)) +* **core:** Do not delete waiting executions when saving of successful executions is disabled ([#11458](https://github.com/n8n-io/n8n/issues/11458)) ([e8757e5](https://github.com/n8n-io/n8n/commit/e8757e58f69e091ac3d2a2f8e8c8e33ac57c1e47)) +* **core:** Don't send a `executionFinished` event to the browser with no run data if the execution has already been cleaned up ([#11502](https://github.com/n8n-io/n8n/issues/11502)) ([d1153f5](https://github.com/n8n-io/n8n/commit/d1153f51e80911cbc8f34ba5f038f349b75295c3)) +* **core:** Include `projectId` in range query middleware ([#11590](https://github.com/n8n-io/n8n/issues/11590)) ([a6070af](https://github.com/n8n-io/n8n/commit/a6070afdda29631fd36e5213f52bf815268bcda4)) +* **core:** Save exeution progress for waiting executions, even when progress saving is disabled ([#11535](https://github.com/n8n-io/n8n/issues/11535)) ([6b9353c](https://github.com/n8n-io/n8n/commit/6b9353c80f61ab36945fff434d98242dc1cab7b3)) +* **core:** Use the correct docs URL for regular nodes when used as tools ([#11529](https://github.com/n8n-io/n8n/issues/11529)) ([a092b8e](https://github.com/n8n-io/n8n/commit/a092b8e972e1253d92df416f19096a045858e7c1)) +* **Edit Image Node:** Fix Text operation by setting Arial as default font ([#11125](https://github.com/n8n-io/n8n/issues/11125)) ([60c1ace](https://github.com/n8n-io/n8n/commit/60c1ace64be29d651ce7b777fbb576598e38b9d7)) +* **editor:** Auto focus first fields on SignIn, SignUp and ForgotMyPassword views ([#11445](https://github.com/n8n-io/n8n/issues/11445)) ([5b5bd72](https://github.com/n8n-io/n8n/commit/5b5bd7291dde17880b7699f7e6832938599ffd8f)) +* **editor:** Do not overwrite the webhookId in the new canvas ([#11562](https://github.com/n8n-io/n8n/issues/11562)) ([dfd785b](https://github.com/n8n-io/n8n/commit/dfd785bc0894257eb6e62b0dd8f71248c27aae53)) +* **editor:** Ensure Enter key on Cancel button correctly cancels node rename ([#11563](https://github.com/n8n-io/n8n/issues/11563)) ([be05ae3](https://github.com/n8n-io/n8n/commit/be05ae36e7790156cb48b317fc254ae46a3b2d8c)) +* **editor:** Fix emitting `n8nReady` notification via `postmessage` on new canvas ([#11558](https://github.com/n8n-io/n8n/issues/11558)) ([463d101](https://github.com/n8n-io/n8n/commit/463d101f3592e6df4afd66c4d0fde0cb4aec34cc)) +* **editor:** Fix run index input for RunData view in sub-nodes ([#11538](https://github.com/n8n-io/n8n/issues/11538)) ([434d31c](https://github.com/n8n-io/n8n/commit/434d31ce928342d52b6ab8b78639afd7829216d4)) +* **editor:** Fix selected credential being overwritten in NDV ([#11496](https://github.com/n8n-io/n8n/issues/11496)) ([a26c0e2](https://github.com/n8n-io/n8n/commit/a26c0e2c3c7da87bfaba9737a967aa0070810d85)) +* **editor:** Keep workflow pristine after load on new canvas ([#11579](https://github.com/n8n-io/n8n/issues/11579)) ([7254359](https://github.com/n8n-io/n8n/commit/7254359855b89769613cd5cc24dbb4f45a7cc76f)) +* Show Pinned data in demo mode ([#11490](https://github.com/n8n-io/n8n/issues/11490)) ([ca2a583](https://github.com/n8n-io/n8n/commit/ca2a583b5cbb0cba3ecb694261806de16547aa91)) +* Toast not aligned to the bottom when AI assistant disable ([#11549](https://github.com/n8n-io/n8n/issues/11549)) ([e80f7e0](https://github.com/n8n-io/n8n/commit/e80f7e0a02a972379f73af6a44de11768081086e)) + + +### Features + +* Add Rapid7 InsightVm credentials ([#11462](https://github.com/n8n-io/n8n/issues/11462)) ([46eceab](https://github.com/n8n-io/n8n/commit/46eceabc27ac219b11b85c16c533a2cff848c5dd)) +* **AI Transform Node:** UX improvements ([#11280](https://github.com/n8n-io/n8n/issues/11280)) ([8a48407](https://github.com/n8n-io/n8n/commit/8a484077af3d3e1fe2d1b90b1ea9edf4ba41fcb6)) +* **Anthropic Chat Model Node:** Add support for Haiku 3.5 ([#11551](https://github.com/n8n-io/n8n/issues/11551)) ([8b39825](https://github.com/n8n-io/n8n/commit/8b398256a81594a52f20f8eb8adf8ff205209bc1)) +* **Convert to File Node:** Add delimiter convert to csv ([#11556](https://github.com/n8n-io/n8n/issues/11556)) ([63d454b](https://github.com/n8n-io/n8n/commit/63d454b776c092ff8c6c521a7e083774adb8f649)) +* **editor:** Update panning and selection keybindings on new canvas ([#11534](https://github.com/n8n-io/n8n/issues/11534)) ([5e2e205](https://github.com/n8n-io/n8n/commit/5e2e205394adf76faf02aee2d4f21df71848e1d4)) +* **Gmail Trigger Node:** Add filter option to include drafts ([#11441](https://github.com/n8n-io/n8n/issues/11441)) ([7a2be77](https://github.com/n8n-io/n8n/commit/7a2be77f384a32ede3acad8fe24fb89227c058bf)) +* **Intercom Node:** Update credential to new style ([#11485](https://github.com/n8n-io/n8n/issues/11485)) ([b137e13](https://github.com/n8n-io/n8n/commit/b137e13845f0714ebf7421c837f5ab104b66709b)) + + + # [1.66.0](https://github.com/n8n-io/n8n/compare/n8n@1.65.0...n8n@1.66.0) (2024-10-31) diff --git a/package.json b/package.json index 6553f0f722..1b35d0384f 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "n8n-monorepo", - "version": "1.66.0", + "version": "1.67.0", "private": true, "engines": { "node": ">=20.15", diff --git a/packages/@n8n/chat/package.json b/packages/@n8n/chat/package.json index 51a4cb5f2b..a6098892f0 100644 --- a/packages/@n8n/chat/package.json +++ b/packages/@n8n/chat/package.json @@ -1,6 +1,6 @@ { "name": "@n8n/chat", - "version": "0.29.0", + "version": "0.30.0", "scripts": { "dev": "pnpm run storybook", "build": "pnpm build:vite && pnpm build:bundle", diff --git a/packages/@n8n/config/package.json b/packages/@n8n/config/package.json index d1dddf3e70..4867390bf7 100644 --- a/packages/@n8n/config/package.json +++ b/packages/@n8n/config/package.json @@ -1,6 +1,6 @@ { "name": "@n8n/config", - "version": "1.16.0", + "version": "1.17.0", "scripts": { "clean": "rimraf dist .turbo", "dev": "pnpm watch", diff --git a/packages/@n8n/nodes-langchain/package.json b/packages/@n8n/nodes-langchain/package.json index 5910094890..38acd88c9a 100644 --- a/packages/@n8n/nodes-langchain/package.json +++ b/packages/@n8n/nodes-langchain/package.json @@ -1,6 +1,6 @@ { "name": "@n8n/n8n-nodes-langchain", - "version": "1.66.0", + "version": "1.67.0", "description": "", "main": "index.js", "scripts": { diff --git a/packages/@n8n/task-runner/package.json b/packages/@n8n/task-runner/package.json index 4b5478a97d..8350667099 100644 --- a/packages/@n8n/task-runner/package.json +++ b/packages/@n8n/task-runner/package.json @@ -1,6 +1,6 @@ { "name": "@n8n/task-runner", - "version": "1.4.0", + "version": "1.5.0", "scripts": { "clean": "rimraf dist .turbo", "start": "node dist/start.js", diff --git a/packages/cli/package.json b/packages/cli/package.json index 0404b8c116..5c589116ee 100644 --- a/packages/cli/package.json +++ b/packages/cli/package.json @@ -1,6 +1,6 @@ { "name": "n8n", - "version": "1.66.0", + "version": "1.67.0", "description": "n8n Workflow Automation Tool", "main": "dist/index", "types": "dist/index.d.ts", diff --git a/packages/core/package.json b/packages/core/package.json index 32fa66a297..8628aa92ef 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -1,6 +1,6 @@ { "name": "n8n-core", - "version": "1.66.0", + "version": "1.67.0", "description": "Core functionality of n8n", "main": "dist/index", "types": "dist/index.d.ts", diff --git a/packages/design-system/package.json b/packages/design-system/package.json index d2f39c3e0e..94f1cba0aa 100644 --- a/packages/design-system/package.json +++ b/packages/design-system/package.json @@ -1,6 +1,6 @@ { "name": "n8n-design-system", - "version": "1.56.0", + "version": "1.57.0", "main": "src/main.ts", "import": "src/main.ts", "scripts": { diff --git a/packages/editor-ui/package.json b/packages/editor-ui/package.json index b1c6462e34..5d5c63a298 100644 --- a/packages/editor-ui/package.json +++ b/packages/editor-ui/package.json @@ -1,6 +1,6 @@ { "name": "n8n-editor-ui", - "version": "1.66.0", + "version": "1.67.0", "description": "Workflow Editor UI for n8n", "main": "index.js", "scripts": { diff --git a/packages/node-dev/package.json b/packages/node-dev/package.json index 2a7bdd3cac..60e8ed6095 100644 --- a/packages/node-dev/package.json +++ b/packages/node-dev/package.json @@ -1,6 +1,6 @@ { "name": "n8n-node-dev", - "version": "1.66.0", + "version": "1.67.0", "description": "CLI to simplify n8n credentials/node development", "main": "dist/src/index", "types": "dist/src/index.d.ts", diff --git a/packages/nodes-base/package.json b/packages/nodes-base/package.json index f04cea20b4..539112b430 100644 --- a/packages/nodes-base/package.json +++ b/packages/nodes-base/package.json @@ -1,6 +1,6 @@ { "name": "n8n-nodes-base", - "version": "1.66.0", + "version": "1.67.0", "description": "Base nodes of n8n", "main": "index.js", "scripts": { diff --git a/packages/workflow/package.json b/packages/workflow/package.json index befa748090..bbb75b7540 100644 --- a/packages/workflow/package.json +++ b/packages/workflow/package.json @@ -1,6 +1,6 @@ { "name": "n8n-workflow", - "version": "1.65.0", + "version": "1.66.0", "description": "Workflow base code of n8n", "main": "dist/index.js", "module": "src/index.ts", From 21b31e488ff6ab0bcf3c79edcd17b9e37d4c64a4 Mon Sep 17 00:00:00 2001 From: oleg Date: Wed, 6 Nov 2024 17:24:43 +0100 Subject: [PATCH 3/8] fix(Auto-fixing Output Parser Node): Only run retry chain on parsing errors (#11569) --- .../agents/Agent/agents/ToolsAgent/execute.ts | 26 ++- .../OutputParserAutofixing.node.ts | 39 +++- .../OutputParserAutofixing/prompt.ts | 16 ++ .../test/OutputParserAutofixing.node.test.ts | 168 +++++++++++++----- .../output_parsers/N8nOutputFixingParser.ts | 12 +- 5 files changed, 202 insertions(+), 59 deletions(-) create mode 100644 packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserAutofixing/prompt.ts diff --git a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/execute.ts b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/execute.ts index 84d775d0f5..25e6e78984 100644 --- a/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/execute.ts +++ b/packages/@n8n/nodes-langchain/nodes/agents/Agent/agents/ToolsAgent/execute.ts @@ -206,10 +206,28 @@ export async function toolsAgentExecute(this: IExecuteFunctions): Promise; + let parserInput: string; + + if (finalResponse instanceof Object) { + if ('output' in finalResponse) { + try { + // If the output is an object, we will try to parse it as JSON + // this is because parser expects stringified JSON object like { "output": { .... } } + // so we try to parse the output before wrapping it and then stringify it + parserInput = JSON.stringify({ output: jsonParse(finalResponse.output) }); + } catch (error) { + // If parsing of the output fails, we will use the raw output + parserInput = finalResponse.output; + } + } else { + // If the output is not an object, we will stringify it as it is + parserInput = JSON.stringify(finalResponse); + } + } else { + parserInput = finalResponse; + } + + const returnValues = (await outputParser.parse(parserInput)) as Record; return handleParsedStepOutput(returnValues); } return handleAgentFinishOutput(steps); diff --git a/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserAutofixing/OutputParserAutofixing.node.ts b/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserAutofixing/OutputParserAutofixing.node.ts index d4743fb043..4f385e1770 100644 --- a/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserAutofixing/OutputParserAutofixing.node.ts +++ b/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserAutofixing/OutputParserAutofixing.node.ts @@ -1,5 +1,6 @@ import type { BaseLanguageModel } from '@langchain/core/language_models/base'; -import { NodeConnectionType } from 'n8n-workflow'; +import { PromptTemplate } from '@langchain/core/prompts'; +import { NodeConnectionType, NodeOperationError } from 'n8n-workflow'; import type { ISupplyDataFunctions, INodeType, @@ -7,6 +8,7 @@ import type { SupplyData, } from 'n8n-workflow'; +import { NAIVE_FIX_PROMPT } from './prompt'; import { N8nOutputFixingParser, type N8nStructuredOutputParser, @@ -65,6 +67,27 @@ export class OutputParserAutofixing implements INodeType { default: '', }, getConnectionHintNoticeField([NodeConnectionType.AiChain, NodeConnectionType.AiAgent]), + { + displayName: 'Options', + name: 'options', + type: 'collection', + placeholder: 'Add Option', + default: {}, + options: [ + { + displayName: 'Retry Prompt', + name: 'prompt', + type: 'string', + default: NAIVE_FIX_PROMPT, + typeOptions: { + rows: 10, + }, + hint: 'Should include "{error}", "{instructions}", and "{completion}" placeholders', + description: + 'Prompt template used for fixing the output. Uses placeholders: "{instructions}" for parsing rules, "{completion}" for the failed attempt, and "{error}" for the validation error message.', + }, + ], + }, ], }; @@ -77,8 +100,20 @@ export class OutputParserAutofixing implements INodeType { NodeConnectionType.AiOutputParser, itemIndex, )) as N8nStructuredOutputParser; + const prompt = this.getNodeParameter('options.prompt', itemIndex, NAIVE_FIX_PROMPT) as string; - const parser = new N8nOutputFixingParser(this, model, outputParser); + if (prompt.length === 0 || !prompt.includes('{error}')) { + throw new NodeOperationError( + this.getNode(), + 'Auto-fixing parser prompt has to contain {error} placeholder', + ); + } + const parser = new N8nOutputFixingParser( + this, + model, + outputParser, + PromptTemplate.fromTemplate(prompt), + ); return { response: parser, diff --git a/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserAutofixing/prompt.ts b/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserAutofixing/prompt.ts new file mode 100644 index 0000000000..9e4431a68c --- /dev/null +++ b/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserAutofixing/prompt.ts @@ -0,0 +1,16 @@ +export const NAIVE_FIX_PROMPT = `Instructions: +-------------- +{instructions} +-------------- +Completion: +-------------- +{completion} +-------------- + +Above, the Completion did not satisfy the constraints given in the Instructions. +Error: +-------------- +{error} +-------------- + +Please try again. Please only respond with an answer that satisfies the constraints laid out in the Instructions:`; diff --git a/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserAutofixing/test/OutputParserAutofixing.node.test.ts b/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserAutofixing/test/OutputParserAutofixing.node.test.ts index 32d25d4f73..9fcae1a8fa 100644 --- a/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserAutofixing/test/OutputParserAutofixing.node.test.ts +++ b/packages/@n8n/nodes-langchain/nodes/output_parser/OutputParserAutofixing/test/OutputParserAutofixing.node.test.ts @@ -1,15 +1,19 @@ /* eslint-disable @typescript-eslint/unbound-method */ /* eslint-disable @typescript-eslint/no-unsafe-call */ import type { BaseLanguageModel } from '@langchain/core/language_models/base'; +import { OutputParserException } from '@langchain/core/output_parsers'; import type { MockProxy } from 'jest-mock-extended'; import { mock } from 'jest-mock-extended'; import { normalizeItems } from 'n8n-core'; import type { IExecuteFunctions, IWorkflowDataProxyData } from 'n8n-workflow'; -import { ApplicationError, NodeConnectionType } from 'n8n-workflow'; +import { ApplicationError, NodeConnectionType, NodeOperationError } from 'n8n-workflow'; -import { N8nOutputFixingParser } from '../../../../utils/output_parsers/N8nOutputParser'; -import type { N8nStructuredOutputParser } from '../../../../utils/output_parsers/N8nOutputParser'; +import type { + N8nOutputFixingParser, + N8nStructuredOutputParser, +} from '../../../../utils/output_parsers/N8nOutputParser'; import { OutputParserAutofixing } from '../OutputParserAutofixing.node'; +import { NAIVE_FIX_PROMPT } from '../prompt'; describe('OutputParserAutofixing', () => { let outputParser: OutputParserAutofixing; @@ -34,6 +38,13 @@ describe('OutputParserAutofixing', () => { throw new ApplicationError('Unexpected connection type'); }); + thisArg.getNodeParameter.mockReset(); + thisArg.getNodeParameter.mockImplementation((parameterName) => { + if (parameterName === 'options.prompt') { + return NAIVE_FIX_PROMPT; + } + throw new ApplicationError('Not implemented'); + }); }); afterEach(() => { @@ -48,73 +59,132 @@ describe('OutputParserAutofixing', () => { }); } - it('should successfully parse valid output without needing to fix it', async () => { - const validOutput = { name: 'Alice', age: 25 }; + describe('Configuration', () => { + it('should throw error when prompt template does not contain {error} placeholder', async () => { + thisArg.getNodeParameter.mockImplementation((parameterName) => { + if (parameterName === 'options.prompt') { + return 'Invalid prompt without error placeholder'; + } + throw new ApplicationError('Not implemented'); + }); - mockStructuredOutputParser.parse.mockResolvedValueOnce(validOutput); + await expect(outputParser.supplyData.call(thisArg, 0)).rejects.toThrow( + new NodeOperationError( + thisArg.getNode(), + 'Auto-fixing parser prompt has to contain {error} placeholder', + ), + ); + }); - const { response } = (await outputParser.supplyData.call(thisArg, 0)) as { - response: N8nOutputFixingParser; - }; + it('should throw error when prompt template is empty', async () => { + thisArg.getNodeParameter.mockImplementation((parameterName) => { + if (parameterName === 'options.prompt') { + return ''; + } + throw new ApplicationError('Not implemented'); + }); - // Ensure the response contains the output-fixing parser - expect(response).toBeDefined(); - expect(response).toBeInstanceOf(N8nOutputFixingParser); + await expect(outputParser.supplyData.call(thisArg, 0)).rejects.toThrow( + new NodeOperationError( + thisArg.getNode(), + 'Auto-fixing parser prompt has to contain {error} placeholder', + ), + ); + }); - const result = await response.parse('{"name": "Alice", "age": 25}'); + it('should use default prompt when none specified', async () => { + thisArg.getNodeParameter.mockImplementation((parameterName) => { + if (parameterName === 'options.prompt') { + return NAIVE_FIX_PROMPT; + } + throw new ApplicationError('Not implemented'); + }); - // Validate that the parser succeeds without retry - expect(result).toEqual(validOutput); - expect(mockStructuredOutputParser.parse).toHaveBeenCalledTimes(1); // Only one call to parse + const { response } = (await outputParser.supplyData.call(thisArg, 0)) as { + response: N8nOutputFixingParser; + }; + + expect(response).toBeDefined(); + }); }); - it('should throw an error when both structured parser and fixing parser fail', async () => { - mockStructuredOutputParser.parse - .mockRejectedValueOnce(new Error('Invalid JSON')) // First attempt fails - .mockRejectedValueOnce(new Error('Fixing attempt failed')); // Second attempt fails + describe('Parsing', () => { + it('should successfully parse valid output without needing to fix it', async () => { + const validOutput = { name: 'Alice', age: 25 }; - const { response } = (await outputParser.supplyData.call(thisArg, 0)) as { - response: N8nOutputFixingParser; - }; + mockStructuredOutputParser.parse.mockResolvedValueOnce(validOutput); - response.getRetryChain = getMockedRetryChain('{}'); + const { response } = (await outputParser.supplyData.call(thisArg, 0)) as { + response: N8nOutputFixingParser; + }; - await expect(response.parse('Invalid JSON string')).rejects.toThrow('Fixing attempt failed'); - expect(mockStructuredOutputParser.parse).toHaveBeenCalledTimes(2); - }); + const result = await response.parse('{"name": "Alice", "age": 25}'); - it('should reject on the first attempt and succeed on retry with the parsed content', async () => { - const validOutput = { name: 'Bob', age: 28 }; + expect(result).toEqual(validOutput); + expect(mockStructuredOutputParser.parse).toHaveBeenCalledTimes(1); + }); - mockStructuredOutputParser.parse.mockRejectedValueOnce(new Error('Invalid JSON')); + it('should not retry on non-OutputParserException errors', async () => { + const error = new Error('Some other error'); + mockStructuredOutputParser.parse.mockRejectedValueOnce(error); - const { response } = (await outputParser.supplyData.call(thisArg, 0)) as { - response: N8nOutputFixingParser; - }; + const { response } = (await outputParser.supplyData.call(thisArg, 0)) as { + response: N8nOutputFixingParser; + }; - response.getRetryChain = getMockedRetryChain(JSON.stringify(validOutput)); + await expect(response.parse('Invalid JSON string')).rejects.toThrow(error); + expect(mockStructuredOutputParser.parse).toHaveBeenCalledTimes(1); + }); - mockStructuredOutputParser.parse.mockResolvedValueOnce(validOutput); + it('should retry on OutputParserException and succeed', async () => { + const validOutput = { name: 'Bob', age: 28 }; - const result = await response.parse('Invalid JSON string'); + mockStructuredOutputParser.parse + .mockRejectedValueOnce(new OutputParserException('Invalid JSON')) + .mockResolvedValueOnce(validOutput); - expect(result).toEqual(validOutput); - expect(mockStructuredOutputParser.parse).toHaveBeenCalledTimes(2); // First fails, second succeeds - }); + const { response } = (await outputParser.supplyData.call(thisArg, 0)) as { + response: N8nOutputFixingParser; + }; - it('should handle non-JSON formatted response from fixing parser', async () => { - mockStructuredOutputParser.parse.mockRejectedValueOnce(new Error('Invalid JSON')); + response.getRetryChain = getMockedRetryChain(JSON.stringify(validOutput)); - const { response } = (await outputParser.supplyData.call(thisArg, 0)) as { - response: N8nOutputFixingParser; - }; + const result = await response.parse('Invalid JSON string'); - response.getRetryChain = getMockedRetryChain('This is not JSON'); + expect(result).toEqual(validOutput); + expect(mockStructuredOutputParser.parse).toHaveBeenCalledTimes(2); + }); - mockStructuredOutputParser.parse.mockRejectedValueOnce(new Error('Unexpected token')); + it('should handle failed retry attempt', async () => { + mockStructuredOutputParser.parse + .mockRejectedValueOnce(new OutputParserException('Invalid JSON')) + .mockRejectedValueOnce(new Error('Still invalid JSON')); - // Expect the structured parser to throw an error on invalid JSON from retry - await expect(response.parse('Invalid JSON string')).rejects.toThrow('Unexpected token'); - expect(mockStructuredOutputParser.parse).toHaveBeenCalledTimes(2); // First fails, second tries and fails + const { response } = (await outputParser.supplyData.call(thisArg, 0)) as { + response: N8nOutputFixingParser; + }; + + response.getRetryChain = getMockedRetryChain('Still not valid JSON'); + + await expect(response.parse('Invalid JSON string')).rejects.toThrow('Still invalid JSON'); + expect(mockStructuredOutputParser.parse).toHaveBeenCalledTimes(2); + }); + + it('should throw non-OutputParserException errors immediately without retry', async () => { + const customError = new Error('Database connection error'); + const retryChainSpy = jest.fn(); + + mockStructuredOutputParser.parse.mockRejectedValueOnce(customError); + + const { response } = (await outputParser.supplyData.call(thisArg, 0)) as { + response: N8nOutputFixingParser; + }; + + response.getRetryChain = retryChainSpy; + + await expect(response.parse('Some input')).rejects.toThrow('Database connection error'); + expect(mockStructuredOutputParser.parse).toHaveBeenCalledTimes(1); + expect(retryChainSpy).not.toHaveBeenCalled(); + }); }); }); diff --git a/packages/@n8n/nodes-langchain/utils/output_parsers/N8nOutputFixingParser.ts b/packages/@n8n/nodes-langchain/utils/output_parsers/N8nOutputFixingParser.ts index eec3b0c187..de07bfc7cf 100644 --- a/packages/@n8n/nodes-langchain/utils/output_parsers/N8nOutputFixingParser.ts +++ b/packages/@n8n/nodes-langchain/utils/output_parsers/N8nOutputFixingParser.ts @@ -1,12 +1,12 @@ import type { Callbacks } from '@langchain/core/callbacks/manager'; import type { BaseLanguageModel } from '@langchain/core/language_models/base'; import type { AIMessage } from '@langchain/core/messages'; -import { BaseOutputParser } from '@langchain/core/output_parsers'; +import { BaseOutputParser, OutputParserException } from '@langchain/core/output_parsers'; +import type { PromptTemplate } from '@langchain/core/prompts'; import type { ISupplyDataFunctions } from 'n8n-workflow'; import { NodeConnectionType } from 'n8n-workflow'; import type { N8nStructuredOutputParser } from './N8nStructuredOutputParser'; -import { NAIVE_FIX_PROMPT } from './prompt'; import { logAiEvent } from '../helpers'; export class N8nOutputFixingParser extends BaseOutputParser { @@ -16,12 +16,13 @@ export class N8nOutputFixingParser extends BaseOutputParser { private context: ISupplyDataFunctions, private model: BaseLanguageModel, private outputParser: N8nStructuredOutputParser, + private fixPromptTemplate: PromptTemplate, ) { super(); } getRetryChain() { - return NAIVE_FIX_PROMPT.pipe(this.model); + return this.fixPromptTemplate.pipe(this.model); } /** @@ -47,11 +48,14 @@ export class N8nOutputFixingParser extends BaseOutputParser { return response; } catch (error) { + if (!(error instanceof OutputParserException)) { + throw error; + } try { // Second attempt: use retry chain to fix the output const result = (await this.getRetryChain().invoke({ completion, - error, + error: error.message, instructions: this.getFormatInstructions(), })) as AIMessage; From 471921dc20a486f01791a246db439fc9ad8f76d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Wed, 6 Nov 2024 18:04:09 +0100 Subject: [PATCH 4/8] ci: Checkout the repo before triggering the Sentry release creation (no-changelog) (#11601) --- .github/workflows/release-publish.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/release-publish.yml b/.github/workflows/release-publish.yml index c7e34ea67a..21e33bbcff 100644 --- a/.github/workflows/release-publish.yml +++ b/.github/workflows/release-publish.yml @@ -126,7 +126,7 @@ jobs: body: ${{github.event.pull_request.body}} create-sentry-release: - name: Create release on Sentry + name: Create a Sentry Release needs: [publish-to-npm, publish-to-docker-hub] runs-on: ubuntu-latest if: github.event.pull_request.merged == true @@ -136,6 +136,7 @@ jobs: SENTRY_ORG: ${{ secrets.SENTRY_ORG }} steps: + - uses: actions/checkout@v4.1.1 - name: Restore cached build artifacts uses: actions/cache/restore@v4.0.0 with: From 059f67500a18532b99fbfde57533d97e9aa407cc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Wed, 6 Nov 2024 19:34:21 +0100 Subject: [PATCH 5/8] refactor(editor): Migrate `EventDestinationSettingsModal.ee.vue` to composition API (no-changelog) (#11584) --- .../EventDestinationSettingsModal.ee.vue | 657 +++++++++--------- 1 file changed, 327 insertions(+), 330 deletions(-) diff --git a/packages/editor-ui/src/components/SettingsLogStreaming/EventDestinationSettingsModal.ee.vue b/packages/editor-ui/src/components/SettingsLogStreaming/EventDestinationSettingsModal.ee.vue index c3580ade82..8955090674 100644 --- a/packages/editor-ui/src/components/SettingsLogStreaming/EventDestinationSettingsModal.ee.vue +++ b/packages/editor-ui/src/components/SettingsLogStreaming/EventDestinationSettingsModal.ee.vue @@ -1,17 +1,15 @@ -