import type { BaseChatModel, BaseChatModelCallOptions } from '@langchain/core/language_models/chat_models'; import type { AIMessage, BaseMessage } from '@langchain/core/messages'; import type { Runnable } from '@langchain/core/runnables'; import type { StructuredToolInterface } from '@langchain/core/tools'; import { type NodeTypeParser } from '@n8n/ai-utilities/node-catalog'; import type { Logger } from '@n8n/backend-common'; import type { WorkflowJSON } from '@n8n/workflow-sdk'; import { type HistoryContext } from '../prompts'; import { TextEditorHandler } from './text-editor-handler'; import { TextEditorToolHandler } from './text-editor-tool-handler'; import type { PlanOutput } from '../../types/planning'; import type { ChatPayload } from '../../workflow-builder-agent'; import type { ParseAndValidateResult } from '../types'; type ParseAndValidateFn = (code: string, currentWorkflow?: WorkflowJSON) => Promise; type GetErrorContextFn = (code: string, errorMessage: string) => string; export interface ChatSetupHandlerConfig { llm: BaseChatModel; tools: StructuredToolInterface[]; enableTextEditorConfig?: boolean; parseAndValidate: ParseAndValidateFn; getErrorContext: GetErrorContextFn; nodeTypeParser?: NodeTypeParser; logger?: Logger; } export interface ChatSetupParams { payload: ChatPayload; historyContext?: HistoryContext; } export type LlmWithTools = Runnable; export interface ChatSetupResult { llmWithTools: LlmWithTools; messages: BaseMessage[]; textEditorEnabled: boolean; preGeneratedWorkflowCode?: string; currentWorkflow?: WorkflowJSON; textEditorHandler?: TextEditorHandler; textEditorToolHandler?: TextEditorToolHandler; } export declare class ChatSetupHandler { private llm; private tools; private enableTextEditorConfig?; private parseAndValidate; private getErrorContext; private nodeTypeParser?; private logger?; constructor(config: ChatSetupHandlerConfig); execute(params: ChatSetupParams): Promise; private shouldEnableTextEditor; private preGenerateWorkflowCode; private bindToolsToLlm; private formatInitialMessages; private initializeTextEditorHandlers; private prefetchSearchResults; } export declare function extractNodeNamesFromPlan(plan: PlanOutput): string[]; export {};