/** * 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 GeneratorFn } from '@finos/legend-shared'; import { type LegendAIMessage, type LegendAIConfig, type LegendAIProductMetadata, type LegendAIOrchestratorDataProductCoordinates, type TDSServiceSchema, type LegendAI_LegendApplicationPlugin_Extension, type MessageSetter, type LegendAIModelContext, LegendAIPythonCodeStatus, LegendAIResolvedEntities } from '@finos/legend-lego/legend-ai'; import { type V1_EntitlementsDataProductDetails, QueryExplicitExecutionContextInfo } from '@finos/legend-graph'; import type { LegendMarketplaceBaseStore } from '../LegendMarketplaceBaseStore.js'; import { type AutosuggestResult, DataProductSearchResult } from '@finos/legend-server-marketplace'; export declare enum MarketplaceAIChatStage { IDLE = "idle", SEARCHING = "searching", PRODUCT_SELECTION = "product-selection", QUERYING = "querying", RESULTS = "results" } interface DataSpaceScope { services: TDSServiceSchema[]; metadata: LegendAIProductMetadata; modelContext: LegendAIModelContext | undefined; pureExecutionContext: QueryExplicitExecutionContextInfo | undefined; } type PythonCodeEntry = { status: LegendAIPythonCodeStatus.LOADING; } | { status: LegendAIPythonCodeStatus.READY; code: string; notebookUrl?: string; } | { status: LegendAIPythonCodeStatus.ERROR; error: string; }; export interface ScoredProductCandidate { product: DataProductSearchResult; productSimilarity: number; fieldCoverage: number; fieldIntersection: number; matchedFields: string[]; missingFields: string[]; compositeScore: number; } export declare function unwrapProductDetails(product: DataProductSearchResult): { groupId: string; artifactId: string; versionId: string; path: string; }; export declare class LegendMarketplaceAIChatStore { readonly baseStore: LegendMarketplaceBaseStore; stage: MarketplaceAIChatStage; questionText: string; messages: LegendAIMessage[]; isSending: boolean; suggestedProducts: DataProductSearchResult[]; scoredCandidates: ScoredProductCandidate[]; scopeProducts: { name: string; coordinates: LegendAIOrchestratorDataProductCoordinates; }[]; selectedProduct: DataProductSearchResult | undefined; selectedProductCoordinates: LegendAIOrchestratorDataProductCoordinates | undefined; selectedProductMetadata: LegendAIProductMetadata | undefined; pureExecutionContext: QueryExplicitExecutionContextInfo | undefined; pendingFallbackQuestion: string | undefined; resolvedProductServices: TDSServiceSchema[]; lastResolvedEntities: LegendAIResolvedEntities | undefined; lastEntityCandidates: { datasetName: string; modelPath: string; description?: string; }[]; selectedDataProductId: string | undefined; private tokenProvider; private readonly accessPointScopeCache; private readonly dataSpaceScopeCache; pythonCodeByMessageId: Map; private lastResolvedLakehouseConfig; resolvedOpenInDataCube: ((accessPointName: string, environmentName: string, extraSourceData?: Record) => void) | undefined; resolvedEnvironmentName: string | undefined; constructor(baseStore: LegendMarketplaceBaseStore); get config(): LegendAIConfig; get plugin(): LegendAI_LegendApplicationPlugin_Extension | undefined; get isEnabled(): boolean; get lastUserMessageText(): string; get scopedCoordinatesString(): string; private get scopeCacheKey(); get welcomeSuggestedQueries(): string[]; setQuestionText(text: string): void; setStage(stage: MarketplaceAIChatStage): void; logCopySql(): void; logSuggestedQueryClicked(): void; logGeneratePython(): void; logCopyPython(): void; logOpenInDataCube(): void; get supportsPython(): boolean; get supportsDataCube(): boolean; /** * The service an action applies to. Falls back to one the action actually * supports, so the button's availability and its target cannot disagree. */ private serviceForMessage; private questionForMessage; generatePythonCode(messageId: string): GeneratorFn; openInDataCube(messageId: string): GeneratorFn; private logQuestionAsked; private logResponseReceived; clearChat(): void; private createMessageSetter; private buildContextPromise; private buildConversationHistory; private extractMetadata; private buildTitleFromPath; private multiSignalSearch; private deriveProductsFromFieldResults; private buildDerivedProduct; private computeScoredCandidates; /** * Interleaves both candidate sources so field-derived products always get a * slot: {@link PRODUCT_CANDIDATES_PER_FIELD_CANDIDATE} from search, then one field. */ private mergeInterleaved; private llmRerankProducts; private buildRankedList; submitQuery(text: string): GeneratorFn; selectDataProduct(result: DataProductSearchResult): void; selectAutosuggestProduct(result: AutosuggestResult): void; deselectProduct(): void; addScopeProduct(result: AutosuggestResult): void; removeScopeProduct(index: number): void; setTokenProvider(provider: () => string | undefined): void; /** * Opens an access point in DataCube, building the lakehouse-consumer source * data from the product's entitlements details rather than a viewer state. */ private openAccessPointInDataCube; private resolveIngestEnvironment; private fetchIngestEnvOrLogFailure; private buildElementDocs; private loadRelationTypesFromEngine; private loadDataProductArtifact; /** * Reads the entitlements record the chat's product selection points at, which * must identify exactly one deployed data product. */ private resolveEntitlementsDetails; /** * Resolves access point schemas for the product picked inside the chat from * the product element and its artifact, with no product viewer involved. */ resolveAccessPointServices(): Promise<{ services: TDSServiceSchema[]; details: V1_EntitlementsDataProductDetails | undefined; productPath: string | undefined; environmentName: string | undefined; }>; resolveDataSpaceContext(): Promise; resolveExecutionContext(setMessages: MessageSetter): Promise; askFollowUp(text: string): GeneratorFn; private get isAccessPointScope(); /** * Answers a question scoped to the selected product: access-point products use * the access-point pipeline; everything else uses entity-search/orchestrator. */ private runScopedDataQuery; /** * When a scoped SQL answer dead-ends (0 rows / execution or generation * failure), auto-routes to the Legend AI Orchestrator via the SQL-path fallback. */ private maybeAutoRouteToOrchestrator; private runScopedDataQueryInner; private resolveAccessPointScope; private tryRunAccessPointScopedQuery; private resolveDataSpaceScope; private tryRunDataSpaceScopedQuery; private enrichWithEntitySearch; private resolveEntityCandidates; private mergeDiversityResults; private buildServicesFromEntitySearch; private getServicesForQuery; private handleNoServices; private handleZeroRows; private dispatchWithSql2; private handleLlmJudgeFallback; private handleAmbiguousIntent; /** * Core SQL generation → execution → analysis pipeline. * Extracted so both the direct DATA_QUERY path and the ambiguous-intent * path can reuse it. */ private runSqlPath; private safeAnalyzeResults; private attemptZeroRowCorrection; private offerOrchestratorFallback; /** * Derives the orchestrator question and any prior SQL-failure context from a * clicked assistant message, independent of transient store state. */ private deriveFallbackContext; /** * Clears the dead-end fallback button from a message (keeping its failed SQL * visible) and appends a fresh assistant bubble for the orchestrator flow. */ private finalizeFallbackMessage; /** * Runs the Legend AI Orchestrator against the current assistant bubble, * threading any prior SQL-failure context into the Pure query generation. */ private runOrchestratorFlow; runOrchestratorFallback(messageId: string): GeneratorFn; } export {}; //# sourceMappingURL=LegendMarketplaceAIChatStore.d.ts.map