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
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
2 changes: 1 addition & 1 deletion Composer/packages/client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"@bfc/extensions": "*",
"@bfc/indexers": "*",
"@bfc/shared": "*",
"@bfcomposer/bf-lu": "^1.1.8",
"@bfcomposer/bf-lu": "^1.2.5",
"@emotion/core": "^10.0.7",
"@reach/router": "^1.2.1",
"axios": "^0.18.0",
Expand Down
2 changes: 1 addition & 1 deletion Composer/packages/lib/indexers/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
},
"dependencies": {
"@bfc/shared": "*",
"@bfcomposer/bf-lu": "^1.1.8",
"@bfcomposer/bf-lu": "^1.2.5",
"botbuilder-lg": "^4.8.0-preview.97252",
"botframework-expressions": "4.7.0-preview.93464",
"lodash": "^4.17.15"
Expand Down
2 changes: 1 addition & 1 deletion Composer/packages/server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"@bfc/lg-languageserver": "*",
"@bfc/lu-languageserver": "*",
"@bfc/shared": "*",
"@bfcomposer/lubuild": "1.1.2-preview",
"@bfcomposer/bf-lu": "^1.2.5",
"archiver": "^3.0.0",
"axios": "^0.18.0",
"azure-storage": "^2.10.3",
Expand Down
74 changes: 43 additions & 31 deletions Composer/packages/server/src/models/bot/luPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
// Licensed under the MIT License.

import isEqual from 'lodash/isEqual';
import { runBuild } from '@bfcomposer/lubuild';
import { luBuild } from '@bfcomposer/bf-lu/lib/parser/lubuild';
import { LuFile } from '@bfc/indexers';

import { Path } from './../../utility/path';
import { IFileStorage } from './../storage/interface';
import { ILuisConfig, LuisStatus, FileUpdateType } from './interface';
import log from './../../logger';

const GENERATEDFOLDER = 'ComposerDialogs/generated';
const LU_STATUS_FILE = 'luis.status.json';
const DEFAULT_STATUS = {
Expand All @@ -24,6 +26,11 @@ export class LuPublisher {
// key: filePath relative to bot dir
// value: lastUpdateTime && lastPublishTime
public status: { [key: string]: LuisStatus } = {};

private builder = new luBuild.Builder(message => {
log(message);
});

constructor(path: string, storage: IFileStorage) {
this.botDir = path;
this.generatedFolderPath = Path.join(this.botDir, GENERATEDFOLDER);
Expand Down Expand Up @@ -80,24 +87,35 @@ export class LuPublisher {
};

public publish = async (luFiles: LuFile[]) => {
const config = this._getConfig(luFiles);
if (config.models.length === 0) {
if (!luFiles.length) {
throw new Error('No luis file exist');
}
const config = this._getConfig();
const curTime = Date.now();
try {
await runBuild(config);
const loadResult = await this._loadLuConatents(luFiles);
const buildResult = await this.builder.build(
loadResult.luContents,
loadResult.recognizers,
config.authoringKey,
config.region,
config.botName,
config.suffix,
config.fallbackLocal,
false,
loadResult.multiRecognizers,
loadResult.settings
);

// update pubish status after sucessfully published
luFiles.forEach(f => {
this.status[f.relativePath].lastPublishTime = curTime;
});
await this.saveStatus();
await this.builder.writeDialogAssets(buildResult, true, this.generatedFolderPath);
} catch (error) {
throw new Error(error?.body?.error?.message ?? 'Error publishing to LUIS.');
throw new Error(error.body?.error?.message || error.message || 'Error publishing to LUIS.');
}

await this._copyDialogsToTargetFolder(config);
};

public getUnpublisedFiles = (files: LuFile[]) => {
Expand Down Expand Up @@ -147,33 +165,27 @@ export class LuPublisher {
}
}

private _copyDialogsToTargetFolder = async (config: any) => {
const defaultLanguage = config.defaultLanguage;
await config.models.forEach(async (filePath: string) => {
const baseName = Path.basename(filePath, '.lu');
const rootPath = Path.dirname(filePath);
const currentPath = `${filePath}.dialog`;
const targetPath = Path.join(this.generatedFolderPath, `${baseName}.lu.dialog`);
const currentVariantPath = Path.join(rootPath, `${baseName}.${defaultLanguage}.lu.dialog`);
const targetVariantPath = Path.join(this.generatedFolderPath, `${baseName}.${defaultLanguage}.lu.dialog`);
await this.storage.copyFile(currentPath, targetPath);
await this.storage.copyFile(currentVariantPath, targetVariantPath);
await this.storage.removeFile(currentPath);
await this.storage.removeFile(currentVariantPath);
});
private _getConfig = () => {
const luConfig = {
authoringKey: this.config?.authoringKey || '',
region: this.config?.authoringRegion || '',
botName: this.config?.name || '',
suffix: this.config?.environment || '',
fallbackLocal: this.config?.defaultLanguage || 'en-us',
};
return luConfig;
};

private _getConfig = (luFiles: LuFile[]) => {
const luConfig: any = { ...this.config };
luConfig.models = [];
luConfig.autodelete = true;
luConfig.dialogs = true;
luConfig.force = false;
luConfig.folder = this.generatedFolderPath;
luFiles.forEach(file => {
luConfig.models.push(Path.resolve(this.botDir, file.relativePath));
private _loadLuConatents = async (luFiles: LuFile[]) => {
const pathList = luFiles.map(file => {
return Path.resolve(this.botDir, file.relativePath);
});

return luConfig;
return await this.builder.loadContents(
pathList,
this.config?.defaultLanguage || '',
this.config?.environment || '',
this.config?.authoringRegion || ''
);
};
}
35 changes: 35 additions & 0 deletions Composer/packages/server/src/types/bf-lu.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

declare module '@bfcomposer/bf-lu/lib/parser/lubuild' {
namespace luBuild {
class Builder {
private readonly handler: (input: string) => any;

constructor(handler: any);

loadContents(
files: string[],
culture: string,
suffix: string,
region: string,
stdin?: string
): { luContents: any[]; recognizers: Map<string, any>; multiRecognizers: Map<string, any>; settings: any };

build(
luContents: any[],
recognizers: Map<string, any>,
authoringKey: string,
region: string,
botName: string,
suffix: string,
fallbackLocale: string,
deleteOldVersion: boolean,
multiRecognizers: Map<string, any>,
settings: any
): any[];

writeDialogAssets(contents: any[], force: boolean, out: string): void;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
},
"dependencies": {
"@microsoft/bf-cli-command": "https://botbuilder.myget.org/F/botbuilder-declarative/npm/@microsoft/bf-cli-command/-/@microsoft/bf-cli-command-1.0.0.tgz",
"@bfcomposer/bf-lu": "https://botbuilder.myget.org/F/botbuilder-declarative/npm/@bfcomposer/bf-lu/-/@bfcomposer/bf-lu-1.1.8.tgz",
"@bfcomposer/bf-lu": "^1.2.5",
"@types/node": "^12.0.4",
"express": "^4.15.2",
"monaco-editor-core": "^0.17.0",
Expand Down
Loading