@blocklet/pages-kit-agents 0.5.40 → 0.5.42
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/lib/cjs/agents/template-designer.d.ts +13 -0
- package/lib/cjs/agents/template-designer.js +67 -0
- package/lib/cjs/agents/template-generator.d.ts +18 -0
- package/lib/cjs/agents/template-generator.js +186 -0
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/component-tuils.d.ts +12 -0
- package/lib/cjs/utils/component-tuils.js +141 -0
- package/lib/cjs/utils/file-utils.d.ts +23 -0
- package/lib/cjs/utils/file-utils.js +77 -0
- package/lib/cjs/workflow-agents/reflection-agent.d.ts +16 -0
- package/lib/cjs/workflow-agents/reflection-agent.js +38 -0
- package/lib/esm/agents/template-designer.d.ts +13 -0
- package/lib/esm/agents/template-designer.js +61 -0
- package/lib/esm/agents/template-generator.d.ts +18 -0
- package/lib/esm/agents/template-generator.js +180 -0
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/component-tuils.d.ts +12 -0
- package/lib/esm/utils/component-tuils.js +136 -0
- package/lib/esm/utils/file-utils.d.ts +23 -0
- package/lib/esm/utils/file-utils.js +74 -0
- package/lib/esm/workflow-agents/reflection-agent.d.ts +16 -0
- package/lib/esm/workflow-agents/reflection-agent.js +34 -0
- package/lib/types/agents/template-designer.d.ts +13 -0
- package/lib/types/agents/template-generator.d.ts +18 -0
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/utils/component-tuils.d.ts +12 -0
- package/lib/types/utils/file-utils.d.ts +23 -0
- package/lib/types/workflow-agents/reflection-agent.d.ts +16 -0
- package/package.json +11 -8
- package/workflow-cli.ts +132 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { AIAgent } from '@aigne/core';
|
|
2
|
+
/**
|
|
3
|
+
* 用于设计页面结构的 workflow
|
|
4
|
+
* 1. AI 根据拿到的 collectorResult 和 componentList,生成一个页面设计模板,需要用 ASCII 图画出来,给到用户确认
|
|
5
|
+
* 2. 用户确认后,AI 保存页面设计模板,并返回页面设计模板
|
|
6
|
+
*/
|
|
7
|
+
export declare const designerAgent: AIAgent<{
|
|
8
|
+
collectResult: string;
|
|
9
|
+
}, {
|
|
10
|
+
ascii: string;
|
|
11
|
+
$message: string;
|
|
12
|
+
filteredComponentList: string[];
|
|
13
|
+
}>;
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.designerAgent = void 0;
|
|
7
|
+
const index_js_1 = require("@aigne/agent-library/default-memory/index.js");
|
|
8
|
+
const core_1 = require("@aigne/core");
|
|
9
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
10
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
11
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
12
|
+
const zod_1 = require("zod");
|
|
13
|
+
const { OPENAI_API_KEY } = process.env;
|
|
14
|
+
(0, node_assert_1.default)(OPENAI_API_KEY, 'Please set the OPENAI_API_KEY environment variable');
|
|
15
|
+
const memory = new index_js_1.DefaultMemory({
|
|
16
|
+
storage: {
|
|
17
|
+
url: 'file:./dbs/memory.db', // Path to store memory data, such as 'file:./memory.db'
|
|
18
|
+
},
|
|
19
|
+
});
|
|
20
|
+
const componentList = node_fs_1.default.readFileSync(node_path_1.default.join(__dirname, '../data-sources/pages-kit-component-list.yaml'), 'utf-8');
|
|
21
|
+
const agentInstructions = `
|
|
22
|
+
你是一个专业的页面设计师,名叫小设。你的任务是根据整理好的用户需求,设计一个页面结构。
|
|
23
|
+
|
|
24
|
+
设计规则:
|
|
25
|
+
1. 设计的页面结构,需要画出 ASCII 图,给到用户确认
|
|
26
|
+
2. 需要在 ASCII 图上,标注出结构和放什么内容
|
|
27
|
+
3. 需要在限定的组件列表中,选择合适的组件
|
|
28
|
+
4. 具有把拼装复合组件的能力,如果涉及到复合组件,请将他们框选起来,标注出复合组件的结构
|
|
29
|
+
5. 不用告诉用户这是 ASCII 图,用户不关心,用户只关心页面设计模板
|
|
30
|
+
6. 你只能使用支持的组件列表中的组件,不能使用其他组件
|
|
31
|
+
7. 如果在没有找到合适的组件,请使用拼装组件的能力,将多个组件拼装起来,形成一个复合组件
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
支持使用的组件列表:
|
|
35
|
+
<component-list>
|
|
36
|
+
${componentList}
|
|
37
|
+
</component-list>
|
|
38
|
+
|
|
39
|
+
整理好的用户需求:
|
|
40
|
+
<collect-result>
|
|
41
|
+
{{collectResult}}
|
|
42
|
+
</collect-result>
|
|
43
|
+
|
|
44
|
+
用户反馈:
|
|
45
|
+
<<< {{userFeedBack}} >>>
|
|
46
|
+
`;
|
|
47
|
+
/**
|
|
48
|
+
* 用于设计页面结构的 workflow
|
|
49
|
+
* 1. AI 根据拿到的 collectorResult 和 componentList,生成一个页面设计模板,需要用 ASCII 图画出来,给到用户确认
|
|
50
|
+
* 2. 用户确认后,AI 保存页面设计模板,并返回页面设计模板
|
|
51
|
+
*/
|
|
52
|
+
exports.designerAgent = core_1.AIAgent.from({
|
|
53
|
+
name: 'designer',
|
|
54
|
+
description: '设计页面结构,并且给到用户确认',
|
|
55
|
+
inputSchema: zod_1.z.object({
|
|
56
|
+
collectResult: zod_1.z.string().describe('整理好的用户需求'),
|
|
57
|
+
}),
|
|
58
|
+
outputSchema: zod_1.z.object({
|
|
59
|
+
ascii: zod_1.z.string().describe('ASCII 图'),
|
|
60
|
+
$message: zod_1.z.string().describe('给到用户的信息,用于用户确认,不需要包含 ASCII 图'),
|
|
61
|
+
filteredComponentList: zod_1.z.array(zod_1.z.string()).describe('过滤后的组件列表,只包含页面设计需要的组件'),
|
|
62
|
+
}),
|
|
63
|
+
memory,
|
|
64
|
+
instructions: `
|
|
65
|
+
${agentInstructions}
|
|
66
|
+
`,
|
|
67
|
+
});
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { FunctionAgent } from '@aigne/core';
|
|
2
|
+
import { ReflectionAgent } from '../workflow-agents/reflection-agent.js';
|
|
3
|
+
export declare const generatorAgentWithReflection: ReflectionAgent<{
|
|
4
|
+
ascii: string;
|
|
5
|
+
collectResult: string;
|
|
6
|
+
$message: string;
|
|
7
|
+
filteredComponentList: string[];
|
|
8
|
+
feedback?: string | null | undefined;
|
|
9
|
+
}, {
|
|
10
|
+
isApproved: boolean;
|
|
11
|
+
feedback: string;
|
|
12
|
+
}>;
|
|
13
|
+
export declare const saveYamlAgent: FunctionAgent<{
|
|
14
|
+
$message: string;
|
|
15
|
+
yaml: string;
|
|
16
|
+
}, {
|
|
17
|
+
$message: string;
|
|
18
|
+
} & import("@aigne/core").Message>;
|
|
@@ -0,0 +1,186 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.saveYamlAgent = exports.generatorAgentWithReflection = void 0;
|
|
7
|
+
const index_js_1 = require("@aigne/agent-library/default-memory/index.js");
|
|
8
|
+
const core_1 = require("@aigne/core");
|
|
9
|
+
const node_assert_1 = __importDefault(require("node:assert"));
|
|
10
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
11
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
12
|
+
const zod_1 = require("zod");
|
|
13
|
+
const reflection_agent_js_1 = require("../workflow-agents/reflection-agent.js");
|
|
14
|
+
const { OPENAI_API_KEY } = process.env;
|
|
15
|
+
(0, node_assert_1.default)(OPENAI_API_KEY, 'Please set the OPENAI_API_KEY environment variable');
|
|
16
|
+
const memory = new index_js_1.DefaultMemory({
|
|
17
|
+
storage: {
|
|
18
|
+
url: 'file:./dbs/memory.db', // Path to store memory data, such as 'file:./memory.db'
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
const componentList = node_fs_1.default.readFileSync(node_path_1.default.join(__dirname, '../data-sources/pages-kit-component-list.yaml'), 'utf-8');
|
|
22
|
+
const pagesKitTemplateRule = node_fs_1.default.readFileSync(node_path_1.default.join(__dirname, '../data-sources/pages-kit-template-rule.md'), 'utf-8');
|
|
23
|
+
const generatorAgentInstructions = `
|
|
24
|
+
你是专业的 Pages Kit 模板工程师小猿。你的任务是根据用户需求和设计师的页面设计模板,生成完全符合 Pages Kit 框架规范的 YAML 结构。
|
|
25
|
+
|
|
26
|
+
## 核心职责
|
|
27
|
+
基于提供的用户需求、设计师ASCII图和组件列表,生成可直接使用的 Pages Kit YAML 模板。
|
|
28
|
+
|
|
29
|
+
## 严格遵循的编码原则
|
|
30
|
+
1. **结构完整性**: 必须完全符合 Pages Kit 框架的 YAML Schema 结构规范
|
|
31
|
+
2. **设计一致性**: 严格按照设计师的页面设计模板实现,不得擅自修改布局和结构
|
|
32
|
+
3. **组件组合**: 当单个组件无法满足设计需求时,使用多个组件组合实现复杂布局
|
|
33
|
+
4. **ID唯一性**: 所有涉及 id 的属性值必须唯一,使用16位随机字符串(字母+数字混合,无语义化)
|
|
34
|
+
5. **语义准确性**: 确保组件选择和属性配置准确反映用户需求和设计意图
|
|
35
|
+
|
|
36
|
+
## 输出要求
|
|
37
|
+
- 生成完整可执行的 YAML 结构
|
|
38
|
+
- 在 $message 中简洑说明实现思路和关键设计决策
|
|
39
|
+
- 确保所有组件都来自提供的过滤组件列表
|
|
40
|
+
- 必须返回所有输入字段以保持数据流的完整性
|
|
41
|
+
|
|
42
|
+
## 技术规范参考
|
|
43
|
+
<pages-kit-template-rule>
|
|
44
|
+
${pagesKitTemplateRule}
|
|
45
|
+
</pages-kit-template-rule>
|
|
46
|
+
|
|
47
|
+
## 全部可用组件
|
|
48
|
+
<component-list>
|
|
49
|
+
${componentList}
|
|
50
|
+
</component-list>
|
|
51
|
+
|
|
52
|
+
## 当前任务输入
|
|
53
|
+
用户需求:
|
|
54
|
+
<collect-result>
|
|
55
|
+
{{collectResult}}
|
|
56
|
+
</collect-result>
|
|
57
|
+
|
|
58
|
+
设计师页面模板:
|
|
59
|
+
<ascii>
|
|
60
|
+
{{ascii}}
|
|
61
|
+
</ascii>
|
|
62
|
+
|
|
63
|
+
本次可使用的组件(已过滤):
|
|
64
|
+
<filtered-component-list>
|
|
65
|
+
{{filteredComponentList}}
|
|
66
|
+
</filtered-component-list>
|
|
67
|
+
|
|
68
|
+
<#if feedback>
|
|
69
|
+
## 验证反馈
|
|
70
|
+
上一次生成的YAML结构存在以下问题,请根据反馈进行修正:
|
|
71
|
+
<feedback>
|
|
72
|
+
{{feedback}}
|
|
73
|
+
</feedback>
|
|
74
|
+
</#if>
|
|
75
|
+
|
|
76
|
+
<#if yaml>
|
|
77
|
+
## 上一次生成的YAML结构
|
|
78
|
+
<yaml>
|
|
79
|
+
{{yaml}}
|
|
80
|
+
</yaml>
|
|
81
|
+
</#if>
|
|
82
|
+
|
|
83
|
+
请严格按照上述要求生成YAML结构,并确保返回所有必需的字段。`;
|
|
84
|
+
const validatorAgentInstructions = `
|
|
85
|
+
你是专业的 Pages Kit 模板验证专家小验。你的任务是严格验证生成的 YAML 结构是否完全符合 Pages Kit 框架规范。
|
|
86
|
+
|
|
87
|
+
## 核心职责
|
|
88
|
+
对生成的 YAML 模板进行全面技术验证,确保其在 Pages Kit 框架中能够正确运行。
|
|
89
|
+
|
|
90
|
+
## 验证检查清单
|
|
91
|
+
1. **结构规范性**: 严格检查是否完全符合 Pages Kit 框架的 YAML Schema 结构
|
|
92
|
+
2. **语法正确性**: 验证 YAML 语法格式是否正确,缩进、字段名等是否准确
|
|
93
|
+
3. **ID唯一性**: 所有 id 属性值必须唯一且为16位随机字符串(字母数字混合,非语义化)
|
|
94
|
+
4. **组件合法性**: 确认所有使用的组件都在允许的组件列表中
|
|
95
|
+
5. **属性完整性**: 检查必需属性是否全部提供,可选属性是否合理
|
|
96
|
+
6. **嵌套层级**: 验证嵌套结构深度和层级关系是否正确
|
|
97
|
+
7. **数据类型**: 确认各字段的数据类型符合规范要求
|
|
98
|
+
|
|
99
|
+
## 技术规范依据
|
|
100
|
+
<pages-kit-template-rule>
|
|
101
|
+
${pagesKitTemplateRule}
|
|
102
|
+
</pages-kit-template-rule>
|
|
103
|
+
|
|
104
|
+
## 验证输入
|
|
105
|
+
用户需求:{{collectResult}}
|
|
106
|
+
设计师ASCII图:{{ascii}}
|
|
107
|
+
可用组件列表:{{filteredComponentList}}
|
|
108
|
+
生成的YAML:{{yaml}}
|
|
109
|
+
|
|
110
|
+
## 验证原则
|
|
111
|
+
- 零容忍态度对待规范违规
|
|
112
|
+
- 优先保证模板的可执行性和稳定性
|
|
113
|
+
- 发现问题时提供清晰的改进建议
|
|
114
|
+
|
|
115
|
+
请对提供的 YAML 结构进行全面验证。`;
|
|
116
|
+
/**
|
|
117
|
+
* 用于实现页面结构的 workflow
|
|
118
|
+
* 1. AI 根据拿到的 ASCII 图,整理好的用户需求,支持使用的组件列表,生成一个 Yaml 结构,给到验证器验证
|
|
119
|
+
* 2. 使用反思工作流,AI 自动根据验证器反馈,自动修改 Yaml 结构,直到验证器验证通过
|
|
120
|
+
* 3. 验证器验证通过后,AI 保存 Yaml 结构,并返回 Yaml 结构
|
|
121
|
+
*/
|
|
122
|
+
const generatorAgent = core_1.AIAgent.from({
|
|
123
|
+
name: 'generator',
|
|
124
|
+
description: '实现页面结构,并且给到用户确认',
|
|
125
|
+
inputSchema: zod_1.z.object({
|
|
126
|
+
ascii: zod_1.z.string().describe('ASCII 图'),
|
|
127
|
+
collectResult: zod_1.z.string().describe('整理好的用户需求'),
|
|
128
|
+
filteredComponentList: zod_1.z.array(zod_1.z.string()).describe('过滤后的组件列表,只包含页面设计需要的组件'),
|
|
129
|
+
$message: zod_1.z.string(),
|
|
130
|
+
feedback: zod_1.z.string().nullish().describe('Feedback from the reviewer'),
|
|
131
|
+
}),
|
|
132
|
+
outputSchema: zod_1.z.object({
|
|
133
|
+
ascii: zod_1.z.string().describe('ASCII 图'),
|
|
134
|
+
collectResult: zod_1.z.string().describe('整理好的用户需求'),
|
|
135
|
+
filteredComponentList: zod_1.z.array(zod_1.z.string()).describe('过滤后的组件列表,只包含页面设计需要的组件'),
|
|
136
|
+
$message: zod_1.z.string().describe('给到用户的信息,用于用户确认'),
|
|
137
|
+
yaml: zod_1.z.string().describe('Yaml 结构'),
|
|
138
|
+
feedback: zod_1.z.string().nullish().describe('Feedback from the reviewer'),
|
|
139
|
+
}),
|
|
140
|
+
memory,
|
|
141
|
+
instructions: `
|
|
142
|
+
${generatorAgentInstructions}
|
|
143
|
+
`,
|
|
144
|
+
});
|
|
145
|
+
const validatorAgent = core_1.AIAgent.from({
|
|
146
|
+
name: 'validator',
|
|
147
|
+
description: '验证 Yaml 结构符合 Pages Kit 框架的 Yaml Schema 结构',
|
|
148
|
+
inputSchema: zod_1.z.object({
|
|
149
|
+
ascii: zod_1.z.string().describe('ASCII 图'),
|
|
150
|
+
collectResult: zod_1.z.string().describe('整理好的用户需求'),
|
|
151
|
+
filteredComponentList: zod_1.z.array(zod_1.z.string()).describe('过滤后的组件列表,只包含页面设计需要的组件'),
|
|
152
|
+
$message: zod_1.z.string(),
|
|
153
|
+
yaml: zod_1.z.string().describe('Yaml 结构'),
|
|
154
|
+
feedback: zod_1.z.string().nullish().describe('Feedback from the reviewer'),
|
|
155
|
+
}),
|
|
156
|
+
memory,
|
|
157
|
+
outputSchema: zod_1.z.object({
|
|
158
|
+
isApproved: zod_1.z.boolean().describe('是否符合 Pages Kit 框架的 Yaml Schema 结构'),
|
|
159
|
+
feedback: zod_1.z.string().describe('Feedback for the markdown'),
|
|
160
|
+
}),
|
|
161
|
+
instructions: `
|
|
162
|
+
${validatorAgentInstructions}
|
|
163
|
+
`,
|
|
164
|
+
});
|
|
165
|
+
exports.generatorAgentWithReflection = new reflection_agent_js_1.ReflectionAgent({
|
|
166
|
+
name: 'generator-with-reflection',
|
|
167
|
+
maxIterations: 3,
|
|
168
|
+
editor: generatorAgent,
|
|
169
|
+
reviewer: validatorAgent,
|
|
170
|
+
isApproved: (result) => result.isApproved,
|
|
171
|
+
});
|
|
172
|
+
exports.saveYamlAgent = core_1.FunctionAgent.from({
|
|
173
|
+
inputSchema: zod_1.z.object({
|
|
174
|
+
$message: zod_1.z.string().describe('给到用户的信息,用于用户确认'),
|
|
175
|
+
yaml: zod_1.z.string().describe('Yaml 结构'),
|
|
176
|
+
}),
|
|
177
|
+
name: 'save-yaml',
|
|
178
|
+
description: '保存 Yaml 结构到文件',
|
|
179
|
+
async process({ yaml }) {
|
|
180
|
+
const templateName = new Date().toISOString().replace(/[:.]/g, '-');
|
|
181
|
+
const filePath = node_path_1.default.join(__dirname, `../test-templates/template-${templateName}.yaml`);
|
|
182
|
+
// 把 yaml 结构保存到文件
|
|
183
|
+
node_fs_1.default.writeFileSync(filePath, yaml);
|
|
184
|
+
return (0, core_1.createMessage)(`Yaml 结构已保存到 ${filePath}`);
|
|
185
|
+
},
|
|
186
|
+
});
|