@8btc/ppt-generator-mcp 0.0.1 → 0.0.3
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/dist/index.js +23 -9
- package/dist/ppt-generator.d.ts +7 -10
- package/dist/ppt-generator.js +4 -28
- package/package.json +5 -1
package/dist/index.js
CHANGED
|
@@ -111,28 +111,42 @@ class PPTGeneratorMCPServer {
|
|
|
111
111
|
await fs_extra_1.default.writeJson(node_path_1.default.join(outputPath, "outline.json"), outline, {
|
|
112
112
|
spaces: 2,
|
|
113
113
|
});
|
|
114
|
-
|
|
114
|
+
// 读取模板文件
|
|
115
|
+
const templateData = await fs_extra_1.default.readJson(templateFilePath);
|
|
116
|
+
const resultJSON = await this.pptGenerator.generateResultJson({
|
|
115
117
|
outline: outline,
|
|
116
|
-
|
|
117
|
-
outputPath: node_path_1.default.join(outputPath, "result.json"),
|
|
118
|
+
templateData: templateData,
|
|
118
119
|
});
|
|
119
|
-
|
|
120
|
+
// 保存result.json
|
|
121
|
+
await fs_extra_1.default.writeJson(node_path_1.default.join(outputPath, "result.json"), resultJSON, {
|
|
122
|
+
spaces: 2,
|
|
123
|
+
});
|
|
124
|
+
if (!resultJSON) {
|
|
120
125
|
console.error("generate_result_json 生成 result.json 失败");
|
|
121
126
|
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, "生成result.json失败");
|
|
122
127
|
}
|
|
123
|
-
const
|
|
124
|
-
result,
|
|
125
|
-
outputPath: node_path_1.default.join(outputPath, "result.pptx"),
|
|
128
|
+
const pptx = await this.pptGenerator.generatePPTFromResult({
|
|
129
|
+
result: resultJSON,
|
|
126
130
|
});
|
|
131
|
+
// 确定输出路径
|
|
132
|
+
const pptOutputPath = node_path_1.default.join(outputPath, "result.pptx");
|
|
133
|
+
// 确保输出目录存在
|
|
134
|
+
await fs_extra_1.default.ensureDir(node_path_1.default.dirname(pptOutputPath));
|
|
135
|
+
// 保存PPT文件
|
|
136
|
+
await pptx.writeFile({ fileName: pptOutputPath });
|
|
127
137
|
return {
|
|
128
138
|
content: [
|
|
129
139
|
{
|
|
130
140
|
type: "text",
|
|
131
|
-
text: JSON.stringify(
|
|
141
|
+
text: JSON.stringify({
|
|
142
|
+
success: true,
|
|
143
|
+
outputPath: pptOutputPath,
|
|
144
|
+
message: `PPT文件生成成功: ${pptOutputPath}`,
|
|
145
|
+
}, null, 2),
|
|
132
146
|
},
|
|
133
147
|
{
|
|
134
148
|
type: "resource_link",
|
|
135
|
-
uri: `file:///${
|
|
149
|
+
uri: `file:///${pptOutputPath}`,
|
|
136
150
|
name: "result.pptx",
|
|
137
151
|
description: "生成的PPT",
|
|
138
152
|
mimeType: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
|
package/dist/ppt-generator.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Outline } from "./types/outline";
|
|
2
2
|
import { Slide } from "./types/slide";
|
|
3
3
|
interface IResult {
|
|
4
|
-
title: string;
|
|
5
4
|
width: number;
|
|
6
5
|
height: number;
|
|
7
6
|
theme: any;
|
|
@@ -20,20 +19,18 @@ export declare class PPTGenerator {
|
|
|
20
19
|
*/
|
|
21
20
|
generateResultJson(params: {
|
|
22
21
|
outline: Outline[];
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
templateData: {
|
|
23
|
+
slides: Slide[];
|
|
24
|
+
width: number;
|
|
25
|
+
height: number;
|
|
26
|
+
theme: any;
|
|
27
|
+
};
|
|
26
28
|
}): Promise<IResult | undefined>;
|
|
27
29
|
/**
|
|
28
30
|
* 两步生成PPT - 第二步:从result.json生成PPT
|
|
29
31
|
*/
|
|
30
32
|
generatePPTFromResult(params: {
|
|
31
33
|
result: IResult;
|
|
32
|
-
|
|
33
|
-
}): Promise<{
|
|
34
|
-
success: boolean;
|
|
35
|
-
outputPath?: string;
|
|
36
|
-
message: string;
|
|
37
|
-
}>;
|
|
34
|
+
}): Promise<import("pptxgenjs").default>;
|
|
38
35
|
}
|
|
39
36
|
export {};
|
package/dist/ppt-generator.js
CHANGED
|
@@ -35,23 +35,16 @@ class PPTGenerator {
|
|
|
35
35
|
*/
|
|
36
36
|
async generateResultJson(params) {
|
|
37
37
|
try {
|
|
38
|
-
const { outline,
|
|
39
|
-
// 读取模板文件
|
|
40
|
-
const templateData = await fs_extra_1.default.readJson(templateFilePath);
|
|
38
|
+
const { outline, templateData } = params;
|
|
41
39
|
// 使用AIPPT函数生成slides
|
|
42
40
|
const generatedSlides = (0, generate_ppt_slides_1.generatePPTSlides)(templateData.slides, outline);
|
|
43
41
|
// 构建完整的result对象,包含模板的其他属性
|
|
44
42
|
const resultData = {
|
|
45
|
-
title: templateData.title,
|
|
46
43
|
width: templateData.width,
|
|
47
44
|
height: templateData.height,
|
|
48
45
|
theme: templateData.theme,
|
|
49
46
|
slides: generatedSlides,
|
|
50
47
|
};
|
|
51
|
-
// 生成输出路径
|
|
52
|
-
const resultPath = outputPath;
|
|
53
|
-
// 保存result.json
|
|
54
|
-
await fs_extra_1.default.writeJson(resultPath, resultData, { spaces: 2 });
|
|
55
48
|
return resultData;
|
|
56
49
|
}
|
|
57
50
|
catch (error) {
|
|
@@ -64,14 +57,7 @@ class PPTGenerator {
|
|
|
64
57
|
*/
|
|
65
58
|
async generatePPTFromResult(params) {
|
|
66
59
|
try {
|
|
67
|
-
const { result: resultData
|
|
68
|
-
// 构造导出选项
|
|
69
|
-
const options = {
|
|
70
|
-
title: resultData.title || "Generated Presentation",
|
|
71
|
-
author: "PPT Generator",
|
|
72
|
-
subject: "Auto-generated presentation",
|
|
73
|
-
keywords: "presentation, auto-generated",
|
|
74
|
-
};
|
|
60
|
+
const { result: resultData } = params;
|
|
75
61
|
// 构造完整的导出选项
|
|
76
62
|
const exportOptions = {
|
|
77
63
|
slides: resultData.slides,
|
|
@@ -84,22 +70,12 @@ class PPTGenerator {
|
|
|
84
70
|
shadow: { h: 0, v: 0, blur: 0, color: "#000000" },
|
|
85
71
|
},
|
|
86
72
|
viewportRatio: (resultData.width || 1920) / (resultData.height || 1080),
|
|
87
|
-
title:
|
|
73
|
+
title: "Generated Presentation",
|
|
88
74
|
viewportSize: resultData.width || 1920,
|
|
89
75
|
};
|
|
90
76
|
// 使用exportPPTX生成PPT
|
|
91
77
|
const pptx = (0, export_pptx_1.exportPPTX)(resultData.slides, false, exportOptions);
|
|
92
|
-
|
|
93
|
-
const finalOutputPath = outputPath;
|
|
94
|
-
// 确保输出目录存在
|
|
95
|
-
await fs_extra_1.default.ensureDir(posix_1.default.dirname(finalOutputPath));
|
|
96
|
-
// 保存PPT文件
|
|
97
|
-
await pptx.writeFile({ fileName: finalOutputPath });
|
|
98
|
-
return {
|
|
99
|
-
success: true,
|
|
100
|
-
outputPath: finalOutputPath,
|
|
101
|
-
message: `PPT文件生成成功: ${finalOutputPath}`,
|
|
102
|
-
};
|
|
78
|
+
return pptx;
|
|
103
79
|
}
|
|
104
80
|
catch (error) {
|
|
105
81
|
console.error(`从result.json生成PPT失败: ${error.message}`);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@8btc/ppt-generator-mcp",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.3",
|
|
4
4
|
"description": "MCP service for generating PPT files from AI-generated outlines and templates",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
"bin": {
|
|
17
17
|
"@8btc/ppt-generator-mcp": "dist/index.js"
|
|
18
18
|
},
|
|
19
|
+
"exports": {
|
|
20
|
+
".": "./dist/index.js",
|
|
21
|
+
"./ppt-generator": "./dist/ppt-generator.js"
|
|
22
|
+
},
|
|
19
23
|
"keywords": [
|
|
20
24
|
"mcp",
|
|
21
25
|
"ppt",
|