n8n-nodes-smartbrsimpleaiagent
Version:
Smart BR Simple AI Agent custom node for n8n testing
57 lines (50 loc) • 1.46 kB
text/typescript
import { INode, INodeParameters, INodeTypeDescription } from 'n8n-workflow';
export interface INodeType {
description: INodeTypeDescription;
execute(this: INode): Promise<INodeParameters>;
}
export class SimpleAiAgent implements INodeType {
public description: INodeTypeDescription = {
displayName: 'SmartBrSimpleAiAgent',
name: 'smartBrSimpleAiAgent',
icon: 'file:icon.svg',
group: ['transform'],
version: 1,
description: 'Smart BR Simple AI Agent custom node for n8n testing',
defaults: {
name: 'SmartBrSimpleAiAgent',
},
inputs: ['main'] as any,
outputs: ['main'] as any,
credentials: [],
properties: [
{
displayName: 'Prompt',
name: 'prompt',
type: 'string',
required: true,
default: '',
description: 'The prompt to send to the AI agent',
placeholder: 'Enter your prompt here...',
},
],
};
constructor() {
// Construtor vazio - a descrição já está inicializada
}
async execute(this: INode): Promise<INodeParameters> {
const prompt = this.parameters?.prompt as string;
if (!prompt || prompt.trim() === '') {
throw new Error('Prompt is required and cannot be empty');
}
// Simulate AI response with better formatting
const response = {
result: `Resposta da IA simulada para o prompt: ${prompt}`,
timestamp: new Date().toISOString(),
prompt: prompt,
};
return {
json: response,
};
}
}