hanseol-dev 5.0.2-dev.9 → 5.0.2-dev.90
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/agents/common/sub-agent.d.ts +21 -0
- package/dist/agents/common/sub-agent.d.ts.map +1 -1
- package/dist/agents/common/sub-agent.js +195 -10
- package/dist/agents/common/sub-agent.js.map +1 -1
- package/dist/agents/index.d.ts +1 -1
- package/dist/agents/index.d.ts.map +1 -1
- package/dist/agents/index.js +1 -1
- package/dist/agents/index.js.map +1 -1
- package/dist/agents/office/excel-agent.d.ts +1 -1
- package/dist/agents/office/excel-agent.d.ts.map +1 -1
- package/dist/agents/office/excel-agent.js +6 -6
- package/dist/agents/office/excel-agent.js.map +1 -1
- package/dist/agents/office/excel-create-agent.d.ts +3 -0
- package/dist/agents/office/excel-create-agent.d.ts.map +1 -0
- package/dist/agents/office/excel-create-agent.js +38 -0
- package/dist/agents/office/excel-create-agent.js.map +1 -0
- package/dist/agents/office/excel-create-prompts.d.ts +4 -0
- package/dist/agents/office/excel-create-prompts.d.ts.map +1 -0
- package/dist/agents/office/excel-create-prompts.js +154 -0
- package/dist/agents/office/excel-create-prompts.js.map +1 -0
- package/dist/agents/office/index.d.ts +6 -3
- package/dist/agents/office/index.d.ts.map +1 -1
- package/dist/agents/office/index.js +6 -3
- package/dist/agents/office/index.js.map +1 -1
- package/dist/agents/office/powerpoint-agent.d.ts +1 -1
- package/dist/agents/office/powerpoint-agent.d.ts.map +1 -1
- package/dist/agents/office/powerpoint-agent.js +6 -6
- package/dist/agents/office/powerpoint-agent.js.map +1 -1
- package/dist/agents/office/powerpoint-create-agent.d.ts +3 -0
- package/dist/agents/office/powerpoint-create-agent.d.ts.map +1 -0
- package/dist/agents/office/powerpoint-create-agent.js +918 -0
- package/dist/agents/office/powerpoint-create-agent.js.map +1 -0
- package/dist/agents/office/powerpoint-create-prompts.d.ts +19 -0
- package/dist/agents/office/powerpoint-create-prompts.d.ts.map +1 -0
- package/dist/agents/office/powerpoint-create-prompts.js +376 -0
- package/dist/agents/office/powerpoint-create-prompts.js.map +1 -0
- package/dist/agents/office/prompts.d.ts +10 -3
- package/dist/agents/office/prompts.d.ts.map +1 -1
- package/dist/agents/office/prompts.js +451 -52
- package/dist/agents/office/prompts.js.map +1 -1
- package/dist/agents/office/word-agent.d.ts +1 -1
- package/dist/agents/office/word-agent.d.ts.map +1 -1
- package/dist/agents/office/word-agent.js +6 -6
- package/dist/agents/office/word-agent.js.map +1 -1
- package/dist/agents/office/word-create-agent.d.ts +3 -0
- package/dist/agents/office/word-create-agent.d.ts.map +1 -0
- package/dist/agents/office/word-create-agent.js +38 -0
- package/dist/agents/office/word-create-agent.js.map +1 -0
- package/dist/agents/office/word-create-prompts.d.ts +4 -0
- package/dist/agents/office/word-create-prompts.d.ts.map +1 -0
- package/dist/agents/office/word-create-prompts.js +164 -0
- package/dist/agents/office/word-create-prompts.js.map +1 -0
- package/dist/cli.js +3 -0
- package/dist/cli.js.map +1 -1
- package/dist/constants.d.ts +1 -1
- package/dist/constants.d.ts.map +1 -1
- package/dist/constants.js +1 -1
- package/dist/constants.js.map +1 -1
- package/dist/pipe/pipe-runner.d.ts.map +1 -1
- package/dist/pipe/pipe-runner.js +20 -0
- package/dist/pipe/pipe-runner.js.map +1 -1
- package/dist/prompts/agents/planning.d.ts.map +1 -1
- package/dist/prompts/agents/planning.js +43 -18
- package/dist/prompts/agents/planning.js.map +1 -1
- package/dist/prompts/shared/tool-usage.d.ts.map +1 -1
- package/dist/prompts/shared/tool-usage.js +6 -3
- package/dist/prompts/shared/tool-usage.js.map +1 -1
- package/dist/prompts/system/plan-execute.js +1 -1
- package/dist/tools/office/excel-client.js +4 -4
- package/dist/tools/office/excel-tools/index.d.ts +2 -0
- package/dist/tools/office/excel-tools/index.d.ts.map +1 -1
- package/dist/tools/office/excel-tools/index.js +12 -0
- package/dist/tools/office/excel-tools/index.js.map +1 -1
- package/dist/tools/office/excel-tools/sheet-builders.d.ts +8 -0
- package/dist/tools/office/excel-tools/sheet-builders.d.ts.map +1 -0
- package/dist/tools/office/excel-tools/sheet-builders.js +414 -0
- package/dist/tools/office/excel-tools/sheet-builders.js.map +1 -0
- package/dist/tools/office/excel-tools.d.ts +1 -1
- package/dist/tools/office/excel-tools.d.ts.map +1 -1
- package/dist/tools/office/excel-tools.js +1 -1
- package/dist/tools/office/excel-tools.js.map +1 -1
- package/dist/tools/office/powerpoint-client.d.ts +3 -0
- package/dist/tools/office/powerpoint-client.d.ts.map +1 -1
- package/dist/tools/office/powerpoint-client.js +136 -10
- package/dist/tools/office/powerpoint-client.js.map +1 -1
- package/dist/tools/office/powerpoint-tools/export.d.ts.map +1 -1
- package/dist/tools/office/powerpoint-tools/export.js +16 -1
- package/dist/tools/office/powerpoint-tools/export.js.map +1 -1
- package/dist/tools/office/powerpoint-tools/index.d.ts +2 -0
- package/dist/tools/office/powerpoint-tools/index.d.ts.map +1 -1
- package/dist/tools/office/powerpoint-tools/index.js +7 -0
- package/dist/tools/office/powerpoint-tools/index.js.map +1 -1
- package/dist/tools/office/powerpoint-tools/launch.d.ts.map +1 -1
- package/dist/tools/office/powerpoint-tools/launch.js +2 -0
- package/dist/tools/office/powerpoint-tools/launch.js.map +1 -1
- package/dist/tools/office/powerpoint-tools/layout-builders.d.ts +12 -0
- package/dist/tools/office/powerpoint-tools/layout-builders.d.ts.map +1 -0
- package/dist/tools/office/powerpoint-tools/layout-builders.js +785 -0
- package/dist/tools/office/powerpoint-tools/layout-builders.js.map +1 -0
- package/dist/tools/office/powerpoint-tools/slides.js +1 -1
- package/dist/tools/office/powerpoint-tools/slides.js.map +1 -1
- package/dist/tools/office/powerpoint-tools.d.ts +1 -1
- package/dist/tools/office/powerpoint-tools.d.ts.map +1 -1
- package/dist/tools/office/powerpoint-tools.js +1 -1
- package/dist/tools/office/powerpoint-tools.js.map +1 -1
- package/dist/tools/office/word-client.js +4 -4
- package/dist/tools/office/word-tools/index.d.ts +4 -1
- package/dist/tools/office/word-tools/index.d.ts.map +1 -1
- package/dist/tools/office/word-tools/index.js +15 -0
- package/dist/tools/office/word-tools/index.js.map +1 -1
- package/dist/tools/office/word-tools/section-builders.d.ts +10 -0
- package/dist/tools/office/word-tools/section-builders.d.ts.map +1 -0
- package/dist/tools/office/word-tools/section-builders.js +421 -0
- package/dist/tools/office/word-tools/section-builders.js.map +1 -0
- package/dist/tools/office/word-tools.d.ts +1 -1
- package/dist/tools/office/word-tools.d.ts.map +1 -1
- package/dist/tools/office/word-tools.js +1 -1
- package/dist/tools/office/word-tools.js.map +1 -1
- package/dist/tools/registry.d.ts.map +1 -1
- package/dist/tools/registry.js +7 -4
- package/dist/tools/registry.js.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,918 @@
|
|
|
1
|
+
import * as fs from 'fs';
|
|
2
|
+
import * as path from 'path';
|
|
3
|
+
import { powerpointClient } from '../../tools/office/powerpoint-client.js';
|
|
4
|
+
import { getSubAgentPhaseLogger, getSubAgentToolCallLogger } from '../common/sub-agent.js';
|
|
5
|
+
import { logger } from '../../utils/logger.js';
|
|
6
|
+
import { getPlatform } from '../../utils/platform-utils.js';
|
|
7
|
+
import { PPT_CREATE_ENHANCEMENT_PROMPT, PPT_STRUCTURED_PLANNING_PROMPT, buildSlideHtmlPrompt, } from './powerpoint-create-prompts.js';
|
|
8
|
+
const DEFAULT_DESIGN = {
|
|
9
|
+
primary_color: '#1B2A4A',
|
|
10
|
+
accent_color: '#00D4AA',
|
|
11
|
+
background_color: '#FFFFFF',
|
|
12
|
+
text_color: '#1A1A2E',
|
|
13
|
+
accent_light: '#E8F5F0',
|
|
14
|
+
gradient_end: '#2D5F8A',
|
|
15
|
+
font_title: 'Segoe UI',
|
|
16
|
+
font_body: 'Malgun Gothic',
|
|
17
|
+
mood: 'modern-minimal',
|
|
18
|
+
design_notes: 'Clean gradients, card-based layouts',
|
|
19
|
+
};
|
|
20
|
+
function extractContent(msg) {
|
|
21
|
+
const content = msg['content'];
|
|
22
|
+
if (content && content.trim())
|
|
23
|
+
return content;
|
|
24
|
+
const reasoning = msg['reasoning_content'];
|
|
25
|
+
if (reasoning && reasoning.trim())
|
|
26
|
+
return reasoning;
|
|
27
|
+
return '';
|
|
28
|
+
}
|
|
29
|
+
function validateAndFixPlan(plan) {
|
|
30
|
+
if (!plan.design)
|
|
31
|
+
return 'Missing design object';
|
|
32
|
+
if (!plan.design.primary_color || !plan.design.accent_color) {
|
|
33
|
+
return 'Missing design colors (primary_color, accent_color)';
|
|
34
|
+
}
|
|
35
|
+
if (!Array.isArray(plan.slides) || plan.slides.length < 3) {
|
|
36
|
+
return 'slides array must have at least 3 entries';
|
|
37
|
+
}
|
|
38
|
+
if (plan.slides[0]?.type !== 'title') {
|
|
39
|
+
logger.info('Auto-fixing: first slide type changed to "title"');
|
|
40
|
+
plan.slides[0].type = 'title';
|
|
41
|
+
}
|
|
42
|
+
const lastSlide = plan.slides[plan.slides.length - 1];
|
|
43
|
+
if (lastSlide.type !== 'closing') {
|
|
44
|
+
logger.info('Auto-fixing: last slide type changed to "closing"');
|
|
45
|
+
lastSlide.type = 'closing';
|
|
46
|
+
}
|
|
47
|
+
for (let i = 0; i < plan.slides.length; i++) {
|
|
48
|
+
if (!plan.slides[i].title) {
|
|
49
|
+
plan.slides[i].title = `Slide ${i + 1}`;
|
|
50
|
+
logger.info(`Auto-fixing: slide ${i + 1} missing title, set placeholder`);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
function repairLlmJson(raw) {
|
|
56
|
+
let result = '';
|
|
57
|
+
let inString = false;
|
|
58
|
+
let i = 0;
|
|
59
|
+
while (i < raw.length) {
|
|
60
|
+
const ch = raw[i];
|
|
61
|
+
if (!inString) {
|
|
62
|
+
if (ch === ',') {
|
|
63
|
+
let j = i + 1;
|
|
64
|
+
while (j < raw.length && /\s/.test(raw[j]))
|
|
65
|
+
j++;
|
|
66
|
+
if (j < raw.length && (raw[j] === '}' || raw[j] === ']')) {
|
|
67
|
+
i++;
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
result += ch;
|
|
72
|
+
if (ch === '"')
|
|
73
|
+
inString = true;
|
|
74
|
+
i++;
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
if (ch === '\\') {
|
|
78
|
+
result += ch;
|
|
79
|
+
if (i + 1 < raw.length) {
|
|
80
|
+
result += raw[i + 1];
|
|
81
|
+
i += 2;
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
i++;
|
|
85
|
+
}
|
|
86
|
+
continue;
|
|
87
|
+
}
|
|
88
|
+
if (ch === '"') {
|
|
89
|
+
let j = i + 1;
|
|
90
|
+
while (j < raw.length && /[ \t\r\n]/.test(raw[j]))
|
|
91
|
+
j++;
|
|
92
|
+
const next = j < raw.length ? raw[j] : '';
|
|
93
|
+
if (next === '' || /[,:}\]]/.test(next)) {
|
|
94
|
+
result += '"';
|
|
95
|
+
inString = false;
|
|
96
|
+
}
|
|
97
|
+
else {
|
|
98
|
+
result += '\\"';
|
|
99
|
+
}
|
|
100
|
+
i++;
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
if (ch === '\n') {
|
|
104
|
+
result += '\\n';
|
|
105
|
+
i++;
|
|
106
|
+
continue;
|
|
107
|
+
}
|
|
108
|
+
if (ch === '\r') {
|
|
109
|
+
result += '\\n';
|
|
110
|
+
i += (i + 1 < raw.length && raw[i + 1] === '\n') ? 2 : 1;
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
if (ch === '\t') {
|
|
114
|
+
result += '\\t';
|
|
115
|
+
i++;
|
|
116
|
+
continue;
|
|
117
|
+
}
|
|
118
|
+
if (ch.charCodeAt(0) < 0x20) {
|
|
119
|
+
i++;
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
result += ch;
|
|
123
|
+
i++;
|
|
124
|
+
}
|
|
125
|
+
return result;
|
|
126
|
+
}
|
|
127
|
+
function parseJsonPlan(raw) {
|
|
128
|
+
let cleaned = raw.trim();
|
|
129
|
+
if (cleaned.startsWith('```')) {
|
|
130
|
+
cleaned = cleaned.replace(/^```(?:json|JSON)?\s*\n?/, '').replace(/\n?```\s*$/, '');
|
|
131
|
+
}
|
|
132
|
+
const firstBrace = cleaned.indexOf('{');
|
|
133
|
+
if (firstBrace > 0) {
|
|
134
|
+
cleaned = cleaned.slice(firstBrace);
|
|
135
|
+
}
|
|
136
|
+
const lastBrace = cleaned.lastIndexOf('}');
|
|
137
|
+
if (lastBrace >= 0 && lastBrace < cleaned.length - 1) {
|
|
138
|
+
cleaned = cleaned.slice(0, lastBrace + 1);
|
|
139
|
+
}
|
|
140
|
+
try {
|
|
141
|
+
return JSON.parse(cleaned);
|
|
142
|
+
}
|
|
143
|
+
catch (e) {
|
|
144
|
+
logger.debug('parseJsonPlan: direct parse failed', { error: String(e), length: cleaned.length });
|
|
145
|
+
}
|
|
146
|
+
const match = cleaned.match(/\{[\s\S]*\}/);
|
|
147
|
+
if (!match)
|
|
148
|
+
return null;
|
|
149
|
+
try {
|
|
150
|
+
return JSON.parse(match[0]);
|
|
151
|
+
}
|
|
152
|
+
catch { }
|
|
153
|
+
const repaired = repairLlmJson(match[0]);
|
|
154
|
+
try {
|
|
155
|
+
return JSON.parse(repaired);
|
|
156
|
+
}
|
|
157
|
+
catch (e) {
|
|
158
|
+
logger.debug('parseJsonPlan: repaired parse failed', { error: String(e) });
|
|
159
|
+
}
|
|
160
|
+
try {
|
|
161
|
+
let final = repaired;
|
|
162
|
+
let braces = 0, brackets = 0;
|
|
163
|
+
let inStr = false, esc = false;
|
|
164
|
+
for (const ch of final) {
|
|
165
|
+
if (esc) {
|
|
166
|
+
esc = false;
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
if (ch === '\\') {
|
|
170
|
+
esc = true;
|
|
171
|
+
continue;
|
|
172
|
+
}
|
|
173
|
+
if (ch === '"') {
|
|
174
|
+
inStr = !inStr;
|
|
175
|
+
continue;
|
|
176
|
+
}
|
|
177
|
+
if (inStr)
|
|
178
|
+
continue;
|
|
179
|
+
if (ch === '{')
|
|
180
|
+
braces++;
|
|
181
|
+
else if (ch === '}')
|
|
182
|
+
braces--;
|
|
183
|
+
else if (ch === '[')
|
|
184
|
+
brackets++;
|
|
185
|
+
else if (ch === ']')
|
|
186
|
+
brackets--;
|
|
187
|
+
}
|
|
188
|
+
if (inStr)
|
|
189
|
+
final += '"';
|
|
190
|
+
for (let i = 0; i < brackets; i++)
|
|
191
|
+
final += ']';
|
|
192
|
+
for (let i = 0; i < braces; i++)
|
|
193
|
+
final += '}';
|
|
194
|
+
return JSON.parse(final);
|
|
195
|
+
}
|
|
196
|
+
catch {
|
|
197
|
+
return null;
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
function extractHtml(raw) {
|
|
201
|
+
const trimmed = raw.trim();
|
|
202
|
+
if (trimmed.startsWith('<!DOCTYPE') || trimmed.startsWith('<html')) {
|
|
203
|
+
return trimmed;
|
|
204
|
+
}
|
|
205
|
+
const fenceMatch = trimmed.match(/```(?:html)?\s*\n([\s\S]*?)\n```/);
|
|
206
|
+
if (fenceMatch?.[1]) {
|
|
207
|
+
return fenceMatch[1].trim();
|
|
208
|
+
}
|
|
209
|
+
const docMatch = trimmed.match(/(<!DOCTYPE[\s\S]*<\/html>)/i);
|
|
210
|
+
if (docMatch?.[1]) {
|
|
211
|
+
return docMatch[1].trim();
|
|
212
|
+
}
|
|
213
|
+
return null;
|
|
214
|
+
}
|
|
215
|
+
function injectViewportCss(html, backgroundColor) {
|
|
216
|
+
let result = html.replace(/<meta\s+name=["']viewport["'][^>]*>/gi, '');
|
|
217
|
+
const bgColor = backgroundColor || '#000000';
|
|
218
|
+
const viewportMeta = `<meta name="viewport" content="width=2040">`;
|
|
219
|
+
const overrideCss = `<style>*{box-sizing:border-box;word-break:keep-all;overflow-wrap:break-word}html{width:2040px!important;height:1200px!important;overflow:hidden!important;margin:0!important;background-color:${bgColor}!important}body{width:1920px!important;height:1080px!important;min-width:1920px!important;min-height:1080px!important;overflow:hidden!important;margin:0!important;display:flex!important;flex-direction:column!important}body>div,body>main,body>section,body>article,body>header,body>footer{max-width:none!important}body>*:nth-child(2){flex:1!important;align-items:stretch!important;align-content:stretch!important;grid-auto-rows:1fr!important}body>*:nth-child(2)>div,body>*:nth-child(2)>section,body>*:nth-child(2)>article{flex:1!important}</style>`;
|
|
220
|
+
const injection = viewportMeta + overrideCss;
|
|
221
|
+
if (result.includes('</head>')) {
|
|
222
|
+
result = result.replace('</head>', `${injection}</head>`);
|
|
223
|
+
}
|
|
224
|
+
else if (result.includes('<head>')) {
|
|
225
|
+
result = result.replace('<head>', `<head>${injection}`);
|
|
226
|
+
}
|
|
227
|
+
else if (result.includes('<html')) {
|
|
228
|
+
result = result.replace(/<html[^>]*>/, (match) => `${match}<head>${injection}</head>`);
|
|
229
|
+
}
|
|
230
|
+
else {
|
|
231
|
+
result = injection + result;
|
|
232
|
+
}
|
|
233
|
+
return result;
|
|
234
|
+
}
|
|
235
|
+
function enforceMinFontSize(html) {
|
|
236
|
+
return html.replace(/font-size:\s*(\d+(?:\.\d+)?)px/g, (_match, size) => {
|
|
237
|
+
const px = parseFloat(size);
|
|
238
|
+
return (px > 12 && px < 20) ? 'font-size:20px' : _match;
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
function injectMeasureCss(html) {
|
|
242
|
+
let result = html.replace(/<meta\s+name=["']viewport["'][^>]*>/gi, '');
|
|
243
|
+
const viewportMeta = `<meta name="viewport" content="width=2040">`;
|
|
244
|
+
const measureCss = `<style>*{box-sizing:border-box;word-break:keep-all;overflow-wrap:break-word}html{width:2040px!important;margin:0!important}body{width:1920px!important;min-width:1920px!important;min-height:1080px!important;margin:0!important;display:flex!important;flex-direction:column!important}body>div,body>main,body>section,body>article,body>header,body>footer{max-width:none!important}</style>`;
|
|
245
|
+
const injection = viewportMeta + measureCss;
|
|
246
|
+
if (result.includes('</head>')) {
|
|
247
|
+
result = result.replace('</head>', `${injection}</head>`);
|
|
248
|
+
}
|
|
249
|
+
else if (result.includes('<head>')) {
|
|
250
|
+
result = result.replace('<head>', `<head>${injection}`);
|
|
251
|
+
}
|
|
252
|
+
else if (result.includes('<html')) {
|
|
253
|
+
result = result.replace(/<html[^>]*>/, (match) => `${match}<head>${injection}</head>`);
|
|
254
|
+
}
|
|
255
|
+
else {
|
|
256
|
+
result = injection + result;
|
|
257
|
+
}
|
|
258
|
+
const measureScript = `<script>document.title='SH:'+document.documentElement.scrollHeight</script>`;
|
|
259
|
+
if (result.includes('</body>')) {
|
|
260
|
+
result = result.replace('</body>', `${measureScript}</body>`);
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
result += measureScript;
|
|
264
|
+
}
|
|
265
|
+
return result;
|
|
266
|
+
}
|
|
267
|
+
function escapeHtml(text) {
|
|
268
|
+
return text
|
|
269
|
+
.replace(/&/g, '&')
|
|
270
|
+
.replace(/</g, '<')
|
|
271
|
+
.replace(/>/g, '>')
|
|
272
|
+
.replace(/"/g, '"');
|
|
273
|
+
}
|
|
274
|
+
function buildTitleSlideHtml(design, mainTitle, subtitle, date, slideNum) {
|
|
275
|
+
return `<!DOCTYPE html>
|
|
276
|
+
<html lang="ko">
|
|
277
|
+
<head>
|
|
278
|
+
<meta charset="UTF-8">
|
|
279
|
+
<style>
|
|
280
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
281
|
+
html { background-color: ${design.primary_color}; }
|
|
282
|
+
html, body { width: 1920px; height: 1080px; overflow: hidden; }
|
|
283
|
+
body {
|
|
284
|
+
background: linear-gradient(135deg, ${design.primary_color} 0%, ${design.gradient_end} 60%, ${design.primary_color} 100%);
|
|
285
|
+
display: flex;
|
|
286
|
+
align-items: center;
|
|
287
|
+
justify-content: center;
|
|
288
|
+
position: relative;
|
|
289
|
+
font-family: "${design.font_title}", "Segoe UI", sans-serif;
|
|
290
|
+
}
|
|
291
|
+
.decor {
|
|
292
|
+
position: absolute;
|
|
293
|
+
border-radius: 50%;
|
|
294
|
+
background: rgba(255,255,255,0.03);
|
|
295
|
+
pointer-events: none;
|
|
296
|
+
}
|
|
297
|
+
.d1 { width: 700px; height: 700px; top: -250px; right: -150px; }
|
|
298
|
+
.d2 { width: 500px; height: 500px; bottom: -180px; left: -120px; }
|
|
299
|
+
.d3 { width: 250px; height: 250px; top: 40%; left: 8%; background: rgba(255,255,255,0.02); }
|
|
300
|
+
.d4 { width: 180px; height: 180px; bottom: 15%; right: 12%; background: rgba(255,255,255,0.02); }
|
|
301
|
+
.top-accent {
|
|
302
|
+
position: absolute;
|
|
303
|
+
top: 0; left: 0; width: 100%; height: 6px;
|
|
304
|
+
background: linear-gradient(90deg, transparent, ${design.accent_color}, transparent);
|
|
305
|
+
}
|
|
306
|
+
.content {
|
|
307
|
+
text-align: center;
|
|
308
|
+
z-index: 1;
|
|
309
|
+
max-width: 1400px;
|
|
310
|
+
padding: 0 60px;
|
|
311
|
+
}
|
|
312
|
+
.main-title {
|
|
313
|
+
font-size: 96px;
|
|
314
|
+
font-weight: 800;
|
|
315
|
+
color: #ffffff;
|
|
316
|
+
letter-spacing: -2px;
|
|
317
|
+
text-shadow: 0 6px 40px rgba(0,0,0,0.25);
|
|
318
|
+
line-height: 1.1;
|
|
319
|
+
margin-bottom: 32px;
|
|
320
|
+
}
|
|
321
|
+
.accent-bar {
|
|
322
|
+
width: 120px; height: 5px;
|
|
323
|
+
background: ${design.accent_color};
|
|
324
|
+
margin: 0 auto 32px;
|
|
325
|
+
border-radius: 3px;
|
|
326
|
+
box-shadow: 0 0 20px ${design.accent_color}40;
|
|
327
|
+
}
|
|
328
|
+
.subtitle {
|
|
329
|
+
font-size: 32px;
|
|
330
|
+
font-weight: 400;
|
|
331
|
+
color: rgba(255,255,255,0.88);
|
|
332
|
+
font-family: "${design.font_body}", "Malgun Gothic", sans-serif;
|
|
333
|
+
line-height: 1.5;
|
|
334
|
+
margin-bottom: 16px;
|
|
335
|
+
}
|
|
336
|
+
.date-text {
|
|
337
|
+
font-size: 22px;
|
|
338
|
+
font-weight: 300;
|
|
339
|
+
color: rgba(255,255,255,0.55);
|
|
340
|
+
font-family: "${design.font_body}", "Malgun Gothic", sans-serif;
|
|
341
|
+
}
|
|
342
|
+
.page-num {
|
|
343
|
+
position: absolute;
|
|
344
|
+
bottom: 24px; right: 44px;
|
|
345
|
+
font-size: 13px;
|
|
346
|
+
color: rgba(255,255,255,0.35);
|
|
347
|
+
}
|
|
348
|
+
</style>
|
|
349
|
+
</head>
|
|
350
|
+
<body>
|
|
351
|
+
<div class="top-accent"></div>
|
|
352
|
+
<div class="decor d1"></div>
|
|
353
|
+
<div class="decor d2"></div>
|
|
354
|
+
<div class="decor d3"></div>
|
|
355
|
+
<div class="decor d4"></div>
|
|
356
|
+
<div class="content">
|
|
357
|
+
<div class="main-title">${escapeHtml(mainTitle)}</div>
|
|
358
|
+
<div class="accent-bar"></div>
|
|
359
|
+
${subtitle ? `<div class="subtitle">${escapeHtml(subtitle)}</div>` : ''}
|
|
360
|
+
<div class="date-text">${escapeHtml(date)}</div>
|
|
361
|
+
</div>
|
|
362
|
+
<div class="page-num">${slideNum}</div>
|
|
363
|
+
</body>
|
|
364
|
+
</html>`;
|
|
365
|
+
}
|
|
366
|
+
function buildClosingSlideHtml(design, companyName, slideNum, language) {
|
|
367
|
+
const thankYou = language === 'ko' ? '감사합니다' : 'Thank You';
|
|
368
|
+
return `<!DOCTYPE html>
|
|
369
|
+
<html lang="${language}">
|
|
370
|
+
<head>
|
|
371
|
+
<meta charset="UTF-8">
|
|
372
|
+
<style>
|
|
373
|
+
* { margin: 0; padding: 0; box-sizing: border-box; }
|
|
374
|
+
html { background-color: ${design.primary_color}; }
|
|
375
|
+
html, body { width: 1920px; height: 1080px; overflow: hidden; }
|
|
376
|
+
body {
|
|
377
|
+
background: linear-gradient(135deg, ${design.primary_color} 0%, ${design.gradient_end} 60%, ${design.primary_color} 100%);
|
|
378
|
+
display: flex;
|
|
379
|
+
align-items: center;
|
|
380
|
+
justify-content: center;
|
|
381
|
+
position: relative;
|
|
382
|
+
font-family: "${design.font_title}", "Segoe UI", sans-serif;
|
|
383
|
+
}
|
|
384
|
+
.decor {
|
|
385
|
+
position: absolute;
|
|
386
|
+
border-radius: 50%;
|
|
387
|
+
background: rgba(255,255,255,0.03);
|
|
388
|
+
pointer-events: none;
|
|
389
|
+
}
|
|
390
|
+
.d1 { width: 600px; height: 600px; top: -200px; left: -150px; }
|
|
391
|
+
.d2 { width: 400px; height: 400px; bottom: -120px; right: -80px; }
|
|
392
|
+
.bottom-accent {
|
|
393
|
+
position: absolute;
|
|
394
|
+
bottom: 0; left: 0; width: 100%; height: 6px;
|
|
395
|
+
background: linear-gradient(90deg, transparent, ${design.accent_color}, transparent);
|
|
396
|
+
}
|
|
397
|
+
.content {
|
|
398
|
+
text-align: center;
|
|
399
|
+
z-index: 1;
|
|
400
|
+
}
|
|
401
|
+
.thank-you {
|
|
402
|
+
font-size: 96px;
|
|
403
|
+
font-weight: 800;
|
|
404
|
+
color: #ffffff;
|
|
405
|
+
letter-spacing: -1px;
|
|
406
|
+
text-shadow: 0 6px 40px rgba(0,0,0,0.25);
|
|
407
|
+
margin-bottom: 32px;
|
|
408
|
+
}
|
|
409
|
+
.accent-bar {
|
|
410
|
+
width: 100px; height: 5px;
|
|
411
|
+
background: ${design.accent_color};
|
|
412
|
+
margin: 0 auto 32px;
|
|
413
|
+
border-radius: 3px;
|
|
414
|
+
box-shadow: 0 0 20px ${design.accent_color}40;
|
|
415
|
+
}
|
|
416
|
+
.company {
|
|
417
|
+
font-size: 36px;
|
|
418
|
+
font-weight: 500;
|
|
419
|
+
color: rgba(255,255,255,0.80);
|
|
420
|
+
font-family: "${design.font_body}", "Malgun Gothic", sans-serif;
|
|
421
|
+
}
|
|
422
|
+
.page-num {
|
|
423
|
+
position: absolute;
|
|
424
|
+
bottom: 24px; right: 44px;
|
|
425
|
+
font-size: 13px;
|
|
426
|
+
color: rgba(255,255,255,0.35);
|
|
427
|
+
}
|
|
428
|
+
</style>
|
|
429
|
+
</head>
|
|
430
|
+
<body>
|
|
431
|
+
<div class="decor d1"></div>
|
|
432
|
+
<div class="decor d2"></div>
|
|
433
|
+
<div class="bottom-accent"></div>
|
|
434
|
+
<div class="content">
|
|
435
|
+
<div class="thank-you">${escapeHtml(thankYou)}</div>
|
|
436
|
+
<div class="accent-bar"></div>
|
|
437
|
+
<div class="company">${escapeHtml(companyName)}</div>
|
|
438
|
+
</div>
|
|
439
|
+
<div class="page-num">${slideNum}</div>
|
|
440
|
+
</body>
|
|
441
|
+
</html>`;
|
|
442
|
+
}
|
|
443
|
+
function getTempDir() {
|
|
444
|
+
const platform = getPlatform();
|
|
445
|
+
if (platform === 'wsl') {
|
|
446
|
+
return { writePath: '/mnt/c/temp', winPath: 'C:\\temp' };
|
|
447
|
+
}
|
|
448
|
+
return { writePath: 'C:\\temp', winPath: 'C:\\temp' };
|
|
449
|
+
}
|
|
450
|
+
function ensureTempDir(writePath) {
|
|
451
|
+
if (!fs.existsSync(writePath)) {
|
|
452
|
+
fs.mkdirSync(writePath, { recursive: true });
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
function normalizeDesign(raw) {
|
|
456
|
+
return {
|
|
457
|
+
primary_color: raw['primary_color'] || DEFAULT_DESIGN.primary_color,
|
|
458
|
+
accent_color: raw['accent_color'] || DEFAULT_DESIGN.accent_color,
|
|
459
|
+
background_color: raw['background_color'] || DEFAULT_DESIGN.background_color,
|
|
460
|
+
text_color: raw['text_color'] || DEFAULT_DESIGN.text_color,
|
|
461
|
+
accent_light: raw['accent_light'] || DEFAULT_DESIGN.accent_light,
|
|
462
|
+
gradient_end: raw['gradient_end'] || DEFAULT_DESIGN.gradient_end,
|
|
463
|
+
font_title: raw['font_title'] || DEFAULT_DESIGN.font_title,
|
|
464
|
+
font_body: raw['font_body'] || DEFAULT_DESIGN.font_body,
|
|
465
|
+
mood: raw['mood'] || DEFAULT_DESIGN.mood,
|
|
466
|
+
design_notes: raw['design_notes'] || DEFAULT_DESIGN.design_notes,
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
async function runStructured(llmClient, instruction, explicitSavePath) {
|
|
470
|
+
const startTime = Date.now();
|
|
471
|
+
const phaseLogger = getSubAgentPhaseLogger();
|
|
472
|
+
const toolCallLogger = getSubAgentToolCallLogger();
|
|
473
|
+
let totalToolCalls = 0;
|
|
474
|
+
const timestamp = Date.now();
|
|
475
|
+
logger.enter('PPT-Create.runStructured');
|
|
476
|
+
const hasKorean = /[\uac00-\ud7af\u1100-\u11ff]/.test(instruction);
|
|
477
|
+
const language = hasKorean ? 'ko' : 'en';
|
|
478
|
+
if (phaseLogger)
|
|
479
|
+
phaseLogger('powerpoint-create', 'enhancement', 'Generating creative guidance...');
|
|
480
|
+
let guidance = '';
|
|
481
|
+
try {
|
|
482
|
+
const enhRes = await llmClient.chatCompletion({
|
|
483
|
+
messages: [
|
|
484
|
+
{ role: 'system', content: PPT_CREATE_ENHANCEMENT_PROMPT },
|
|
485
|
+
{ role: 'user', content: instruction },
|
|
486
|
+
],
|
|
487
|
+
temperature: 0.7,
|
|
488
|
+
max_tokens: 2000,
|
|
489
|
+
});
|
|
490
|
+
const enhMsg = enhRes.choices[0]?.message;
|
|
491
|
+
guidance = enhMsg ? extractContent(enhMsg) : '';
|
|
492
|
+
if (guidance.length < 500) {
|
|
493
|
+
logger.warn('PPT enhancement too short, retrying', { length: guidance.length });
|
|
494
|
+
const retryEnhRes = await llmClient.chatCompletion({
|
|
495
|
+
messages: [
|
|
496
|
+
{ role: 'system', content: PPT_CREATE_ENHANCEMENT_PROMPT },
|
|
497
|
+
{ role: 'user', content: `${instruction}\n\nIMPORTANT: Produce a COMPLETE, DETAILED design system and content plan. Include ALL 7 sections: DOCUMENT_TYPE, AUDIENCE, MOOD, COLOR PALETTE (6 hex values), FONTS, SLIDE PLAN (10-15 slides), DESIGN NOTES. Do NOT stop early.` },
|
|
498
|
+
],
|
|
499
|
+
temperature: 0.7,
|
|
500
|
+
max_tokens: 2000,
|
|
501
|
+
});
|
|
502
|
+
const retryMsg = retryEnhRes.choices[0]?.message;
|
|
503
|
+
const retryGuidance = retryMsg ? extractContent(retryMsg) : '';
|
|
504
|
+
if (retryGuidance.length > guidance.length) {
|
|
505
|
+
guidance = retryGuidance;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
if (phaseLogger)
|
|
509
|
+
phaseLogger('powerpoint-create', 'enhancement', `Done (${guidance.length} chars)`);
|
|
510
|
+
}
|
|
511
|
+
catch (e) {
|
|
512
|
+
logger.warn('PPT enhancement failed, proceeding without', { error: String(e) });
|
|
513
|
+
}
|
|
514
|
+
const enhancedInstruction = guidance
|
|
515
|
+
? `${instruction}\n\n═══ CREATIVE GUIDANCE ═══\n${guidance}\n═══ END GUIDANCE ═══`
|
|
516
|
+
: instruction;
|
|
517
|
+
if (phaseLogger)
|
|
518
|
+
phaseLogger('powerpoint-create', 'planning', 'Generating JSON plan...');
|
|
519
|
+
let plan = null;
|
|
520
|
+
try {
|
|
521
|
+
const planRes = await llmClient.chatCompletion({
|
|
522
|
+
messages: [
|
|
523
|
+
{ role: 'system', content: PPT_STRUCTURED_PLANNING_PROMPT },
|
|
524
|
+
{ role: 'user', content: enhancedInstruction },
|
|
525
|
+
],
|
|
526
|
+
temperature: 0.4,
|
|
527
|
+
max_tokens: 8000,
|
|
528
|
+
});
|
|
529
|
+
const planMsg = planRes.choices[0]?.message;
|
|
530
|
+
const finishReason = planRes.choices[0]?.finish_reason;
|
|
531
|
+
const rawPlan = planMsg ? extractContent(planMsg) : '';
|
|
532
|
+
if (finishReason === 'length') {
|
|
533
|
+
logger.warn('PPT planning response was truncated (finish_reason=length)');
|
|
534
|
+
}
|
|
535
|
+
logger.debug('PPT planning raw response', { length: rawPlan.length, finishReason, first200: rawPlan.slice(0, 200) });
|
|
536
|
+
plan = rawPlan ? parseJsonPlan(rawPlan) : null;
|
|
537
|
+
if (plan) {
|
|
538
|
+
plan.design = normalizeDesign(plan.design);
|
|
539
|
+
const validationError = validateAndFixPlan(plan);
|
|
540
|
+
if (validationError) {
|
|
541
|
+
logger.warn('PPT plan validation failed', { error: validationError });
|
|
542
|
+
if (phaseLogger)
|
|
543
|
+
phaseLogger('powerpoint-create', 'planning', `Validation failed: ${validationError}. Retrying...`);
|
|
544
|
+
const retryRes = await llmClient.chatCompletion({
|
|
545
|
+
messages: [
|
|
546
|
+
{ role: 'system', content: PPT_STRUCTURED_PLANNING_PROMPT },
|
|
547
|
+
{ role: 'user', content: enhancedInstruction },
|
|
548
|
+
],
|
|
549
|
+
temperature: 0.2,
|
|
550
|
+
max_tokens: 8000,
|
|
551
|
+
});
|
|
552
|
+
const retryMsg = retryRes.choices[0]?.message;
|
|
553
|
+
const retryRaw = retryMsg ? extractContent(retryMsg) : '';
|
|
554
|
+
const retryPlan = retryRaw ? parseJsonPlan(retryRaw) : null;
|
|
555
|
+
if (retryPlan) {
|
|
556
|
+
retryPlan.design = normalizeDesign(retryPlan.design);
|
|
557
|
+
const retryError = validateAndFixPlan(retryPlan);
|
|
558
|
+
if (!retryError) {
|
|
559
|
+
plan = retryPlan;
|
|
560
|
+
if (phaseLogger)
|
|
561
|
+
phaseLogger('powerpoint-create', 'planning', `Retry succeeded (${plan.slides.length} slides)`);
|
|
562
|
+
}
|
|
563
|
+
else {
|
|
564
|
+
plan = null;
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
else {
|
|
568
|
+
plan = null;
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
else {
|
|
572
|
+
if (phaseLogger)
|
|
573
|
+
phaseLogger('powerpoint-create', 'planning', `Done (${plan.slides.length} slides)`);
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
else {
|
|
577
|
+
logger.warn('PPT JSON plan parsing failed');
|
|
578
|
+
if (phaseLogger)
|
|
579
|
+
phaseLogger('powerpoint-create', 'planning', 'JSON parsing failed. Falling back.');
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
catch (e) {
|
|
583
|
+
logger.warn('PPT planning failed', { error: String(e) });
|
|
584
|
+
if (phaseLogger)
|
|
585
|
+
phaseLogger('powerpoint-create', 'planning', 'Planning error. Falling back.');
|
|
586
|
+
}
|
|
587
|
+
if (!plan) {
|
|
588
|
+
logger.error('PPT planning failed after retries — cannot create presentation');
|
|
589
|
+
return {
|
|
590
|
+
success: false,
|
|
591
|
+
error: 'Failed to generate presentation plan. Please try again.',
|
|
592
|
+
};
|
|
593
|
+
}
|
|
594
|
+
if (plan.slides.length > 15) {
|
|
595
|
+
logger.warn(`PPT plan has ${plan.slides.length} slides, capping to 15`);
|
|
596
|
+
const firstSlide = plan.slides[0];
|
|
597
|
+
const lastSlide = plan.slides[plan.slides.length - 1];
|
|
598
|
+
const contentSlides = plan.slides.slice(1, -1).slice(0, 13);
|
|
599
|
+
plan.slides = [firstSlide, ...contentSlides, lastSlide];
|
|
600
|
+
if (phaseLogger)
|
|
601
|
+
phaseLogger('powerpoint-create', 'planning', `Capped to ${plan.slides.length} slides`);
|
|
602
|
+
}
|
|
603
|
+
if (phaseLogger)
|
|
604
|
+
phaseLogger('powerpoint-create', 'execution', 'Starting HTML rendering pipeline...');
|
|
605
|
+
const { writePath: tempWritePath, winPath: tempWinPath } = getTempDir();
|
|
606
|
+
ensureTempDir(tempWritePath);
|
|
607
|
+
let savePath = explicitSavePath;
|
|
608
|
+
if (!savePath) {
|
|
609
|
+
const fullPathMatch = instruction.match(/([A-Za-z]:\\[^\s,]+\.pptx|\/[^\s,]+\.pptx)/i);
|
|
610
|
+
if (fullPathMatch) {
|
|
611
|
+
savePath = fullPathMatch[1];
|
|
612
|
+
}
|
|
613
|
+
else {
|
|
614
|
+
const nameMatch = instruction.match(/([\w][\w\-_.]*\.pptx)/i);
|
|
615
|
+
if (nameMatch) {
|
|
616
|
+
savePath = `C:\\temp\\${nameMatch[1]}`;
|
|
617
|
+
}
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
const kstNow = new Date(Date.now() + 9 * 60 * 60 * 1000);
|
|
621
|
+
const kstDate = `${kstNow.getUTCFullYear()}년 ${kstNow.getUTCMonth() + 1}월`;
|
|
622
|
+
const titleSlidePlan = plan.slides.find(s => s.type === 'title');
|
|
623
|
+
const rawTitleText = titleSlidePlan?.title || '';
|
|
624
|
+
const titleSeps = [' - ', ' – ', ' — ', ': ', ' | '];
|
|
625
|
+
let companyName = rawTitleText;
|
|
626
|
+
let titleSubtitle = '';
|
|
627
|
+
for (const sep of titleSeps) {
|
|
628
|
+
const idx = rawTitleText.indexOf(sep);
|
|
629
|
+
if (idx > 0) {
|
|
630
|
+
companyName = rawTitleText.slice(0, idx).trim();
|
|
631
|
+
titleSubtitle = rawTitleText.slice(idx + sep.length).trim();
|
|
632
|
+
break;
|
|
633
|
+
}
|
|
634
|
+
}
|
|
635
|
+
if (!titleSubtitle && titleSlidePlan) {
|
|
636
|
+
titleSubtitle = ((titleSlidePlan.content_direction || '').split('\n')[0] || '').trim().slice(0, 120);
|
|
637
|
+
}
|
|
638
|
+
if (/로고|슬로건|연락처|contact|logo|placeholder/i.test(titleSubtitle)) {
|
|
639
|
+
titleSubtitle = '';
|
|
640
|
+
}
|
|
641
|
+
const createResult = await powerpointClient.powerpointCreate();
|
|
642
|
+
totalToolCalls++;
|
|
643
|
+
if (toolCallLogger)
|
|
644
|
+
toolCallLogger('powerpoint-create', 'powerpoint_create', {}, createResult.success ? 'Created' : createResult['error'] || '', createResult.success, 0, totalToolCalls);
|
|
645
|
+
if (!createResult.success) {
|
|
646
|
+
return { success: false, error: `Failed to create presentation: ${createResult['error']}` };
|
|
647
|
+
}
|
|
648
|
+
const builtSlides = [];
|
|
649
|
+
let failCount = 0;
|
|
650
|
+
const tempFiles = [];
|
|
651
|
+
for (let i = 0; i < plan.slides.length; i++) {
|
|
652
|
+
const slidePlan = plan.slides[i];
|
|
653
|
+
const slideNum = i + 1;
|
|
654
|
+
if (failCount >= 3) {
|
|
655
|
+
logger.warn('Too many slide failures, stopping');
|
|
656
|
+
break;
|
|
657
|
+
}
|
|
658
|
+
if (phaseLogger)
|
|
659
|
+
phaseLogger('powerpoint-create', 'execution', `Rendering slide ${slideNum}/${plan.slides.length}: ${slidePlan.title}`);
|
|
660
|
+
let html = null;
|
|
661
|
+
let htmlPrompt = null;
|
|
662
|
+
if (slidePlan.type === 'title') {
|
|
663
|
+
html = buildTitleSlideHtml(plan.design, companyName, titleSubtitle, kstDate, slideNum);
|
|
664
|
+
}
|
|
665
|
+
else if (slidePlan.type === 'closing') {
|
|
666
|
+
html = buildClosingSlideHtml(plan.design, companyName, slideNum, language);
|
|
667
|
+
}
|
|
668
|
+
else {
|
|
669
|
+
htmlPrompt = buildSlideHtmlPrompt(slidePlan.title, slidePlan.content_direction || '', plan.design, i, plan.slides.length, language);
|
|
670
|
+
try {
|
|
671
|
+
const htmlRes = await llmClient.chatCompletion({
|
|
672
|
+
messages: [
|
|
673
|
+
{ role: 'system', content: htmlPrompt },
|
|
674
|
+
{ role: 'user', content: 'Generate the HTML slide now.' },
|
|
675
|
+
],
|
|
676
|
+
temperature: 0.3,
|
|
677
|
+
max_tokens: 8000,
|
|
678
|
+
});
|
|
679
|
+
const htmlMsg = htmlRes.choices[0]?.message;
|
|
680
|
+
const rawHtml = htmlMsg ? extractContent(htmlMsg) : '';
|
|
681
|
+
html = extractHtml(rawHtml);
|
|
682
|
+
if (!html && rawHtml.length > 100) {
|
|
683
|
+
logger.warn(`Slide ${slideNum}: HTML extraction failed, retrying`);
|
|
684
|
+
const retryRes = await llmClient.chatCompletion({
|
|
685
|
+
messages: [
|
|
686
|
+
{ role: 'system', content: htmlPrompt },
|
|
687
|
+
{ role: 'user', content: 'Generate the complete HTML document. Start with <!DOCTYPE html> and end with </html>. No markdown fences.' },
|
|
688
|
+
],
|
|
689
|
+
temperature: 0.2,
|
|
690
|
+
max_tokens: 4000,
|
|
691
|
+
});
|
|
692
|
+
const retryMsg = retryRes.choices[0]?.message;
|
|
693
|
+
const retryRaw = retryMsg ? extractContent(retryMsg) : '';
|
|
694
|
+
html = extractHtml(retryRaw);
|
|
695
|
+
}
|
|
696
|
+
}
|
|
697
|
+
catch (e) {
|
|
698
|
+
logger.warn(`Slide ${slideNum}: LLM call failed: ${e}`);
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
if (!html) {
|
|
702
|
+
logger.warn(`Slide ${slideNum}: Failed to generate HTML, skipping`);
|
|
703
|
+
failCount++;
|
|
704
|
+
continue;
|
|
705
|
+
}
|
|
706
|
+
if (htmlPrompt) {
|
|
707
|
+
const MAX_REGEN_ATTEMPTS = 5;
|
|
708
|
+
for (let attempt = 0; attempt < MAX_REGEN_ATTEMPTS; attempt++) {
|
|
709
|
+
const measureFileName = `hanseol_measure_${slideNum}_${timestamp}_${attempt}.html`;
|
|
710
|
+
const measureWritePath = path.join(tempWritePath, measureFileName);
|
|
711
|
+
const measureWinPath = `${tempWinPath}\\${measureFileName}`;
|
|
712
|
+
try {
|
|
713
|
+
fs.writeFileSync(measureWritePath, injectMeasureCss(html), 'utf-8');
|
|
714
|
+
const contentHeight = await powerpointClient.measureHtmlHeight(measureWinPath);
|
|
715
|
+
try {
|
|
716
|
+
fs.unlinkSync(measureWritePath);
|
|
717
|
+
}
|
|
718
|
+
catch { }
|
|
719
|
+
if (contentHeight <= 1100) {
|
|
720
|
+
if (attempt > 0)
|
|
721
|
+
logger.info(`Slide ${slideNum}: Fits after ${attempt} regeneration(s) (${contentHeight}px)`);
|
|
722
|
+
break;
|
|
723
|
+
}
|
|
724
|
+
logger.warn(`Slide ${slideNum}: Content overflows (${contentHeight}px > 1080px), attempt ${attempt + 1}/${MAX_REGEN_ATTEMPTS}`);
|
|
725
|
+
if (phaseLogger)
|
|
726
|
+
phaseLogger('powerpoint-create', 'execution', `Slide ${slideNum}: overflow (${contentHeight}px), regen ${attempt + 1}/${MAX_REGEN_ATTEMPTS}...`);
|
|
727
|
+
try {
|
|
728
|
+
const regenRes = await llmClient.chatCompletion({
|
|
729
|
+
messages: [
|
|
730
|
+
{ role: 'system', content: htmlPrompt },
|
|
731
|
+
{ role: 'user', content: `Generate the HTML slide now. CRITICAL: Your previous version was ${contentHeight}px tall but the slide is only 1080px. Content was CLIPPED at the bottom.\n\nYou MUST:\n- Use FEWER items (max 3 cards, max 3 rows, max 3 metrics)\n- SHORTER text per item (1-2 lines max)\n- SIMPLER layout with generous padding\n- body padding: 60px 80px minimum\n- Do NOT exceed 3 content blocks total\n\nThis is attempt ${attempt + 1}. ${attempt >= 2 ? 'DRASTICALLY simplify — use only 2 main items with large text.' : ''}` },
|
|
732
|
+
],
|
|
733
|
+
temperature: 0.2,
|
|
734
|
+
max_tokens: 8000,
|
|
735
|
+
});
|
|
736
|
+
const regenMsg = regenRes.choices[0]?.message;
|
|
737
|
+
const regenRaw = regenMsg ? extractContent(regenMsg) : '';
|
|
738
|
+
const regenHtml = extractHtml(regenRaw);
|
|
739
|
+
if (regenHtml) {
|
|
740
|
+
html = regenHtml;
|
|
741
|
+
logger.info(`Slide ${slideNum}: Regenerated HTML (attempt ${attempt + 1})`);
|
|
742
|
+
}
|
|
743
|
+
else {
|
|
744
|
+
break;
|
|
745
|
+
}
|
|
746
|
+
}
|
|
747
|
+
catch (e) {
|
|
748
|
+
logger.warn(`Slide ${slideNum}: Overflow regeneration attempt ${attempt + 1} failed: ${e}`);
|
|
749
|
+
break;
|
|
750
|
+
}
|
|
751
|
+
}
|
|
752
|
+
catch {
|
|
753
|
+
break;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
const htmlFileName = `hanseol_slide_${slideNum}_${timestamp}.html`;
|
|
758
|
+
const pngFileName = `hanseol_slide_${slideNum}_${timestamp}.png`;
|
|
759
|
+
const htmlWritePath = path.join(tempWritePath, htmlFileName);
|
|
760
|
+
const pngWritePath = path.join(tempWritePath, pngFileName);
|
|
761
|
+
const htmlWinPath = `${tempWinPath}\\${htmlFileName}`;
|
|
762
|
+
const pngWinPath = `${tempWinPath}\\${pngFileName}`;
|
|
763
|
+
try {
|
|
764
|
+
fs.writeFileSync(htmlWritePath, enforceMinFontSize(injectViewportCss(html, plan.design.background_color)), 'utf-8');
|
|
765
|
+
tempFiles.push(htmlWritePath);
|
|
766
|
+
}
|
|
767
|
+
catch (e) {
|
|
768
|
+
logger.warn(`Slide ${slideNum}: Failed to write HTML file: ${e}`);
|
|
769
|
+
failCount++;
|
|
770
|
+
continue;
|
|
771
|
+
}
|
|
772
|
+
let renderSuccess = false;
|
|
773
|
+
try {
|
|
774
|
+
const renderResult = await powerpointClient.renderHtmlToImage(htmlWinPath, pngWinPath);
|
|
775
|
+
totalToolCalls++;
|
|
776
|
+
renderSuccess = renderResult.success;
|
|
777
|
+
if (!renderSuccess) {
|
|
778
|
+
await new Promise(r => setTimeout(r, 2000));
|
|
779
|
+
const retryRender = await powerpointClient.renderHtmlToImage(htmlWinPath, pngWinPath);
|
|
780
|
+
totalToolCalls++;
|
|
781
|
+
renderSuccess = retryRender.success;
|
|
782
|
+
}
|
|
783
|
+
}
|
|
784
|
+
catch (e) {
|
|
785
|
+
logger.warn(`Slide ${slideNum}: Edge screenshot failed: ${e}`);
|
|
786
|
+
try {
|
|
787
|
+
await new Promise(r => setTimeout(r, 2000));
|
|
788
|
+
const retryRender = await powerpointClient.renderHtmlToImage(htmlWinPath, pngWinPath);
|
|
789
|
+
totalToolCalls++;
|
|
790
|
+
renderSuccess = retryRender.success;
|
|
791
|
+
}
|
|
792
|
+
catch {
|
|
793
|
+
renderSuccess = false;
|
|
794
|
+
}
|
|
795
|
+
}
|
|
796
|
+
try {
|
|
797
|
+
fs.unlinkSync(htmlWritePath);
|
|
798
|
+
}
|
|
799
|
+
catch { }
|
|
800
|
+
if (!renderSuccess) {
|
|
801
|
+
logger.warn(`Slide ${slideNum}: Screenshot rendering failed, skipping`);
|
|
802
|
+
failCount++;
|
|
803
|
+
continue;
|
|
804
|
+
}
|
|
805
|
+
try {
|
|
806
|
+
const pngStats = fs.statSync(pngWritePath);
|
|
807
|
+
if (pngStats.size < 15000) {
|
|
808
|
+
logger.warn(`Slide ${slideNum}: Screenshot too small (${pngStats.size} bytes), likely blank — skipping`);
|
|
809
|
+
failCount++;
|
|
810
|
+
try {
|
|
811
|
+
fs.unlinkSync(pngWritePath);
|
|
812
|
+
}
|
|
813
|
+
catch { }
|
|
814
|
+
continue;
|
|
815
|
+
}
|
|
816
|
+
}
|
|
817
|
+
catch { }
|
|
818
|
+
tempFiles.push(pngWritePath);
|
|
819
|
+
const addResult = await powerpointClient.powerpointAddSlide(7);
|
|
820
|
+
totalToolCalls++;
|
|
821
|
+
if (!addResult.success) {
|
|
822
|
+
logger.warn(`Slide ${slideNum}: Failed to add blank slide`);
|
|
823
|
+
failCount++;
|
|
824
|
+
continue;
|
|
825
|
+
}
|
|
826
|
+
const bgResult = await powerpointClient.powerpointAddFullSlideImage(slideNum, pngWinPath);
|
|
827
|
+
totalToolCalls++;
|
|
828
|
+
if (toolCallLogger)
|
|
829
|
+
toolCallLogger('powerpoint-create', 'addFullSlideImage', { slideNum, imagePath: pngWinPath }, bgResult.success ? 'OK' : 'Failed', bgResult.success, slideNum, totalToolCalls);
|
|
830
|
+
if (bgResult.success) {
|
|
831
|
+
builtSlides.push(`Slide ${slideNum}: ${slidePlan.title} (${slidePlan.type})`);
|
|
832
|
+
try {
|
|
833
|
+
await powerpointClient.powerpointAddNote(slideNum, html);
|
|
834
|
+
}
|
|
835
|
+
catch { }
|
|
836
|
+
}
|
|
837
|
+
else {
|
|
838
|
+
logger.warn(`Slide ${slideNum}: Failed to set background: ${JSON.stringify(bgResult)}`);
|
|
839
|
+
failCount++;
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
if (builtSlides.length > 0) {
|
|
843
|
+
try {
|
|
844
|
+
const slideCountResult = await powerpointClient.powerpointGetSlideCount();
|
|
845
|
+
const totalSlidesInPpt = slideCountResult['slide_count'] || 0;
|
|
846
|
+
if (totalSlidesInPpt > builtSlides.length) {
|
|
847
|
+
logger.warn(`PPT has ${totalSlidesInPpt} slides but only ${builtSlides.length} were rendered — deleting ${totalSlidesInPpt - builtSlides.length} trailing blanks`);
|
|
848
|
+
for (let d = totalSlidesInPpt; d > builtSlides.length; d--) {
|
|
849
|
+
await powerpointClient.powerpointDeleteSlide(d);
|
|
850
|
+
totalToolCalls++;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
}
|
|
854
|
+
catch (e) {
|
|
855
|
+
logger.warn(`Failed to clean up trailing slides: ${e}`);
|
|
856
|
+
}
|
|
857
|
+
}
|
|
858
|
+
if (builtSlides.length > 0) {
|
|
859
|
+
let saveResult = await powerpointClient.powerpointSave(savePath);
|
|
860
|
+
totalToolCalls++;
|
|
861
|
+
if (toolCallLogger)
|
|
862
|
+
toolCallLogger('powerpoint-create', 'powerpoint_save', { path: savePath }, saveResult.success ? (saveResult['path'] || 'OK') : (saveResult.error || 'Failed'), saveResult.success, 0, totalToolCalls);
|
|
863
|
+
if (!saveResult.success && savePath) {
|
|
864
|
+
const fallbackPath = 'C:\\temp\\presentation.pptx';
|
|
865
|
+
saveResult = await powerpointClient.powerpointSave(fallbackPath);
|
|
866
|
+
totalToolCalls++;
|
|
867
|
+
if (toolCallLogger)
|
|
868
|
+
toolCallLogger('powerpoint-create', 'powerpoint_save', { path: fallbackPath }, saveResult.success ? (saveResult['path'] || 'OK') : (saveResult.error || 'Failed'), saveResult.success, 0, totalToolCalls);
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
for (const tempFile of tempFiles) {
|
|
872
|
+
try {
|
|
873
|
+
fs.unlinkSync(tempFile);
|
|
874
|
+
}
|
|
875
|
+
catch { }
|
|
876
|
+
}
|
|
877
|
+
const duration = Date.now() - startTime;
|
|
878
|
+
const summary = `Presentation created with ${builtSlides.length} slides (HTML rendering, ${plan.design.mood}):\n${builtSlides.join('\n')}`;
|
|
879
|
+
logger.exit('PPT-Create.runStructured', { slideCount: builtSlides.length, totalToolCalls, duration });
|
|
880
|
+
return {
|
|
881
|
+
success: builtSlides.length > 0,
|
|
882
|
+
result: summary,
|
|
883
|
+
metadata: { iterations: plan.slides.length, toolCalls: totalToolCalls, duration },
|
|
884
|
+
};
|
|
885
|
+
}
|
|
886
|
+
export function createPowerPointCreateRequestTool() {
|
|
887
|
+
return {
|
|
888
|
+
definition: {
|
|
889
|
+
type: 'function',
|
|
890
|
+
function: {
|
|
891
|
+
name: 'powerpoint_create_agent',
|
|
892
|
+
description: 'Autonomous PowerPoint CREATION agent. Creates NEW presentations from scratch with professional slide designs, color schemes, and visual hierarchy. Uses HTML rendering pipeline for maximum design quality — each slide is rendered as a beautiful HTML page and captured as a high-quality image. Give it a topic or outline and it produces a polished, enterprise-grade presentation. For EDITING existing .pptx files, use powerpoint_modify_agent instead.',
|
|
893
|
+
parameters: {
|
|
894
|
+
type: 'object',
|
|
895
|
+
properties: {
|
|
896
|
+
instruction: {
|
|
897
|
+
type: 'string',
|
|
898
|
+
description: 'Detailed instruction for creating a new presentation. Include: topic/title, desired content, and design preferences. The agent autonomously creates a professional presentation with title, content, and closing slides.',
|
|
899
|
+
},
|
|
900
|
+
save_path: {
|
|
901
|
+
type: 'string',
|
|
902
|
+
description: 'Windows file path to save the presentation (e.g., "C:\\\\temp\\\\pitch.pptx"). MUST be provided if the user specified a save path.',
|
|
903
|
+
},
|
|
904
|
+
},
|
|
905
|
+
required: ['instruction'],
|
|
906
|
+
},
|
|
907
|
+
},
|
|
908
|
+
},
|
|
909
|
+
execute: async (args, llmClient) => {
|
|
910
|
+
const instruction = args['instruction'];
|
|
911
|
+
const explicitSavePath = args['save_path'];
|
|
912
|
+
return runStructured(llmClient, instruction, explicitSavePath);
|
|
913
|
+
},
|
|
914
|
+
categories: ['llm-agent'],
|
|
915
|
+
requiresSubLLM: true,
|
|
916
|
+
};
|
|
917
|
+
}
|
|
918
|
+
//# sourceMappingURL=powerpoint-create-agent.js.map
|