/** * Copyright (c) 2026-present, Goldman Sachs * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ import type React from 'react'; import { type TDSServiceSchema, type LegendAIConfig, type LegendAIAssistantMessage, type LegendAIUserMessage, type LegendAIMessage, type LegendAIConversationTurn, type LegendAIProductMetadata, LegendAIQuestionIntent, LegendAIErrorType } from '../LegendAITypes.js'; import { type LegendAI_LegendApplicationPlugin_Extension, type LegendAIOrchestratorDataProductCoordinates, type LegendAISqlExecutionResultData, type LegendAIResolvedEntities } from '../LegendAI_LegendApplicationPlugin_Extension.js'; import { type QueryExplicitExecutionContextInfo } from '@finos/legend-graph'; export declare function elapsedSeconds(startTime: number, decimals?: 1 | 2): string; export type MessageSetter = React.Dispatch>; export declare function createMessagePair(text: string): [LegendAIUserMessage, LegendAIAssistantMessage]; export interface LegendAIOperationContext { config: LegendAIConfig; plugin: LegendAI_LegendApplicationPlugin_Extension; history: LegendAIConversationTurn[]; setMessages: MessageSetter; } interface LegendAIOrchestratorOptionsParam { dataProductCoordinates: LegendAIOrchestratorDataProductCoordinates; pureExecutionContext?: QueryExplicitExecutionContextInfo; } export declare function updateLastAssistant(setMessages: MessageSetter, updater: (msg: LegendAIAssistantMessage) => Partial): void; export declare function addThinkingStep(setMessages: MessageSetter, label: string): void; export declare function completeThinkingSteps(setMessages: MessageSetter): void; export declare function classifyError(error: Error): LegendAIErrorType; export declare function finishWithThinkingError(setMessages: MessageSetter, errorMsg: string, startTime: number, errorType?: LegendAIErrorType): void; export declare function buildConversationHistory(messages: LegendAIMessage[]): LegendAIConversationTurn[]; export declare function buildGenerationFailureMessage(failure: string, suggestion: string | undefined, services: TDSServiceSchema[]): string; export declare function buildExecutionErrorMessage(errStr: string, services: TDSServiceSchema[]): string; export declare function buildMetadataOverview(question: string, metadata: LegendAIProductMetadata, context: LegendAIOperationContext): Promise; export declare function attachMetadataOverview(setMessages: MessageSetter, metadataOverview: string): void; export declare function handleMetadataQuestion(question: string, metadata: LegendAIProductMetadata, context: LegendAIOperationContext, startTime: number, hasQueryableServices?: boolean): Promise; export declare function generateAndJudgeSql(question: string, services: TDSServiceSchema[], coordinates: string, context: LegendAIOperationContext, startTime: number, metadata?: LegendAIProductMetadata): Promise; /** * Dedicated generate-and-judge loop for access point queries. * Uses AP-specific prompts that focus on `p()` syntax and omit * coordinates, parameters, and service()-related rules. */ export declare function generateAndJudgeAccessPointSql(question: string, accessPoints: TDSServiceSchema[], context: LegendAIOperationContext, startTime: number): Promise; export declare function executeSqlAndReport(sql: string, services: TDSServiceSchema[], config: LegendAIConfig, plugin: LegendAI_LegendApplicationPlugin_Extension, setMessages: MessageSetter, startTime: number, dataProductCoordinates?: LegendAIOrchestratorDataProductCoordinates): Promise; export declare function executePureQueryAndReport(pureQuery: string, pureExecutionContext: QueryExplicitExecutionContextInfo, dataProductCoordinates: LegendAIOrchestratorDataProductCoordinates, config: LegendAIConfig, plugin: LegendAI_LegendApplicationPlugin_Extension, setMessages: MessageSetter, startTime: number): Promise; export declare function analyzeOrchestratorResults(question: string, query: string, execResult: LegendAISqlExecutionResultData, metadata: LegendAIProductMetadata, context: LegendAIOperationContext, startTime: number): Promise; export declare function processQuestionViaOrchestrator(question: string, dataProductCoordinates: LegendAIOrchestratorDataProductCoordinates, metadata: LegendAIProductMetadata, context: LegendAIOperationContext, pureExecutionContext?: QueryExplicitExecutionContextInfo, preResolvedEntities?: LegendAIResolvedEntities): Promise; export declare function cleanLlmSqlResponse(raw: string): string; export declare function isValidSqlCorrection(trimmed: string, currentSql: string): boolean; export declare function sanitizeJoinOrderBy(sql: string): string; export declare function sanitizeLiteralColumns(sql: string): string; /** * Strips non-date service parameters whose values were NOT explicitly * mentioned by the user in their question. Parameters with values that * appear in the question text are kept, since those are user-intended. */ export declare function stripGuessedNonDateServiceParams(sql: string, question: string): string; /** * Ensures all date-like parameters from the service schemas are present * in EVERY service() call in the SQL. If the LLM omitted a mandatory date * parameter, this injects it with today's date into each service() call * that lacks it. Only applies to service() calls (not p() calls). */ export declare function ensureDateParameters(sql: string, services: TDSServiceSchema[]): string; export interface MissingParamInfo { name: string; hint?: string; isDateLike: boolean; } /** * Detects ALL service parameters required by the schema but missing from * the generated SQL. Works for any parameter type — date, identifier, key, * or anything else. Each result includes a hint (from schema column docs * or sample values) and whether the param is date-like. */ export declare function detectMissingServiceParams(sql: string, services: TDSServiceSchema[]): MissingParamInfo[]; /** * Builds a user-facing warning message listing which service parameters * are missing from the query and need to be provided by the user. */ export declare function buildMissingParamsWarning(missingParams: MissingParamInfo[]): string; /** * Appends a safety LIMIT to queries that lack one, preventing unbounded * result sets on large services. Skips aggregation queries since those * naturally produce bounded output. */ export declare function ensureSafeLimit(sql: string, limit?: number): string; /** * Scores each service against the user question by counting keyword * overlap between the question tokens and the service title, description, * column names, and parameter names. Returns services sorted by * descending relevance score. */ export declare function preFilterServicesByRelevance(question: string, services: TDSServiceSchema[], limit: number): TDSServiceSchema[]; export declare function processQuestion(question: string, services: TDSServiceSchema[], coordinates: string, metadata: LegendAIProductMetadata, context: LegendAIOperationContext, dataProductCoordinates?: LegendAIOrchestratorDataProductCoordinates, pureExecutionContext?: QueryExplicitExecutionContextInfo): Promise; export declare function processQuestionWithIntent(question: string, intent: LegendAIQuestionIntent, services: TDSServiceSchema[], coordinates: string, metadata: LegendAIProductMetadata, context: LegendAIOperationContext, orchestratorOptions?: LegendAIOrchestratorOptionsParam): Promise; export {}; //# sourceMappingURL=LegendAIChatProcessors.d.ts.map