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
4 changes: 2 additions & 2 deletions Composer/packages/lib/indexers/__tests__/luIndexer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,12 @@ hi

`;
const { intents, diagnostics }: any = parse(content);
expect(intents.length).toEqual(0);
expect(intents.length).toEqual(1);
expect(diagnostics.length).toEqual(1);
expect(diagnostics[0].range.start.line).toEqual(2);
expect(diagnostics[0].range.start.character).toEqual(0);
expect(diagnostics[0].range.end.line).toEqual(2);
expect(diagnostics[0].range.end.character).toEqual(1);
expect(diagnostics[0].range.end.character).toEqual(2);
});
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { checkProperty, getProperties } from '../../src/dialogUtils/extractMemoryPaths';

const data = [
{
$type: 'Microsoft.NumberInput',
property: 'user.a',
},
{
$type: 'Microsoft.SetProperty',
property: 'user.b',
},
{
$type: 'Microsoft.OAuthInput',
tokenProperty: 'user.c',
},
{
$type: 'Microsoft.HttpRequest',
resultProperty: 'user.d',
},
{
$type: 'Microsoft.SetProperties',
assignments: [{ property: 'user.e' }, { property: 'user.f' }],
},
];

describe('extract the properties', () => {
it('should check the property', () => {
expect(checkProperty('user.age')).toBe(true);
expect(checkProperty('user.value.age')).toBe(true);
expect(checkProperty('user. age')).toBe(false);
expect(checkProperty('conversation.id')).toBe(true);
expect(checkProperty('dialog.id')).toBe(true);
expect(checkProperty('this.value')).toBe(true);
expect(checkProperty('user.a ge')).toBe(false);
expect(checkProperty('user')).toBe(false);
expect(checkProperty('user.')).toBe(false);
expect(checkProperty('user.age ')).toBe(true);
expect(checkProperty(' user.age ')).toBe(true);
expect(checkProperty('a.b')).toBe(false);
});
it('should extract the properties', () => {
expect(getProperties(data[0])[0]).toBe('user.a');
expect(getProperties(data[1])[0]).toBe('user.b');
expect(getProperties(data[2])[0]).toBe('user.c');
expect(getProperties(data[3])[0]).toBe('user.d');
expect(getProperties(data[4]).indexOf('user.e')).toBeGreaterThan(-1);
});
});
2 changes: 2 additions & 0 deletions Composer/packages/lib/indexers/src/dialogIndexer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { ITrigger, DialogInfo, FileInfo } from './type';
import { JsonWalk, VisitorFunc } from './utils/jsonWalk';
import { getBaseName } from './utils/help';
import { Diagnostic } from './diagnostic';
import ExtractMemoryPaths from './dialogUtils/extractMemoryPaths';

// find out all lg templates given dialog
function ExtractLgTemplates(dialog): string[] {
Expand Down Expand Up @@ -176,6 +177,7 @@ function parse(id: string, content: any, schema: any) {
referredDialogs: ExtractReferredDialogs(content),
lgTemplates: ExtractLgTemplates(content),
luIntents: ExtractLuIntents(content),
userDefinedVariables: ExtractMemoryPaths(content),
luFile: getBaseName(luFile, '.lu'),
lgFile: getBaseName(lgFile, '.lg'),
triggers: ExtractTriggers(content),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

import { SDKTypes } from '@bfc/shared';
import has from 'lodash/has';

import { VisitorFunc, JsonWalk } from '../utils/jsonWalk';

//limit the scope
export function checkProperty(property: string): boolean {
const scopePatt = /(user|conversation|dialog|this).[\S]+$/;
return scopePatt.test(property.trim());
}

// find all properties from specific type
export function getProperties(value: any): string[] {
let properties: string[] = [];
switch (value.$type) {
case SDKTypes.NumberInput:
case SDKTypes.TextInput:
case SDKTypes.ConfirmInput:
case SDKTypes.ChoiceInput:
case SDKTypes.AttachmentInput:
case SDKTypes.DateTimeInput:
case SDKTypes.SetProperty:
properties = [value.property];
break;
case SDKTypes.OAuthInput:
properties = [value.tokenProperty];
break;
case SDKTypes.SetProperties:
properties = value.assignments?.map(assignment => assignment.property);
break;
case SDKTypes.HttpRequest:
properties = [value.resultProperty];
break;
}
return (
properties?.reduce((result: string[], property) => {
if (typeof property === 'string' && checkProperty(property)) result.push(property);
return result;
}, []) || []
);
}

// find out all properties from given dialog
function ExtractMemoryPaths(dialog): string[] {
let properties: string[] = [];

const visitor: VisitorFunc = (path: string, value: any): boolean => {
if (has(value, '$type')) {
properties = [...properties, ...getProperties(value)];
}
return false;
};
JsonWalk('$', dialog, visitor);

return Array.from(new Set<string>(properties));
}

export default ExtractMemoryPaths;
1 change: 1 addition & 0 deletions Composer/packages/lib/indexers/src/type.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface DialogInfo {
luIntents: string[];
referredDialogs: string[];
relativePath: string;
userDefinedVariables: string[];
triggers: ITrigger[];
}

Expand Down
32 changes: 26 additions & 6 deletions Composer/packages/server/src/services/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,37 @@ export class BotProjectService {
return BotProjectService.currentBotProject?.files.find(file => file.name === name);
}

public static staticMemoryResolver(name: string): string[] | undefined {
return [
public static staticMemoryResolver(): string[] {
const defaultProperties = [
'this.value',
'this.turnCount',
'turn.DialogEvent.value',
'intent.score',
'this.options',
'dialog.eventCounter',
'dialog.expectedProperties',
'dialog.lastEvent',
'dialog.requiredProperties',
'dialog.retries',
'dialog.lastIntent',
'dialog.lastTriggerEvent',
'turn.lastresult',
'turn.activity',
'turn.recognized',
'turn.recognized.intent',
'turn.recognized.intents.***.score',
'turn.recognized.score',
'turn.recognized.entities',
'turn.recognized.text',
'turn.unrecognizedText',
'turn.recognizedEntities',
'turn.interrupted',
'turn.dialogEvent',
'turn.repeatedIds',
'turn.activityProcessed',
];
const userDefined: string[] =
BotProjectService.currentBotProject?.dialogs.reduce((result: string[], dialog) => {
result = [...dialog.userDefinedVariables, ...result];
return result;
}, []) || [];
return [...defaultProperties, ...userDefined];
}

public static getCurrentBotProject(): BotProject | undefined {
Expand Down