Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [#4545] Zod package - botbuilder-core #4562

Merged
merged 6 commits into from
Nov 9, 2023
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
41 changes: 19 additions & 22 deletions libraries/adaptive-expressions/etc/adaptive-expressions.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export class BoolExpression extends ExpressionProperty<boolean> {

// @public
export class BoolExpressionConverter {
// Warning: (ae-forgotten-export) The symbol "Input" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "Input_2" needs to be exported by the entry point index.d.ts
convert(value: Input_2 | BoolExpression): BoolExpression;
}

Expand Down Expand Up @@ -330,7 +330,7 @@ export class Clause extends Expression {
// @public
export class CommonRegex {
static CreateRegex(pattern: string): RegExp;
}
}

// @public (undocumented)
export class CommonRegexLexer extends Lexer {
Expand Down Expand Up @@ -1010,15 +1010,15 @@ export interface CommonRegexVisitor<Result> extends ParseTreeVisitor<Result> {
// @public
export class ComparisonEvaluator extends ExpressionEvaluator {
constructor(type: string, func: (arg0: any[]) => boolean, validator: ValidateExpressionDelegate, verify?: VerifyExpression);
}
}

// @public
export class Constant extends Expression {
constructor(value: any);
deepEquals(other: Expression): boolean;
toString(): string;
value: any;
}
}

// @public
export function convertCSharpDateTimeToDayjs(fmtString: string): string;
Expand Down Expand Up @@ -1099,9 +1099,9 @@ export class EnumExpression<T> extends ExpressionProperty<T> {
// @public
export class EnumExpressionConverter<T> {
constructor(enumValue: unknown);
// Warning: (ae-forgotten-export) The symbol "Input" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "Input_3" needs to be exported by the entry point index.d.ts
convert(value: Input_3<T> | EnumExpression<T>): EnumExpression<T>;
}
}

// @public
export type EvaluateExpressionDelegate = (expression: Expression, state: MemoryInterface, options: Options) => ValueWithError;
Expand Down Expand Up @@ -1518,7 +1518,7 @@ export class ExpressionEvaluator {
tryEvaluate: (expression: Expression, state: MemoryInterface, options: Options) => ValueWithError;
type: string;
validateExpression: (expression: Expression) => void;
}
}

// @public
export class ExpressionFunctions {
Expand Down Expand Up @@ -2054,7 +2054,7 @@ export class IntExpression extends ExpressionProperty<number> {

// @public
export class IntExpressionConverter {
// Warning: (ae-forgotten-export) The symbol "Input" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "Input_4" needs to be exported by the entry point index.d.ts
convert(value: Input_4 | IntExpression): IntExpression;
}

Expand Down Expand Up @@ -2677,7 +2677,7 @@ export interface MemoryInterface {
// @public
export class MultivariateNumericEvaluator extends ExpressionEvaluator {
constructor(type: string, func: (args: any[]) => number, verify?: VerifyExpression);
}
}

// @public (undocumented)
export class NameContext extends ParserRuleContext {
Expand Down Expand Up @@ -2707,8 +2707,7 @@ class Node_2 {
toString(builder?: string[], indent?: number): string;
tree: TriggerTree;
readonly triggers: Trigger[];
}

}
export { Node_2 as Node }

// @public (undocumented)
Expand Down Expand Up @@ -2789,14 +2788,14 @@ export class NumberExpression extends ExpressionProperty<number> {

// @public
export class NumberExpressionConverter {
// Warning: (ae-forgotten-export) The symbol "Input" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "Input_5" needs to be exported by the entry point index.d.ts
convert(value: Input_5 | NumberExpression): NumberExpression;
}

// @public
export class NumberTransformEvaluator extends ExpressionEvaluator {
constructor(type: string, func: (args: any[]) => number);
}
}

// @public (undocumented)
export class NumericAtomContext extends PrimaryExpressionContext {
Expand All @@ -2814,7 +2813,7 @@ export class NumericAtomContext extends PrimaryExpressionContext {
// @public
export class NumericEvaluator extends ExpressionEvaluator {
constructor(type: string, func: (args: any[]) => any);
}
}

// @public
export class ObjectExpression<T> extends ExpressionProperty<T> {
Expand All @@ -2823,7 +2822,7 @@ export class ObjectExpression<T> extends ExpressionProperty<T> {

// @public
export class ObjectExpressionConverter<T extends object = {}> {
// Warning: (ae-forgotten-export) The symbol "Input" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "Input_6" needs to be exported by the entry point index.d.ts
convert(value: Input_6<T> | ObjectExpression<T>): ObjectExpression<T>;
}

Expand Down Expand Up @@ -3102,7 +3101,6 @@ enum ReturnType_2 {
Object = 4,
String = 8
}

export { ReturnType_2 as ReturnType }

// @public (undocumented)
Expand Down Expand Up @@ -3240,7 +3238,7 @@ export class StringExpression extends ExpressionProperty<string> {

// @public
export class StringExpressionConverter {
// Warning: (ae-forgotten-export) The symbol "Input" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "Input_7" needs to be exported by the entry point index.d.ts
convert(value: Input_7 | StringExpression): StringExpression;
}

Expand Down Expand Up @@ -3311,14 +3309,14 @@ export class TextContentContext extends ParserRuleContext {
// @public
export class TimeTransformEvaluator extends ExpressionEvaluator {
constructor(type: string, func: (timestamp: Date, numOfTransformation: number) => Date);
}
}

// @public
export class TimeZoneConverter {
static ianaToWindows(ianaTimeZoneId: string): string;
static verifyTimeZoneStr(timezoneStr: string): boolean;
static windowsToIana(windowsTimeZoneId: string): string;
}
}

// @public
export class Trigger {
Expand All @@ -3329,7 +3327,7 @@ export class Trigger {
readonly originalExpression: Expression;
relationship(other: Trigger, comparers: PredicateComparers): RelationshipType;
toString(builder?: string[], indent?: number): string;
}
}

// @public
export class TriggerTree {
Expand All @@ -3345,7 +3343,7 @@ export class TriggerTree {
totalTriggers: number;
treeToString(indent?: number): string;
verifyTree(): Node_2;
}
}

// @public (undocumented)
export class TripleOpExpContext extends ExpressionContext {
Expand Down Expand Up @@ -3413,7 +3411,6 @@ export type ValueWithError = {
// @public
export type VerifyExpression = (value: any, expression: Expression, child: number) => string | undefined;


// (No @packageDocumentation comment for this package)

```
17 changes: 8 additions & 9 deletions libraries/botbuilder-ai/etc/botbuilder-ai.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ export interface AnswerSpanResponse {
text: string;
}

// Warning: (ae-forgotten-export) The symbol "QnAMakerClient" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "QnAMakerTelemetryClient" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "QnAMakerClient_2" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "QnAMakerTelemetryClient_2" needs to be exported by the entry point index.d.ts
//
// @public
export class CustomQuestionAnswering implements QnAMakerClient_2, QnAMakerTelemetryClient_2 {
Expand Down Expand Up @@ -94,7 +94,7 @@ export class CustomQuestionAnswering implements QnAMakerClient_2, QnAMakerTeleme
[key: string]: number;
}): Promise<void>;
get telemetryClient(): BotTelemetryClient;
}
}

// @public
export interface DateTimeSpec {
Expand Down Expand Up @@ -228,7 +228,7 @@ export class LuisAdaptiveRecognizer extends Recognizer implements LuisAdaptiveRe
// (undocumented)
static $kind: string;
applicationId: StringExpression;
// Warning: (ae-forgotten-export) The symbol "DynamicList" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "DynamicList_2" needs to be exported by the entry point index.d.ts
dynamicLists: ArrayExpression<DynamicList_2>;
endpoint: StringExpression;
endpointKey: StringExpression;
Expand Down Expand Up @@ -287,7 +287,7 @@ export class LuisBotComponent extends BotComponent {
export class LuisComponentRegistration extends ComponentRegistration {
constructor();
getDeclarativeTypes(_resourceExplorer: unknown): ComponentDeclarativeTypes[];
}
}

// @public
export interface LuisPredictionOptions extends msRest.RequestOptionsBase {
Expand Down Expand Up @@ -327,7 +327,7 @@ export class LuisRecognizer implements LuisRecognizerTelemetryClient {
}>;
get telemetryClient(): BotTelemetryClient;
static topIntent(results?: RecognizerResult, defaultIntent?: string, minScore?: number): string;
}
}

// @public (undocumented)
export interface LuisRecognizerOptions {
Expand Down Expand Up @@ -467,7 +467,7 @@ export class QnAMaker implements QnAMakerClient, QnAMakerTelemetryClient {
[key: string]: number;
}): Promise<void>;
get telemetryClient(): BotTelemetryClient;
}
}

// @public (undocumented)
export const QNAMAKER_TRACE_LABEL = "QnAMaker Trace";
Expand Down Expand Up @@ -499,7 +499,7 @@ export const QnAMakerClientKey: unique symbol;
export class QnAMakerComponentRegistration extends ComponentRegistration {
constructor();
getDeclarativeTypes(_resourceExplorer: unknown): ComponentDeclarativeTypes[];
}
}

// Warning: (ae-forgotten-export) The symbol "QnAMakerDialogConfiguration" needs to be exported by the entry point index.d.ts
//
Expand Down Expand Up @@ -742,7 +742,6 @@ export function validateExternalEntity(entity: ExternalEntity): void;
// @public
export function validateListElement(element: ListElement): void;


// (No @packageDocumentation comment for this package)

```
2 changes: 1 addition & 1 deletion libraries/botbuilder-ai/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"lodash": "^4.17.21",
"node-fetch": "^2.6.7",
"url-parse": "^1.5.9",
"zod": "~1.11.17"
"zod": "^3.22.4"
},
"resolutions": {
"follow-redirects": "1.14.7"
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder-ai/src/luisRecognizer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export interface LuisRecognizerOptionsV2 extends LuisRecognizerOptions {
// This is just meant to operate as a simple type assertion.
const UnsafeLuisRecognizerUnion = z.custom<LuisRecognizerOptionsV3 | LuisRecognizerOptionsV2 | LuisPredictionOptions>(
(val: unknown): val is LuisRecognizerOptionsV3 | LuisRecognizerOptionsV2 | LuisPredictionOptions =>
z.record(z.unknown()).check(val),
z.record(z.unknown()).safeParse(val).success,
{
message: 'LuisRecognizerOptionsV3 | LuisRecognizerOptionsV2 | LuisPredictionOptions',
}
Expand Down
15 changes: 7 additions & 8 deletions libraries/botbuilder-ai/src/luisRecognizerOptionsV3.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,13 @@ export class LuisRecognizerV3 extends LuisRecognizerInternal {
const values: unknown[] = Array.isArray(value) ? value : [];
if (instances?.length === values?.length) {
instances.forEach((childInstance) => {
if (
z
.object({ startIndex: z.number(), endIndex: z.number() })
.nonstrict()
.check(childInstance)
) {
const start = childInstance.startIndex;
const end = childInstance.endIndex;
const childInstanceParsed = z
.object({ startIndex: z.number(), endIndex: z.number() })
.nonstrict()
.safeParse(childInstance);
if (childInstanceParsed.success) {
const start = childInstanceParsed.data.startIndex;
const end = childInstanceParsed.data.endIndex;
externalEntities.push({
entityName: key,
startIndex: start,
Expand Down
12 changes: 8 additions & 4 deletions libraries/botbuilder-ai/src/qnaMakerDialog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -448,17 +448,21 @@ export class QnAMakerDialog extends WaterfallDialog implements QnAMakerDialogCon
if (top) {
this.top = new IntExpression(top);
}

if (qnaSuggestionsActivityFactory.check(activeLearningTitleOrFactory)) {
const qnaSuggestionsActivityFactoryParsed = qnaSuggestionsActivityFactory.safeParse(
activeLearningTitleOrFactory
);
if (qnaSuggestionsActivityFactoryParsed.success) {
if (!cardNoMatchText) {
// Without a developer-provided cardNoMatchText, the end user will not be able to tell the convey to the bot and QnA Maker that the suggested alternative questions were not correct.
// When the user's reply to a suggested alternatives Activity matches the cardNoMatchText, the QnAMakerDialog sends this information to the QnA Maker service for active learning.
throw new Error('cardNoMatchText is required when using the suggestionsActivityFactory.');
}

this.suggestionsActivityFactory = activeLearningTitleOrFactory;
this.suggestionsActivityFactory = qnaSuggestionsActivityFactoryParsed.data;
} else {
this.activeLearningCardTitle = new StringExpression(activeLearningTitleOrFactory ?? this.defaultCardTitle);
this.activeLearningCardTitle = new StringExpression(
activeLearningTitleOrFactory?.toString() ?? this.defaultCardTitle
);
}

if (cardNoMatchText) {
Expand Down
9 changes: 5 additions & 4 deletions libraries/botbuilder-ai/tests/qnaMakerDialog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -504,8 +504,9 @@ describe('QnAMakerDialog', function () {
await rejects(
adapter.send('QnaMaker_TopNAnswer.json').startTest(),
(thrown) =>
thrown.message.includes('invalid_type at message') &&
thrown.message.includes('Expected object, received number')
thrown.message.includes('invalid_type') &&
thrown.message.includes('"expected": "object"') &&
thrown.message.includes('"received": "number"')
);
});

Expand Down Expand Up @@ -544,7 +545,7 @@ describe('QnAMakerDialog', function () {

await rejects(
adapter.send('QnaMaker_TopNAnswer.json').startTest(),
(thrown) => thrown.message.includes('invalid_type at message') && thrown.message.includes('Required')
(thrown) => thrown.message.includes('invalid_type') && thrown.message.includes('Required')
);

sandbox.verify();
Expand Down Expand Up @@ -586,7 +587,7 @@ describe('QnAMakerDialog', function () {

await rejects(
adapter.send('QnaMaker_TopNAnswer.json').startTest(),
(thrown) => thrown.message.includes('invalid_type at message') && thrown.message.includes('Required')
(thrown) => thrown.message.includes('invalid_type') && thrown.message.includes('Required')
);

sandbox.verify();
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder-azure-blobs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"botbuilder-stdlib": "4.1.6",
"get-stream": "^6.0.0",
"p-map": "^4.0.0",
"zod": "~1.11.17",
"zod": "^3.22.4",
"@azure/core-http": "^3.0.2"
},
"scripts": {
Expand Down
Loading
Loading