Skip to content
This repository was archived by the owner on Jul 9, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
aa473fa
use import resolver in lu parsing
zhixzhan Mar 24, 2021
0c1863e
Merge branch 'main' into zhixzhan/lu-parse-resolver
zhixzhan Mar 25, 2021
60ea594
Merge branch 'main' into zhixzhan/lu-parse-resolver
boydc2014 Mar 25, 2021
7c7cd2f
Merge branch 'main' into zhixzhan/lu-parse-resolver
boydc2014 Mar 25, 2021
3cea98a
Merge branch 'main' into zhixzhan/lu-parse-resolver
zhixzhan Mar 25, 2021
9956543
Merge branch 'main' into zhixzhan/lu-parse-resolver
zhixzhan Mar 26, 2021
863c3d5
update ut
zhixzhan Mar 26, 2021
24c19e3
Merge branch 'main' into zhixzhan/lu-parse-resolver
zhixzhan Mar 26, 2021
8e7d9a5
handle lu resolve error
zhixzhan Mar 26, 2021
4f37cd3
Merge branch 'main' into zhixzhan/lu-parse-resolver
zhixzhan Mar 29, 2021
0280752
Merge branch 'main' into zhixzhan/lu-parse-resolver
boydc2014 Mar 29, 2021
396ed84
use origin fileId to update
zhixzhan Mar 30, 2021
3edc186
Merge branch 'zhixzhan/lu-parse-resolver' of https://github.com/micro…
zhixzhan Mar 30, 2021
29ea4dd
Merge branch 'main' into zhixzhan/lu-parse-resolver
zhixzhan Mar 30, 2021
1ec6fac
update
zhixzhan Mar 30, 2021
1f53d7e
Merge branch 'main' into zhixzhan/lu-parse-resolver
zhixzhan Mar 30, 2021
09e9f76
Merge branch 'main' into zhixzhan/lu-parse-resolver
zhixzhan Mar 30, 2021
5ec8ca9
Merge branch 'main' into zhixzhan/lu-parse-resolver
zhixzhan Mar 30, 2021
886bdae
Merge branch 'main' into zhixzhan/lu-parse-resolver
zhixzhan Mar 30, 2021
a800e95
Merge branch 'main' into zhixzhan/lu-parse-resolver
zhixzhan Mar 31, 2021
5036ad7
Merge branch 'main' into zhixzhan/lu-parse-resolver
boydc2014 Mar 31, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
luFileState,
qnaFileState,
settingsState,
luFilesSelectorFamily,
} from '../../recoilModel';
import { decodeDesignerPathToArrayPath } from '../../utils/convertUtils/designerPathEncoder';
import lgDiagnosticWorker from '../../recoilModel/parsers/lgDiagnosticWorker';
Expand Down Expand Up @@ -50,6 +51,7 @@ export const useEmptyPropsHandler = (
qnaFileState({ projectId: activeBot, qnaFileId: `${dialogId}.${locale}` })
);
const lgFiles = useRecoilValue(lgFilesSelectorFamily(projectId));
const luFiles = useRecoilValue(luFilesSelectorFamily(projectId));
const { updateDialog, setDesignPageLocation, navTo } = useRecoilValue(dispatcherState);

// migration: add id to dialog when dialog doesn't have id
Expand Down Expand Up @@ -84,14 +86,14 @@ export const useEmptyPropsHandler = (
let isMounted = true;
if (currentLu.isContentUnparsed) {
//for current dialog, check the lu file to make sure the file is parsed.
luWorker.parse(currentLu.id, currentLu.content, settings.luFeatures).then((result) => {
luWorker.parse(currentLu.id, currentLu.content, settings.luFeatures, luFiles).then((result) => {
isMounted ? setCurrentLu(result as LuFile) : null;
});
return () => {
isMounted = false;
};
}
}, [currentDialog, currentLu]);
}, [currentDialog, currentLu, luFiles]);

useEffect(() => {
if (!currentDialog || !currentQna.id) return;
Expand Down
1 change: 1 addition & 0 deletions Composer/packages/client/src/recoilModel/atoms/botState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ const emptyLu: LuFile = {
content: '',
diagnostics: [],
intents: [],
allIntents: [],
empty: true,
resource: {
Sections: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const file1 = {
content: `\r\n# Hello\r\n-hi`,
};

const luFiles = [luUtil.parse(file1.id, file1.content, luFeatures)] as LuFile[];
const luFiles = [luUtil.parse(file1.id, file1.content, luFeatures, [])] as LuFile[];

const getLuIntent = (Name, Body): LuIntentSection =>
({
Expand Down
19 changes: 11 additions & 8 deletions Composer/packages/client/src/recoilModel/dispatchers/lu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,12 @@ const getRelatedLuFileChanges = async (
// sync add/remove intents
if (onlyAdds || onlyDeletes) {
for (const item of sameIdOtherLocaleFiles) {
let newLuFile = (await luWorker.addIntents(item, addedIntents, luFeatures)) as LuFile;
let newLuFile = (await luWorker.addIntents(item, addedIntents, luFeatures, luFiles)) as LuFile;
newLuFile = (await luWorker.removeIntents(
newLuFile,
deletedIntents.map(({ Name }) => Name),
luFeatures
luFeatures,
luFiles
)) as LuFile;
changes.push(newLuFile);
}
Expand All @@ -130,7 +131,7 @@ export const createLuFileState = async (
const locale = await snapshot.getPromise(localeState(projectId));
const { languages, luFeatures } = await snapshot.getPromise(settingsState(projectId));
const createdLuId = `${id}.${locale}`;
const createdLuFile = (await luWorker.parse(id, content, luFeatures)) as LuFile;
const createdLuFile = (await luWorker.parse(id, content, luFeatures, luFiles)) as LuFile;
if (luFiles.find((lu) => lu.id === createdLuId)) {
setError(callbackHelpers, new Error(formatMessage('lu file already exist')));
return;
Expand Down Expand Up @@ -197,7 +198,7 @@ export const luDispatcher = () => {
const { luFeatures } = await snapshot.getPromise(settingsState(projectId));

try {
const updatedFile = (await luWorker.parse(id, content, luFeatures)) as LuFile;
const updatedFile = (await luWorker.parse(id, content, luFeatures, luFiles)) as LuFile;
const updatedFiles = await getRelatedLuFileChanges(luFiles, updatedFile, projectId, luFeatures);
// compare to drop expired change on current id file.
/**
Expand Down Expand Up @@ -252,7 +253,8 @@ export const luDispatcher = () => {
item,
intentName,
{ Name: intent.Name },
luFeatures
luFeatures,
luFiles
)) as LuFile;
changes.push(updatedFile);
}
Expand All @@ -263,7 +265,8 @@ export const luDispatcher = () => {
luFile,
intentName,
{ Body: intent.Body },
luFeatures
luFeatures,
luFiles
)) as LuFile;
updateLuFiles(callbackHelpers, projectId, { updates: [updatedFile] });
}
Expand All @@ -290,7 +293,7 @@ export const luDispatcher = () => {
const file = luFiles.find((temp) => temp.id === id);
if (!file) return luFiles;
try {
const updatedFile = (await luWorker.addIntent(file, intent, luFeatures)) as LuFile;
const updatedFile = (await luWorker.addIntent(file, intent, luFeatures, luFiles)) as LuFile;
const updatedFiles = await getRelatedLuFileChanges(luFiles, updatedFile, projectId, luFeatures);
updateLuFiles(callbackHelpers, projectId, { updates: updatedFiles });
} catch (error) {
Expand All @@ -316,7 +319,7 @@ export const luDispatcher = () => {
const file = luFiles.find((temp) => temp.id === id);
if (!file) return luFiles;
try {
const updatedFile = (await luWorker.removeIntent(file, intentName, luFeatures)) as LuFile;
const updatedFile = (await luWorker.removeIntent(file, intentName, luFeatures, luFiles)) as LuFile;
const updatedFiles = await getRelatedLuFileChanges(luFiles, updatedFile, projectId, luFeatures);
updateLuFiles(callbackHelpers, projectId, { updates: updatedFiles });
} catch (error) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ const emptyLuFile = (id: string, content: string): LuFile => {
content,
diagnostics: [],
intents: [],
allIntents: [],
empty: true,
resource: {
Sections: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('test lu worker', () => {
it('get expected parse result', async () => {
const content = `# Hello
- hi`;
const result: any = await luWorker.parse('', content, luFeatures);
const result: any = await luWorker.parse('', content, luFeatures, []);
const expected = [
{ Body: '- hi', Entities: [], Name: 'Hello', range: new Range(new Position(1, 0), new Position(2, 4)) },
];
Expand All @@ -47,7 +47,7 @@ hi
@ simple friendsName

`;
const { intents, diagnostics }: any = await luWorker.parse('', content, luFeatures);
const { intents, diagnostics }: any = await luWorker.parse('', content, luFeatures, []);
expect(intents.length).toEqual(1);
expect(diagnostics.length).toEqual(1);
expect(diagnostics[0].range.start.line).toEqual(2);
Expand All @@ -57,7 +57,7 @@ hi
});

it('get expected add intent result', async () => {
const result: any = await luWorker.addIntent(luFile, getLuIntent('New', '-IntentValue'), luFeatures);
const result: any = await luWorker.addIntent(luFile, getLuIntent('New', '-IntentValue'), luFeatures, []);
const expected = {
Body: '-IntentValue',
Entities: [],
Expand All @@ -73,7 +73,8 @@ hi
const result: any = await luWorker.addIntents(
luFile,
[getLuIntent('New1', '-IntentValue1'), getLuIntent('New2', '-IntentValue2')],
luFeatures
luFeatures,
[]
);
const expected = {
Body: '-IntentValue2',
Expand All @@ -87,7 +88,7 @@ hi
});

it('get expected update intent result', async () => {
const result: any = await luWorker.updateIntent(luFile, 'New', getLuIntent('New', '-update'), luFeatures);
const result: any = await luWorker.updateIntent(luFile, 'New', getLuIntent('New', '-update'), luFeatures, []);
const expected = {
Body: '-update',
Entities: [],
Expand All @@ -100,14 +101,14 @@ hi
});

it('get expected remove intent result', async () => {
const result: any = await luWorker.removeIntent(luFile, 'New2', luFeatures);
const result: any = await luWorker.removeIntent(luFile, 'New2', luFeatures, []);
expect(result.intents.length).toBe(3);
expect(result.intents[3]).toBeUndefined();
luFile = result;
});

it('get expected remove intent result', async () => {
const result: any = await luWorker.removeIntents(luFile, ['New1', 'New'], luFeatures);
const result: any = await luWorker.removeIntents(luFile, ['New1', 'New'], luFeatures, []);
expect(result.intents.length).toBe(1);
});
});
30 changes: 18 additions & 12 deletions Composer/packages/client/src/recoilModel/parsers/luWorker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
} from './types';
// Wrapper class
class LuWorker extends BaseWorker<LuActionType> {
parse(id: string, content: string, luFeatures) {
const payload = { id, content, luFeatures };
parse(id: string, content: string, luFeatures, luFiles: LuFile[]) {
const payload = { id, content, luFeatures, luFiles };
return this.sendMsg<LuParsePayload>(LuActionType.Parse, payload);
}

Expand All @@ -26,28 +26,34 @@ class LuWorker extends BaseWorker<LuActionType> {
return this.sendMsg<LuParseAllPayload>(LuActionType.ParseAll, payload);
}

addIntent(luFile: LuFile, intent: LuIntentSection, luFeatures) {
const payload = { luFile, intent, luFeatures };
addIntent(luFile: LuFile, intent: LuIntentSection, luFeatures, luFiles: LuFile[]) {
const payload = { luFile, intent, luFeatures, luFiles };
return this.sendMsg<LuAddIntentPayload>(LuActionType.AddIntent, payload);
}

updateIntent(luFile: LuFile, intentName: string, intent: { Name?: string; Body?: string }, luFeatures) {
const payload = { luFile, intentName, intent, luFeatures };
updateIntent(
luFile: LuFile,
intentName: string,
intent: { Name?: string; Body?: string },
luFeatures,
luFiles: LuFile[]
) {
const payload = { luFile, intentName, intent, luFeatures, luFiles };
return this.sendMsg<LuUpdateIntentPayload>(LuActionType.UpdateIntent, payload);
}

removeIntent(luFile: LuFile, intentName: string, luFeatures) {
const payload = { luFile, intentName, luFeatures };
removeIntent(luFile: LuFile, intentName: string, luFeatures, luFiles: LuFile[]) {
const payload = { luFile, intentName, luFeatures, luFiles };
return this.sendMsg<LuRemoveIntentPayload>(LuActionType.RemoveIntent, payload);
}

addIntents(luFile: LuFile, intents: LuIntentSection[], luFeatures) {
const payload = { luFile, intents, luFeatures };
addIntents(luFile: LuFile, intents: LuIntentSection[], luFeatures, luFiles: LuFile[]) {
const payload = { luFile, intents, luFeatures, luFiles };
return this.sendMsg<LuAddIntentsPayload>(LuActionType.AddIntents, payload);
}

removeIntents(luFile: LuFile, intentNames: string[], luFeatures) {
const payload = { luFile, intentNames, luFeatures };
removeIntents(luFile: LuFile, intentNames: string[], luFeatures, luFiles: LuFile[]) {
const payload = { luFile, intentNames, luFeatures, luFiles };
return this.sendMsg<LuRemoveIntentsPayload>(LuActionType.RemoveIntents, payload);
}
}
Expand Down
6 changes: 6 additions & 0 deletions Composer/packages/client/src/recoilModel/parsers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export type LuParsePayload = {
id: string;
content: string;
luFeatures: ILUFeaturesConfig;
luFiles: LuFile[];
};

export type LuParseAllPayload = {
Expand All @@ -19,31 +20,36 @@ export type LuAddIntentPayload = {
luFile: LuFile;
intent: LuIntentSection;
luFeatures: ILUFeaturesConfig;
luFiles: LuFile[];
};

export type LuAddIntentsPayload = {
luFile: LuFile;
intents: LuIntentSection[];
luFeatures: ILUFeaturesConfig;
luFiles: LuFile[];
};

export type LuUpdateIntentPayload = {
luFile: LuFile;
intentName: string;
intent?: { Name?: string; Body?: string };
luFeatures: ILUFeaturesConfig;
luFiles: LuFile[];
};

export type LuRemoveIntentPayload = {
luFile: LuFile;
intentName: string;
luFeatures: ILUFeaturesConfig;
luFiles: LuFile[];
};

export type LuRemoveIntentsPayload = {
luFile: LuFile;
intentNames: string[];
luFeatures: ILUFeaturesConfig;
luFiles: LuFile[];
};

export type LgParsePayload = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// Licensed under the MIT License.

import { luUtil } from '@bfc/indexers';
import { luImportResolverGenerator } from '@bfc/shared';

import {
LuActionType,
Expand Down Expand Up @@ -66,48 +67,52 @@ type LuMessageEvent =
| RemoveIntentsMessage
| ParseAllMessage;

const luFileResolver = (luFiles) => {
return luImportResolverGenerator(luFiles, '.lu');
};

export const handleMessage = (msg: LuMessageEvent) => {
let result: any = null;
switch (msg.type) {
case LuActionType.Parse: {
const { id, content, luFeatures } = msg.payload;
result = luUtil.parse(id, content, luFeatures);
const { id, content, luFeatures, luFiles } = msg.payload;
result = luUtil.parse(id, content, luFeatures, luFiles);
break;
}

case LuActionType.ParseAll: {
const { luResources, luFeatures } = msg.payload;
result = luResources.map(({ id, content }) => luUtil.parse(id, content, luFeatures));
result = luResources.map(({ id, content }) => luUtil.parse(id, content, luFeatures, luResources));
break;
}

case LuActionType.AddIntent: {
const { luFile, intent, luFeatures } = msg.payload;
result = luUtil.addIntent(luFile, intent, luFeatures);
const { luFile, intent, luFeatures, luFiles } = msg.payload;
result = luUtil.addIntent(luFile, intent, luFeatures, luFileResolver(luFiles));
break;
}

case LuActionType.AddIntents: {
const { luFile, intents, luFeatures } = msg.payload;
result = luUtil.addIntents(luFile, intents, luFeatures);
const { luFile, intents, luFeatures, luFiles } = msg.payload;
result = luUtil.addIntents(luFile, intents, luFeatures, luFileResolver(luFiles));
break;
}

case LuActionType.UpdateIntent: {
const { luFile, intentName, intent, luFeatures } = msg.payload;
result = luUtil.updateIntent(luFile, intentName, intent || null, luFeatures);
const { luFile, intentName, intent, luFeatures, luFiles } = msg.payload;
result = luUtil.updateIntent(luFile, intentName, intent || null, luFeatures, luFileResolver(luFiles));
break;
}

case LuActionType.RemoveIntent: {
const { luFile, intentName, luFeatures } = msg.payload;
result = luUtil.removeIntent(luFile, intentName, luFeatures);
const { luFile, intentName, luFeatures, luFiles } = msg.payload;
result = luUtil.removeIntent(luFile, intentName, luFeatures, luFileResolver(luFiles));
break;
}

case LuActionType.RemoveIntents: {
const { luFile, intentNames, luFeatures } = msg.payload;
result = luUtil.removeIntents(luFile, intentNames, luFeatures);
const { luFile, intentNames, luFeatures, luFiles } = msg.payload;
result = luUtil.removeIntents(luFile, intentNames, luFeatures, luFileResolver(luFiles));
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ const luFile: LuFile = {
Entities: [{ Name: 'target', Type: 'ml' }],
},
],
allIntents: [],
empty: false,
content: '',
imports: [],
Expand Down
Loading