@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
package/CHANGELOG.md
ADDED
package/index.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export * from "./src/form-builder/index.js";
|
|
2
|
+
export * from "./src/form-builder/consts/index.js";
|
|
3
|
+
export * from "./src/form-builder/utils/index.js";
|
|
4
|
+
export * from "./src/form-builder/types/index.js";
|
|
5
|
+
export * from "./src/form-builder/prompts/index.js";
|
|
6
|
+
export * from "./src/form-builder/model/ds.js";
|
|
7
|
+
|
|
8
|
+
export * from "./src/form-designer/index.js";
|
|
9
|
+
export * from "./src/fields-builder/index.js";
|
|
10
|
+
export * from "./src/continue-confirmer/index.js";
|
package/package.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@baishuyun/agents",
|
|
3
|
+
"version": "0.0.1",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.ts",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"keywords": [],
|
|
8
|
+
"author": "",
|
|
9
|
+
"license": "ISC",
|
|
10
|
+
"publishConfig": {
|
|
11
|
+
"access": "public"
|
|
12
|
+
},
|
|
13
|
+
"dependencies": {
|
|
14
|
+
"@ai-sdk/deepseek": "^1.0.29",
|
|
15
|
+
"@ai-sdk/openai": "^2.0.76",
|
|
16
|
+
"@ai-sdk/vercel": "^1.0.29",
|
|
17
|
+
"@ai-sdk/xai": "^2.0.39",
|
|
18
|
+
"ai": "^5.0.101",
|
|
19
|
+
"zod": "^4.1.13"
|
|
20
|
+
},
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^20.11.17",
|
|
23
|
+
"typescript": "^5.9.3",
|
|
24
|
+
"@baishuyun/types": "1.0.1",
|
|
25
|
+
"@baishuyun/typescript-config": "0.0.1"
|
|
26
|
+
},
|
|
27
|
+
"scripts": {
|
|
28
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Experimental_Agent as Agent, type StopCondition } from "ai";
|
|
2
|
+
|
|
3
|
+
import { CONTINUE_CONFIRMER_PROMPT } from "./prompt.js";
|
|
4
|
+
import { ds } from "../form-builder/model/ds.js";
|
|
5
|
+
import {
|
|
6
|
+
confirmToCreateRelatedForm,
|
|
7
|
+
confirmToCreateFieldsForRelatedForm,
|
|
8
|
+
} from "../form-builder/tools/index.js";
|
|
9
|
+
|
|
10
|
+
import { promptToCreateRelatedForm } from "../form-builder/tools/prompt-to-create-realted-form.js";
|
|
11
|
+
|
|
12
|
+
const tools = {
|
|
13
|
+
promptToCreateRelatedForm,
|
|
14
|
+
confirmToCreateFieldsForRelatedForm,
|
|
15
|
+
confirmToCreateRelatedForm,
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const done: StopCondition<typeof tools> = ({ steps }) => {
|
|
19
|
+
return steps.some((step) =>
|
|
20
|
+
step.content.some(
|
|
21
|
+
(part) =>
|
|
22
|
+
// 确认创建关联表字段,结束
|
|
23
|
+
(part.type === "tool-result" &&
|
|
24
|
+
part.toolName === "confirmToCreateFieldsForRelatedForm") ||
|
|
25
|
+
// 没有关联表,结束
|
|
26
|
+
(part.type === "tool-result" &&
|
|
27
|
+
!part.output &&
|
|
28
|
+
part.toolName === "promptToCreateRelatedForm"),
|
|
29
|
+
),
|
|
30
|
+
);
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
export type ContinueTools = typeof tools;
|
|
34
|
+
|
|
35
|
+
export const continueAgent = new Agent({
|
|
36
|
+
system: CONTINUE_CONFIRMER_PROMPT,
|
|
37
|
+
model: ds,
|
|
38
|
+
tools,
|
|
39
|
+
toolChoice: "required",
|
|
40
|
+
stopWhen: done,
|
|
41
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export const CONTINUE_CONFIRMER_PROMPT = `
|
|
2
|
+
你是表单构建提示员,根据上下文信息,判断是否需要创建关联表单。
|
|
3
|
+
|
|
4
|
+
步骤:
|
|
5
|
+
1. 如果需要创建关联表单,询问用户是否继续创建关联表单并调用 confirmToCreateRelatedForm 工具请求确认。
|
|
6
|
+
2. 如果用户确认继续创建关联表单,严格使用上下文识别到的关联表调用 confirmToCreateFieldsForRelatedForm 工具,让用户确认关联表来生成字段。
|
|
7
|
+
3. 如果上下文信息中没有明确的关联表创建需求,不要主动提及关联表创建。直接提示表单创建已完成。
|
|
8
|
+
|
|
9
|
+
要求:
|
|
10
|
+
- 不要任何总结,确保简洁,只询问用户是否继续创建关联表单。
|
|
11
|
+
`;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
export const fieldsBuilderPrompt = `
|
|
2
|
+
你是表单字段构建专家,根据上下文设计说明理解业务需求,完成表单字段构建,生成字段描述 json。
|
|
3
|
+
|
|
4
|
+
步骤:
|
|
5
|
+
1. 严格根据前文设计说明,理解业务需求
|
|
6
|
+
2. 根据需求,调用工具进行字段设计
|
|
7
|
+
3. 请求用户确认保存字段
|
|
8
|
+
|
|
9
|
+
输出:
|
|
10
|
+
- 仅包含工具的结构化输出,不包含任何其他文字说明
|
|
11
|
+
- 严格按设计说明的个数,严禁新增、遗漏字段
|
|
12
|
+
- 设计中提到要关联其他表的字段,必须使用关联字段设计工具
|
|
13
|
+
|
|
14
|
+
注意:
|
|
15
|
+
- 关联字段有最高优先级,如果上下文提到字段需要关联其他表,必须使用关联字段设计工具
|
|
16
|
+
- 涉及到合同、记录相关等字段信息时,使用关联字段
|
|
17
|
+
- 表单布局需要紧凑合理
|
|
18
|
+
- 关联表单无需重复设计字段反向关联
|
|
19
|
+
- 对于身份证号、手机号等字段,使用文本字段,并添加相应的正则表达式校验
|
|
20
|
+
- 字段设计时,注意字段的必填项和选填项
|
|
21
|
+
- 字段类型尽量使用多样化字段,避免单一字段类型
|
|
22
|
+
- 请至少使用(buildLinkDataField)工具设计一个关联字段
|
|
23
|
+
`;
|
|
24
|
+
|
|
25
|
+
export const fieldsOnlyPrompt = `
|
|
26
|
+
你是表单字段构建专家,根据上下文设计说明理解业务需求,完成表单字段构建,生成字段描述 json。设计文档中字段设计完毕后,立即停止。
|
|
27
|
+
|
|
28
|
+
输出:
|
|
29
|
+
- 仅包含工具的结构化输出,不包含任何其他文字说明
|
|
30
|
+
- 严格按设计说明的个数,严禁新增、遗漏字段
|
|
31
|
+
- 设计中提到要关联其他表的字段,必须使用关联字段设计工具
|
|
32
|
+
-
|
|
33
|
+
|
|
34
|
+
注意:
|
|
35
|
+
- 关联字段有最高优先级,如果上下文提到字段需要关联其他表,必须使用关联字段设计工具
|
|
36
|
+
- 涉及到合同、记录相关等字段信息时,使用关联字段
|
|
37
|
+
- 表单布局需要紧凑合理
|
|
38
|
+
- 关联表单无需重复设计字段反向关联
|
|
39
|
+
- 对于身份证号、手机号等字段,使用文本字段,并添加相应的正则表达式校验
|
|
40
|
+
- 字段设计时,注意字段的必填项和选填项
|
|
41
|
+
- 字段类型尽量使用多样化字段,避免单一字段类型
|
|
42
|
+
- 请至少使用(buildLinkDataField)工具设计一个关联字段
|
|
43
|
+
`;
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import { type InferUITools, type StopCondition, tool } from "ai";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { fieldsOnlyPrompt } from "./fields-builder.js";
|
|
4
|
+
import { ds } from "../form-builder/model/ds.js";
|
|
5
|
+
import { fieldsTools } from "../form-builder/types/index.js";
|
|
6
|
+
import { EnhancedAgent } from "../utils/index.js";
|
|
7
|
+
|
|
8
|
+
export const stop = tool({
|
|
9
|
+
name: "promptToStop",
|
|
10
|
+
description:
|
|
11
|
+
"stop when all fields have been built and no more fields are needed to be added.",
|
|
12
|
+
inputSchema: z.object({
|
|
13
|
+
hasRelatedForm: z.boolean(),
|
|
14
|
+
}),
|
|
15
|
+
outputSchema: z.boolean(),
|
|
16
|
+
execute: (input) => {
|
|
17
|
+
return input.hasRelatedForm;
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
const tools = {
|
|
22
|
+
...fieldsTools,
|
|
23
|
+
promptToStop: stop,
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
export type FieldsBuildTools = InferUITools<typeof tools>;
|
|
27
|
+
|
|
28
|
+
const needConfirm: StopCondition<typeof tools> = ({ steps }) => {
|
|
29
|
+
return steps.some((step) =>
|
|
30
|
+
step.content.some(
|
|
31
|
+
(part) => part.type === "tool-result" && part.toolName === "promptToStop",
|
|
32
|
+
),
|
|
33
|
+
);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export type SaveCheckedFieldsPayload = {
|
|
37
|
+
formName: string;
|
|
38
|
+
relatedForms: Record<string, string>;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
export const FieldsBuildWithConfirmAgent = new EnhancedAgent<
|
|
42
|
+
SaveCheckedFieldsPayload,
|
|
43
|
+
typeof tools
|
|
44
|
+
>(
|
|
45
|
+
{
|
|
46
|
+
system: fieldsOnlyPrompt,
|
|
47
|
+
model: ds,
|
|
48
|
+
tools,
|
|
49
|
+
toolChoice: "required",
|
|
50
|
+
stopWhen: needConfirm,
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
type: "data-confirm",
|
|
54
|
+
data: {
|
|
55
|
+
type: "tool-confirmToSaveCheckedFields",
|
|
56
|
+
payload: {
|
|
57
|
+
formName: "",
|
|
58
|
+
relatedForms: {},
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
},
|
|
62
|
+
{
|
|
63
|
+
relatedForms: {},
|
|
64
|
+
},
|
|
65
|
+
(ctx, body) => {
|
|
66
|
+
console.log("ctx", ctx);
|
|
67
|
+
return {
|
|
68
|
+
formName: body.name,
|
|
69
|
+
relatedForms: ctx.relatedForms,
|
|
70
|
+
};
|
|
71
|
+
},
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
export const createBuilder = () =>
|
|
75
|
+
new EnhancedAgent<
|
|
76
|
+
{
|
|
77
|
+
formName: string;
|
|
78
|
+
relatedForms: Record<string, string>;
|
|
79
|
+
},
|
|
80
|
+
typeof tools
|
|
81
|
+
>(
|
|
82
|
+
{
|
|
83
|
+
system: fieldsOnlyPrompt,
|
|
84
|
+
model: ds,
|
|
85
|
+
tools,
|
|
86
|
+
toolChoice: "required",
|
|
87
|
+
stopWhen: needConfirm,
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
type: "data-confirm",
|
|
91
|
+
data: {
|
|
92
|
+
type: "tool-confirmToSaveCheckedFields",
|
|
93
|
+
payload: {
|
|
94
|
+
formName: "",
|
|
95
|
+
relatedForms: {},
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
relatedForms: {},
|
|
101
|
+
},
|
|
102
|
+
(ctx, body) => {
|
|
103
|
+
console.log("ctx", ctx);
|
|
104
|
+
return {
|
|
105
|
+
formName: body.name,
|
|
106
|
+
relatedForms: ctx.relatedForms,
|
|
107
|
+
};
|
|
108
|
+
},
|
|
109
|
+
);
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { Experimental_Agent as Agent, stepCountIs } from "ai";
|
|
2
|
+
|
|
3
|
+
import { ds } from "./model/ds.js";
|
|
4
|
+
|
|
5
|
+
import * as tools from "./tools/index.js";
|
|
6
|
+
import { formBuilderPrompt } from "./prompts/index.js";
|
|
7
|
+
import {
|
|
8
|
+
getExecutableTools,
|
|
9
|
+
getToolsRequiringConfirmation,
|
|
10
|
+
} from "./utils/process-confirm-tool-call.js";
|
|
11
|
+
|
|
12
|
+
export const formBuilderAgent = new Agent({
|
|
13
|
+
system: formBuilderPrompt,
|
|
14
|
+
model: ds,
|
|
15
|
+
tools,
|
|
16
|
+
stopWhen: stepCountIs(200),
|
|
17
|
+
experimental_context: {
|
|
18
|
+
relatedForms: {},
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
export const ToolsRequiringConfirmation = getToolsRequiringConfirmation(tools);
|
|
23
|
+
|
|
24
|
+
export const ToolsCanBeExecutedDirectly = getExecutableTools(tools);
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
export const formBuilderPrompt = `
|
|
2
|
+
你是表单设计专家,根据用户业务需求,完成表单设计。请控制表单规模,合理使用关联字段,尽量进行表单拆分。
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
步骤:
|
|
6
|
+
1. 根据用户需求,创建表单,列出字段,从业务角度给出每个字段的设计说明
|
|
7
|
+
2. 调用确认工具,确认是否继续创建表单
|
|
8
|
+
3. 用户确认后,调用工具创建正式表单字段,如果字段需要关联其他表单,创建关联字段(buildLinkDataField),并记住关联表单名称
|
|
9
|
+
4. 字段设计完毕后,调用确认工具,确认是否保存字段
|
|
10
|
+
5. 如果步骤 3. 中创建了关联表单,调用确认工具,提示确认是否创建所有关联表单
|
|
11
|
+
6. 如果用户确认继续创建关联表单,调用确认工具,确认为哪一个关联表单创建字段
|
|
12
|
+
7. 如果用户确认为关联表单创建字段,回到步骤 3.,继续创建对应关联表单字段
|
|
13
|
+
|
|
14
|
+
格式:
|
|
15
|
+
- 关联字段 label 命名无需加“关联”二字,直接像设计普通字段一样命名
|
|
16
|
+
- 关联字段创建无需特定分区和说明,像设计普通字段一样设计
|
|
17
|
+
- 统一使用中文
|
|
18
|
+
- 字段设计时,不要返回分区说明,请直接用分割线工具表示分区信息
|
|
19
|
+
- 表单布局需要紧凑合理,不同区域尝试用分割线字段分割
|
|
20
|
+
- 确保回复精简,不要有多余的解释
|
|
21
|
+
|
|
22
|
+
注意:
|
|
23
|
+
- 每次设计表单字段时,就考虑到后续可能需要设计的关联表单,而不是设计新表单时再关联旧表单
|
|
24
|
+
- 关联表单无需重复设计字段反向关联
|
|
25
|
+
- 如果有多个表,主表单就应该有关联字段关联其他表单
|
|
26
|
+
- 对于身份证号、手机号等字段,使用文本字段,并添加相应的正则表达式校验
|
|
27
|
+
- 字段设计时,注意字段的必填项和选填项
|
|
28
|
+
- 字段类型尽量使用多样化字段,避免单一字段类型
|
|
29
|
+
- 尽量进行表单拆分,避免单个表单字段过多,使用关联字段连接不同表单
|
|
30
|
+
- 涉及到合同、人员、记录等信息时,使用关联字段
|
|
31
|
+
- 完成后,不需要总结
|
|
32
|
+
`;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { tool } from "ai";
|
|
3
|
+
import { buildWidgetName } from "../utils/index.js";
|
|
4
|
+
|
|
5
|
+
export const buildAddressField = tool({
|
|
6
|
+
name: "buildAddressField",
|
|
7
|
+
description:
|
|
8
|
+
"Builds a form field for collecting address information from users.",
|
|
9
|
+
inputSchema: z.object({
|
|
10
|
+
label: z.string().min(1).max(100),
|
|
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
|
+
addressMode: z
|
|
15
|
+
.enum(["all", "provinceCityDistrict", "provinceCity", "provinceOnly"])
|
|
16
|
+
.default("all"),
|
|
17
|
+
}),
|
|
18
|
+
execute: (input) => {
|
|
19
|
+
const { label, required, fieldWidth, description, addressMode } = input;
|
|
20
|
+
const modeMap: Record<string, string> = {
|
|
21
|
+
all: "pcda",
|
|
22
|
+
provinceCityDistrict: "pcd",
|
|
23
|
+
provinceCity: "pc",
|
|
24
|
+
provinceOnly: "p",
|
|
25
|
+
};
|
|
26
|
+
return {
|
|
27
|
+
widget: {
|
|
28
|
+
type: "address",
|
|
29
|
+
widgetName: buildWidgetName(),
|
|
30
|
+
widgetNameAlias: "",
|
|
31
|
+
customCls: null,
|
|
32
|
+
width: 720,
|
|
33
|
+
enable: true,
|
|
34
|
+
visible: true,
|
|
35
|
+
allowBlank: !required,
|
|
36
|
+
labelStyle: label,
|
|
37
|
+
funMode: "module",
|
|
38
|
+
module: null,
|
|
39
|
+
libs: [],
|
|
40
|
+
extendSet: {
|
|
41
|
+
sort: ["datahelp", "module", "formEvent"],
|
|
42
|
+
status: true,
|
|
43
|
+
triggerField: "",
|
|
44
|
+
triggerFieldMode: "none",
|
|
45
|
+
version: 1,
|
|
46
|
+
},
|
|
47
|
+
needDetail: true,
|
|
48
|
+
format: modeMap[addressMode] || "all",
|
|
49
|
+
eventMode: 1, //公式联动触发模式 1 默认,省市县/详细地址内容改变都触发 2 只有省市县改变才触发 3 只有详细地址改变才触发
|
|
50
|
+
seleceMapAddress: true, //开启经纬度定位
|
|
51
|
+
},
|
|
52
|
+
description,
|
|
53
|
+
label,
|
|
54
|
+
lineWidth: parseInt(fieldWidth, 10),
|
|
55
|
+
tab: null,
|
|
56
|
+
};
|
|
57
|
+
},
|
|
58
|
+
});
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { tool } from "ai";
|
|
3
|
+
import { buildWidgetName } from "../utils/index.js";
|
|
4
|
+
|
|
5
|
+
export const buildAttachmentField = tool({
|
|
6
|
+
name: "buildAttachmentField",
|
|
7
|
+
description: "Builds an attachment field for a form.",
|
|
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
|
+
fileType: z
|
|
15
|
+
.enum([
|
|
16
|
+
"exe",
|
|
17
|
+
"pdf",
|
|
18
|
+
"doc",
|
|
19
|
+
"docx",
|
|
20
|
+
"xls",
|
|
21
|
+
"xlsx",
|
|
22
|
+
"ppt",
|
|
23
|
+
"pptx",
|
|
24
|
+
"txt",
|
|
25
|
+
"jpg",
|
|
26
|
+
"jpeg",
|
|
27
|
+
"png",
|
|
28
|
+
"gif",
|
|
29
|
+
"bmp",
|
|
30
|
+
])
|
|
31
|
+
.array()
|
|
32
|
+
.optional()
|
|
33
|
+
.default(["exe", "pdf"]),
|
|
34
|
+
}),
|
|
35
|
+
execute: (input) => {
|
|
36
|
+
const { label, required, fieldWidth, description, fileType } = input;
|
|
37
|
+
return {
|
|
38
|
+
widget: {
|
|
39
|
+
type: "upload",
|
|
40
|
+
widgetName: buildWidgetName(),
|
|
41
|
+
widgetNameAlias: "",
|
|
42
|
+
customCls: null,
|
|
43
|
+
enable: true,
|
|
44
|
+
visible: true,
|
|
45
|
+
allowBlank: !required,
|
|
46
|
+
labelStyle: label,
|
|
47
|
+
maxFileCount: 50, //允许多文件上传 1为不可以 50为可以
|
|
48
|
+
download: true, //打包下载
|
|
49
|
+
is_file_down: true, //操作权限 可下载
|
|
50
|
+
check_image_exif: true, //照片支持查看EXIF扩展信息
|
|
51
|
+
online_edit: true, //允许文档在线编辑
|
|
52
|
+
online_edit_record: true, //是否查看协作记录
|
|
53
|
+
fileSizeLimit: 10485760, //设置单个文件大小上限,单位是字节,范围 1M-20M
|
|
54
|
+
fileType,
|
|
55
|
+
},
|
|
56
|
+
description,
|
|
57
|
+
label,
|
|
58
|
+
lineWidth: parseInt(fieldWidth),
|
|
59
|
+
tab: null,
|
|
60
|
+
};
|
|
61
|
+
},
|
|
62
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { tool } from "ai";
|
|
3
|
+
import { buildWidgetName } from "../utils/index.js";
|
|
4
|
+
|
|
5
|
+
export const buildButtonField = tool({
|
|
6
|
+
name: "buildButtonField",
|
|
7
|
+
description: "build a button field",
|
|
8
|
+
inputSchema: z.object({
|
|
9
|
+
label: z.string().min(1).max(100),
|
|
10
|
+
theme: z.enum(["primary", "bordered", "ghost"]).default("primary"),
|
|
11
|
+
buttonText: z.string().min(1).max(100),
|
|
12
|
+
backgroundColor: z.string().min(1).max(7),
|
|
13
|
+
required: z.boolean().default(false),
|
|
14
|
+
fieldWidth: z.enum(["3", "4", "6", "8", "9", "12"]).default("12"),
|
|
15
|
+
description: z.string().min(1).max(100).default(""),
|
|
16
|
+
}),
|
|
17
|
+
execute: (input) => {
|
|
18
|
+
const {
|
|
19
|
+
label,
|
|
20
|
+
buttonText,
|
|
21
|
+
backgroundColor,
|
|
22
|
+
theme,
|
|
23
|
+
required,
|
|
24
|
+
fieldWidth,
|
|
25
|
+
description,
|
|
26
|
+
} = input;
|
|
27
|
+
const themeMap = {
|
|
28
|
+
primary: "default",
|
|
29
|
+
bordered: "style1",
|
|
30
|
+
ghost: "none",
|
|
31
|
+
};
|
|
32
|
+
return {
|
|
33
|
+
widget: {
|
|
34
|
+
type: "button",
|
|
35
|
+
widgetName: buildWidgetName(),
|
|
36
|
+
widgetNameAlias: "",
|
|
37
|
+
triggerEvent: 0,
|
|
38
|
+
customCls: null,
|
|
39
|
+
height: 36,
|
|
40
|
+
width: 350,
|
|
41
|
+
text: buttonText,
|
|
42
|
+
enable: true,
|
|
43
|
+
visible: true,
|
|
44
|
+
allowBlank: !required,
|
|
45
|
+
labelStyle: label,
|
|
46
|
+
extendSet: {
|
|
47
|
+
sort: ["datahelp", "module", "formEvent"],
|
|
48
|
+
status: true,
|
|
49
|
+
triggerField: "",
|
|
50
|
+
triggerFieldMode: "none",
|
|
51
|
+
funMode: "popupreport",
|
|
52
|
+
},
|
|
53
|
+
background: {
|
|
54
|
+
//颜色
|
|
55
|
+
mode: "color",
|
|
56
|
+
color: backgroundColor,
|
|
57
|
+
position: "center",
|
|
58
|
+
},
|
|
59
|
+
mode: "all", //模式 all 扩展 popupreport 弹出报表 popupform 弹出表单 print 页面打印 popuppage 弹出外部网页
|
|
60
|
+
theme: themeMap[theme] || "default", //风格 default 默认,有边框有底色 style1 有边框无底色 none 无边框无底色
|
|
61
|
+
eventAlert: false, //是否显示提醒框
|
|
62
|
+
alertinfo: {
|
|
63
|
+
icon: "success",
|
|
64
|
+
tip: "请设置提示内容",
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
description,
|
|
68
|
+
label,
|
|
69
|
+
lineWidth: parseInt(fieldWidth),
|
|
70
|
+
tab: null,
|
|
71
|
+
};
|
|
72
|
+
},
|
|
73
|
+
});
|
|
@@ -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 buildCheckBoxGroupField = tool({
|
|
6
|
+
name: "buildCheckBoxGroupField",
|
|
7
|
+
description: "build a check boxk group field",
|
|
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
|
+
description: z.string().min(1).max(100).optional(),
|
|
12
|
+
required: z.boolean().default(false),
|
|
13
|
+
layout: z.enum(["horizontal", "vertical"]).default("horizontal"),
|
|
14
|
+
options: z.array(
|
|
15
|
+
z.object({
|
|
16
|
+
value: z.string().min(1).max(100),
|
|
17
|
+
text: z.string().min(1).max(100),
|
|
18
|
+
color: z.string().min(1).max(7),
|
|
19
|
+
}),
|
|
20
|
+
),
|
|
21
|
+
}),
|
|
22
|
+
execute: (input) => {
|
|
23
|
+
const { label, fieldWidth, description, options, required, layout } = input;
|
|
24
|
+
return {
|
|
25
|
+
widget: {
|
|
26
|
+
type: "checkboxgroup",
|
|
27
|
+
widgetName: buildWidgetName(),
|
|
28
|
+
widgetNameAlias: "",
|
|
29
|
+
customCls: null,
|
|
30
|
+
enable: true,
|
|
31
|
+
visible: true,
|
|
32
|
+
allowBlank: !required,
|
|
33
|
+
labelStyle: label,
|
|
34
|
+
funMode: "module",
|
|
35
|
+
module: null,
|
|
36
|
+
libs: [],
|
|
37
|
+
extendSet: {
|
|
38
|
+
sort: ["datahelp", "module", "formEvent"],
|
|
39
|
+
status: true,
|
|
40
|
+
triggerField: "",
|
|
41
|
+
triggerFieldMode: "none",
|
|
42
|
+
version: 1,
|
|
43
|
+
},
|
|
44
|
+
items: options,
|
|
45
|
+
colorEnable: true, //颜色 是否开启颜色
|
|
46
|
+
layout,
|
|
47
|
+
allowAddOptions: false, //允许成员填写时添加新选项
|
|
48
|
+
},
|
|
49
|
+
description,
|
|
50
|
+
label,
|
|
51
|
+
lineWidth: parseInt(fieldWidth),
|
|
52
|
+
tab: null,
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { tool } from "ai";
|
|
3
|
+
|
|
4
|
+
export const confirmToCreateFieldsForRelatedForm = tool({
|
|
5
|
+
name: "confirmToCreateFieldsForRelatedForm",
|
|
6
|
+
description: "require user confirm to create fields for related forms.",
|
|
7
|
+
inputSchema: z.object({
|
|
8
|
+
forms: z.array(
|
|
9
|
+
z.object({
|
|
10
|
+
title: z.string().min(2).max(100),
|
|
11
|
+
description: z.string().min(2).max(500),
|
|
12
|
+
}),
|
|
13
|
+
),
|
|
14
|
+
}),
|
|
15
|
+
outputSchema: z.string(),
|
|
16
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { tool } from "ai";
|
|
3
|
+
|
|
4
|
+
export const confirmToCreateForm = tool({
|
|
5
|
+
name: "confirmToCreateForm",
|
|
6
|
+
description: "confirm to start creating a form",
|
|
7
|
+
inputSchema: z.object({
|
|
8
|
+
formName: z.string().min(2).max(100),
|
|
9
|
+
}),
|
|
10
|
+
outputSchema: z.string(),
|
|
11
|
+
});
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { tool } from "ai";
|
|
3
|
+
|
|
4
|
+
export const confirmToCreateRelatedForm = tool({
|
|
5
|
+
name: "confirmToCreateRelatedForm",
|
|
6
|
+
description: "require user confirm to create following related forms.",
|
|
7
|
+
inputSchema: z.object({
|
|
8
|
+
forms: z.array(
|
|
9
|
+
z.object({
|
|
10
|
+
title: z.string().min(2).max(100),
|
|
11
|
+
description: z.string().min(2).max(500),
|
|
12
|
+
}),
|
|
13
|
+
),
|
|
14
|
+
}),
|
|
15
|
+
outputSchema: z.string(),
|
|
16
|
+
});
|