1
1
mirror of https://github.com/leon-ai/leon.git synced 2025-01-03 06:06:06 +03:00

refactor: domain, skill-config and skill in skills/schemas.ts

This commit is contained in:
Divlo 2022-11-01 21:51:19 +01:00
parent 6c292994fd
commit 71e0f1933c
No known key found for this signature in database
GPG Key ID: 8F9478F220CE65E9
5 changed files with 91 additions and 107 deletions

View File

@ -2,10 +2,8 @@ import fs from 'node:fs'
import path from 'node:path'
import type { ShortLanguageCode } from '@/helpers/lang-helper'
import type { Domain } from '@/models/domain'
import type { GlobalEntity } from '@@/core/data/schemas'
import type { SkillConfig } from '@/models/skill-config'
import type { Skill, SkillBridge } from '@/models/skill'
import type { Domain, Skill, SkillConfig, SkillBridge } from '@@/skills/schemas'
interface SkillDomain {
name: string

View File

@ -1,12 +0,0 @@
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>

View File

@ -1,68 +0,0 @@
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>

View File

@ -1,23 +0,0 @@
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>

View File

@ -1 +1,90 @@
// TODO
import type { Static } from '@sinclair/typebox'
import { Type } from '@sinclair/typebox'
const domainSchema = {
name: Type.String({ minLength: 1 })
}
const skillBridges = [Type.Literal('python')]
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' })
})
}
const skillActionTypes = [Type.Literal('logic'), Type.Literal('dialog')]
const skillDataTypes = [
Type.Literal('skill_resolver'),
Type.Literal('global_resolver'),
Type.Literal('entity')
]
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()))
}
const domainSchemaObject = Type.Strict(
Type.Object(domainSchema, { additionalProperties: false })
)
const skillSchemaObject = Type.Strict(
Type.Object(skillSchema, { additionalProperties: false })
)
const skillConfigSchemaObject = Type.Strict(
Type.Object(skillConfigSchema, { additionalProperties: false })
)
export type Domain = Static<typeof domainSchemaObject>
export type Skill = Static<typeof skillSchemaObject>
export type SkillConfig = Static<typeof skillConfigSchemaObject>
export type SkillBridge = Static<typeof skillSchema.bridge>