@finos/legend-extension-dsl-data-space-studio 0.1.364 → 0.2.1
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/components/DataSpaceGeneralEditor/DataSpaceAISuggestionReviewModal.d.ts +35 -0
- package/lib/components/DataSpaceGeneralEditor/DataSpaceAISuggestionReviewModal.d.ts.map +1 -0
- package/lib/components/DataSpaceGeneralEditor/DataSpaceAISuggestionReviewModal.js +92 -0
- package/lib/components/DataSpaceGeneralEditor/DataSpaceAISuggestionReviewModal.js.map +1 -0
- package/lib/components/DataSpaceGeneralEditor/DataSpaceHomeTab.d.ts.map +1 -1
- package/lib/components/DataSpaceGeneralEditor/DataSpaceHomeTab.js +38 -27
- package/lib/components/DataSpaceGeneralEditor/DataSpaceHomeTab.js.map +1 -1
- package/lib/index.css +2 -2
- package/lib/index.css.map +1 -1
- package/lib/package.json +1 -1
- package/lib/stores/DataSpaceAISuggestion.d.ts +45 -0
- package/lib/stores/DataSpaceAISuggestion.d.ts.map +1 -0
- package/lib/stores/DataSpaceAISuggestion.js +175 -0
- package/lib/stores/DataSpaceAISuggestion.js.map +1 -0
- package/package.json +9 -9
- package/src/components/DataSpaceGeneralEditor/DataSpaceAISuggestionReviewModal.tsx +339 -0
- package/src/components/DataSpaceGeneralEditor/DataSpaceHomeTab.tsx +83 -74
- package/src/stores/DataSpaceAISuggestion.ts +255 -0
- package/tsconfig.json +2 -0
|
@@ -24,7 +24,6 @@ import {
|
|
|
24
24
|
} from '@finos/legend-application-studio';
|
|
25
25
|
import { DataSpace } from '@finos/legend-extension-dsl-data-space/graph';
|
|
26
26
|
import {
|
|
27
|
-
clsx,
|
|
28
27
|
PanelForm,
|
|
29
28
|
PanelFormTextField,
|
|
30
29
|
PanelLoadingIndicator,
|
|
@@ -42,6 +41,15 @@ import {
|
|
|
42
41
|
dataSpace_setDescription,
|
|
43
42
|
dataSpace_setTitle,
|
|
44
43
|
} from '../../stores/studio/DSL_DataSpace_GraphModifierHelper.js';
|
|
44
|
+
import {
|
|
45
|
+
buildDataSpaceAISuggestionRows,
|
|
46
|
+
serializeDataSpaceAISuggestionFields,
|
|
47
|
+
type DataSpaceAISuggestionRow,
|
|
48
|
+
} from '../../stores/DataSpaceAISuggestion.js';
|
|
49
|
+
import {
|
|
50
|
+
DataSpaceAISuggestionReviewModal,
|
|
51
|
+
type DataSpaceAISuggestionSelection,
|
|
52
|
+
} from './DataSpaceAISuggestionReviewModal.js';
|
|
45
53
|
import { DataSpaceDiagramsSection } from './DataSpaceDiagramsSection.js';
|
|
46
54
|
import { DataSpaceElementsSection } from './DataSpaceElementsSection.js';
|
|
47
55
|
import { DataSpaceSupportInfoSection } from './DataSpaceSupportInfoSection.js';
|
|
@@ -78,9 +86,10 @@ export const DataSpaceHomeTab = observer(() => {
|
|
|
78
86
|
.find(Boolean)
|
|
79
87
|
: undefined;
|
|
80
88
|
const [isSuggestingWithAI, setIsSuggestingWithAI] = useState(false);
|
|
81
|
-
const [
|
|
82
|
-
|
|
83
|
-
|
|
89
|
+
const [aiSuggestion, setAISuggestion] = useState<
|
|
90
|
+
| { id: number; rows: DataSpaceAISuggestionRow[]; overwrite: boolean }
|
|
91
|
+
| undefined
|
|
92
|
+
>(undefined);
|
|
84
93
|
const aiSuggestTelemetry = useLegendAISuggestTelemetry(
|
|
85
94
|
editorStore,
|
|
86
95
|
{
|
|
@@ -89,7 +98,9 @@ export const DataSpaceHomeTab = observer(() => {
|
|
|
89
98
|
},
|
|
90
99
|
{ legendAIUrl, available: Boolean(aiDocSuggester), isReadOnly },
|
|
91
100
|
);
|
|
92
|
-
const suggestDocumentationWithAI = async (
|
|
101
|
+
const suggestDocumentationWithAI = async (
|
|
102
|
+
overwrite: boolean,
|
|
103
|
+
): Promise<void> => {
|
|
93
104
|
if (!aiDocSuggester || !legendAIUrl) {
|
|
94
105
|
return;
|
|
95
106
|
}
|
|
@@ -97,7 +108,6 @@ export const DataSpaceHomeTab = observer(() => {
|
|
|
97
108
|
existingText: dataSpace.description,
|
|
98
109
|
});
|
|
99
110
|
setIsSuggestingWithAI(true);
|
|
100
|
-
setAIDocSuggestion(undefined);
|
|
101
111
|
let stage = LEGENDAI_SUGGEST_STAGE.SERIALIZE;
|
|
102
112
|
try {
|
|
103
113
|
const definitions =
|
|
@@ -106,21 +116,30 @@ export const DataSpaceHomeTab = observer(() => {
|
|
|
106
116
|
);
|
|
107
117
|
stage = LEGENDAI_SUGGEST_STAGE.REQUEST;
|
|
108
118
|
const suggestion = await aiDocSuggester(
|
|
109
|
-
{ definitions, data_space_name: dataSpace.path },
|
|
119
|
+
{ definitions, data_space_name: dataSpace.path, overwrite },
|
|
110
120
|
legendAIUrl,
|
|
111
121
|
);
|
|
122
|
+
const rows = buildDataSpaceAISuggestionRows(dataSpace, suggestion);
|
|
112
123
|
const shouldShow = aiSuggestTelemetry.succeed(request, {
|
|
113
|
-
|
|
124
|
+
// the response is structured, so measure the parts that differ
|
|
125
|
+
suggestionText: rows.map((row) => row.suggestedValue).join('\n'),
|
|
114
126
|
definitionsLength: definitions.length,
|
|
115
127
|
currentText: dataSpace.description,
|
|
116
|
-
confidence: suggestion.confidence,
|
|
117
128
|
});
|
|
118
|
-
if (!shouldShow) {
|
|
129
|
+
if (!shouldShow && overwrite) {
|
|
119
130
|
editorStore.applicationStore.notificationService.notifyWarning(
|
|
120
|
-
'LegendAI did not return
|
|
131
|
+
'LegendAI did not return any suggestions for this data space',
|
|
121
132
|
);
|
|
133
|
+
setAISuggestion(undefined);
|
|
134
|
+
return;
|
|
122
135
|
}
|
|
123
|
-
|
|
136
|
+
// with nothing new to fill in, still open the review so the user can
|
|
137
|
+
// ask to regenerate the fields that already have a value
|
|
138
|
+
setAISuggestion((prev) => ({
|
|
139
|
+
id: (prev?.id ?? 0) + 1,
|
|
140
|
+
rows,
|
|
141
|
+
overwrite,
|
|
142
|
+
}));
|
|
124
143
|
} catch (error) {
|
|
125
144
|
assertErrorThrown(error);
|
|
126
145
|
aiSuggestTelemetry.fail(request, error, stage);
|
|
@@ -142,28 +161,37 @@ export const DataSpaceHomeTab = observer(() => {
|
|
|
142
161
|
setIsSuggestingWithAI(false);
|
|
143
162
|
}
|
|
144
163
|
};
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
164
|
+
const applyAISuggestion = (
|
|
165
|
+
selection: DataSpaceAISuggestionSelection,
|
|
166
|
+
): void => {
|
|
167
|
+
const existingText = dataSpace.description;
|
|
168
|
+
selection.forEach(({ row, value }) => row.write(dataSpace, value));
|
|
169
|
+
const appliedRows = selection.map(({ row }) => row);
|
|
149
170
|
const dataSpacePath = dataSpace.path;
|
|
150
171
|
aiSuggestTelemetry.apply({
|
|
151
|
-
existingText
|
|
152
|
-
appliedText:
|
|
172
|
+
existingText,
|
|
173
|
+
appliedText: serializeDataSpaceAISuggestionFields(dataSpace, appliedRows),
|
|
153
174
|
readCurrentText: (store) => {
|
|
154
175
|
const element =
|
|
155
176
|
store.graphManagerState.graph.getNullableElement(dataSpacePath);
|
|
156
177
|
return element instanceof DataSpace
|
|
157
|
-
? {
|
|
178
|
+
? {
|
|
179
|
+
found: true,
|
|
180
|
+
text: serializeDataSpaceAISuggestionFields(element, appliedRows),
|
|
181
|
+
}
|
|
158
182
|
: { found: false };
|
|
159
183
|
},
|
|
160
184
|
});
|
|
161
|
-
|
|
162
|
-
setAIDocSuggestion(undefined);
|
|
185
|
+
setAISuggestion(undefined);
|
|
163
186
|
};
|
|
164
|
-
const
|
|
187
|
+
const discardAISuggestion = (): void => {
|
|
165
188
|
aiSuggestTelemetry.discard();
|
|
166
|
-
|
|
189
|
+
setAISuggestion(undefined);
|
|
190
|
+
};
|
|
191
|
+
const runSuggestWithAI = (overwrite: boolean): void => {
|
|
192
|
+
suggestDocumentationWithAI(overwrite).catch(
|
|
193
|
+
editorStore.applicationStore.alertUnhandledError,
|
|
194
|
+
);
|
|
167
195
|
};
|
|
168
196
|
|
|
169
197
|
return (
|
|
@@ -177,6 +205,25 @@ export const DataSpaceHomeTab = observer(() => {
|
|
|
177
205
|
}}
|
|
178
206
|
/>
|
|
179
207
|
)}
|
|
208
|
+
{aiDocSuggester && (
|
|
209
|
+
<div className="dataSpace-editor__ai-suggest">
|
|
210
|
+
<button
|
|
211
|
+
className="dataSpace-editor__ai-suggest-btn"
|
|
212
|
+
onClick={(): void => runSuggestWithAI(false)}
|
|
213
|
+
disabled={isSuggestingWithAI || isReadOnly}
|
|
214
|
+
title="Use AI to suggest titles and descriptions for this data space, its execution contexts, diagrams, and executables"
|
|
215
|
+
>
|
|
216
|
+
<SparkleIcon />
|
|
217
|
+
<span>
|
|
218
|
+
{isSuggestingWithAI ? 'Suggesting...' : 'Suggest with AI'}
|
|
219
|
+
</span>
|
|
220
|
+
</button>
|
|
221
|
+
<span className="dataSpace-editor__ai-suggest__hint">
|
|
222
|
+
Fill in titles and descriptions, then review which to keep
|
|
223
|
+
</span>
|
|
224
|
+
</div>
|
|
225
|
+
)}
|
|
226
|
+
<PanelLoadingIndicator isLoading={isSuggestingWithAI && !aiSuggestion} />
|
|
180
227
|
<PanelFormTextField
|
|
181
228
|
name="Title"
|
|
182
229
|
value={dataSpace.title ?? ''}
|
|
@@ -187,70 +234,32 @@ export const DataSpaceHomeTab = observer(() => {
|
|
|
187
234
|
<div className="panel__content__form__section">
|
|
188
235
|
<div className="panel__content__form__section__header__label">
|
|
189
236
|
Description
|
|
190
|
-
{aiDocSuggestion && (
|
|
191
|
-
<span
|
|
192
|
-
className="dataSpace-editor__ai-suggestion-badge"
|
|
193
|
-
style={{ marginLeft: '0.8rem' }}
|
|
194
|
-
>
|
|
195
|
-
<SparkleIcon />
|
|
196
|
-
AI Suggestion
|
|
197
|
-
</span>
|
|
198
|
-
)}
|
|
199
|
-
{aiDocSuggester && !aiDocSuggestion && (
|
|
200
|
-
<button
|
|
201
|
-
className="dataSpace-editor__ai-suggest-btn"
|
|
202
|
-
style={{ marginLeft: '0.8rem' }}
|
|
203
|
-
onClick={(): void => {
|
|
204
|
-
suggestDocumentationWithAI().catch(
|
|
205
|
-
editorStore.applicationStore.alertUnhandledError,
|
|
206
|
-
);
|
|
207
|
-
}}
|
|
208
|
-
disabled={isSuggestingWithAI || isReadOnly}
|
|
209
|
-
title="Use AI to suggest a description for this data space"
|
|
210
|
-
>
|
|
211
|
-
<SparkleIcon />
|
|
212
|
-
<span>
|
|
213
|
-
{isSuggestingWithAI ? 'Suggesting...' : 'Suggest with AI'}
|
|
214
|
-
</span>
|
|
215
|
-
</button>
|
|
216
|
-
)}
|
|
217
237
|
</div>
|
|
218
238
|
<div className="panel__content__form__section__header__prompt">
|
|
219
239
|
Provide a description for this Data Space.
|
|
220
240
|
</div>
|
|
221
|
-
<PanelLoadingIndicator isLoading={isSuggestingWithAI} />
|
|
222
241
|
<textarea
|
|
223
|
-
className=
|
|
224
|
-
'textarea--ai-suggested': Boolean(aiDocSuggestion),
|
|
225
|
-
})}
|
|
242
|
+
className="panel__content__form__section__textarea"
|
|
226
243
|
spellCheck={false}
|
|
227
244
|
disabled={isReadOnly}
|
|
228
|
-
|
|
229
|
-
value={aiDocSuggestion ?? dataSpace.description ?? ''}
|
|
245
|
+
value={dataSpace.description ?? ''}
|
|
230
246
|
onChange={(event) => {
|
|
231
247
|
handleDescriptionChange(event.target.value);
|
|
232
248
|
}}
|
|
233
249
|
placeholder="Enter description"
|
|
234
250
|
/>
|
|
235
|
-
{aiDocSuggestion && (
|
|
236
|
-
<div className="dataSpace-editor__ai-suggestion__actions">
|
|
237
|
-
<button
|
|
238
|
-
className="btn btn--dark dataSpace-editor__ai-suggestion__apply-btn"
|
|
239
|
-
onClick={applyAIDocSuggestion}
|
|
240
|
-
title="Apply AI suggestion to description"
|
|
241
|
-
>
|
|
242
|
-
Apply Suggestion
|
|
243
|
-
</button>
|
|
244
|
-
<button
|
|
245
|
-
className="btn dataSpace-editor__ai-suggestion__dismiss-btn"
|
|
246
|
-
onClick={discardAIDocSuggestion}
|
|
247
|
-
title="Dismiss AI suggestion"
|
|
248
|
-
>
|
|
249
|
-
Dismiss
|
|
250
|
-
</button>
|
|
251
|
-
</div>
|
|
252
|
-
)}
|
|
253
251
|
</div>
|
|
252
|
+
{aiSuggestion && (
|
|
253
|
+
<DataSpaceAISuggestionReviewModal
|
|
254
|
+
key={aiSuggestion.id}
|
|
255
|
+
rows={aiSuggestion.rows}
|
|
256
|
+
overwrite={aiSuggestion.overwrite}
|
|
257
|
+
isRegenerating={isSuggestingWithAI}
|
|
258
|
+
onApply={applyAISuggestion}
|
|
259
|
+
onDismiss={discardAISuggestion}
|
|
260
|
+
onRegenerate={(): void => runSuggestWithAI(true)}
|
|
261
|
+
/>
|
|
262
|
+
)}
|
|
254
263
|
<DataSpaceDiagramsSection />
|
|
255
264
|
<DataSpaceElementsSection />
|
|
256
265
|
<DataSpaceSupportInfoSection />
|
|
@@ -0,0 +1,255 @@
|
|
|
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 type {
|
|
18
|
+
DataSpaceDocResponse,
|
|
19
|
+
DataSpaceExecutableMeta,
|
|
20
|
+
} from '@finos/legend-application-studio';
|
|
21
|
+
import type {
|
|
22
|
+
DataSpace,
|
|
23
|
+
DataSpaceExecutable,
|
|
24
|
+
} from '@finos/legend-extension-dsl-data-space/graph';
|
|
25
|
+
import {
|
|
26
|
+
dataSpace_setDescription,
|
|
27
|
+
dataSpace_setDiagramDescription,
|
|
28
|
+
dataSpace_setDiagramTitle,
|
|
29
|
+
dataSpace_setExecutableDescription,
|
|
30
|
+
dataSpace_setExecutableTitle,
|
|
31
|
+
dataSpace_setExecutionContextDescription,
|
|
32
|
+
dataSpace_setTitle,
|
|
33
|
+
} from './studio/DSL_DataSpace_GraphModifierHelper.js';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* One title or description LegendAI proposes for a data space, for the user to
|
|
37
|
+
* accept or reject. `read` and `write` locate the target by name/path/index
|
|
38
|
+
* on whichever data space instance they are given, so they keep working on
|
|
39
|
+
* the element found in a rebuilt graph.
|
|
40
|
+
*/
|
|
41
|
+
export type DataSpaceAISuggestionRow = {
|
|
42
|
+
key: string;
|
|
43
|
+
groupKey: string;
|
|
44
|
+
groupLabel: string;
|
|
45
|
+
fieldLabel: string;
|
|
46
|
+
currentValue: string | undefined;
|
|
47
|
+
suggestedValue: string;
|
|
48
|
+
read: (dataSpace: DataSpace) => string | undefined;
|
|
49
|
+
write: (dataSpace: DataSpace, value: string) => void;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const isBlank = (value: string | undefined): boolean => !value?.trim();
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Executables are matched by id; those declared without one are paired, in
|
|
56
|
+
* order, with the remaining suggestions, as LegendAI lists them in grammar
|
|
57
|
+
* order.
|
|
58
|
+
*/
|
|
59
|
+
const matchExecutables = (
|
|
60
|
+
executables: DataSpaceExecutable[],
|
|
61
|
+
metas: DataSpaceExecutableMeta[],
|
|
62
|
+
): Map<number, DataSpaceExecutableMeta> => {
|
|
63
|
+
const matches = new Map<number, DataSpaceExecutableMeta>();
|
|
64
|
+
const unmatchedMetaIndexes: number[] = [];
|
|
65
|
+
metas.forEach((meta, metaIdx) => {
|
|
66
|
+
const execIdx =
|
|
67
|
+
meta.id === undefined || meta.id === null
|
|
68
|
+
? -1
|
|
69
|
+
: executables.findIndex(
|
|
70
|
+
(executable, idx) =>
|
|
71
|
+
executable.id !== undefined &&
|
|
72
|
+
executable.id === String(meta.id) &&
|
|
73
|
+
!matches.has(idx),
|
|
74
|
+
);
|
|
75
|
+
if (execIdx === -1) {
|
|
76
|
+
unmatchedMetaIndexes.push(metaIdx);
|
|
77
|
+
} else {
|
|
78
|
+
matches.set(execIdx, meta);
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
const idlessExecIndexes = executables
|
|
82
|
+
.map((executable, idx) => (executable.id === undefined ? idx : -1))
|
|
83
|
+
.filter((idx) => idx !== -1 && !matches.has(idx));
|
|
84
|
+
unmatchedMetaIndexes
|
|
85
|
+
.slice(0, idlessExecIndexes.length)
|
|
86
|
+
.forEach((metaIdx, i) =>
|
|
87
|
+
matches.set(
|
|
88
|
+
idlessExecIndexes[i] as number,
|
|
89
|
+
metas[metaIdx] as DataSpaceExecutableMeta,
|
|
90
|
+
),
|
|
91
|
+
);
|
|
92
|
+
return matches;
|
|
93
|
+
};
|
|
94
|
+
|
|
95
|
+
export const buildDataSpaceAISuggestionRows = (
|
|
96
|
+
dataSpace: DataSpace,
|
|
97
|
+
suggestion: DataSpaceDocResponse,
|
|
98
|
+
): DataSpaceAISuggestionRow[] => {
|
|
99
|
+
const rows: Omit<DataSpaceAISuggestionRow, 'currentValue'>[] = [];
|
|
100
|
+
|
|
101
|
+
rows.push(
|
|
102
|
+
{
|
|
103
|
+
key: 'dataSpace.title',
|
|
104
|
+
groupKey: 'dataSpace',
|
|
105
|
+
groupLabel: 'Data Space',
|
|
106
|
+
fieldLabel: 'Title',
|
|
107
|
+
suggestedValue: suggestion.title,
|
|
108
|
+
read: (ds) => ds.title,
|
|
109
|
+
write: (ds, value) => dataSpace_setTitle(ds, value),
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
key: 'dataSpace.description',
|
|
113
|
+
groupKey: 'dataSpace',
|
|
114
|
+
groupLabel: 'Data Space',
|
|
115
|
+
fieldLabel: 'Description',
|
|
116
|
+
suggestedValue: suggestion.description,
|
|
117
|
+
read: (ds) => ds.description,
|
|
118
|
+
write: (ds, value) => dataSpace_setDescription(ds, value),
|
|
119
|
+
},
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
suggestion.executionContexts?.forEach((meta) => {
|
|
123
|
+
const find = (ds: DataSpace) =>
|
|
124
|
+
ds.executionContexts?.find((ec) => ec.name === meta.name);
|
|
125
|
+
if (!find(dataSpace)) {
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const groupKey = `executionContext:${meta.name}`;
|
|
129
|
+
rows.push({
|
|
130
|
+
key: `${groupKey}.description`,
|
|
131
|
+
groupKey,
|
|
132
|
+
groupLabel: `Execution Context · ${meta.name}`,
|
|
133
|
+
fieldLabel: 'Description',
|
|
134
|
+
suggestedValue: meta.description,
|
|
135
|
+
read: (ds) => find(ds)?.description,
|
|
136
|
+
write: (ds, value) => {
|
|
137
|
+
const executionContext = find(ds);
|
|
138
|
+
if (executionContext) {
|
|
139
|
+
dataSpace_setExecutionContextDescription(executionContext, value);
|
|
140
|
+
}
|
|
141
|
+
},
|
|
142
|
+
});
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
suggestion.diagrams?.forEach((meta) => {
|
|
146
|
+
const find = (ds: DataSpace) =>
|
|
147
|
+
ds.diagrams?.find((d) => d.diagram.value.path === meta.diagram);
|
|
148
|
+
const diagram = find(dataSpace);
|
|
149
|
+
if (!diagram) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
const groupKey = `diagram:${meta.diagram}`;
|
|
153
|
+
const groupLabel = `Diagram · ${diagram.title || meta.diagram}`;
|
|
154
|
+
rows.push(
|
|
155
|
+
{
|
|
156
|
+
key: `${groupKey}.title`,
|
|
157
|
+
groupKey,
|
|
158
|
+
groupLabel,
|
|
159
|
+
fieldLabel: 'Title',
|
|
160
|
+
suggestedValue: meta.title,
|
|
161
|
+
read: (ds) => find(ds)?.title,
|
|
162
|
+
write: (ds, value) => {
|
|
163
|
+
const target = find(ds);
|
|
164
|
+
if (target) {
|
|
165
|
+
dataSpace_setDiagramTitle(target, value);
|
|
166
|
+
}
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
key: `${groupKey}.description`,
|
|
171
|
+
groupKey,
|
|
172
|
+
groupLabel,
|
|
173
|
+
fieldLabel: 'Description',
|
|
174
|
+
suggestedValue: meta.description,
|
|
175
|
+
read: (ds) => find(ds)?.description,
|
|
176
|
+
write: (ds, value) => {
|
|
177
|
+
const target = find(ds);
|
|
178
|
+
if (target) {
|
|
179
|
+
dataSpace_setDiagramDescription(target, value);
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
},
|
|
183
|
+
);
|
|
184
|
+
});
|
|
185
|
+
|
|
186
|
+
const executables = dataSpace.executables ?? [];
|
|
187
|
+
const executableMatches = matchExecutables(
|
|
188
|
+
executables,
|
|
189
|
+
suggestion.executables ?? [],
|
|
190
|
+
);
|
|
191
|
+
Array.from(executableMatches.entries())
|
|
192
|
+
.sort(([a], [b]) => a - b)
|
|
193
|
+
.forEach(([idx, meta]) => {
|
|
194
|
+
const executable = executables[idx] as DataSpaceExecutable;
|
|
195
|
+
const find = (ds: DataSpace) => ds.executables?.[idx];
|
|
196
|
+
const groupKey = `executable:${idx}`;
|
|
197
|
+
const groupLabel = `Executable · ${executable.title || (executable.id ?? idx + 1)}`;
|
|
198
|
+
rows.push(
|
|
199
|
+
{
|
|
200
|
+
key: `${groupKey}.title`,
|
|
201
|
+
groupKey,
|
|
202
|
+
groupLabel,
|
|
203
|
+
fieldLabel: 'Title',
|
|
204
|
+
suggestedValue: meta.title,
|
|
205
|
+
read: (ds) => find(ds)?.title,
|
|
206
|
+
write: (ds, value) => {
|
|
207
|
+
const target = find(ds);
|
|
208
|
+
if (target) {
|
|
209
|
+
dataSpace_setExecutableTitle(target, value);
|
|
210
|
+
}
|
|
211
|
+
},
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
key: `${groupKey}.description`,
|
|
215
|
+
groupKey,
|
|
216
|
+
groupLabel,
|
|
217
|
+
fieldLabel: 'Description',
|
|
218
|
+
suggestedValue: meta.description,
|
|
219
|
+
read: (ds) => find(ds)?.description,
|
|
220
|
+
write: (ds, value) => {
|
|
221
|
+
const target = find(ds);
|
|
222
|
+
if (target) {
|
|
223
|
+
dataSpace_setExecutableDescription(target, value);
|
|
224
|
+
}
|
|
225
|
+
},
|
|
226
|
+
},
|
|
227
|
+
);
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
return rows
|
|
231
|
+
.map((row) => ({ ...row, currentValue: row.read(dataSpace) }))
|
|
232
|
+
.filter(
|
|
233
|
+
(row) =>
|
|
234
|
+
!isBlank(row.suggestedValue) &&
|
|
235
|
+
row.suggestedValue.trim() !== (row.currentValue ?? '').trim(),
|
|
236
|
+
);
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Rows whose current value is empty are pre-selected; when the user asked to
|
|
241
|
+
* regenerate everything, all rows are.
|
|
242
|
+
*/
|
|
243
|
+
export const isDataSpaceAISuggestionRowSelectedByDefault = (
|
|
244
|
+
row: DataSpaceAISuggestionRow,
|
|
245
|
+
overwrite: boolean,
|
|
246
|
+
): boolean => overwrite || isBlank(row.currentValue);
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* Flattens the fields a suggestion wrote so the applied value can be compared
|
|
250
|
+
* with what is eventually pushed.
|
|
251
|
+
*/
|
|
252
|
+
export const serializeDataSpaceAISuggestionFields = (
|
|
253
|
+
dataSpace: DataSpace,
|
|
254
|
+
rows: DataSpaceAISuggestionRow[],
|
|
255
|
+
): string => rows.map((row) => row.read(dataSpace) ?? '').join('\n');
|
package/tsconfig.json
CHANGED
|
@@ -54,6 +54,7 @@
|
|
|
54
54
|
"./src/index.ts",
|
|
55
55
|
"./src/__lib__/DSL_DataSpace_LegendStudioCodeSnippet.ts",
|
|
56
56
|
"./src/__lib__/DSL_DataSpace_LegendStudioDocumentation.ts",
|
|
57
|
+
"./src/stores/DataSpaceAISuggestion.ts",
|
|
57
58
|
"./src/stores/DataSpaceEditorState.ts",
|
|
58
59
|
"./src/stores/DataSpaceExecutableSampleValuesState.ts",
|
|
59
60
|
"./src/stores/DataSpaceExecutableTemplateState.ts",
|
|
@@ -70,6 +71,7 @@
|
|
|
70
71
|
"./src/components/DataSpacePreviewAction.tsx",
|
|
71
72
|
"./src/components/DataSpaceQueryAction.tsx",
|
|
72
73
|
"./src/components/DataSpaceTemplateQueryPromoteReview.tsx",
|
|
74
|
+
"./src/components/DataSpaceGeneralEditor/DataSpaceAISuggestionReviewModal.tsx",
|
|
73
75
|
"./src/components/DataSpaceGeneralEditor/DataSpaceDiagramsSection.tsx",
|
|
74
76
|
"./src/components/DataSpaceGeneralEditor/DataSpaceElementsSection.tsx",
|
|
75
77
|
"./src/components/DataSpaceGeneralEditor/DataSpaceExecutablesSection.tsx",
|