@8btc/ppt-generator-mcp 0.0.32-beta.13 → 0.0.32-beta.14
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.
|
@@ -13,6 +13,7 @@ const validator_1 = require("../utils/validator");
|
|
|
13
13
|
const schema_1 = require("../utils/schema");
|
|
14
14
|
const zod_1 = require("zod");
|
|
15
15
|
const fs_extra_1 = __importDefault(require("fs-extra"));
|
|
16
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
16
17
|
const inputSchema = {
|
|
17
18
|
outputPath: zod_1.z.string().describe("ppt文件所在文件夹路径"),
|
|
18
19
|
outlinePath: zod_1.z
|
|
@@ -34,12 +35,14 @@ const t = zod_1.z.object({ ...inputSchema });
|
|
|
34
35
|
const toolHandler = async ({ outputPath, outlinePath, pageIndex, resultJsonPath, }) => {
|
|
35
36
|
try {
|
|
36
37
|
// 读取大纲文件
|
|
37
|
-
const
|
|
38
|
+
const _outlinePath = node_path_1.default.resolve(outputPath, outlinePath);
|
|
39
|
+
const outlineData = await fs_extra_1.default.readJSON(_outlinePath);
|
|
38
40
|
if (!Array.isArray(outlineData)) {
|
|
39
41
|
throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, "Invalid outline file format.");
|
|
40
42
|
}
|
|
41
43
|
// 读取结果文件
|
|
42
|
-
const
|
|
44
|
+
const _resultJsonPath = node_path_1.default.resolve(outputPath, resultJsonPath);
|
|
45
|
+
const resultData = await fs_extra_1.default.readJSON(_resultJsonPath);
|
|
43
46
|
if (!Array.isArray(resultData.slides)) {
|
|
44
47
|
throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, "Invalid result file format.");
|
|
45
48
|
}
|
|
@@ -81,7 +81,7 @@ exports.generatePPTSlides = generatePPTSlides;
|
|
|
81
81
|
const formatOutlineList = (outlineList, contentsTemplates) => {
|
|
82
82
|
const normalizedOutlineList = [];
|
|
83
83
|
const maxContentsCount = contentsTemplates.reduce((acc, cur) => {
|
|
84
|
-
const count = cur.elements.filter((el) => (0, slides_util_1.checkTextType)(el, "item"))
|
|
84
|
+
const count = cur.elements.filter((el) => (0, slides_util_1.checkTextType)(el, "item"))?.length;
|
|
85
85
|
acc = Math.max(acc, count);
|
|
86
86
|
return acc;
|
|
87
87
|
}, 1);
|
|
@@ -90,7 +90,7 @@ const formatOutlineList = (outlineList, contentsTemplates) => {
|
|
|
90
90
|
outlineItem.outlineIndex = idx++;
|
|
91
91
|
if (outlineItem.type === "content") {
|
|
92
92
|
const items = outlineItem.data.items;
|
|
93
|
-
if (items
|
|
93
|
+
if (items?.length === 5 || items?.length === 6) {
|
|
94
94
|
const items1 = items.slice(0, 3);
|
|
95
95
|
const items2 = items.slice(3);
|
|
96
96
|
normalizedOutlineList.push({
|
|
@@ -103,7 +103,7 @@ const formatOutlineList = (outlineList, contentsTemplates) => {
|
|
|
103
103
|
offset: 3,
|
|
104
104
|
});
|
|
105
105
|
}
|
|
106
|
-
else if (items
|
|
106
|
+
else if (items?.length === 7 || items?.length === 8) {
|
|
107
107
|
const items1 = items.slice(0, 4);
|
|
108
108
|
const items2 = items.slice(4);
|
|
109
109
|
normalizedOutlineList.push({
|
|
@@ -116,7 +116,7 @@ const formatOutlineList = (outlineList, contentsTemplates) => {
|
|
|
116
116
|
offset: 4,
|
|
117
117
|
});
|
|
118
118
|
}
|
|
119
|
-
else if (items
|
|
119
|
+
else if (items?.length === 9 || items?.length === 10) {
|
|
120
120
|
const items1 = items.slice(0, 3);
|
|
121
121
|
const items2 = items.slice(3, 6);
|
|
122
122
|
const items3 = items.slice(6);
|
|
@@ -135,7 +135,7 @@ const formatOutlineList = (outlineList, contentsTemplates) => {
|
|
|
135
135
|
offset: 6,
|
|
136
136
|
});
|
|
137
137
|
}
|
|
138
|
-
else if (items
|
|
138
|
+
else if (items?.length > 10) {
|
|
139
139
|
const items1 = items.slice(0, 4);
|
|
140
140
|
const items2 = items.slice(4, 8);
|
|
141
141
|
const items3 = items.slice(8);
|
|
@@ -160,8 +160,8 @@ const formatOutlineList = (outlineList, contentsTemplates) => {
|
|
|
160
160
|
}
|
|
161
161
|
else if (outlineItem.type === "contents") {
|
|
162
162
|
const items = outlineItem.data.items;
|
|
163
|
-
if (items
|
|
164
|
-
const loop = Math.ceil(items
|
|
163
|
+
if (items?.length > maxContentsCount) {
|
|
164
|
+
const loop = Math.ceil(items?.length / maxContentsCount);
|
|
165
165
|
for (let i = 0; i < loop; i++) {
|
|
166
166
|
const items1 = items.slice(i * maxContentsCount, (i + 1) * maxContentsCount);
|
|
167
167
|
normalizedOutlineList.push({
|
package/package.json
CHANGED