Skip to content

Commit 827dbb4

Browse files
authored
Misc refactorings and improvements (#927)
* remove STML mapping (was only prototype, much weaker than Jsonata) * reduce logging * extract required utils to own file * remove outdated todo, as the feature now exists * fix schema diagram not showing 0 value in enum component * reduce API key persistence due to potential security risks * fix test case * apply formatting changes --------- Co-authored-by: Logende <Logende@users.noreply.github.com>
1 parent d89c5cc commit 827dbb4

26 files changed

Lines changed: 101 additions & 1432 deletions

meta_configurator/src/components/panels/ai-prompts/ApiKey.vue

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@ Component for displaying the OpenAI API key input.
55
import {type Ref, ref} from 'vue';
66
import Password from 'primevue/password';
77
import SelectButton from 'primevue/selectbutton';
8-
import {getApiKeyRef, getIsPersistKeyRef} from '@/utility/ai/apiKey';
9-
10-
const isShowPersistOption = false; // currently the option of whether to persist the key is not shown because without persistence the key currently can not be accessed
8+
import {getApiKeyRef, getRememberInTabRef} from '@/utility/ai/apiKey';
119
1210
const apiKey: Ref<string> = getApiKeyRef();
13-
const isPersistKey: Ref<boolean> = getIsPersistKeyRef();
11+
const rememberInTab: Ref<boolean> = getRememberInTabRef();
1412
15-
const persistOptions = ref([
16-
{name: 'true', value: true},
17-
{name: 'false', value: false},
13+
const rememberOptions = ref([
14+
{name: 'Remember in this tab', value: true},
15+
{name: 'Forget on refresh', value: false},
1816
]);
1917
</script>
2018

@@ -28,17 +26,18 @@ const persistOptions = ref([
2826
possible without permanently connecting your credit card with your account. Check this
2927
<a href="https://platform.openai.com/docs/pricing" target="_blank">link</a> for pricing.
3028
<br />
31-
<br />
3229
MetaConfigurator by default uses the gpt-4o-mini model, which has very low cost. For improved
3330
results you can change to more performant models in the settings tab.
31+
<br />
32+
<br />
33+
Your key is stored only in your browser and sent directly to your chosen provider. It is never
34+
sent to MetaConfigurator servers.
3435
<span class="api-key-container">
3536
<span>Key:</span>
36-
<Password v-model="apiKey" placeholder="Enter your OpenAI API Key" :feedback="false" />
37-
<span v-show="isShowPersistOption">Persist:</span>
37+
<Password v-model="apiKey" placeholder="Enter your API Key" :feedback="false" />
3838
<SelectButton
39-
v-show="isShowPersistOption"
40-
v-model="isPersistKey"
41-
:options="persistOptions"
39+
v-model="rememberInTab"
40+
:options="rememberOptions"
4241
option-label="name"
4342
option-value="value" />
4443
</span>

meta_configurator/src/components/panels/ai-prompts/aiPromptUtils.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,4 @@ function hasMoreOpeningBrackets(input: string): boolean {
3838
return openingCount > closingCount;
3939
}
4040

41-
export function getApiKey(): string {
42-
return localStorage.getItem('openai_api_key') || '';
43-
}
41+
export {getApiKey} from '@/utility/ai/apiKey';

meta_configurator/src/components/toolbar/dialogs/data-mapping/DataMappingDialog.vue

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ import Message from 'primevue/message';
99
import ApiKey from '@/components/panels/ai-prompts/ApiKey.vue';
1010
import {SessionMode} from '@/store/sessionMode';
1111
import {getDataForMode} from '@/data/useDataLink';
12-
import {DataMappingServiceStml} from '@/data-mapping/stml/dataMappingServiceStml';
1312
import {DataMappingServiceJsonata} from '@/data-mapping/jsonata/dataMappingServiceJsonata';
1413
import type {DataMappingService} from '@/data-mapping/dataMappingService';
1514
import type {Editor} from 'brace';
@@ -35,19 +34,15 @@ const isLoadingMapping = ref(false);
3534
3635
const settings = useSettings();
3736
38-
const mappingServiceTypes = ['Advanced (JSONata)', 'SimpleTransformationMappingLanguage (STML)'];
37+
const mappingServiceTypes = ['Advanced (JSONata)'];
3938
4039
const mappingServiceWarnings = [
4140
'The JSONata mapping service is very expressive flexible, but may generate invalid mappings for complex inputs, which have to manually be corrected.',
42-
'The STML mapping service usually generates valid mappings, but it can perform only simple source to target path mappings and value transformations. WARNING: It supports executing arbitrary JavaScript functions as transformations, which may lead to security issues if the input is not properly sanitized.',
4341
];
4442
4543
const selectedMappingServiceType: Ref<string> = ref(mappingServiceTypes[0]);
4644
4745
const mappingService: Ref<DataMappingService> = computed(() => {
48-
if (selectedMappingServiceType.value === 'SimpleTransformationMappingLanguage (STML)') {
49-
return new DataMappingServiceStml();
50-
}
5146
if (selectedMappingServiceType.value === 'Advanced (JSONata)') {
5247
return new DataMappingServiceJsonata();
5348
}

meta_configurator/src/data-mapping/jsonata/dataMappingServiceJsonata.ts

Lines changed: 17 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,6 @@ export class DataMappingServiceJsonata implements DataMappingService {
2222
userComments: string
2323
): Promise<{config: string; success: boolean; message: string}> {
2424
const inputDataSubset = trimDataToMaxSize(input);
25-
console.log(
26-
'Reduced input data from ' +
27-
JSON.stringify(input).length / 1024 +
28-
' KB to ' +
29-
JSON.stringify(inputDataSubset).length / 1024 +
30-
' KB'
31-
);
3225

3326
// infer schema for input data
3427
const inputFileSchema = inferJsonSchema(inputDataSubset);
@@ -43,25 +36,6 @@ export class DataMappingServiceJsonata implements DataMappingService {
4336
const inputFileSchemaStr = JSON.stringify(inputFileSchema);
4437
const targetSchemaStr = JSON.stringify(targetSchema);
4538
const inputDataSubsetStr = JSON.stringify(inputDataSubset);
46-
console.log(
47-
'Sizes of the different input files in KB:' +
48-
' jsonata example files: ' +
49-
(
50-
(jsonataReferenceStr.length +
51-
jsonataInputExampleStr.length +
52-
jsonataInputExampleSchemaStr.length +
53-
jsonataExpressionStr.length +
54-
jsonataOutputExampleStr.length +
55-
jsonataOutputExampleSchemaStr.length) /
56-
1024
57-
).toFixed(2) +
58-
' inputFileSchema: ' +
59-
(inputFileSchemaStr.length / 1024).toFixed(2) +
60-
' targetSchema: ' +
61-
(targetSchemaStr.length / 1024).toFixed(2) +
62-
' inputDataSubset: ' +
63-
(inputDataSubsetStr.length / 1024).toFixed(2)
64-
);
6539
const resultPromise = queryJsonataExpression(
6640
apiKey,
6741
jsonataReferenceStr,
@@ -124,12 +98,25 @@ export class DataMappingServiceJsonata implements DataMappingService {
12498
return result;
12599
}
126100

127-
removeSpecialCharactersRecursive(data: any) {
128-
// TODO
101+
removeSpecialCharactersRecursive(data: any): void {
102+
if (Array.isArray(data)) {
103+
data.forEach(item => this.removeSpecialCharactersRecursive(item));
104+
} else if (data !== null && typeof data === 'object') {
105+
for (const key of Object.keys(data)) {
106+
const sanitizedKey = key.replace(/[^a-zA-Z0-9_]/g, '_');
107+
if (sanitizedKey !== key) {
108+
data[sanitizedKey] = data[key];
109+
delete data[key];
110+
}
111+
this.removeSpecialCharactersRecursive(data[sanitizedKey]);
112+
}
113+
}
129114
}
130115

131-
sanitizeMappingConfig(config: string, input: any): string {
132-
return config; // TODO
116+
sanitizeMappingConfig(config: string, _input: any): string {
117+
// JSONata natively supports special characters in property names via backtick syntax,
118+
// so no transformation of the mapping config expression is required.
119+
return config;
133120
}
134121

135122
validateMappingConfig(config: string, input: any): {success: boolean; message: string} {

meta_configurator/src/data-mapping/stml/__tests__/applyTransformations.test.ts

Lines changed: 0 additions & 89 deletions
This file was deleted.

meta_configurator/src/data-mapping/stml/__tests__/dataMappingUtils.test.ts

Lines changed: 0 additions & 75 deletions
This file was deleted.

0 commit comments

Comments
 (0)