@blocklet/pages-kit-agents 0.5.14 → 0.5.16
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 +3 -0
- package/cli.ts +80 -10
- package/lib/cjs/agents/content-reviwer.d.ts +19 -0
- package/lib/cjs/agents/content-reviwer.js +154 -0
- package/lib/cjs/agents/multi-agent-page-writer.js +11 -12
- package/lib/cjs/agents/page-structure-planner.js +0 -1
- package/lib/cjs/tsconfig.tsbuildinfo +1 -1
- package/lib/cjs/utils/agent-utils.js +19 -1
- package/lib/cjs/utils/file-utils.js +53 -9
- package/lib/cjs/utils/template-utils.d.ts +13 -0
- package/lib/cjs/utils/template-utils.js +30 -0
- package/lib/esm/agents/content-reviwer.d.ts +19 -0
- package/lib/esm/agents/content-reviwer.js +151 -0
- package/lib/esm/agents/multi-agent-page-writer.js +11 -12
- package/lib/esm/agents/page-structure-planner.js +0 -1
- package/lib/esm/tsconfig.tsbuildinfo +1 -1
- package/lib/esm/utils/agent-utils.js +19 -1
- package/lib/esm/utils/file-utils.js +53 -9
- package/lib/esm/utils/template-utils.d.ts +13 -0
- package/lib/esm/utils/template-utils.js +29 -0
- package/lib/types/agents/content-reviwer.d.ts +19 -0
- package/lib/types/tsconfig.tsbuildinfo +1 -1
- package/lib/types/utils/template-utils.d.ts +13 -0
- package/package.json +2 -2
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { ClaudeChatModel } from '@aigne/core/models/claude-chat-model.js';
|
|
2
|
+
import { DeepSeekChatModel } from '@aigne/core/models/deepseek-chat-model.js';
|
|
2
3
|
import { GeminiChatModel } from '@aigne/core/models/gemini-chat-model.js';
|
|
3
4
|
import { OpenAIChatModel } from '@aigne/core/models/openai-chat-model.js';
|
|
5
|
+
import { XAIChatModel } from '@aigne/core/models/xai-chat-model.js';
|
|
4
6
|
import assert from 'node:assert';
|
|
5
|
-
const { OPENAI_API_KEY, GEMINI_API_KEY, CLAUDE_API_KEY } = process.env;
|
|
7
|
+
const { OPENAI_API_KEY, GEMINI_API_KEY, CLAUDE_API_KEY, XAI_API_KEY, DEEPSEEK_API_KEY } = process.env;
|
|
6
8
|
export function getModel(modelName = 'openai') {
|
|
7
9
|
if (modelName?.includes('gpt')) {
|
|
8
10
|
assert(OPENAI_API_KEY, 'Please set the OPENAI_API_KEY environment variable');
|
|
@@ -34,5 +36,21 @@ export function getModel(modelName = 'openai') {
|
|
|
34
36
|
});
|
|
35
37
|
return model;
|
|
36
38
|
}
|
|
39
|
+
if (modelName?.includes('grok')) {
|
|
40
|
+
assert(XAI_API_KEY, 'Please set the XAI_API_KEY environment variable');
|
|
41
|
+
const grok = new XAIChatModel({
|
|
42
|
+
apiKey: XAI_API_KEY,
|
|
43
|
+
model: modelName,
|
|
44
|
+
});
|
|
45
|
+
return grok;
|
|
46
|
+
}
|
|
47
|
+
if (modelName?.includes('deepseek')) {
|
|
48
|
+
assert(DEEPSEEK_API_KEY, 'Please set the DEEPSEEK_API_KEY environment variable');
|
|
49
|
+
const deepseek = new DeepSeekChatModel({
|
|
50
|
+
apiKey: DEEPSEEK_API_KEY,
|
|
51
|
+
model: modelName,
|
|
52
|
+
});
|
|
53
|
+
return deepseek;
|
|
54
|
+
}
|
|
37
55
|
return undefined;
|
|
38
56
|
}
|
|
@@ -8,6 +8,7 @@ import path from 'path';
|
|
|
8
8
|
export async function updateFileList() {
|
|
9
9
|
const outputDir = path.join(process.cwd(), 'sample-output');
|
|
10
10
|
const indexPath = path.join(outputDir, 'index.html');
|
|
11
|
+
const dataJsPath = path.join(outputDir, 'file-list-data.js');
|
|
11
12
|
// 存储所有子文件夹及其HTML文件信息
|
|
12
13
|
const fileList = [];
|
|
13
14
|
try {
|
|
@@ -30,28 +31,71 @@ export async function updateFileList() {
|
|
|
30
31
|
.filter((file) => file.isFile() && file.name.endsWith('.html'))
|
|
31
32
|
.map((file) => {
|
|
32
33
|
const fileName = file.name.replace(/\.html$/, '');
|
|
34
|
+
const jsonFileName = `${fileName}.json`;
|
|
35
|
+
const jsonFilePath = path.join(folderPath, jsonFileName);
|
|
36
|
+
const htmlFilePath = `${folderName}/${file.name}`;
|
|
37
|
+
const jsonFileRelativePath = `${folderName}/${jsonFileName}`;
|
|
33
38
|
return {
|
|
34
39
|
name: fileName,
|
|
35
|
-
path:
|
|
40
|
+
path: htmlFilePath,
|
|
41
|
+
jsonPath: existsSync(jsonFilePath) ? jsonFileRelativePath : undefined,
|
|
36
42
|
createdAt: new Date().toISOString(),
|
|
37
43
|
};
|
|
38
44
|
});
|
|
45
|
+
// 读取每个HTML文件对应的JSON文件(如果存在)
|
|
46
|
+
for (const htmlFile of htmlFiles) {
|
|
47
|
+
if (htmlFile.jsonPath) {
|
|
48
|
+
try {
|
|
49
|
+
// eslint-disable-next-line no-await-in-loop
|
|
50
|
+
const jsonContent = await fs.readFile(path.join(outputDir, htmlFile.jsonPath), 'utf8');
|
|
51
|
+
const jsonData = JSON.parse(jsonContent);
|
|
52
|
+
// 提取评分数据
|
|
53
|
+
if (jsonData && jsonData.result) {
|
|
54
|
+
htmlFile.scoreData = {
|
|
55
|
+
total_score: jsonData.result.total_score,
|
|
56
|
+
level: jsonData.result.level,
|
|
57
|
+
suggestions: jsonData.result.suggestions,
|
|
58
|
+
dimension_scores: jsonData.result.dimension_scores,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
catch (jsonError) {
|
|
63
|
+
console.error(`Error reading JSON file ${htmlFile.jsonPath}:`, jsonError);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
}
|
|
39
67
|
// 将文件夹信息添加到列表
|
|
40
68
|
fileList.push({
|
|
41
69
|
folder: folderName,
|
|
42
70
|
files: htmlFiles,
|
|
43
71
|
});
|
|
44
72
|
}
|
|
45
|
-
//
|
|
73
|
+
// 创建独立的JS文件
|
|
74
|
+
const jsonString = JSON.stringify(fileList, null, 2);
|
|
75
|
+
const jsContent = `/* eslint-disable prettier/prettier */
|
|
76
|
+
/* eslint-disable @typescript-eslint/quotes */
|
|
77
|
+
// 自动生成的文件列表数据 - 请勿手动修改
|
|
78
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
79
|
+
const FILE_LIST_DATA = ${jsonString};
|
|
80
|
+
`;
|
|
81
|
+
await fs.writeFile(dataJsPath, jsContent, 'utf8');
|
|
82
|
+
// 确保index.html引用了这个JS文件
|
|
46
83
|
if (existsSync(indexPath)) {
|
|
47
84
|
let indexHtml = await fs.readFile(indexPath, 'utf8');
|
|
48
|
-
//
|
|
49
|
-
const
|
|
50
|
-
if (
|
|
51
|
-
//
|
|
52
|
-
const
|
|
53
|
-
|
|
54
|
-
|
|
85
|
+
// 检查index.html是否已经包含了对file-list-data.js的引用
|
|
86
|
+
const scriptIncludeRegex = /<script src=["']file-list-data\.js["']><\/script>/;
|
|
87
|
+
if (!scriptIncludeRegex.test(indexHtml)) {
|
|
88
|
+
// 如果没有引用,则替换原来的内联数据定义为引用外部JS文件
|
|
89
|
+
const fileListPlaceholder = /const FILE_LIST_DATA = .*?;/s;
|
|
90
|
+
if (fileListPlaceholder.test(indexHtml)) {
|
|
91
|
+
// 替换内联数据为引用外部JS文件
|
|
92
|
+
indexHtml = indexHtml.replace(fileListPlaceholder, `// 文件列表数据已移至外部JS文件
|
|
93
|
+
// 以下行将在第一次更新时被删除
|
|
94
|
+
const FILE_LIST_DATA = [];`);
|
|
95
|
+
// 在</head>前添加script标签引用外部JS文件
|
|
96
|
+
indexHtml = indexHtml.replace('</head>', ' <script src="file-list-data.js"></script>\n </head>');
|
|
97
|
+
await fs.writeFile(indexPath, indexHtml, 'utf8');
|
|
98
|
+
}
|
|
55
99
|
}
|
|
56
100
|
}
|
|
57
101
|
}
|
|
@@ -26,3 +26,16 @@ export declare function saveHtmlContent({ htmlContent, outputFolder, outputFileN
|
|
|
26
26
|
outputFolder: string;
|
|
27
27
|
outputFileName: string;
|
|
28
28
|
}): Promise<string>;
|
|
29
|
+
/**
|
|
30
|
+
* 保存JSON内容到指定目录
|
|
31
|
+
* @param jsonContent 要保存的JSON数据
|
|
32
|
+
* @param outputFolder 输出文件夹路径
|
|
33
|
+
* @param outputFileName 输出JSON文件名称,不包含扩展名
|
|
34
|
+
* @returns 生成的JSON文件的完整路径
|
|
35
|
+
* @throws 如果无法创建输出目录或写入文件则抛出异常
|
|
36
|
+
*/
|
|
37
|
+
export declare function saveJsonContent({ jsonContent, outputFolder, outputFileName, }: {
|
|
38
|
+
jsonContent: Record<string, any> | string;
|
|
39
|
+
outputFolder: string;
|
|
40
|
+
outputFileName: string;
|
|
41
|
+
}): Promise<string>;
|
|
@@ -65,3 +65,32 @@ export async function saveHtmlContent({ htmlContent, outputFolder, outputFileNam
|
|
|
65
65
|
throw new Error(`Failed to save HTML content: ${err.message}`);
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
+
/**
|
|
69
|
+
* 保存JSON内容到指定目录
|
|
70
|
+
* @param jsonContent 要保存的JSON数据
|
|
71
|
+
* @param outputFolder 输出文件夹路径
|
|
72
|
+
* @param outputFileName 输出JSON文件名称,不包含扩展名
|
|
73
|
+
* @returns 生成的JSON文件的完整路径
|
|
74
|
+
* @throws 如果无法创建输出目录或写入文件则抛出异常
|
|
75
|
+
*/
|
|
76
|
+
export async function saveJsonContent({ jsonContent, outputFolder, outputFileName, }) {
|
|
77
|
+
try {
|
|
78
|
+
// 创建输出目录
|
|
79
|
+
const outputDir = path.resolve(process.cwd(), 'sample-output', outputFolder);
|
|
80
|
+
// 确保输出目录存在
|
|
81
|
+
if (!fs.existsSync(outputDir)) {
|
|
82
|
+
fs.mkdirSync(outputDir, { recursive: true });
|
|
83
|
+
}
|
|
84
|
+
// 构建输出文件的完整路径
|
|
85
|
+
const outputFilePath = path.join(outputDir, `${outputFileName}.json`);
|
|
86
|
+
// 如果传入的是对象,转换为JSON字符串
|
|
87
|
+
const content = typeof jsonContent === 'string' ? jsonContent : JSON.stringify(jsonContent, null, 2);
|
|
88
|
+
// 写入JSON内容
|
|
89
|
+
fs.writeFileSync(outputFilePath, content, 'utf-8');
|
|
90
|
+
return outputFilePath;
|
|
91
|
+
}
|
|
92
|
+
catch (error) {
|
|
93
|
+
const err = error;
|
|
94
|
+
throw new Error(`Failed to save JSON content: ${err.message}`);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { AIAgent } from '@aigne/core';
|
|
2
|
+
export declare const contentReviewerAgent: AIAgent<{
|
|
3
|
+
question: string;
|
|
4
|
+
locale: string;
|
|
5
|
+
dataSource: string;
|
|
6
|
+
content: string;
|
|
7
|
+
}, {
|
|
8
|
+
result: {
|
|
9
|
+
total_score: number;
|
|
10
|
+
level: string;
|
|
11
|
+
suggestions: string[];
|
|
12
|
+
dimension_scores: {
|
|
13
|
+
name: string;
|
|
14
|
+
score: number;
|
|
15
|
+
maxScore: number;
|
|
16
|
+
comment: string;
|
|
17
|
+
}[];
|
|
18
|
+
};
|
|
19
|
+
}>;
|