Skip to content

Commit

Permalink
fix type errors in workflow, core, nodes-langchain, and nodes-base
Browse files Browse the repository at this point in the history
  • Loading branch information
netroy committed May 17, 2024
1 parent ef7fdb4 commit 6591ee6
Show file tree
Hide file tree
Showing 107 changed files with 248 additions and 926 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function getInputs(
[NodeConnectionType.AiOutputParser]: 'Output Parser',
};

return inputs.map(({ type, filter, required }) => {
return inputs.map(({ type, filter }) => {
const input: INodeInputConfiguration = {
type,
displayName: type in displayNames ? displayNames[type] : undefined,
Expand Down Expand Up @@ -370,13 +370,13 @@ export class Agent implements INodeType {
if (agentType === 'conversationalAgent') {
return await conversationalAgentExecute.call(this, nodeVersion);
} else if (agentType === 'toolsAgent') {
return await toolsAgentExecute.call(this, nodeVersion);
return await toolsAgentExecute.call(this);
} else if (agentType === 'openAiFunctionsAgent') {
return await openAiFunctionsAgentExecute.call(this, nodeVersion);
} else if (agentType === 'reActAgent') {
return await reActAgentAgentExecute.call(this, nodeVersion);
} else if (agentType === 'sqlAgent') {
return await sqlAgentAgentExecute.call(this, nodeVersion);
return await sqlAgentAgentExecute.call(this);
} else if (agentType === 'planAndExecuteAgent') {
return await planAndExecuteAgentExecute.call(this, nodeVersion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,5 +120,5 @@ export async function conversationalAgentExecute(
}
}

return await this.prepareOutputData(returnData);
return [returnData];
}
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,5 @@ export async function openAiFunctionsAgentExecute(
}
}

return await this.prepareOutputData(returnData);
return [returnData];
}
Original file line number Diff line number Diff line change
Expand Up @@ -100,5 +100,5 @@ export async function planAndExecuteAgentExecute(
}
}

return await this.prepareOutputData(returnData);
return [returnData];
}
Original file line number Diff line number Diff line change
Expand Up @@ -121,5 +121,5 @@ export async function reActAgentAgentExecute(
}
}

return await this.prepareOutputData(returnData);
return [returnData];
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ const parseTablesString = (tablesString: string) =>

export async function sqlAgentAgentExecute(
this: IExecuteFunctions,
nodeVersion: number,
): Promise<INodeExecutionData[][]> {
this.logger.verbose('Executing SQL Agent');

Expand Down Expand Up @@ -152,5 +151,5 @@ export async function sqlAgentAgentExecute(
}
}

return await this.prepareOutputData(returnData);
return [returnData];
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ function getOutputParserSchema(outputParser: BaseOutputParser): ZodObject<any, a
return schema;
}

export async function toolsAgentExecute(
this: IExecuteFunctions,
nodeVersion: number,
): Promise<INodeExecutionData[][]> {
export async function toolsAgentExecute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
this.logger.verbose('Executing Tools Agent');
const model = await this.getInputConnectionData(NodeConnectionType.AiLanguageModel, 0);

Expand Down Expand Up @@ -185,5 +182,5 @@ export async function toolsAgentExecute(
}
}

return await this.prepareOutputData(returnData);
return [returnData];
}
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,6 @@ export class OpenAiAssistant implements INodeType {
}
}

return await this.prepareOutputData(returnData);
return [returnData];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,6 @@ export class ChainRetrievalQa implements INodeType {
throw error;
}
}
return await this.prepareOutputData(returnData);
return [returnData];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,6 @@ export class ChainSummarizationV1 implements INodeType {
returnData.push({ json: { response } });
}

return await this.prepareOutputData(returnData);
return [returnData];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,6 @@ export class ChainSummarizationV2 implements INodeType {
}
}

return await this.prepareOutputData(returnData);
return [returnData];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export class MemoryChatRetriever implements INodeType {
const messages = await memory?.chatHistory.getMessages();

if (simplifyOutput && messages) {
return await this.prepareOutputData(simplifyMessages(messages));
return [simplifyMessages(messages)];
}

const serializedMessages =
Expand All @@ -107,6 +107,6 @@ export class MemoryChatRetriever implements INodeType {
return { json: serializedMessage as unknown as IDataObject };
}) ?? [];

return await this.prepareOutputData(serializedMessages);
return [serializedMessages];
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { IExecuteFunctions, IWorkflowDataProxyData } from 'n8n-workflow';
import type { IExecuteFunctions, INode, IWorkflowDataProxyData } from 'n8n-workflow';
import { mock } from 'jest-mock-extended';
import { normalizeItems } from 'n8n-core';
import type { z } from 'zod';
Expand All @@ -12,7 +12,7 @@ describe('OutputParserStructured', () => {
});
const workflowDataProxy = mock<IWorkflowDataProxyData>({ $input: mock() });
thisArg.getWorkflowDataProxy.mockReturnValue(workflowDataProxy);
thisArg.getNode.mockReturnValue({ typeVersion: 1.1 });
thisArg.getNode.mockReturnValue(mock<INode>({ typeVersion: 1.1 }));
thisArg.addInputData.mockReturnValue({ index: 0 });
thisArg.addOutputData.mockReturnValue();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,6 @@ export class VectorStoreInMemoryInsert implements INodeType {
clearStore,
);

return await this.prepareOutputData(serializedDocuments);
return [serializedDocuments];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,6 @@ export class VectorStorePineconeInsert implements INodeType {
pineconeIndex,
});

return await this.prepareOutputData(serializedDocuments);
return [serializedDocuments];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const VectorStoreQdrant = createVectorStoreNode({
methods: { listSearch: { qdrantCollectionsSearch } },
insertFields,
sharedFields,
async getVectorStoreClient(context, filter, embeddings, itemIndex) {
async getVectorStoreClient(context, _, embeddings, itemIndex) {
const collection = context.getNodeParameter('qdrantCollection', itemIndex, '', {
extractValue: true,
}) as string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,6 @@ export class VectorStoreSupabaseInsert implements INodeType {
queryName,
});

return await this.prepareOutputData(serializedDocuments);
return [serializedDocuments];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,6 @@ export class VectorStoreZepInsert implements INodeType {

await ZepVectorStore.fromDocuments(processedDocuments, embeddings, zepConfig);

return await this.prepareOutputData(serializedDocuments);
return [serializedDocuments];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ export const createVectorStoreNode = (args: VectorStoreNodeConstructorArgs) =>
void logAiEvent(this, 'n8n.ai.vector.store.searched', { query: prompt });
}

return await this.prepareOutputData(resultData);
return [resultData];
}

if (mode === 'insert') {
Expand Down Expand Up @@ -270,7 +270,7 @@ export const createVectorStoreNode = (args: VectorStoreNodeConstructorArgs) =>
}
}

return await this.prepareOutputData(resultData);
return [resultData];
}

throw new NodeOperationError(
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/Secrets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { ExpressionError } from 'n8n-workflow';

function buildSecretsValueProxy(value: IDataObject): unknown {
return new Proxy(value, {
get(target, valueName) {
get(_target, valueName) {
if (typeof valueName !== 'string') {
return;
}
Expand All @@ -27,15 +27,15 @@ export function getSecretsProxy(additionalData: IWorkflowExecuteAdditionalData):
return new Proxy(
{},
{
get(target, providerName) {
get(_target, providerName) {
if (typeof providerName !== 'string') {
return {};
}
if (secretsHelpers.hasProvider(providerName)) {
return new Proxy(
{},
{
get(target2, secretName) {
get(_target2, secretName) {
if (typeof secretName !== 'string') {
return;
}
Expand Down
14 changes: 9 additions & 5 deletions packages/core/test/ObjectStore.manager.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import fs from 'node:fs/promises';
import { mock } from 'jest-mock-extended';
import { ObjectStoreManager } from '@/BinaryData/ObjectStore.manager';
import { ObjectStoreService } from '@/ObjectStore/ObjectStore.service.ee';
import { isStream } from '@/ObjectStore/utils';
import type { MetadataResponseHeaders } from '@/ObjectStore/types';
import { mockInstance, toFileId, toStream } from './utils';

jest.mock('fs/promises');
Expand Down Expand Up @@ -74,11 +76,13 @@ describe('getMetadata()', () => {
const mimeType = 'text/plain';
const fileName = 'file.txt';

objectStoreService.getMetadata.mockResolvedValue({
'content-length': '1',
'content-type': mimeType,
'x-amz-meta-filename': fileName,
});
objectStoreService.getMetadata.mockResolvedValue(
mock<MetadataResponseHeaders>({
'content-length': '1',
'content-type': mimeType,
'x-amz-meta-filename': fileName,
}),
);

const metadata = await objectStoreManager.getMetadata(fileId);

Expand Down
Loading

0 comments on commit 6591ee6

Please sign in to comment.