@finos/legend-lego 2.0.196 → 2.0.198
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/code-editor/CodeEditor.d.ts.map +1 -1
- package/lib/code-editor/CodeEditor.js +14 -1
- package/lib/code-editor/CodeEditor.js.map +1 -1
- package/lib/index.css +2 -2
- package/lib/index.css.map +1 -1
- package/lib/legend-ai/LegendAIDocEnrichment.d.ts +60 -0
- package/lib/legend-ai/LegendAIDocEnrichment.d.ts.map +1 -0
- package/lib/legend-ai/LegendAIDocEnrichment.js +429 -0
- package/lib/legend-ai/LegendAIDocEnrichment.js.map +1 -0
- package/lib/legend-ai/LegendAITypes.d.ts +127 -1
- package/lib/legend-ai/LegendAITypes.d.ts.map +1 -1
- package/lib/legend-ai/LegendAITypes.js +111 -2
- package/lib/legend-ai/LegendAITypes.js.map +1 -1
- package/lib/legend-ai/LegendAI_LegendApplicationPlugin_Extension.d.ts +14 -1
- package/lib/legend-ai/LegendAI_LegendApplicationPlugin_Extension.d.ts.map +1 -1
- package/lib/legend-ai/LegendAI_LegendApplicationPlugin_Extension.js.map +1 -1
- package/lib/legend-ai/__test-utils__/LegendAITestUtils.d.ts +2 -1
- package/lib/legend-ai/__test-utils__/LegendAITestUtils.d.ts.map +1 -1
- package/lib/legend-ai/__test-utils__/LegendAITestUtils.js +37 -2
- package/lib/legend-ai/__test-utils__/LegendAITestUtils.js.map +1 -1
- package/lib/legend-ai/components/LegendAIAnalysisPanel.d.ts.map +1 -1
- package/lib/legend-ai/components/LegendAIAnalysisPanel.js +11 -12
- package/lib/legend-ai/components/LegendAIAnalysisPanel.js.map +1 -1
- package/lib/legend-ai/components/LegendAIAnalysisUtils.d.ts +7 -0
- package/lib/legend-ai/components/LegendAIAnalysisUtils.d.ts.map +1 -1
- package/lib/legend-ai/components/LegendAIAnalysisUtils.js +106 -41
- package/lib/legend-ai/components/LegendAIAnalysisUtils.js.map +1 -1
- package/lib/legend-ai/components/LegendAIChat.d.ts +1 -5
- package/lib/legend-ai/components/LegendAIChat.d.ts.map +1 -1
- package/lib/legend-ai/components/LegendAIChat.js +168 -109
- package/lib/legend-ai/components/LegendAIChat.js.map +1 -1
- package/lib/legend-ai/components/LegendAIChatHelpers.d.ts +21 -0
- package/lib/legend-ai/components/LegendAIChatHelpers.d.ts.map +1 -0
- package/lib/legend-ai/components/LegendAIChatHelpers.js +85 -0
- package/lib/legend-ai/components/LegendAIChatHelpers.js.map +1 -0
- package/lib/legend-ai/components/LegendAIChatInput.d.ts +21 -0
- package/lib/legend-ai/components/LegendAIChatInput.d.ts.map +1 -0
- package/lib/legend-ai/components/LegendAIChatInput.js +78 -0
- package/lib/legend-ai/components/LegendAIChatInput.js.map +1 -0
- package/lib/legend-ai/components/LegendAIScopeSelector.d.ts +25 -0
- package/lib/legend-ai/components/LegendAIScopeSelector.d.ts.map +1 -0
- package/lib/legend-ai/components/LegendAIScopeSelector.js +85 -0
- package/lib/legend-ai/components/LegendAIScopeSelector.js.map +1 -0
- package/lib/legend-ai/index.d.ts +8 -3
- package/lib/legend-ai/index.d.ts.map +1 -1
- package/lib/legend-ai/index.js +8 -3
- package/lib/legend-ai/index.js.map +1 -1
- package/lib/legend-ai/stores/LegendAIChatProcessors.d.ts +105 -0
- package/lib/legend-ai/stores/LegendAIChatProcessors.d.ts.map +1 -0
- package/lib/legend-ai/stores/LegendAIChatProcessors.js +1482 -0
- package/lib/legend-ai/stores/LegendAIChatProcessors.js.map +1 -0
- package/lib/legend-ai/stores/LegendAIChatState.d.ts +2 -35
- package/lib/legend-ai/stores/LegendAIChatState.d.ts.map +1 -1
- package/lib/legend-ai/stores/LegendAIChatState.js +114 -949
- package/lib/legend-ai/stores/LegendAIChatState.js.map +1 -1
- package/package.json +5 -5
- package/src/code-editor/CodeEditor.tsx +19 -0
- package/src/legend-ai/LegendAIDocEnrichment.ts +572 -0
- package/src/legend-ai/LegendAITypes.ts +213 -5
- package/src/legend-ai/LegendAI_LegendApplicationPlugin_Extension.ts +25 -0
- package/src/legend-ai/__test-utils__/LegendAITestUtils.ts +55 -1
- package/src/legend-ai/components/LegendAIAnalysisPanel.tsx +14 -34
- package/src/legend-ai/components/LegendAIAnalysisUtils.ts +157 -47
- package/src/legend-ai/components/LegendAIChat.tsx +389 -206
- package/src/legend-ai/components/LegendAIChatHelpers.ts +117 -0
- package/src/legend-ai/components/LegendAIChatInput.tsx +209 -0
- package/src/legend-ai/components/LegendAIScopeSelector.tsx +199 -0
- package/src/legend-ai/index.ts +31 -4
- package/src/legend-ai/stores/LegendAIChatProcessors.ts +2563 -0
- package/src/legend-ai/stores/LegendAIChatState.ts +161 -1697
- package/tsconfig.json +5 -0
|
@@ -0,0 +1,117 @@
|
|
|
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 { PRIMITIVE_TYPE } from '@finos/legend-graph';
|
|
18
|
+
import type {
|
|
19
|
+
LegendAIProductMetadata,
|
|
20
|
+
TDSServiceSchema,
|
|
21
|
+
TDSColumnSchema,
|
|
22
|
+
} from '../LegendAITypes.js';
|
|
23
|
+
|
|
24
|
+
const MAX_SUGGESTED_QUERIES = 8;
|
|
25
|
+
|
|
26
|
+
const STRING_TYPES = new Set<string>([PRIMITIVE_TYPE.STRING]);
|
|
27
|
+
|
|
28
|
+
const NUMERIC_TYPES = new Set<string>([
|
|
29
|
+
PRIMITIVE_TYPE.NUMBER,
|
|
30
|
+
PRIMITIVE_TYPE.INTEGER,
|
|
31
|
+
PRIMITIVE_TYPE.FLOAT,
|
|
32
|
+
PRIMITIVE_TYPE.DECIMAL,
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
const DATE_TYPES = new Set<string>([
|
|
36
|
+
PRIMITIVE_TYPE.DATE,
|
|
37
|
+
PRIMITIVE_TYPE.STRICTDATE,
|
|
38
|
+
PRIMITIVE_TYPE.DATETIME,
|
|
39
|
+
]);
|
|
40
|
+
|
|
41
|
+
export function isStringColumn(c: TDSColumnSchema): boolean {
|
|
42
|
+
return STRING_TYPES.has(c.type ?? '') && !c.name.toLowerCase().includes('id');
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export function isNumericColumn(c: TDSColumnSchema): boolean {
|
|
46
|
+
return NUMERIC_TYPES.has(c.type ?? '');
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
export function isDateColumn(c: TDSColumnSchema): boolean {
|
|
50
|
+
return (
|
|
51
|
+
DATE_TYPES.has(c.type ?? '') ||
|
|
52
|
+
c.name.toLowerCase().includes('date') ||
|
|
53
|
+
c.name.toLowerCase().includes('time')
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function buildDataInsightSuggestions(
|
|
58
|
+
primary: TDSServiceSchema,
|
|
59
|
+
stringCol: TDSColumnSchema | undefined,
|
|
60
|
+
numericCol: TDSColumnSchema | undefined,
|
|
61
|
+
): string[] {
|
|
62
|
+
const result: string[] = [];
|
|
63
|
+
if (stringCol) {
|
|
64
|
+
result.push(
|
|
65
|
+
`Show the distinct ${stringCol.name} values from ${primary.title}`,
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
if (numericCol && !stringCol) {
|
|
70
|
+
result.push(`What is the total ${numericCol.name} in ${primary.title}?`);
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function buildMultiServiceSuggestion(services: TDSServiceSchema[]): string[] {
|
|
76
|
+
if (services.length < 2) {
|
|
77
|
+
return [];
|
|
78
|
+
}
|
|
79
|
+
return [`Show 10 records from ${services[1]?.title}`];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
export function buildSuggestedQueries(
|
|
83
|
+
services: TDSServiceSchema[],
|
|
84
|
+
metadata: LegendAIProductMetadata,
|
|
85
|
+
): string[] {
|
|
86
|
+
const suggestions: string[] = [
|
|
87
|
+
`What data does ${metadata.name} offer and how can I use it?`,
|
|
88
|
+
];
|
|
89
|
+
|
|
90
|
+
if (services.length === 0) {
|
|
91
|
+
return [
|
|
92
|
+
...suggestions,
|
|
93
|
+
'What access points are available?',
|
|
94
|
+
'Describe the data model and key entities',
|
|
95
|
+
];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const primary = services[0];
|
|
99
|
+
if (!primary) {
|
|
100
|
+
return [
|
|
101
|
+
...suggestions,
|
|
102
|
+
'What access points are available and what columns do they have?',
|
|
103
|
+
];
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
const stringCol = primary.columns.find(isStringColumn);
|
|
107
|
+
const numericCol = primary.columns.find(isNumericColumn);
|
|
108
|
+
|
|
109
|
+
const multiSvcSuggestions = buildMultiServiceSuggestion(services);
|
|
110
|
+
|
|
111
|
+
return [
|
|
112
|
+
...suggestions,
|
|
113
|
+
`Show 10 records from ${primary.title}`,
|
|
114
|
+
...buildDataInsightSuggestions(primary, stringCol, numericCol),
|
|
115
|
+
...multiSvcSuggestions,
|
|
116
|
+
].slice(0, MAX_SUGGESTED_QUERIES);
|
|
117
|
+
}
|
|
@@ -0,0 +1,209 @@
|
|
|
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 { useRef, useLayoutEffect, useEffect, useState, useMemo } from 'react';
|
|
18
|
+
import {
|
|
19
|
+
SendIcon,
|
|
20
|
+
LoadingIcon,
|
|
21
|
+
SquareIcon,
|
|
22
|
+
SparkleStarsIcon,
|
|
23
|
+
CheckIcon,
|
|
24
|
+
clsx,
|
|
25
|
+
} from '@finos/legend-art';
|
|
26
|
+
import type { LegendAIChatState, LegendAIScopeItem } from '../LegendAITypes.js';
|
|
27
|
+
import { LegendAIScopeSelector } from './LegendAIScopeSelector.js';
|
|
28
|
+
|
|
29
|
+
const MAX_TEXTAREA_HEIGHT = 160;
|
|
30
|
+
|
|
31
|
+
export const LegendAIChatInput = (props: {
|
|
32
|
+
state: LegendAIChatState;
|
|
33
|
+
scopes: LegendAIScopeItem[];
|
|
34
|
+
}): React.ReactNode => {
|
|
35
|
+
const { state, scopes } = props;
|
|
36
|
+
const textareaRef = useRef<HTMLTextAreaElement>(null);
|
|
37
|
+
const modelDropdownRef = useRef<HTMLDivElement>(null);
|
|
38
|
+
const [isModelDropdownOpen, setIsModelDropdownOpen] = useState(false);
|
|
39
|
+
|
|
40
|
+
const modelLabel = useMemo(() => {
|
|
41
|
+
const modelName = state.selectedModelName ?? 'Auto';
|
|
42
|
+
return modelName.length > 18 ? `${modelName.slice(0, 17)}...` : modelName;
|
|
43
|
+
}, [state.selectedModelName]);
|
|
44
|
+
|
|
45
|
+
const effectiveModelName =
|
|
46
|
+
state.selectedModelName ?? state.availableModelNames[0];
|
|
47
|
+
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (!isModelDropdownOpen) {
|
|
50
|
+
return undefined;
|
|
51
|
+
}
|
|
52
|
+
const handleClickOutside = (event: MouseEvent): void => {
|
|
53
|
+
if (
|
|
54
|
+
modelDropdownRef.current &&
|
|
55
|
+
!modelDropdownRef.current.contains(event.target as Node)
|
|
56
|
+
) {
|
|
57
|
+
setIsModelDropdownOpen(false);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
const handleEscape = (event: KeyboardEvent): void => {
|
|
61
|
+
if (event.key === 'Escape') {
|
|
62
|
+
setIsModelDropdownOpen(false);
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
66
|
+
document.addEventListener('keydown', handleEscape);
|
|
67
|
+
return (): void => {
|
|
68
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
69
|
+
document.removeEventListener('keydown', handleEscape);
|
|
70
|
+
};
|
|
71
|
+
}, [isModelDropdownOpen]);
|
|
72
|
+
|
|
73
|
+
useLayoutEffect(() => {
|
|
74
|
+
const el = textareaRef.current;
|
|
75
|
+
if (el) {
|
|
76
|
+
el.style.height = 'auto';
|
|
77
|
+
const nextHeight = Math.min(el.scrollHeight, MAX_TEXTAREA_HEIGHT);
|
|
78
|
+
el.style.height = `${nextHeight}px`;
|
|
79
|
+
}
|
|
80
|
+
}, [state.questionText]);
|
|
81
|
+
|
|
82
|
+
return (
|
|
83
|
+
<div className="legend-ai__input-area">
|
|
84
|
+
<div className="legend-ai__question-wrapper">
|
|
85
|
+
{state.selectedScopes.length > 0 && (
|
|
86
|
+
<LegendAIScopeSelector
|
|
87
|
+
scopes={scopes}
|
|
88
|
+
selectedScopes={state.selectedScopes}
|
|
89
|
+
onToggleScope={state.toggleScope}
|
|
90
|
+
onRemoveScope={state.removeScope}
|
|
91
|
+
hideSelector={true}
|
|
92
|
+
/>
|
|
93
|
+
)}
|
|
94
|
+
|
|
95
|
+
<div className="legend-ai__input-top">
|
|
96
|
+
<textarea
|
|
97
|
+
ref={textareaRef}
|
|
98
|
+
className="legend-ai__question"
|
|
99
|
+
placeholder="Ask anything about your data..."
|
|
100
|
+
rows={1}
|
|
101
|
+
spellCheck={false}
|
|
102
|
+
value={state.questionText}
|
|
103
|
+
onChange={(e): void => state.setQuestionText(e.target.value)}
|
|
104
|
+
onKeyDown={(e): void => {
|
|
105
|
+
if (e.key === 'Enter' && !e.shiftKey) {
|
|
106
|
+
e.preventDefault();
|
|
107
|
+
if (!state.isSending && state.questionText.trim()) {
|
|
108
|
+
state.askQuestion();
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}}
|
|
112
|
+
/>
|
|
113
|
+
</div>
|
|
114
|
+
|
|
115
|
+
<div className="legend-ai__input-bottom">
|
|
116
|
+
<div className="legend-ai__input-bottom-left">
|
|
117
|
+
<LegendAIScopeSelector
|
|
118
|
+
scopes={scopes}
|
|
119
|
+
selectedScopes={state.selectedScopes}
|
|
120
|
+
onToggleScope={state.toggleScope}
|
|
121
|
+
onRemoveScope={state.removeScope}
|
|
122
|
+
hidePills={true}
|
|
123
|
+
/>
|
|
124
|
+
|
|
125
|
+
{state.availableModelNames.length > 0 && (
|
|
126
|
+
<div className="legend-ai__model-selector" ref={modelDropdownRef}>
|
|
127
|
+
<button
|
|
128
|
+
type="button"
|
|
129
|
+
className="legend-ai__model-btn"
|
|
130
|
+
title="Select model"
|
|
131
|
+
aria-label="Select model"
|
|
132
|
+
aria-haspopup="true"
|
|
133
|
+
aria-expanded={isModelDropdownOpen}
|
|
134
|
+
onClick={(): void =>
|
|
135
|
+
setIsModelDropdownOpen((current) => !current)
|
|
136
|
+
}
|
|
137
|
+
>
|
|
138
|
+
<span className="legend-ai__model-btn-icon">
|
|
139
|
+
<SparkleStarsIcon />
|
|
140
|
+
</span>
|
|
141
|
+
<span className="legend-ai__model-btn-label">
|
|
142
|
+
{modelLabel}
|
|
143
|
+
</span>
|
|
144
|
+
</button>
|
|
145
|
+
{isModelDropdownOpen && (
|
|
146
|
+
<div className="legend-ai__model-dropdown">
|
|
147
|
+
{state.availableModelNames.map((modelName) => {
|
|
148
|
+
const isSelected = modelName === effectiveModelName;
|
|
149
|
+
return (
|
|
150
|
+
<button
|
|
151
|
+
key={modelName}
|
|
152
|
+
type="button"
|
|
153
|
+
aria-pressed={isSelected}
|
|
154
|
+
className={clsx('legend-ai__model-dropdown-item', {
|
|
155
|
+
'legend-ai__model-dropdown-item--selected':
|
|
156
|
+
isSelected,
|
|
157
|
+
})}
|
|
158
|
+
onClick={(): void => {
|
|
159
|
+
state.setSelectedModelName(modelName);
|
|
160
|
+
setIsModelDropdownOpen(false);
|
|
161
|
+
}}
|
|
162
|
+
>
|
|
163
|
+
<span className="legend-ai__model-dropdown-item-label">
|
|
164
|
+
{modelName}
|
|
165
|
+
</span>
|
|
166
|
+
<span className="legend-ai__model-dropdown-item-check">
|
|
167
|
+
{isSelected ? <CheckIcon /> : null}
|
|
168
|
+
</span>
|
|
169
|
+
</button>
|
|
170
|
+
);
|
|
171
|
+
})}
|
|
172
|
+
</div>
|
|
173
|
+
)}
|
|
174
|
+
</div>
|
|
175
|
+
)}
|
|
176
|
+
</div>
|
|
177
|
+
|
|
178
|
+
<div className="legend-ai__input-bottom-right">
|
|
179
|
+
{state.isSending && (
|
|
180
|
+
<button
|
|
181
|
+
type="button"
|
|
182
|
+
title="Stop generation"
|
|
183
|
+
aria-label="Stop generation"
|
|
184
|
+
className="legend-ai__stop-btn"
|
|
185
|
+
onClick={(): void => state.stopGeneration()}
|
|
186
|
+
>
|
|
187
|
+
<SquareIcon />
|
|
188
|
+
</button>
|
|
189
|
+
)}
|
|
190
|
+
<button
|
|
191
|
+
type="button"
|
|
192
|
+
title="Send"
|
|
193
|
+
aria-label="Send"
|
|
194
|
+
className="legend-ai__send-btn"
|
|
195
|
+
disabled={state.isSending || !state.questionText.trim()}
|
|
196
|
+
onClick={(): void => state.askQuestion()}
|
|
197
|
+
>
|
|
198
|
+
{state.isSending ? (
|
|
199
|
+
<LoadingIcon isLoading={true} />
|
|
200
|
+
) : (
|
|
201
|
+
<SendIcon />
|
|
202
|
+
)}
|
|
203
|
+
</button>
|
|
204
|
+
</div>
|
|
205
|
+
</div>
|
|
206
|
+
</div>
|
|
207
|
+
</div>
|
|
208
|
+
);
|
|
209
|
+
};
|
|
@@ -0,0 +1,199 @@
|
|
|
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 { useState, useRef, useEffect, useCallback, useMemo } from 'react';
|
|
18
|
+
import {
|
|
19
|
+
PlusCircleIcon,
|
|
20
|
+
SearchIcon,
|
|
21
|
+
CheckIcon,
|
|
22
|
+
TimesIcon,
|
|
23
|
+
} from '@finos/legend-art';
|
|
24
|
+
import type { LegendAIScopeItem } from '../LegendAITypes.js';
|
|
25
|
+
|
|
26
|
+
export const LegendAIScopeSelector = (props: {
|
|
27
|
+
scopes: LegendAIScopeItem[];
|
|
28
|
+
selectedScopes: LegendAIScopeItem[];
|
|
29
|
+
onToggleScope: (scope: LegendAIScopeItem) => void;
|
|
30
|
+
onRemoveScope: (scopeId: string) => void;
|
|
31
|
+
hidePills?: boolean;
|
|
32
|
+
hideSelector?: boolean;
|
|
33
|
+
}): React.ReactNode => {
|
|
34
|
+
const {
|
|
35
|
+
scopes,
|
|
36
|
+
selectedScopes,
|
|
37
|
+
onToggleScope,
|
|
38
|
+
onRemoveScope,
|
|
39
|
+
hidePills,
|
|
40
|
+
hideSelector,
|
|
41
|
+
} = props;
|
|
42
|
+
const [dropdownOpen, setDropdownOpen] = useState(false);
|
|
43
|
+
const [searchText, setSearchText] = useState('');
|
|
44
|
+
const dropdownRef = useRef<HTMLDivElement>(null);
|
|
45
|
+
const btnRef = useRef<HTMLButtonElement>(null);
|
|
46
|
+
const searchRef = useRef<HTMLInputElement>(null);
|
|
47
|
+
|
|
48
|
+
const filteredScopes = useMemo(
|
|
49
|
+
() =>
|
|
50
|
+
searchText.trim()
|
|
51
|
+
? scopes.filter(
|
|
52
|
+
(s) =>
|
|
53
|
+
s.label.toLowerCase().includes(searchText.toLowerCase()) ||
|
|
54
|
+
s.description?.toLowerCase().includes(searchText.toLowerCase()),
|
|
55
|
+
)
|
|
56
|
+
: scopes,
|
|
57
|
+
[scopes, searchText],
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const closeDropdown = useCallback((): void => {
|
|
61
|
+
setDropdownOpen(false);
|
|
62
|
+
setSearchText('');
|
|
63
|
+
btnRef.current?.focus();
|
|
64
|
+
}, []);
|
|
65
|
+
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (!dropdownOpen) {
|
|
68
|
+
return undefined;
|
|
69
|
+
}
|
|
70
|
+
const handleClickOutside = (e: MouseEvent): void => {
|
|
71
|
+
if (
|
|
72
|
+
dropdownRef.current &&
|
|
73
|
+
!dropdownRef.current.contains(e.target as Node)
|
|
74
|
+
) {
|
|
75
|
+
setDropdownOpen(false);
|
|
76
|
+
setSearchText('');
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
const handleEscape = (e: KeyboardEvent): void => {
|
|
80
|
+
if (e.key === 'Escape') {
|
|
81
|
+
closeDropdown();
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
85
|
+
document.addEventListener('keydown', handleEscape);
|
|
86
|
+
return (): void => {
|
|
87
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
88
|
+
document.removeEventListener('keydown', handleEscape);
|
|
89
|
+
};
|
|
90
|
+
}, [dropdownOpen, closeDropdown]);
|
|
91
|
+
|
|
92
|
+
useEffect(() => {
|
|
93
|
+
if (dropdownOpen) {
|
|
94
|
+
requestAnimationFrame(() => searchRef.current?.focus());
|
|
95
|
+
}
|
|
96
|
+
}, [dropdownOpen]);
|
|
97
|
+
|
|
98
|
+
return (
|
|
99
|
+
<>
|
|
100
|
+
{!hidePills && selectedScopes.length > 0 && (
|
|
101
|
+
<div className="legend-ai__scope-pills">
|
|
102
|
+
{selectedScopes.map((scope) => (
|
|
103
|
+
<span key={scope.id} className="legend-ai__scope-pill">
|
|
104
|
+
<span className="legend-ai__scope-pill-label">{scope.label}</span>
|
|
105
|
+
<button
|
|
106
|
+
type="button"
|
|
107
|
+
className="legend-ai__scope-pill-remove"
|
|
108
|
+
aria-label={`Remove ${scope.label}`}
|
|
109
|
+
onClick={(): void => onRemoveScope(scope.id)}
|
|
110
|
+
>
|
|
111
|
+
<TimesIcon />
|
|
112
|
+
</button>
|
|
113
|
+
</span>
|
|
114
|
+
))}
|
|
115
|
+
</div>
|
|
116
|
+
)}
|
|
117
|
+
{!hideSelector && (
|
|
118
|
+
<div className="legend-ai__scope-selector" ref={dropdownRef}>
|
|
119
|
+
<button
|
|
120
|
+
ref={btnRef}
|
|
121
|
+
type="button"
|
|
122
|
+
className="legend-ai__scope-btn"
|
|
123
|
+
title="Add scope"
|
|
124
|
+
aria-label="Add scope"
|
|
125
|
+
aria-haspopup="true"
|
|
126
|
+
aria-expanded={dropdownOpen}
|
|
127
|
+
onClick={(): void => {
|
|
128
|
+
if (dropdownOpen) {
|
|
129
|
+
closeDropdown();
|
|
130
|
+
} else {
|
|
131
|
+
setDropdownOpen(true);
|
|
132
|
+
setSearchText('');
|
|
133
|
+
}
|
|
134
|
+
}}
|
|
135
|
+
>
|
|
136
|
+
<PlusCircleIcon />
|
|
137
|
+
</button>
|
|
138
|
+
{dropdownOpen && (
|
|
139
|
+
<div
|
|
140
|
+
className="legend-ai__scope-dropdown"
|
|
141
|
+
aria-multiselectable="true"
|
|
142
|
+
>
|
|
143
|
+
<div className="legend-ai__scope-dropdown-search">
|
|
144
|
+
<SearchIcon />
|
|
145
|
+
<input
|
|
146
|
+
ref={searchRef}
|
|
147
|
+
type="text"
|
|
148
|
+
className="legend-ai__scope-dropdown-search-input"
|
|
149
|
+
placeholder="Search scopes..."
|
|
150
|
+
value={searchText}
|
|
151
|
+
onChange={(e): void => setSearchText(e.target.value)}
|
|
152
|
+
onKeyDown={(e): void => {
|
|
153
|
+
if (e.key === 'Escape') {
|
|
154
|
+
e.stopPropagation();
|
|
155
|
+
closeDropdown();
|
|
156
|
+
}
|
|
157
|
+
}}
|
|
158
|
+
/>
|
|
159
|
+
</div>
|
|
160
|
+
<div className="legend-ai__scope-dropdown-list">
|
|
161
|
+
{filteredScopes.length === 0 ? (
|
|
162
|
+
<div className="legend-ai__scope-dropdown-empty">
|
|
163
|
+
No matching scopes
|
|
164
|
+
</div>
|
|
165
|
+
) : (
|
|
166
|
+
filteredScopes.map((scope) => {
|
|
167
|
+
const isSelected = selectedScopes.some(
|
|
168
|
+
(s) => s.id === scope.id,
|
|
169
|
+
);
|
|
170
|
+
return (
|
|
171
|
+
<button
|
|
172
|
+
key={scope.id}
|
|
173
|
+
type="button"
|
|
174
|
+
aria-pressed={isSelected}
|
|
175
|
+
className={`legend-ai__scope-dropdown-item${isSelected ? 'legend-ai__scope-dropdown-item--selected' : ''}`}
|
|
176
|
+
onClick={(): void => {
|
|
177
|
+
onToggleScope(scope);
|
|
178
|
+
setDropdownOpen(false);
|
|
179
|
+
setSearchText('');
|
|
180
|
+
}}
|
|
181
|
+
>
|
|
182
|
+
<span className="legend-ai__scope-dropdown-item-check">
|
|
183
|
+
{isSelected && <CheckIcon />}
|
|
184
|
+
</span>
|
|
185
|
+
<span className="legend-ai__scope-dropdown-item-label">
|
|
186
|
+
{scope.label}
|
|
187
|
+
</span>
|
|
188
|
+
</button>
|
|
189
|
+
);
|
|
190
|
+
})
|
|
191
|
+
)}
|
|
192
|
+
</div>
|
|
193
|
+
</div>
|
|
194
|
+
)}
|
|
195
|
+
</div>
|
|
196
|
+
)}
|
|
197
|
+
</>
|
|
198
|
+
);
|
|
199
|
+
};
|
package/src/legend-ai/index.ts
CHANGED
|
@@ -19,15 +19,19 @@ export * from './LegendAI_LegendApplicationPlugin_Extension.js';
|
|
|
19
19
|
export {
|
|
20
20
|
LegendAIChat,
|
|
21
21
|
LEGEND_AI_ANCHOR_ID,
|
|
22
|
+
renderStepStatusIcon,
|
|
23
|
+
} from './components/LegendAIChat.js';
|
|
24
|
+
export {
|
|
22
25
|
isStringColumn,
|
|
23
26
|
isNumericColumn,
|
|
24
27
|
isDateColumn,
|
|
25
28
|
buildSuggestedQueries,
|
|
26
|
-
|
|
27
|
-
} from './components/
|
|
29
|
+
} from './components/LegendAIChatHelpers.js';
|
|
30
|
+
export { LegendAIScopeSelector } from './components/LegendAIScopeSelector.js';
|
|
31
|
+
export { LegendAIChatInput } from './components/LegendAIChatInput.js';
|
|
28
32
|
export { LegendAIErrorBoundary } from './components/LegendAIErrorBoundary.js';
|
|
33
|
+
export { useLegendAIChatState } from './stores/LegendAIChatState.js';
|
|
29
34
|
export {
|
|
30
|
-
useLegendAIChatState,
|
|
31
35
|
updateLastAssistant,
|
|
32
36
|
addThinkingStep,
|
|
33
37
|
completeThinkingSteps,
|
|
@@ -37,18 +41,32 @@ export {
|
|
|
37
41
|
buildGenerationFailureMessage,
|
|
38
42
|
buildExecutionErrorMessage,
|
|
39
43
|
generateAndJudgeSql,
|
|
44
|
+
generateAndJudgeAccessPointSql,
|
|
40
45
|
executeSqlAndReport,
|
|
41
46
|
executePureQueryAndReport,
|
|
42
47
|
processQuestionViaOrchestrator,
|
|
43
48
|
processQuestion,
|
|
44
49
|
processQuestionWithIntent,
|
|
45
50
|
handleMetadataQuestion,
|
|
51
|
+
buildMetadataOverview,
|
|
52
|
+
attachMetadataOverview,
|
|
46
53
|
elapsedSeconds,
|
|
47
54
|
createMessagePair,
|
|
48
55
|
analyzeOrchestratorResults,
|
|
56
|
+
cleanLlmSqlResponse,
|
|
57
|
+
isValidSqlCorrection,
|
|
58
|
+
sanitizeJoinOrderBy,
|
|
59
|
+
sanitizeLiteralColumns,
|
|
60
|
+
stripGuessedNonDateServiceParams,
|
|
61
|
+
ensureDateParameters,
|
|
62
|
+
detectMissingServiceParams,
|
|
63
|
+
buildMissingParamsWarning,
|
|
64
|
+
ensureSafeLimit,
|
|
65
|
+
preFilterServicesByRelevance,
|
|
49
66
|
type MessageSetter,
|
|
50
67
|
type LegendAIOperationContext,
|
|
51
|
-
|
|
68
|
+
type MissingParamInfo,
|
|
69
|
+
} from './stores/LegendAIChatProcessors.js';
|
|
52
70
|
export { LegendAIResultGrid } from './components/LegendAIResultGrid.js';
|
|
53
71
|
export { LegendAIAnalysisPanel } from './components/LegendAIAnalysisPanel.js';
|
|
54
72
|
export {
|
|
@@ -56,9 +74,18 @@ export {
|
|
|
56
74
|
LegendAIDonutChart,
|
|
57
75
|
} from './components/LegendAICharts.js';
|
|
58
76
|
export {
|
|
77
|
+
type LegendAIGridAnalysis,
|
|
59
78
|
computeKeyMetrics,
|
|
60
79
|
computeChartData,
|
|
61
80
|
inferChartType,
|
|
62
81
|
computeTopItems,
|
|
63
82
|
findNumericColumnName,
|
|
83
|
+
analyzeGridData,
|
|
64
84
|
} from './components/LegendAIAnalysisUtils.js';
|
|
85
|
+
export {
|
|
86
|
+
buildPropertyDocIndex,
|
|
87
|
+
enrichColumnsFromElementDocs,
|
|
88
|
+
inferServiceRelationshipsFromAssociations,
|
|
89
|
+
extractLambdaPreFilters,
|
|
90
|
+
formatPreFiltersForContext,
|
|
91
|
+
} from './LegendAIDocEnrichment.js';
|