/** * 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 EntityChange } from '@finos/legend-server-sdlc'; import { LEGENDAI_SUGGEST_ERROR_KIND, LEGENDAI_SUGGEST_STAGE, type LegendAISuggestDataProductApplyData, type LegendAISuggestIdentity, type LegendAISuggestTarget } from '../../__lib__/LegendStudioTelemetryHelper.js'; import type { EditorStore } from './EditorStore.js'; /** * Normalized Levenshtein distance between two strings (0 = identical, * 1 = completely different). Returns `undefined` when either string is too * long to diff cheaply. */ export declare const computeLegendAISuggestEditRatio: (before: string, after: string) => number | undefined; export declare const classifyLegendAISuggestError: (error: Error, stage: LEGENDAI_SUGGEST_STAGE) => { errorKind: LEGENDAI_SUGGEST_ERROR_KIND; httpStatus?: number; }; /** * Reads the current value of the text an applied suggestion wrote, looking the * element up by path in the current graph (element instances do not survive * graph rebuilds, so readers must not close over them). Returns * `{ found: false }` when the target no longer exists. */ export type LegendAIAppliedTextReader = (editorStore: EditorStore) => { found: false; } | { found: true; text: string | undefined; }; type LegendAIAppliedSuggestion = { identity: LegendAISuggestIdentity; appliedText: string; appliedAt: number; readCurrentText: LegendAIAppliedTextReader; supersededApplyCount: number; }; /** * Remembers suggestions applied in this editor session until the element they * touched is pushed, then reports whether the applied text survived * (`editor.legendai-suggest.persisted`). Only the latest apply per target is * kept; earlier ones are counted in `supersededApplyCount`. * * NOTE: tracking is keyed by element path, so an element renamed after the * apply is not reported. */ export declare class LegendAIAppliedSuggestionRegistry { private readonly appliedSuggestions; get size(): number; register(suggestion: Omit): void; reportPushedChanges(editorStore: EditorStore, pushedChanges: EntityChange[]): void; } /** * A single suggestion request, returned by * {@link LegendAISuggestTelemetryTracker.launch} and passed back when the * request settles so late responses are still attributed correctly. */ export type LegendAISuggestRequest = { readonly suggestionId: string; readonly attempt: number; readonly launchedAt: number; readonly textAtLaunch: string | undefined; }; /** * Drives the `editor.legendai-suggest.*` lifecycle for one editor instance * (one service editor, one dataspace home tab, one data product access point * group) and keeps the legacy per-surface events firing alongside it. * * Lifecycle: `launch` → `succeed` | `fail` → `apply` | `discard`, with * `dispose` reporting an `abandon` when the editor goes away while a request * is pending or a suggestion is on screen. */ export declare class LegendAISuggestTelemetryTracker { private readonly editorStore; private target; private attemptCount; private pending; private shown; constructor(editorStore: EditorStore, target: LegendAISuggestTarget); /** * Keeps the target fresh (e.g. after an element or group rename) without * resetting the attempt count. */ setTarget(target: LegendAISuggestTarget): void; private get telemetryService(); private get sourceInfo(); private identity; reportExposure(data: { available: boolean; isReadOnly: boolean; }): void; launch(data: { existingText: string | undefined; accessPointCount?: number | undefined; }): LegendAISuggestRequest; /** * Records a LegendAI response. An empty suggestion is reported as a * `failure` with `errorKind: empty-response` since nothing is shown. * * @returns whether the suggestion is non-empty and should be shown */ succeed(request: LegendAISuggestRequest, data: { suggestionText: string | undefined; definitionsLength: number; currentText: string | undefined; confidence?: number | undefined; accessPointSuggestionCount?: number | undefined; }): boolean; /** * Must be called before the caller decorates `error.message` (e.g. with the * entitlement documentation link) so the raw server message is reported. */ fail(request: LegendAISuggestRequest, error: Error, stage: LEGENDAI_SUGGEST_STAGE): void; apply(data: { existingText: string | undefined; appliedText: string; readCurrentText: LegendAIAppliedTextReader; dataProduct?: LegendAISuggestDataProductApplyData | undefined; }): void; discard(): void; /** * Call when the hosting editor unmounts. A request that settles afterwards * still reports its `success` / `failure`, but is no longer shown. */ dispose(): void; /** * Per-surface events kept for backward compatibility with existing * dashboards (`editor..legendai-suggest.*`). */ private logLegacyEvent; } export {}; //# sourceMappingURL=LegendAISuggestTelemetry.d.ts.map