Skip to content

Commit

Permalink
fix: update voiceflow dtos (PL-844)
Browse files Browse the repository at this point in the history
  • Loading branch information
DecathectZero committed Apr 3, 2024
1 parent 6ae808e commit d67e7b6
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 23 deletions.
43 changes: 40 additions & 3 deletions lib/controllers/test/interface.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { FunctionVariableType } from '@voiceflow/dtos';
import { IntentClassificationSettingsDTO, VariableDatatype } from '@voiceflow/dtos';
import { ObjectId } from 'mongodb';
import { z } from 'zod';

import { RuntimeCommandDTO } from '@/runtime/lib/Handlers/function/runtime-command/runtime-command.dto';
Expand All @@ -12,14 +13,16 @@ export const TestFunctionRequestBodyDTO = z
inputVars: z.record(
z
.object({
type: z.literal(FunctionVariableType.STRING),
// TODO: 'string' is deprecated, use 'text' instead after FE updated
type: z.literal(VariableDatatype.TEXT).or(z.literal('string')),
})
.strict()
),
outputVars: z.record(
z
.object({
type: z.literal(FunctionVariableType.STRING),
// TODO: 'string' is deprecated, use 'text' instead after FE updated
type: z.literal(VariableDatatype.TEXT).or(z.literal('string')),
})
.strict()
),
Expand All @@ -42,3 +45,37 @@ export const TestFunctionResponseDTO = z
.strict();

export type TestFunctionResponse = z.infer<typeof TestFunctionResponseDTO>;

export const TestClassificationRequestBodyDTO = z
.object({
projectID: z.string().refine((id) => ObjectId.isValid(id), {
message: 'projectID must be a valid ObjectId',
}),
versionID: z.string().refine((id) => ObjectId.isValid(id), {
message: 'versionID must be a valid ObjectId',
}),
utterance: z.string(),
intentClassificationSettings: IntentClassificationSettingsDTO,
})
.strict();

export type TestClassificationRequestBodyDTO = z.infer<typeof TestClassificationRequestBodyDTO>;

export const ClassificationDTO = z.object({
intents: z.array(
z.object({
name: z.string(),
confidence: z.number(),
})
),
});

export const TestClassificationResponseDTO = z
.object({
nlu: ClassificationDTO,
llm: ClassificationDTO,
utterance: z.string(),
})
.strict();

export type TestClassificationResponse = z.infer<typeof TestClassificationResponseDTO>;
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"@voiceflow/body-parser": "^1.21.1",
"@voiceflow/chat-types": "2.13.104",
"@voiceflow/common": "8.2.8",
"@voiceflow/dtos": "1.30.0",
"@voiceflow/dtos": "^1.49.0",
"@voiceflow/event-ingestion-service": "1.5.1",
"@voiceflow/exception": "^1.5.1",
"@voiceflow/google-types": "2.20.57",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { FunctionVariableType } from '@voiceflow/dtos';
import { VariableDatatype } from '@voiceflow/dtos';

import { ExecuteFunctionException } from './execute-function.exception';

export class FunctionInputTypeException extends ExecuteFunctionException {
constructor(
public readonly varName: string,
public readonly expectedType: FunctionVariableType,
public readonly expectedType: VariableDatatype,
public readonly actualValue: unknown
) {
super();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,16 @@
import { FunctionCompiledVariableDeclaration, FunctionVariableType } from '@voiceflow/dtos';
import { FunctionCompiledVariableDeclaration, VariableDatatype } from '@voiceflow/dtos';
import { z } from 'zod';

import { FunctionInputTypeException } from '../exceptions/function-input-type.exception';
import { FunctionRequiredVarException } from '../exceptions/function-required-var.exception';

const variableTypeValidators = new Map<FunctionVariableType, z.ZodType>([
[FunctionVariableType.STRING, z.string()],
[FunctionVariableType.NUMBER, z.number()],
[FunctionVariableType.BOOLEAN, z.boolean()],
[FunctionVariableType.OBJECT, z.record(z.any())],
[FunctionVariableType.ARRAY, z.array(z.any())],
const variableTypeValidators = new Map<VariableDatatype, z.ZodType>([
[VariableDatatype.TEXT, z.string()],
[VariableDatatype.NUMBER, z.number()],
[VariableDatatype.BOOLEAN, z.boolean()],
]);

function getZodValidator(type: FunctionVariableType) {
function getZodValidator(type: VariableDatatype) {
const validator = variableTypeValidators.get(type)!;

if (!validator) {
Expand Down
20 changes: 11 additions & 9 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -4505,21 +4505,23 @@ __metadata:
languageName: node
linkType: hard

"@voiceflow/dtos@npm:1.30.0":
version: 1.30.0
resolution: "@voiceflow/dtos@npm:1.30.0"
"@voiceflow/dtos@npm:1.33.2":
version: 1.33.2
resolution: "@voiceflow/dtos@npm:1.33.2"
peerDependencies:
zod: ^3.20.0
checksum: f1260a067a13391941029d7b4585a6816122c97f822e5a6c359e4dcb63fc8048ea7f4a073275d812386123fe77ef76021a39096e5bfde67c2047caab463c80fa
checksum: 7b47dcab653066e79671f6904fcafbce31e823ee41b7f28a3bb13bc9a74e25eba6d95de51e3d4cfbdd5c00cff38d9ead5f071844f93914cac8941edd14167f07
languageName: node
linkType: hard

"@voiceflow/dtos@npm:1.33.2":
version: 1.33.2
resolution: "@voiceflow/dtos@npm:1.33.2"
"@voiceflow/dtos@npm:^1.49.0":
version: 1.51.0
resolution: "@voiceflow/dtos@npm:1.51.0"
dependencies:
"@voiceflow/internal": 3.2.3
peerDependencies:
zod: ^3.20.0
checksum: 7b47dcab653066e79671f6904fcafbce31e823ee41b7f28a3bb13bc9a74e25eba6d95de51e3d4cfbdd5c00cff38d9ead5f071844f93914cac8941edd14167f07
checksum: cabad47bf83ae5dc48bdd61ddae9381c55b331bd29f68f8133c82c5aa920d91eb8a82d02c47b542b25c9aeebb57bf39dbc753d06aa5a5620328e73534bc301df
languageName: node
linkType: hard

Expand Down Expand Up @@ -4640,7 +4642,7 @@ __metadata:
"@voiceflow/chat-types": 2.13.104
"@voiceflow/commitlint-config": 2.0.0
"@voiceflow/common": 8.2.8
"@voiceflow/dtos": 1.30.0
"@voiceflow/dtos": ^1.49.0
"@voiceflow/eslint-config": 6.1.0
"@voiceflow/event-ingestion-service": 1.5.1
"@voiceflow/exception": ^1.5.1
Expand Down

0 comments on commit d67e7b6

Please sign in to comment.