Skip to content

Commit

Permalink
Merge branch 'main' into southworks/fix/lg-expression-validation
Browse files Browse the repository at this point in the history
  • Loading branch information
OEvgeny authored May 16, 2024
2 parents be46791 + d245206 commit 259a975
Show file tree
Hide file tree
Showing 26 changed files with 227 additions and 66 deletions.
1 change: 0 additions & 1 deletion Composer/packages/client/config/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ function getClientEnvironment(publicUrl) {
// images into the `src` and `import` them in code to get their paths.
PUBLIC_URL: publicUrl,
GIT_SHA: getGitSha().toString().replace('\n', ''),
SDK_PACKAGE_VERSION: '4.12.0', // TODO: change this when Composer supports custom schema/custom runtime
COMPOSER_VERSION: getComposerVersion(),
LOCAL_PUBLISH_PATH:
process.env.LOCAL_PUBLISH_PATH || path.resolve(process.cwd(), '../../../extensions/localPublish/hostedBots'),
Expand Down
11 changes: 9 additions & 2 deletions Composer/packages/client/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,14 @@ export const App: React.FC = () => {
const [isClosing, setIsClosing] = useState(false);
const [listener, setListener] = useState<{ destroy(): boolean }>({} as any);

const { fetchExtensions, fetchFeatureFlags, checkNodeVersion, performAppCleanupOnQuit, setMachineInfo } =
useRecoilValue(dispatcherState);
const {
fetchExtensions,
fetchFeatureFlags,
checkNodeVersion,
setBotBuilderVersion,
performAppCleanupOnQuit,
setMachineInfo,
} = useRecoilValue(dispatcherState);
const updateFile = useRecoilCallback((callbackHelpers: CallbackInterface) => async ({ projectId, value }) => {
callbackHelpers.set(lgFileState({ projectId, lgFileId: value.id }), value);
});
Expand All @@ -53,6 +59,7 @@ export const App: React.FC = () => {

useEffect(() => {
checkNodeVersion();
setBotBuilderVersion();
fetchExtensions();
fetchFeatureFlags();

Expand Down
56 changes: 47 additions & 9 deletions Composer/packages/client/src/pages/about/About.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { generateUniqueId } from '@bfc/shared';
import { useRecoilValue } from 'recoil';

import { isElectron } from '../../utils/electronUtil';
import { userSettingsState } from '../../recoilModel';
import { userSettingsState, botBuilderVersionState } from '../../recoilModel';

import * as about from './styles';

Expand All @@ -27,6 +27,8 @@ const getLocaleA11yStatementLink = (locale: string) => {
export const About: React.FC<RouteComponentProps> = () => {
const { appLocale } = useRecoilValue(userSettingsState);
const a11yStatementLink = getLocaleA11yStatementLink(appLocale);
const botBuilderVersion = useRecoilValue(botBuilderVersionState);

return (
<div css={about.content} role="main">
<div css={about.body}>
Expand Down Expand Up @@ -63,14 +65,50 @@ export const About: React.FC<RouteComponentProps> = () => {
<div css={about.diagnosticsInfo}>
<div css={about.diagnosticsInfoText}>
<div css={about.diagnosticsInfoTextAlignLeft}>{formatMessage(`SDK runtime packages`)}</div>
<div css={about.diagnosticsInfoTextAlignLeft}>
<Link
href={`https://github.com/microsoft/botframework-sdk/releases/tag/${process.env.SDK_PACKAGE_VERSION}`}
style={{ marginLeft: '5px', textDecoration: 'underline' }}
target={'_blank'}
>
{process.env.SDK_PACKAGE_VERSION || 'Unknown'}
</Link>
<div css={about.diagnosticsInfoTextAlignLeft} style={{ display: 'flex', flexDirection: 'column' }}>
<p style={{ margin: '0', marginLeft: '10px' }}>
<span style={{ opacity: '75%', marginRight: '5px' }}>DotNet:</span>
{botBuilderVersion.dotnet || '...'} (
<Link
href={`https://www.nuget.org/packages/Microsoft.Bot.Builder.Dialogs.Adaptive.Runtime/${botBuilderVersion.dotnet}`}
style={{ textDecoration: 'underline' }}
target={'_blank'}
>
nuget
</Link>
,
<Link
href={`https://github.com/microsoft/botbuilder-dotnet/releases/tag/${botBuilderVersion.dotnet}`}
style={{ marginLeft: '3px', textDecoration: 'underline' }}
target={'_blank'}
>
release
</Link>
)
</p>
<p style={{ margin: '0', marginLeft: '10px' }}>
<span style={{ opacity: '75%', marginRight: '5px' }}>JavaScript:</span>
{botBuilderVersion.js || '...'} (
<Link
href={`https://www.npmjs.com/package/botbuilder-dialogs-adaptive-runtime/v/${botBuilderVersion.js}`}
style={{ textDecoration: 'underline' }}
target={'_blank'}
>
npm
</Link>
,
<Link
href={`https://github.com/microsoft/botbuilder-js/releases/tag/${botBuilderVersion.js.replace(
'-preview',
'',
)}`}
style={{ marginLeft: '3px', textDecoration: 'underline' }}
target={'_blank'}
>
release
</Link>
)
</p>
</div>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion Composer/packages/client/src/pages/about/styles.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export const smallerText = css`
export const diagnosticsInfoText = css`
display: flex;
justify-content: space-between;
width: 550px;
max-width: 700px;
font-size: 24px;
`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ const AdapterSection = ({ projectId, scrollToSectionId }: Props) => {
a2: ({ children }) => (
<Link
key="package-adapter-settings-page-learn-more"
href={'https://aka.ms/composer-packagmanageraddconnection-learnmore'}
href={
'https://docs.microsoft.com/en-us/composer/how-to-manage-packages?tabs=dotnet#connect-to-package-feeds'
}
target="_blank"
>
{children}
Expand Down
5 changes: 5 additions & 0 deletions Composer/packages/client/src/recoilModel/atoms/appState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ export const userHasNodeInstalledState = atom<boolean>({
default: true,
});

export const botBuilderVersionState = atom<{ dotnet: string; js: string }>({
key: getFullyQualifiedKey('botBuilderVersion'),
default: { dotnet: '', js: '' },
});

export const warnAboutDotNetState = atom<boolean>({
key: getFullyQualifiedKey('warnAboutDotNetState'),
default: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import { CallbackInterface, useRecoilCallback } from 'recoil';
import debounce from 'lodash/debounce';
import formatMessage from 'format-message';
import { getBotBuilderVersion } from '@bfc/shared';

import {
appUpdateState,
Expand All @@ -24,6 +25,7 @@ import {
showWarningDiagnosticsState,
projectsForDiagnosticsFilterState,
templateFeedUrlState,
botBuilderVersionState,
} from '../atoms/appState';
import { AppUpdaterStatus, CreationFlowStatus, CreationFlowType } from '../../constants';
import OnboardingState from '../../utils/onboardingStorage';
Expand Down Expand Up @@ -161,6 +163,18 @@ export const applicationDispatcher = () => {
}
});

const setBotBuilderVersion = useRecoilCallback(({ set }: CallbackInterface) => async () => {
try {
const versions = await getBotBuilderVersion();
set(botBuilderVersionState, versions);
} catch (err) {
set(applicationErrorState, {
message: formatMessage('Error getting BotBuilder version from BotFramework-Components repository'),
summary: err.message,
});
}
});

const fetchTemplateFeedUrl = useRecoilCallback(({ set }: CallbackInterface) => async () => {
try {
const response = await httpClient.get(`/assets/templateFeedUrl`);
Expand Down Expand Up @@ -234,5 +248,6 @@ export const applicationDispatcher = () => {
setProjectsForDiagnosticsFilter,
fetchTemplateFeedUrl,
setTemplateFeedUrl,
setBotBuilderVersion,
};
};
1 change: 0 additions & 1 deletion Composer/packages/client/src/telemetry/TelemetryClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ export default class TelemetryClient {
...this._additionalProperties?.(),
timestamp: Date.now(),
composerVersion: process.env.COMPOSER_VERSION || 'unknown',
sdkPackageVersion: process.env.SDK_PACKAGE_VERSION || 'unknown',
};
}
}
16 changes: 14 additions & 2 deletions Composer/packages/client/src/telemetry/useInitializeLogger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ import { useRecoilValue } from 'recoil';
import { PageNames } from '@bfc/shared';
import camelCase from 'lodash/camelCase';

import { currentProjectIdState, dispatcherState, featureFlagsState, userSettingsState } from '../recoilModel';
import {
currentProjectIdState,
dispatcherState,
featureFlagsState,
userSettingsState,
botBuilderVersionState,
} from '../recoilModel';
import { getPageName } from '../utils/getPageName';
import { useLocation } from '../utils/hooks';

Expand All @@ -19,6 +25,7 @@ export const useInitializeLogger = () => {
const rootProjectId = useRecoilValue(currentProjectIdState);
const { telemetry } = useRecoilValue(userSettingsState);
const featureFlags = useRecoilValue(featureFlagsState);
const botBuilderVersion = useRecoilValue(botBuilderVersionState);
const reducedFeatureFlags = Object.entries(featureFlags).reduce(
(acc, [key, { enabled }]) => ({
...acc,
Expand All @@ -33,7 +40,12 @@ export const useInitializeLogger = () => {

const page = useMemo<PageNames>(() => getPageName(pathname), [pathname]);

TelemetryClient.setup(telemetry, { rootProjectId, page, ...reducedFeatureFlags });
TelemetryClient.setup(telemetry, {
rootProjectId,
page,
sdkPackageVersion: botBuilderVersion,
...reducedFeatureFlags,
});

useEffect(() => {
// Update user settings when the user opens the app to ensure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ const getInitialItems = <T extends ArrayBasedStructuredResponseItem>(
const fixMultilineItems = (items: TemplateBodyItem[]) => {
return items.map((item) => {
if (item.kind === 'variation' && /\r?\n/g.test(item.value)) {
// if it's an SSML tag, remove the line breaks.
if (/^<speak/g.test(item.value.trim())) {
return {
...item,
value: item.value.replace(/[\r\n]+/g, ''),
};
}
return {
...item,
// Escape all un-escaped -
Expand Down
63 changes: 63 additions & 0 deletions Composer/packages/lib/shared/src/getBotBuilderVersion.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import axios from 'axios';

/**
* Function created to retrieve BotBuilder versions from BotFramework-Components repository containing the following example content as reference:
*
* ```js
* // Copyright (c) Microsoft Corporation.
* // Licensed under the MIT License.
*
* const dotnet = {
* name: 'dotnet',
* defaultSdkVersion: '4.18.1',
* };
*
* const js = {
* name: 'js',
* defaultSdkVersion: '4.18.0-preview',
* };
*
* module.exports = { dotnet, js };
* ```
*/
const getField = (content: string, path: string) => {
const [key, ...fields] = path.split('.');
const objectPath = fields.reduce((acc, val, i, arr) => {
const objKey = i < arr.length - 1 ? '{' : '';
return acc + `.+?(?<=${val}:${objKey})`;
}, '');
const withQuotes = `('|")(.+?)('|")(}|,)`;
const withoutQuotes = `\\w+|\\d+`;
const pattern = `${key}={${objectPath}(${withQuotes}|${withoutQuotes})`;
const oneLine = content.replace(/\r?\n|\r|\s+/g, '');
// eslint-disable-next-line security/detect-non-literal-regexp
const regex = oneLine.match(new RegExp(pattern));
if (!regex) {
return;
}
const value = regex[1].match(withQuotes) ? regex[3] : regex[1];
return value;
};

/**
* Gets BotBuilder version for DotNet and JavaScript from BotFramework-Components repository.
*/
export const getBotBuilderVersion = async () => {
const defaultValues = { dotnet: 'unknown', js: 'unknown' };
try {
const url =
'https://raw.githubusercontent.com/microsoft/botframework-components/main/generators/generator-bot-adaptive/platforms.js';
const { data } = await axios.get(url);
const version = {
dotnet: getField(data, 'dotnet.defaultSdkVersion') || defaultValues.dotnet,
js: getField(data, 'js.defaultSdkVersion') || defaultValues.js,
};
return version;
} catch (e) {
console?.error(e);
return defaultValues;
}
};
1 change: 1 addition & 0 deletions Composer/packages/lib/shared/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export * from './EditorAPI';
export * from './featureFlagUtils';
export * from './functionUtils';
export * from './generateUniqueId';
export * from './getBotBuilderVersion';
export * from './icons';
export * from './labelMap';
export * from './lgUtils';
Expand Down
2 changes: 2 additions & 0 deletions Composer/packages/server/src/models/bot/botStructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ const BotStructureTemplate = {
formDialogs: 'form-dialogs/${FORMDIALOGNAME}',
skillManifests: 'manifests/${MANIFESTFILENAME}',
botProject: '${BOTNAME}.botproj',
botCsProject: '${BOTNAME}.csproj',
recognizer: 'recognizers/${RECOGNIZERNAME}',
crossTrainConfig: 'settings/${CROSSTRAINCONFIGNAME}',
// PVA
Expand Down Expand Up @@ -81,6 +82,7 @@ export const BotStructureFilesPatterns = [
templateInterpolate(BotStructureTemplate.formDialogs, { FORMDIALOGNAME: '*.form' }),
templateInterpolate(BotStructureTemplate.skillManifests, { MANIFESTFILENAME: '*.json' }),
templateInterpolate(BotStructureTemplate.botProject, { BOTNAME: '*' }),
templateInterpolate(BotStructureTemplate.botCsProject, { BOTNAME: '*' }),
templateInterpolate(BotStructureTemplate.recognizer, { RECOGNIZERNAME: '*.dialog' }),
templateInterpolate(BotStructureTemplate.crossTrainConfig, { CROSSTRAINCONFIGNAME: 'cross-train.config.json' }),
'*.schema',
Expand Down
2 changes: 1 addition & 1 deletion Composer/packages/server/src/utility/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ export async function ejectAndMerge(currentProject: BotProject, jobId: string) {
BackgroundProcessManager.updateProcess(jobId, 202, formatMessage('Building runtime'));
await runtime.build(runtimePath, currentProject);

const manifestFile = runtime.identifyManifest(currentProject.dataDir, currentProject.name);
const manifestFile = runtime.identifyManifest(currentProject.dataDir, currentProject);

// run the merge command to merge all package dependencies from the template to the bot project
BackgroundProcessManager.updateProcess(jobId, 202, formatMessage('Merging Packages'));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export const buildInFunctionsMap: Map<string, FunctionEntity> = new Map<string,
new FunctionEntity(
['text: string', 'startIndex: number', 'length?: number'],
ReturnType.String,
'Returns characters from a string. Substring(sourceString, startPos, endPos). startPos cannot be less than 0. endPos greater than source strings length will be taken as the max length of the string.'
'Returns characters from a string. Substring(sourceString, startPos, length). startPos cannot be less than 0. A length greater than source strings length will be taken as the max length of the string.'
),
],
[
Expand Down
2 changes: 1 addition & 1 deletion Composer/packages/types/src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export type RuntimeTemplate = {

uninstallComponent: (runtimePath: string, componentName: string, project: IBotProject) => Promise<string>;

identifyManifest: (runtimePath: string, projName?: string) => string;
identifyManifest: (runtimePath: string, project: IBotProject) => string;

/** build for deploy method */
buildDeploy: (
Expand Down
Loading

0 comments on commit 259a975

Please sign in to comment.