@skychameleon/workflow 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +16 -3
- package/workflow/blocks/base.schema.ts +48 -0
- package/workflow/blocks/chat_bot/input-file.schema.ts +37 -11
- package/workflow/blocks/chat_bot/input-text.schema.ts +62 -25
- package/workflow/blocks/chat_bot/send-file.schema.ts +32 -14
- package/workflow/blocks/chat_bot/send-msg.schema.ts +19 -0
- package/workflow/blocks/general/run-code.schema.ts +15 -0
- package/workflow/blocks/general/start.schema.ts +26 -0
- package/workflow/blocks/general/var-set.schema.ts +32 -0
- package/workflow/blocks/index.ts +15 -0
- package/workflow/blocks/registry.ts +24 -17
- package/workflow/blocks/shared/general.types.ts +55 -0
- package/workflow/blocks/validation/duplicate-vars.start.ts +22 -0
- package/workflow/blocks/validation/regex.ts +1 -0
- package/workflow/edges/base.schema.ts +20 -0
- package/workflow/edges/index.ts +2 -0
- package/workflow/edges/query-rule.schema.ts +61 -0
- package/workflow/shared/index.ts +1 -0
- package/workflow/shared/shared.schema.ts +24 -0
- package/workflow/validation/check-edge-to-blocks.ts +31 -0
- package/workflow/validation/check-rule-var.ts +25 -0
- package/workflow/validation/duplicate-id-blocks.ts +26 -0
- package/workflow/validation/duplicate-id-edges.ts +24 -0
- package/workflow/validation/index.ts +4 -0
- package/workflow/workflow.schema.ts +39 -0
- package/index.ts +0 -0
- package/workflow/blocks/base.schema.d.ts +0 -19
- package/workflow/blocks/chat_bot/send-msg.schema.d.ts +0 -11
- package/workflow/blocks/general/run-code.schema.d.ts +0 -8
- package/workflow/blocks/general/start.schema.d.ts +0 -10
- package/workflow/blocks/general/var-set.schema.d.ts +0 -25
- package/workflow/blocks/shared/general.types.d.ts +0 -63
- package/workflow/edges/base.schema.d.ts +0 -9
- package/workflow/edges/query-rule.schema.d.ts +0 -38
- package/workflow/workflow.schema.d.ts +0 -18
package/package.json
CHANGED
|
@@ -1,19 +1,32 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@skychameleon/workflow",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Everything about workflow",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"type": "module",
|
|
7
7
|
"scripts": {
|
|
8
|
+
"test": "npx tsx --test",
|
|
8
9
|
"format": "npx prettier --write ."
|
|
9
10
|
},
|
|
10
11
|
"publishConfig": {
|
|
11
12
|
"access": "public"
|
|
12
13
|
},
|
|
13
14
|
"devDependencies": {
|
|
14
|
-
"@skychameleon/core": "^1.0.3"
|
|
15
|
+
"@skychameleon/core": "^1.0.3",
|
|
16
|
+
"@types/node": "^25.3.3",
|
|
17
|
+
"tsx": "^4.21.0"
|
|
18
|
+
},
|
|
19
|
+
"dependencies": {
|
|
20
|
+
"zod": "^4.3.6"
|
|
15
21
|
},
|
|
16
22
|
"exports": {
|
|
17
|
-
"./workflow
|
|
23
|
+
"./workflow": "./workflow/workflow.schema.ts",
|
|
24
|
+
"./edges": "./workflow/edges/index.ts",
|
|
25
|
+
"./blocks": "./workflow/blocks/index.ts",
|
|
26
|
+
"./shared": "./workflow/shared/index.ts",
|
|
27
|
+
"./validation": "./workflow/validation/index.ts"
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"zod": "^3.22.0"
|
|
18
31
|
}
|
|
19
32
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import {
|
|
3
|
+
EntranceHandlerZod,
|
|
4
|
+
ExitHandlerZod,
|
|
5
|
+
type EntranceHandler,
|
|
6
|
+
type ExitHandler,
|
|
7
|
+
} from "./shared/general.types";
|
|
8
|
+
|
|
9
|
+
export const ChatBotBlockZodTypes = z.enum([
|
|
10
|
+
"send-file",
|
|
11
|
+
"send-msg",
|
|
12
|
+
"input-text",
|
|
13
|
+
"input-file",
|
|
14
|
+
]);
|
|
15
|
+
export type ChatBotBlockTypes = z.infer<typeof ChatBotBlockZodTypes>;
|
|
16
|
+
|
|
17
|
+
export const MainBlockZodTypes = z.enum(["start", "var-set", "run-code"]);
|
|
18
|
+
export type MainBlockTypes = z.infer<typeof MainBlockZodTypes>;
|
|
19
|
+
|
|
20
|
+
export const BlockZodTypes = z.union([ChatBotBlockZodTypes, MainBlockZodTypes]);
|
|
21
|
+
export type BlockTypes = z.infer<typeof BlockZodTypes>;
|
|
22
|
+
|
|
23
|
+
export const BlockCategoryZod = z.enum(["pending", "action"]);
|
|
24
|
+
export type BlockCategory = z.infer<typeof BlockCategoryZod>;
|
|
25
|
+
|
|
26
|
+
export const createBaseBlockSchema = <
|
|
27
|
+
Type extends BlockTypes,
|
|
28
|
+
Category extends BlockCategory,
|
|
29
|
+
>(
|
|
30
|
+
type: Type,
|
|
31
|
+
category: Category,
|
|
32
|
+
) =>
|
|
33
|
+
z.object({
|
|
34
|
+
_id: z.string(),
|
|
35
|
+
index: z.number(),
|
|
36
|
+
category: z.literal(category),
|
|
37
|
+
type: z.literal(type),
|
|
38
|
+
label: z.string(),
|
|
39
|
+
x: z.number(),
|
|
40
|
+
y: z.number(),
|
|
41
|
+
width: z.number(),
|
|
42
|
+
height: z.number(),
|
|
43
|
+
entrance: EntranceHandlerZod,
|
|
44
|
+
exit: ExitHandlerZod,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
export type BaseBlockSchema = z.infer<ReturnType<typeof createBaseBlockSchema>>
|
|
48
|
+
export default createBaseBlockSchema;
|
|
@@ -1,16 +1,42 @@
|
|
|
1
|
-
import type
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
import type z from "zod";
|
|
2
|
+
import createBaseBlockSchema from "../base.schema";
|
|
3
|
+
import { VarSetBlockSchemaZod } from "../general/var-set.schema";
|
|
4
|
+
import {
|
|
5
|
+
AdditionalOptionsZod,
|
|
6
|
+
SendTextZod,
|
|
7
7
|
} from "../shared/general.types";
|
|
8
|
+
import { InputVarChatBotTypeZod } from "../../shared/shared.schema";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* Блок отвечающий за получения файла
|
|
11
12
|
*/
|
|
12
|
-
export
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
export const InputFileChatBotBlockSchemaZod = createBaseBlockSchema(
|
|
14
|
+
"input-file",
|
|
15
|
+
"pending",
|
|
16
|
+
).extend({
|
|
17
|
+
sendText: SendTextZod,
|
|
18
|
+
varSet: VarSetBlockSchemaZod.omit({
|
|
19
|
+
code: true,
|
|
20
|
+
})
|
|
21
|
+
.pick({
|
|
22
|
+
name: true,
|
|
23
|
+
varType: true,
|
|
24
|
+
completion: true,
|
|
25
|
+
})
|
|
26
|
+
.refine(
|
|
27
|
+
(varSet) => InputVarChatBotTypeZod.safeParse(varSet.varType).success,
|
|
28
|
+
{
|
|
29
|
+
message:
|
|
30
|
+
"varType must be one of InputVarChatBotType values for input-text block",
|
|
31
|
+
path: ["varSet", "varType"],
|
|
32
|
+
},
|
|
33
|
+
),
|
|
34
|
+
additionalOptions: AdditionalOptionsZod.pick({
|
|
35
|
+
back_button: true,
|
|
36
|
+
skip_button: true,
|
|
37
|
+
}),
|
|
38
|
+
});
|
|
39
|
+
type InputFileChatBotBlockSchema = z.infer<
|
|
40
|
+
typeof InputFileChatBotBlockSchemaZod
|
|
41
|
+
>;
|
|
42
|
+
export default InputFileChatBotBlockSchema;
|
|
@@ -1,35 +1,72 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
InputVarChatBotType,
|
|
7
|
-
SendText,
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import {
|
|
3
|
+
AdditionalOptionsZod,
|
|
4
|
+
CodeExpressionZod,
|
|
5
|
+
SendTextZod,
|
|
8
6
|
} from "../shared/general.types";
|
|
7
|
+
import createBaseBlockSchema from "../base.schema";
|
|
8
|
+
import { VarSetBlockSchemaZod } from "../general/var-set.schema";
|
|
9
|
+
import { InputVarChatBotTypeZod } from "../../shared/shared.schema";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Типы для составления клавиатуры
|
|
12
13
|
* Если создается кодом - KeyboardCode, то он должен вернуть объекта типа KeyboardConstructor
|
|
13
14
|
*/
|
|
14
|
-
export
|
|
15
|
-
export type
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
15
|
+
export const KeyboardCodeZod = CodeExpressionZod;
|
|
16
|
+
export type KeyboardCode = z.infer<typeof KeyboardCodeZod>;
|
|
17
|
+
|
|
18
|
+
export const KeyboardConstructorZod = z.array(
|
|
19
|
+
z.object({
|
|
20
|
+
text: z.union([
|
|
21
|
+
z.string(),
|
|
22
|
+
z.object({
|
|
23
|
+
useCodeExpression: z.boolean(),
|
|
24
|
+
code: KeyboardCodeZod,
|
|
25
|
+
}),
|
|
26
|
+
]),
|
|
27
|
+
callback_data: z.string(),
|
|
28
|
+
}),
|
|
29
|
+
);
|
|
30
|
+
|
|
31
|
+
export type KeyboardConstructor = z.infer<typeof KeyboardConstructorZod>;
|
|
24
32
|
|
|
25
33
|
/**
|
|
26
34
|
* Блок отвечающий за получения текстового сообщения
|
|
27
35
|
*/
|
|
28
|
-
export
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
+
export const InputTextChatBotBlockSchemaZod = createBaseBlockSchema(
|
|
37
|
+
"input-text",
|
|
38
|
+
"pending",
|
|
39
|
+
).extend({
|
|
40
|
+
sendText: SendTextZod,
|
|
41
|
+
validator: z.union([z.literal(false), CodeExpressionZod]),
|
|
42
|
+
convertor: z.union([z.literal(false), CodeExpressionZod]),
|
|
43
|
+
varSet: VarSetBlockSchemaZod.omit({
|
|
44
|
+
code: true,
|
|
45
|
+
})
|
|
46
|
+
.pick({
|
|
47
|
+
name: true,
|
|
48
|
+
varType: true,
|
|
49
|
+
completion: true,
|
|
50
|
+
})
|
|
51
|
+
.refine(
|
|
52
|
+
(varSet) => InputVarChatBotTypeZod.safeParse(varSet.varType).success,
|
|
53
|
+
{
|
|
54
|
+
message:
|
|
55
|
+
"varType must be one of InputVarChatBotType values for input-text block",
|
|
56
|
+
path: ["varSet", "varType"],
|
|
57
|
+
},
|
|
58
|
+
),
|
|
59
|
+
keyboard: z.union([
|
|
60
|
+
z.literal(false),
|
|
61
|
+
KeyboardCodeZod,
|
|
62
|
+
KeyboardConstructorZod,
|
|
63
|
+
]),
|
|
64
|
+
additionalOptions: AdditionalOptionsZod.pick({
|
|
65
|
+
back_button: true,
|
|
66
|
+
skip_button: true,
|
|
67
|
+
}),
|
|
68
|
+
});
|
|
69
|
+
type InputTextChatBotBlockSchema = z.infer<
|
|
70
|
+
typeof InputTextChatBotBlockSchemaZod
|
|
71
|
+
>;
|
|
72
|
+
export default InputTextChatBotBlockSchema;
|
|
@@ -1,19 +1,37 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
VarType,
|
|
7
|
-
SendText,
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import createBaseBlockSchema from "../base.schema";
|
|
3
|
+
import {
|
|
4
|
+
SendTextZod,
|
|
5
|
+
AdditionalOptionsZod,
|
|
8
6
|
} from "../shared/general.types";
|
|
7
|
+
import { VarSetBlockSchemaZod } from "../general/var-set.schema";
|
|
8
|
+
import { VarType } from "../../shared/shared.schema";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Блок отвечающий за отправление файлов
|
|
12
12
|
*/
|
|
13
|
-
export
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
13
|
+
export const SendFileChatBotBlockSchemaZod = createBaseBlockSchema(
|
|
14
|
+
"send-file",
|
|
15
|
+
"action",
|
|
16
|
+
).extend({
|
|
17
|
+
several: z.boolean(),
|
|
18
|
+
sendText: SendTextZod,
|
|
19
|
+
varSet: VarSetBlockSchemaZod.omit({
|
|
20
|
+
code: true,
|
|
21
|
+
})
|
|
22
|
+
.pick({
|
|
23
|
+
name: true,
|
|
24
|
+
varType: true,
|
|
25
|
+
completion: true,
|
|
26
|
+
})
|
|
27
|
+
.refine((varSet) => varSet.varType === VarType.BOOLEAN, {
|
|
28
|
+
message: "varType must be BOOLEAN for send-file block",
|
|
29
|
+
path: ["varSet", "varType"],
|
|
30
|
+
}),
|
|
31
|
+
errorText: z.string(),
|
|
32
|
+
additionalOptions: AdditionalOptionsZod.pick({
|
|
33
|
+
send_other_chat: true,
|
|
34
|
+
}),
|
|
35
|
+
});
|
|
36
|
+
type SendFileChatBotBlockSchema = z.infer<typeof SendFileChatBotBlockSchemaZod>;
|
|
37
|
+
export default SendFileChatBotBlockSchema;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import createBaseBlockSchema from "../base.schema";
|
|
3
|
+
import { AdditionalOptionsZod, SendTextZod } from "../shared/general.types";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Блок отвечающий за отправление текстового сообщения
|
|
7
|
+
*/
|
|
8
|
+
export const SendMsgChatBotBlockSchemaZod = createBaseBlockSchema(
|
|
9
|
+
"send-msg",
|
|
10
|
+
"action",
|
|
11
|
+
).extend({
|
|
12
|
+
markdown: z.boolean(),
|
|
13
|
+
sendText: SendTextZod,
|
|
14
|
+
additionalOptions: AdditionalOptionsZod.pick({
|
|
15
|
+
send_other_chat: true,
|
|
16
|
+
}),
|
|
17
|
+
});
|
|
18
|
+
type SendMsgChatBotBlockSchema = z.infer<typeof SendMsgChatBotBlockSchemaZod>;
|
|
19
|
+
export default SendMsgChatBotBlockSchema;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import createBaseBlockSchema from "../base.schema";
|
|
3
|
+
import { CodeExpressionZod } from "../shared/general.types";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Блок отвечающий за запуск кода
|
|
7
|
+
*/
|
|
8
|
+
export const RunCodeBlockSchemaZod = createBaseBlockSchema(
|
|
9
|
+
"start",
|
|
10
|
+
"action",
|
|
11
|
+
).extend({
|
|
12
|
+
code: CodeExpressionZod,
|
|
13
|
+
});
|
|
14
|
+
type RunCodeBlockSchema = z.infer<typeof RunCodeBlockSchemaZod>;
|
|
15
|
+
export default RunCodeBlockSchema;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import createBaseBlockSchema from "../base.schema";
|
|
3
|
+
import { VarSetBlockSchemaZod } from "./var-set.schema";
|
|
4
|
+
import { validateDuplicateVars } from "../validation/duplicate-vars.start";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Блок отвечающий за запуск сценария и содержащий все необходимые переменные для работы
|
|
8
|
+
*/
|
|
9
|
+
export const StartBlockSchemaZod = createBaseBlockSchema(
|
|
10
|
+
"start",
|
|
11
|
+
"action",
|
|
12
|
+
).extend({
|
|
13
|
+
vars: z
|
|
14
|
+
.array(
|
|
15
|
+
VarSetBlockSchemaZod.pick({
|
|
16
|
+
name: true,
|
|
17
|
+
varType: true,
|
|
18
|
+
code: true,
|
|
19
|
+
completion: true,
|
|
20
|
+
}),
|
|
21
|
+
)
|
|
22
|
+
.superRefine(validateDuplicateVars),
|
|
23
|
+
});
|
|
24
|
+
type StartBlockSchema = z.infer<typeof StartBlockSchemaZod>;
|
|
25
|
+
|
|
26
|
+
export default StartBlockSchema;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import createBaseBlockSchema from "../base.schema";
|
|
3
|
+
import {
|
|
4
|
+
CodeExpressionZod,
|
|
5
|
+
} from "../shared/general.types";
|
|
6
|
+
import { regexVarName } from "../validation/regex";
|
|
7
|
+
import { InputVarChatBotTypeZod, VarTypeZod } from "../../shared/shared.schema";
|
|
8
|
+
|
|
9
|
+
export const CompletionTypesZod = z.enum(["function", "variable"]);
|
|
10
|
+
export type CompletionTypes = z.infer<typeof CompletionTypesZod>;
|
|
11
|
+
|
|
12
|
+
export const VarSetBlockSchemaZod = createBaseBlockSchema(
|
|
13
|
+
"var-set",
|
|
14
|
+
"action",
|
|
15
|
+
).extend({
|
|
16
|
+
name: z.string().regex(regexVarName),
|
|
17
|
+
varType: z.union([VarTypeZod, InputVarChatBotTypeZod]),
|
|
18
|
+
code: CodeExpressionZod,
|
|
19
|
+
completion: z.union([
|
|
20
|
+
z.literal(false),
|
|
21
|
+
z.object({
|
|
22
|
+
label: z.string().optional(),
|
|
23
|
+
type: CompletionTypesZod.optional(),
|
|
24
|
+
detail: z.string().optional(),
|
|
25
|
+
info: z.string().optional(),
|
|
26
|
+
apply: z.string().optional(),
|
|
27
|
+
}),
|
|
28
|
+
]),
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
type VarSetBlock = z.infer<typeof VarSetBlockSchemaZod>;
|
|
32
|
+
export default VarSetBlock;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export * from "./base.schema"
|
|
2
|
+
export * from "./registry"
|
|
3
|
+
|
|
4
|
+
export * from "./chat_bot/input-file.schema"
|
|
5
|
+
export * from "./chat_bot/input-text.schema"
|
|
6
|
+
export * from "./chat_bot/send-file.schema"
|
|
7
|
+
export * from "./chat_bot/send-msg.schema"
|
|
8
|
+
|
|
9
|
+
export * from "./general/run-code.schema"
|
|
10
|
+
export * from "./general/start.schema"
|
|
11
|
+
export * from "./general/var-set.schema"
|
|
12
|
+
|
|
13
|
+
export * from "./shared/general.types"
|
|
14
|
+
export * from "./validation/duplicate-vars.start"
|
|
15
|
+
export * from "./validation/regex"
|
|
@@ -1,18 +1,25 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import
|
|
8
|
-
import
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import { StartBlockSchemaZod } from "./general/start.schema.ts";
|
|
3
|
+
import { VarSetBlockSchemaZod } from "./general/var-set.schema.ts";
|
|
4
|
+
import { RunCodeBlockSchemaZod } from "./general/run-code.schema.ts";
|
|
5
|
+
import { SendMsgChatBotBlockSchemaZod } from "./chat_bot/send-msg.schema.ts";
|
|
6
|
+
import { SendFileChatBotBlockSchemaZod } from "./chat_bot/send-file.schema.ts";
|
|
7
|
+
import { InputTextChatBotBlockSchemaZod } from "./chat_bot/input-text.schema.ts";
|
|
8
|
+
import { InputFileChatBotBlockSchemaZod } from "./chat_bot/input-file.schema.ts";
|
|
9
9
|
|
|
10
|
-
export
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
10
|
+
export const GeneralBlockSchemaZods = z.union([
|
|
11
|
+
StartBlockSchemaZod,
|
|
12
|
+
VarSetBlockSchemaZod,
|
|
13
|
+
RunCodeBlockSchemaZod,
|
|
14
|
+
]);
|
|
15
|
+
|
|
16
|
+
export type GeneralBlocksSchema = z.infer<typeof GeneralBlockSchemaZods>;
|
|
17
|
+
|
|
18
|
+
export const ChatBotBlocksSchemaZods = z.union([
|
|
19
|
+
SendMsgChatBotBlockSchemaZod,
|
|
20
|
+
SendFileChatBotBlockSchemaZod,
|
|
21
|
+
InputTextChatBotBlockSchemaZod,
|
|
22
|
+
InputFileChatBotBlockSchemaZod,
|
|
23
|
+
]);
|
|
24
|
+
|
|
25
|
+
export type ChatBotBlocksSchema = z.infer<typeof ChatBotBlocksSchemaZods>;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
|
|
3
|
+
export const CodeExpressionZod = z.string();
|
|
4
|
+
export type CodeExpression = z.infer<typeof CodeExpressionZod>;
|
|
5
|
+
/**
|
|
6
|
+
* Обработчик блока после выхода из основной логики бота
|
|
7
|
+
*/
|
|
8
|
+
export const ExitHandlerZod = z.union([
|
|
9
|
+
z.literal(false),
|
|
10
|
+
z.object({ code: z.string() }),
|
|
11
|
+
]);
|
|
12
|
+
export type ExitHandler = z.infer<typeof EntranceHandlerZod>;
|
|
13
|
+
/**
|
|
14
|
+
* Обработчик блока перед входом в основную логику бота
|
|
15
|
+
*/
|
|
16
|
+
export const EntranceHandlerZod = z.union([
|
|
17
|
+
z.literal(false),
|
|
18
|
+
z.object({ code: z.string() }),
|
|
19
|
+
]);
|
|
20
|
+
export type EntranceHandler = z.infer<typeof EntranceHandlerZod>;
|
|
21
|
+
|
|
22
|
+
export const DynamicTextZod = z.object({
|
|
23
|
+
useCodeExpression: z.boolean(),
|
|
24
|
+
code: CodeExpressionZod,
|
|
25
|
+
});
|
|
26
|
+
export type DynamicText = z.infer<typeof DynamicTextZod>;
|
|
27
|
+
|
|
28
|
+
export const SendTextZod = z.union([z.string(), DynamicTextZod]);
|
|
29
|
+
export type SendText = z.infer<typeof SendTextZod>;
|
|
30
|
+
|
|
31
|
+
export const ChatIDZod = z.number();
|
|
32
|
+
export type ChatID = z.infer<typeof ChatIDZod>;
|
|
33
|
+
/**
|
|
34
|
+
* Дополнительные опции для чат-ботов
|
|
35
|
+
*/
|
|
36
|
+
export const AdditionalOptionsZod = z.object({
|
|
37
|
+
back_button: z.union([
|
|
38
|
+
z.literal(false),
|
|
39
|
+
z.string(),
|
|
40
|
+
z.object({
|
|
41
|
+
useCodeExpression: z.boolean(),
|
|
42
|
+
code: CodeExpressionZod,
|
|
43
|
+
}),
|
|
44
|
+
]),
|
|
45
|
+
skip_button: z.union([
|
|
46
|
+
z.literal(false),
|
|
47
|
+
z.string(),
|
|
48
|
+
z.object({
|
|
49
|
+
useCodeExpression: z.boolean(),
|
|
50
|
+
code: CodeExpressionZod,
|
|
51
|
+
}),
|
|
52
|
+
]),
|
|
53
|
+
send_other_chat: z.union([z.literal(false), ChatIDZod]),
|
|
54
|
+
});
|
|
55
|
+
export type AdditionalOptions = z.infer<typeof AdditionalOptionsZod>;
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { ZodIssueCode } from "zod/v3";
|
|
2
|
+
import type VarSetBlock from "../general/var-set.schema";
|
|
3
|
+
import type z from "zod";
|
|
4
|
+
|
|
5
|
+
export const validateDuplicateVars = (
|
|
6
|
+
vars: Pick<VarSetBlock, "name" | "varType" | "code" | "completion">[],
|
|
7
|
+
ctx: z.RefinementCtx,
|
|
8
|
+
) => {
|
|
9
|
+
const seen = new Set<string>();
|
|
10
|
+
|
|
11
|
+
vars.forEach((v, index) => {
|
|
12
|
+
if (seen.has(v.name)) {
|
|
13
|
+
ctx.addIssue({
|
|
14
|
+
code: ZodIssueCode.custom,
|
|
15
|
+
message: `Переменная "${v.name}" уже объявлена в этом блоке`,
|
|
16
|
+
path: [index, "name"],
|
|
17
|
+
});
|
|
18
|
+
} else {
|
|
19
|
+
seen.add(v.name)
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const regexVarName = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/g;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
|
|
3
|
+
export const EdgeTypesZod = z.enum(["query-rule"]);
|
|
4
|
+
export type EdgeTypes = z.infer<typeof EdgeTypesZod>;
|
|
5
|
+
|
|
6
|
+
const createBaseEdgeSchemaZod = <Type extends EdgeTypes, Guard>(
|
|
7
|
+
type: Type,
|
|
8
|
+
guard: Guard,
|
|
9
|
+
) =>
|
|
10
|
+
z.object({
|
|
11
|
+
_id: z.string(),
|
|
12
|
+
label: z.string().optional(),
|
|
13
|
+
type: z.literal(type),
|
|
14
|
+
priority: z.number(),
|
|
15
|
+
source: z.string(),
|
|
16
|
+
target: z.string(),
|
|
17
|
+
guards: guard,
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
export default createBaseEdgeSchemaZod;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import createBaseEdgeSchemaZod from "./base.schema";
|
|
3
|
+
import { VarSetBlockSchemaZod } from "../blocks/general/var-set.schema";
|
|
4
|
+
|
|
5
|
+
export enum LogicOperator {
|
|
6
|
+
AND = "and",
|
|
7
|
+
OR = "or",
|
|
8
|
+
}
|
|
9
|
+
export const LogicOperatorZod = z.enum(LogicOperator);
|
|
10
|
+
export type LogicOperatorType = z.infer<typeof LogicOperatorZod>;
|
|
11
|
+
|
|
12
|
+
export enum ConditionList {
|
|
13
|
+
EMPTY = "empty",
|
|
14
|
+
NOT_EMPTY = "not_empty",
|
|
15
|
+
EQUAL = "equal",
|
|
16
|
+
NOT_EQUAL = "not_equal",
|
|
17
|
+
LESS = "less",
|
|
18
|
+
LESS_OR_EQUAL = "less_or_equal",
|
|
19
|
+
GREATER = "greater",
|
|
20
|
+
GREATER_OR_EQUAL = "greater_or_equal",
|
|
21
|
+
IS_NULL = "is_null",
|
|
22
|
+
IS_NOT_NULL = "is_not_null",
|
|
23
|
+
}
|
|
24
|
+
export const ConditionListZod = z.enum(ConditionList);
|
|
25
|
+
export type ConditionListType = z.infer<typeof ConditionListZod>;
|
|
26
|
+
|
|
27
|
+
export const ValueModeZod = z.object({
|
|
28
|
+
mode: z.enum(["value", "variable", "expression"]),
|
|
29
|
+
value: z.string(),
|
|
30
|
+
});
|
|
31
|
+
export type ValueMode = z.infer<typeof ValueModeZod>;
|
|
32
|
+
|
|
33
|
+
export const SingleRuleGuardSchema = z.object({
|
|
34
|
+
var: VarSetBlockSchemaZod.pick({
|
|
35
|
+
name: true,
|
|
36
|
+
varType: true,
|
|
37
|
+
}),
|
|
38
|
+
condition: ConditionListZod,
|
|
39
|
+
valueMode: ValueModeZod,
|
|
40
|
+
});
|
|
41
|
+
export type SingleRuleGuard = z.infer<typeof SingleRuleGuardSchema>;
|
|
42
|
+
|
|
43
|
+
export interface RuleGuardGroupSchema {
|
|
44
|
+
operator: LogicOperator;
|
|
45
|
+
guards: (SingleRuleGuard | RuleGuardGroupSchema)[];
|
|
46
|
+
}
|
|
47
|
+
export const RuleGuardGroupSchemaZod: z.ZodType<RuleGuardGroupSchema> = z.lazy(
|
|
48
|
+
() =>
|
|
49
|
+
z.object({
|
|
50
|
+
operator: LogicOperatorZod,
|
|
51
|
+
guards: z.array(
|
|
52
|
+
z.union([SingleRuleGuardSchema, RuleGuardGroupSchemaZod]),
|
|
53
|
+
)
|
|
54
|
+
}),
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
export const QueryRuleEdgeSchemaZod = createBaseEdgeSchemaZod(
|
|
58
|
+
"query-rule",
|
|
59
|
+
RuleGuardGroupSchemaZod,
|
|
60
|
+
);
|
|
61
|
+
export type QueryRuleEdgeSchema = z.infer<typeof QueryRuleEdgeSchemaZod>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./shared.schema"
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Типы переменных
|
|
5
|
+
*
|
|
6
|
+
* Типы для полученных сообщений из чат-ботов
|
|
7
|
+
* Общие типы
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
export enum InputVarChatBotType {
|
|
11
|
+
FILE = "file",
|
|
12
|
+
}
|
|
13
|
+
export const InputVarChatBotTypeZod = z.enum(InputVarChatBotType);
|
|
14
|
+
|
|
15
|
+
export enum VarType {
|
|
16
|
+
STRING = "string",
|
|
17
|
+
NUMBER = "number",
|
|
18
|
+
BOOLEAN = "boolean",
|
|
19
|
+
OBJECT = "object",
|
|
20
|
+
ARRAY = "array",
|
|
21
|
+
FUNCTION = "function",
|
|
22
|
+
ANY = "any",
|
|
23
|
+
}
|
|
24
|
+
export const VarTypeZod = z.enum(VarType);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type z from "zod";
|
|
2
|
+
import type { ChatBotBlocksSchema, GeneralBlocksSchema } from "../blocks/registry";
|
|
3
|
+
import type { QueryRuleEdgeSchema } from "../edges/query-rule.schema"
|
|
4
|
+
import { ZodIssueCode } from "zod/v3";
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
export const checkEdgeToBlocks = (
|
|
8
|
+
blocks: (ChatBotBlocksSchema | GeneralBlocksSchema)[],
|
|
9
|
+
edges: QueryRuleEdgeSchema[],
|
|
10
|
+
ctx: z.RefinementCtx
|
|
11
|
+
) => {
|
|
12
|
+
const blockIds = new Set(blocks.map(block => block._id))
|
|
13
|
+
|
|
14
|
+
edges.forEach((edge, index) => {
|
|
15
|
+
if (!blockIds.has(edge.source)) {
|
|
16
|
+
ctx.addIssue({
|
|
17
|
+
code: ZodIssueCode.custom,
|
|
18
|
+
message: `Связь "${edge._id}" ссылается на несуществующий блок source: "${edge.source}"`,
|
|
19
|
+
path: ["states", "edges", index, "source"]
|
|
20
|
+
})
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (!blockIds.has(edge.target)) {
|
|
24
|
+
ctx.addIssue({
|
|
25
|
+
code: ZodIssueCode.custom,
|
|
26
|
+
message: `Связь "${edge._id}" ссылается на несуществующий блок target: "${edge.target}"`,
|
|
27
|
+
path: ["states", "edges", index, "target"]
|
|
28
|
+
})
|
|
29
|
+
}
|
|
30
|
+
})
|
|
31
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type z from "zod";
|
|
2
|
+
import type { ChatBotBlocksSchema, GeneralBlocksSchema } from "../blocks/registry";
|
|
3
|
+
import type { QueryRuleEdgeSchema } from "../edges/query-rule.schema"
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Проверяет, есть ли в текущем edge доступ к переменным в rule
|
|
9
|
+
* Для текущего rule в edge доступ к блокам имеющие переменную(ые) доступно только до edge
|
|
10
|
+
*/
|
|
11
|
+
export const checkRuleVar = (
|
|
12
|
+
blocks: (ChatBotBlocksSchema | GeneralBlocksSchema)[],
|
|
13
|
+
edges: QueryRuleEdgeSchema[],
|
|
14
|
+
ctx: z.RefinementCtx
|
|
15
|
+
) => {
|
|
16
|
+
const blockIndexed = Object.groupBy(blocks, ({ index }) => index)
|
|
17
|
+
|
|
18
|
+
edges.forEach((edge) => {
|
|
19
|
+
const beginBlock = edge.source;
|
|
20
|
+
const block = blocks.find((block) => block._id == beginBlock)
|
|
21
|
+
if (!block) return
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
})
|
|
25
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type z from "zod";
|
|
2
|
+
import type { ChatBotBlocksSchema, GeneralBlocksSchema } from "../blocks/registry";
|
|
3
|
+
import { ZodIssueCode } from "zod/v3";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Валидация блоков на id. Должны быть уникальными
|
|
7
|
+
*/
|
|
8
|
+
export const duplicateIdBlocks = (
|
|
9
|
+
blocks: (ChatBotBlocksSchema | GeneralBlocksSchema)[],
|
|
10
|
+
ctx: z.RefinementCtx
|
|
11
|
+
) => {
|
|
12
|
+
const seen = new Set<string>();
|
|
13
|
+
|
|
14
|
+
blocks.forEach((block, index) => {
|
|
15
|
+
if (seen.has(block._id)) {
|
|
16
|
+
|
|
17
|
+
ctx.addIssue({
|
|
18
|
+
code: ZodIssueCode.custom,
|
|
19
|
+
message: `_id "${block._id}" с индексом ${block.index} уже используется`,
|
|
20
|
+
path: [index, "name"],
|
|
21
|
+
});
|
|
22
|
+
} else {
|
|
23
|
+
seen.add(block._id)
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type z from "zod";
|
|
2
|
+
import { ZodIssueCode } from "zod/v3";
|
|
3
|
+
import type { QueryRuleEdgeSchema } from "../edges/query-rule.schema";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Валидация связей на id. Должны быть уникальными
|
|
7
|
+
*/
|
|
8
|
+
export const duplicateIdEdges = (
|
|
9
|
+
edges: QueryRuleEdgeSchema[],
|
|
10
|
+
ctx: z.RefinementCtx
|
|
11
|
+
) => {
|
|
12
|
+
const seen = new Set<string>();
|
|
13
|
+
edges.forEach((edge, index) => {
|
|
14
|
+
if (seen.has(edge._id)) {
|
|
15
|
+
ctx.addIssue({
|
|
16
|
+
code: ZodIssueCode.custom,
|
|
17
|
+
message: `_id "${edge._id}" уже используется`,
|
|
18
|
+
path: [index, "name"],
|
|
19
|
+
});
|
|
20
|
+
} else {
|
|
21
|
+
seen.add(edge._id)
|
|
22
|
+
}
|
|
23
|
+
})
|
|
24
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import z from "zod";
|
|
2
|
+
import {
|
|
3
|
+
ChatBotBlocksSchemaZods,
|
|
4
|
+
GeneralBlockSchemaZods,
|
|
5
|
+
} from "./blocks/registry";
|
|
6
|
+
import {
|
|
7
|
+
QueryRuleEdgeSchemaZod,
|
|
8
|
+
} from "./edges/query-rule.schema";
|
|
9
|
+
import { checkEdgeToBlocks } from "./validation/check-edge-to-blocks";
|
|
10
|
+
import { duplicateIdBlocks } from "./validation/duplicate-id-blocks";
|
|
11
|
+
import { duplicateIdEdges } from "./validation/duplicate-id-edges";
|
|
12
|
+
|
|
13
|
+
export const MetadataSchemaZod = z.object({
|
|
14
|
+
name: z.string(),
|
|
15
|
+
description: z.string(),
|
|
16
|
+
exportedAt: z.iso.datetime(),
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
export type MetadataSchema = z.infer<typeof MetadataSchemaZod>;
|
|
20
|
+
|
|
21
|
+
export const WorkflowSchemaZod = z.object({
|
|
22
|
+
metadata: MetadataSchemaZod,
|
|
23
|
+
states: z.object({
|
|
24
|
+
edges: z.array(QueryRuleEdgeSchemaZod)
|
|
25
|
+
.superRefine((edges, ctx) => duplicateIdEdges(edges, ctx)),
|
|
26
|
+
blocks: z.array(z.union([GeneralBlockSchemaZods, ChatBotBlocksSchemaZods]))
|
|
27
|
+
.superRefine((blocks, ctx) => duplicateIdBlocks(blocks, ctx)),
|
|
28
|
+
}),
|
|
29
|
+
}).superRefine((data, ctx) => {
|
|
30
|
+
const { states } = data
|
|
31
|
+
const { edges, blocks } = states
|
|
32
|
+
|
|
33
|
+
checkEdgeToBlocks(blocks, edges, ctx)
|
|
34
|
+
// checkRuleVar(blocks, edges, ctx)
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
type WorkflowSchema = z.infer<typeof WorkflowSchemaZod>;
|
|
38
|
+
|
|
39
|
+
export default WorkflowSchema;
|
package/index.ts
DELETED
|
File without changes
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import type { EntranceHandler, ExitHandler } from "./shared/general.types";
|
|
2
|
-
|
|
3
|
-
type ChatBotBlockTypes = "send_file" | "send_msg" | "input-text" | "input-file";
|
|
4
|
-
|
|
5
|
-
type MainBlockTypes = "start" | "var_set" | "run_code";
|
|
6
|
-
|
|
7
|
-
type BlockTypes = MainBlockTypes | ChatBotBlockTypes;
|
|
8
|
-
|
|
9
|
-
export interface BaseBlockSchema<T extends BlockTypes> {
|
|
10
|
-
_id: string;
|
|
11
|
-
type: T;
|
|
12
|
-
label: string;
|
|
13
|
-
x: number;
|
|
14
|
-
y: number;
|
|
15
|
-
width: number;
|
|
16
|
-
height: number;
|
|
17
|
-
entrance: EntranceHandler;
|
|
18
|
-
exit: ExitHandler;
|
|
19
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { BaseBlockSchema } from "../base.schema";
|
|
2
|
-
import type { AdditionalOptions, SendText } from "../shared/general.types";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* Блок отвечающий за отправление текстового сообщения
|
|
6
|
-
*/
|
|
7
|
-
export interface SendMsgChatBotBlockSchema extends BaseBlockSchema<"send_msg"> {
|
|
8
|
-
markdown: boolean;
|
|
9
|
-
sendText: SendText;
|
|
10
|
-
additionalOptions: Pick<AdditionalOptions, "send_other_chat">;
|
|
11
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import type { BaseBlockSchema } from "../base.schema";
|
|
2
|
-
import type { VarType } from "../shared/general.types";
|
|
3
|
-
import type { VarSetBlockSchema } from "./var-set.schema";
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Блок отвечающий за запуск сценария и содержащий все необходимые переменные для работы
|
|
7
|
-
*/
|
|
8
|
-
export interface StartBlockSchema extends BaseBlockSchema<"start"> {
|
|
9
|
-
vars: VarSetBlockSchema<VarType>[];
|
|
10
|
-
}
|
|
@@ -1,25 +0,0 @@
|
|
|
1
|
-
import type { BaseBlockSchema } from "../base.schema";
|
|
2
|
-
import type { VarType, InputVarChatBotType } from "../shared/general.types";
|
|
3
|
-
|
|
4
|
-
type CompletionTypes = `function` | `variable`;
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Блок отвечающий за создание переменной в контексте клиента
|
|
8
|
-
*/
|
|
9
|
-
export interface VarSetBlockSchema<
|
|
10
|
-
Type extends VarType | InputVarChatBotType,
|
|
11
|
-
> extends BaseBlockSchema<"var_set"> {
|
|
12
|
-
name: string;
|
|
13
|
-
varType: Type;
|
|
14
|
-
code: string;
|
|
15
|
-
completion:
|
|
16
|
-
| false
|
|
17
|
-
| {
|
|
18
|
-
// для подсказки в редакторе-codemirror
|
|
19
|
-
label?: string;
|
|
20
|
-
type?: CompletionTypes;
|
|
21
|
-
detail?: string;
|
|
22
|
-
info?: string;
|
|
23
|
-
apply?: string;
|
|
24
|
-
};
|
|
25
|
-
}
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
export type CodeExpression = string;
|
|
2
|
-
/**
|
|
3
|
-
* Обработчик блока после выхода из основной логики бота
|
|
4
|
-
*/
|
|
5
|
-
export type ExitHandler =
|
|
6
|
-
| false
|
|
7
|
-
| {
|
|
8
|
-
code: string;
|
|
9
|
-
};
|
|
10
|
-
/**
|
|
11
|
-
* Обработчик блока перед входом в основную логику бота
|
|
12
|
-
*/
|
|
13
|
-
export type EntranceHandler =
|
|
14
|
-
| false
|
|
15
|
-
| {
|
|
16
|
-
code: string;
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
interface DynamicText {
|
|
20
|
-
useCodeExpression: boolean;
|
|
21
|
-
code: CodeExpression;
|
|
22
|
-
}
|
|
23
|
-
export type SendText = string | DynamicText;
|
|
24
|
-
export type ChatID = number;
|
|
25
|
-
/**
|
|
26
|
-
* Дополнительные опции для чат-ботов
|
|
27
|
-
*/
|
|
28
|
-
export type AdditionalOptions = {
|
|
29
|
-
back_button:
|
|
30
|
-
| false
|
|
31
|
-
| string
|
|
32
|
-
| {
|
|
33
|
-
useCodeExpression: boolean;
|
|
34
|
-
code: CodeExpression;
|
|
35
|
-
};
|
|
36
|
-
skip_button:
|
|
37
|
-
| false
|
|
38
|
-
| string
|
|
39
|
-
| {
|
|
40
|
-
useCodeExpression: boolean;
|
|
41
|
-
code: CodeExpression;
|
|
42
|
-
};
|
|
43
|
-
send_other_chat: false | ChatID;
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Типы переменных
|
|
48
|
-
*
|
|
49
|
-
* Типы для полученных сообщений из чат-ботов
|
|
50
|
-
* Общие типы
|
|
51
|
-
*/
|
|
52
|
-
export enum InputVarChatBotType {
|
|
53
|
-
FILE = "file",
|
|
54
|
-
}
|
|
55
|
-
export enum VarType {
|
|
56
|
-
STRING = "string",
|
|
57
|
-
NUMBER = "number",
|
|
58
|
-
BOOLEAN = "boolean",
|
|
59
|
-
OBJECT = "object",
|
|
60
|
-
ARRAY = "array",
|
|
61
|
-
FUNCTION = "function",
|
|
62
|
-
ANY = "any",
|
|
63
|
-
}
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import type { VarType } from "../blocks/shared/general.types";
|
|
2
|
-
import type { BaseEdgeSchema } from "./base.schema";
|
|
3
|
-
|
|
4
|
-
export enum LogicOperator {
|
|
5
|
-
AND = "and",
|
|
6
|
-
OR = "or",
|
|
7
|
-
}
|
|
8
|
-
export enum ConditionList {
|
|
9
|
-
EMPTY = "empty",
|
|
10
|
-
NOT_EMPTY = "not_empty",
|
|
11
|
-
EQUAL = "equal",
|
|
12
|
-
NOT_EQUAL = "not_equal",
|
|
13
|
-
LESS = "less",
|
|
14
|
-
LESS_OR_EQUAL = "less_or_equal",
|
|
15
|
-
GREATER = "greater",
|
|
16
|
-
GREATER_OR_EQUAL = "greater_or_equal",
|
|
17
|
-
IS_NULL = "is_null",
|
|
18
|
-
IS_NOT_NULL = "is_not_null",
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface SingleRuleGuard {
|
|
22
|
-
var: string;
|
|
23
|
-
typeVar: VarType;
|
|
24
|
-
/*--*/
|
|
25
|
-
condition: ConditionList;
|
|
26
|
-
/*--*/
|
|
27
|
-
valueMode: {
|
|
28
|
-
mode: "value" | "variable" | "expression";
|
|
29
|
-
value: string;
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export interface RuleGuardGroup {
|
|
34
|
-
operator: LogicOperator;
|
|
35
|
-
guards: (SingleRuleGuard | RuleGuardGroup)[];
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export type QueryRuleEdgeSchema = BaseEdgeSchema<"query-rule", RuleGuardGroup>;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import type { ChatBotBlockSchema, GeneralBlockSchema } from "./blocks/registry";
|
|
2
|
-
import type { QueryRuleEdgeSchema } from "./edges/query-rule.schema";
|
|
3
|
-
|
|
4
|
-
export interface Metadata {
|
|
5
|
-
name: string;
|
|
6
|
-
description: string;
|
|
7
|
-
exportedAt: string;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
interface WorkflowSchema {
|
|
11
|
-
states: {
|
|
12
|
-
blocks: (GeneralBlockSchema | ChatBotBlockSchema)[];
|
|
13
|
-
edges: QueryRuleEdgeSchema[];
|
|
14
|
-
};
|
|
15
|
-
metadata: Metadata;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export default WorkflowSchema;
|