// src/nodes/llmCompletionNode.ts
import { BaseAINode, BaseAINodeInput } from './baseAINode';
import { INodeContext, INodeOutput } from '@flowlab/core';
import { IAIProvider, AIModelOptions } from '../types';

interface LLMCompletionNodeInput extends BaseAINodeInput {
  promptTemplate: string; // Make prompt mandatory for this node
}

export class LLMCompletionNode extends BaseAINode {
  id = 'LLMCompletionNode';

  // MARK: 执行AI
  protected async executeAI(context: INodeContext, provider: IAIProvider, renderedPrompt: string): Promise<Record<string, any>> {
    const options = (context.input as LLMCompletionNodeInput).modelOptions;
    const { text, usage } = await provider.generateText(renderedPrompt, options, context);
    return { completionText: text, usage };
  }

  // MARK: 验证输入
  validateInput(input: Record<string, any>): boolean {
    if (!super.validateInput(input)) return false;
    if (!input.promptTemplate || typeof input.promptTemplate !== 'string') {
      console.error(`Validation Error [${this.id}]: Missing or invalid 'promptTemplate'.`);
      return false;
    }
    return true;
  }
}

// src/nodes/structuredDataExtractionNode.ts


// src/nodes/functionCallingNode.ts


// --- Add other nodes similarly: ---
// EmbeddingNode, ClassificationNode, LLMChatNode etc.
// Potentially a VectorSearchNode (might depend on specific vector DB client libraries)