@n8n/n8n-nodes-langchain 1.100.1 → 1.101.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/credentials/WeaviateApi.credentials.js +164 -0
- package/dist/credentials/WeaviateApi.credentials.js.map +1 -0
- package/dist/known/credentials.json +7 -0
- package/dist/known/nodes.json +4 -0
- package/dist/nodes/agents/Agent/Agent.node.js +5 -2
- package/dist/nodes/agents/Agent/Agent.node.js.map +1 -1
- package/dist/nodes/agents/Agent/V1/AgentV1.node.js +1 -4
- package/dist/nodes/agents/Agent/V1/AgentV1.node.js.map +1 -1
- package/dist/nodes/agents/Agent/V2/AgentV2.node.js +23 -6
- package/dist/nodes/agents/Agent/V2/AgentV2.node.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/SqlAgent/description.js +0 -1
- package/dist/nodes/agents/Agent/agents/SqlAgent/description.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V2/description.js +29 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V2/description.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V2/execute.js +83 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/V2/execute.js.map +1 -1
- package/dist/nodes/agents/Agent/agents/ToolsAgent/common.js.map +1 -1
- package/dist/nodes/agents/OpenAiAssistant/OpenAiAssistant.node.js +0 -1
- package/dist/nodes/agents/OpenAiAssistant/OpenAiAssistant.node.js.map +1 -1
- package/dist/nodes/chains/ChainRetrievalQA/ChainRetrievalQa.node.js +0 -1
- package/dist/nodes/chains/ChainRetrievalQA/ChainRetrievalQa.node.js.map +1 -1
- package/dist/nodes/chains/ChainSummarization/V1/ChainSummarizationV1.node.js +0 -1
- package/dist/nodes/chains/ChainSummarization/V1/ChainSummarizationV1.node.js.map +1 -1
- package/dist/nodes/chains/ChainSummarization/V2/ChainSummarizationV2.node.js +0 -1
- package/dist/nodes/chains/ChainSummarization/V2/ChainSummarizationV2.node.js.map +1 -1
- package/dist/nodes/code/Code.node.js.map +1 -1
- package/dist/nodes/document_loaders/DocumentBinaryInputLoader/DocumentBinaryInputLoader.node.js +0 -2
- package/dist/nodes/document_loaders/DocumentBinaryInputLoader/DocumentBinaryInputLoader.node.js.map +1 -1
- package/dist/nodes/document_loaders/DocumentDefaultDataLoader/DocumentDefaultDataLoader.node.js +0 -2
- package/dist/nodes/document_loaders/DocumentDefaultDataLoader/DocumentDefaultDataLoader.node.js.map +1 -1
- package/dist/nodes/document_loaders/DocumentGithubLoader/DocumentGithubLoader.node.js +0 -2
- package/dist/nodes/document_loaders/DocumentGithubLoader/DocumentGithubLoader.node.js.map +1 -1
- package/dist/nodes/document_loaders/DocumentJSONInputLoader/DocumentJsonInputLoader.node.js +0 -2
- package/dist/nodes/document_loaders/DocumentJSONInputLoader/DocumentJsonInputLoader.node.js.map +1 -1
- package/dist/nodes/embeddings/EmbeddingsAwsBedrock/EmbeddingsAwsBedrock.node.js +0 -2
- package/dist/nodes/embeddings/EmbeddingsAwsBedrock/EmbeddingsAwsBedrock.node.js.map +1 -1
- package/dist/nodes/embeddings/EmbeddingsAzureOpenAi/EmbeddingsAzureOpenAi.node.js +0 -2
- package/dist/nodes/embeddings/EmbeddingsAzureOpenAi/EmbeddingsAzureOpenAi.node.js.map +1 -1
- package/dist/nodes/embeddings/EmbeddingsCohere/EmbeddingsCohere.node.js +0 -2
- package/dist/nodes/embeddings/EmbeddingsCohere/EmbeddingsCohere.node.js.map +1 -1
- package/dist/nodes/embeddings/EmbeddingsGoogleGemini/EmbeddingsGoogleGemini.node.js +0 -2
- package/dist/nodes/embeddings/EmbeddingsGoogleGemini/EmbeddingsGoogleGemini.node.js.map +1 -1
- package/dist/nodes/embeddings/EmbeddingsGoogleVertex/EmbeddingsGoogleVertex.node.js +0 -2
- package/dist/nodes/embeddings/EmbeddingsGoogleVertex/EmbeddingsGoogleVertex.node.js.map +1 -1
- package/dist/nodes/embeddings/EmbeddingsHuggingFaceInference/EmbeddingsHuggingFaceInference.node.js +0 -2
- package/dist/nodes/embeddings/EmbeddingsHuggingFaceInference/EmbeddingsHuggingFaceInference.node.js.map +1 -1
- package/dist/nodes/embeddings/EmbeddingsMistralCloud/EmbeddingsMistralCloud.node.js +0 -2
- package/dist/nodes/embeddings/EmbeddingsMistralCloud/EmbeddingsMistralCloud.node.js.map +1 -1
- package/dist/nodes/embeddings/EmbeddingsOllama/EmbeddingsOllama.node.js +0 -2
- package/dist/nodes/embeddings/EmbeddingsOllama/EmbeddingsOllama.node.js.map +1 -1
- package/dist/nodes/embeddings/EmbeddingsOpenAI/EmbeddingsOpenAi.node.js +0 -2
- package/dist/nodes/embeddings/EmbeddingsOpenAI/EmbeddingsOpenAi.node.js.map +1 -1
- package/dist/nodes/llms/LMChatAnthropic/LmChatAnthropic.node.js +4 -5
- package/dist/nodes/llms/LMChatAnthropic/LmChatAnthropic.node.js.map +1 -1
- package/dist/nodes/llms/LMChatOllama/LmChatOllama.node.js +0 -3
- package/dist/nodes/llms/LMChatOllama/LmChatOllama.node.js.map +1 -1
- package/dist/nodes/llms/LMChatOpenAi/LmChatOpenAi.node.js +6 -6
- package/dist/nodes/llms/LMChatOpenAi/LmChatOpenAi.node.js.map +1 -1
- package/dist/nodes/llms/LMChatOpenAi/methods/loadModels.js +3 -1
- package/dist/nodes/llms/LMChatOpenAi/methods/loadModels.js.map +1 -1
- package/dist/nodes/llms/LMCohere/LmCohere.node.js +0 -3
- package/dist/nodes/llms/LMCohere/LmCohere.node.js.map +1 -1
- package/dist/nodes/llms/LMOllama/LmOllama.node.js +0 -3
- package/dist/nodes/llms/LMOllama/LmOllama.node.js.map +1 -1
- package/dist/nodes/llms/LMOpenAi/LmOpenAi.node.js +3 -4
- package/dist/nodes/llms/LMOpenAi/LmOpenAi.node.js.map +1 -1
- package/dist/nodes/llms/LMOpenHuggingFaceInference/LmOpenHuggingFaceInference.node.js +0 -3
- package/dist/nodes/llms/LMOpenHuggingFaceInference/LmOpenHuggingFaceInference.node.js.map +1 -1
- package/dist/nodes/llms/LmChatAwsBedrock/LmChatAwsBedrock.node.js +1 -5
- package/dist/nodes/llms/LmChatAwsBedrock/LmChatAwsBedrock.node.js.map +1 -1
- package/dist/nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.js +3 -4
- package/dist/nodes/llms/LmChatAzureOpenAi/LmChatAzureOpenAi.node.js.map +1 -1
- package/dist/nodes/llms/LmChatDeepSeek/LmChatDeepSeek.node.js +3 -4
- package/dist/nodes/llms/LmChatDeepSeek/LmChatDeepSeek.node.js.map +1 -1
- package/dist/nodes/llms/LmChatGoogleGemini/LmChatGoogleGemini.node.js +0 -3
- package/dist/nodes/llms/LmChatGoogleGemini/LmChatGoogleGemini.node.js.map +1 -1
- package/dist/nodes/llms/LmChatGoogleVertex/LmChatGoogleVertex.node.js +0 -3
- package/dist/nodes/llms/LmChatGoogleVertex/LmChatGoogleVertex.node.js.map +1 -1
- package/dist/nodes/llms/LmChatGroq/LmChatGroq.node.js +1 -4
- package/dist/nodes/llms/LmChatGroq/LmChatGroq.node.js.map +1 -1
- package/dist/nodes/llms/LmChatMistralCloud/LmChatMistralCloud.node.js +0 -3
- package/dist/nodes/llms/LmChatMistralCloud/LmChatMistralCloud.node.js.map +1 -1
- package/dist/nodes/llms/LmChatOpenRouter/LmChatOpenRouter.node.js +3 -3
- package/dist/nodes/llms/LmChatOpenRouter/LmChatOpenRouter.node.js.map +1 -1
- package/dist/nodes/llms/LmChatXAiGrok/LmChatXAiGrok.node.js +3 -4
- package/dist/nodes/llms/LmChatXAiGrok/LmChatXAiGrok.node.js.map +1 -1
- package/dist/nodes/llms/N8nLlmTracing.js.map +1 -1
- package/dist/nodes/llms/N8nNonEstimatingTracing.js.map +1 -1
- package/dist/nodes/llms/n8nDefaultFailedAttemptHandler.js +1 -1
- package/dist/nodes/llms/n8nDefaultFailedAttemptHandler.js.map +1 -1
- package/dist/nodes/memory/MemoryBufferWindow/MemoryBufferWindow.node.js +0 -2
- package/dist/nodes/memory/MemoryBufferWindow/MemoryBufferWindow.node.js.map +1 -1
- package/dist/nodes/memory/MemoryChatRetriever/MemoryChatRetriever.node.js +0 -2
- package/dist/nodes/memory/MemoryChatRetriever/MemoryChatRetriever.node.js.map +1 -1
- package/dist/nodes/memory/MemoryManager/MemoryManager.node.js +0 -2
- package/dist/nodes/memory/MemoryManager/MemoryManager.node.js.map +1 -1
- package/dist/nodes/memory/MemoryMotorhead/MemoryMotorhead.node.js +0 -2
- package/dist/nodes/memory/MemoryMotorhead/MemoryMotorhead.node.js.map +1 -1
- package/dist/nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.js +0 -2
- package/dist/nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.js.map +1 -1
- package/dist/nodes/memory/MemoryRedisChat/MemoryRedisChat.node.js +0 -2
- package/dist/nodes/memory/MemoryRedisChat/MemoryRedisChat.node.js.map +1 -1
- package/dist/nodes/memory/MemoryXata/MemoryXata.node.js +0 -2
- package/dist/nodes/memory/MemoryXata/MemoryXata.node.js.map +1 -1
- package/dist/nodes/memory/MemoryZep/MemoryZep.node.js +0 -2
- package/dist/nodes/memory/MemoryZep/MemoryZep.node.js.map +1 -1
- package/dist/nodes/output_parser/OutputParserAutofixing/OutputParserAutofixing.node.js +0 -2
- package/dist/nodes/output_parser/OutputParserAutofixing/OutputParserAutofixing.node.js.map +1 -1
- package/dist/nodes/output_parser/OutputParserItemList/OutputParserItemList.node.js +0 -2
- package/dist/nodes/output_parser/OutputParserItemList/OutputParserItemList.node.js.map +1 -1
- package/dist/nodes/output_parser/OutputParserStructured/OutputParserStructured.node.js +0 -1
- package/dist/nodes/output_parser/OutputParserStructured/OutputParserStructured.node.js.map +1 -1
- package/dist/nodes/rerankers/RerankerCohere/RerankerCohere.node.js.map +1 -1
- package/dist/nodes/retrievers/RetrieverContextualCompression/RetrieverContextualCompression.node.js +0 -1
- package/dist/nodes/retrievers/RetrieverContextualCompression/RetrieverContextualCompression.node.js.map +1 -1
- package/dist/nodes/retrievers/RetrieverMultiQuery/RetrieverMultiQuery.node.js +0 -1
- package/dist/nodes/retrievers/RetrieverMultiQuery/RetrieverMultiQuery.node.js.map +1 -1
- package/dist/nodes/retrievers/RetrieverVectorStore/RetrieverVectorStore.node.js +0 -2
- package/dist/nodes/retrievers/RetrieverVectorStore/RetrieverVectorStore.node.js.map +1 -1
- package/dist/nodes/retrievers/RetrieverWorkflow/RetrieverWorkflow.node.js.map +1 -1
- package/dist/nodes/text_splitters/TextSplitterCharacterTextSplitter/TextSplitterCharacterTextSplitter.node.js +0 -2
- package/dist/nodes/text_splitters/TextSplitterCharacterTextSplitter/TextSplitterCharacterTextSplitter.node.js.map +1 -1
- package/dist/nodes/text_splitters/TextSplitterRecursiveCharacterTextSplitter/TextSplitterRecursiveCharacterTextSplitter.node.js +0 -2
- package/dist/nodes/text_splitters/TextSplitterRecursiveCharacterTextSplitter/TextSplitterRecursiveCharacterTextSplitter.node.js.map +1 -1
- package/dist/nodes/text_splitters/TextSplitterTokenSplitter/TextSplitterTokenSplitter.node.js +0 -2
- package/dist/nodes/text_splitters/TextSplitterTokenSplitter/TextSplitterTokenSplitter.node.js.map +1 -1
- package/dist/nodes/text_splitters/TextSplitterTokenSplitter/TokenTextSplitter.js.map +1 -1
- package/dist/nodes/tools/ToolCalculator/ToolCalculator.node.js +0 -2
- package/dist/nodes/tools/ToolCalculator/ToolCalculator.node.js.map +1 -1
- package/dist/nodes/tools/ToolCode/ToolCode.node.js +0 -2
- package/dist/nodes/tools/ToolCode/ToolCode.node.js.map +1 -1
- package/dist/nodes/tools/ToolHttpRequest/ToolHttpRequest.node.js +0 -2
- package/dist/nodes/tools/ToolHttpRequest/ToolHttpRequest.node.js.map +1 -1
- package/dist/nodes/tools/ToolHttpRequest/utils.js.map +1 -1
- package/dist/nodes/tools/ToolSerpApi/ToolSerpApi.node.js +0 -2
- package/dist/nodes/tools/ToolSerpApi/ToolSerpApi.node.js.map +1 -1
- package/dist/nodes/tools/ToolThink/ToolThink.node.js.map +1 -1
- package/dist/nodes/tools/ToolVectorStore/ToolVectorStore.node.js +0 -2
- package/dist/nodes/tools/ToolVectorStore/ToolVectorStore.node.js.map +1 -1
- package/dist/nodes/tools/ToolWikipedia/ToolWikipedia.node.js +0 -2
- package/dist/nodes/tools/ToolWikipedia/ToolWikipedia.node.js.map +1 -1
- package/dist/nodes/tools/ToolWolframAlpha/ToolWolframAlpha.node.js +0 -2
- package/dist/nodes/tools/ToolWolframAlpha/ToolWolframAlpha.node.js.map +1 -1
- package/dist/nodes/tools/ToolWorkflow/v1/versionDescription.js +0 -2
- package/dist/nodes/tools/ToolWorkflow/v1/versionDescription.js.map +1 -1
- package/dist/nodes/tools/ToolWorkflow/v2/versionDescription.js.map +1 -1
- package/dist/nodes/trigger/ChatTrigger/ChatTrigger.node.js +215 -153
- package/dist/nodes/trigger/ChatTrigger/ChatTrigger.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStoreInMemory/VectorStoreInMemory.node.js +1 -1
- package/dist/nodes/vector_store/VectorStoreInMemory/VectorStoreInMemory.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStoreInMemoryInsert/VectorStoreInMemoryInsert.node.js +0 -1
- package/dist/nodes/vector_store/VectorStoreInMemoryInsert/VectorStoreInMemoryInsert.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStoreInMemoryLoad/VectorStoreInMemoryLoad.node.js +0 -1
- package/dist/nodes/vector_store/VectorStoreInMemoryLoad/VectorStoreInMemoryLoad.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStorePGVector/VectorStorePGVector.node.js +2 -2
- package/dist/nodes/vector_store/VectorStorePGVector/VectorStorePGVector.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStoreQdrant/VectorStoreQdrant.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStoreSupabaseLoad/VectorStoreSupabaseLoad.node.js.map +1 -1
- package/dist/nodes/vector_store/VectorStoreWeaviate/VectorStoreWeaviate.node.js +242 -0
- package/dist/nodes/vector_store/VectorStoreWeaviate/VectorStoreWeaviate.node.js.map +1 -0
- package/dist/nodes/vector_store/VectorStoreWeaviate/Weaviate.utils.js +127 -0
- package/dist/nodes/vector_store/VectorStoreWeaviate/Weaviate.utils.js.map +1 -0
- package/dist/nodes/vector_store/VectorStoreWeaviate/weaviate.svg +2 -0
- package/dist/nodes/vector_store/shared/createVectorStoreNode/createVectorStoreNode.js +0 -1
- package/dist/nodes/vector_store/shared/createVectorStoreNode/createVectorStoreNode.js.map +1 -1
- package/dist/nodes/vector_store/shared/createVectorStoreNode/methods/listSearch.js +15 -2
- package/dist/nodes/vector_store/shared/createVectorStoreNode/methods/listSearch.js.map +1 -1
- package/dist/nodes/vector_store/shared/descriptions.js +26 -2
- package/dist/nodes/vector_store/shared/descriptions.js.map +1 -1
- package/dist/nodes/vendors/OpenAi/actions/assistant/message.operation.js +0 -1
- package/dist/nodes/vendors/OpenAi/actions/assistant/message.operation.js.map +1 -1
- package/dist/nodes/vendors/OpenAi/actions/versionDescription.js.map +1 -1
- package/dist/types/credentials.json +1 -0
- package/dist/types/nodes.json +4 -3
- package/dist/utils/httpProxyAgent.js +20 -6
- package/dist/utils/httpProxyAgent.js.map +1 -1
- package/dist/utils/logWrapper.js.map +1 -1
- package/package.json +21 -15
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../nodes/llms/N8nNonEstimatingTracing.ts"],"sourcesContent":["import { BaseCallbackHandler } from '@langchain/core/callbacks/base';\nimport type { SerializedFields } from '@langchain/core/dist/load/map_keys';\nimport type {\n\tSerialized,\n\tSerializedNotImplemented,\n\tSerializedSecret,\n} from '@langchain/core/load/serializable';\nimport type { BaseMessage } from '@langchain/core/messages';\nimport type { LLMResult } from '@langchain/core/outputs';\nimport pick from 'lodash/pick';\nimport type { IDataObject, ISupplyDataFunctions, JsonObject } from 'n8n-workflow';\nimport { NodeConnectionTypes, NodeError, NodeOperationError } from 'n8n-workflow';\n\nimport { logAiEvent } from '@utils/helpers';\n\ntype RunDetail = {\n\tindex: number;\n\tmessages: BaseMessage[] | string[] | string;\n\toptions: SerializedSecret | SerializedNotImplemented | SerializedFields;\n};\n\nexport class N8nNonEstimatingTracing extends BaseCallbackHandler {\n\tname = 'N8nNonEstimatingTracing';\n\n\t// This flag makes sure that LangChain will wait for the handlers to finish before continuing\n\t// This is crucial for the handleLLMError handler to work correctly (it should be called before the error is propagated to the root node)\n\tawaitHandlers = true;\n\n\tconnectionType = NodeConnectionTypes.AiLanguageModel;\n\n\t#parentRunIndex?: number;\n\n\t/**\n\t * A map to associate LLM run IDs to run details.\n\t * Key: Unique identifier for each LLM run (run ID)\n\t * Value: RunDetails object\n\t *\n\t */\n\trunsMap: Record<string, RunDetail> = {};\n\n\toptions = {\n\t\t// Default(OpenAI format) parser\n\t\terrorDescriptionMapper: (error: NodeError) => error.description,\n\t};\n\n\tconstructor(\n\t\tprivate executionFunctions: ISupplyDataFunctions,\n\t\toptions?: {\n\t\t\terrorDescriptionMapper?: (error: NodeError) => string;\n\t\t},\n\t) {\n\t\tsuper();\n\t\tthis.options = { ...this.options, ...options };\n\t}\n\n\tasync handleLLMEnd(output: LLMResult, runId: string) {\n\t\t// The fallback should never happen since handleLLMStart should always set the run details\n\t\t// but just in case, we set the index to the length of the runsMap\n\t\tconst runDetails = this.runsMap[runId] ?? { index: Object.keys(this.runsMap).length };\n\n\t\toutput.generations = output.generations.map((gen) =>\n\t\t\tgen.map((g) => pick(g, ['text', 'generationInfo'])),\n\t\t);\n\n\t\tconst tokenUsageEstimate = {\n\t\t\tcompletionTokens: 0,\n\t\t\tpromptTokens: 0,\n\t\t\ttotalTokens: 0,\n\t\t};\n\t\tconst response: {\n\t\t\tresponse: { generations: LLMResult['generations'] };\n\t\t\ttokenUsageEstimate?: typeof tokenUsageEstimate;\n\t\t} = {\n\t\t\tresponse: { generations: output.generations },\n\t\t};\n\n\t\tresponse.tokenUsageEstimate = tokenUsageEstimate;\n\n\t\tconst parsedMessages =\n\t\t\ttypeof runDetails.messages === 'string'\n\t\t\t\t? runDetails.messages\n\t\t\t\t: runDetails.messages.map((message) => {\n\t\t\t\t\t\tif (typeof message === 'string') return message;\n\t\t\t\t\t\tif (typeof message?.toJSON === 'function') return message.toJSON();\n\n\t\t\t\t\t\treturn message;\n\t\t\t\t\t});\n\n\t\tconst sourceNodeRunIndex =\n\t\t\tthis.#parentRunIndex !== undefined ? this.#parentRunIndex + runDetails.index : undefined;\n\n\t\tthis.executionFunctions.addOutputData(\n\t\t\tthis.connectionType,\n\t\t\trunDetails.index,\n\t\t\t[[{ json: { ...response } }]],\n\t\t\tundefined,\n\t\t\tsourceNodeRunIndex,\n\t\t);\n\n\t\tlogAiEvent(this.executionFunctions, 'ai-llm-generated-output', {\n\t\t\tmessages: parsedMessages,\n\t\t\toptions: runDetails.options,\n\t\t\tresponse,\n\t\t});\n\t}\n\n\tasync handleLLMStart(llm: Serialized, prompts: string[], runId: string) {\n\t\tconst estimatedTokens = 0;\n\t\tconst sourceNodeRunIndex =\n\t\t\tthis.#parentRunIndex !== undefined\n\t\t\t\t? this.#parentRunIndex + this.executionFunctions.getNextRunIndex()\n\t\t\t\t: undefined;\n\n\t\tconst options = llm.type === 'constructor' ? llm.kwargs : llm;\n\t\tconst { index } = this.executionFunctions.addInputData(\n\t\t\tthis.connectionType,\n\t\t\t[\n\t\t\t\t[\n\t\t\t\t\t{\n\t\t\t\t\t\tjson: {\n\t\t\t\t\t\t\tmessages: prompts,\n\t\t\t\t\t\t\testimatedTokens,\n\t\t\t\t\t\t\toptions,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t],\n\t\t\tsourceNodeRunIndex,\n\t\t);\n\n\t\t// Save the run details for later use when processing `handleLLMEnd` event\n\t\tthis.runsMap[runId] = {\n\t\t\tindex,\n\t\t\toptions,\n\t\t\tmessages: prompts,\n\t\t};\n\t}\n\n\tasync handleLLMError(
|
|
1
|
+
{"version":3,"sources":["../../../nodes/llms/N8nNonEstimatingTracing.ts"],"sourcesContent":["import { BaseCallbackHandler } from '@langchain/core/callbacks/base';\nimport type { SerializedFields } from '@langchain/core/dist/load/map_keys';\nimport type {\n\tSerialized,\n\tSerializedNotImplemented,\n\tSerializedSecret,\n} from '@langchain/core/load/serializable';\nimport type { BaseMessage } from '@langchain/core/messages';\nimport type { LLMResult } from '@langchain/core/outputs';\nimport pick from 'lodash/pick';\nimport type { IDataObject, ISupplyDataFunctions, JsonObject } from 'n8n-workflow';\nimport { NodeConnectionTypes, NodeError, NodeOperationError } from 'n8n-workflow';\n\nimport { logAiEvent } from '@utils/helpers';\n\ntype RunDetail = {\n\tindex: number;\n\tmessages: BaseMessage[] | string[] | string;\n\toptions: SerializedSecret | SerializedNotImplemented | SerializedFields;\n};\n\nexport class N8nNonEstimatingTracing extends BaseCallbackHandler {\n\tname = 'N8nNonEstimatingTracing';\n\n\t// This flag makes sure that LangChain will wait for the handlers to finish before continuing\n\t// This is crucial for the handleLLMError handler to work correctly (it should be called before the error is propagated to the root node)\n\tawaitHandlers = true;\n\n\tconnectionType = NodeConnectionTypes.AiLanguageModel;\n\n\t#parentRunIndex?: number;\n\n\t/**\n\t * A map to associate LLM run IDs to run details.\n\t * Key: Unique identifier for each LLM run (run ID)\n\t * Value: RunDetails object\n\t *\n\t */\n\trunsMap: Record<string, RunDetail> = {};\n\n\toptions = {\n\t\t// Default(OpenAI format) parser\n\t\terrorDescriptionMapper: (error: NodeError) => error.description,\n\t};\n\n\tconstructor(\n\t\tprivate executionFunctions: ISupplyDataFunctions,\n\t\toptions?: {\n\t\t\terrorDescriptionMapper?: (error: NodeError) => string;\n\t\t},\n\t) {\n\t\tsuper();\n\t\tthis.options = { ...this.options, ...options };\n\t}\n\n\tasync handleLLMEnd(output: LLMResult, runId: string) {\n\t\t// The fallback should never happen since handleLLMStart should always set the run details\n\t\t// but just in case, we set the index to the length of the runsMap\n\t\tconst runDetails = this.runsMap[runId] ?? { index: Object.keys(this.runsMap).length };\n\n\t\toutput.generations = output.generations.map((gen) =>\n\t\t\tgen.map((g) => pick(g, ['text', 'generationInfo'])),\n\t\t);\n\n\t\tconst tokenUsageEstimate = {\n\t\t\tcompletionTokens: 0,\n\t\t\tpromptTokens: 0,\n\t\t\ttotalTokens: 0,\n\t\t};\n\t\tconst response: {\n\t\t\tresponse: { generations: LLMResult['generations'] };\n\t\t\ttokenUsageEstimate?: typeof tokenUsageEstimate;\n\t\t} = {\n\t\t\tresponse: { generations: output.generations },\n\t\t};\n\n\t\tresponse.tokenUsageEstimate = tokenUsageEstimate;\n\n\t\tconst parsedMessages =\n\t\t\ttypeof runDetails.messages === 'string'\n\t\t\t\t? runDetails.messages\n\t\t\t\t: runDetails.messages.map((message) => {\n\t\t\t\t\t\tif (typeof message === 'string') return message;\n\t\t\t\t\t\tif (typeof message?.toJSON === 'function') return message.toJSON();\n\n\t\t\t\t\t\treturn message;\n\t\t\t\t\t});\n\n\t\tconst sourceNodeRunIndex =\n\t\t\tthis.#parentRunIndex !== undefined ? this.#parentRunIndex + runDetails.index : undefined;\n\n\t\tthis.executionFunctions.addOutputData(\n\t\t\tthis.connectionType,\n\t\t\trunDetails.index,\n\t\t\t[[{ json: { ...response } }]],\n\t\t\tundefined,\n\t\t\tsourceNodeRunIndex,\n\t\t);\n\n\t\tlogAiEvent(this.executionFunctions, 'ai-llm-generated-output', {\n\t\t\tmessages: parsedMessages,\n\t\t\toptions: runDetails.options,\n\t\t\tresponse,\n\t\t});\n\t}\n\n\tasync handleLLMStart(llm: Serialized, prompts: string[], runId: string) {\n\t\tconst estimatedTokens = 0;\n\t\tconst sourceNodeRunIndex =\n\t\t\tthis.#parentRunIndex !== undefined\n\t\t\t\t? this.#parentRunIndex + this.executionFunctions.getNextRunIndex()\n\t\t\t\t: undefined;\n\n\t\tconst options = llm.type === 'constructor' ? llm.kwargs : llm;\n\t\tconst { index } = this.executionFunctions.addInputData(\n\t\t\tthis.connectionType,\n\t\t\t[\n\t\t\t\t[\n\t\t\t\t\t{\n\t\t\t\t\t\tjson: {\n\t\t\t\t\t\t\tmessages: prompts,\n\t\t\t\t\t\t\testimatedTokens,\n\t\t\t\t\t\t\toptions,\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t],\n\t\t\tsourceNodeRunIndex,\n\t\t);\n\n\t\t// Save the run details for later use when processing `handleLLMEnd` event\n\t\tthis.runsMap[runId] = {\n\t\t\tindex,\n\t\t\toptions,\n\t\t\tmessages: prompts,\n\t\t};\n\t}\n\n\tasync handleLLMError(error: IDataObject | Error, runId: string, parentRunId?: string) {\n\t\tconst runDetails = this.runsMap[runId] ?? { index: Object.keys(this.runsMap).length };\n\n\t\t// Filter out non-x- headers to avoid leaking sensitive information in logs\n\t\tif (typeof error === 'object' && error?.hasOwnProperty('headers')) {\n\t\t\tconst errorWithHeaders = error as { headers: Record<string, unknown> };\n\n\t\t\tObject.keys(errorWithHeaders.headers).forEach((key) => {\n\t\t\t\tif (!key.startsWith('x-')) {\n\t\t\t\t\tdelete errorWithHeaders.headers[key];\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\n\t\tif (error instanceof NodeError) {\n\t\t\tif (this.options.errorDescriptionMapper) {\n\t\t\t\terror.description = this.options.errorDescriptionMapper(error);\n\t\t\t}\n\n\t\t\tthis.executionFunctions.addOutputData(this.connectionType, runDetails.index, error);\n\t\t} else {\n\t\t\t// If the error is not a NodeError, we wrap it in a NodeOperationError\n\t\t\tthis.executionFunctions.addOutputData(\n\t\t\t\tthis.connectionType,\n\t\t\t\trunDetails.index,\n\t\t\t\tnew NodeOperationError(this.executionFunctions.getNode(), error as JsonObject, {\n\t\t\t\t\tfunctionality: 'configuration-node',\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tlogAiEvent(this.executionFunctions, 'ai-llm-errored', {\n\t\t\terror: Object.keys(error).length === 0 ? error.toString() : error,\n\t\t\trunId,\n\t\t\tparentRunId,\n\t\t});\n\t}\n\n\t// Used to associate subsequent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;AAAA,MACD,CAAC;AAAA,IACF;AAEA,QAAI,iBAAiB,+BAAW;AAC/B,UAAI,KAAK,QAAQ,wBAAwB;AACxC,cAAM,cAAc,KAAK,QAAQ,uBAAuB,KAAK;AAAA,MAC9D;AAEA,WAAK,mBAAmB,cAAc,KAAK,gBAAgB,WAAW,OAAO,KAAK;AAAA,IACnF,OAAO;AAEN,WAAK,mBAAmB;AAAA,QACvB,KAAK;AAAA,QACL,WAAW;AAAA,QACX,IAAI,uCAAmB,KAAK,mBAAmB,QAAQ,GAAG,OAAqB;AAAA,UAC9E,eAAe;AAAA,QAChB,CAAC;AAAA,MACF;AAAA,IACD;AAEA,mCAAW,KAAK,oBAAoB,kBAAkB;AAAA,MACrD,OAAO,OAAO,KAAK,KAAK,EAAE,WAAW,IAAI,MAAM,SAAS,IAAI;AAAA,MAC5D;AAAA,MACA;AAAA,IACD,CAAC;AAAA,EACF;AAAA;AAAA,EAGA,kBAAkB,UAAkB;AACnC,uBAAK,iBAAkB;AAAA,EACxB;AACD;AAtJC;","names":["pick"]}
|
|
@@ -52,7 +52,7 @@ const n8nDefaultFailedAttemptHandler = (error) => {
|
|
|
52
52
|
throw error;
|
|
53
53
|
}
|
|
54
54
|
const status = (
|
|
55
|
-
// eslint-disable-next-line @typescript-eslint/no-
|
|
55
|
+
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
|
56
56
|
error?.response?.status ?? error?.status
|
|
57
57
|
);
|
|
58
58
|
if (status && STATUS_NO_RETRY.includes(+status)) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../nodes/llms/n8nDefaultFailedAttemptHandler.ts"],"sourcesContent":["const STATUS_NO_RETRY = [\n\t400, // Bad Request\n\t401, // Unauthorized\n\t402, // Payment Required\n\t403, // Forbidden\n\t404, // Not Found\n\t405, // Method Not Allowed\n\t406, // Not Acceptable\n\t407, // Proxy Authentication Required\n\t409, // Conflict\n];\n\n/**\n * This function is used as a default handler for failed attempts in all LLMs.\n * It is based on a default handler from the langchain core package.\n * It throws an error when it encounters a known error that should not be retried.\n * @param error\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const n8nDefaultFailedAttemptHandler = (error: any) => {\n\tif (\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call\n\t\terror?.message?.startsWith?.('Cancel') ||\n\t\terror?.message?.startsWith?.('AbortError') ||\n\t\terror?.name === 'AbortError'\n\t) {\n\t\tthrow error;\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/no-
|
|
1
|
+
{"version":3,"sources":["../../../nodes/llms/n8nDefaultFailedAttemptHandler.ts"],"sourcesContent":["const STATUS_NO_RETRY = [\n\t400, // Bad Request\n\t401, // Unauthorized\n\t402, // Payment Required\n\t403, // Forbidden\n\t404, // Not Found\n\t405, // Method Not Allowed\n\t406, // Not Acceptable\n\t407, // Proxy Authentication Required\n\t409, // Conflict\n];\n\n/**\n * This function is used as a default handler for failed attempts in all LLMs.\n * It is based on a default handler from the langchain core package.\n * It throws an error when it encounters a known error that should not be retried.\n * @param error\n */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const n8nDefaultFailedAttemptHandler = (error: any) => {\n\tif (\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access,@typescript-eslint/no-unsafe-call\n\t\terror?.message?.startsWith?.('Cancel') ||\n\t\terror?.message?.startsWith?.('AbortError') ||\n\t\terror?.name === 'AbortError'\n\t) {\n\t\tthrow error;\n\t}\n\n\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\tif (error?.code === 'ECONNABORTED') {\n\t\tthrow error;\n\t}\n\n\tconst status =\n\t\t// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access\n\t\terror?.response?.status ?? error?.status;\n\tif (status && STATUS_NO_RETRY.includes(+status)) {\n\t\tthrow error;\n\t}\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,MAAM,kBAAkB;AAAA,EACvB;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AAAA,EACA;AAAA;AACD;AASO,MAAM,iCAAiC,CAAC,UAAe;AAC7D;AAAA;AAAA,IAEC,OAAO,SAAS,aAAa,QAAQ,KACrC,OAAO,SAAS,aAAa,YAAY,KACzC,OAAO,SAAS;AAAA,IACf;AACD,UAAM;AAAA,EACP;AAGA,MAAI,OAAO,SAAS,gBAAgB;AACnC,UAAM;AAAA,EACP;AAEA,QAAM;AAAA;AAAA,IAEL,OAAO,UAAU,UAAU,OAAO;AAAA;AACnC,MAAI,UAAU,gBAAgB,SAAS,CAAC,MAAM,GAAG;AAChD,UAAM;AAAA,EACP;AACD;","names":[]}
|
|
@@ -90,9 +90,7 @@ class MemoryBufferWindow {
|
|
|
90
90
|
]
|
|
91
91
|
}
|
|
92
92
|
},
|
|
93
|
-
// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node
|
|
94
93
|
inputs: [],
|
|
95
|
-
// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong
|
|
96
94
|
outputs: [import_n8n_workflow.NodeConnectionTypes.AiMemory],
|
|
97
95
|
outputNames: ["Memory"],
|
|
98
96
|
properties: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/memory/MemoryBufferWindow/MemoryBufferWindow.node.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/memory/MemoryBufferWindow/MemoryBufferWindow.node.ts"],"sourcesContent":["import type { BufferWindowMemoryInput } from 'langchain/memory';\nimport { BufferWindowMemory } from 'langchain/memory';\nimport {\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { getSessionId } from '@utils/helpers';\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nimport {\n\tsessionIdOption,\n\tsessionKeyProperty,\n\tcontextWindowLengthProperty,\n\texpressionSessionKeyProperty,\n} from '../descriptions';\n\nclass MemoryChatBufferSingleton {\n\tprivate static instance: MemoryChatBufferSingleton;\n\n\tprivate memoryBuffer: Map<\n\t\tstring,\n\t\t{ buffer: BufferWindowMemory; created: Date; last_accessed: Date }\n\t>;\n\n\tprivate constructor() {\n\t\tthis.memoryBuffer = new Map();\n\t}\n\n\tstatic getInstance(): MemoryChatBufferSingleton {\n\t\tif (!MemoryChatBufferSingleton.instance) {\n\t\t\tMemoryChatBufferSingleton.instance = new MemoryChatBufferSingleton();\n\t\t}\n\t\treturn MemoryChatBufferSingleton.instance;\n\t}\n\n\tasync getMemory(\n\t\tsessionKey: string,\n\t\tmemoryParams: BufferWindowMemoryInput,\n\t): Promise<BufferWindowMemory> {\n\t\tawait this.cleanupStaleBuffers();\n\n\t\tlet memoryInstance = this.memoryBuffer.get(sessionKey);\n\t\tif (memoryInstance) {\n\t\t\tmemoryInstance.last_accessed = new Date();\n\t\t} else {\n\t\t\tconst newMemory = new BufferWindowMemory(memoryParams);\n\n\t\t\tmemoryInstance = {\n\t\t\t\tbuffer: newMemory,\n\t\t\t\tcreated: new Date(),\n\t\t\t\tlast_accessed: new Date(),\n\t\t\t};\n\t\t\tthis.memoryBuffer.set(sessionKey, memoryInstance);\n\t\t}\n\t\treturn memoryInstance.buffer;\n\t}\n\n\tprivate async cleanupStaleBuffers(): Promise<void> {\n\t\tconst oneHourAgo = new Date(Date.now() - 60 * 60 * 1000);\n\n\t\tfor (const [key, memoryInstance] of this.memoryBuffer.entries()) {\n\t\t\tif (memoryInstance.last_accessed < oneHourAgo) {\n\t\t\t\tawait this.memoryBuffer.get(key)?.buffer.clear();\n\t\t\t\tthis.memoryBuffer.delete(key);\n\t\t\t}\n\t\t}\n\t}\n}\n\nexport class MemoryBufferWindow implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Simple Memory',\n\t\tname: 'memoryBufferWindow',\n\t\ticon: 'fa:database',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3],\n\t\tdescription: 'Stores in n8n memory, so no credentials required',\n\t\tdefaults: {\n\t\t\tname: 'Simple Memory',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Memory'],\n\t\t\t\tMemory: ['For beginners'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.memorybufferwindow/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\n\t\tinputs: [],\n\n\t\toutputs: [NodeConnectionTypes.AiMemory],\n\t\toutputNames: ['Memory'],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Session Key',\n\t\t\t\tname: 'sessionKey',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: 'chat_history',\n\t\t\t\tdescription: 'The key to use to store the memory in the workflow data',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Session ID',\n\t\t\t\tname: 'sessionKey',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '={{ $json.sessionId }}',\n\t\t\t\tdescription: 'The key to use to store the memory',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1.1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...sessionIdOption,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.2 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\texpressionSessionKeyProperty(1.3),\n\t\t\tsessionKeyProperty,\n\t\t\tcontextWindowLengthProperty,\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst contextWindowLength = this.getNodeParameter('contextWindowLength', itemIndex) as number;\n\t\tconst workflowId = this.getWorkflow().id;\n\t\tconst memoryInstance = MemoryChatBufferSingleton.getInstance();\n\n\t\tconst nodeVersion = this.getNode().typeVersion;\n\n\t\tlet sessionId;\n\n\t\tif (nodeVersion >= 1.2) {\n\t\t\tsessionId = getSessionId(this, itemIndex);\n\t\t} else {\n\t\t\tsessionId = this.getNodeParameter('sessionKey', itemIndex) as string;\n\t\t}\n\n\t\tconst memory = await memoryInstance.getMemory(`${workflowId}__${sessionId}`, {\n\t\t\tk: contextWindowLength,\n\t\t\tinputKey: 'input',\n\t\t\tmemoryKey: 'chat_history',\n\t\t\toutputKey: 'output',\n\t\t\treturnMessages: true,\n\t\t});\n\n\t\treturn {\n\t\t\tresponse: logWrapper(memory, this),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,oBAAmC;AACnC,0BAMO;AAEP,qBAA6B;AAC7B,wBAA2B;AAC3B,0BAA6C;AAE7C,0BAKO;AAEP,MAAM,0BAA0B;AAAA,EAQvB,cAAc;AACrB,SAAK,eAAe,oBAAI,IAAI;AAAA,EAC7B;AAAA,EAEA,OAAO,cAAyC;AAC/C,QAAI,CAAC,0BAA0B,UAAU;AACxC,gCAA0B,WAAW,IAAI,0BAA0B;AAAA,IACpE;AACA,WAAO,0BAA0B;AAAA,EAClC;AAAA,EAEA,MAAM,UACL,YACA,cAC8B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jB,CAAC;AAED,WAAO;AAAA,MACN,cAAU,8BAAW,QAAQ,IAAI;AAAA,IAClC;AAAA,EACD;AACD;","names":[]}
|
|
@@ -67,7 +67,6 @@ class MemoryChatRetriever {
|
|
|
67
67
|
]
|
|
68
68
|
}
|
|
69
69
|
},
|
|
70
|
-
// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node
|
|
71
70
|
inputs: [
|
|
72
71
|
import_n8n_workflow.NodeConnectionTypes.Main,
|
|
73
72
|
{
|
|
@@ -77,7 +76,6 @@ class MemoryChatRetriever {
|
|
|
77
76
|
required: true
|
|
78
77
|
}
|
|
79
78
|
],
|
|
80
|
-
// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong
|
|
81
79
|
outputs: [import_n8n_workflow.NodeConnectionTypes.Main],
|
|
82
80
|
properties: [
|
|
83
81
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/memory/MemoryChatRetriever/MemoryChatRetriever.node.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/memory/MemoryChatRetriever/MemoryChatRetriever.node.ts"],"sourcesContent":["import type { BaseChatMemory } from '@langchain/community/memory/chat_memory';\nimport type { BaseMessage } from '@langchain/core/messages';\nimport {\n\tNodeConnectionTypes,\n\ttype IDataObject,\n\ttype IExecuteFunctions,\n\ttype INodeExecutionData,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n} from 'n8n-workflow';\n\nfunction simplifyMessages(messages: BaseMessage[]) {\n\tconst chunkedMessages = [];\n\tfor (let i = 0; i < messages.length; i += 2) {\n\t\tchunkedMessages.push([messages[i], messages[i + 1]]);\n\t}\n\n\tconst transformedMessages = chunkedMessages.map((exchange) => {\n\t\tconst simplified = {\n\t\t\t[exchange[0]._getType()]: exchange[0].content,\n\t\t};\n\n\t\tif (exchange[1]) {\n\t\t\tsimplified[exchange[1]._getType()] = exchange[1].content;\n\t\t}\n\n\t\treturn {\n\t\t\tjson: simplified,\n\t\t};\n\t});\n\treturn transformedMessages;\n}\n\n// This node is deprecated. Use MemoryManager instead.\nexport class MemoryChatRetriever implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Chat Messages Retriever',\n\t\tname: 'memoryChatRetriever',\n\t\ticon: 'fa:database',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\thidden: true,\n\t\tversion: 1,\n\t\tdescription: 'Retrieve chat messages from memory and use them in the workflow',\n\t\tdefaults: {\n\t\t\tname: 'Chat Messages Retriever',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Miscellaneous'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.memorymanager/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\n\t\tinputs: [\n\t\t\tNodeConnectionTypes.Main,\n\t\t\t{\n\t\t\t\tdisplayName: 'Memory',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\ttype: NodeConnectionTypes.AiMemory,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\n\t\toutputs: [NodeConnectionTypes.Main],\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName: \"This node is deprecated. Use 'Chat Memory Manager' node instead.\",\n\t\t\t\ttype: 'notice',\n\t\t\t\tdefault: '',\n\t\t\t\tname: 'deprecatedNotice',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Simplify Output',\n\t\t\t\tname: 'simplifyOutput',\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdescription: 'Whether to simplify the output to only include the sender and the text',\n\t\t\t\tdefault: true,\n\t\t\t},\n\t\t],\n\t};\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tthis.logger.debug('Executing Chat Memory Retriever');\n\n\t\tconst memory = (await this.getInputConnectionData(NodeConnectionTypes.AiMemory, 0)) as\n\t\t\t| BaseChatMemory\n\t\t\t| undefined;\n\t\tconst simplifyOutput = this.getNodeParameter('simplifyOutput', 0) as boolean;\n\n\t\tconst messages = await memory?.chatHistory.getMessages();\n\n\t\tif (simplifyOutput && messages) {\n\t\t\treturn [simplifyMessages(messages)];\n\t\t}\n\n\t\tconst serializedMessages =\n\t\t\tmessages?.map((message) => {\n\t\t\t\tconst serializedMessage = message.toJSON();\n\t\t\t\treturn { json: serializedMessage as unknown as IDataObject };\n\t\t\t}) ?? [];\n\n\t\treturn [serializedMessages];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,0BAOO;AAEP,SAAS,iBAAiB,UAAyB;AAClD,QAAM,kBAAkB,CAAC;AACzB,WAAS,IAAI,GAAG,IAAI,SAAS,QAAQ,KAAK,GAAG;AAC5C,oBAAgB,KAAK,CAAC,SAAS,CAAC,GAAG,SAAS,IAAI,CAAC,CAAC,CAAC;AAAA,EACpD;AAEA,QAAM,sBAAsB,gBAAgB,IAAI,CAAC,aAAa;AAC7D,UAAM,aAAa;AAAA,MAClB,CAAC,SAAS,CAAC,EAAE,SAAS,CAAC,GAAG,SAAS,CAAC,EAAE;AAAA,IACvC;AAEA,QAAI,SAAS,CAAC,GAAG;AAChB,iBAAW,SAAS,CAAC,EAAE,SAAS,CAAC,IAAI,SAAS,CAAC,EAAE;AAAA,IAClD;AAEA,WAAO;AAAA,MACN,MAAM;AAAA,IACP;AAAA,EACD,CAAC;AACD,SAAO;AACR;AAGO,MAAM,oBAAyC;AAAA,EAA/C;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,WAAW;AAAA,MACX,OAAO,CAAC,WAAW;AAAA,MACnB,QAAQ;AAAA,MACR,SAAS;AAAA,MACT,aA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|
|
91
91
|
}
|
|
92
92
|
},
|
|
93
|
-
// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node
|
|
94
93
|
inputs: [
|
|
95
94
|
{
|
|
96
95
|
displayName: "",
|
|
@@ -103,7 +102,6 @@ class MemoryManager {
|
|
|
103
102
|
maxConnections: 1
|
|
104
103
|
}
|
|
105
104
|
],
|
|
106
|
-
// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong
|
|
107
105
|
outputs: [
|
|
108
106
|
{
|
|
109
107
|
displayName: "",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/memory/MemoryManager/MemoryManager.node.ts"],"sourcesContent":["/* eslint-disable n8n-nodes-base/node-dirname-against-convention */\nimport type { BaseChatMemory } from '@langchain/community/memory/chat_memory';\nimport type { MessageContent, BaseMessage } from '@langchain/core/messages';\nimport { AIMessage, SystemMessage, HumanMessage } from '@langchain/core/messages';\nimport { NodeConnectionTypes } from 'n8n-workflow';\nimport type {\n\tIDataObject,\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeType,\n\tINodeTypeDescription,\n} from 'n8n-workflow';\n\ntype MessageRole = 'ai' | 'system' | 'user';\ninterface MessageRecord {\n\ttype: MessageRole;\n\tmessage: string;\n\thideFromUI: boolean;\n}\n\nexport function simplifyMessages(messages: BaseMessage[]): Array<Record<string, MessageContent>> {\n\tif (messages.length === 0) return [];\n\n\tconst result: Array<Record<string, MessageContent>> = [];\n\tlet index = 0;\n\n\twhile (index < messages.length) {\n\t\tconst currentGroup: Record<string, MessageContent> = {};\n\n\t\tdo {\n\t\t\tconst message = messages[index];\n\t\t\tconst messageType = message.getType();\n\n\t\t\tif (messageType in currentGroup) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcurrentGroup[messageType] = message.content;\n\t\t\tindex++;\n\t\t} while (index < messages.length);\n\n\t\tresult.push(currentGroup);\n\t}\n\n\treturn result;\n}\n\nconst prepareOutputSetup = (ctx: IExecuteFunctions, version: number, memory: BaseChatMemory) => {\n\tif (version === 1) {\n\t\t//legacy behavior of insert and delete for version 1\n\t\treturn async (i: number) => {\n\t\t\tconst messages = await memory.chatHistory.getMessages();\n\n\t\t\tconst serializedMessages = messages?.map((message) => message.toJSON()) ?? [];\n\n\t\t\tconst executionData = ctx.helpers.constructExecutionMetaData(\n\t\t\t\tctx.helpers.returnJsonArray(serializedMessages as unknown as IDataObject[]),\n\t\t\t\t{ itemData: { item: i } },\n\t\t\t);\n\n\t\t\treturn executionData;\n\t\t};\n\t}\n\treturn async (i: number) => {\n\t\treturn [\n\t\t\t{\n\t\t\t\tjson: { success: true },\n\t\t\t\tpairedItem: { item: i },\n\t\t\t},\n\t\t];\n\t};\n};\n\nexport class MemoryManager implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Chat Memory Manager',\n\t\tname: 'memoryManager',\n\t\ticon: 'fa:database',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1],\n\t\tdescription: 'Manage chat messages memory and use it in the workflow',\n\t\tdefaults: {\n\t\t\tname: 'Chat Memory Manager',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Miscellaneous', 'Root Nodes'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.memorymanager/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node\n\t\tinputs: [\n\t\t\t{\n\t\t\t\tdisplayName: '',\n\t\t\t\ttype: NodeConnectionTypes.Main,\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Memory',\n\t\t\t\ttype: NodeConnectionTypes.AiMemory,\n\t\t\t\trequired: true,\n\t\t\t\tmaxConnections: 1,\n\t\t\t},\n\t\t],\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong\n\t\toutputs: [\n\t\t\t{\n\t\t\t\tdisplayName: '',\n\t\t\t\ttype: NodeConnectionTypes.Main,\n\t\t\t},\n\t\t],\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Operation Mode',\n\t\t\t\tname: 'mode',\n\t\t\t\ttype: 'options',\n\t\t\t\tnoDataExpression: true,\n\t\t\t\tdefault: 'load',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Get Many Messages',\n\t\t\t\t\t\tdescription: 'Retrieve chat messages from connected memory',\n\t\t\t\t\t\tvalue: 'load',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Insert Messages',\n\t\t\t\t\t\tdescription: 'Insert chat messages into connected memory',\n\t\t\t\t\t\tvalue: 'insert',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Delete Messages',\n\t\t\t\t\t\tdescription: 'Delete chat messages from connected memory',\n\t\t\t\t\t\tvalue: 'delete',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Insert Mode',\n\t\t\t\tname: 'insertMode',\n\t\t\t\ttype: 'options',\n\t\t\t\tdescription: 'Choose how new messages are inserted into the memory',\n\t\t\t\tnoDataExpression: true,\n\t\t\t\tdefault: 'insert',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Insert Messages',\n\t\t\t\t\t\tvalue: 'insert',\n\t\t\t\t\t\tdescription: 'Add messages alongside existing ones',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Override All Messages',\n\t\t\t\t\t\tvalue: 'override',\n\t\t\t\t\t\tdescription: 'Replace the current memory with new messages',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tmode: ['insert'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Delete Mode',\n\t\t\t\tname: 'deleteMode',\n\t\t\t\ttype: 'options',\n\t\t\t\tdescription: 'How messages are deleted from memory',\n\t\t\t\tnoDataExpression: true,\n\t\t\t\tdefault: 'lastN',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Last N',\n\t\t\t\t\t\tvalue: 'lastN',\n\t\t\t\t\t\tdescription: 'Delete the last N messages',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'All Messages',\n\t\t\t\t\t\tvalue: 'all',\n\t\t\t\t\t\tdescription: 'Clear all messages from memory',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tmode: ['delete'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Chat Messages',\n\t\t\t\tname: 'messages',\n\t\t\t\tdescription: 'Chat messages to insert into memory',\n\t\t\t\ttype: 'fixedCollection',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tmultipleValues: true,\n\t\t\t\t},\n\t\t\t\tdefault: {},\n\t\t\t\tplaceholder: 'Add message',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'messageValues',\n\t\t\t\t\t\tdisplayName: 'Message',\n\t\t\t\t\t\tvalues: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Type Name or ID',\n\t\t\t\t\t\t\t\tname: 'type',\n\t\t\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tname: 'AI',\n\t\t\t\t\t\t\t\t\t\tvalue: 'ai',\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tname: 'System',\n\t\t\t\t\t\t\t\t\t\tvalue: 'system',\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tname: 'User',\n\t\t\t\t\t\t\t\t\t\tvalue: 'user',\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tdefault: 'system',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Message',\n\t\t\t\t\t\t\t\tname: 'message',\n\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t\t\tdefault: '',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Hide Message in Chat',\n\t\t\t\t\t\t\t\tname: 'hideFromUI',\n\t\t\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t\t\t\tdescription: 'Whether to hide the message from the chat UI',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tmode: ['insert'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Messages Count',\n\t\t\t\tname: 'lastMessagesCount',\n\t\t\t\ttype: 'number',\n\t\t\t\tdescription: 'The amount of last messages to delete',\n\t\t\t\tdefault: 2,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tmode: ['delete'],\n\t\t\t\t\t\tdeleteMode: ['lastN'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Simplify Output',\n\t\t\t\tname: 'simplifyOutput',\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdescription: 'Whether to simplify the output to only include the sender and the text',\n\t\t\t\tdefault: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tmode: ['load'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\ttype: 'collection',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Group Messages',\n\t\t\t\t\t\tname: 'groupMessages',\n\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\tdefault: true,\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Whether to group messages into a single item or return each message as a separate item',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tmode: ['load'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t};\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst nodeVersion = this.getNode().typeVersion;\n\t\tconst items = this.getInputData();\n\t\tconst mode = this.getNodeParameter('mode', 0, 'load') as 'load' | 'insert' | 'delete';\n\t\tconst memory = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiMemory,\n\t\t\t0,\n\t\t)) as BaseChatMemory;\n\n\t\tconst prepareOutput = prepareOutputSetup(this, nodeVersion, memory);\n\n\t\tconst returnData: INodeExecutionData[] = [];\n\n\t\tfor (let i = 0; i < items.length; i++) {\n\t\t\tconst messages = await memory.chatHistory.getMessages();\n\n\t\t\tif (mode === 'delete') {\n\t\t\t\tconst deleteMode = this.getNodeParameter('deleteMode', i) as 'lastN' | 'all';\n\n\t\t\t\tif (deleteMode === 'lastN') {\n\t\t\t\t\tconst lastMessagesCount = this.getNodeParameter('lastMessagesCount', i) as number;\n\t\t\t\t\tif (messages.length >= lastMessagesCount) {\n\t\t\t\t\t\tconst newMessages = messages.slice(0, messages.length - lastMessagesCount);\n\n\t\t\t\t\t\tawait memory.chatHistory.clear();\n\t\t\t\t\t\tfor (const message of newMessages) {\n\t\t\t\t\t\t\tawait memory.chatHistory.addMessage(message);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tawait memory.chatHistory.clear();\n\t\t\t\t}\n\n\t\t\t\treturnData.push(...(await prepareOutput(i)));\n\t\t\t}\n\n\t\t\tif (mode === 'insert') {\n\t\t\t\tconst insertMode = this.getNodeParameter('insertMode', i) as 'insert' | 'override';\n\t\t\t\tconst messagesToInsert = this.getNodeParameter(\n\t\t\t\t\t'messages.messageValues',\n\t\t\t\t\ti,\n\t\t\t\t\t[],\n\t\t\t\t) as MessageRecord[];\n\n\t\t\t\tconst templateMapper = {\n\t\t\t\t\tai: AIMessage,\n\t\t\t\t\tsystem: SystemMessage,\n\t\t\t\t\tuser: HumanMessage,\n\t\t\t\t};\n\n\t\t\t\tif (insertMode === 'override') {\n\t\t\t\t\tawait memory.chatHistory.clear();\n\t\t\t\t}\n\n\t\t\t\tfor (const message of messagesToInsert) {\n\t\t\t\t\tconst MessageClass = new templateMapper[message.type](message.message);\n\n\t\t\t\t\tif (message.hideFromUI) {\n\t\t\t\t\t\tMessageClass.additional_kwargs.hideFromUI = true;\n\t\t\t\t\t}\n\n\t\t\t\t\tawait memory.chatHistory.addMessage(MessageClass);\n\t\t\t\t}\n\n\t\t\t\treturnData.push(...(await prepareOutput(i)));\n\t\t\t}\n\n\t\t\tif (mode === 'load') {\n\t\t\t\tconst simplifyOutput = this.getNodeParameter('simplifyOutput', i, false) as boolean;\n\t\t\t\tconst options = this.getNodeParameter('options', i);\n\n\t\t\t\t//Load mode, legacy behavior for version 1, buggy - outputs only for single input item\n\t\t\t\tif (simplifyOutput && messages.length && nodeVersion === 1) {\n\t\t\t\t\tconst groupMessages = options.groupMessages as boolean;\n\t\t\t\t\tconst output = simplifyMessages(messages);\n\n\t\t\t\t\treturn [\n\t\t\t\t\t\tthis.helpers.constructExecutionMetaData(\n\t\t\t\t\t\t\tthis.helpers.returnJsonArray(\n\t\t\t\t\t\t\t\tgroupMessages ? [{ messages: output, messagesCount: output.length }] : output,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t{ itemData: { item: i } },\n\t\t\t\t\t\t),\n\t\t\t\t\t];\n\t\t\t\t}\n\n\t\t\t\tlet groupMessages = true;\n\t\t\t\t//disable grouping if explicitly set to false\n\t\t\t\tif (options.groupMessages === false) {\n\t\t\t\t\tgroupMessages = false;\n\t\t\t\t}\n\t\t\t\t//disable grouping if not set and node version is 1 (legacy behavior)\n\t\t\t\tif (options.groupMessages === undefined && nodeVersion === 1) {\n\t\t\t\t\tgroupMessages = false;\n\t\t\t\t}\n\n\t\t\t\tlet output: IDataObject[] =\n\t\t\t\t\t(simplifyOutput\n\t\t\t\t\t\t? simplifyMessages(messages)\n\t\t\t\t\t\t: (messages?.map((message) => message.toJSON()) as unknown as IDataObject[])) ?? [];\n\n\t\t\t\tif (groupMessages) {\n\t\t\t\t\toutput = [{ messages: output, messagesCount: output.length }];\n\t\t\t\t}\n\n\t\t\t\tconst executionData = this.helpers.constructExecutionMetaData(\n\t\t\t\t\tthis.helpers.returnJsonArray(output),\n\t\t\t\t\t{ itemData: { item: i } },\n\t\t\t\t);\n\n\t\t\t\treturnData.push(...executionData);\n\t\t\t}\n\t\t}\n\n\t\treturn [returnData];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,sBAAuD;AACvD,0BAAoC;AAgB7B,SAAS,iBAAiB,UAAgE;AAChG,MAAI,SAAS,WAAW,EAAG,QAAO,CAAC;AAEnC,QAAM,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,iBAAiB,QAAQ;AAExC,iBAAO;AAAA,YACN,KAAK,QAAQ;AAAA,cACZ,KAAK,QAAQ;AAAA,gBACZD,iBAAgB,CAAC,EAAE,UAAUC,SAAQ,eAAeA,QAAO,OAAO,CAAC,IAAIA;AAAA,cACxE;AAAA,cACA,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE;AAAA,YACzB;AAAA,UACD;AAAA,QACD;AAEA,YAAI,gBAAgB;AAEpB,YAAI,QAAQ,kBAAkB,OAAO;AACpC,0BAAgB;AAAA,QACjB;AAEA,YAAI,QAAQ,kBAAkB,UAAa,gBAAgB,GAAG;AAC7D,0BAAgB;AAAA,QACjB;AAEA,YAAI,UACF,iBACE,iBAAiB,QAAQ,IACxB,UAAU,IAAI,CAAC,YAAY,QAAQ,OAAO,CAAC,MAAmC,CAAC;AAEpF,YAAI,eAAe;AAClB,mBAAS,CAAC,EAAE,UAAU,QAAQ,eAAe,OAAO,OAAO,CAAC;AAAA,QAC7D;AAEA,cAAM,gBAAgB,KAAK,QAAQ;AAAA,UAClC,KAAK,QAAQ,gBAAgB,MAAM;AAAA,UACnC,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE;AAAA,QACzB;AAEA,mBAAW,KAAK,GAAG,aAAa;AAAA,MACjC;AAAA,IACD;AAEA,WAAO,CAAC,UAAU;AAAA,EACnB;AACD;","names":["groupMessages","output"]}
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/memory/MemoryManager/MemoryManager.node.ts"],"sourcesContent":["import type { BaseChatMemory } from '@langchain/community/memory/chat_memory';\nimport type { MessageContent, BaseMessage } from '@langchain/core/messages';\nimport { AIMessage, SystemMessage, HumanMessage } from '@langchain/core/messages';\nimport { NodeConnectionTypes } from 'n8n-workflow';\nimport type {\n\tIDataObject,\n\tIExecuteFunctions,\n\tINodeExecutionData,\n\tINodeType,\n\tINodeTypeDescription,\n} from 'n8n-workflow';\n\ntype MessageRole = 'ai' | 'system' | 'user';\ninterface MessageRecord {\n\ttype: MessageRole;\n\tmessage: string;\n\thideFromUI: boolean;\n}\n\nexport function simplifyMessages(messages: BaseMessage[]): Array<Record<string, MessageContent>> {\n\tif (messages.length === 0) return [];\n\n\tconst result: Array<Record<string, MessageContent>> = [];\n\tlet index = 0;\n\n\twhile (index < messages.length) {\n\t\tconst currentGroup: Record<string, MessageContent> = {};\n\n\t\tdo {\n\t\t\tconst message = messages[index];\n\t\t\tconst messageType = message.getType();\n\n\t\t\tif (messageType in currentGroup) {\n\t\t\t\tbreak;\n\t\t\t}\n\n\t\t\tcurrentGroup[messageType] = message.content;\n\t\t\tindex++;\n\t\t} while (index < messages.length);\n\n\t\tresult.push(currentGroup);\n\t}\n\n\treturn result;\n}\n\nconst prepareOutputSetup = (ctx: IExecuteFunctions, version: number, memory: BaseChatMemory) => {\n\tif (version === 1) {\n\t\t//legacy behavior of insert and delete for version 1\n\t\treturn async (i: number) => {\n\t\t\tconst messages = await memory.chatHistory.getMessages();\n\n\t\t\tconst serializedMessages = messages?.map((message) => message.toJSON()) ?? [];\n\n\t\t\tconst executionData = ctx.helpers.constructExecutionMetaData(\n\t\t\t\tctx.helpers.returnJsonArray(serializedMessages as unknown as IDataObject[]),\n\t\t\t\t{ itemData: { item: i } },\n\t\t\t);\n\n\t\t\treturn executionData;\n\t\t};\n\t}\n\treturn async (i: number) => {\n\t\treturn [\n\t\t\t{\n\t\t\t\tjson: { success: true },\n\t\t\t\tpairedItem: { item: i },\n\t\t\t},\n\t\t];\n\t};\n};\n\nexport class MemoryManager implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Chat Memory Manager',\n\t\tname: 'memoryManager',\n\t\ticon: 'fa:database',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1],\n\t\tdescription: 'Manage chat messages memory and use it in the workflow',\n\t\tdefaults: {\n\t\t\tname: 'Chat Memory Manager',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Miscellaneous', 'Root Nodes'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.memorymanager/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\n\t\tinputs: [\n\t\t\t{\n\t\t\t\tdisplayName: '',\n\t\t\t\ttype: NodeConnectionTypes.Main,\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Memory',\n\t\t\t\ttype: NodeConnectionTypes.AiMemory,\n\t\t\t\trequired: true,\n\t\t\t\tmaxConnections: 1,\n\t\t\t},\n\t\t],\n\n\t\toutputs: [\n\t\t\t{\n\t\t\t\tdisplayName: '',\n\t\t\t\ttype: NodeConnectionTypes.Main,\n\t\t\t},\n\t\t],\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Operation Mode',\n\t\t\t\tname: 'mode',\n\t\t\t\ttype: 'options',\n\t\t\t\tnoDataExpression: true,\n\t\t\t\tdefault: 'load',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Get Many Messages',\n\t\t\t\t\t\tdescription: 'Retrieve chat messages from connected memory',\n\t\t\t\t\t\tvalue: 'load',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Insert Messages',\n\t\t\t\t\t\tdescription: 'Insert chat messages into connected memory',\n\t\t\t\t\t\tvalue: 'insert',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Delete Messages',\n\t\t\t\t\t\tdescription: 'Delete chat messages from connected memory',\n\t\t\t\t\t\tvalue: 'delete',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Insert Mode',\n\t\t\t\tname: 'insertMode',\n\t\t\t\ttype: 'options',\n\t\t\t\tdescription: 'Choose how new messages are inserted into the memory',\n\t\t\t\tnoDataExpression: true,\n\t\t\t\tdefault: 'insert',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Insert Messages',\n\t\t\t\t\t\tvalue: 'insert',\n\t\t\t\t\t\tdescription: 'Add messages alongside existing ones',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Override All Messages',\n\t\t\t\t\t\tvalue: 'override',\n\t\t\t\t\t\tdescription: 'Replace the current memory with new messages',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tmode: ['insert'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Delete Mode',\n\t\t\t\tname: 'deleteMode',\n\t\t\t\ttype: 'options',\n\t\t\t\tdescription: 'How messages are deleted from memory',\n\t\t\t\tnoDataExpression: true,\n\t\t\t\tdefault: 'lastN',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'Last N',\n\t\t\t\t\t\tvalue: 'lastN',\n\t\t\t\t\t\tdescription: 'Delete the last N messages',\n\t\t\t\t\t},\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'All Messages',\n\t\t\t\t\t\tvalue: 'all',\n\t\t\t\t\t\tdescription: 'Clear all messages from memory',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tmode: ['delete'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Chat Messages',\n\t\t\t\tname: 'messages',\n\t\t\t\tdescription: 'Chat messages to insert into memory',\n\t\t\t\ttype: 'fixedCollection',\n\t\t\t\ttypeOptions: {\n\t\t\t\t\tmultipleValues: true,\n\t\t\t\t},\n\t\t\t\tdefault: {},\n\t\t\t\tplaceholder: 'Add message',\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tname: 'messageValues',\n\t\t\t\t\t\tdisplayName: 'Message',\n\t\t\t\t\t\tvalues: [\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Type Name or ID',\n\t\t\t\t\t\t\t\tname: 'type',\n\t\t\t\t\t\t\t\ttype: 'options',\n\t\t\t\t\t\t\t\toptions: [\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tname: 'AI',\n\t\t\t\t\t\t\t\t\t\tvalue: 'ai',\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tname: 'System',\n\t\t\t\t\t\t\t\t\t\tvalue: 'system',\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\t\t\tname: 'User',\n\t\t\t\t\t\t\t\t\t\tvalue: 'user',\n\t\t\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t\t],\n\t\t\t\t\t\t\t\tdefault: 'system',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Message',\n\t\t\t\t\t\t\t\tname: 'message',\n\t\t\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t\t\tdefault: '',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tdisplayName: 'Hide Message in Chat',\n\t\t\t\t\t\t\t\tname: 'hideFromUI',\n\t\t\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\t\t\trequired: true,\n\t\t\t\t\t\t\t\tdefault: false,\n\t\t\t\t\t\t\t\tdescription: 'Whether to hide the message from the chat UI',\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t],\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tmode: ['insert'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Messages Count',\n\t\t\t\tname: 'lastMessagesCount',\n\t\t\t\ttype: 'number',\n\t\t\t\tdescription: 'The amount of last messages to delete',\n\t\t\t\tdefault: 2,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tmode: ['delete'],\n\t\t\t\t\t\tdeleteMode: ['lastN'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Simplify Output',\n\t\t\t\tname: 'simplifyOutput',\n\t\t\t\ttype: 'boolean',\n\t\t\t\tdescription: 'Whether to simplify the output to only include the sender and the text',\n\t\t\t\tdefault: true,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tmode: ['load'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\ttype: 'collection',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Group Messages',\n\t\t\t\t\t\tname: 'groupMessages',\n\t\t\t\t\t\ttype: 'boolean',\n\t\t\t\t\t\tdefault: true,\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'Whether to group messages into a single item or return each message as a separate item',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\tmode: ['load'],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t],\n\t};\n\n\tasync execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {\n\t\tconst nodeVersion = this.getNode().typeVersion;\n\t\tconst items = this.getInputData();\n\t\tconst mode = this.getNodeParameter('mode', 0, 'load') as 'load' | 'insert' | 'delete';\n\t\tconst memory = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiMemory,\n\t\t\t0,\n\t\t)) as BaseChatMemory;\n\n\t\tconst prepareOutput = prepareOutputSetup(this, nodeVersion, memory);\n\n\t\tconst returnData: INodeExecutionData[] = [];\n\n\t\tfor (let i = 0; i < items.length; i++) {\n\t\t\tconst messages = await memory.chatHistory.getMessages();\n\n\t\t\tif (mode === 'delete') {\n\t\t\t\tconst deleteMode = this.getNodeParameter('deleteMode', i) as 'lastN' | 'all';\n\n\t\t\t\tif (deleteMode === 'lastN') {\n\t\t\t\t\tconst lastMessagesCount = this.getNodeParameter('lastMessagesCount', i) as number;\n\t\t\t\t\tif (messages.length >= lastMessagesCount) {\n\t\t\t\t\t\tconst newMessages = messages.slice(0, messages.length - lastMessagesCount);\n\n\t\t\t\t\t\tawait memory.chatHistory.clear();\n\t\t\t\t\t\tfor (const message of newMessages) {\n\t\t\t\t\t\t\tawait memory.chatHistory.addMessage(message);\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tawait memory.chatHistory.clear();\n\t\t\t\t}\n\n\t\t\t\treturnData.push(...(await prepareOutput(i)));\n\t\t\t}\n\n\t\t\tif (mode === 'insert') {\n\t\t\t\tconst insertMode = this.getNodeParameter('insertMode', i) as 'insert' | 'override';\n\t\t\t\tconst messagesToInsert = this.getNodeParameter(\n\t\t\t\t\t'messages.messageValues',\n\t\t\t\t\ti,\n\t\t\t\t\t[],\n\t\t\t\t) as MessageRecord[];\n\n\t\t\t\tconst templateMapper = {\n\t\t\t\t\tai: AIMessage,\n\t\t\t\t\tsystem: SystemMessage,\n\t\t\t\t\tuser: HumanMessage,\n\t\t\t\t};\n\n\t\t\t\tif (insertMode === 'override') {\n\t\t\t\t\tawait memory.chatHistory.clear();\n\t\t\t\t}\n\n\t\t\t\tfor (const message of messagesToInsert) {\n\t\t\t\t\tconst MessageClass = new templateMapper[message.type](message.message);\n\n\t\t\t\t\tif (message.hideFromUI) {\n\t\t\t\t\t\tMessageClass.additional_kwargs.hideFromUI = true;\n\t\t\t\t\t}\n\n\t\t\t\t\tawait memory.chatHistory.addMessage(MessageClass);\n\t\t\t\t}\n\n\t\t\t\treturnData.push(...(await prepareOutput(i)));\n\t\t\t}\n\n\t\t\tif (mode === 'load') {\n\t\t\t\tconst simplifyOutput = this.getNodeParameter('simplifyOutput', i, false) as boolean;\n\t\t\t\tconst options = this.getNodeParameter('options', i);\n\n\t\t\t\t//Load mode, legacy behavior for version 1, buggy - outputs only for single input item\n\t\t\t\tif (simplifyOutput && messages.length && nodeVersion === 1) {\n\t\t\t\t\tconst groupMessages = options.groupMessages as boolean;\n\t\t\t\t\tconst output = simplifyMessages(messages);\n\n\t\t\t\t\treturn [\n\t\t\t\t\t\tthis.helpers.constructExecutionMetaData(\n\t\t\t\t\t\t\tthis.helpers.returnJsonArray(\n\t\t\t\t\t\t\t\tgroupMessages ? [{ messages: output, messagesCount: output.length }] : output,\n\t\t\t\t\t\t\t),\n\t\t\t\t\t\t\t{ itemData: { item: i } },\n\t\t\t\t\t\t),\n\t\t\t\t\t];\n\t\t\t\t}\n\n\t\t\t\tlet groupMessages = true;\n\t\t\t\t//disable grouping if explicitly set to false\n\t\t\t\tif (options.groupMessages === false) {\n\t\t\t\t\tgroupMessages = false;\n\t\t\t\t}\n\t\t\t\t//disable grouping if not set and node version is 1 (legacy behavior)\n\t\t\t\tif (options.groupMessages === undefined && nodeVersion === 1) {\n\t\t\t\t\tgroupMessages = false;\n\t\t\t\t}\n\n\t\t\t\tlet output: IDataObject[] =\n\t\t\t\t\t(simplifyOutput\n\t\t\t\t\t\t? simplifyMessages(messages)\n\t\t\t\t\t\t: (messages?.map((message) => message.toJSON()) as unknown as IDataObject[])) ?? [];\n\n\t\t\t\tif (groupMessages) {\n\t\t\t\t\toutput = [{ messages: output, messagesCount: output.length }];\n\t\t\t\t}\n\n\t\t\t\tconst executionData = this.helpers.constructExecutionMetaData(\n\t\t\t\t\tthis.helpers.returnJsonArray(output),\n\t\t\t\t\t{ itemData: { item: i } },\n\t\t\t\t);\n\n\t\t\t\treturnData.push(...executionData);\n\t\t\t}\n\t\t}\n\n\t\treturn [returnData];\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,sBAAuD;AACvD,0BAAoC;AAgB7B,SAAS,iBAAiB,UAAgE;AAChG,MAAI,SAAS,WAAW,EAAG,QAAO,CAAC;AAEnC,QAAM,SAAgD,CAAC;AACvD,MAAI,QAAQ;AAEZ,SAAO,QAAQ,SAAS,QAAQ;AAC/B,UAAM,eAA+C,CAAC;AAEtD,OAAG;AACF,YAAM,UAAU,SAAS,KAAK;AAC9B,YAAM,cAAc,QAAQ,QAAQ;AAEpC,UAAI,eAAe,cAAc;AAChC;AAAA,MACD;AAEA,mBAAa,WAAW,IAAI,QAAQ;AACpC;AAAA,IACD,SAAS,QAAQ,SAAS;AAE1B,WAAO,KAAK,YAAY;AAAA,EACzB;AAEA,SAAO;AACR;AAEA,MAAM,qBAAqB,CAAC,KAAwB,SAAiB,WAA2B;AAC/F,MAAI,YAAY,GAAG;AAElB,WAAO,OAAO,MAAc;AAC3B,YAAM,WAAW,MAAM,OAAO,YAAY,YAAY;AAEtD,YAAM,qBAAqB,UAAU,IAAI,CAAC,YAAY,QAAQ,OAAO,CAAC,KAAK,CAAC;AAE5E,YAAM,gBAAgB,IAAI,QAAQ;AAAA,QACjC,IAAI,QAAQ,gBAAgB,kBAA8C;AAAA,QAC1E,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE;AAAA,MACzB;AAEA,aAAO;AAAA,IACR;AAAA,EACD;AACA,SAAO,OAAO,MAAc;AAC3B,WAAO;AAAA,MACN;AAAA,QACC,MAAM,EAAE,SAAS,KAAK;AAAA,QACtB,YAAY,EAAE,MAAM,EAAE;AAAA,MACvB;AAAA,IACD;AAAA,EACD;AAC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{
|
|
|
54
54
|
]
|
|
55
55
|
}
|
|
56
56
|
},
|
|
57
|
-
// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node
|
|
58
57
|
inputs: [],
|
|
59
|
-
// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong
|
|
60
58
|
outputs: [import_n8n_workflow.NodeConnectionTypes.AiMemory],
|
|
61
59
|
outputNames: ["Memory"],
|
|
62
60
|
credentials: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/memory/MemoryMotorhead/MemoryMotorhead.node.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/memory/MemoryMotorhead/MemoryMotorhead.node.ts"],"sourcesContent":["import { MotorheadMemory } from '@langchain/community/memory/motorhead_memory';\nimport {\n\tNodeConnectionTypes,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n} from 'n8n-workflow';\n\nimport { getSessionId } from '@utils/helpers';\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nimport { expressionSessionKeyProperty, sessionIdOption, sessionKeyProperty } from '../descriptions';\n\nexport class MemoryMotorhead implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Motorhead',\n\t\tname: 'memoryMotorhead',\n\t\ticon: 'fa:file-export',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3],\n\t\tdescription: 'Use Motorhead Memory',\n\t\tdefaults: {\n\t\t\tname: 'Motorhead',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Memory'],\n\t\t\t\tMemory: ['Other memories'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.memorymotorhead/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\n\t\tinputs: [],\n\n\t\toutputs: [NodeConnectionTypes.AiMemory],\n\t\toutputNames: ['Memory'],\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'motorheadApi',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Session ID',\n\t\t\t\tname: 'sessionId',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Session ID',\n\t\t\t\tname: 'sessionId',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '={{ $json.sessionId }}',\n\t\t\t\tdescription: 'The key to use to store the memory',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1.1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...sessionIdOption,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.2 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\texpressionSessionKeyProperty(1.3),\n\t\t\tsessionKeyProperty,\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst credentials = await this.getCredentials('motorheadApi');\n\t\tconst nodeVersion = this.getNode().typeVersion;\n\n\t\tlet sessionId;\n\n\t\tif (nodeVersion >= 1.2) {\n\t\t\tsessionId = getSessionId(this, itemIndex);\n\t\t} else {\n\t\t\tsessionId = this.getNodeParameter('sessionId', itemIndex) as string;\n\t\t}\n\n\t\tconst memory = new MotorheadMemory({\n\t\t\tsessionId,\n\t\t\turl: `${credentials.host as string}/motorhead`,\n\t\t\tclientId: credentials.clientId as string,\n\t\t\tapiKey: credentials.apiKey as string,\n\t\t\tmemoryKey: 'chat_history',\n\t\t\treturnMessages: true,\n\t\t\tinputKey: 'input',\n\t\t\toutputKey: 'output',\n\t\t});\n\n\t\tawait memory.init();\n\n\t\treturn {\n\t\t\tresponse: logWrapper(memory, this),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,8BAAgC;AAChC,0BAMO;AAEP,qBAA6B;AAC7B,wBAA2B;AAC3B,0BAA6C;AAE7C,0BAAkF;AAE3E,MAAM,gBAAqC;AAAA,EAA3C;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,WAAW;AAAA,MACX,OAAO,CAAC,WAAW;AAAA,MACnB,SAAS,CAAC,GAAG,KAAK,KAAK,GAAG;AAAA,MAC1B,aAAa;AAAA,MACb,UAAU;AAAA,QACT,MAAM;AAAA,MACP;AAAA,MACA,OAAO;AAAA,QACN,YAAY,CAAC,IAAI;AAAA,QACjB,eAAe;AAAA,UACd,IAAI,CAAC,QAAQ;AAAA,UACb,QAAQ,CAAC,gBAAgB;AAAA,QAC1B;AAAA,QACA,WAAW;AAAA,UACV,sBAAsB;AAAA,YACrB;AAAA,cACC,KAAK;AAAA,YACN;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,MAEA,QAAQ,CAAC;AAAA,MAET,SAAS,CAAC,wCAAoB,QAAQ;AAAA,MACtC,aAAa,CAAC,QAAQ;AAAA,MACtB,aAAa;AAAA,QACZ;AAAA,UACC,MAAM;AAAA,UACN,UAAU;AAAA,QACX;AAAA,MACD;AAAA,MACA,YAAY;AAAA,YACX,kDA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@@ -63,9 +63,7 @@ class MemoryPostgresChat {
|
|
|
63
63
|
]
|
|
64
64
|
}
|
|
65
65
|
},
|
|
66
|
-
// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node
|
|
67
66
|
inputs: [],
|
|
68
|
-
// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong
|
|
69
67
|
outputs: [import_n8n_workflow.NodeConnectionTypes.AiMemory],
|
|
70
68
|
outputNames: ["Memory"],
|
|
71
69
|
properties: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/memory/MemoryPostgresChat/MemoryPostgresChat.node.ts"],"sourcesContent":["import { PostgresChatMessageHistory } from '@langchain/community/stores/message/postgres';\nimport { BufferMemory, BufferWindowMemory } from 'langchain/memory';\nimport { configurePostgres } from 'n8n-nodes-base/dist/nodes/Postgres/transport/index';\nimport type { PostgresNodeCredentials } from 'n8n-nodes-base/dist/nodes/Postgres/v2/helpers/interfaces';\nimport { postgresConnectionTest } from 'n8n-nodes-base/dist/nodes/Postgres/v2/methods/credentialTest';\nimport type {\n\tISupplyDataFunctions,\n\tINodeType,\n\tINodeTypeDescription,\n\tSupplyData,\n} from 'n8n-workflow';\nimport { NodeConnectionTypes } from 'n8n-workflow';\nimport type pg from 'pg';\n\nimport { getSessionId } from '@utils/helpers';\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nimport {\n\tsessionIdOption,\n\tsessionKeyProperty,\n\tcontextWindowLengthProperty,\n\texpressionSessionKeyProperty,\n} from '../descriptions';\n\nexport class MemoryPostgresChat implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Postgres Chat Memory',\n\t\tname: 'memoryPostgresChat',\n\t\ticon: 'file:postgres.svg',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3],\n\t\tdescription: 'Stores the chat history in Postgres table.',\n\t\tdefaults: {\n\t\t\tname: 'Postgres Chat Memory',\n\t\t},\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'postgres',\n\t\t\t\trequired: true,\n\t\t\t\ttestedBy: 'postgresConnectionTest',\n\t\t\t},\n\t\t],\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Memory'],\n\t\t\t\tMemory: ['Other memories'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.memorypostgreschat/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\n\t\tinputs: [],\n\n\t\toutputs: [NodeConnectionTypes.AiMemory],\n\t\toutputNames: ['Memory'],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\tsessionIdOption,\n\t\t\texpressionSessionKeyProperty(1.2),\n\t\t\tsessionKeyProperty,\n\t\t\t{\n\t\t\t\tdisplayName: 'Table Name',\n\t\t\t\tname: 'tableName',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: 'n8n_chat_histories',\n\t\t\t\tdescription:\n\t\t\t\t\t'The table name to store the chat history in. If table does not exist, it will be created.',\n\t\t\t},\n\t\t\t{\n\t\t\t\t...contextWindowLengthProperty,\n\t\t\t\tdisplayOptions: { hide: { '@version': [{ _cnd: { lt: 1.1 } }] } },\n\t\t\t},\n\t\t],\n\t};\n\n\tmethods = {\n\t\tcredentialTest: {\n\t\t\tpostgresConnectionTest,\n\t\t},\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst credentials = await this.getCredentials<PostgresNodeCredentials>('postgres');\n\t\tconst tableName = this.getNodeParameter('tableName', itemIndex, 'n8n_chat_histories') as string;\n\t\tconst sessionId = getSessionId(this, itemIndex);\n\n\t\tconst pgConf = await configurePostgres.call(this, credentials);\n\t\tconst pool = pgConf.db.$pool as unknown as pg.Pool;\n\n\t\tconst pgChatHistory = new PostgresChatMessageHistory({\n\t\t\tpool,\n\t\t\tsessionId,\n\t\t\ttableName,\n\t\t});\n\n\t\tconst memClass = this.getNode().typeVersion < 1.1 ? BufferMemory : BufferWindowMemory;\n\t\tconst kOptions =\n\t\t\tthis.getNode().typeVersion < 1.1\n\t\t\t\t? {}\n\t\t\t\t: { k: this.getNodeParameter('contextWindowLength', itemIndex) };\n\n\t\tconst memory = new memClass({\n\t\t\tmemoryKey: 'chat_history',\n\t\t\tchatHistory: pgChatHistory,\n\t\t\treturnMessages: true,\n\t\t\tinputKey: 'input',\n\t\t\toutputKey: 'output',\n\t\t\t...kOptions,\n\t\t});\n\n\t\treturn {\n\t\t\tresponse: logWrapper(memory, this),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,sBAA2C;AAC3C,oBAAiD;AACjD,uBAAkC;AAElC,4BAAuC;AAOvC,0BAAoC;AAGpC,qBAA6B;AAC7B,wBAA2B;AAC3B,0BAA6C;AAE7C,0BAKO;AAEA,MAAM,mBAAwC;AAAA,EAA9C;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,OAAO,CAAC,WAAW;AAAA,MACnB,SAAS,CAAC,GAAG,KAAK,KAAK,GAAG;AAAA,MAC1B,aAAa;AAAA,MACb,UAAU;AAAA,QACT,MAAM;AAAA,MACP;AAAA,MACA,aAAa;AAAA,QACZ;AAAA,UACC,MAAM;AAAA,UACN,UAAU;AAAA,UACV,UAAU;AAAA,QACX;AAAA,MACD;AAAA,MACA,OAAO;AAAA,QACN,YAAY,CAAC,IAAI;AAAA,QACjB,eAAe;AAA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EjE,UAAM,SAAS,IAAI,SAAS;AAAA,MAC3B,WAAW;AAAA,MACX,aAAa;AAAA,MACb,gBAAgB;AAAA,MAChB,UAAU;AAAA,MACV,WAAW;AAAA,MACX,GAAG;AAAA,IACJ,CAAC;AAED,WAAO;AAAA,MACN,cAAU,8BAAW,QAAQ,IAAI;AAAA,IAClC;AAAA,EACD;AACD;","names":[]}
|
|
@@ -61,9 +61,7 @@ class MemoryRedisChat {
|
|
|
61
61
|
]
|
|
62
62
|
}
|
|
63
63
|
},
|
|
64
|
-
// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node
|
|
65
64
|
inputs: [],
|
|
66
|
-
// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong
|
|
67
65
|
outputs: [import_n8n_workflow.NodeConnectionTypes.AiMemory],
|
|
68
66
|
outputNames: ["Memory"],
|
|
69
67
|
properties: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/memory/MemoryRedisChat/MemoryRedisChat.node.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/memory/MemoryRedisChat/MemoryRedisChat.node.ts"],"sourcesContent":["import type { RedisChatMessageHistoryInput } from '@langchain/redis';\nimport { RedisChatMessageHistory } from '@langchain/redis';\nimport { BufferMemory, BufferWindowMemory } from 'langchain/memory';\nimport {\n\tNodeOperationError,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype ISupplyDataFunctions,\n\ttype SupplyData,\n\tNodeConnectionTypes,\n} from 'n8n-workflow';\nimport type { RedisClientOptions } from 'redis';\nimport { createClient } from 'redis';\n\nimport { getSessionId } from '@utils/helpers';\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nimport {\n\tsessionIdOption,\n\tsessionKeyProperty,\n\tcontextWindowLengthProperty,\n\texpressionSessionKeyProperty,\n} from '../descriptions';\n\nexport class MemoryRedisChat implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Redis Chat Memory',\n\t\tname: 'memoryRedisChat',\n\t\ticon: 'file:redis.svg',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3, 1.4, 1.5],\n\t\tdescription: 'Stores the chat history in Redis.',\n\t\tdefaults: {\n\t\t\tname: 'Redis Chat Memory',\n\t\t},\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'redis',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Memory'],\n\t\t\t\tMemory: ['Other memories'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.memoryredischat/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\n\t\tinputs: [],\n\n\t\toutputs: [NodeConnectionTypes.AiMemory],\n\t\toutputNames: ['Memory'],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Session Key',\n\t\t\t\tname: 'sessionKey',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: 'chat_history',\n\t\t\t\tdescription: 'The key to use to store the memory in the workflow data',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Session ID',\n\t\t\t\tname: 'sessionKey',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '={{ $json.sessionId }}',\n\t\t\t\tdescription: 'The key to use to store the memory',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1.1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...sessionIdOption,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.2 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\texpressionSessionKeyProperty(1.4),\n\t\t\tsessionKeyProperty,\n\t\t\t{\n\t\t\t\tdisplayName: 'Session Time To Live',\n\t\t\t\tname: 'sessionTTL',\n\t\t\t\ttype: 'number',\n\t\t\t\tdefault: 0,\n\t\t\t\tdescription:\n\t\t\t\t\t'For how long the session should be stored in seconds. If set to 0 it will not expire.',\n\t\t\t},\n\t\t\t{\n\t\t\t\t...contextWindowLengthProperty,\n\t\t\t\tdisplayOptions: { hide: { '@version': [{ _cnd: { lt: 1.3 } }] } },\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst credentials = await this.getCredentials('redis');\n\t\tconst nodeVersion = this.getNode().typeVersion;\n\n\t\tconst sessionTTL = this.getNodeParameter('sessionTTL', itemIndex, 0) as number;\n\n\t\tlet sessionId;\n\n\t\tif (nodeVersion >= 1.2) {\n\t\t\tsessionId = getSessionId(this, itemIndex);\n\t\t} else {\n\t\t\tsessionId = this.getNodeParameter('sessionKey', itemIndex) as string;\n\t\t}\n\n\t\tconst redisOptions: RedisClientOptions = {\n\t\t\tsocket: {\n\t\t\t\thost: credentials.host as string,\n\t\t\t\tport: credentials.port as number,\n\t\t\t\ttls: credentials.ssl === true,\n\t\t\t},\n\t\t\tdatabase: credentials.database as number,\n\t\t};\n\n\t\tif (credentials.user && nodeVersion >= 1.5) {\n\t\t\tredisOptions.username = credentials.user as string;\n\t\t}\n\t\tif (credentials.password) {\n\t\t\tredisOptions.password = credentials.password as string;\n\t\t}\n\n\t\tconst client = createClient({\n\t\t\t...redisOptions,\n\t\t});\n\n\t\tclient.on('error', async (error: Error) => {\n\t\t\tawait client.quit();\n\t\t\tthrow new NodeOperationError(this.getNode(), 'Redis Error: ' + error.message);\n\t\t});\n\n\t\tconst redisChatConfig: RedisChatMessageHistoryInput = {\n\t\t\tclient,\n\t\t\tsessionId,\n\t\t};\n\n\t\tif (sessionTTL > 0) {\n\t\t\tredisChatConfig.sessionTTL = sessionTTL;\n\t\t}\n\t\tconst redisChatHistory = new RedisChatMessageHistory(redisChatConfig);\n\n\t\tconst memClass = this.getNode().typeVersion < 1.3 ? BufferMemory : BufferWindowMemory;\n\t\tconst kOptions =\n\t\t\tthis.getNode().typeVersion < 1.3\n\t\t\t\t? {}\n\t\t\t\t: { k: this.getNodeParameter('contextWindowLength', itemIndex) };\n\n\t\tconst memory = new memClass({\n\t\t\tmemoryKey: 'chat_history',\n\t\t\tchatHistory: redisChatHistory,\n\t\t\treturnMessages: true,\n\t\t\tinputKey: 'input',\n\t\t\toutputKey: 'output',\n\t\t\t...kOptions,\n\t\t});\n\n\t\tasync function closeFunction() {\n\t\t\tvoid client.disconnect();\n\t\t}\n\n\t\treturn {\n\t\t\tcloseFunction,\n\t\t\tresponse: logWrapper(memory, this),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,mBAAwC;AACxC,oBAAiD;AACjD,0BAOO;AAEP,IAAAA,gBAA6B;AAE7B,qBAA6B;AAC7B,wBAA2B;AAC3B,0BAA6C;AAE7C,0BAKO;AAEA,MAAM,gBAAqC;AAAA,EAA3C;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,OAAO,CAAC,WAAW;AAAA,MACnB,SAAS,CAAC,GAAG,KAAK,KAAK,KAAK,KAAK,GAAG;AAAA,MACpC,aAAa;AAAA,MACb,UAAU;AAAA,QACT,MAAM;AAAA,MACP;AAAA,MACA,aAAa;AAAA,QACZ;AAAA,UACC,MAAM;AAAA,UACN,UA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AC3B,WAAW;AAAA,MACX,aAAa;AAAA,MACb,gBAAgB;AAAA,MAChB,UAAU;AAAA,MACV,WAAW;AAAA,MACX,GAAG;AAAA,IACJ,CAAC;AAED,mBAAe,gBAAgB;AAC9B,WAAK,OAAO,WAAW;AAAA,IACxB;AAEA,WAAO;AAAA,MACN;AAAA,MACA,cAAU,8BAAW,QAAQ,IAAI;AAAA,IAClC;AAAA,EACD;AACD;","names":["import_redis"]}
|
|
@@ -57,9 +57,7 @@ class MemoryXata {
|
|
|
57
57
|
]
|
|
58
58
|
}
|
|
59
59
|
},
|
|
60
|
-
// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node
|
|
61
60
|
inputs: [],
|
|
62
|
-
// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong
|
|
63
61
|
outputs: [import_n8n_workflow.NodeConnectionTypes.AiMemory],
|
|
64
62
|
outputNames: ["Memory"],
|
|
65
63
|
credentials: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/memory/MemoryXata/MemoryXata.node.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/memory/MemoryXata/MemoryXata.node.ts"],"sourcesContent":["import { XataChatMessageHistory } from '@langchain/community/stores/message/xata';\nimport { BaseClient } from '@xata.io/client';\nimport { BufferMemory, BufferWindowMemory } from 'langchain/memory';\nimport { NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';\nimport type {\n\tISupplyDataFunctions,\n\tINodeType,\n\tINodeTypeDescription,\n\tSupplyData,\n} from 'n8n-workflow';\n\nimport { getSessionId } from '@utils/helpers';\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nimport {\n\tsessionIdOption,\n\tsessionKeyProperty,\n\tcontextWindowLengthProperty,\n\texpressionSessionKeyProperty,\n} from '../descriptions';\n\nexport class MemoryXata implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Xata',\n\t\tname: 'memoryXata',\n\t\ticon: 'file:xata.svg',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3, 1.4],\n\t\tdescription: 'Use Xata Memory',\n\t\tdefaults: {\n\t\t\tname: 'Xata',\n\t\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-non-core-color-present\n\t\t\tcolor: '#1321A7',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Memory'],\n\t\t\t\tMemory: ['Other memories'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.memoryxata/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\n\t\tinputs: [],\n\n\t\toutputs: [NodeConnectionTypes.AiMemory],\n\t\toutputNames: ['Memory'],\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'xataApi',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Session ID',\n\t\t\t\tname: 'sessionId',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Session ID',\n\t\t\t\tname: 'sessionId',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '={{ $json.sessionId }}',\n\t\t\t\tdescription: 'The key to use to store the memory',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1.1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...sessionIdOption,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.2 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\tsessionKeyProperty,\n\t\t\texpressionSessionKeyProperty(1.4),\n\t\t\t{\n\t\t\t\t...contextWindowLengthProperty,\n\t\t\t\tdisplayOptions: { hide: { '@version': [{ _cnd: { lt: 1.3 } }] } },\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst credentials = await this.getCredentials('xataApi');\n\t\tconst nodeVersion = this.getNode().typeVersion;\n\n\t\tlet sessionId;\n\n\t\tif (nodeVersion >= 1.2) {\n\t\t\tsessionId = getSessionId(this, itemIndex);\n\t\t} else {\n\t\t\tsessionId = this.getNodeParameter('sessionId', itemIndex) as string;\n\t\t}\n\n\t\tconst xataClient = new BaseClient({\n\t\t\tapiKey: credentials.apiKey as string,\n\t\t\tbranch: (credentials.branch as string) || 'main',\n\t\t\tdatabaseURL: credentials.databaseEndpoint as string,\n\t\t});\n\n\t\tconst table = (credentials.databaseEndpoint as string).match(\n\t\t\t/https:\\/\\/[^.]+\\.[^.]+\\.xata\\.sh\\/db\\/([^\\/:]+)/,\n\t\t);\n\n\t\tif (table === null) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'It was not possible to extract the table from the Database Endpoint.',\n\t\t\t);\n\t\t}\n\n\t\tconst chatHistory = new XataChatMessageHistory({\n\t\t\ttable: table[1],\n\t\t\tsessionId,\n\t\t\tclient: xataClient,\n\t\t\tapiKey: credentials.apiKey as string,\n\t\t});\n\n\t\tconst memClass = this.getNode().typeVersion < 1.3 ? BufferMemory : BufferWindowMemory;\n\t\tconst kOptions =\n\t\t\tthis.getNode().typeVersion < 1.3\n\t\t\t\t? {}\n\t\t\t\t: { k: this.getNodeParameter('contextWindowLength', itemIndex) };\n\n\t\tconst memory = new memClass({\n\t\t\tchatHistory,\n\t\t\tmemoryKey: 'chat_history',\n\t\t\treturnMessages: true,\n\t\t\tinputKey: 'input',\n\t\t\toutputKey: 'output',\n\t\t\t...kOptions,\n\t\t});\n\n\t\treturn {\n\t\t\tresponse: logWrapper(memory, this),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,kBAAuC;AACvC,oBAA2B;AAC3B,oBAAiD;AACjD,0BAAwD;AAQxD,qBAA6B;AAC7B,wBAA2B;AAC3B,0BAA6C;AAE7C,0BAKO;AAEA,MAAM,WAAgC;AAAA,EAAtC;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,OAAO,CAAC,WAAW;AAAA,MACnB,SAAS,CAAC,GAAG,KAAK,KAAK,KAAK,GAAG;AAAA,MAC/B,aAAa;AAAA,MACb,UAAU;AAAA,QACT,MAAM;AAAA;AAAA,QAEN,OAAO;AAAA,MACR;AAAA,MACA,OAAO;AAAA,QACN,YAAY,CAAC,IAAI;AAAA,QACjB,eAAe;AAAA,UACd,IAAI,CAAC,QAAQ;AAAA,UACb,QAAQ,CAAC,gBAAgB;AAAA,QAC1B;AAAA,QACA,WAAW;AAAA,UACV,sBAAsB;AAAA,YACrB;AAAA,cACC,KAAK;AAAA,YACN;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,MAEA,QAAQ,CAAC;AAAA,MAET,SAAS,CAAC,wCAAoB,QAAQ;AAAA,MACtC,aAAa,CAAC,QAAQ;AAAA,MACtB,aAAa;AAAA,QACZ;AAAA,UACC,MAAM;AAAA,UACN,UAAU;AAAA,QACX;AAAA,MACD;AAAA,MACA,YAAY;AAAA,YACX,kDAA6B,CAAC,wCAAoB,OAAO,CAAC;AAAA,QAC1D;AAAA,UACC,aAAa;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;AAAA,QACb;AAAA,MACD;AAAA,IACD;AAEA,UAAM,cAAc,IAAI,mCAAuB;AAAA,MAC9C,OAAO,MAAM,CAAC;AAAA,MACd;AAAA,MACA,QAAQ;AAAA,MACR,QAAQ,YAAY;AAAA,IACrB,CAAC;AAED,UAAM,WAAW,KAAK,QAAQ,EAAE,cAAc,MAAM,6BAAe;AACnE,UAAM,WACL,KAAK,QAAQ,EAAE,cAAc,MAC1B,CAAC,IACD,EAAE,GAAG,KAAK,iBAAiB,uBAAuB,SAAS,EAAE;AAEjE,UAAM,SAAS,IAAI,SAAS;AAAA,MAC3B;AAAA,MACA,WAAW;AAAA,MACX,gBAAgB;AAAA,MAChB,UAAU;AAAA,MACV,WAAW;AAAA,MACX,GAAG;AAAA,IACJ,CAAC;AAED,WAAO;AAAA,MACN,cAAU,8BAAW,QAAQ,IAAI;AAAA,IAClC;AAAA,EACD;AACD;","names":[]}
|
|
@@ -64,9 +64,7 @@ class MemoryZep {
|
|
|
64
64
|
]
|
|
65
65
|
}
|
|
66
66
|
},
|
|
67
|
-
// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node
|
|
68
67
|
inputs: [],
|
|
69
|
-
// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong
|
|
70
68
|
outputs: [import_n8n_workflow.NodeConnectionTypes.AiMemory],
|
|
71
69
|
outputNames: ["Memory"],
|
|
72
70
|
credentials: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/memory/MemoryZep/MemoryZep.node.ts"],"sourcesContent":["
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/memory/MemoryZep/MemoryZep.node.ts"],"sourcesContent":["import type { BaseChatMemory } from '@langchain/community/dist/memory/chat_memory';\nimport { ZepMemory } from '@langchain/community/memory/zep';\nimport { ZepCloudMemory } from '@langchain/community/memory/zep_cloud';\nimport type { InputValues, MemoryVariables } from '@langchain/core/memory';\nimport type { BaseMessage } from '@langchain/core/messages';\nimport {\n\tNodeConnectionTypes,\n\ttype ISupplyDataFunctions,\n\ttype INodeType,\n\ttype INodeTypeDescription,\n\ttype SupplyData,\n\tNodeOperationError,\n} from 'n8n-workflow';\n\nimport { getSessionId } from '@utils/helpers';\nimport { logWrapper } from '@utils/logWrapper';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nimport { expressionSessionKeyProperty, sessionIdOption, sessionKeyProperty } from '../descriptions';\n\n// Extend ZepCloudMemory to trim white space in messages.\nclass WhiteSpaceTrimmedZepCloudMemory extends ZepCloudMemory {\n\toverride async loadMemoryVariables(values: InputValues): Promise<MemoryVariables> {\n\t\tconst memoryVariables = await super.loadMemoryVariables(values);\n\t\tmemoryVariables.chat_history = memoryVariables.chat_history.filter((m: BaseMessage) =>\n\t\t\tm.content.toString().trim(),\n\t\t);\n\t\treturn memoryVariables;\n\t}\n}\n\nexport class MemoryZep implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Zep',\n\t\tname: 'memoryZep',\n\t\t// eslint-disable-next-line n8n-nodes-base/node-class-description-icon-not-svg\n\t\ticon: 'file:zep.png',\n\t\tgroup: ['transform'],\n\t\tversion: [1, 1.1, 1.2, 1.3],\n\t\tdescription: 'Use Zep Memory',\n\t\tdefaults: {\n\t\t\tname: 'Zep',\n\t\t},\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Memory'],\n\t\t\t\tMemory: ['Other memories'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.memoryzep/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\n\t\tinputs: [],\n\n\t\toutputs: [NodeConnectionTypes.AiMemory],\n\t\toutputNames: ['Memory'],\n\t\tcredentials: [\n\t\t\t{\n\t\t\t\tname: 'zepApi',\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t],\n\t\tproperties: [\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Only works with Zep Cloud and Community edition <= v0.27.2',\n\t\t\t\tname: 'supportedVersions',\n\t\t\t\ttype: 'notice',\n\t\t\t\tdefault: '',\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Session ID',\n\t\t\t\tname: 'sessionId',\n\t\t\t\ttype: 'string',\n\t\t\t\trequired: true,\n\t\t\t\tdefault: '',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Session ID',\n\t\t\t\tname: 'sessionId',\n\t\t\t\ttype: 'string',\n\t\t\t\tdefault: '={{ $json.sessionId }}',\n\t\t\t\tdescription: 'The key to use to store the memory',\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [1.1],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\t{\n\t\t\t\t...sessionIdOption,\n\t\t\t\tdisplayOptions: {\n\t\t\t\t\tshow: {\n\t\t\t\t\t\t'@version': [{ _cnd: { gte: 1.2 } }],\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t},\n\t\t\texpressionSessionKeyProperty(1.3),\n\t\t\tsessionKeyProperty,\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst credentials = await this.getCredentials<{\n\t\t\tapiKey?: string;\n\t\t\tapiUrl?: string;\n\t\t\tcloud?: boolean;\n\t\t}>('zepApi');\n\n\t\tconst nodeVersion = this.getNode().typeVersion;\n\n\t\tlet sessionId;\n\n\t\tif (nodeVersion >= 1.2) {\n\t\t\tsessionId = getSessionId(this, itemIndex);\n\t\t} else {\n\t\t\tsessionId = this.getNodeParameter('sessionId', itemIndex) as string;\n\t\t}\n\n\t\tlet memory: BaseChatMemory;\n\n\t\tif (credentials.cloud) {\n\t\t\tif (!credentials.apiKey) {\n\t\t\t\tthrow new NodeOperationError(this.getNode(), 'API key is required to use Zep Cloud');\n\t\t\t}\n\t\t\tmemory = new WhiteSpaceTrimmedZepCloudMemory({\n\t\t\t\tsessionId,\n\t\t\t\tapiKey: credentials.apiKey,\n\t\t\t\tmemoryType: 'perpetual',\n\t\t\t\tmemoryKey: 'chat_history',\n\t\t\t\treturnMessages: true,\n\t\t\t\tinputKey: 'input',\n\t\t\t\toutputKey: 'output',\n\t\t\t\tseparateMessages: false,\n\t\t\t});\n\t\t} else {\n\t\t\tif (!credentials.apiUrl) {\n\t\t\t\tthrow new NodeOperationError(this.getNode(), 'API url is required to use Zep Open Source');\n\t\t\t}\n\t\t\tmemory = new ZepMemory({\n\t\t\t\tsessionId,\n\t\t\t\tbaseURL: credentials.apiUrl,\n\t\t\t\tapiKey: credentials.apiKey,\n\t\t\t\tmemoryKey: 'chat_history',\n\t\t\t\treturnMessages: true,\n\t\t\t\tinputKey: 'input',\n\t\t\t\toutputKey: 'output',\n\t\t\t});\n\t\t}\n\n\t\treturn {\n\t\t\tresponse: logWrapper(memory, this),\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,iBAA0B;AAC1B,uBAA+B;AAG/B,0BAOO;AAEP,qBAA6B;AAC7B,wBAA2B;AAC3B,0BAA6C;AAE7C,0BAAkF;AAGlF,MAAM,wCAAwC,gCAAe;AAAA,EAC5D,MAAe,oBAAoB,QAA+C;AACjF,UAAM,kBAAkB,MAAM,MAAM,oBAAoB,MAAM;AAC9D,oBAAgB,eAAe,gBAAgB,aAAa;AAAA,MAAO,CAAC,MACnE,EAAE,QAAQ,SAAS,EAAE,KAAK;AAAA,IAC3B;AACA,WAAO;AAAA,EACR;A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|
|
53
53
|
}
|
|
54
54
|
},
|
|
55
|
-
// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node
|
|
56
55
|
inputs: [
|
|
57
56
|
{
|
|
58
57
|
displayName: "Model",
|
|
@@ -67,7 +66,6 @@ class OutputParserAutofixing {
|
|
|
67
66
|
type: import_n8n_workflow.NodeConnectionTypes.AiOutputParser
|
|
68
67
|
}
|
|
69
68
|
],
|
|
70
|
-
// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong
|
|
71
69
|
outputs: [import_n8n_workflow.NodeConnectionTypes.AiOutputParser],
|
|
72
70
|
outputNames: ["Output Parser"],
|
|
73
71
|
properties: [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../../../nodes/output_parser/OutputParserAutofixing/OutputParserAutofixing.node.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport { PromptTemplate } from '@langchain/core/prompts';\nimport { NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';\nimport type {\n\tISupplyDataFunctions,\n\tINodeType,\n\tINodeTypeDescription,\n\tSupplyData,\n} from 'n8n-workflow';\n\nimport {\n\tN8nOutputFixingParser,\n\ttype N8nStructuredOutputParser,\n} from '@utils/output_parsers/N8nOutputParser';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nimport { NAIVE_FIX_PROMPT } from './prompt';\n\nexport class OutputParserAutofixing implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Auto-fixing Output Parser',\n\t\tname: 'outputParserAutofixing',\n\t\ticon: 'fa:tools',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'Deprecated, use structured output parser',\n\t\tdefaults: {\n\t\t\tname: 'Auto-fixing Output Parser',\n\t\t},\n\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Output Parsers'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.outputparserautofixing/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\
|
|
1
|
+
{"version":3,"sources":["../../../../nodes/output_parser/OutputParserAutofixing/OutputParserAutofixing.node.ts"],"sourcesContent":["import type { BaseLanguageModel } from '@langchain/core/language_models/base';\nimport { PromptTemplate } from '@langchain/core/prompts';\nimport { NodeConnectionTypes, NodeOperationError } from 'n8n-workflow';\nimport type {\n\tISupplyDataFunctions,\n\tINodeType,\n\tINodeTypeDescription,\n\tSupplyData,\n} from 'n8n-workflow';\n\nimport {\n\tN8nOutputFixingParser,\n\ttype N8nStructuredOutputParser,\n} from '@utils/output_parsers/N8nOutputParser';\nimport { getConnectionHintNoticeField } from '@utils/sharedFields';\n\nimport { NAIVE_FIX_PROMPT } from './prompt';\n\nexport class OutputParserAutofixing implements INodeType {\n\tdescription: INodeTypeDescription = {\n\t\tdisplayName: 'Auto-fixing Output Parser',\n\t\tname: 'outputParserAutofixing',\n\t\ticon: 'fa:tools',\n\t\ticonColor: 'black',\n\t\tgroup: ['transform'],\n\t\tversion: 1,\n\t\tdescription: 'Deprecated, use structured output parser',\n\t\tdefaults: {\n\t\t\tname: 'Auto-fixing Output Parser',\n\t\t},\n\n\t\tcodex: {\n\t\t\tcategories: ['AI'],\n\t\t\tsubcategories: {\n\t\t\t\tAI: ['Output Parsers'],\n\t\t\t},\n\t\t\tresources: {\n\t\t\t\tprimaryDocumentation: [\n\t\t\t\t\t{\n\t\t\t\t\t\turl: 'https://docs.n8n.io/integrations/builtin/cluster-nodes/sub-nodes/n8n-nodes-langchain.outputparserautofixing/',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t},\n\n\t\tinputs: [\n\t\t\t{\n\t\t\t\tdisplayName: 'Model',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\ttype: NodeConnectionTypes.AiLanguageModel,\n\t\t\t\trequired: true,\n\t\t\t},\n\t\t\t{\n\t\t\t\tdisplayName: 'Output Parser',\n\t\t\t\tmaxConnections: 1,\n\t\t\t\trequired: true,\n\t\t\t\ttype: NodeConnectionTypes.AiOutputParser,\n\t\t\t},\n\t\t],\n\n\t\toutputs: [NodeConnectionTypes.AiOutputParser],\n\t\toutputNames: ['Output Parser'],\n\t\tproperties: [\n\t\t\t{\n\t\t\t\tdisplayName:\n\t\t\t\t\t'This node wraps another output parser. If the first one fails it calls an LLM to fix the format',\n\t\t\t\tname: 'info',\n\t\t\t\ttype: 'notice',\n\t\t\t\tdefault: '',\n\t\t\t},\n\t\t\tgetConnectionHintNoticeField([NodeConnectionTypes.AiChain, NodeConnectionTypes.AiAgent]),\n\t\t\t{\n\t\t\t\tdisplayName: 'Options',\n\t\t\t\tname: 'options',\n\t\t\t\ttype: 'collection',\n\t\t\t\tplaceholder: 'Add Option',\n\t\t\t\tdefault: {},\n\t\t\t\toptions: [\n\t\t\t\t\t{\n\t\t\t\t\t\tdisplayName: 'Retry Prompt',\n\t\t\t\t\t\tname: 'prompt',\n\t\t\t\t\t\ttype: 'string',\n\t\t\t\t\t\tdefault: NAIVE_FIX_PROMPT,\n\t\t\t\t\t\ttypeOptions: {\n\t\t\t\t\t\t\trows: 10,\n\t\t\t\t\t\t},\n\t\t\t\t\t\thint: 'Should include \"{error}\", \"{instructions}\", and \"{completion}\" placeholders',\n\t\t\t\t\t\tdescription:\n\t\t\t\t\t\t\t'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.',\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t},\n\t\t],\n\t};\n\n\tasync supplyData(this: ISupplyDataFunctions, itemIndex: number): Promise<SupplyData> {\n\t\tconst model = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiLanguageModel,\n\t\t\titemIndex,\n\t\t)) as BaseLanguageModel;\n\t\tconst outputParser = (await this.getInputConnectionData(\n\t\t\tNodeConnectionTypes.AiOutputParser,\n\t\t\titemIndex,\n\t\t)) as N8nStructuredOutputParser;\n\t\tconst prompt = this.getNodeParameter('options.prompt', itemIndex, NAIVE_FIX_PROMPT) as string;\n\n\t\tif (prompt.length === 0 || !prompt.includes('{error}')) {\n\t\t\tthrow new NodeOperationError(\n\t\t\t\tthis.getNode(),\n\t\t\t\t'Auto-fixing parser prompt has to contain {error} placeholder',\n\t\t\t);\n\t\t}\n\t\tconst parser = new N8nOutputFixingParser(\n\t\t\tthis,\n\t\t\tmodel,\n\t\t\toutputParser,\n\t\t\tPromptTemplate.fromTemplate(prompt),\n\t\t);\n\n\t\treturn {\n\t\t\tresponse: parser,\n\t\t};\n\t}\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,qBAA+B;AAC/B,0BAAwD;AAQxD,6BAGO;AACP,0BAA6C;AAE7C,oBAAiC;AAE1B,MAAM,uBAA4C;AAAA,EAAlD;AACN,uBAAoC;AAAA,MACnC,aAAa;AAAA,MACb,MAAM;AAAA,MACN,MAAM;AAAA,MACN,WAAW;AAAA,MACX,OAAO,CAAC,WAAW;AAAA,MACnB,SAAS;AAAA,MACT,aAAa;AAAA,MACb,UAAU;AAAA,QACT,MAAM;AAAA,MACP;AAAA,MAEA,OAAO;AAAA,QACN,YAAY,CAAC,IAAI;AAAA,QACjB,eAAe;AAAA,UACd,IAAI,CAAC,gBAAgB;AAAA,QACtB;AAAA,QACA,WAAW;AAAA,UACV,sBAAsB;AAAA,YACrB;AAAA,cACC,KAAK;AAAA,YACN;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,MAEA,QAAQ;AAAA,QACP;AAAA,UACC,aAAa;AAAA,UACb,gBAAgB;AAAA,UAChB,MAAM,wCAAoB;AAAA,UAC1B,UAAU;AAAA,QACX;AAAA,QACA;AAAA,UACC,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{
|
|
|
50
50
|
]
|
|
51
51
|
}
|
|
52
52
|
},
|
|
53
|
-
// eslint-disable-next-line n8n-nodes-base/node-class-description-inputs-wrong-regular-node
|
|
54
53
|
inputs: [],
|
|
55
|
-
// eslint-disable-next-line n8n-nodes-base/node-class-description-outputs-wrong
|
|
56
54
|
outputs: [import_n8n_workflow.NodeConnectionTypes.AiOutputParser],
|
|
57
55
|
outputNames: ["Output Parser"],
|
|
58
56
|
properties: [
|