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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
schemasState,
currentProjectIdState,
botDiagnosticsState,
jsonSchemaFilesState,
botProjectIdsState,
formDialogSchemaIdsState,
} from '../../../src/recoilModel';
Expand Down Expand Up @@ -80,6 +81,12 @@ const state = {
],
},
],
jsonSchemaFiles: [
{
id: 'schema1.json',
content: 'test',
},
],
diagnostics: [
{
message: 'server error',
Expand All @@ -105,6 +112,7 @@ const initRecoilState = ({ set }) => {
set(dialogsState(state.projectId), state.dialogs);
set(luFilesState(state.projectId), state.luFiles);
set(lgFilesState(state.projectId), state.lgFiles);
set(jsonSchemaFilesState(state.projectId), state.jsonSchemaFiles);
set(botDiagnosticsState(state.projectId), state.diagnostics);
set(settingsState(state.projectId), state.settings);
set(schemasState(state.projectId), mockProjectResponse.schemas);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
botProjectFileState,
dialogSchemasState,
formDialogSchemasSelectorFamily,
jsonSchemaFilesState,
lgFilesState,
luFilesState,
qnaFilesState,
Expand Down Expand Up @@ -43,6 +44,7 @@ export default function useNotifications(projectId: string, filter?: string) {
const qnaFiles = useRecoilValue(qnaFilesState(projectId));
const formDialogSchemas = useRecoilValue(formDialogSchemasSelectorFamily(projectId));
const botProjectFile = useRecoilValue(botProjectFileState(projectId));
const jsonSchemaFiles = useRecoilValue(jsonSchemaFilesState(projectId));

const botAssets: BotAssets = {
projectId,
Expand All @@ -55,6 +57,7 @@ export default function useNotifications(projectId: string, filter?: string) {
dialogSchemas,
formDialogSchemas,
botProjectFile,
jsonSchemaFiles,
};

const memoized = useMemo(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
settingsState,
filePersistenceState,
botProjectFileState,
jsonSchemaFilesState,
} from './atoms';
import { botsForFilePersistenceSelector, formDialogSchemasSelectorFamily } from './selectors';

Expand All @@ -37,6 +38,7 @@ const getBotAssets = async (projectId, snapshot: Snapshot): Promise<BotAssets> =
snapshot.getPromise(dialogSchemasState(projectId)),
snapshot.getPromise(botProjectFileState(projectId)),
snapshot.getPromise(formDialogSchemasSelectorFamily(projectId)),
snapshot.getPromise(jsonSchemaFilesState(projectId)),
]);
return {
projectId,
Expand All @@ -49,6 +51,7 @@ const getBotAssets = async (projectId, snapshot: Snapshot): Promise<BotAssets> =
dialogSchemas: result[6],
botProjectFile: result[7],
formDialogSchemas: result[8],
jsonSchemaFiles: result[9],
};
};

Expand Down
6 changes: 6 additions & 0 deletions Composer/packages/client/src/recoilModel/atoms/botState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
DialogSchemaFile,
DialogSetting,
FormDialogSchema,
JsonSchemaFile,
LgFile,
LuFile,
QnAFile,
Expand Down Expand Up @@ -274,6 +275,11 @@ export const qnaFilesState = atomFamily<QnAFile[], string>({
default: [],
});

export const jsonSchemaFilesState = atomFamily<JsonSchemaFile[], string>({
key: getFullyQualifiedKey('jsonSchemaFiles'),
default: [],
});

export const filePersistenceState = atomFamily<FilePersistence, string>({
key: getFullyQualifiedKey('filePersistence'),
default: {} as FilePersistence,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
filePersistenceState,
formDialogSchemaIdsState,
formDialogSchemaState,
jsonSchemaFilesState,
lgFilesState,
localeState,
locationState,
Expand Down Expand Up @@ -266,10 +267,11 @@ export const initBotState = async (callbackHelpers: CallbackInterface, data: any
const {
dialogs,
dialogSchemas,
formDialogSchemas,
luFiles,
lgFiles,
qnaFiles,
jsonSchemaFiles,
formDialogSchemas,
skillManifestFiles,
skills,
mergedSettings,
Expand Down Expand Up @@ -309,6 +311,7 @@ export const initBotState = async (callbackHelpers: CallbackInterface, data: any
set(skillManifestsState(projectId), skillManifestFiles);
set(luFilesState(projectId), initLuFilesStatus(botName, luFiles, dialogs));
set(lgFilesState(projectId), lgFiles);
set(jsonSchemaFilesState(projectId), jsonSchemaFiles);
set(dialogsState(projectId), verifiedDialogs);
set(dialogSchemasState(projectId), dialogSchemas);
set(botEnvironmentState(projectId), botEnvironment);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { jsonSchemaFileIndexer } from '../src/jsonSchemaFileIndexer';
import { FileInfo } from '../src/type';
import { getBaseName } from '../src/utils/help';

const { index } = jsonSchemaFileIndexer;

describe('jsonSchemaFileIndexer', () => {
describe('index', () => {
it('should return json schema files', () => {
const input: FileInfo[] = [
{
name: 'test1.json',
relativePath: './test1.json',
content: '{ "$schema":"http://json-schema.org/draft/schema" }',
path: '/',
},
{
name: 'test2.json',
relativePath: './test2.json',
content: '{ "$schema":"http://json-schema.org/draft-07/schema" }',
path: '/',
},
{
name: 'test3.json',
relativePath: './test3.json',
content: '{ "$schema":"http://json-schema.org/draft-07/schemav2" }',
path: '/',
},
];

const expected = input.map((item) => {
return {
name: getBaseName(item.name),
content: JSON.parse(item.content),
};
});

const actual = index(input);

expect(actual).toHaveLength(expected.length);

for (let i = 0; i < actual.length; i++) {
expect(actual[i].id).toEqual(expected[i].name);
expect(actual[i].content.$schema).toEqual(expected[i].content.$schema);
}
});

it('should not return other json files', () => {
const input: FileInfo[] = [
{
name: 'test1',
relativePath: './test1.json',
content: '{ "$schema":"http://microsoft.org/wsp" }',
path: '/',
},
{
name: 'test2',
relativePath: './test2.json',
content: '{ "$schema":"http://json-schema.org/draft-07/schema" }',
path: '/',
},
{
name: 'test3',
relativePath: './test3.json',
content: '{ "$schema":"http://microsoft.org/wsp" }',
path: '/',
},
];

const expected = [
{
name: 'test2',
content: JSON.parse(input[1].content),
},
];

const actual = index(input);

expect(actual).toHaveLength(expected.length);

for (let i = 0; i < actual.length; i++) {
expect(actual[i].id).toEqual(expected[i].name);
expect(actual[i].content.$schema).toEqual(expected[i].content.$schema);
}
});
});
});
1 change: 1 addition & 0 deletions Composer/packages/lib/indexers/src/dialogIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ function extractTriggers(dialog): ITrigger[] {
displayName: '',
type: rule.$kind,
isIntent: rule.$kind === SDKKinds.OnIntent,
content: rule,
};
if (has(rule, '$designer.name')) {
trigger.displayName = rule.$designer.name;
Expand Down
2 changes: 2 additions & 0 deletions Composer/packages/lib/indexers/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { DialogSetting, FileInfo, importResolverGenerator } from '@bfc/shared';

import { dialogIndexer } from './dialogIndexer';
import { dialogSchemaIndexer } from './dialogSchemaIndexer';
import { jsonSchemaFileIndexer } from './jsonSchemaFileIndexer';
import { lgIndexer } from './lgIndexer';
import { luIndexer } from './luIndexer';
import { qnaIndexer } from './qnaIndexer';
Expand Down Expand Up @@ -60,6 +61,7 @@ class Indexer {
skillManifestFiles: skillManifestIndexer.index(result[FileExtensions.Manifest]),
skills: skillIndexer.index(skillContent, settings.skill),
botProjectSpaceFiles: botProjectSpaceIndexer.index(result[FileExtensions.BotProjectSpace]),
jsonSchemaFiles: jsonSchemaFileIndexer.index(result[FileExtensions.Json]),
formDialogSchemas: formDialogSchemaIndexer.index(result[FileExtensions.FormDialog]),
};
}
Expand Down
30 changes: 30 additions & 0 deletions Composer/packages/lib/indexers/src/jsonSchemaFileIndexer.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { FileInfo, JsonSchemaFile } from '@bfc/shared';
import has from 'lodash/has';

import { getBaseName } from './utils/help';

const index = (jsonFiles: FileInfo[]) => {
return jsonFiles.reduce((jsonSchemaFiles: JsonSchemaFile[], { content, name }) => {
try {
const jsonContent = JSON.parse(content);

if (has(jsonContent, '$schema')) {
const schema = jsonContent.$schema.toLowerCase().trim();
if (schema.startsWith('http://json-schema.org')) {
return [...jsonSchemaFiles, { content: jsonContent, id: getBaseName(name) }];
}
}

return jsonSchemaFiles;
} catch (error) {
return jsonSchemaFiles;
}
}, [] as JsonSchemaFile[]);
};

export const jsonSchemaFileIndexer = {
index,
};
11 changes: 10 additions & 1 deletion Composer/packages/lib/indexers/src/skillManifestIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,23 @@
// Licensed under the MIT License.

import { FileInfo, SkillManifestInfo } from '@bfc/shared';
import has from 'lodash/has';

import { getBaseName } from './utils/help';

const index = (skillManifestFiles: FileInfo[]) => {
return skillManifestFiles.reduce((manifests: SkillManifestInfo[], { content, name, lastModified }) => {
try {
const jsonContent = JSON.parse(content);
return [...manifests, { content: jsonContent, id: getBaseName(name, '.json'), lastModified }];

if (has(jsonContent, '$schema')) {
const schema = jsonContent.$schema.toLowerCase().trim();
if (schema.startsWith('https://schemas.botframework.com/schemas/skills')) {
return [...manifests, { content: jsonContent, id: getBaseName(name, '.json'), lastModified }];
}
}

return manifests;
} catch (error) {
return manifests;
}
Expand Down
1 change: 1 addition & 0 deletions Composer/packages/lib/indexers/src/utils/fileExtensions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ export enum FileExtensions {
lg = '.lg',
Manifest = '.json',
BotProjectSpace = '.botproj',
Json = '.json',
}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ beforeEach(async () => {
describe('init', () => {
it('should get project successfully', () => {
const project: { [key: string]: any } = proj.getProject();
expect(project.files.length).toBe(15);
expect(project.files.length).toBe(16);
});

it('should always have a default bot project file', () => {
Expand Down Expand Up @@ -123,7 +123,7 @@ describe('copyTo', () => {
const newBotProject = await proj.copyTo(locationRef);
await newBotProject.init();
const project: { [key: string]: any } = newBotProject.getProject();
expect(project.files.length).toBe(15);
expect(project.files.length).toBe(16);
});
});

Expand Down Expand Up @@ -400,7 +400,7 @@ describe('deleteAllFiles', () => {
const newBotProject = await proj.copyTo(locationRef);
await newBotProject.init();
const project: { [key: string]: any } = newBotProject.getProject();
expect(project.files.length).toBe(15);
expect(project.files.length).toBe(16);
await newBotProject.deleteAllFiles();
expect(fs.existsSync(copyDir)).toBe(false);
});
Expand Down
2 changes: 1 addition & 1 deletion Composer/packages/server/src/models/bot/botProject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ export class BotProject implements IBotProject {
'**/*.lg',
'**/*.lu',
'**/*.qna',
'manifests/*.json',
'**/*.json',
'sdk.override.schema',
'sdk.override.uischema',
'sdk.schema',
Expand Down
8 changes: 8 additions & 0 deletions Composer/packages/types/src/indexers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export enum FileExtensions {
Setting = 'appsettings.json',
FormDialogSchema = '.form-dialog',
BotProject = '.botproj',
Json = '.json',
}

export type FileInfo = {
Expand All @@ -32,6 +33,7 @@ export type ITrigger = {
displayName: string;
type: string;
isIntent: boolean;
content: any;
};

export type ReferredLuIntents = {
Expand Down Expand Up @@ -168,6 +170,11 @@ export type Skill = {
name: string;
};

export type JsonSchemaFile = {
id: string;
content: string;
};

export type TextFile = {
id: string;
content: string;
Expand Down Expand Up @@ -200,6 +207,7 @@ export type BotAssets = {
dialogSchemas: DialogSchemaFile[];
formDialogSchemas: FormDialogSchema[];
botProjectFile: BotProjectFile;
jsonSchemaFiles: JsonSchemaFile[];
};

export type BotInfo = {
Expand Down