Skip to content

Commit

Permalink
updates zod version in botbuilder-core
Browse files Browse the repository at this point in the history
  • Loading branch information
JhontSouth committed Nov 6, 2023
1 parent 663bc95 commit bab8c73
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 21 deletions.
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.0.0"
},
"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.0.0",
"@azure/core-http": "^3.0.2"
},
"scripts": {
Expand Down
2 changes: 1 addition & 1 deletion libraries/botbuilder-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"botframework-connector": "4.1.6",
"botframework-schema": "4.1.6",
"uuid": "^8.3.2",
"zod": "~1.11.17"
"zod": "^3.0.0"
},
"devDependencies": {
"@microsoft/bf-chatdown": "^4.15.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ export class ConfigurationBotFrameworkAuthentication extends BotFrameworkAuthent
);
} catch (err) {
// Throw a new error with the validation details prominently featured.
if (z.instanceof(z.ZodError).check(err)) {
if (z.instanceof(z.ZodError).safeParse(err).success) {
throw new Error(JSON.stringify(err.errors, null, 2));
}
throw err;
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -14177,6 +14177,11 @@ z-schema@~3.18.3:
optionalDependencies:
commander "^2.7.1"

zod@^3.0.0:
version "3.22.4"
resolved "https://registry.yarnpkg.com/zod/-/zod-3.22.4.tgz#f31c3a9386f61b1f228af56faa9255e845cf3fff"
integrity sha512-iC+8Io04lddc+mVqQ9AZ7OQ2MrUKGN+oIQyq1vemgt46jwCwLfhq7/pwnBnNXXXZb8VTVLKwp9EDkx+ryxIWmg==

zod@~1.11.17:
version "1.11.17"
resolved "https://registry.yarnpkg.com/zod/-/zod-1.11.17.tgz#2aae9e91fc66128116ae9844e8f416a95f453f8e"
Expand Down

0 comments on commit bab8c73

Please sign in to comment.