Skip to content

Commit

Permalink
fix(Code Tool Node): Fix Input Schema Parameter not hiding correctly (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
CharlieKolb authored Feb 17, 2025
1 parent b4380d0 commit 8e15ebf
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ import type {
} from 'n8n-workflow';
import { jsonParse, NodeConnectionType, NodeOperationError } from 'n8n-workflow';

import { inputSchemaField, jsonSchemaExampleField, schemaTypeField } from '@utils/descriptions';
import {
buildInputSchemaField,
buildJsonSchemaExampleField,
schemaTypeField,
} from '@utils/descriptions';
import { convertJsonSchemaToZod, generateSchema } from '@utils/schemaParsing';
import { getConnectionHintNoticeField } from '@utils/sharedFields';

Expand Down Expand Up @@ -168,8 +172,8 @@ export class ToolCode implements INodeType {
default: false,
},
{ ...schemaTypeField, displayOptions: { show: { specifyInputSchema: [true] } } },
jsonSchemaExampleField,
inputSchemaField,
buildJsonSchemaExampleField({ showExtraProps: { specifyInputSchema: [true] } }),
buildInputSchemaField({ showExtraProps: { specifyInputSchema: [true] } }),
],
};

Expand Down
20 changes: 15 additions & 5 deletions packages/@n8n/nodes-langchain/utils/descriptions.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { INodeProperties } from 'n8n-workflow';
import type { DisplayCondition, INodeProperties, NodeParameterValue } from 'n8n-workflow';

export const schemaTypeField: INodeProperties = {
displayName: 'Schema Type',
Expand All @@ -21,7 +21,9 @@ export const schemaTypeField: INodeProperties = {
description: 'How to specify the schema for the function',
};

export const jsonSchemaExampleField: INodeProperties = {
export const buildJsonSchemaExampleField = (props?: {
showExtraProps?: Record<string, Array<NodeParameterValue | DisplayCondition> | undefined>;
}): INodeProperties => ({
displayName: 'JSON Example',
name: 'jsonSchemaExample',
type: 'json',
Expand All @@ -34,13 +36,18 @@ export const jsonSchemaExampleField: INodeProperties = {
},
displayOptions: {
show: {
...props?.showExtraProps,
schemaType: ['fromJson'],
},
},
description: 'Example JSON object to use to generate the schema',
};
});

export const jsonSchemaExampleField = buildJsonSchemaExampleField();

export const inputSchemaField: INodeProperties = {
export const buildInputSchemaField = (props?: {
showExtraProps?: Record<string, Array<NodeParameterValue | DisplayCondition> | undefined>;
}): INodeProperties => ({
displayName: 'Input Schema',
name: 'inputSchema',
type: 'json',
Expand All @@ -59,11 +66,14 @@ export const inputSchemaField: INodeProperties = {
},
displayOptions: {
show: {
...props?.showExtraProps,
schemaType: ['manual'],
},
},
description: 'Schema to use for the function',
};
});

export const inputSchemaField = buildInputSchemaField();

export const promptTypeOptions: INodeProperties = {
displayName: 'Source for Prompt (User Message)',
Expand Down

0 comments on commit 8e15ebf

Please # to comment.