@blocklet/pages-kit-agents 0.5.47 → 0.5.48
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/.env.local.example +7 -0
- package/cli.ts +1 -1
- package/index.ts +0 -1
- package/lib/cjs/agents/content-reviwer.d.ts +1 -1
- package/lib/cjs/agents/multi-agent-page-writer.js +3 -10
- package/lib/cjs/agents/orchestrator/index.d.ts +115 -0
- package/lib/cjs/agents/orchestrator/index.js +264 -0
- package/lib/cjs/agents/orchestrator/orchestrator-prompts.d.ts +130 -0
- package/lib/cjs/agents/orchestrator/orchestrator-prompts.js +135 -0
- package/lib/cjs/agents/page-metadata-generator.d.ts +1 -1
- package/lib/cjs/agents/page-metadata-generator.js +4 -1
- package/lib/cjs/agents/page-structure-planner.d.ts +59 -22
- package/lib/cjs/agents/page-structure-planner.js +108 -78
- package/lib/cjs/agents/router-datacache-generator.d.ts +24 -0
- package/lib/cjs/agents/router-datacache-generator.js +78 -0
- package/lib/cjs/agents/section-content-generator.js +11 -8
- package/lib/cjs/agents/template-designer.d.ts +7 -6
- package/lib/cjs/agents/template-designer.js +22 -17
- package/lib/cjs/agents/template-generator.d.ts +55 -7
- package/lib/cjs/agents/template-generator.js +99 -89
- package/lib/cjs/index.d.ts +0 -1
- package/lib/cjs/index.js +0 -1
- package/lib/cjs/prompts/fs-memory-recorder.md +59 -0
- package/lib/cjs/prompts/fs-memory-retriever.md +30 -0
- package/lib/cjs/prompts/html-generator.md +91 -0
- package/lib/cjs/prompts/page-structure-planner-prompt.md +47 -0
- package/lib/cjs/prompts/page-structure-validator-prompt.md +78 -0
- package/lib/cjs/prompts/pages-kit-template-rule.md +491 -0
- package/lib/cjs/prompts/site-map-generator.md +126 -0
- package/lib/cjs/skill-agents/parse-component-list-agent.d.ts +100 -0
- package/lib/cjs/skill-agents/parse-component-list-agent.js +198 -0
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/agent-utils.d.ts +4 -0
- package/lib/cjs/utils/agent-utils.js +106 -0
- package/lib/esm/agents/content-reviwer.d.ts +1 -1
- package/lib/esm/agents/multi-agent-page-writer.js +5 -12
- package/lib/esm/agents/orchestrator/index.d.ts +115 -0
- package/lib/esm/agents/orchestrator/index.js +243 -0
- package/lib/esm/agents/orchestrator/orchestrator-prompts.d.ts +130 -0
- package/lib/esm/agents/orchestrator/orchestrator-prompts.js +131 -0
- package/lib/esm/agents/page-metadata-generator.d.ts +1 -1
- package/lib/esm/agents/page-metadata-generator.js +4 -1
- package/lib/esm/agents/page-structure-planner.d.ts +59 -22
- package/lib/esm/agents/page-structure-planner.js +105 -78
- package/lib/esm/agents/router-datacache-generator.d.ts +24 -0
- package/lib/esm/agents/router-datacache-generator.js +72 -0
- package/lib/esm/agents/section-content-generator.js +11 -8
- package/lib/esm/agents/template-designer.d.ts +7 -6
- package/lib/esm/agents/template-designer.js +22 -14
- package/lib/esm/agents/template-generator.d.ts +55 -7
- package/lib/esm/agents/template-generator.js +98 -88
- package/lib/esm/index.d.ts +0 -1
- package/lib/esm/index.js +0 -1
- package/lib/esm/prompts/fs-memory-recorder.md +59 -0
- package/lib/esm/prompts/fs-memory-retriever.md +30 -0
- package/lib/esm/prompts/html-generator.md +91 -0
- package/lib/esm/prompts/page-structure-planner-prompt.md +47 -0
- package/lib/esm/prompts/page-structure-validator-prompt.md +78 -0
- package/lib/esm/prompts/pages-kit-template-rule.md +491 -0
- package/lib/esm/prompts/site-map-generator.md +126 -0
- package/lib/esm/skill-agents/parse-component-list-agent.d.ts +100 -0
- package/lib/esm/skill-agents/parse-component-list-agent.js +192 -0
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/agent-utils.d.ts +4 -0
- package/lib/esm/utils/agent-utils.js +105 -0
- package/lib/types/agents/content-reviwer.d.ts +1 -1
- package/lib/types/agents/orchestrator/index.d.ts +115 -0
- package/lib/types/agents/orchestrator/orchestrator-prompts.d.ts +130 -0
- package/lib/types/agents/page-metadata-generator.d.ts +1 -1
- package/lib/types/agents/page-structure-planner.d.ts +59 -22
- package/lib/types/agents/router-datacache-generator.d.ts +24 -0
- package/lib/types/agents/template-designer.d.ts +7 -6
- package/lib/types/agents/template-generator.d.ts +55 -7
- package/lib/types/index.d.ts +0 -1
- package/lib/types/skill-agents/parse-component-list-agent.d.ts +100 -0
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/utils/agent-utils.d.ts +4 -0
- package/package.json +8 -3
- package/workflow-cli.ts +61 -41
- package/lib/cjs/agents/page-structure-validator.d.ts +0 -30
- package/lib/cjs/agents/page-structure-validator.js +0 -124
- package/lib/esm/agents/page-structure-validator.d.ts +0 -30
- package/lib/esm/agents/page-structure-validator.js +0 -121
- package/lib/types/agents/page-structure-validator.d.ts +0 -30
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
import { ensureZodUnionArray } from '@aigne/core/utils/json-schema.js';
|
|
2
|
+
import { duplicates } from '@aigne/core/utils/type-utils.js';
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
/**
|
|
5
|
+
* @hidden
|
|
6
|
+
*/
|
|
7
|
+
export const SYNTHESIZE_PLAN_USER_PROMPT_TEMPLATE = `\
|
|
8
|
+
Synthesize the results of executing all steps in the plan into a cohesive result
|
|
9
|
+
`;
|
|
10
|
+
/**
|
|
11
|
+
* @hidden
|
|
12
|
+
*/
|
|
13
|
+
export function getFullPlanSchema(agents) {
|
|
14
|
+
const agentNames = agents.map((i) => i.name);
|
|
15
|
+
if (new Set(agentNames).size !== agentNames.length) {
|
|
16
|
+
const dup = duplicates(agentNames);
|
|
17
|
+
throw new Error(`Duplicate agent names found in orchestrator: ${dup.join(',')}`);
|
|
18
|
+
}
|
|
19
|
+
const TaskSchema = z.object({
|
|
20
|
+
description: z.string().describe('Detailed description of the task'),
|
|
21
|
+
agent: z
|
|
22
|
+
.union(ensureZodUnionArray(agents.map((i) => z.literal(i.name))))
|
|
23
|
+
.describe('Name of the agent to execute the task'),
|
|
24
|
+
});
|
|
25
|
+
const StepSchema = z.object({
|
|
26
|
+
description: z.string().describe('Detailed description of the step'),
|
|
27
|
+
tasks: z.array(TaskSchema).describe('Tasks that can run in parallel in this step'),
|
|
28
|
+
});
|
|
29
|
+
return z.object({
|
|
30
|
+
steps: z.array(StepSchema).describe('All sequential steps in the plan'),
|
|
31
|
+
isComplete: z.boolean().describe('Whether the previous plan results achieve the objective'),
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* @hidden
|
|
36
|
+
*/
|
|
37
|
+
export const FULL_PLAN_PROMPT_TEMPLATE = `You are tasked with orchestrating a plan to complete an objective.
|
|
38
|
+
You can analyze results from the previous steps already executed to decide if the objective is complete.
|
|
39
|
+
Your plan must be structured in sequential steps, with each step containing independent parallel subtasks.
|
|
40
|
+
|
|
41
|
+
<objective>
|
|
42
|
+
{{objective}}
|
|
43
|
+
</objective>
|
|
44
|
+
|
|
45
|
+
<steps_completed>
|
|
46
|
+
{{#steps}}
|
|
47
|
+
- Step: {{step.description}}
|
|
48
|
+
Result: {{result}}
|
|
49
|
+
{{/steps}}
|
|
50
|
+
</steps_completed>
|
|
51
|
+
|
|
52
|
+
<previous_plan_status>
|
|
53
|
+
{{plan.status}}
|
|
54
|
+
</previous_plan_status>
|
|
55
|
+
|
|
56
|
+
<previous_plan_result>
|
|
57
|
+
{{plan.result}}
|
|
58
|
+
</previous_plan_result>
|
|
59
|
+
|
|
60
|
+
You have access to the following Agents(which are collections of tools/functions):
|
|
61
|
+
|
|
62
|
+
<agents>
|
|
63
|
+
{{#agents}}
|
|
64
|
+
- Agent: {{name}}
|
|
65
|
+
Description: {{description}}
|
|
66
|
+
Functions:
|
|
67
|
+
{{#tools}}
|
|
68
|
+
- Tool: {{name}}
|
|
69
|
+
Description: {{description}}
|
|
70
|
+
{{/tools}}
|
|
71
|
+
{{/agents}}
|
|
72
|
+
</agents>
|
|
73
|
+
|
|
74
|
+
- If the previous plan results achieve the objective, return isComplete=true.
|
|
75
|
+
- Otherwise, generate remaining steps needed.
|
|
76
|
+
- Generate a plan with all remaining steps needed.
|
|
77
|
+
- Steps are sequential, but each Step can have parallel subtasks.
|
|
78
|
+
- For each Step, specify a description of the step and independent subtasks that can run in parallel.
|
|
79
|
+
- For each subtask specify:
|
|
80
|
+
1. Clear description of the task that an LLM can execute
|
|
81
|
+
2. Name of 1 Agent to use for the task`;
|
|
82
|
+
/**
|
|
83
|
+
* @hidden
|
|
84
|
+
*/
|
|
85
|
+
export const TASK_PROMPT_TEMPLATE = `\
|
|
86
|
+
You are part of a larger workflow to achieve the step then the objective:
|
|
87
|
+
|
|
88
|
+
<objective>
|
|
89
|
+
{{objective}}
|
|
90
|
+
</objective>
|
|
91
|
+
|
|
92
|
+
<step>
|
|
93
|
+
{{step.description}}
|
|
94
|
+
</step>
|
|
95
|
+
|
|
96
|
+
Your job is to accomplish only the following task:
|
|
97
|
+
|
|
98
|
+
<task>
|
|
99
|
+
{{task.description}}
|
|
100
|
+
</task>
|
|
101
|
+
|
|
102
|
+
Results so far that may provide helpful context:
|
|
103
|
+
|
|
104
|
+
<steps_completed>
|
|
105
|
+
{{#steps}}
|
|
106
|
+
- Step: {{step.description}}
|
|
107
|
+
Result: {{result}}
|
|
108
|
+
{{/steps}}
|
|
109
|
+
</steps_completed>
|
|
110
|
+
`;
|
|
111
|
+
/**
|
|
112
|
+
* @hidden
|
|
113
|
+
*/
|
|
114
|
+
export const SYNTHESIZE_STEP_PROMPT_TEMPLATE = `\
|
|
115
|
+
Synthesize the results of these parallel tasks into a cohesive result
|
|
116
|
+
|
|
117
|
+
<objective>
|
|
118
|
+
{{objective}}
|
|
119
|
+
</objective>
|
|
120
|
+
|
|
121
|
+
<step>
|
|
122
|
+
{{step.description}}
|
|
123
|
+
</step>
|
|
124
|
+
|
|
125
|
+
<tasks>
|
|
126
|
+
{{#tasks}}
|
|
127
|
+
- Task: {{task.description}}
|
|
128
|
+
Result: {{result}}
|
|
129
|
+
{{/tasks}}
|
|
130
|
+
</tasks>
|
|
131
|
+
`;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { AIAgent } from '@aigne/core';
|
|
2
2
|
import { z } from 'zod';
|
|
3
|
+
// import { getMemory } from '../utils';
|
|
3
4
|
const prompt = `您是一名专业的SEO和内容编辑专家,擅长创建有吸引力和描述性强的页面元数据。
|
|
4
5
|
|
|
5
6
|
您的职责
|
|
6
7
|
1. 基于已生成的页面内容,创建准确、吸引人的页面标题
|
|
7
8
|
2. 创建简洁而信息丰富的页面描述,适合在搜索结果和社交媒体分享中显示
|
|
8
9
|
3. 确保标题和描述准确反映页面内容
|
|
9
|
-
4. 优化元数据以提高页面的SEO价值
|
|
10
|
+
4. 优化元数据以提高页面的 SEO 价值
|
|
10
11
|
|
|
11
12
|
## 输入上下文:
|
|
12
13
|
{{context}}
|
|
@@ -24,6 +25,7 @@ const prompt = `您是一名专业的SEO和内容编辑专家,擅长创建有
|
|
|
24
25
|
4. 标题和描述应使用 {{locale}} 语言
|
|
25
26
|
|
|
26
27
|
请为以上页面内容生成合适的标题和描述。`;
|
|
28
|
+
// const memory = getMemory({ autoUpdate: false });
|
|
27
29
|
export const generatePageMetadataAgent = AIAgent.from({
|
|
28
30
|
name: 'Page Metadata Generator',
|
|
29
31
|
instructions: prompt,
|
|
@@ -37,4 +39,5 @@ export const generatePageMetadataAgent = AIAgent.from({
|
|
|
37
39
|
title: z.string().describe('页面标题'),
|
|
38
40
|
description: z.string().describe('页面描述'),
|
|
39
41
|
}),
|
|
42
|
+
// memory,
|
|
40
43
|
});
|
|
@@ -1,43 +1,70 @@
|
|
|
1
1
|
import { AIAgent } from '@aigne/core';
|
|
2
|
-
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { ReflectionAgent } from '../workflow-agents/reflection-agent.js';
|
|
4
|
+
export declare const plannerParamsSchema: z.ZodObject<{
|
|
5
|
+
context: z.ZodString;
|
|
6
|
+
question: z.ZodString;
|
|
7
|
+
locale: z.ZodString;
|
|
8
|
+
outputSchema: z.ZodString;
|
|
9
|
+
expectedSections: z.ZodString;
|
|
10
|
+
}, "strip", z.ZodTypeAny, {
|
|
11
|
+
outputSchema: string;
|
|
12
|
+
context: string;
|
|
13
|
+
question: string;
|
|
14
|
+
locale: string;
|
|
15
|
+
expectedSections: string;
|
|
16
|
+
}, {
|
|
17
|
+
outputSchema: string;
|
|
3
18
|
context: string;
|
|
4
19
|
question: string;
|
|
5
|
-
|
|
20
|
+
locale: string;
|
|
21
|
+
expectedSections: string;
|
|
22
|
+
}>;
|
|
23
|
+
export interface PageStructurePlannerOutput {
|
|
24
|
+
structurePlan: Array<{
|
|
6
25
|
sectionName: string;
|
|
7
26
|
sectionContentPlan: string;
|
|
8
27
|
}>;
|
|
28
|
+
}
|
|
29
|
+
export declare const pageStructurePlannerWithReflection: ReflectionAgent<{
|
|
30
|
+
outputSchema: string;
|
|
31
|
+
context: string;
|
|
32
|
+
question: string;
|
|
9
33
|
locale: string;
|
|
10
|
-
|
|
34
|
+
expectedSections: string;
|
|
11
35
|
validationFeedback?: {
|
|
12
36
|
isValid: boolean;
|
|
13
37
|
missingSections: string[];
|
|
14
|
-
duplicateContent:
|
|
15
|
-
sections: string[];
|
|
38
|
+
duplicateContent: {
|
|
16
39
|
description: string;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
};
|
|
24
|
-
}
|
|
25
|
-
export interface PageStructurePlannerOutput {
|
|
26
|
-
structurePlan: Array<{
|
|
40
|
+
sections: string[];
|
|
41
|
+
score: number;
|
|
42
|
+
suggestion: string;
|
|
43
|
+
}[];
|
|
44
|
+
} | undefined;
|
|
45
|
+
structurePlan?: {
|
|
27
46
|
sectionName: string;
|
|
28
47
|
sectionContentPlan: string;
|
|
29
|
-
}
|
|
30
|
-
}
|
|
48
|
+
}[] | undefined;
|
|
49
|
+
}, {
|
|
50
|
+
isApproved: boolean;
|
|
51
|
+
validationFeedback: {
|
|
52
|
+
isValid: boolean;
|
|
53
|
+
missingSections: string[];
|
|
54
|
+
duplicateContent: {
|
|
55
|
+
description: string;
|
|
56
|
+
sections: string[];
|
|
57
|
+
score: number;
|
|
58
|
+
suggestion: string;
|
|
59
|
+
}[];
|
|
60
|
+
};
|
|
61
|
+
}>;
|
|
31
62
|
export declare const pageStructurePlannerAgent: AIAgent<{
|
|
63
|
+
outputSchema: string;
|
|
32
64
|
context: string;
|
|
33
65
|
question: string;
|
|
34
66
|
locale: string;
|
|
35
|
-
outputSchema: string;
|
|
36
67
|
expectedSections: string;
|
|
37
|
-
initialStructurePlan: {
|
|
38
|
-
sectionName: string;
|
|
39
|
-
sectionContentPlan: string;
|
|
40
|
-
}[];
|
|
41
68
|
validationFeedback?: {
|
|
42
69
|
isValid: boolean;
|
|
43
70
|
missingSections: string[];
|
|
@@ -45,9 +72,19 @@ export declare const pageStructurePlannerAgent: AIAgent<{
|
|
|
45
72
|
description: string;
|
|
46
73
|
sections: string[];
|
|
47
74
|
score: number;
|
|
75
|
+
suggestion: string;
|
|
48
76
|
}[];
|
|
49
77
|
} | undefined;
|
|
78
|
+
structurePlan?: {
|
|
79
|
+
sectionName: string;
|
|
80
|
+
sectionContentPlan: string;
|
|
81
|
+
}[] | undefined;
|
|
50
82
|
}, {
|
|
83
|
+
outputSchema: string;
|
|
84
|
+
context: string;
|
|
85
|
+
question: string;
|
|
86
|
+
locale: string;
|
|
87
|
+
expectedSections: string;
|
|
51
88
|
structurePlan: {
|
|
52
89
|
sectionName: string;
|
|
53
90
|
sectionContentPlan: string;
|
|
@@ -1,97 +1,124 @@
|
|
|
1
|
-
import { AIAgent
|
|
1
|
+
import { AIAgent } from '@aigne/core';
|
|
2
|
+
import fs from 'node:fs';
|
|
3
|
+
import path from 'node:path';
|
|
2
4
|
import { z } from 'zod';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
5
|
+
import { getMemory } from '../utils/agent-utils.js';
|
|
6
|
+
import { ReflectionAgent } from '../workflow-agents/reflection-agent.js';
|
|
7
|
+
const pageStructurePlannerPrompt = fs.readFileSync(path.join(__dirname, '../prompts/page-structure-planner-prompt.md'), 'utf-8');
|
|
8
|
+
const pageStructureValidatorPrompt = fs.readFileSync(path.join(__dirname, '../prompts/page-structure-validator-prompt.md'), 'utf-8');
|
|
9
|
+
// 共同的输入参数 schema
|
|
10
|
+
export const plannerParamsSchema = z.object({
|
|
11
|
+
context: z.string(),
|
|
12
|
+
question: z.string(),
|
|
13
|
+
locale: z.string(),
|
|
14
|
+
outputSchema: z.string(),
|
|
15
|
+
expectedSections: z.string(),
|
|
16
|
+
});
|
|
17
|
+
const validationFeedbackSchema = z.object({
|
|
18
|
+
isValid: z.boolean(),
|
|
19
|
+
missingSections: z.array(z.string()),
|
|
20
|
+
duplicateContent: z
|
|
21
|
+
.array(z.object({
|
|
22
|
+
sections: z.array(z.string()).describe('重复的 sections'),
|
|
23
|
+
description: z.string().describe('为什么判断为重复'),
|
|
24
|
+
score: z.number().describe('重复评分,0-100 分'),
|
|
25
|
+
suggestion: z.string().describe('改进建议,如果需要修改,请给出修改建议'),
|
|
26
|
+
}))
|
|
27
|
+
.describe('重复内容的 sections 列表'),
|
|
28
|
+
});
|
|
29
|
+
const contextRule = `
|
|
30
|
+
## 当前任务输入
|
|
31
|
+
上下文信息:
|
|
32
|
+
<context>
|
|
20
33
|
{{context}}
|
|
34
|
+
</context>
|
|
21
35
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
## 用户指令:
|
|
36
|
+
用户指令:
|
|
37
|
+
<question>
|
|
26
38
|
{{question}}
|
|
39
|
+
</question>
|
|
27
40
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
2. 分析输出模式中的sectionsData属性,了解页面包含哪些section
|
|
33
|
-
3. 为每个section规划内容方向,确保各section内容互补而不重复
|
|
34
|
-
4. 返回一个结构化的规划,清楚说明每个section应包含的内容
|
|
35
|
-
5. 如果 Section 中包含列表数据,根据输入上下文中包含的数据,明确指定列表数据的数量,尽可能全的展示上下文中提供的相关数据。
|
|
36
|
-
6. 如果初始结构规划中包含的section,请根据初始结构规划中的内容规划,保持初始结构规划中的内容规划。
|
|
37
|
-
|
|
41
|
+
输出结构模式:
|
|
42
|
+
<output-schema>
|
|
43
|
+
{{outputSchema}}
|
|
44
|
+
</output-schema>
|
|
38
45
|
|
|
39
|
-
|
|
40
|
-
|
|
46
|
+
预期包含的Sections:
|
|
47
|
+
<expected-sections>
|
|
48
|
+
{{expectedSections}}
|
|
49
|
+
</expected-sections>
|
|
41
50
|
|
|
42
|
-
|
|
51
|
+
<#if structurePlan>
|
|
52
|
+
## 当前生成的结构规划:
|
|
53
|
+
<current-structure-plan>
|
|
43
54
|
{{structurePlan}}
|
|
55
|
+
</current-structure-plan>
|
|
56
|
+
</#if>
|
|
44
57
|
|
|
45
|
-
|
|
46
|
-
|
|
58
|
+
<#if validationFeedback>
|
|
59
|
+
## 验证反馈
|
|
60
|
+
上一次生成的页面结构规划存在以下问题,请根据反馈建议进行修正:
|
|
61
|
+
<validation-feedback>
|
|
62
|
+
{{validationFeedback}}
|
|
63
|
+
</validation-feedback>
|
|
64
|
+
</#if>
|
|
47
65
|
|
|
48
|
-
|
|
49
|
-
{{
|
|
66
|
+
当前时间:${new Date().toISOString()}
|
|
67
|
+
语言:{{locale}}
|
|
68
|
+
`;
|
|
69
|
+
const plannerInstructions = `
|
|
70
|
+
${pageStructurePlannerPrompt}
|
|
71
|
+
|
|
72
|
+
${contextRule}
|
|
73
|
+
`;
|
|
74
|
+
const validatorInstructions = `
|
|
50
75
|
|
|
51
|
-
|
|
52
|
-
1. 包含所有必要的section
|
|
53
|
-
2. 避免不同section之间内容重复
|
|
54
|
-
3. 明确区分各section的内容方向
|
|
55
|
-
4. 遵循section描述中的要求
|
|
76
|
+
${pageStructureValidatorPrompt}
|
|
56
77
|
|
|
57
|
-
|
|
78
|
+
${contextRule}
|
|
58
79
|
`;
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
80
|
+
const memory = getMemory({ autoUpdate: false });
|
|
81
|
+
const structurePlanSchema = z.array(z.object({
|
|
82
|
+
sectionName: z.string(),
|
|
83
|
+
sectionContentPlan: z.string().describe('该section的内容规划描述'),
|
|
84
|
+
}));
|
|
85
|
+
const plannerAgent = AIAgent.from({
|
|
86
|
+
name: 'planner',
|
|
87
|
+
description: '生成页面结构规划',
|
|
88
|
+
inputSchema: z.object({
|
|
89
|
+
...plannerParamsSchema.shape,
|
|
90
|
+
validationFeedback: validationFeedbackSchema.optional(),
|
|
91
|
+
structurePlan: structurePlanSchema.optional(),
|
|
92
|
+
}),
|
|
93
|
+
outputSchema: z.object({
|
|
94
|
+
...plannerParamsSchema.shape,
|
|
95
|
+
structurePlan: structurePlanSchema,
|
|
96
|
+
}),
|
|
97
|
+
memory,
|
|
98
|
+
instructions: plannerInstructions,
|
|
99
|
+
includeInputInOutput: true,
|
|
100
|
+
});
|
|
101
|
+
const validatorAgent = AIAgent.from({
|
|
102
|
+
name: 'validator',
|
|
103
|
+
description: '验证页面结构规划的完整性和有效性',
|
|
68
104
|
inputSchema: z.object({
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
locale: z.string(),
|
|
72
|
-
outputSchema: z.string(),
|
|
73
|
-
expectedSections: z.string(),
|
|
74
|
-
initialStructurePlan: z.array(z.object({
|
|
75
|
-
sectionName: z.string(),
|
|
76
|
-
sectionContentPlan: z.string(),
|
|
77
|
-
})),
|
|
78
|
-
validationFeedback: z
|
|
79
|
-
.object({
|
|
80
|
-
isValid: z.boolean(),
|
|
81
|
-
missingSections: z.array(z.string()),
|
|
82
|
-
duplicateContent: z.array(z.object({
|
|
83
|
-
sections: z.array(z.string()),
|
|
84
|
-
description: z.string(),
|
|
85
|
-
score: z.number(),
|
|
86
|
-
})),
|
|
87
|
-
})
|
|
88
|
-
.optional(),
|
|
105
|
+
...plannerParamsSchema.shape,
|
|
106
|
+
structurePlan: structurePlanSchema,
|
|
89
107
|
}),
|
|
108
|
+
memory,
|
|
90
109
|
outputSchema: z.object({
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
sectionContentPlan: z.string().describe('该section的内容规划描述'),
|
|
94
|
-
})),
|
|
110
|
+
isApproved: z.boolean().describe('结构规划是否符合要求,无缺失 section 且无严重重复内容'),
|
|
111
|
+
validationFeedback: validationFeedbackSchema,
|
|
95
112
|
}),
|
|
113
|
+
instructions: validatorInstructions,
|
|
96
114
|
includeInputInOutput: true,
|
|
97
115
|
});
|
|
116
|
+
export const pageStructurePlannerWithReflection = new ReflectionAgent({
|
|
117
|
+
name: 'page-structure-planner-with-reflection',
|
|
118
|
+
maxIterations: 2,
|
|
119
|
+
editor: plannerAgent,
|
|
120
|
+
reviewer: validatorAgent,
|
|
121
|
+
isApproved: (result) => result.isApproved,
|
|
122
|
+
});
|
|
123
|
+
// 保留原有的 agent 导出以保持向后兼容
|
|
124
|
+
export const pageStructurePlannerAgent = plannerAgent;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { FunctionAgent } from '@aigne/core';
|
|
2
|
+
export declare const routerDataCacheGeneratorAgent: FunctionAgent<{
|
|
3
|
+
context: string;
|
|
4
|
+
componentList: {
|
|
5
|
+
data: {
|
|
6
|
+
name: string;
|
|
7
|
+
description: string;
|
|
8
|
+
id: string;
|
|
9
|
+
component: string;
|
|
10
|
+
rawData?: any;
|
|
11
|
+
}[];
|
|
12
|
+
summary: {
|
|
13
|
+
total: number;
|
|
14
|
+
basicComponents: Record<string, string>;
|
|
15
|
+
customComponents: Record<string, string>;
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
templateYaml: string;
|
|
19
|
+
locale?: string | undefined;
|
|
20
|
+
}, {
|
|
21
|
+
success: boolean;
|
|
22
|
+
dataCache?: any;
|
|
23
|
+
error?: string | undefined;
|
|
24
|
+
}>;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { FunctionAgent } from '@aigne/core';
|
|
2
|
+
import { generatePageDataZodToAgent } from '@blocklet/pages-kit-block-studio/generate-wrapper-code';
|
|
3
|
+
import yaml from 'js-yaml';
|
|
4
|
+
import { z } from 'zod';
|
|
5
|
+
import { ComponentListOutputSchema } from '../skill-agents/parse-component-list-agent';
|
|
6
|
+
import generatePageContentMultiAgent from './multi-agent-page-writer';
|
|
7
|
+
export const routerDataCacheGeneratorAgent = FunctionAgent.from({
|
|
8
|
+
name: 'Router Data Cache Generator',
|
|
9
|
+
description: 'Generate page content using page data and component list, assembling them into state for content generation',
|
|
10
|
+
inputSchema: z.object({
|
|
11
|
+
templateYaml: z.string().describe('Template Yaml'),
|
|
12
|
+
componentList: ComponentListOutputSchema,
|
|
13
|
+
context: z.string().describe('整理好的上下文信息'),
|
|
14
|
+
locale: z.string().describe('Locale').default('en').optional(),
|
|
15
|
+
}),
|
|
16
|
+
outputSchema: z.object({
|
|
17
|
+
success: z.boolean(),
|
|
18
|
+
dataCache: z.any().optional().describe('Generated page data cache'),
|
|
19
|
+
error: z.string().optional(),
|
|
20
|
+
}),
|
|
21
|
+
async process({ templateYaml, componentList, context, locale = 'en' }) {
|
|
22
|
+
const pageTemplate = yaml.load(templateYaml);
|
|
23
|
+
const pageTemplateId = pageTemplate.id;
|
|
24
|
+
try {
|
|
25
|
+
// Assemble state object from page and componentList
|
|
26
|
+
const state = {
|
|
27
|
+
pages: {
|
|
28
|
+
[pageTemplateId]: pageTemplate,
|
|
29
|
+
},
|
|
30
|
+
// 将 componentList rawData 转换为 components
|
|
31
|
+
components: Object.fromEntries(componentList.data
|
|
32
|
+
.filter((component) => component.rawData)
|
|
33
|
+
.map((component, index) => [
|
|
34
|
+
component.id,
|
|
35
|
+
{
|
|
36
|
+
index,
|
|
37
|
+
data: component.rawData,
|
|
38
|
+
},
|
|
39
|
+
])),
|
|
40
|
+
resources: {
|
|
41
|
+
components: {},
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
// Generate output schema using the assembled state
|
|
45
|
+
const outputSchema = generatePageDataZodToAgent(state, pageTemplateId);
|
|
46
|
+
if (!outputSchema) {
|
|
47
|
+
return {
|
|
48
|
+
success: false,
|
|
49
|
+
error: 'Failed to generate output schema',
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
// Generate page content using the multi-agent
|
|
53
|
+
const dataCache = await generatePageContentMultiAgent({
|
|
54
|
+
context,
|
|
55
|
+
question: 'Please generate the page content based on the context',
|
|
56
|
+
locale,
|
|
57
|
+
outputSchema,
|
|
58
|
+
});
|
|
59
|
+
return {
|
|
60
|
+
success: true,
|
|
61
|
+
dataCache,
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error('Error in router dataCache generation:', error);
|
|
66
|
+
return {
|
|
67
|
+
success: false,
|
|
68
|
+
error: error instanceof Error ? error.message : 'Unknown error during generation',
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
});
|
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
import { AIAgent } from '@aigne/core';
|
|
2
2
|
import { zodSchemaToJsonSchema } from '@blocklet/pages-kit-block-studio/zod-utils';
|
|
3
3
|
import { z } from 'zod';
|
|
4
|
+
// import { getMemory } from '../utils/agent-utils.js';
|
|
4
5
|
import { logger } from '../utils/logger.js';
|
|
6
|
+
// const memory = getMemory({ autoUpdate: false });
|
|
5
7
|
export async function createSectionContentAgent(input) {
|
|
6
8
|
const prompt = `您是一名有着丰富经验且富有创意的设计师,擅长产品站点的内容创作。
|
|
7
9
|
|
|
@@ -19,7 +21,7 @@ export async function createSectionContentAgent(input) {
|
|
|
19
21
|
|
|
20
22
|
Hero Section 中的标题必须能充分描述上下文中的产品,标题应该是描述,而不是口号,让用户打开网页第一眼就知道了产品是什么,能帮助用户做什么。
|
|
21
23
|
|
|
22
|
-
|
|
24
|
+
Hero Section 中的描述可以包含两点信息:
|
|
23
25
|
- 我们的产品如何工作的
|
|
24
26
|
- 支撑标题中的描述,让它更可信
|
|
25
27
|
|
|
@@ -41,11 +43,11 @@ FAQ 中的问答应该包含用户常关心的问题,并给出答案,如果
|
|
|
41
43
|
## 用户指令:
|
|
42
44
|
{{question}}
|
|
43
45
|
|
|
44
|
-
## 当前section信息
|
|
45
|
-
Section名称: {{sectionName}}
|
|
46
|
-
Section计划: {{sectionPlan}}
|
|
46
|
+
## 当前 section 信息
|
|
47
|
+
Section 名称: {{sectionName}}
|
|
48
|
+
Section 计划: {{sectionPlan}}
|
|
47
49
|
|
|
48
|
-
注意:Section计划是对这个 section 需要展示的内容和风格的要求,您需要根据这个要求来生成面向用户,对用户阅读友好的内容,不要直接重复 section 计划中的要求。
|
|
50
|
+
注意:Section 计划是对这个 section 需要展示的内容和风格的要求,您需要根据这个要求来生成面向用户,对用户阅读友好的内容,不要直接重复 section 计划中的要求。
|
|
49
51
|
|
|
50
52
|
## 数据格式要求
|
|
51
53
|
${JSON.stringify(zodSchemaToJsonSchema(input.sectionSchema))}
|
|
@@ -55,9 +57,9 @@ ${JSON.stringify(zodSchemaToJsonSchema(input.sectionSchema))}
|
|
|
55
57
|
|
|
56
58
|
|
|
57
59
|
## 内容生成要求
|
|
58
|
-
1. 仅生成当前指定section的内容
|
|
59
|
-
2. 避免与已生成的section内容重复
|
|
60
|
-
3. 内容要围绕section计划描述的主题展开
|
|
60
|
+
1. 仅生成当前指定 section 的内容
|
|
61
|
+
2. 避免与已生成的 section 内容重复
|
|
62
|
+
3. 内容要围绕 section 计划描述的主题展开
|
|
61
63
|
4. 上下文中有相关图片时返回图片链接,如果没有相关的图片不要随便使用其他图片
|
|
62
64
|
5. 如果数组类型确实没有数据,请返回空数组
|
|
63
65
|
6. 内容需符合提供的数据格式要求
|
|
@@ -89,6 +91,7 @@ ${JSON.stringify(zodSchemaToJsonSchema(input.sectionSchema))}
|
|
|
89
91
|
generatedSections: z.string(),
|
|
90
92
|
}),
|
|
91
93
|
outputSchema: input.sectionSchema,
|
|
94
|
+
// memory,
|
|
92
95
|
});
|
|
93
96
|
return agent;
|
|
94
97
|
}
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { AIAgent } from '@aigne/core';
|
|
2
|
-
/**
|
|
3
|
-
* 用于设计页面结构的 workflow
|
|
4
|
-
* 1. AI 根据拿到的 collectorResult 和 componentList,生成一个页面设计模板,需要用 ASCII 图画出来,给到用户确认
|
|
5
|
-
* 2. 用户确认后,AI 保存页面设计模板,并返回页面设计模板
|
|
6
|
-
*/
|
|
7
2
|
export declare const designerAgent: AIAgent<{
|
|
3
|
+
componentListYaml: string;
|
|
8
4
|
collectResult: string;
|
|
9
5
|
}, {
|
|
10
6
|
ascii: string;
|
|
11
7
|
$message: string;
|
|
12
|
-
filteredComponentList:
|
|
8
|
+
filteredComponentList: {
|
|
9
|
+
name: string;
|
|
10
|
+
description: string;
|
|
11
|
+
id: string;
|
|
12
|
+
component: string;
|
|
13
|
+
}[];
|
|
13
14
|
}>;
|