@8btc/ppt-generator-mcp 0.0.32-beta.13 → 0.0.32-beta.15
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/tools/generate-ppt.d.ts +0 -9
- package/dist/tools/generate-ppt.js +1 -2
- package/dist/tools/get-outline-item.d.ts +4 -4
- package/dist/tools/get-outline-item.js +9 -6
- package/dist/tools/pptGenerator/generate-ppt-slides.js +7 -7
- package/dist/tools/update-ppt.d.ts +38 -4
- package/dist/tools/update-ppt.js +10 -6
- package/package.json +1 -1
|
@@ -89,15 +89,12 @@ declare const t: z.ZodObject<{
|
|
|
89
89
|
images: z.ZodArray<z.ZodObject<{
|
|
90
90
|
imageType: z.ZodEnum<["pageFigure", "itemFigure"]>;
|
|
91
91
|
src: z.ZodString;
|
|
92
|
-
proportion: z.ZodEnum<["vertical", "horizontal"]>;
|
|
93
92
|
}, "strip", z.ZodTypeAny, {
|
|
94
93
|
src: string;
|
|
95
94
|
imageType: "pageFigure" | "itemFigure";
|
|
96
|
-
proportion: "vertical" | "horizontal";
|
|
97
95
|
}, {
|
|
98
96
|
src: string;
|
|
99
97
|
imageType: "pageFigure" | "itemFigure";
|
|
100
|
-
proportion: "vertical" | "horizontal";
|
|
101
98
|
}>, "many">;
|
|
102
99
|
}, "strip", z.ZodTypeAny, {
|
|
103
100
|
title: string;
|
|
@@ -108,7 +105,6 @@ declare const t: z.ZodObject<{
|
|
|
108
105
|
images: {
|
|
109
106
|
src: string;
|
|
110
107
|
imageType: "pageFigure" | "itemFigure";
|
|
111
|
-
proportion: "vertical" | "horizontal";
|
|
112
108
|
}[];
|
|
113
109
|
}, {
|
|
114
110
|
title: string;
|
|
@@ -119,7 +115,6 @@ declare const t: z.ZodObject<{
|
|
|
119
115
|
images: {
|
|
120
116
|
src: string;
|
|
121
117
|
imageType: "pageFigure" | "itemFigure";
|
|
122
|
-
proportion: "vertical" | "horizontal";
|
|
123
118
|
}[];
|
|
124
119
|
}>;
|
|
125
120
|
}, "strip", z.ZodTypeAny, {
|
|
@@ -133,7 +128,6 @@ declare const t: z.ZodObject<{
|
|
|
133
128
|
images: {
|
|
134
129
|
src: string;
|
|
135
130
|
imageType: "pageFigure" | "itemFigure";
|
|
136
|
-
proportion: "vertical" | "horizontal";
|
|
137
131
|
}[];
|
|
138
132
|
};
|
|
139
133
|
}, {
|
|
@@ -147,7 +141,6 @@ declare const t: z.ZodObject<{
|
|
|
147
141
|
images: {
|
|
148
142
|
src: string;
|
|
149
143
|
imageType: "pageFigure" | "itemFigure";
|
|
150
|
-
proportion: "vertical" | "horizontal";
|
|
151
144
|
}[];
|
|
152
145
|
};
|
|
153
146
|
}>, z.ZodObject<{
|
|
@@ -187,7 +180,6 @@ declare const t: z.ZodObject<{
|
|
|
187
180
|
images: {
|
|
188
181
|
src: string;
|
|
189
182
|
imageType: "pageFigure" | "itemFigure";
|
|
190
|
-
proportion: "vertical" | "horizontal";
|
|
191
183
|
}[];
|
|
192
184
|
};
|
|
193
185
|
} | {
|
|
@@ -225,7 +217,6 @@ declare const t: z.ZodObject<{
|
|
|
225
217
|
images: {
|
|
226
218
|
src: string;
|
|
227
219
|
imageType: "pageFigure" | "itemFigure";
|
|
228
|
-
proportion: "vertical" | "horizontal";
|
|
229
220
|
}[];
|
|
230
221
|
};
|
|
231
222
|
} | {
|
|
@@ -50,7 +50,6 @@ const inputSchema = {
|
|
|
50
50
|
images: zod_1.z.array(zod_1.z.object({
|
|
51
51
|
imageType: zod_1.z.enum(["pageFigure", "itemFigure"]), // 先不要背景
|
|
52
52
|
src: zod_1.z.string(),
|
|
53
|
-
proportion: zod_1.z.enum(["vertical", "horizontal"]),
|
|
54
53
|
})),
|
|
55
54
|
}),
|
|
56
55
|
}),
|
|
@@ -129,7 +128,7 @@ generate_ppt参数outline的要求
|
|
|
129
128
|
inputSchema: (0, schema_1.zodToJsonSchema)(inputSchema),
|
|
130
129
|
};
|
|
131
130
|
const toolHandler = async ({ outline, templateFilePath, outputPath, }) => {
|
|
132
|
-
|
|
131
|
+
// logger.info("generate_ppt", { outline, templateFilePath, outputPath });
|
|
133
132
|
if (!templateFilePath) {
|
|
134
133
|
templateFilePath = node_path_1.default.join(__dirname, "..", "tpls", "tpl-2.json");
|
|
135
134
|
}
|
|
@@ -3,17 +3,17 @@ declare const t: z.ZodObject<{
|
|
|
3
3
|
outputPath: z.ZodString;
|
|
4
4
|
outlinePath: z.ZodString;
|
|
5
5
|
resultJsonPath: z.ZodString;
|
|
6
|
-
|
|
6
|
+
pageNumber: z.ZodNumber;
|
|
7
7
|
}, "strip", z.ZodTypeAny, {
|
|
8
8
|
outputPath: string;
|
|
9
9
|
outlinePath: string;
|
|
10
10
|
resultJsonPath: string;
|
|
11
|
-
|
|
11
|
+
pageNumber: number;
|
|
12
12
|
}, {
|
|
13
13
|
outputPath: string;
|
|
14
14
|
outlinePath: string;
|
|
15
15
|
resultJsonPath: string;
|
|
16
|
-
|
|
16
|
+
pageNumber: number;
|
|
17
17
|
}>;
|
|
18
18
|
type IUpdatePPTTImage = z.infer<typeof t>;
|
|
19
19
|
export declare const get_outline_item: {
|
|
@@ -28,7 +28,7 @@ export declare const get_outline_item: {
|
|
|
28
28
|
} | undefined;
|
|
29
29
|
};
|
|
30
30
|
};
|
|
31
|
-
toolHandler: ({ outputPath, outlinePath,
|
|
31
|
+
toolHandler: ({ outputPath, outlinePath, pageNumber, resultJsonPath, }: IUpdatePPTTImage) => Promise<{
|
|
32
32
|
content: {
|
|
33
33
|
type: string;
|
|
34
34
|
text: string;
|
|
@@ -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
|
|
@@ -21,7 +22,7 @@ const inputSchema = {
|
|
|
21
22
|
resultJsonPath: zod_1.z
|
|
22
23
|
.string()
|
|
23
24
|
.describe(`PPT结果json地址, 例如:AI个性化学习_result.json`),
|
|
24
|
-
|
|
25
|
+
pageNumber: zod_1.z.number().describe("需要替换的页码, 例如:1 ~ 100"),
|
|
25
26
|
};
|
|
26
27
|
// tool descriptor
|
|
27
28
|
const tool = {
|
|
@@ -31,22 +32,24 @@ const tool = {
|
|
|
31
32
|
inputSchema: (0, schema_1.zodToJsonSchema)(inputSchema),
|
|
32
33
|
};
|
|
33
34
|
const t = zod_1.z.object({ ...inputSchema });
|
|
34
|
-
const toolHandler = async ({ outputPath, outlinePath,
|
|
35
|
+
const toolHandler = async ({ outputPath, outlinePath, pageNumber, 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
|
}
|
|
46
|
-
if (
|
|
49
|
+
if (pageNumber < 0 || pageNumber >= outlineData.length) {
|
|
47
50
|
throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, "Page index out of range.");
|
|
48
51
|
}
|
|
49
|
-
const outlineItem = outlineData[resultData.slides[
|
|
52
|
+
const outlineItem = outlineData[resultData.slides[pageNumber - 1]?.outlineIndex];
|
|
50
53
|
if (!outlineItem) {
|
|
51
54
|
throw new types_js_1.McpError(types_js_1.ErrorCode.InternalError, "Invalid outline file format.");
|
|
52
55
|
}
|
|
@@ -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({
|
|
@@ -4,7 +4,7 @@ declare const t: z.ZodObject<{
|
|
|
4
4
|
outputPath: z.ZodString;
|
|
5
5
|
outlinePath: z.ZodString;
|
|
6
6
|
resultJsonPath: z.ZodString;
|
|
7
|
-
|
|
7
|
+
pageNumber: z.ZodNumber;
|
|
8
8
|
newContent: z.ZodDiscriminatedUnion<"type", [z.ZodObject<{
|
|
9
9
|
type: z.ZodLiteral<"cover">;
|
|
10
10
|
data: z.ZodObject<{
|
|
@@ -89,18 +89,36 @@ declare const t: z.ZodObject<{
|
|
|
89
89
|
title: string;
|
|
90
90
|
text: string;
|
|
91
91
|
}>, "many">;
|
|
92
|
+
images: z.ZodArray<z.ZodObject<{
|
|
93
|
+
imageType: z.ZodEnum<["pageFigure", "itemFigure"]>;
|
|
94
|
+
src: z.ZodString;
|
|
95
|
+
}, "strip", z.ZodTypeAny, {
|
|
96
|
+
src: string;
|
|
97
|
+
imageType: "pageFigure" | "itemFigure";
|
|
98
|
+
}, {
|
|
99
|
+
src: string;
|
|
100
|
+
imageType: "pageFigure" | "itemFigure";
|
|
101
|
+
}>, "many">;
|
|
92
102
|
}, "strip", z.ZodTypeAny, {
|
|
93
103
|
title: string;
|
|
94
104
|
items: {
|
|
95
105
|
title: string;
|
|
96
106
|
text: string;
|
|
97
107
|
}[];
|
|
108
|
+
images: {
|
|
109
|
+
src: string;
|
|
110
|
+
imageType: "pageFigure" | "itemFigure";
|
|
111
|
+
}[];
|
|
98
112
|
}, {
|
|
99
113
|
title: string;
|
|
100
114
|
items: {
|
|
101
115
|
title: string;
|
|
102
116
|
text: string;
|
|
103
117
|
}[];
|
|
118
|
+
images: {
|
|
119
|
+
src: string;
|
|
120
|
+
imageType: "pageFigure" | "itemFigure";
|
|
121
|
+
}[];
|
|
104
122
|
}>;
|
|
105
123
|
}, "strip", z.ZodTypeAny, {
|
|
106
124
|
type: "content";
|
|
@@ -110,6 +128,10 @@ declare const t: z.ZodObject<{
|
|
|
110
128
|
title: string;
|
|
111
129
|
text: string;
|
|
112
130
|
}[];
|
|
131
|
+
images: {
|
|
132
|
+
src: string;
|
|
133
|
+
imageType: "pageFigure" | "itemFigure";
|
|
134
|
+
}[];
|
|
113
135
|
};
|
|
114
136
|
}, {
|
|
115
137
|
type: "content";
|
|
@@ -119,6 +141,10 @@ declare const t: z.ZodObject<{
|
|
|
119
141
|
title: string;
|
|
120
142
|
text: string;
|
|
121
143
|
}[];
|
|
144
|
+
images: {
|
|
145
|
+
src: string;
|
|
146
|
+
imageType: "pageFigure" | "itemFigure";
|
|
147
|
+
}[];
|
|
122
148
|
};
|
|
123
149
|
}>, z.ZodObject<{
|
|
124
150
|
type: z.ZodLiteral<"end">;
|
|
@@ -132,7 +158,7 @@ declare const t: z.ZodObject<{
|
|
|
132
158
|
outputPath: string;
|
|
133
159
|
outlinePath: string;
|
|
134
160
|
resultJsonPath: string;
|
|
135
|
-
|
|
161
|
+
pageNumber: number;
|
|
136
162
|
newContent: {
|
|
137
163
|
type: "cover";
|
|
138
164
|
data: {
|
|
@@ -159,6 +185,10 @@ declare const t: z.ZodObject<{
|
|
|
159
185
|
title: string;
|
|
160
186
|
text: string;
|
|
161
187
|
}[];
|
|
188
|
+
images: {
|
|
189
|
+
src: string;
|
|
190
|
+
imageType: "pageFigure" | "itemFigure";
|
|
191
|
+
}[];
|
|
162
192
|
};
|
|
163
193
|
} | {
|
|
164
194
|
type: "end";
|
|
@@ -168,7 +198,7 @@ declare const t: z.ZodObject<{
|
|
|
168
198
|
outputPath: string;
|
|
169
199
|
outlinePath: string;
|
|
170
200
|
resultJsonPath: string;
|
|
171
|
-
|
|
201
|
+
pageNumber: number;
|
|
172
202
|
newContent: {
|
|
173
203
|
type: "cover";
|
|
174
204
|
data: {
|
|
@@ -195,6 +225,10 @@ declare const t: z.ZodObject<{
|
|
|
195
225
|
title: string;
|
|
196
226
|
text: string;
|
|
197
227
|
}[];
|
|
228
|
+
images: {
|
|
229
|
+
src: string;
|
|
230
|
+
imageType: "pageFigure" | "itemFigure";
|
|
231
|
+
}[];
|
|
198
232
|
};
|
|
199
233
|
} | {
|
|
200
234
|
type: "end";
|
|
@@ -213,7 +247,7 @@ export declare const update_ppt: {
|
|
|
213
247
|
} | undefined;
|
|
214
248
|
};
|
|
215
249
|
};
|
|
216
|
-
toolHandler: ({ outlinePath,
|
|
250
|
+
toolHandler: ({ outlinePath, pageNumber, newContent, templateFilePath, outputPath, resultJsonPath, }: IUpdatePptOutline) => Promise<{
|
|
217
251
|
content: {
|
|
218
252
|
type: string;
|
|
219
253
|
text: string;
|
package/dist/tools/update-ppt.js
CHANGED
|
@@ -26,7 +26,7 @@ const inputSchema = {
|
|
|
26
26
|
resultJsonPath: zod_1.z
|
|
27
27
|
.string()
|
|
28
28
|
.describe(`需要替换的PPT结果json地址, 例如:AI个性化学习_result.json`),
|
|
29
|
-
|
|
29
|
+
pageNumber: zod_1.z.number().describe("需要替换的页码, 例如:1 ~ 100"),
|
|
30
30
|
newContent: zod_1.z.discriminatedUnion("type", [
|
|
31
31
|
zod_1.z.object({
|
|
32
32
|
type: zod_1.z.literal("cover"),
|
|
@@ -57,6 +57,10 @@ const inputSchema = {
|
|
|
57
57
|
title: zod_1.z.string(),
|
|
58
58
|
text: zod_1.z.string(),
|
|
59
59
|
})),
|
|
60
|
+
images: zod_1.z.array(zod_1.z.object({
|
|
61
|
+
imageType: zod_1.z.enum(["pageFigure", "itemFigure"]), // 先不要背景
|
|
62
|
+
src: zod_1.z.string(),
|
|
63
|
+
})),
|
|
60
64
|
}),
|
|
61
65
|
}),
|
|
62
66
|
zod_1.z.object({
|
|
@@ -72,7 +76,7 @@ const tool = {
|
|
|
72
76
|
inputSchema: (0, schema_1.zodToJsonSchema)(inputSchema),
|
|
73
77
|
};
|
|
74
78
|
const t = zod_1.z.object({ ...inputSchema });
|
|
75
|
-
const toolHandler = async ({ outlinePath,
|
|
79
|
+
const toolHandler = async ({ outlinePath, pageNumber, newContent, templateFilePath, outputPath, resultJsonPath, }) => {
|
|
76
80
|
try {
|
|
77
81
|
// --1.修改大纲文件--------------
|
|
78
82
|
const _outlinePath = node_path_1.default.resolve(outputPath, outlinePath);
|
|
@@ -80,7 +84,7 @@ const toolHandler = async ({ outlinePath, pageIndex, newContent, templateFilePat
|
|
|
80
84
|
if (!Array.isArray(outlineData)) {
|
|
81
85
|
throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, "Invalid outline file format.");
|
|
82
86
|
}
|
|
83
|
-
if (
|
|
87
|
+
if (pageNumber < 1 || pageNumber > outlineData.length) {
|
|
84
88
|
throw new types_js_1.McpError(types_js_1.ErrorCode.InvalidParams, "Page index out of range.");
|
|
85
89
|
}
|
|
86
90
|
const _resultJsonPath = node_path_1.default.resolve(outputPath, resultJsonPath);
|
|
@@ -96,7 +100,7 @@ const toolHandler = async ({ outlinePath, pageIndex, newContent, templateFilePat
|
|
|
96
100
|
//
|
|
97
101
|
}
|
|
98
102
|
}
|
|
99
|
-
const resultSlide = resultJson.slides[
|
|
103
|
+
const resultSlide = resultJson.slides[pageNumber - 1];
|
|
100
104
|
// 替换指定页码内容
|
|
101
105
|
outlineData[resultSlide?.outlineIndex || 0] = newContent;
|
|
102
106
|
// 写回大纲文件
|
|
@@ -120,8 +124,8 @@ const toolHandler = async ({ outlinePath, pageIndex, newContent, templateFilePat
|
|
|
120
124
|
outline: outlineData,
|
|
121
125
|
templateData: templateData,
|
|
122
126
|
});
|
|
123
|
-
resultJson.slides[
|
|
124
|
-
resultJSON?.slides[
|
|
127
|
+
resultJson.slides[pageNumber - 1] =
|
|
128
|
+
resultJSON?.slides[pageNumber - 1] || resultJson.slides[pageNumber - 1];
|
|
125
129
|
// 保存result.json
|
|
126
130
|
await fs_extra_1.default.writeJson(node_path_1.default.join(outputPath, `${fileName}_result.json`), resultJson, {
|
|
127
131
|
spaces: 2,
|
package/package.json
CHANGED