@blocklet/pages-kit-agents 0.5.41 → 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.
Files changed (30) hide show
  1. package/lib/cjs/agents/template-designer.d.ts +13 -0
  2. package/lib/cjs/agents/template-designer.js +67 -0
  3. package/lib/cjs/agents/template-generator.d.ts +18 -0
  4. package/lib/cjs/agents/template-generator.js +186 -0
  5. package/lib/cjs/tsconfig.tsbuildinfo +1 -1
  6. package/lib/cjs/utils/component-tuils.d.ts +12 -0
  7. package/lib/cjs/utils/component-tuils.js +141 -0
  8. package/lib/cjs/utils/file-utils.d.ts +23 -0
  9. package/lib/cjs/utils/file-utils.js +77 -0
  10. package/lib/cjs/workflow-agents/reflection-agent.d.ts +16 -0
  11. package/lib/cjs/workflow-agents/reflection-agent.js +38 -0
  12. package/lib/esm/agents/template-designer.d.ts +13 -0
  13. package/lib/esm/agents/template-designer.js +61 -0
  14. package/lib/esm/agents/template-generator.d.ts +18 -0
  15. package/lib/esm/agents/template-generator.js +180 -0
  16. package/lib/esm/tsconfig.tsbuildinfo +1 -1
  17. package/lib/esm/utils/component-tuils.d.ts +12 -0
  18. package/lib/esm/utils/component-tuils.js +136 -0
  19. package/lib/esm/utils/file-utils.d.ts +23 -0
  20. package/lib/esm/utils/file-utils.js +74 -0
  21. package/lib/esm/workflow-agents/reflection-agent.d.ts +16 -0
  22. package/lib/esm/workflow-agents/reflection-agent.js +34 -0
  23. package/lib/types/agents/template-designer.d.ts +13 -0
  24. package/lib/types/agents/template-generator.d.ts +18 -0
  25. package/lib/types/tsconfig.tsbuildinfo +1 -1
  26. package/lib/types/utils/component-tuils.d.ts +12 -0
  27. package/lib/types/utils/file-utils.d.ts +23 -0
  28. package/lib/types/workflow-agents/reflection-agent.d.ts +16 -0
  29. package/package.json +5 -2
  30. package/workflow-cli.ts +132 -0
@@ -0,0 +1,12 @@
1
+ import { z } from 'zod';
2
+ export declare function getSchemaByComponentIds(sections: {
3
+ componentId: string;
4
+ componentName: string;
5
+ sectionName: string;
6
+ }[]): z.ZodObject<Record<string, any>, "strip", z.ZodTypeAny, {
7
+ [x: string]: any;
8
+ }, {
9
+ [x: string]: any;
10
+ }>;
11
+ export declare function getComponentsSimpleMetadata(): string;
12
+ export declare function getComponentsMetadata(): string;
@@ -3,3 +3,26 @@
3
3
  * and generating a list of all HTML files in each subfolder
4
4
  */
5
5
  export declare function updateFileList(): Promise<void>;
6
+ /**
7
+ * File content information interface
8
+ */
9
+ export interface FileContent {
10
+ filePath: string;
11
+ fileName: string;
12
+ content: string;
13
+ }
14
+ /**
15
+ * Recursively reads files matching a pattern from a directory and its subdirectories
16
+ * @param dirPath - The directory path to search in
17
+ * @param pattern - String or RegExp pattern to match file names
18
+ * @param options - Optional configuration
19
+ * @returns Promise<FileContent[]> - Array of file content objects
20
+ */
21
+ export declare function readFilesByPattern(dirPath: string, pattern: string | RegExp, options?: {
22
+ recursive?: boolean;
23
+ }): Promise<FileContent[]>;
24
+ export declare function readFileByPath(filePath: string): Promise<string>;
25
+ /**
26
+ * Save content to a file, creating directories if needed
27
+ */
28
+ export declare function saveFileByPath(filePath: string, content: string): Promise<void>;
@@ -0,0 +1,16 @@
1
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type Message } from '@aigne/core';
2
+ import type { PromiseOrValue } from '@aigne/core/utils/type-utils.js';
3
+ export interface ReflectionAgentOptions<I extends Message = Message, RO extends Message = Message> extends AgentOptions<I, I> {
4
+ editor: Agent<I, I>;
5
+ reviewer: Agent<I, RO>;
6
+ isApproved?: (result: RO) => PromiseOrValue<boolean>;
7
+ maxIterations?: number;
8
+ }
9
+ export declare class ReflectionAgent<I extends Message = Message, RO extends Message = Message> extends Agent<I, I> {
10
+ constructor(options: ReflectionAgentOptions<I, RO>);
11
+ editor: Agent<I, I>;
12
+ reviewer: Agent<I, RO>;
13
+ isApproved?: (result: RO) => PromiseOrValue<boolean>;
14
+ maxIterations: number;
15
+ process(input: I, options: AgentInvokeOptions): Promise<AgentProcessResult<I>>;
16
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@blocklet/pages-kit-agents",
3
- "version": "0.5.41",
3
+ "version": "0.5.42",
4
4
  "description": "AIGNE based agents for pages kit",
5
5
  "author": "Arcblock <blocklet@arcblock.io> https://github.com/blocklet",
6
6
  "homepage": "https://github.com/blocklet/pages-kit#readme",
@@ -23,6 +23,7 @@
23
23
  },
24
24
  "keywords": [],
25
25
  "dependencies": {
26
+ "@aigne/agent-library": "^1.12.6",
26
27
  "@aigne/anthropic": "^0.2.7",
27
28
  "@aigne/core": "^1.18.6",
28
29
  "@aigne/deepseek": "^0.2.7",
@@ -31,14 +32,16 @@
31
32
  "@aigne/xai": "^0.2.7",
32
33
  "@types/js-yaml": "^4.0.9",
33
34
  "@types/yargs": "^17.0.33",
35
+ "inquirer": "^12.5.2",
34
36
  "js-yaml": "^4.1.0",
35
37
  "open": "^10.1.2",
36
38
  "yargs": "^17.7.2",
37
39
  "zod": "^3.24.2",
38
- "@blocklet/pages-kit-block-studio": "0.5.41"
40
+ "@blocklet/pages-kit-block-studio": "0.5.42"
39
41
  },
40
42
  "scripts": {
41
43
  "start": "npx -y bun run cli.ts",
44
+ "workflow": "npx -y bun run workflow-cli.ts",
42
45
  "lint": "eslint --ext .mjs,.js,.jsx,.ts,.tsx",
43
46
  "lint:fix": "npm run lint -- --fix",
44
47
  "build": "run-p build:*",
@@ -0,0 +1,132 @@
1
+ import { AIGNE, ProcessMode, TeamAgent } from '@aigne/core';
2
+ import { logger as aigneLogger, LogLevel } from '@aigne/core/utils/logger.js';
3
+ import yaml from 'js-yaml';
4
+ import fs from 'node:fs/promises';
5
+ import path from 'node:path';
6
+ import { z } from 'zod';
7
+
8
+ import { designerAgent } from './agents/template-designer.js';
9
+ import { generatorAgentWithReflection, saveYamlAgent } from './agents/template-generator.js';
10
+ import { readFileByPath } from './utils/file-utils.js';
11
+ import { getModel } from './utils/index.js';
12
+ import { logger } from './utils/logger.js';
13
+ import { contentCompletenessEvaluatorAgent } from './workflow-agents/content-completeness-evaluator.js';
14
+ import { contentCompletionWorkflowAgent } from './workflow-agents/content-completion-workflow-agent.js';
15
+ import { parseDataSourcesAgent } from './workflow-agents/parse-datasources.js';
16
+ import { UserFeedbackAgent } from './workflow-agents/user-feedback-agent.js';
17
+
18
+ aigneLogger.level = LogLevel.DEBUG;
19
+
20
+ const DEFAULT_LOCALE = 'zh';
21
+ const DEFAULT_MODEL_NAME = 'gpt-4o';
22
+ const DEFAULT_PROJECT_ID = 'DEFAULT_PROJECT_ID';
23
+
24
+ const ConfigSchema = z.object({
25
+ inputInfoPath: z.string(),
26
+ locale: z.string(),
27
+ modelName: z.string(),
28
+ projectId: z.string(),
29
+ });
30
+
31
+ type WorkflowConfig = z.infer<typeof ConfigSchema>;
32
+
33
+ async function loadConfig(): Promise<WorkflowConfig> {
34
+ const configPath = path.join(__dirname, 'workflow-config.yaml');
35
+ try {
36
+ const fileContent = await fs.readFile(configPath, 'utf-8');
37
+ const parsedConfig = yaml.load(fileContent) as any;
38
+ return ConfigSchema.parse(parsedConfig);
39
+ } catch (error) {
40
+ logger.error(`Failed to load workflow-config.yaml: ${error instanceof Error ? error.message : String(error)}`);
41
+ throw new Error('请在同级目录下提供完整的 workflow-config.yaml 配置文件');
42
+ }
43
+ }
44
+
45
+ async function runWorkflow({
46
+ inputInfo,
47
+ locale,
48
+ modelName,
49
+ projectId,
50
+ }: {
51
+ inputInfo: string;
52
+ locale: string;
53
+ modelName: string;
54
+ projectId: string;
55
+ }) {
56
+ logger.info('inputInfo', inputInfo);
57
+ logger.info('locale', locale);
58
+ logger.info('modelName', modelName);
59
+ logger.info('projectId', projectId);
60
+
61
+ const model = getModel(modelName);
62
+ const engine = new AIGNE({
63
+ model,
64
+ });
65
+
66
+ const teamAgent = TeamAgent.from({
67
+ name: 'generate web site',
68
+ inputSchema: z.object({
69
+ rawData: z.string(),
70
+ locale: z.string(),
71
+ projectId: z.string(),
72
+ }),
73
+ mode: ProcessMode.sequential,
74
+ skills: [
75
+ parseDataSourcesAgent,
76
+ contentCompletenessEvaluatorAgent,
77
+ contentCompletionWorkflowAgent,
78
+ new UserFeedbackAgent({
79
+ name: 'template designer',
80
+ executor: designerAgent,
81
+ isApproved: () => false,
82
+ getShowMessage: ({ $message, ascii }) => `🤖:${$message}\n\n${ascii}`,
83
+ }),
84
+ generatorAgentWithReflection,
85
+ saveYamlAgent,
86
+ ],
87
+ });
88
+
89
+ const result = await engine.invoke(teamAgent, {
90
+ rawData: inputInfo,
91
+ locale,
92
+ projectId,
93
+ });
94
+
95
+ logger.info('result', result);
96
+ }
97
+
98
+ // 主函数
99
+ async function main() {
100
+ try {
101
+ logger.info('🔧 读取 workflow-config.yaml 配置...');
102
+ const config = await loadConfig();
103
+ logger.info('📚 读取原始信息...');
104
+ const inputInfo = await readFileByPath(config.inputInfoPath);
105
+
106
+ await runWorkflow({
107
+ inputInfo,
108
+ locale: config.locale || DEFAULT_LOCALE,
109
+ modelName: config.modelName || DEFAULT_MODEL_NAME,
110
+ projectId: config.projectId || DEFAULT_PROJECT_ID,
111
+ });
112
+ } catch (error) {
113
+ logger.error(`工作流执行失败: ${error instanceof Error ? error.message : String(error)}`);
114
+ process.exit(1);
115
+ }
116
+ }
117
+
118
+ // 处理程序退出
119
+ process.on('SIGINT', () => {
120
+ logger.info('\n\n工作流已被用户中断');
121
+ process.exit(0);
122
+ });
123
+
124
+ // 执行主函数
125
+ if (require.main === module) {
126
+ main().catch((error) => {
127
+ logger.error(`Error: ${error instanceof Error ? error.message : String(error)}`);
128
+ process.exit(1);
129
+ });
130
+ }
131
+
132
+ export { runWorkflow };