refactor(core): All calls to supplyData should use a distinct context type (no-changelog) (#11421)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-10-28 11:37:23 +01:00
committed by GitHub
parent 04c075a46b
commit 8f5fe05a92
70 changed files with 560 additions and 308 deletions

View File

@@ -1,7 +1,7 @@
import type { Callbacks } from '@langchain/core/callbacks/manager';
import { StructuredOutputParser } from 'langchain/output_parsers';
import get from 'lodash/get';
import type { IExecuteFunctions } from 'n8n-workflow';
import type { ISupplyDataFunctions } from 'n8n-workflow';
import { NodeConnectionType, NodeOperationError } from 'n8n-workflow';
import { z } from 'zod';
@@ -14,11 +14,11 @@ const STRUCTURED_OUTPUT_ARRAY_KEY = '__structured__output__array';
export class N8nStructuredOutputParser extends StructuredOutputParser<
z.ZodType<object, z.ZodTypeDef, object>
> {
context: IExecuteFunctions;
constructor(context: IExecuteFunctions, zodSchema: z.ZodSchema<object>) {
constructor(
private context: ISupplyDataFunctions,
zodSchema: z.ZodSchema<object>,
) {
super(zodSchema);
this.context = context;
}
lc_namespace = ['langchain', 'output_parsers', 'structured'];
@@ -39,7 +39,7 @@ export class N8nStructuredOutputParser extends StructuredOutputParser<
get(parsed, STRUCTURED_OUTPUT_KEY) ??
parsed) as Record<string, unknown>;
void logAiEvent(this.context, 'ai-output-parsed', { text, response: result });
logAiEvent(this.context, 'ai-output-parsed', { text, response: result });
this.context.addOutputData(NodeConnectionType.AiOutputParser, index, [
[{ json: { action: 'parse', response: result } }],
@@ -56,7 +56,7 @@ export class N8nStructuredOutputParser extends StructuredOutputParser<
},
);
void logAiEvent(this.context, 'ai-output-parsed', {
logAiEvent(this.context, 'ai-output-parsed', {
text,
response: e.message ?? e,
});
@@ -73,7 +73,7 @@ export class N8nStructuredOutputParser extends StructuredOutputParser<
static async fromZodJsonSchema(
zodSchema: z.ZodSchema<object>,
nodeVersion: number,
context: IExecuteFunctions,
context: ISupplyDataFunctions,
): Promise<N8nStructuredOutputParser> {
let returnSchema: z.ZodType<object, z.ZodTypeDef, object>;
if (nodeVersion === 1) {