@baishuyun/agents 0.0.1
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/CHANGELOG.md +7 -0
- package/index.ts +10 -0
- package/package.json +30 -0
- package/src/continue-confirmer/index.ts +41 -0
- package/src/continue-confirmer/prompt.ts +11 -0
- package/src/fields-builder/fields-builder.ts +43 -0
- package/src/fields-builder/index.ts +109 -0
- package/src/form-builder/consts/index.ts +5 -0
- package/src/form-builder/index.ts +24 -0
- package/src/form-builder/model/ds.ts +8 -0
- package/src/form-builder/model/openai.ts +7 -0
- package/src/form-builder/model/v0.ts +7 -0
- package/src/form-builder/model/xai.ts +7 -0
- package/src/form-builder/prompts/fields-design-docs.ts +3 -0
- package/src/form-builder/prompts/index.ts +32 -0
- package/src/form-builder/schema/index.ts +7 -0
- package/src/form-builder/tools/address.ts +58 -0
- package/src/form-builder/tools/attachment.ts +62 -0
- package/src/form-builder/tools/button.ts +73 -0
- package/src/form-builder/tools/checkbox.ts +55 -0
- package/src/form-builder/tools/confirm-to-create-fields-for-related-form.ts +16 -0
- package/src/form-builder/tools/confirm-to-create-form.ts +11 -0
- package/src/form-builder/tools/confirm-to-create-related-form.ts +16 -0
- package/src/form-builder/tools/confirm-to-save-checked-fields.ts +11 -0
- package/src/form-builder/tools/date-time.ts +73 -0
- package/src/form-builder/tools/department-group.ts +49 -0
- package/src/form-builder/tools/department.ts +49 -0
- package/src/form-builder/tools/image.ts +123 -0
- package/src/form-builder/tools/index.ts +27 -0
- package/src/form-builder/tools/input.ts +70 -0
- package/src/form-builder/tools/link-data.ts +70 -0
- package/src/form-builder/tools/load-data.ts +49 -0
- package/src/form-builder/tools/location.ts +94 -0
- package/src/form-builder/tools/member-group.ts +51 -0
- package/src/form-builder/tools/member.ts +51 -0
- package/src/form-builder/tools/number-input.ts +106 -0
- package/src/form-builder/tools/prompt-to-create-realted-form.ts +12 -0
- package/src/form-builder/tools/radio.ts +54 -0
- package/src/form-builder/tools/select-checker.ts +58 -0
- package/src/form-builder/tools/select.ts +56 -0
- package/src/form-builder/tools/serial-number.ts +75 -0
- package/src/form-builder/tools/signature.ts +38 -0
- package/src/form-builder/tools/splitline.ts +41 -0
- package/src/form-builder/tools/textarea.ts +55 -0
- package/src/form-builder/types/index.ts +53 -0
- package/src/form-builder/utils/index.ts +5 -0
- package/src/form-builder/utils/process-confirm-tool-call.ts +123 -0
- package/src/form-designer/index.ts +61 -0
- package/src/form-designer/prompts.ts +50 -0
- package/src/utils/index.ts +104 -0
- package/tsconfig.json +7 -0
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { tool } from 'ai';
|
|
3
|
+
import { buildWidgetName } from '../utils/index.js';
|
|
4
|
+
|
|
5
|
+
export const buildMemberSelectField = tool({
|
|
6
|
+
name: 'buildMemberSelectField',
|
|
7
|
+
description:
|
|
8
|
+
'Build a team member select field for a form. The field allows users to select one members from own orgnization.',
|
|
9
|
+
inputSchema: z.object({
|
|
10
|
+
label: z.string().min(1).max(100),
|
|
11
|
+
placeholder: z.string().min(1).max(100).optional(),
|
|
12
|
+
required: z.boolean().default(false),
|
|
13
|
+
fieldWidth: z.enum(['3', '4', '6', '8', '9', '12']).default('12'),
|
|
14
|
+
description: z.string().min(1).max(100).optional(),
|
|
15
|
+
}),
|
|
16
|
+
execute: (input) => {
|
|
17
|
+
const { label, required, fieldWidth, description } = input;
|
|
18
|
+
return {
|
|
19
|
+
widget: {
|
|
20
|
+
type: 'user',
|
|
21
|
+
widgetName: buildWidgetName(),
|
|
22
|
+
widgetNameAlias: '',
|
|
23
|
+
customCls: null,
|
|
24
|
+
height: '34',
|
|
25
|
+
width: 350,
|
|
26
|
+
enable: true,
|
|
27
|
+
visible: true,
|
|
28
|
+
allowBlank: !required,
|
|
29
|
+
labelStyle: label,
|
|
30
|
+
funMode: 'module',
|
|
31
|
+
module: null,
|
|
32
|
+
libs: [],
|
|
33
|
+
extendSet: {
|
|
34
|
+
sort: ['datahelp', 'module', 'formEvent'],
|
|
35
|
+
status: true,
|
|
36
|
+
triggerField: '',
|
|
37
|
+
triggerFieldMode: 'none',
|
|
38
|
+
version: 1,
|
|
39
|
+
},
|
|
40
|
+
noRepeat: false,
|
|
41
|
+
limit: {},
|
|
42
|
+
limitWidget: null, //可选范围 由部门字段确定,如果有值 是 _widget_1762226067008 这种,另一个部门字段的id。和limit互斥,limit将为[]
|
|
43
|
+
valueOption: 0,
|
|
44
|
+
},
|
|
45
|
+
description,
|
|
46
|
+
label,
|
|
47
|
+
lineWidth: parseInt(fieldWidth),
|
|
48
|
+
tab: null,
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
});
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { tool } from "ai";
|
|
3
|
+
import { buildWidgetName } from "../utils/index.js";
|
|
4
|
+
|
|
5
|
+
export const buildNumberInputField = tool({
|
|
6
|
+
name: "buildNumberInputField",
|
|
7
|
+
description: "build a number input field",
|
|
8
|
+
inputSchema: z.object({
|
|
9
|
+
label: z
|
|
10
|
+
.string()
|
|
11
|
+
.min(1)
|
|
12
|
+
.max(100)
|
|
13
|
+
.describe("The label of the number input field"),
|
|
14
|
+
min: z
|
|
15
|
+
.number()
|
|
16
|
+
.optional()
|
|
17
|
+
.describe("The minimum value of the number input field"),
|
|
18
|
+
regex: z
|
|
19
|
+
.string()
|
|
20
|
+
.optional()
|
|
21
|
+
.default("^[-]?[\\d]{0,}[\\.]?[\\d]{0,}$")
|
|
22
|
+
.describe("The regex for validating the number input"),
|
|
23
|
+
placeholder: z.string().min(1).max(100).optional(),
|
|
24
|
+
max: z
|
|
25
|
+
.number()
|
|
26
|
+
.optional()
|
|
27
|
+
.describe("The maximum value of the number input field"),
|
|
28
|
+
required: z
|
|
29
|
+
.boolean()
|
|
30
|
+
.optional()
|
|
31
|
+
.describe("Whether the number input field is required"),
|
|
32
|
+
description: z
|
|
33
|
+
.string()
|
|
34
|
+
.max(500)
|
|
35
|
+
.optional()
|
|
36
|
+
.describe("The description of the number input field"),
|
|
37
|
+
fieldWidth: z
|
|
38
|
+
.enum(["3", "4", "6", "8", "9", "12"])
|
|
39
|
+
.optional()
|
|
40
|
+
.default("12")
|
|
41
|
+
.describe("The width of the number input field in the form layout"),
|
|
42
|
+
}),
|
|
43
|
+
execute: (input) => {
|
|
44
|
+
const {
|
|
45
|
+
label,
|
|
46
|
+
fieldWidth,
|
|
47
|
+
description,
|
|
48
|
+
required,
|
|
49
|
+
regex,
|
|
50
|
+
placeholder,
|
|
51
|
+
max,
|
|
52
|
+
min,
|
|
53
|
+
} = input;
|
|
54
|
+
return {
|
|
55
|
+
widget: {
|
|
56
|
+
type: "number",
|
|
57
|
+
widgetName: buildWidgetName(),
|
|
58
|
+
widgetNameAlias: "",
|
|
59
|
+
triggerEvent: false,
|
|
60
|
+
customCls: null,
|
|
61
|
+
height: 34,
|
|
62
|
+
width: 350,
|
|
63
|
+
enable: true,
|
|
64
|
+
visible: true,
|
|
65
|
+
allowBlank: !required,
|
|
66
|
+
labelStyle: label,
|
|
67
|
+
funMode: "module",
|
|
68
|
+
module: null,
|
|
69
|
+
libs: [],
|
|
70
|
+
extendSet: {
|
|
71
|
+
sort: ["datahelp", "module", "formEvent"],
|
|
72
|
+
status: true,
|
|
73
|
+
triggerField: "",
|
|
74
|
+
triggerFieldMode: "none",
|
|
75
|
+
version: 1,
|
|
76
|
+
},
|
|
77
|
+
regex,
|
|
78
|
+
hint: placeholder,
|
|
79
|
+
noRepeat: false,
|
|
80
|
+
alertinfo: {
|
|
81
|
+
icon: "success",
|
|
82
|
+
tip: "请设置提示内容",
|
|
83
|
+
},
|
|
84
|
+
allowDecimals: true, //允许小数,默认值 true,已废弃
|
|
85
|
+
allowNegative: true, //允许负数,默认值 true ,已废弃
|
|
86
|
+
maxNumber: max, //限定数值范围 最大值
|
|
87
|
+
minNumber: min, //限定数值范围 最小值
|
|
88
|
+
displayMode: "percent", // 新的格式, percent 百分比 number 数值
|
|
89
|
+
precision: null, //保留小数位数
|
|
90
|
+
thousandsSeparator: false, //显示千分符
|
|
91
|
+
notround: true, //不四舍五入
|
|
92
|
+
format: "", //旧的格式,新的由多个属性来控制,前端代码会用其他几个参数拼接出正确的这个值。 其中结尾有% 代表百分比 ,没有%代表数字 ,然后小数点后面的0的个数代表 保留的小数位数,如果小数点后面没有0代表(如0.%),代表没有设置 保留小数位数,保留用户输入的所有小数
|
|
93
|
+
afterSuffix: {
|
|
94
|
+
//单位
|
|
95
|
+
zh_cn: "", //中文的
|
|
96
|
+
en_us: "", //英文的
|
|
97
|
+
zh_tw: "", //繁体的
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
description,
|
|
101
|
+
label,
|
|
102
|
+
lineWidth: parseInt(fieldWidth),
|
|
103
|
+
tab: null,
|
|
104
|
+
};
|
|
105
|
+
},
|
|
106
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { tool } from "ai";
|
|
3
|
+
|
|
4
|
+
export const promptToCreateRelatedForm = tool({
|
|
5
|
+
name: "promptToCreateRelatedForm",
|
|
6
|
+
description:
|
|
7
|
+
"Determines whether to create a related form based on user input. Returns true if a related form should be created, otherwise false.",
|
|
8
|
+
inputSchema: z.object({
|
|
9
|
+
hasRelatedForm: z.boolean(),
|
|
10
|
+
}),
|
|
11
|
+
outputSchema: z.boolean(),
|
|
12
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { tool } from "ai";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
export const buildRadioField = tool({
|
|
5
|
+
name: "buildRadioField",
|
|
6
|
+
inputSchema: z.object({
|
|
7
|
+
label: z.string().min(1).max(100),
|
|
8
|
+
fieldWidth: z.enum(["3", "4", "6", "8", "9", "12"]).default("12"),
|
|
9
|
+
description: z.string().min(1).max(100).optional(),
|
|
10
|
+
required: z.boolean().default(false),
|
|
11
|
+
layout: z.enum(["horizontal", "vertical"]).default("horizontal"),
|
|
12
|
+
options: z.array(
|
|
13
|
+
z.object({
|
|
14
|
+
value: z.string().min(1).max(100),
|
|
15
|
+
text: z.string().min(1).max(100),
|
|
16
|
+
color: z.string().min(1).max(7),
|
|
17
|
+
}),
|
|
18
|
+
),
|
|
19
|
+
}),
|
|
20
|
+
execute: (input) => {
|
|
21
|
+
const { label, fieldWidth, description, options, required, layout } = input;
|
|
22
|
+
return {
|
|
23
|
+
widget: {
|
|
24
|
+
type: "radiogroup",
|
|
25
|
+
enable: true,
|
|
26
|
+
visible: true,
|
|
27
|
+
allowBlank: !required,
|
|
28
|
+
funMode: "module",
|
|
29
|
+
module: null,
|
|
30
|
+
libs: [],
|
|
31
|
+
items: options,
|
|
32
|
+
layout,
|
|
33
|
+
stopCancel: false,
|
|
34
|
+
widgetName: `_widget_${Date.now()}`,
|
|
35
|
+
widgetNameAlias: "",
|
|
36
|
+
customCls: null,
|
|
37
|
+
value: null,
|
|
38
|
+
labelStyle: label,
|
|
39
|
+
extendSet: {
|
|
40
|
+
sort: ["datahelp", "module", "formEvent"],
|
|
41
|
+
status: true,
|
|
42
|
+
triggerField: "",
|
|
43
|
+
triggerFieldMode: "none",
|
|
44
|
+
version: 1,
|
|
45
|
+
},
|
|
46
|
+
colorEnable: true, //颜色 是否开启颜色
|
|
47
|
+
},
|
|
48
|
+
description,
|
|
49
|
+
label,
|
|
50
|
+
lineWidth: parseInt(fieldWidth),
|
|
51
|
+
tab: null,
|
|
52
|
+
};
|
|
53
|
+
},
|
|
54
|
+
});
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { tool } from "ai";
|
|
3
|
+
import { buildWidgetName } from "../utils/index.js";
|
|
4
|
+
|
|
5
|
+
const select = z.object({
|
|
6
|
+
label: z.string().min(1).max(100),
|
|
7
|
+
required: z.boolean().default(false),
|
|
8
|
+
options: z.array(
|
|
9
|
+
z.object({
|
|
10
|
+
value: z.string().min(1).max(100),
|
|
11
|
+
text: z.string().min(1).max(100),
|
|
12
|
+
}),
|
|
13
|
+
),
|
|
14
|
+
description: z.string().min(1).max(100).optional(),
|
|
15
|
+
fieldWidth: z.enum(["3", "4", "6", "8", "9", "12"]).default("12"),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
export const buildSelectCheckerField = tool({
|
|
19
|
+
name: "buildSelectCheckerField",
|
|
20
|
+
description: "Builds a select checker field",
|
|
21
|
+
inputSchema: select,
|
|
22
|
+
execute: (input) => {
|
|
23
|
+
const { label, required, options, fieldWidth, description } = input;
|
|
24
|
+
return {
|
|
25
|
+
widget: {
|
|
26
|
+
type: "combocheck",
|
|
27
|
+
widgetName: buildWidgetName(),
|
|
28
|
+
widgetNameAlias: "",
|
|
29
|
+
customCls: null,
|
|
30
|
+
height: 34,
|
|
31
|
+
width: 350,
|
|
32
|
+
enable: true,
|
|
33
|
+
visible: true,
|
|
34
|
+
allowBlank: !required,
|
|
35
|
+
labelStyle: label,
|
|
36
|
+
funMode: "module",
|
|
37
|
+
module: null,
|
|
38
|
+
libs: [],
|
|
39
|
+
extendSet: {
|
|
40
|
+
sort: ["datahelp", "module", "formEvent"],
|
|
41
|
+
status: true,
|
|
42
|
+
triggerField: "",
|
|
43
|
+
triggerFieldMode: "none",
|
|
44
|
+
version: 1,
|
|
45
|
+
},
|
|
46
|
+
colorEnable: true, //颜色 是否开启颜色
|
|
47
|
+
mode: "",
|
|
48
|
+
allowAddOptions: false, //允许成员填写时添加新选项
|
|
49
|
+
allowAddLinkData: false,
|
|
50
|
+
items: options,
|
|
51
|
+
},
|
|
52
|
+
description,
|
|
53
|
+
label,
|
|
54
|
+
lineWidth: parseInt(fieldWidth),
|
|
55
|
+
tab: null,
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
});
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { tool } from "ai";
|
|
3
|
+
|
|
4
|
+
const select = z.object({
|
|
5
|
+
label: z.string().min(1).max(100),
|
|
6
|
+
required: z.boolean().default(false),
|
|
7
|
+
options: z.array(
|
|
8
|
+
z.object({
|
|
9
|
+
value: z.string().min(1).max(100),
|
|
10
|
+
text: z.string().min(1).max(100),
|
|
11
|
+
}),
|
|
12
|
+
),
|
|
13
|
+
description: z.string().min(1).max(100).optional(),
|
|
14
|
+
fieldWidth: z.enum(["3", "4", "6", "8", "9", "12"]).default("12"),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
export const buildSelectField = tool({
|
|
18
|
+
name: "buildSelectField",
|
|
19
|
+
description: "Builds a select field",
|
|
20
|
+
inputSchema: select,
|
|
21
|
+
execute: (input) => {
|
|
22
|
+
const { label, required, options, fieldWidth, description } = input;
|
|
23
|
+
return {
|
|
24
|
+
widget: {
|
|
25
|
+
type: "combo",
|
|
26
|
+
height: 34,
|
|
27
|
+
width: 350,
|
|
28
|
+
enable: true,
|
|
29
|
+
visible: true,
|
|
30
|
+
allowBlank: !required,
|
|
31
|
+
labelStyle: label,
|
|
32
|
+
mode: 1,
|
|
33
|
+
allowAddLinkData: false,
|
|
34
|
+
items: options,
|
|
35
|
+
widgetName: `_widget_${Date.now()}`,
|
|
36
|
+
widgetNameAlias: "",
|
|
37
|
+
customCls: null,
|
|
38
|
+
funMode: "module",
|
|
39
|
+
module: null,
|
|
40
|
+
libs: [],
|
|
41
|
+
extendSet: {
|
|
42
|
+
sort: ["datahelp", "module", "formEvent"],
|
|
43
|
+
status: true,
|
|
44
|
+
triggerField: "",
|
|
45
|
+
triggerFieldMode: "none",
|
|
46
|
+
version: 1,
|
|
47
|
+
},
|
|
48
|
+
colorEnable: true, //颜色 是否开启颜色
|
|
49
|
+
},
|
|
50
|
+
description,
|
|
51
|
+
label,
|
|
52
|
+
lineWidth: parseInt(fieldWidth),
|
|
53
|
+
tab: null,
|
|
54
|
+
};
|
|
55
|
+
},
|
|
56
|
+
});
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { tool } from "ai";
|
|
3
|
+
import { buildWidgetName } from "../utils/index.js";
|
|
4
|
+
|
|
5
|
+
const incNumberRuleSchema = z.object({
|
|
6
|
+
type: z.literal("incNumber"),
|
|
7
|
+
digitsNum: z.number().min(2).max(12),
|
|
8
|
+
resetDuration: z.enum(["none", "day", "week", "month", "year"]),
|
|
9
|
+
startValue: z.number().min(0),
|
|
10
|
+
fixedLength: z.boolean(),
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
const fixedCharsRuleSchema = z.object({
|
|
14
|
+
type: z.literal("fixedChars"),
|
|
15
|
+
chars: z.string().min(1).max(100),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const widgetRuleSchema = z.object({
|
|
19
|
+
type: z.literal("widget"),
|
|
20
|
+
widgetName: z.string().min(1).max(100),
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
const serialNumberRuleSchema = z.union([
|
|
24
|
+
incNumberRuleSchema,
|
|
25
|
+
fixedCharsRuleSchema,
|
|
26
|
+
widgetRuleSchema,
|
|
27
|
+
]);
|
|
28
|
+
|
|
29
|
+
export const buildSerialNumberField = tool({
|
|
30
|
+
name: "buildSerialNumberField",
|
|
31
|
+
description: "Builds a serial number field for a form.",
|
|
32
|
+
inputSchema: z.object({
|
|
33
|
+
label: z
|
|
34
|
+
.string()
|
|
35
|
+
.min(1)
|
|
36
|
+
.max(100)
|
|
37
|
+
.describe("The label for the serial number field."),
|
|
38
|
+
description: z
|
|
39
|
+
.string()
|
|
40
|
+
.max(500)
|
|
41
|
+
.optional()
|
|
42
|
+
.describe("An optional description for the serial number field."),
|
|
43
|
+
fieldWidth: z
|
|
44
|
+
.enum(["3", "4", "6", "8", "9", "12"])
|
|
45
|
+
.default("12")
|
|
46
|
+
.describe("The width of the field in the form. total is 12."),
|
|
47
|
+
rules: z
|
|
48
|
+
.array(serialNumberRuleSchema)
|
|
49
|
+
.min(1)
|
|
50
|
+
.describe("The rules for generating the serial number."),
|
|
51
|
+
}),
|
|
52
|
+
execute: (input) => {
|
|
53
|
+
const { label, description, fieldWidth, rules } = input;
|
|
54
|
+
|
|
55
|
+
return {
|
|
56
|
+
widget: {
|
|
57
|
+
type: "sn",
|
|
58
|
+
widgetName: buildWidgetName(),
|
|
59
|
+
widgetNameAlias: "",
|
|
60
|
+
triggerEvent: 0,
|
|
61
|
+
customCls: null,
|
|
62
|
+
width: 350,
|
|
63
|
+
enable: true,
|
|
64
|
+
visible: true,
|
|
65
|
+
labelStyle: "流水号",
|
|
66
|
+
rules: rules,
|
|
67
|
+
importMode: 1, //导入模式 1 excel末尾递增 2 excel最大值递增 3 excel/表单最大值比较递增
|
|
68
|
+
},
|
|
69
|
+
description,
|
|
70
|
+
label,
|
|
71
|
+
lineWidth: parseInt(fieldWidth),
|
|
72
|
+
tab: null,
|
|
73
|
+
};
|
|
74
|
+
},
|
|
75
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { z } from 'zod';
|
|
2
|
+
import { tool } from 'ai';
|
|
3
|
+
import { buildWidgetName } from '../utils/index.js';
|
|
4
|
+
|
|
5
|
+
export const buildSignatureField = tool({
|
|
6
|
+
name: 'buildSignatureField',
|
|
7
|
+
description:
|
|
8
|
+
'Build a signature field for a form. The signature field should allow users to draw their signature using a mouse or touchscreen.',
|
|
9
|
+
inputSchema: z.object({
|
|
10
|
+
label: z.string().min(1).max(100),
|
|
11
|
+
placeholder: z.string().min(1).max(100).optional(),
|
|
12
|
+
required: z.boolean().default(false),
|
|
13
|
+
fieldWidth: z.enum(['3', '4', '6', '8', '9', '12']).default('12'),
|
|
14
|
+
description: z.string().min(1).max(100).optional(),
|
|
15
|
+
}),
|
|
16
|
+
execute: (input) => {
|
|
17
|
+
const { label, required, fieldWidth } = input;
|
|
18
|
+
return {
|
|
19
|
+
widget: {
|
|
20
|
+
type: 'signature',
|
|
21
|
+
widgetName: buildWidgetName(),
|
|
22
|
+
widgetNameAlias: '',
|
|
23
|
+
customCls: null,
|
|
24
|
+
height: 34,
|
|
25
|
+
width: 350,
|
|
26
|
+
enable: true,
|
|
27
|
+
visible: true,
|
|
28
|
+
allowBlank: !required,
|
|
29
|
+
rely: null,
|
|
30
|
+
labelStyle: label,
|
|
31
|
+
},
|
|
32
|
+
description: null,
|
|
33
|
+
label,
|
|
34
|
+
lineWidth: parseInt(fieldWidth, 10),
|
|
35
|
+
tab: null,
|
|
36
|
+
};
|
|
37
|
+
},
|
|
38
|
+
});
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { tool } from "ai";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { buildWidgetName } from "../utils/index.js";
|
|
4
|
+
|
|
5
|
+
export const buildFieldSplitline = tool({
|
|
6
|
+
name: "buildFieldSplitline",
|
|
7
|
+
description: "build a split line to split fields",
|
|
8
|
+
inputSchema: z.object({
|
|
9
|
+
label: z.string().min(1).max(100),
|
|
10
|
+
fieldWidth: z.enum(["3", "4", "6", "8", "9", "12"]).default("12"),
|
|
11
|
+
lineStyle: z
|
|
12
|
+
.enum(["default", "ghost", "dashed", "thin"])
|
|
13
|
+
.default("default"),
|
|
14
|
+
labelColor: z.string().min(1).max(7).default("#000000"),
|
|
15
|
+
lineColor: z.string().min(1).max(7).default("#000000"),
|
|
16
|
+
description: z.string().min(1).max(100).default(""),
|
|
17
|
+
}),
|
|
18
|
+
execute: (input) => {
|
|
19
|
+
const { label, fieldWidth, description, labelColor, lineColor, lineStyle } =
|
|
20
|
+
input;
|
|
21
|
+
return {
|
|
22
|
+
widget: {
|
|
23
|
+
type: "separator",
|
|
24
|
+
widgetName: buildWidgetName(),
|
|
25
|
+
widgetNameAlias: "",
|
|
26
|
+
customCls: null,
|
|
27
|
+
enable: true,
|
|
28
|
+
visible: true,
|
|
29
|
+
allowBlank: true,
|
|
30
|
+
labelStyle: label,
|
|
31
|
+
lineStyle,
|
|
32
|
+
labelColor,
|
|
33
|
+
lineColor,
|
|
34
|
+
},
|
|
35
|
+
description,
|
|
36
|
+
label,
|
|
37
|
+
lineWidth: parseInt(fieldWidth),
|
|
38
|
+
tab: null,
|
|
39
|
+
};
|
|
40
|
+
},
|
|
41
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { tool } from "ai";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { buildWidgetName } from "../utils/index.js";
|
|
4
|
+
|
|
5
|
+
export const buildTextareaField = tool({
|
|
6
|
+
name: "buildTextareaField",
|
|
7
|
+
description: "build a multiline text field",
|
|
8
|
+
inputSchema: z.object({
|
|
9
|
+
label: z.string().min(1).max(100),
|
|
10
|
+
placeholder: z.string().min(1).max(100).optional(),
|
|
11
|
+
required: z.boolean().default(false),
|
|
12
|
+
fieldWidth: z.enum(["3", "4", "6", "8", "9", "12"]).default("12"),
|
|
13
|
+
description: z.string().min(1).max(100).optional(),
|
|
14
|
+
}),
|
|
15
|
+
execute: (input) => {
|
|
16
|
+
const { label, required, fieldWidth, description } = input;
|
|
17
|
+
return {
|
|
18
|
+
widget: {
|
|
19
|
+
type: "textarea",
|
|
20
|
+
widgetName: buildWidgetName(),
|
|
21
|
+
widgetNameAlias: "",
|
|
22
|
+
triggerEvent: false,
|
|
23
|
+
customCls: null,
|
|
24
|
+
height: 140,
|
|
25
|
+
width: 734,
|
|
26
|
+
value: "",
|
|
27
|
+
enable: true,
|
|
28
|
+
visible: true,
|
|
29
|
+
allowBlank: !required,
|
|
30
|
+
labelStyle: label,
|
|
31
|
+
funMode: "module",
|
|
32
|
+
module: null,
|
|
33
|
+
libs: [],
|
|
34
|
+
extendSet: {
|
|
35
|
+
sort: ["datahelp", "module", "formEvent"],
|
|
36
|
+
status: true,
|
|
37
|
+
triggerField: "",
|
|
38
|
+
triggerFieldMode: "none",
|
|
39
|
+
version: 1,
|
|
40
|
+
},
|
|
41
|
+
noRepeat: false,
|
|
42
|
+
alertinfo: {
|
|
43
|
+
icon: "success",
|
|
44
|
+
tip: "请设置提示内容",
|
|
45
|
+
},
|
|
46
|
+
autoHeight: true, //根据内容自适应高度
|
|
47
|
+
maxLength: 5000, //限制输入最大字符数 不限制的话,整个maxLength不存在
|
|
48
|
+
},
|
|
49
|
+
description,
|
|
50
|
+
label,
|
|
51
|
+
lineWidth: parseInt(fieldWidth),
|
|
52
|
+
tab: null,
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import type { InferUITools, ToolSet, UIDataTypes, UIMessage } from "ai";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
|
|
4
|
+
import { option } from "../schema/index.js";
|
|
5
|
+
import * as tools from "../tools/index.js";
|
|
6
|
+
import {
|
|
7
|
+
getExecutableTools,
|
|
8
|
+
getToolsRequiringConfirmation,
|
|
9
|
+
} from "../utils/process-confirm-tool-call.js";
|
|
10
|
+
|
|
11
|
+
export type FormBuildTools = InferUITools<typeof tools>;
|
|
12
|
+
|
|
13
|
+
const getFieldsTool: () => ToolSet = () => {
|
|
14
|
+
const result: ToolSet = {};
|
|
15
|
+
const exectableFunNameSet = getExecutableTools(tools);
|
|
16
|
+
for (const key of Object.keys(tools)) {
|
|
17
|
+
const idx = key as keyof typeof tools;
|
|
18
|
+
if (exectableFunNameSet.has(key)) {
|
|
19
|
+
result[key] = tools[idx];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const getConfirmTool: () => ToolSet = () => {
|
|
27
|
+
const result: ToolSet = {};
|
|
28
|
+
const confirmFunNames = getToolsRequiringConfirmation(tools);
|
|
29
|
+
for (const key of Object.keys(tools)) {
|
|
30
|
+
const idx = key as keyof typeof tools;
|
|
31
|
+
if (confirmFunNames.includes(key)) {
|
|
32
|
+
result[key] = tools[idx];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
return result;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
export const fieldsTools = getFieldsTool();
|
|
40
|
+
|
|
41
|
+
export const confirmTools = getConfirmTool();
|
|
42
|
+
|
|
43
|
+
export type ConfirmTools = InferUITools<typeof confirmTools>;
|
|
44
|
+
|
|
45
|
+
export type FieldsTools = InferUITools<typeof fieldsTools>;
|
|
46
|
+
|
|
47
|
+
export type FormBuildUIMessage = UIMessage<never, UIDataTypes, FormBuildTools>;
|
|
48
|
+
|
|
49
|
+
export type Option = z.infer<typeof option>;
|
|
50
|
+
|
|
51
|
+
export interface FormBuilderContext {
|
|
52
|
+
relatedForms: Record<string, string>; // formName -> widgetId
|
|
53
|
+
}
|