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