@finos/legend-lego 2.0.195 → 2.0.197

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/lib/code-editor/CodeEditor.d.ts.map +1 -1
  2. package/lib/code-editor/CodeEditor.js +14 -1
  3. package/lib/code-editor/CodeEditor.js.map +1 -1
  4. package/lib/index.css +2 -2
  5. package/lib/index.css.map +1 -1
  6. package/lib/legend-ai/LegendAITypes.d.ts +33 -0
  7. package/lib/legend-ai/LegendAITypes.d.ts.map +1 -1
  8. package/lib/legend-ai/LegendAITypes.js +39 -1
  9. package/lib/legend-ai/LegendAITypes.js.map +1 -1
  10. package/lib/legend-ai/LegendAI_LegendApplicationPlugin_Extension.d.ts +96 -1
  11. package/lib/legend-ai/LegendAI_LegendApplicationPlugin_Extension.d.ts.map +1 -1
  12. package/lib/legend-ai/LegendAI_LegendApplicationPlugin_Extension.js +56 -0
  13. package/lib/legend-ai/LegendAI_LegendApplicationPlugin_Extension.js.map +1 -1
  14. package/lib/legend-ai/__test-utils__/LegendAITestUtils.d.ts.map +1 -1
  15. package/lib/legend-ai/__test-utils__/LegendAITestUtils.js +6 -0
  16. package/lib/legend-ai/__test-utils__/LegendAITestUtils.js.map +1 -1
  17. package/lib/legend-ai/components/LegendAIAnalysisPanel.d.ts +24 -0
  18. package/lib/legend-ai/components/LegendAIAnalysisPanel.d.ts.map +1 -0
  19. package/lib/legend-ai/components/LegendAIAnalysisPanel.js +35 -0
  20. package/lib/legend-ai/components/LegendAIAnalysisPanel.js.map +1 -0
  21. package/lib/legend-ai/components/LegendAIAnalysisUtils.d.ts +23 -0
  22. package/lib/legend-ai/components/LegendAIAnalysisUtils.d.ts.map +1 -0
  23. package/lib/legend-ai/components/LegendAIAnalysisUtils.js +168 -0
  24. package/lib/legend-ai/components/LegendAIAnalysisUtils.js.map +1 -0
  25. package/lib/legend-ai/components/LegendAICharts.d.ts +25 -0
  26. package/lib/legend-ai/components/LegendAICharts.d.ts.map +1 -0
  27. package/lib/legend-ai/components/LegendAICharts.js +70 -0
  28. package/lib/legend-ai/components/LegendAICharts.js.map +1 -0
  29. package/lib/legend-ai/components/LegendAIChat.d.ts +2 -1
  30. package/lib/legend-ai/components/LegendAIChat.d.ts.map +1 -1
  31. package/lib/legend-ai/components/LegendAIChat.js +14 -10
  32. package/lib/legend-ai/components/LegendAIChat.js.map +1 -1
  33. package/lib/legend-ai/index.d.ts +5 -2
  34. package/lib/legend-ai/index.d.ts.map +1 -1
  35. package/lib/legend-ai/index.js +5 -2
  36. package/lib/legend-ai/index.js.map +1 -1
  37. package/lib/legend-ai/stores/LegendAIChatState.d.ts +12 -5
  38. package/lib/legend-ai/stores/LegendAIChatState.d.ts.map +1 -1
  39. package/lib/legend-ai/stores/LegendAIChatState.js +604 -69
  40. package/lib/legend-ai/stores/LegendAIChatState.js.map +1 -1
  41. package/package.json +5 -5
  42. package/src/code-editor/CodeEditor.tsx +19 -0
  43. package/src/legend-ai/LegendAITypes.ts +51 -1
  44. package/src/legend-ai/LegendAI_LegendApplicationPlugin_Extension.ts +169 -0
  45. package/src/legend-ai/__test-utils__/LegendAITestUtils.ts +9 -0
  46. package/src/legend-ai/components/LegendAIAnalysisPanel.tsx +102 -0
  47. package/src/legend-ai/components/LegendAIAnalysisUtils.ts +226 -0
  48. package/src/legend-ai/components/LegendAICharts.tsx +166 -0
  49. package/src/legend-ai/components/LegendAIChat.tsx +74 -26
  50. package/src/legend-ai/index.ts +18 -0
  51. package/src/legend-ai/stores/LegendAIChatState.ts +1039 -128
  52. package/tsconfig.json +3 -0
@@ -56,6 +56,44 @@ export declare class LegendAIResolvedEntities {
56
56
  rootEntity: string;
57
57
  relatedEntities: string[];
58
58
  }
59
+ export declare class LegendAIEntityCandidate {
60
+ datasetName: string;
61
+ description?: string;
62
+ modelPath: string;
63
+ similarityScore: number;
64
+ }
65
+ export declare enum LegendAIChartType {
66
+ BAR = "bar",
67
+ LINE = "line",
68
+ PIE = "pie",
69
+ TABLE = "table",
70
+ NONE = "none"
71
+ }
72
+ export declare class LegendAIChartRecommendation {
73
+ chartType: LegendAIChartType;
74
+ xAxis?: string;
75
+ yAxis?: string;
76
+ label?: string;
77
+ reasoning: string;
78
+ }
79
+ export declare class LegendAIKeyMetric {
80
+ label: string;
81
+ value: string;
82
+ detail?: string;
83
+ }
84
+ export declare class LegendAIChartDataPoint {
85
+ label: string;
86
+ value: number;
87
+ color?: string;
88
+ colorIndex?: number;
89
+ }
90
+ export declare class LegendAIResultAnalysis {
91
+ summary: string;
92
+ chartRecommendation?: LegendAIChartRecommendation;
93
+ keyMetrics: LegendAIKeyMetric[];
94
+ chartData: LegendAIChartDataPoint[];
95
+ suggestedQueries: string[];
96
+ }
59
97
  /**
60
98
  * @deprecated Use {@link QueryExplicitExecutionContextInfo} from `@finos/legend-graph` directly.
61
99
  */
@@ -111,7 +149,7 @@ export declare abstract class LegendAI_LegendApplicationPlugin_Extension extends
111
149
  * Resolve root and related entities for a given user query within a data product.
112
150
  * Uses the dataset search API to determine which entities are most relevant.
113
151
  */
114
- abstract resolveEntitiesForQuery(query: string, dataProductCoordinates: LegendAIOrchestratorDataProductCoordinates, config: LegendAIConfig): Promise<LegendAIResolvedEntities>;
152
+ abstract resolveEntitiesForQuery(query: string, dataProductCoordinates: LegendAIOrchestratorDataProductCoordinates, config: LegendAIConfig, pureExecutionContext?: QueryExplicitExecutionContextInfo): Promise<LegendAIResolvedEntities>;
115
153
  /**
116
154
  * Execute a Pure/Legend query against the engine and return tabular results.
117
155
  * Converts the Pure expression text to a lambda, then executes it using
@@ -123,5 +161,62 @@ export declare abstract class LegendAI_LegendApplicationPlugin_Extension extends
123
161
  * Wraps the SQL in `#SQL{...}#`, builds a lakehouse runtime, and executes via the engine.
124
162
  */
125
163
  abstract executeLakehouseSql(sql: string, dataProductCoordinates: LegendAIOrchestratorDataProductCoordinates, config: LegendAIConfig): Promise<LegendAISqlExecutionResultData>;
164
+ /**
165
+ * Analyze query results using the LLM to produce a summary, chart
166
+ * recommendation, key metrics, and suggested follow-up queries.
167
+ */
168
+ abstract analyzeQueryResults(question: string, query: string, columns: string[], rows: TDSRowDataType[], metadata: LegendAIProductMetadata, config: LegendAIConfig): Promise<LegendAIResultAnalysis | undefined>;
169
+ /**
170
+ * Build a fallback analysis when the query returns no results.
171
+ */
172
+ abstract buildNoResultsFallback(question: string, query: string, metadata: LegendAIProductMetadata, config: LegendAIConfig): Promise<LegendAIResultAnalysis | undefined>;
173
+ /**
174
+ * Build a contextual summary of the data product for the user.
175
+ */
176
+ abstract buildDataContextSummary(question: string, metadata: LegendAIProductMetadata, config: LegendAIConfig): Promise<string | undefined>;
177
+ /**
178
+ * Build a fallback message when query execution fails.
179
+ */
180
+ abstract buildFailureFallback(question: string, errorMessage: string, metadata: LegendAIProductMetadata, config: LegendAIConfig): Promise<string | undefined>;
181
+ /**
182
+ * Given a user question and pre-fetched entity search candidates, disambiguate
183
+ * which entity is the correct root for the query. Uses LLM disambiguation
184
+ * and/or probing to pick the best entity.
185
+ */
186
+ abstract disambiguateEntity(question: string, candidates: LegendAIEntityCandidate[], config: LegendAIConfig, pureExecutionContext?: QueryExplicitExecutionContextInfo, dataProductCoordinates?: LegendAIOrchestratorDataProductCoordinates): Promise<LegendAIResolvedEntities>;
187
+ /**
188
+ * Given a user question and candidate data products (with their matched fields),
189
+ * use the LLM to pick the top N most relevant products.
190
+ * Returns 0-based indices into the candidates array, ordered by relevance.
191
+ * Returns undefined if reranking is not possible (e.g. LLM unavailable).
192
+ */
193
+ abstract rerankProducts(question: string, candidates: {
194
+ title: string;
195
+ description: string;
196
+ matchedFields: string[];
197
+ }[], allFieldNames: string[], topN: number, config: LegendAIConfig): Promise<number[] | undefined>;
198
+ /**
199
+ * Given a user question and available services, use LLM to select the most
200
+ * relevant service(s) for SQL generation. Returns the filtered subset of
201
+ * services. Default implementation returns all services (no pre-filtering).
202
+ * Override in plugins to add LLM-based service selection.
203
+ */
204
+ selectRelevantServices(_question: string, services: TDSServiceSchema[], _config: LegendAIConfig): Promise<TDSServiceSchema[]>;
205
+ /**
206
+ * Probe a service by executing SELECT * LIMIT 1 to discover the real column
207
+ * names from the engine. Returns the actual column names or undefined if
208
+ * probing fails (non-fatal). This is the ground truth for column names.
209
+ */
210
+ probeServiceColumns(_service: TDSServiceSchema, _coordinates: string, _config: LegendAIConfig): Promise<string[] | undefined>;
211
+ /**
212
+ * Build an error correction prompt that feeds the execution error back to
213
+ * the LLM and asks it to fix the SQL. Used in the execution retry loop.
214
+ */
215
+ abstract buildErrorCorrectionPrompt(failedSql: string, errorMessage: string, question: string, services: TDSServiceSchema[], coordinates: string, availableColumns?: string[]): string;
216
+ /**
217
+ * Build a zero-row correction prompt that asks the LLM to relax or fix
218
+ * filters when a syntactically valid query returns 0 rows.
219
+ */
220
+ abstract buildZeroRowCorrectionPrompt(sql: string, question: string, services: TDSServiceSchema[], coordinates: string): string;
126
221
  }
127
222
  //# sourceMappingURL=LegendAI_LegendApplicationPlugin_Extension.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"LegendAI_LegendApplicationPlugin_Extension.d.ts","sourceRoot":"","sources":["../../src/legend-ai/LegendAI_LegendApplicationPlugin_Extension.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,uBAAuB,EACvB,KAAK,8BAA8B,EACpC,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EACV,iCAAiC,EACjC,cAAc,EACf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EACV,gBAAgB,EAChB,cAAc,EACd,wBAAwB,EACxB,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,oBAAoB,CAAC;AAE5B,qBAAa,2BAA2B;IACtC,GAAG,EAAG,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,EAAG,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,oBAAY,oBAAoB;IAC9B,IA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BAAgB,EAAE,iCAAiC,EACnD,sBAAsB,EAAE,0CAA0C,EAClE,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,8BAA8B,CAAC;IAE1C;;;OAGG;IACH,QAAQ,CAAC,mBAAmB,CAC1B,GAAG,EAAE,MAAM,EACX,sBAAsB,EAAE,0CAA0C,EAClE,MAAM,EAAE,cAAc,GACrB,OAAO,CAAC,8BAA8B,CAAC;CAC3C"}
1
+ {"version":3,"file":"LegendAI_LegendApplicationPlugin_Extension.d.ts","sourceRoot":"","sources":["../../src/legend-ai/LegendAI_LegendApplicationPlugin_Extension.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,uBAAuB,EACvB,KAAK,8BAA8B,EACpC,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EACV,iCAAiC,EACjC,cAAc,EACf,MAAM,qBAAqB,CAAC;AAC7B,OAAO,KAAK,EACV,gBAAgB,EAChB,cAAc,EACd,wBAAwB,EACxB,uBAAuB,EACvB,sBAAsB,EACvB,MAAM,oBAAoB,CAAC;AAE5B,qBAAa,2BAA2B;IACtC,GAAG,EAAG,MAAM,GAAG,IAAI,CAAC;IACpB,OAAO,EAAG,MAAM,GAAG,IAAI,CAAC;IACxB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB;AAED,oBAAY,oBAAoB;IAC9B,IAAI,SAAS;IACb,IAAI,SAAS;CACd;AAED,qBAAa,mBAAmB;IAC9B,OAAO,EAAG,oBAAoB,CAAC;IAC/B,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED,qBAAa,8BAA8B;IACzC,OAAO,EAAG,MAAM,EAAE,CAAC;IACnB,IAAI,EAAG,cAAc,EAAE,CAAC;CACzB;AAED,qBAAa,0CAA0C;IACrD,YAAY,EAAG,MAAM,CAAC;IACtB,QAAQ,EAAG,MAAM,CAAC;IAClB,WAAW,EAAG,MAAM,CAAC;IACrB,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AAC,MAAM,EAAE,GAAG,SAAS,CAAC;IAIhC;;;OAGG;IACH,QAAQ,CAAC,0BAA0B,CACjC,SAAS,EAAE,MAAM,EACjB,YAAY,EAAE,MAAM,EACpB,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,gBAAgB,EAAE,EAC5B,WAAW,EAAE,MAAM,EACnB,gBAAgB,CAAC,EAAE,MAAM,EAAE,GAC1B,MAAM;IAET;;;OAGG;IACH,QAAQ,CAAC,4BAA4B,CACnC,GAAG,EAAE,MAAM,EACX,QAAQ,EAAE,MAAM,EAChB,QAAQ,EAAE,gBAAgB,EAAE,EAC5B,WAAW,EAAE,MAAM,GAClB,MAAM;CACV"}
@@ -50,6 +50,45 @@ export class LegendAIResolvedEntities {
50
50
  rootEntity;
51
51
  relatedEntities;
52
52
  }
53
+ export class LegendAIEntityCandidate {
54
+ datasetName;
55
+ description;
56
+ modelPath;
57
+ similarityScore;
58
+ }
59
+ export var LegendAIChartType;
60
+ (function (LegendAIChartType) {
61
+ LegendAIChartType["BAR"] = "bar";
62
+ LegendAIChartType["LINE"] = "line";
63
+ LegendAIChartType["PIE"] = "pie";
64
+ LegendAIChartType["TABLE"] = "table";
65
+ LegendAIChartType["NONE"] = "none";
66
+ })(LegendAIChartType || (LegendAIChartType = {}));
67
+ export class LegendAIChartRecommendation {
68
+ chartType;
69
+ xAxis;
70
+ yAxis;
71
+ label;
72
+ reasoning;
73
+ }
74
+ export class LegendAIKeyMetric {
75
+ label;
76
+ value;
77
+ detail;
78
+ }
79
+ export class LegendAIChartDataPoint {
80
+ label;
81
+ value;
82
+ color;
83
+ colorIndex;
84
+ }
85
+ export class LegendAIResultAnalysis {
86
+ summary;
87
+ chartRecommendation;
88
+ keyMetrics;
89
+ chartData;
90
+ suggestedQueries;
91
+ }
53
92
  export class LegendAI_LegendApplicationPlugin_Extension extends LegendApplicationPlugin {
54
93
  /**
55
94
  * This helps to better type-check for this empty abstract type
@@ -59,5 +98,22 @@ export class LegendAI_LegendApplicationPlugin_Extension extends LegendApplicatio
59
98
  install(pluginManager) {
60
99
  pluginManager.registerApplicationPlugin(this);
61
100
  }
101
+ /**
102
+ * Given a user question and available services, use LLM to select the most
103
+ * relevant service(s) for SQL generation. Returns the filtered subset of
104
+ * services. Default implementation returns all services (no pre-filtering).
105
+ * Override in plugins to add LLM-based service selection.
106
+ */
107
+ selectRelevantServices(_question, services, _config) {
108
+ return Promise.resolve(services);
109
+ }
110
+ /**
111
+ * Probe a service by executing SELECT * LIMIT 1 to discover the real column
112
+ * names from the engine. Returns the actual column names or undefined if
113
+ * probing fails (non-fatal). This is the ground truth for column names.
114
+ */
115
+ probeServiceColumns(_service, _coordinates, _config) {
116
+ return Promise.resolve(undefined);
117
+ }
62
118
  }
63
119
  //# sourceMappingURL=LegendAI_LegendApplicationPlugin_Extension.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"LegendAI_LegendApplicationPlugin_Extension.js","sourceRoot":"","sources":["../../src/legend-ai/LegendAI_LegendApplicationPlugin_Extension.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,uBAAuB,GAExB,MAAM,2BAA2B,CAAC;AAanC,MAAM,OAAO,2BAA2B;IACtC,GAAG,CAAiB;IACpB,OAAO,CAAiB;IACxB,UAAU,CAAU;CACrB;AAED,MAAM,CAAN,IAAY,oBAGX;AAHD,WAAY,oBAAoB;IAC9B,qCAAa,CAAA;IACb,qCAAa,CAAA;AACf,CAAC,EAHW,oBAAoB,KAApB,oBAAoB,QAG/B;AAED,MAAM,OAAO,mBAAmB;IAC9B,OAAO,CAAwB;IAC/B,MAAM,CAAU;IAChB,YAAY,CAAU;CACvB;AAED,MAAM,OAAO,8BAA8B;IACzC,OAAO,CAAY;IACnB,IAAI,CAAoB;CACzB;AAED,MAAM,OAAO,0CAA0C;IACrD,YAAY,CAAU;IACtB,QAAQ,CAAU;IAClB,WAAW,CAAU;IACrB,OAAO,CAAU;CAClB;AAQD,MAAM,OAAO,2BAA2B;IACtC,aAAa,CAAU;IACvB,kCAAkC,CAA2C;CAC9E;AAED,MAAM,OAAO,4BAA4B;IACvC,YAAY,CAAU;CACvB;AAED,MAAM,OAAO,wBAAwB;IACnC,UAAU,CAAU;IACpB,eAAe,CAAY;CAC5B;AAOD,MAAM,OAAgB,0CAA2C,SAAQ,uBAAuB;IAC9F;;;OAGG;IACc,kBAAkB,CAAgD;IAEnF,OAAO,CACL,aAAsE;QAEtE,aAAa,CAAC,yBAAyB,CAAC,IAAI,CAAC,CAAC;IAChD,CAAC;CA8GF"}
1
+ {"version":3,"file":"LegendAI_LegendApplicationPlugin_Extension.js","sourceRoot":"","sources":["../../src/legend-ai/LegendAI_LegendApplicationPlugin_Extension.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,uBAAuB,GAExB,MAAM,2BAA2B,CAAC;AAanC,MAAM,OAAO,2BAA2B;IACtC,GAAG,CAAiB;IACpB,OAAO,CAAiB;IACxB,UAAU,CAAU;CACrB;AAED,MAAM,CAAN,IAAY,oBAGX;AAHD,WAAY,oBAAoB;IAC9B,qCAAa,CAAA;IACb,qCAAa,CAAA;AACf,CAAC,EAHW,oBAAoB,KAApB,oBAAoB,QAG/B;AAED,MAAM,OAAO,mBAAmB;IAC9B,OAAO,CAAwB;IAC/B,MAAM,CAAU;IAChB,YAAY,CAAU;CACvB;AAED,MAAM,OAAO,8BAA8B;IACzC,OAAO,CAAY;IACnB,IAAI,CAAoB;CACzB;AAED,MAAM,OAAO,0CAA0C;IACrD,YAAY,CAAU;IACtB,QAAQ,CAAU;IAClB,WAAW,CAAU;IACrB,OAAO,CAAU;CAClB;AAQD,MAAM,OAAO,2BAA2B;IACtC,aAAa,CAAU;IACvB,kCAAkC,CAA2C;CAC9E;AAED,MAAM,OAAO,4BAA4B;IACvC,YAAY,CAAU;CACvB;AAED,MAAM,OAAO,wBAAwB;IACnC,UAAU,CAAU;IACpB,eAAe,CAAY;CAC5B;AAED,M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ot":"","sources":["../../../src/legend-ai/__test-utils__/LegendAITestUtils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,wBAAwB,EAC7B,KAAK,cAAc,EACnB,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,EAItB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,KAAK,0CAA0C,EAIhD,MAAM,kDAAkD,CAAC;AAE1D,eAAO,MAAM,sBAAsB,QAAO;IACxC,MAAM,EAAE,aAAa,CAAC;IACtB,WAAW,EAAE,MAAM,eAAe,EAAE,CAAC;CAWtC,CAAC;AACF,eAAO,MAAM,0BAA0B,GACrC,YAAY,OAAO,CAAC,wBAAwB,CAAC,KAC5C,wBAeD,CAAC;AACH,eAAO,MAAM,mBAAmB,GAAI,QAAQ,aAAa,KAAG,IAK3D,CAAC;AACF,eAAO,MAAM,yBAAyB,EAAE,cASvC,CAAC;AAEF,eAAO,MAAM,2BAA2B,EAAE,uBAIzC,CAAC;AAEF,eAAO,MAAM,2BAA2B,EAAE,gBAAgB,EAUzD,CAAC;AACF,eAAO,MAAM,8BAA8B,GACzC,YAAY,OAAO,CAAC,0CAA0C,CAAC,KAC9D,0CAmC+C,CAAC"}
1
+ {"version":3,"file":"LegendAITestUtils.d.ts","sourceRoot":"","sources":["../../../src/legend-ai/__test-utils__/LegendAITestUtils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AACpE,OAAO,EACL,KAAK,eAAe,EACpB,KAAK,wBAAwB,EAC7B,KAAK,cAAc,EACnB,KAAK,uBAAuB,EAC5B,KAAK,gBAAgB,EAItB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EACL,KAAK,0CAA0C,EAIhD,MAAM,kDAAkD,CAAC;AAE1D,eAAO,MAAM,sBAAsB,QAAO;IACxC,MAAM,EAAE,aAAa,CAAC;IACtB,WAAW,EAAE,MAAM,eAAe,EAAE,CAAC;CAWtC,CAAC;AACF,eAAO,MAAM,0BAA0B,GACrC,YAAY,OAAO,CAAC,wBAAwB,CAAC,KAC5C,wBAkBD,CAAC;AACH,eAAO,MAAM,mBAAmB,GAAI,QAAQ,aAAa,KAAG,IAK3D,CAAC;AACF,eAAO,MAAM,yBAAyB,EAAE,cASvC,CAAC;AAEF,eAAO,MAAM,2BAA2B,EAAE,uBAIzC,CAAC;AAEF,eAAO,MAAM,2BAA2B,EAAE,gBAAgB,EAUzD,CAAC;AACF,eAAO,MAAM,8BAA8B,GACzC,YAAY,OAAO,CAAC,0CAA0C,CAAC,KAC9D,0CAyC+C,CAAC"}
@@ -34,14 +34,17 @@ export const TEST__makeAssistantMessage = (overrides) => ({
34
34
  thinkingSteps: [],
35
35
  sql: null,
36
36
  textAnswer: null,
37
+ dataContext: null,
37
38
  gridData: null,
38
39
  error: null,
40
+ errorType: null,
39
41
  sqlGenTime: null,
40
42
  execTime: null,
41
43
  thinkingDuration: null,
42
44
  isProcessing: true,
43
45
  isExecuting: false,
44
46
  suggestedQueries: [],
47
+ fallbackAction: null,
45
48
  ...overrides,
46
49
  });
47
50
  export const TEST__seedAssistant = (setter) => {
@@ -93,6 +96,9 @@ export const TEST__createMockLegendAIPlugin = (overrides) => ({
93
96
  extractJudgeResult: (_a) => ({
94
97
  verdict: LegendAIJudgeVerdict.PASS,
95
98
  }),
99
+ selectRelevantServices: (_q, services) => Promise.resolve(services),
100
+ buildErrorCorrectionPrompt: () => '',
101
+ buildZeroRowCorrectionPrompt: () => '',
96
102
  ...overrides,
97
103
  });
98
104
  //# sourceMappingURL=LegendAITestUtils.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"LegendAITestUtils.js","sourceRoot":"","sources":["../../../src/legend-ai/__test-utils__/LegendAITestUtils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;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CAAC,kBAAkB;IACvB,gBAAgB,EAAE,CAChB,IAAY,EACZ,EAAU,EACV,EAAsB,EACtB,EAAU,EACV,EAA+B,EAC/B,EAAE,CAAC,cAAc;IACnB,OAAO,EAAE,UAAU,EAAE;IACrB,UAAU,EAAE,UAAU,EAAE;IACxB,sBAAsB,EAAE,CAAC,EAAU,EAA+B,EAAE,CAAC,CAAC;QACpE,GAAG,EAAE,iBAAiB;QACtB,OAAO,EAAE,IAAI;KACd,CAAC;IACF,kBAAkB,EAAE,CAAC,EAAU,EAAuB,EAAE,CAAC,CAAC;QACxD,OAAO,EAAE,oBAAoB,CAAC,IAAI;KACnC,CAAC;IACF,GAAG,SAAS;CACb,CAA+C,CAAC"}
1
+ {"version":3,"file":"LegendAITestUtils.js","sourceRoot":"","sources":["../../../src/legend-ai/__test-utils__/LegendAITestUtils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAEvD,OAAO,EAOL,mBAAmB,EACnB,sBAAsB,GACvB,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAIL,oBAAoB,GACrB,MAAM,kDAAkD,CAAC;AAE1D,MAAM,CAAC,MAAM,sBAAsB,GAAG,GAGpC,EAAE;IACF,IAAI,QAAQ,GAAsB,EAAE,CAAC;IACrC,MAAM,MAAM,GAAkB,CAAC,MAAM,EAAE,EAAE;QACvC,IAAI,OAAO,MAAM,KAAK,UAAU,EAAE,CAAC;YACjC,QAAQ,GAAG,MAAM,CAAC,QAAQ,CAAC,CAAC;QAC9B,CAAC;aAAM,CAAC;YACN,QAAQ,GAAG,MAAM,CAAC;QACpB,CAAC;IACH,CAAC,CAAC;IACF,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,GAAG,EAAE,CAAC,QAAQ,EAAE,CAAC;AACjD,CAAC,CAAC;AACF,MAAM,CAAC,MAAM,0BAA0B,GAAG,CACxC,SAA6C,EACnB,EAAE,CAAC,C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GAAG,SAAS;CACb,CAA+C,CAAC"}
@@ -0,0 +1,24 @@
1
+ /**
2
+ * Copyright (c) 2026-present, Goldman Sachs
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { LegendAIGridData } from '../LegendAITypes.js';
17
+ export declare const LegendAIAnalysisPanel: (props: {
18
+ gridData: LegendAIGridData;
19
+ summary: string;
20
+ SummaryRenderer: React.ComponentType<{
21
+ value: string;
22
+ }>;
23
+ }) => React.ReactNode;
24
+ //# sourceMappingURL=LegendAIAnalysisPanel.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LegendAIAnalysisPanel.d.ts","sourceRoot":"","sources":["../../../src/legend-ai/components/LegendAIAnalysisPanel.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAIH,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AAS5D,eAAO,MAAM,qBAAqB,GAAI,OAAO;IAC3C,QAAQ,EAAE,gBAAgB,CAAC;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,eAAe,EAAE,KAAK,CAAC,aAAa,CAAC;QAAE,KAAK,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CACzD,KAAG,KAAK,CAAC,SAsET,CAAC"}
@@ -0,0 +1,35 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ /**
3
+ * Copyright (c) 2026-present, Goldman Sachs
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+ import { useMemo } from 'react';
18
+ import { LegendAIChartType } from '../LegendAI_LegendApplicationPlugin_Extension.js';
19
+ import { computeKeyMetrics, computeChartData, inferChartType, findNumericColumnName, } from './LegendAIAnalysisUtils.js';
20
+ import { LegendAIBarChart, LegendAIDonutChart } from './LegendAICharts.js';
21
+ export const LegendAIAnalysisPanel = (props) => {
22
+ const { gridData, summary, SummaryRenderer } = props;
23
+ const metrics = useMemo(() => computeKeyMetrics(gridData), [gridData]);
24
+ const chartType = useMemo(() => inferChartType(gridData), [gridData]);
25
+ const chartData = useMemo(() => chartType === LegendAIChartType.NONE ? [] : computeChartData(gridData), [gridData, chartType]);
26
+ const numericColName = useMemo(() => findNumericColumnName(gridData), [gridData]);
27
+ const donutTitleProp = useMemo(() => numericColName === undefined
28
+ ? {}
29
+ : { title: `${numericColName} Distribution` }, [numericColName]);
30
+ const barTitleProp = useMemo(() => numericColName === undefined
31
+ ? {}
32
+ : { title: `Top ${chartData.length} by ${numericColName}` }, [numericColName, chartData.length]);
33
+ return (_jsxs("div", { className: "legend-ai-analysis", children: [metrics.length > 0 && (_jsx("div", { className: "legend-ai-analysis__metrics", children: metrics.map((m) => (_jsxs("div", { className: "legend-ai-analysis__metric-card", children: [_jsx("span", { className: "legend-ai-analysis__metric-value", children: m.value }), _jsx("span", { className: "legend-ai-analysis__metric-label", children: m.label }), m.detail !== undefined && (_jsx("span", { className: "legend-ai-analysis__metric-detail", children: m.detail }))] }, m.label))) })), chartData.length > 0 && (_jsx("div", { className: "legend-ai-analysis__chart-section", children: chartType === LegendAIChartType.PIE ? (_jsx(LegendAIDonutChart, { data: chartData, ...donutTitleProp })) : (_jsx(LegendAIBarChart, { data: chartData, ...barTitleProp })) })), _jsx("div", { className: "legend-ai-analysis__narrative", children: _jsx(SummaryRenderer, { value: summary }) })] }));
34
+ };
35
+ //# sourceMappingURL=LegendAIAnalysisPanel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LegendAIAnalysisPanel.js","sourceRoot":"","sources":["../../../src/legend-ai/components/LegendAIAnalysisPanel.tsx"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,kDAAkD,CAAC;AAErF,OAAO,EACL,iBAAiB,EACjB,gBAAgB,EAChB,cAAc,EACd,qBAAqB,GACtB,MAAM,4BAA4B,CAAC;AACpC,OAAO,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,qBAAqB,CAAC;AAE3E,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,KAIrC,EAAmB,EAAE;IACpB,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,KAAK,CAAC;IAErD,MAAM,OAAO,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,iBAAiB,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEvE,MAAM,SAAS,GAAG,OAAO,CAAC,GAAG,EAAE,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEtE,MAAM,SAAS,GAAG,OAAO,CACvB,GAAG,EAAE,CACH,SAAS,KAAK,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,gBAAgB,CAAC,QAAQ,CAAC,EACxE,CAAC,QAAQ,EAAE,SAAS,CAAC,CACtB,CAAC;IAEF,MAAM,cAAc,GAAG,OAAO,CAC5B,GAAG,EAAE,CAAC,qBAAqB,CAAC,QAAQ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,SAAS,KAAM,YAAY,GAAI,CACxD,GACG,CACP,EAED,cAAK,SAAS,EAAC,+BAA+B,YAC5C,KAAC,eAAe,IAAC,KAAK,EAAE,OAAO,GAAI,GAC/B,IACF,CACP,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Copyright (c) 2026-present, Goldman Sachs
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { type LegendAIKeyMetric, type LegendAIChartDataPoint, LegendAIChartType } from '../LegendAI_LegendApplicationPlugin_Extension.js';
17
+ import type { LegendAIGridData } from '../LegendAITypes.js';
18
+ export declare function computeKeyMetrics(gridData: LegendAIGridData): LegendAIKeyMetric[];
19
+ export declare function inferChartType(gridData: LegendAIGridData): LegendAIChartType;
20
+ export declare function computeChartData(gridData: LegendAIGridData): LegendAIChartDataPoint[];
21
+ export declare function computeTopItems(gridData: LegendAIGridData): LegendAIChartDataPoint[];
22
+ export declare function findNumericColumnName(gridData: LegendAIGridData): string | undefined;
23
+ //# sourceMappingURL=LegendAIAnalysisUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LegendAIAnalysisUtils.d.ts","sourceRoot":"","sources":["../../../src/legend-ai/components/LegendAIAnalysisUtils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EACL,KAAK,iBAAiB,EACtB,KAAK,sBAAsB,EAC3B,iBAAiB,EAClB,MAAM,kDAAkD,CAAC;AAC1D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AA4F5D,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,gBAAgB,GACzB,iBAAiB,EAAE,CA4BrB;AAED,wBAAgB,cAAc,CAAC,QAAQ,EAAE,gBAAgB,GAAG,iBAAiB,CAqB5E;AAED,wBAAgB,gBAAgB,CAC9B,QAAQ,EAAE,gBAAgB,GACzB,sBAAsB,EAAE,CAmC1B;AAED,wBAAgB,eAAe,CAC7B,QAAQ,EAAE,gBAAgB,GACzB,sBAAsB,EAAE,CAE1B;AAED,wBAAgB,qBAAqB,CACnC,QAAQ,EAAE,gBAAgB,GACzB,MAAM,GAAG,SAAS,CAUpB"}
@@ -0,0 +1,168 @@
1
+ /**
2
+ * Copyright (c) 2026-present, Goldman Sachs
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import { LegendAIChartType, } from '../LegendAI_LegendApplicationPlugin_Extension.js';
17
+ import { isNonNullable, isNumber, isString } from '@finos/legend-shared';
18
+ const CHART_PALETTE_COUNT = 10;
19
+ const MAX_CHART_ITEMS = 10;
20
+ const TOP_N_ITEMS = 5;
21
+ const MAX_PROFILE_SAMPLE = 1000;
22
+ const MAX_KEY_METRICS = 4;
23
+ const MAX_METRIC_COLUMNS = 5;
24
+ const MAX_BAR_CHART_ROWS = 20;
25
+ const MAX_PIE_CHART_ROWS = 6;
26
+ function profileColumns(gridData) {
27
+ const rows = gridData.rowData.length > MAX_PROFILE_SAMPLE
28
+ ? gridData.rowData.slice(0, MAX_PROFILE_SAMPLE)
29
+ : gridData.rowData;
30
+ return gridData.columnDefs.map((col) => {
31
+ const field = col.field ?? col.colId ?? '';
32
+ const values = rows.map((r) => r[field]).filter(isNonNullable);
33
+ const numericValues = values.filter(isNumber);
34
+ const unique = new Set(values.map(String));
35
+ return {
36
+ name: field,
37
+ isNumeric: numericValues.length === values.length && values.length > 0,
38
+ isString: values.length > 0 && values.every(isString),
39
+ uniqueCount: unique.size,
40
+ values,
41
+ numericValues,
42
+ };
43
+ });
44
+ }
45
+ function formatNumber(n) {
46
+ if (Number.isInteger(n) && Math.abs(n) < 1_000_000) {
47
+ return n.toLocaleString();
48
+ }
49
+ if (Math.abs(n) >= 1_000_000) {
50
+ return `${(n / 1_000_000).toFixed(1)}M`;
51
+ }
52
+ if (Math.abs(n) >= 1_000) {
53
+ return `${(n / 1_000).toFixed(1)}K`;
54
+ }
55
+ return n.toFixed(2);
56
+ }
57
+ function computeNumericMetrics(col, metrics) {
58
+ let sum = 0;
59
+ let min = Number.POSITIVE_INFINITY;
60
+ let max = Number.NEGATIVE_INFINITY;
61
+ for (const n of col.numericValues) {
62
+ sum += n;
63
+ if (n < min) {
64
+ min = n;
65
+ }
66
+ if (n > max) {
67
+ max = n;
68
+ }
69
+ }
70
+ const avg = sum / col.numericValues.length;
71
+ if (col.uniqueCount > 1) {
72
+ metrics.push({
73
+ label: `Avg ${col.name}`,
74
+ value: formatNumber(avg),
75
+ ...(min === max
76
+ ? {}
77
+ : { detail: `${formatNumber(min)} – ${formatNumber(max)}` }),
78
+ });
79
+ }
80
+ if (col.uniqueCount > 2 && metrics.length < MAX_METRIC_COLUMNS) {
81
+ metrics.push({
82
+ label: `Total ${col.name}`,
83
+ value: formatNumber(sum),
84
+ });
85
+ }
86
+ }
87
+ export function computeKeyMetrics(gridData) {
88
+ const profiles = profileColumns(gridData);
89
+ const metrics = [];
90
+ const rowCount = gridData.rowData.length;
91
+ metrics.push({
92
+ label: 'Total Rows',
93
+ value: rowCount.toLocaleString(),
94
+ });
95
+ const numericCol = profiles.find((c) => c.isNumeric && c.numericValues.length > 0);
96
+ if (numericCol) {
97
+ computeNumericMetrics(numericCol, metrics);
98
+ }
99
+ const stringCol = profiles.find((c) => c.isString && c.uniqueCount > 1 && c.uniqueCount <= rowCount);
100
+ if (stringCol) {
101
+ metrics.push({
102
+ label: `Unique ${stringCol.name}`,
103
+ value: stringCol.uniqueCount.toLocaleString(),
104
+ });
105
+ }
106
+ return metrics.slice(0, MAX_KEY_METRICS);
107
+ }
108
+ export function inferChartType(gridData) {
109
+ const profiles = profileColumns(gridData);
110
+ const numericCols = profiles.filter((c) => c.isNumeric);
111
+ const stringCols = profiles.filter((c) => c.isString && c.uniqueCount > 1);
112
+ if (stringCols.length >= 1 &&
113
+ numericCols.length >= 1 &&
114
+ gridData.rowData.length <= MAX_BAR_CHART_ROWS) {
115
+ if (gridData.rowData.length <= MAX_PIE_CHART_ROWS) {
116
+ return LegendAIChartType.PIE;
117
+ }
118
+ return LegendAIChartType.BAR;
119
+ }
120
+ if (numericCols.length >= 1 && gridData.rowData.length > 1) {
121
+ return LegendAIChartType.BAR;
122
+ }
123
+ return LegendAIChartType.NONE;
124
+ }
125
+ export function computeChartData(gridData) {
126
+ const profiles = profileColumns(gridData);
127
+ const numericCol = profiles.find((c) => c.isNumeric);
128
+ const labelCol = profiles.find((c) => c.isString && c.uniqueCount > 1);
129
+ if (!numericCol) {
130
+ return [];
131
+ }
132
+ const field = numericCol.name;
133
+ const labelField = labelCol?.name;
134
+ const rows = gridData.rowData.length > MAX_PROFILE_SAMPLE
135
+ ? gridData.rowData.slice(0, MAX_PROFILE_SAMPLE)
136
+ : gridData.rowData;
137
+ const entries = rows
138
+ .map((row) => {
139
+ const rawValue = row[field];
140
+ return {
141
+ label: labelField
142
+ ? String(row[labelField] ?? '')
143
+ : String(row[gridData.columnDefs[0]?.field ?? ''] ?? ''),
144
+ value: typeof rawValue === 'number' ? rawValue : 0,
145
+ };
146
+ })
147
+ .filter((e) => e.label.length > 0)
148
+ .sort((a, b) => b.value - a.value)
149
+ .slice(0, MAX_CHART_ITEMS);
150
+ return entries.map((e, i) => ({
151
+ label: e.label,
152
+ value: e.value,
153
+ colorIndex: i % CHART_PALETTE_COUNT,
154
+ }));
155
+ }
156
+ export function computeTopItems(gridData) {
157
+ return computeChartData(gridData).slice(0, TOP_N_ITEMS);
158
+ }
159
+ export function findNumericColumnName(gridData) {
160
+ const profiles = profileColumns(gridData);
161
+ const numericCol = profiles.find((c) => c.isNumeric);
162
+ if (!numericCol) {
163
+ return undefined;
164
+ }
165
+ const colDef = gridData.columnDefs.find((c) => (c.field ?? c.colId ?? '') === numericCol.name);
166
+ return colDef?.headerName ?? colDef?.field;
167
+ }
168
+ //# sourceMappingURL=LegendAIAnalysisUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LegendAIAnalysisUtils.js","sourceRoot":"","sources":["../../../src/legend-ai/components/LegendAIAnalysisUtils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,EAGL,iBAAiB,GAClB,MAAM,kDAAkD,CAAC;AAE1D,OAAO,EAAE,aAAa,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,sBAAsB,CAAC;AAEzE,MAAM,mBAAmB,GAAG,EAAE,CAAC;AAC/B,MAAM,eAAe,GAAG,EAAE,CAAC;AAC3B,MAAM,WAAW,GAAG,CAAC,CAAC;AACtB,MAAM,kBAAkB,GAAG,IAAI,CAAC;AAChC,MAAM,eAAe,GAAG,CAAC,CAAC;AAC1B,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAC7B,MAAM,kBAAkB,GAAG,EAAE,CAAC;AAC9B,MAAM,kBAAkB,GAAG,CAAC,CAAC;AAW7B,SAAS,cAAc,CAAC,QAA0B;IAChD,MAAM,IAAI,GACR,QAAQ,CAAC,OAAO,CAAC,MAAM,GAAG,kBAAkB;QAC1C,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,EAAE,kBAAkB,CAAC;QAC/C,CAAC,CAAC,QAAQ,CA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MAAM,UAAU,eAAe,CAC7B,QAA0B;IAE1B,OAAO,gBAAgB,CAAC,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,WAAW,CAAC,CAAC;AAC1D,CAAC;AAED,MAAM,UAAU,qBAAqB,CACnC,QAA0B;IAE1B,MAAM,QAAQ,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;IAC1C,MAAM,UAAU,GAAG,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;IACrD,IAAI,CAAC,UAAU,EAAE,CAAC;QAChB,OAAO,SAAS,CAAC;IACnB,CAAC;IACD,MAAM,MAAM,GAAG,QAAQ,CAAC,UAAU,CAAC,IAAI,CACrC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,KAAK,IAAI,EAAE,CAAC,KAAK,UAAU,CAAC,IAAI,CACtD,CAAC;IACF,OAAO,MAAM,EAAE,UAAU,IAAI,MAAM,EAAE,KAAK,CAAC;AAC7C,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Copyright (c) 2026-present, Goldman Sachs
3
+ *
4
+ * Licensed under the Apache License, Version 2.0 (the "License");
5
+ * you may not use this file except in compliance with the License.
6
+ * You may obtain a copy of the License at
7
+ *
8
+ * http://www.apache.org/licenses/LICENSE-2.0
9
+ *
10
+ * Unless required by applicable law or agreed to in writing, software
11
+ * distributed under the License is distributed on an "AS IS" BASIS,
12
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ * See the License for the specific language governing permissions and
14
+ * limitations under the License.
15
+ */
16
+ import type { LegendAIChartDataPoint } from '../LegendAI_LegendApplicationPlugin_Extension.js';
17
+ export declare const LegendAIBarChart: (props: {
18
+ data: LegendAIChartDataPoint[];
19
+ title?: string;
20
+ }) => React.ReactNode;
21
+ export declare const LegendAIDonutChart: (props: {
22
+ data: LegendAIChartDataPoint[];
23
+ title?: string;
24
+ }) => React.ReactNode;
25
+ //# sourceMappingURL=LegendAICharts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LegendAICharts.d.ts","sourceRoot":"","sources":["../../../src/legend-ai/components/LegendAICharts.tsx"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAGH,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kDAAkD,CAAC;AAgB/F,eAAO,MAAM,gBAAgB,GAAI,OAAO;IACtC,IAAI,EAAE,sBAAsB,EAAE,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,KAAG,KAAK,CAAC,SA8CT,CAAC;AAEF,eAAO,MAAM,kBAAkB,GAAI,OAAO;IACxC,IAAI,EAAE,sBAAsB,EAAE,CAAC;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB,KAAG,KAAK,CAAC,SA8ET,CAAC"}