/** * 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 { DataGridColumnDefinition } from '../data-grid/index.js'; import { type TDSRowDataType, type QueryExplicitExecutionContextInfo, type AbstractPureGraphManager, type GraphManagerState } from '@finos/legend-graph'; import type { LegendApplicationPlugin } from '@finos/legend-application'; import { LegendAI_LegendApplicationPlugin_Extension, type LegendAIOrchestratorDataProductCoordinates } from './LegendAI_LegendApplicationPlugin_Extension.js'; export declare class TDSColumnSchema { name: string; type?: string; documentation?: string; sampleValues?: string; /** Whether this column is nullable (multiplicity lowerBound === 0). */ nullable?: boolean; /** Physical relational type (e.g. 'VARCHAR(100)', 'DECIMAL(18,4)'). */ relationalType?: string; } export declare class TDSParameterSchema { name: string; type?: string; required?: boolean; } /** * Describes a hardcoded filter constraint baked into a service lambda. * These are equality checks, isEmpty/isNotEmpty checks, or isNotNull * guards that are applied before the TDS result is returned. */ export interface TDSServicePreFilter { /** Dot-separated property path (e.g. 'FeSecCoveragePublic.SymCoveragePublicEquities.SymSecEntityPublic.fsymId'). */ property: string; /** The comparison operator. */ operator: 'equal' | 'isEmpty' | 'isNotEmpty' | 'isNotNull'; /** The literal value for equality comparisons. */ value?: string | number | boolean; } export declare enum TDSServiceSourceType { SERVICE = "service", ACCESS_POINT = "accessPoint" } export declare class TDSServiceSchema { title: string; description?: string; pattern: string; columns: TDSColumnSchema[]; parameters: string[]; /** * Rich parameter metadata including type and multiplicity. * When populated, downstream consumers can use this for richer * prompts and user-facing hints. Falls back to `parameters` names. */ parameterSchemas?: TDSParameterSchema[]; /** * Indicates the source of this service schema. * - SERVICE: traditional DataSpace service executable (uses `FROM service(...)` SQL syntax) * - ACCESS_POINT: data product access point (uses `FROM p(...)` SQL syntax with lakehouse runtime) */ sourceType?: TDSServiceSourceType; /** Full data product path (e.g. 'my::package::DataProduct'), used with `p()` syntax for access points. */ dataProductPath?: string; /** * Set to true when parameter extraction from the service query failed. * Downstream consumers can use this to warn users that required parameters * may not be detected automatically. */ parameterExtractionFailed?: boolean; /** Access point group title this AP belongs to. */ accessPointGroupTitle?: string; /** Raw DDL script (CREATE VIEW/TABLE) from the access point resource builder. */ ddlScript?: string; /** * Hardcoded filter constraints extracted from the service lambda. * These indicate pre-applied conditions the AI must not contradict. */ preFilters?: TDSServicePreFilter[]; } export declare class LegendAIConfig { enabled: boolean; llmServiceUrl: string | undefined; llmModelName: string | undefined; llmModelOptions?: string[]; sqlExecutionUrl: string | undefined; orchestratorUrl: string | undefined; marketplaceSearchUrl: string | undefined; engineUrl: string | undefined; orchestratorAuthToken?: string; maxJudgeAttempts?: number; /** Lakehouse runtime environment name (e.g. 'prod', 'uat'). Defaults to 'prod' when not set. */ lakehouseEnvironment?: string; /** URL to EngHub documentation for Legend AI setup. */ enghubDocUrl?: string; /** URL to EntHub request access page for the AI coverage app. */ enthubRequestAccessUrl?: string; } export declare const DEFAULT_LEGEND_AI_CONFIG: LegendAIConfig; /** Runtime environment name that indicates production. */ export declare const LAKEHOUSE_ENV_PROD = "prod"; /** EngHub coverage app name for production. */ export declare const COVERAGE_NAME_PROD = "legend-ai"; /** EngHub coverage app name for non-production (sandbox). */ export declare const COVERAGE_NAME_SANDBOX = "Legend-AI-Sandbox"; /** * Delimiter used in TDS column `doc` fields to separate human-readable * documentation from sample values. Shared across DataProduct and * DataSpace parsers. */ export declare const TDS_SAMPLE_VALUES_DELIMITER = "-- e.g."; export declare function getTodayISO(): string; /** Action ID used to offer the Legend AI Orchestrator as a fallback. */ export declare const LEGEND_AI_ORCHESTRATOR_FALLBACK_ACTION_ID = "orchestrator-fallback"; export declare function findLegendAIPlugin(plugins: LegendApplicationPlugin[]): LegendAI_LegendApplicationPlugin_Extension | undefined; export declare class LegendAIGridData { columnDefs: DataGridColumnDefinition[]; rowData: TDSRowDataType[]; } export declare function buildColumnDefsFromNames(columns: string[]): DataGridColumnDefinition[]; export declare enum LegendAIThinkingStepStatus { ACTIVE = "active", DONE = "done", ERROR = "error" } export declare class LegendAIThinkingStep { id: string; label: string; status: LegendAIThinkingStepStatus; } export declare enum LegendAIErrorType { PERMISSION = "PERMISSION", NETWORK = "NETWORK", EXECUTION = "EXECUTION", GENERATION = "GENERATION", GENERAL = "GENERAL" } export declare class LegendAIServiceError extends Error { name: string; errorType: LegendAIErrorType; constructor(message: string, errorType: LegendAIErrorType); } export declare enum LegendAIMessageRole { USER = "user", ASSISTANT = "assistant" } export declare class LegendAIUserMessage { id: string; role: LegendAIMessageRole.USER; text: string; } export interface LegendAIFallbackAction { label: string; actionId: string; } export declare enum LegendAIMessageFeedbackRating { THUMBS_UP = "thumbs_up", THUMBS_DOWN = "thumbs_down" } export interface LegendAIMessageFeedback { messageId: string; rating: LegendAIMessageFeedbackRating; question: string; answer?: string; sql?: string; rowCount?: number; } export declare class LegendAIAssistantMessage { id: string; role: LegendAIMessageRole.ASSISTANT; thinkingSteps: LegendAIThinkingStep[]; sql: string | null; textAnswer: string | null; dataContext: string | null; gridData: LegendAIGridData | null; error: string | null; errorType: LegendAIErrorType | null; sqlGenTime: string | null; execTime: string | null; thinkingDuration: string | null; isProcessing: boolean; isExecuting: boolean; suggestedQueries: string[]; fallbackAction: LegendAIFallbackAction | null; } export type LegendAIMessage = LegendAIUserMessage | LegendAIAssistantMessage; export declare class LegendAIConversationTurn { question: string; sql: string; /** * The intent classification of this turn, allowing downstream prompts * to differentiate prior metadata answers from SQL query results. */ intent?: LegendAIQuestionIntent; /** Number of rows returned by the query, when available. */ rowCount?: number; /** Brief summary of the result (e.g. column names, first few values). */ resultSummary?: string; } export interface LegendAIChatState { questionText: string; setQuestionText: (text: string) => void; isSending: boolean; messages: LegendAIMessage[]; selectedModelName: string | undefined; availableModelNames: string[]; setSelectedModelName: (modelName: string) => void; askQuestion: () => void; askQuestionWithIntent: (text: string, intent: LegendAIQuestionIntent) => void; runFallbackAction: (messageId: string) => void; clearChat: () => void; expandedThinking: Set; toggleThinking: (index: number) => void; conversationRef: { readonly current: HTMLDivElement | null; }; selectedScopes: LegendAIScopeItem[]; toggleScope: (scope: LegendAIScopeItem) => void; removeScope: (scopeId: string) => void; stopGeneration: () => void; } export interface LegendAIScopeItem { id: string; label: string; description?: string; } export interface LegendAIServiceSummary { title: string; description?: string; columnNames?: string[]; parameters?: string[]; } export interface LegendAIAccessPointInfo { title?: string; description?: string; } export interface LegendAITagInfo { profile: string; value: string; } export declare class LegendAIAccessPointGroupInfo { title: string; description?: string; accessPoints: LegendAIAccessPointInfo[]; } export interface LegendAIAccessPointRelationship { leftAccessPoint: string; rightAccessPoint: string; sharedColumns: string[]; } /** * Describes a relationship between two TDS services in a DataSpace, * derived from model association documentation (elementDocs). * Used to generate accurate JOIN hints in LLM prompts. */ export interface LegendAIServiceRelationship { /** Title of the first service. */ leftService: string; /** Title of the second service. */ rightService: string; /** Column names that can serve as JOIN keys between the services. */ joinColumns: string[]; /** Name of the intermediate entity connecting both services (e.g. "Own2Ownermap"). */ viaEntity?: string; /** Cardinality from the connecting entity to the left service (e.g. "1:*"). */ leftCardinality?: string; /** Cardinality from the connecting entity to the right service (e.g. "1:*"). */ rightCardinality?: string; } export declare class LegendAIProductMetadata { name: string; description?: string; coordinates: string; serviceSummaries: LegendAIServiceSummary[]; accessPointGroups?: LegendAIAccessPointGroupInfo[]; tags?: LegendAITagInfo[]; supportInfo?: string; /** Inferred cross-access-point relationships based on shared column names. */ accessPointRelationships?: LegendAIAccessPointRelationship[]; /** Cross-service relationships derived from model associations (elementDocs). */ serviceRelationships?: LegendAIServiceRelationship[]; /** Per-product domain knowledge for LLM context enrichment. */ domainContext?: string; } export declare enum LegendAIQuestionIntent { DATA_QUERY = "data_query", METADATA = "metadata", ORCHESTRATOR = "orchestrator" } export declare const METADATA_SIGNAL_PATTERNS: readonly RegExp[]; export declare const DATA_QUERY_SIGNAL_PATTERNS: readonly RegExp[]; /** * Result of the fast deterministic regex-based classifier. * Includes the scores and resolved intent so callers can decide * whether the classification is confident or needs LLM arbitration. */ export declare class QuestionIntentClassification { intent: LegendAIQuestionIntent; metaScore: number; dataScore: number; ambiguous: boolean; } /** * Fast deterministic regex classifier (sync, < 1ms). * Returns both the resolved intent AND whether the result is ambiguous, * so callers can decide to escalate to an LLM for ambiguous cases. */ export declare function classifyQuestionIntentFast(question: string, hasServices: boolean): QuestionIntentClassification; /** * Legacy synchronous classifier for backward compatibility. * Returns just the intent, discarding ambiguity info. */ export declare function classifyQuestionIntent(question: string, hasServices: boolean): LegendAIQuestionIntent; export declare function extractParameterSchemas(query: string, graphManager: AbstractPureGraphManager, graphManagerState: GraphManagerState): Promise<{ parameters: string[]; parameterSchemas: TDSParameterSchema[]; parameterExtractionFailed: boolean; }>; export interface LegendAIChatProps { services: TDSServiceSchema[]; coordinates: string; config: LegendAIConfig; metadata: LegendAIProductMetadata; title?: string; plugin: LegendAI_LegendApplicationPlugin_Extension; /** * Structured data product coordinates for the Legend AI Orchestrator flow. * When provided alongside an orchestratorUrl in config, enables ad-hoc * query generation via entity resolution + orchestrator. */ dataProductCoordinates?: LegendAIOrchestratorDataProductCoordinates; /** * Execution context (mapping + runtime) for executing Pure queries * returned by the orchestrator. Required for the execute-after-generate flow. */ pureExecutionContext?: QueryExplicitExecutionContextInfo; availableScopes?: LegendAIScopeItem[]; /** Called when the user clicks the close button in the chat header. */ onClose?: () => void; /** Called when the user clicks the minimize button in the chat header. */ onMinimize?: () => void; /** * Optional callback fired when users submit thumbs-up/down feedback * for an assistant response. */ onMessageFeedback?: (feedback: LegendAIMessageFeedback) => Promise | void; } //# sourceMappingURL=LegendAITypes.d.ts.map