@finos/legend-lego 2.0.188 → 2.0.189
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.
- package/lib/index.css +2 -2
- package/lib/index.css.map +1 -1
- package/lib/legend-ai/LegendAITypes.d.ts +196 -0
- package/lib/legend-ai/LegendAITypes.d.ts.map +1 -0
- package/lib/legend-ai/LegendAITypes.js +281 -0
- package/lib/legend-ai/LegendAITypes.js.map +1 -0
- package/lib/legend-ai/LegendAI_LegendApplicationPlugin_Extension.d.ts +127 -0
- package/lib/legend-ai/LegendAI_LegendApplicationPlugin_Extension.d.ts.map +1 -0
- package/lib/legend-ai/LegendAI_LegendApplicationPlugin_Extension.js +63 -0
- package/lib/legend-ai/LegendAI_LegendApplicationPlugin_Extension.js.map +1 -0
- package/lib/legend-ai/__test-utils__/LegendAITestUtils.d.ts +29 -0
- package/lib/legend-ai/__test-utils__/LegendAITestUtils.d.ts.map +1 -0
- package/lib/legend-ai/__test-utils__/LegendAITestUtils.js +98 -0
- package/lib/legend-ai/__test-utils__/LegendAITestUtils.js.map +1 -0
- package/lib/legend-ai/components/LegendAIChat.d.ts +23 -0
- package/lib/legend-ai/components/LegendAIChat.d.ts.map +1 -0
- package/lib/legend-ai/components/LegendAIChat.js +179 -0
- package/lib/legend-ai/components/LegendAIChat.js.map +1 -0
- package/lib/legend-ai/components/LegendAIErrorBoundary.d.ts +31 -0
- package/lib/legend-ai/components/LegendAIErrorBoundary.d.ts.map +1 -0
- package/lib/legend-ai/components/LegendAIErrorBoundary.js +35 -0
- package/lib/legend-ai/components/LegendAIErrorBoundary.js.map +1 -0
- package/lib/legend-ai/components/LegendAIResultGrid.d.ts +20 -0
- package/lib/legend-ai/components/LegendAIResultGrid.d.ts.map +1 -0
- package/lib/legend-ai/components/LegendAIResultGrid.js +90 -0
- package/lib/legend-ai/components/LegendAIResultGrid.js.map +1 -0
- package/lib/legend-ai/index.d.ts +22 -0
- package/lib/legend-ai/index.d.ts.map +1 -0
- package/lib/legend-ai/index.js +22 -0
- package/lib/legend-ai/index.js.map +1 -0
- package/lib/legend-ai/stores/LegendAIChatState.d.ts +46 -0
- package/lib/legend-ai/stores/LegendAIChatState.d.ts.map +1 -0
- package/lib/legend-ai/stores/LegendAIChatState.js +559 -0
- package/lib/legend-ai/stores/LegendAIChatState.js.map +1 -0
- package/package.json +5 -1
- package/src/legend-ai/LegendAITypes.ts +386 -0
- package/src/legend-ai/LegendAI_LegendApplicationPlugin_Extension.ts +208 -0
- package/src/legend-ai/__test-utils__/LegendAITestUtils.ts +139 -0
- package/src/legend-ai/components/LegendAIChat.tsx +502 -0
- package/src/legend-ai/components/LegendAIErrorBoundary.tsx +42 -0
- package/src/legend-ai/components/LegendAIResultGrid.tsx +132 -0
- package/src/legend-ai/index.ts +46 -0
- package/src/legend-ai/stores/LegendAIChatState.ts +1004 -0
- package/tsconfig.json +8 -0
|
@@ -0,0 +1,132 @@
|
|
|
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
|
+
|
|
17
|
+
import { useMemo, useRef, useEffect, useCallback } from 'react';
|
|
18
|
+
import {
|
|
19
|
+
DataGrid,
|
|
20
|
+
type DataGridColumnDefinition,
|
|
21
|
+
} from '../../data-grid/index.js';
|
|
22
|
+
import {
|
|
23
|
+
type LegendAIGridData,
|
|
24
|
+
buildColumnDefsFromNames,
|
|
25
|
+
} from '../LegendAITypes.js';
|
|
26
|
+
|
|
27
|
+
const FIT_GRID_WIDTH_COLUMN_THRESHOLD = 6;
|
|
28
|
+
|
|
29
|
+
export const LegendAIResultGrid = (props: {
|
|
30
|
+
data: LegendAIGridData;
|
|
31
|
+
}): React.ReactNode => {
|
|
32
|
+
const { data } = props;
|
|
33
|
+
const gridRef = useRef<HTMLDivElement>(null);
|
|
34
|
+
|
|
35
|
+
const defaultColDef = useMemo(
|
|
36
|
+
() => ({
|
|
37
|
+
resizable: true,
|
|
38
|
+
sortable: true,
|
|
39
|
+
filter: true,
|
|
40
|
+
minWidth: 120,
|
|
41
|
+
wrapHeaderText: true,
|
|
42
|
+
autoHeaderHeight: true,
|
|
43
|
+
}),
|
|
44
|
+
[],
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
const handleWheel = useCallback((e: WheelEvent) => {
|
|
48
|
+
const container = gridRef.current;
|
|
49
|
+
if (!container) {
|
|
50
|
+
return;
|
|
51
|
+
}
|
|
52
|
+
const viewport = container.querySelector<HTMLElement>(
|
|
53
|
+
'.ag-body-horizontal-scroll-viewport',
|
|
54
|
+
);
|
|
55
|
+
if (!viewport) {
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
if (e.shiftKey && e.deltaY !== 0) {
|
|
60
|
+
viewport.scrollLeft += e.deltaY;
|
|
61
|
+
e.preventDefault();
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const body = container.querySelector<HTMLElement>('.ag-body-viewport');
|
|
66
|
+
if (body && e.deltaY !== 0) {
|
|
67
|
+
const atTop = body.scrollTop <= 0 && e.deltaY < 0;
|
|
68
|
+
const atBottom =
|
|
69
|
+
body.scrollTop + body.clientHeight >= body.scrollHeight - 1 &&
|
|
70
|
+
e.deltaY > 0;
|
|
71
|
+
if (atTop || atBottom) {
|
|
72
|
+
viewport.scrollLeft += e.deltaY;
|
|
73
|
+
e.preventDefault();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}, []);
|
|
77
|
+
|
|
78
|
+
useEffect(() => {
|
|
79
|
+
const el = gridRef.current;
|
|
80
|
+
if (!el) {
|
|
81
|
+
return undefined;
|
|
82
|
+
}
|
|
83
|
+
el.addEventListener('wheel', handleWheel, { passive: false });
|
|
84
|
+
return (): void => {
|
|
85
|
+
el.removeEventListener('wheel', handleWheel);
|
|
86
|
+
};
|
|
87
|
+
}, [handleWheel]);
|
|
88
|
+
|
|
89
|
+
const effectiveColumnDefs: DataGridColumnDefinition[] = useMemo(() => {
|
|
90
|
+
if (data.columnDefs.length > 0) {
|
|
91
|
+
return data.columnDefs;
|
|
92
|
+
}
|
|
93
|
+
const firstRow = data.rowData[0];
|
|
94
|
+
if (firstRow) {
|
|
95
|
+
return buildColumnDefsFromNames(Object.keys(firstRow));
|
|
96
|
+
}
|
|
97
|
+
return [];
|
|
98
|
+
}, [data.columnDefs, data.rowData]);
|
|
99
|
+
|
|
100
|
+
if (effectiveColumnDefs.length === 0) {
|
|
101
|
+
return <div className="legend-ai__grid--empty">No results to display</div>;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const fewColumns =
|
|
105
|
+
effectiveColumnDefs.length <= FIT_GRID_WIDTH_COLUMN_THRESHOLD;
|
|
106
|
+
|
|
107
|
+
return (
|
|
108
|
+
<div ref={gridRef} className="legend-ai__grid ag-theme-balham">
|
|
109
|
+
<DataGrid
|
|
110
|
+
columnDefs={effectiveColumnDefs}
|
|
111
|
+
rowData={data.rowData}
|
|
112
|
+
defaultColDef={defaultColDef}
|
|
113
|
+
suppressFieldDotNotation={true}
|
|
114
|
+
autoSizeStrategy={
|
|
115
|
+
fewColumns
|
|
116
|
+
? { type: 'fitGridWidth', defaultMinWidth: 120 }
|
|
117
|
+
: { type: 'fitCellContents' }
|
|
118
|
+
}
|
|
119
|
+
alwaysShowHorizontalScroll={!fewColumns}
|
|
120
|
+
enableRangeSelection={true}
|
|
121
|
+
copyHeadersToClipboard={true}
|
|
122
|
+
enableCharts={true}
|
|
123
|
+
statusBar={{
|
|
124
|
+
statusPanels: [
|
|
125
|
+
{ statusPanel: 'agTotalRowCountComponent', align: 'left' },
|
|
126
|
+
{ statusPanel: 'agAggregationComponent', align: 'right' },
|
|
127
|
+
],
|
|
128
|
+
}}
|
|
129
|
+
/>
|
|
130
|
+
</div>
|
|
131
|
+
);
|
|
132
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2020-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
|
+
|
|
17
|
+
export * from './LegendAITypes.js';
|
|
18
|
+
export * from './LegendAI_LegendApplicationPlugin_Extension.js';
|
|
19
|
+
export {
|
|
20
|
+
LegendAIChat,
|
|
21
|
+
LEGEND_AI_ANCHOR_ID,
|
|
22
|
+
isStringColumn,
|
|
23
|
+
isNumericColumn,
|
|
24
|
+
isDateColumn,
|
|
25
|
+
buildSuggestedQueries,
|
|
26
|
+
} from './components/LegendAIChat.js';
|
|
27
|
+
export { LegendAIErrorBoundary } from './components/LegendAIErrorBoundary.js';
|
|
28
|
+
export {
|
|
29
|
+
useLegendAIChatState,
|
|
30
|
+
updateLastAssistant,
|
|
31
|
+
addThinkingStep,
|
|
32
|
+
completeThinkingSteps,
|
|
33
|
+
finishWithThinkingError,
|
|
34
|
+
buildConversationHistory,
|
|
35
|
+
buildGenerationFailureMessage,
|
|
36
|
+
buildExecutionErrorMessage,
|
|
37
|
+
generateAndJudgeSql,
|
|
38
|
+
executeSqlAndReport,
|
|
39
|
+
executePureQueryAndReport,
|
|
40
|
+
processQuestionViaOrchestrator,
|
|
41
|
+
processQuestion,
|
|
42
|
+
processQuestionWithIntent,
|
|
43
|
+
handleMetadataQuestion,
|
|
44
|
+
type MessageSetter,
|
|
45
|
+
} from './stores/LegendAIChatState.js';
|
|
46
|
+
export { LegendAIResultGrid } from './components/LegendAIResultGrid.js';
|