mirror of
https://github.com/leon-ai/leon.git
synced 2024-12-25 09:44:22 +03:00
feat(server): add JSON models with TypeBox
Later, we will be able to validate JSON files thanks to AJV.
This commit is contained in:
parent
5acd22a885
commit
2a7b2f45d6
8241
package-lock.json
generated
8241
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -75,6 +75,7 @@
|
||||
"@nlpjs/lang-all": "^4.22.12",
|
||||
"@nlpjs/nlp": "^4.22.17",
|
||||
"archiver": "^5.3.1",
|
||||
"@sinclair/typebox": "0.24.49",
|
||||
"async": "^3.2.0",
|
||||
"axios": "1.1.2",
|
||||
"cross-env": "^7.0.3",
|
||||
|
12
server/src/models/domain.ts
Normal file
12
server/src/models/domain.ts
Normal file
@ -0,0 +1,12 @@
|
||||
import type { Static } from '@sinclair/typebox'
|
||||
import { Type } from '@sinclair/typebox'
|
||||
|
||||
export const domainSchema = {
|
||||
name: Type.String({ minLength: 1 })
|
||||
}
|
||||
|
||||
export const domainSchemaObject = Type.Strict(
|
||||
Type.Object(domainSchema, { additionalProperties: false })
|
||||
)
|
||||
|
||||
export type Domain = Static<typeof domainSchemaObject>
|
18
server/src/models/global-entities.ts
Normal file
18
server/src/models/global-entities.ts
Normal file
@ -0,0 +1,18 @@
|
||||
import type { Static } from '@sinclair/typebox'
|
||||
import { Type } from '@sinclair/typebox'
|
||||
|
||||
export const globalEntity = {
|
||||
options: Type.Record(
|
||||
Type.String(),
|
||||
Type.Object({
|
||||
synonyms: Type.Array(Type.String()),
|
||||
data: Type.Record(Type.String(), Type.Array(Type.String()))
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
export const globalEntitySchemaObject = Type.Strict(
|
||||
Type.Object(globalEntity, { additionalProperties: false })
|
||||
)
|
||||
|
||||
export type GlobalEntity = Static<typeof globalEntitySchemaObject>
|
19
server/src/models/global-resolvers.ts
Normal file
19
server/src/models/global-resolvers.ts
Normal file
@ -0,0 +1,19 @@
|
||||
import type { Static } from '@sinclair/typebox'
|
||||
import { Type } from '@sinclair/typebox'
|
||||
|
||||
export const globalResolver = {
|
||||
name: Type.String(),
|
||||
intents: Type.Record(
|
||||
Type.String(),
|
||||
Type.Object({
|
||||
utterance_samples: Type.Array(Type.String()),
|
||||
value: Type.Unknown()
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
export const globalResolverSchemaObject = Type.Strict(
|
||||
Type.Object(globalResolver, { additionalProperties: false })
|
||||
)
|
||||
|
||||
export type GlobalResolver = Static<typeof globalResolverSchemaObject>
|
68
server/src/models/skill-config.ts
Normal file
68
server/src/models/skill-config.ts
Normal file
@ -0,0 +1,68 @@
|
||||
import type { Static } from '@sinclair/typebox'
|
||||
import { Type } from '@sinclair/typebox'
|
||||
|
||||
export const skillActionTypes = [Type.Literal('logic'), Type.Literal('dialog')]
|
||||
|
||||
export const skillDataTypes = [
|
||||
Type.Literal('skill_resolver'),
|
||||
Type.Literal('global_resolver'),
|
||||
Type.Literal('entity')
|
||||
]
|
||||
|
||||
export const skillConfigSchema = {
|
||||
variables: Type.Optional(Type.Record(Type.String(), Type.String())),
|
||||
actions: Type.Record(
|
||||
Type.String(),
|
||||
Type.Object({
|
||||
type: Type.Union(skillActionTypes),
|
||||
loop: Type.Optional(
|
||||
Type.Object({
|
||||
expected_item: Type.Object({
|
||||
type: Type.Union(skillDataTypes),
|
||||
name: Type.String()
|
||||
})
|
||||
})
|
||||
),
|
||||
utterance_samples: Type.Optional(Type.Array(Type.String())),
|
||||
answers: Type.Optional(Type.Array(Type.String())),
|
||||
unknown_answers: Type.Optional(Type.Array(Type.String())),
|
||||
suggestions: Type.Optional(Type.Array(Type.String())),
|
||||
slots: Type.Optional(
|
||||
Type.Array(
|
||||
Type.Object({
|
||||
name: Type.String(),
|
||||
item: Type.Object({
|
||||
type: Type.Union(skillDataTypes),
|
||||
name: Type.String()
|
||||
}),
|
||||
questions: Type.Array(Type.String()),
|
||||
suggestions: Type.Optional(Type.Array(Type.String()))
|
||||
})
|
||||
)
|
||||
),
|
||||
entities: Type.Optional(
|
||||
Type.Array(
|
||||
Type.Object({
|
||||
type: Type.Literal('enum'),
|
||||
name: Type.String(),
|
||||
options: Type.Record(
|
||||
Type.String(),
|
||||
Type.Object({
|
||||
synonyms: Type.Array(Type.String())
|
||||
})
|
||||
)
|
||||
})
|
||||
)
|
||||
),
|
||||
next_action: Type.Optional(Type.String())
|
||||
})
|
||||
),
|
||||
answers: Type.Optional(Type.Record(Type.String(), Type.Array(Type.String()))),
|
||||
entities: Type.Optional(Type.Record(Type.String(), Type.String()))
|
||||
}
|
||||
|
||||
export const skillConfigSchemaObject = Type.Strict(
|
||||
Type.Object(skillConfigSchema, { additionalProperties: false })
|
||||
)
|
||||
|
||||
export type SkillConfig = Static<typeof skillConfigSchemaObject>
|
23
server/src/models/skill.ts
Normal file
23
server/src/models/skill.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import type { Static } from '@sinclair/typebox'
|
||||
import { Type } from '@sinclair/typebox'
|
||||
|
||||
export const skillBridges = [Type.Literal('python')]
|
||||
|
||||
export const skillSchema = {
|
||||
name: Type.String({ minLength: 1 }),
|
||||
bridge: Type.Union(skillBridges),
|
||||
version: Type.String({ minLength: 1 }),
|
||||
description: Type.String({ minLength: 1 }),
|
||||
author: Type.Object({
|
||||
name: Type.String({ minLength: 1 }),
|
||||
email: Type.String({ minLength: 1, maxLength: 254, format: 'email' }),
|
||||
url: Type.String({ minLength: 1, maxLength: 255, format: 'uri' })
|
||||
})
|
||||
}
|
||||
|
||||
export const skillSchemaObject = Type.Strict(
|
||||
Type.Object(skillSchema, { additionalProperties: false })
|
||||
)
|
||||
|
||||
export type SkillBridge = Static<typeof skillSchema.bridge>
|
||||
export type Skill = Static<typeof skillSchemaObject>
|
Loading…
Reference in New Issue
Block a user