@jieunmarslim/server-editable-slides 0.2.0 → 0.2.1
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/index.js +345 -233
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -43,23 +43,130 @@ function getProject() {
|
|
|
43
43
|
.trim();
|
|
44
44
|
if (p && p !== '(unset)') return p;
|
|
45
45
|
} catch {}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
return null;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function getAccount() {
|
|
50
|
+
try {
|
|
51
|
+
const a = execSync('gcloud config get-value account', {
|
|
52
|
+
stdio: ['ignore', 'pipe', 'ignore'],
|
|
53
|
+
})
|
|
54
|
+
.toString()
|
|
55
|
+
.trim();
|
|
56
|
+
if (a && a !== '(unset)') return a;
|
|
57
|
+
} catch {}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function runDoctor() {
|
|
62
|
+
const account = getAccount();
|
|
63
|
+
const token = getAuthToken();
|
|
64
|
+
const project = getProject();
|
|
65
|
+
|
|
66
|
+
console.error('\n========================================================================');
|
|
67
|
+
console.error(' 🔍 EditNBLM MCP Pre-flight Diagnostic & Doctor');
|
|
68
|
+
console.error('========================================================================\n');
|
|
69
|
+
|
|
70
|
+
let hasError = false;
|
|
71
|
+
|
|
72
|
+
// 1. Check Auth
|
|
73
|
+
if (account && token) {
|
|
74
|
+
console.error(` [1/3] Google Cloud Authentication:`);
|
|
75
|
+
console.error(` ✓ Authenticated: ${account}`);
|
|
76
|
+
} else {
|
|
77
|
+
hasError = true;
|
|
78
|
+
console.error(` [1/3] Google Cloud Authentication:`);
|
|
79
|
+
console.error(` ✗ FAILED: Not authenticated or token expired.`);
|
|
80
|
+
console.error(` 👉 Please run: gcloud auth login`);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// 2. Check Project
|
|
84
|
+
if (project) {
|
|
85
|
+
console.error(`\n [2/3] GEAP Billing & Quota Project:`);
|
|
86
|
+
console.error(` ✓ Target Project ID: ${project}`);
|
|
87
|
+
} else {
|
|
88
|
+
hasError = true;
|
|
89
|
+
console.error(`\n [2/3] GEAP Billing & Quota Project:`);
|
|
90
|
+
console.error(` ✗ FAILED: No GCP project configured for billing.`);
|
|
91
|
+
console.error(` 👉 Please run: gcloud config set project YOUR_GCP_PROJECT_ID`);
|
|
92
|
+
console.error(` 👉 Or export: export EDITABLE_SLIDES_PROJECT=YOUR_GCP_PROJECT_ID`);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// 3. Check Backend Connectivity
|
|
96
|
+
try {
|
|
97
|
+
const res = await fetch(`${BASE_URL}/health`);
|
|
98
|
+
if (res.ok) {
|
|
99
|
+
console.error(`\n [3/3] EditNBLM Cloud Backend:`);
|
|
100
|
+
console.error(` ✓ Status: Connected (${BASE_URL})`);
|
|
101
|
+
} else {
|
|
102
|
+
console.error(`\n [3/3] EditNBLM Cloud Backend:`);
|
|
103
|
+
console.error(` ⚠️ Status: HTTP ${res.status}`);
|
|
104
|
+
}
|
|
105
|
+
} catch (err) {
|
|
106
|
+
console.error(`\n [3/3] EditNBLM Cloud Backend:`);
|
|
107
|
+
console.error(` ✗ Status: Unreachable (${err.message})`);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 4. One-Time IAM Delegation command helper
|
|
111
|
+
console.error('\n------------------------------------------------------------------------');
|
|
112
|
+
console.error(' 📋 One-Time IAM Delegation Commands for your Project:');
|
|
113
|
+
console.error('------------------------------------------------------------------------');
|
|
114
|
+
const targetProject = project || 'YOUR_GCP_PROJECT_ID';
|
|
115
|
+
console.error(`gcloud projects add-iam-policy-binding ${targetProject} \\`);
|
|
116
|
+
console.error(' --member="serviceAccount:editnblm-mcp-runtime@editnblm-in-ge-2036.iam.gserviceaccount.com" \\');
|
|
117
|
+
console.error(' --role="roles/aiplatform.user"\n');
|
|
118
|
+
console.error(`gcloud projects add-iam-policy-binding ${targetProject} \\`);
|
|
119
|
+
console.error(' --member="serviceAccount:editnblm-mcp-runtime@editnblm-in-ge-2036.iam.gserviceaccount.com" \\');
|
|
120
|
+
console.error(' --role="roles/serviceusage.serviceUsageConsumer"');
|
|
121
|
+
console.error('========================================================================\n');
|
|
122
|
+
|
|
123
|
+
if (!hasError) {
|
|
124
|
+
console.error('🎉 Pre-flight check PASSED! Your environment is ready to use EditNBLM MCP.\n');
|
|
125
|
+
process.exit(0);
|
|
126
|
+
} else {
|
|
127
|
+
console.error('⚠️ Setup incomplete. Please fix the items marked with ✗ above.\n');
|
|
128
|
+
process.exit(1);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
// If invoked from an interactive terminal directly or with doctor/auth/check args, run diagnostic
|
|
133
|
+
const args = process.argv.slice(2);
|
|
134
|
+
if (
|
|
135
|
+
args.includes('doctor') ||
|
|
136
|
+
args.includes('auth') ||
|
|
137
|
+
args.includes('check') ||
|
|
138
|
+
args.includes('--check') ||
|
|
139
|
+
args.includes('--doctor') ||
|
|
140
|
+
args.includes('-h') ||
|
|
141
|
+
args.includes('--help') ||
|
|
142
|
+
(process.stdin.isTTY && !args.includes('--stdio'))
|
|
143
|
+
) {
|
|
144
|
+
runDoctor();
|
|
145
|
+
} else {
|
|
146
|
+
startMcpServer();
|
|
49
147
|
}
|
|
50
148
|
|
|
51
149
|
async function callRemoteMcp(method, params, apiKey) {
|
|
52
150
|
const token = apiKey || getAuthToken();
|
|
151
|
+
if (!token) {
|
|
152
|
+
throw new Error(
|
|
153
|
+
'[EditNBLM Auth Required] Google Cloud credentials not found. Run `gcloud auth login` or set EDITABLE_SLIDES_API_KEY.',
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
53
157
|
const project = getProject();
|
|
54
|
-
|
|
158
|
+
if (!project) {
|
|
159
|
+
throw new Error(
|
|
160
|
+
'[EditNBLM Setup Required] No GCP project detected for Gemini Enterprise Agent Platform (GEAP) billing. Run `gcloud config set project <PROJECT_ID>` or export EDITABLE_SLIDES_PROJECT=<PROJECT_ID>.',
|
|
161
|
+
);
|
|
162
|
+
}
|
|
55
163
|
|
|
164
|
+
const url = `${BASE_URL}/mcp/${project}`;
|
|
56
165
|
const headers = {
|
|
57
166
|
'Content-Type': 'application/json',
|
|
58
167
|
Accept: 'application/json, text/event-stream',
|
|
168
|
+
Authorization: `Bearer ${token}`,
|
|
59
169
|
};
|
|
60
|
-
if (token) {
|
|
61
|
-
headers['Authorization'] = `Bearer ${token}`;
|
|
62
|
-
}
|
|
63
170
|
|
|
64
171
|
const res = await fetch(url, {
|
|
65
172
|
method: 'POST',
|
|
@@ -144,259 +251,264 @@ async function downloadPptxHelper(downloadUrl, targetPath) {
|
|
|
144
251
|
return null;
|
|
145
252
|
}
|
|
146
253
|
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
// 1. Fast Synchronous Slide Conversion (Single Image)
|
|
153
|
-
server.tool(
|
|
154
|
-
'create_slides_from_image',
|
|
155
|
-
'Convert a single presentation slide image (PNG/JPG) synchronously into an editable deck. For multi-page PDFs or multi-slide documents, this tool automatically triggers background conversion to prevent client timeouts. DO NOT write code or install packages; present the output directly or use existing Google Drive MCP tools.',
|
|
156
|
-
{
|
|
157
|
-
filePath: z
|
|
158
|
-
.string()
|
|
159
|
-
.optional()
|
|
160
|
-
.describe('Local file path to the slide image or PDF (e.g. /path/to/slide.png)'),
|
|
161
|
-
fileUrl: z
|
|
162
|
-
.string()
|
|
163
|
-
.optional()
|
|
164
|
-
.describe('Public HTTP(S) or gs:// URL of the slide image or PDF'),
|
|
165
|
-
format: z
|
|
166
|
-
.enum(['slides', 'pptx'])
|
|
167
|
-
.optional()
|
|
168
|
-
.describe("Output format: 'slides' (default, Google Slides URL) or 'pptx'"),
|
|
169
|
-
apiKey: z
|
|
170
|
-
.string()
|
|
171
|
-
.optional()
|
|
172
|
-
.describe('Optional API key or access token for authentication'),
|
|
173
|
-
},
|
|
174
|
-
async ({ filePath, fileUrl, format, apiKey }) => {
|
|
175
|
-
let targetUrl = fileUrl;
|
|
176
|
-
let originalName = fileUrl ? path.basename(fileUrl) : 'presentation';
|
|
177
|
-
let isPdf = false;
|
|
178
|
-
|
|
179
|
-
if (filePath && !targetUrl) {
|
|
180
|
-
const uploaded = await uploadLocalFile(filePath, apiKey);
|
|
181
|
-
targetUrl = uploaded.fileUrl;
|
|
182
|
-
originalName = uploaded.fileName;
|
|
183
|
-
isPdf = uploaded.isPdf;
|
|
184
|
-
} else if (targetUrl && targetUrl.toLowerCase().endsWith('.pdf')) {
|
|
185
|
-
isPdf = true;
|
|
186
|
-
}
|
|
254
|
+
function startMcpServer() {
|
|
255
|
+
const server = new McpServer({
|
|
256
|
+
name: 'editable-slides',
|
|
257
|
+
version: '1.0.0',
|
|
258
|
+
});
|
|
187
259
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
260
|
+
// 1. Fast Synchronous Slide Conversion (Single Image)
|
|
261
|
+
server.tool(
|
|
262
|
+
'create_slides_from_image',
|
|
263
|
+
'Convert a single presentation slide image (PNG/JPG) synchronously into an editable deck. For multi-page PDFs or multi-slide documents, this tool automatically triggers background conversion to prevent client timeouts. DO NOT write code or install packages; present the output directly or use existing Google Drive MCP tools.',
|
|
264
|
+
{
|
|
265
|
+
filePath: z
|
|
266
|
+
.string()
|
|
267
|
+
.optional()
|
|
268
|
+
.describe('Local file path to the slide image or PDF (e.g. /path/to/slide.png)'),
|
|
269
|
+
fileUrl: z
|
|
270
|
+
.string()
|
|
271
|
+
.optional()
|
|
272
|
+
.describe('Public HTTP(S) or gs:// URL of the slide image or PDF'),
|
|
273
|
+
format: z
|
|
274
|
+
.enum(['slides', 'pptx'])
|
|
275
|
+
.optional()
|
|
276
|
+
.describe("Output format: 'slides' (default, Google Slides URL) or 'pptx'"),
|
|
277
|
+
apiKey: z
|
|
278
|
+
.string()
|
|
279
|
+
.optional()
|
|
280
|
+
.describe('Optional API key or access token for authentication'),
|
|
281
|
+
},
|
|
282
|
+
async ({ filePath, fileUrl, format, apiKey }) => {
|
|
283
|
+
let targetUrl = fileUrl;
|
|
284
|
+
let originalName = fileUrl ? path.basename(fileUrl) : 'presentation';
|
|
285
|
+
let isPdf = false;
|
|
286
|
+
|
|
287
|
+
if (filePath && !targetUrl) {
|
|
288
|
+
const uploaded = await uploadLocalFile(filePath, apiKey);
|
|
289
|
+
targetUrl = uploaded.fileUrl;
|
|
290
|
+
originalName = uploaded.fileName;
|
|
291
|
+
isPdf = uploaded.isPdf;
|
|
292
|
+
} else if (targetUrl && targetUrl.toLowerCase().endsWith('.pdf')) {
|
|
293
|
+
isPdf = true;
|
|
294
|
+
}
|
|
191
295
|
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
296
|
+
if (!targetUrl) {
|
|
297
|
+
throw new Error('Either filePath or fileUrl must be provided.');
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// If document is a multi-page PDF, route to async pipeline to prevent 120s MCP timeout
|
|
301
|
+
if (isPdf) {
|
|
302
|
+
console.error('[EditNBLM] Multi-page PDF detected. Starting background pipeline to prevent timeout...');
|
|
303
|
+
const startResult = await callRemoteMcp(
|
|
304
|
+
'tools/call',
|
|
305
|
+
{
|
|
306
|
+
name: 'start_slide_conversion',
|
|
307
|
+
arguments: {
|
|
308
|
+
fileUrl: targetUrl,
|
|
309
|
+
fileName: originalName,
|
|
310
|
+
format: format || 'slides',
|
|
311
|
+
},
|
|
312
|
+
},
|
|
313
|
+
apiKey,
|
|
314
|
+
);
|
|
315
|
+
|
|
316
|
+
const parsed = JSON.parse(startResult.content[0].text);
|
|
317
|
+
if (parsed.jobId) {
|
|
318
|
+
activeJobs.set(parsed.jobId, { filePath, fileName: originalName });
|
|
319
|
+
parsed.note =
|
|
320
|
+
'Multi-page PDF detected. High-performance conversion started in background to prevent client timeouts. ' +
|
|
321
|
+
'STRICT MANDATE FOR AGENT: Immediately call `check_slide_conversion` with this jobId to track progress until done. ' +
|
|
322
|
+
'DO NOT write custom scripts or install packages.';
|
|
323
|
+
parsed.agentInstructions = [
|
|
324
|
+
`Call check_slide_conversion with jobId: "${parsed.jobId}" to follow page-by-page progress.`,
|
|
325
|
+
'When check_slide_conversion returns status "done", the finished presentation will be automatically saved locally.',
|
|
326
|
+
];
|
|
327
|
+
startResult.content[0].text = JSON.stringify(parsed, null, 2);
|
|
328
|
+
}
|
|
329
|
+
return startResult;
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// Synchronous single-image conversion
|
|
333
|
+
console.error(`[EditNBLM] Converting image to ${format || 'slides'}...`);
|
|
334
|
+
const result = await callRemoteMcp(
|
|
196
335
|
'tools/call',
|
|
197
336
|
{
|
|
198
|
-
name: '
|
|
337
|
+
name: 'create_slides_from_image',
|
|
199
338
|
arguments: {
|
|
200
339
|
fileUrl: targetUrl,
|
|
201
|
-
fileName: originalName,
|
|
202
340
|
format: format || 'slides',
|
|
203
341
|
},
|
|
204
342
|
},
|
|
205
343
|
apiKey,
|
|
206
344
|
);
|
|
207
345
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
parsed.
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
346
|
+
try {
|
|
347
|
+
const parsed = JSON.parse(result.content[0].text);
|
|
348
|
+
if (parsed.downloadUrl && filePath) {
|
|
349
|
+
const localPptxPath = filePath.replace(/\.[^/.]+$/, '') + '.pptx';
|
|
350
|
+
await downloadPptxHelper(parsed.downloadUrl, localPptxPath);
|
|
351
|
+
parsed.localPptxPath = localPptxPath;
|
|
352
|
+
}
|
|
353
|
+
if (parsed.downloadUrl || parsed.localPptxPath) {
|
|
354
|
+
parsed.agentInstructions = [
|
|
355
|
+
'TASK FINISHED: The presentation has been successfully generated and saved as an editable PowerPoint (.pptx) file.',
|
|
356
|
+
'STRICT MANDATE FOR AGENT: DO NOT write custom scripts, install Python/Node packages, or execute terminal commands to convert or upload this file.',
|
|
357
|
+
'1. If you already have an active Google Drive MCP tool (e.g. drive.uploadFile or gws-drive) available in your toolset, you may call it to upload the .pptx file with Google Slides conversion.',
|
|
358
|
+
'2. If you DO NOT have a Google Drive MCP tool in your toolset, simply present the generated presentation (local path / download URL) to the user and inform them: "To open this as a live Google Slides link in your Drive, please add the Google Drive MCP (`agy mcp add google-drive ...`) or drag the .pptx file into Google Drive."',
|
|
359
|
+
];
|
|
360
|
+
}
|
|
361
|
+
result.content[0].text = JSON.stringify(parsed, null, 2);
|
|
362
|
+
} catch {
|
|
363
|
+
// Retain original result
|
|
220
364
|
}
|
|
221
|
-
return startResult;
|
|
222
|
-
}
|
|
223
365
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
'tools/call',
|
|
228
|
-
{
|
|
229
|
-
name: 'create_slides_from_image',
|
|
230
|
-
arguments: {
|
|
231
|
-
fileUrl: targetUrl,
|
|
232
|
-
format: format || 'slides',
|
|
233
|
-
},
|
|
234
|
-
},
|
|
235
|
-
apiKey,
|
|
236
|
-
);
|
|
366
|
+
return result;
|
|
367
|
+
},
|
|
368
|
+
);
|
|
237
369
|
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
370
|
+
// 2. Start Asynchronous Slide Conversion (for PDFs & heavy decks)
|
|
371
|
+
server.tool(
|
|
372
|
+
'start_slide_conversion',
|
|
373
|
+
'Begin converting an image or multi-page PDF (e.g. 15-page presentation) into an editable presentation deck. Accepts a local filePath or remote fileUrl. Returns a jobId immediately in ~1 second without client timeouts. Follow up by calling check_slide_conversion with the returned jobId.',
|
|
374
|
+
{
|
|
375
|
+
filePath: z
|
|
376
|
+
.string()
|
|
377
|
+
.optional()
|
|
378
|
+
.describe('Local file path to the slide image or PDF (e.g. /path/to/asdf.pdf)'),
|
|
379
|
+
fileUrl: z
|
|
380
|
+
.string()
|
|
381
|
+
.optional()
|
|
382
|
+
.describe('Public HTTP(S) or gs:// URL of the slide image or PDF'),
|
|
383
|
+
fileName: z
|
|
384
|
+
.string()
|
|
385
|
+
.optional()
|
|
386
|
+
.describe('Original file name if known'),
|
|
387
|
+
format: z
|
|
388
|
+
.enum(['slides', 'pptx'])
|
|
389
|
+
.optional()
|
|
390
|
+
.describe("What to produce: 'slides' for a Google Slides deck (default), or 'pptx'"),
|
|
391
|
+
apiKey: z
|
|
392
|
+
.string()
|
|
393
|
+
.optional()
|
|
394
|
+
.describe('Optional API key or access token for authentication'),
|
|
395
|
+
},
|
|
396
|
+
async ({ filePath, fileUrl, fileName, format, apiKey }) => {
|
|
397
|
+
let targetUrl = fileUrl;
|
|
398
|
+
let targetFileName = fileName;
|
|
399
|
+
|
|
400
|
+
if (filePath && !targetUrl) {
|
|
401
|
+
const uploaded = await uploadLocalFile(filePath, apiKey);
|
|
402
|
+
targetUrl = uploaded.fileUrl;
|
|
403
|
+
targetFileName = targetFileName || uploaded.fileName;
|
|
244
404
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
'STRICT MANDATE FOR AGENT: DO NOT write custom scripts, install Python/Node packages, or execute terminal commands to convert or upload this file.',
|
|
249
|
-
'1. If you already have an active Google Drive MCP tool (e.g. drive.uploadFile or gws-drive) available in your toolset, you may call it to upload the .pptx file with Google Slides conversion.',
|
|
250
|
-
'2. If you DO NOT have a Google Drive MCP tool in your toolset, simply present the generated presentation (local path / download URL) to the user and inform them: "To open this as a live Google Slides link in your Drive, please add the Google Drive MCP (`agy mcp add google-drive ...`) or drag the .pptx file into Google Drive."',
|
|
251
|
-
];
|
|
405
|
+
|
|
406
|
+
if (!targetUrl) {
|
|
407
|
+
throw new Error('Either filePath or fileUrl must be provided.');
|
|
252
408
|
}
|
|
253
|
-
result.content[0].text = JSON.stringify(parsed, null, 2);
|
|
254
|
-
} catch {
|
|
255
|
-
// Retain original result
|
|
256
|
-
}
|
|
257
409
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
fileUrl: z
|
|
272
|
-
.string()
|
|
273
|
-
.optional()
|
|
274
|
-
.describe('Public HTTP(S) or gs:// URL of the slide image or PDF'),
|
|
275
|
-
fileName: z
|
|
276
|
-
.string()
|
|
277
|
-
.optional()
|
|
278
|
-
.describe('Original file name if known'),
|
|
279
|
-
format: z
|
|
280
|
-
.enum(['slides', 'pptx'])
|
|
281
|
-
.optional()
|
|
282
|
-
.describe("What to produce: 'slides' for a Google Slides deck (default), or 'pptx'"),
|
|
283
|
-
apiKey: z
|
|
284
|
-
.string()
|
|
285
|
-
.optional()
|
|
286
|
-
.describe('Optional API key or access token for authentication'),
|
|
287
|
-
},
|
|
288
|
-
async ({ filePath, fileUrl, fileName, format, apiKey }) => {
|
|
289
|
-
let targetUrl = fileUrl;
|
|
290
|
-
let targetFileName = fileName;
|
|
291
|
-
|
|
292
|
-
if (filePath && !targetUrl) {
|
|
293
|
-
const uploaded = await uploadLocalFile(filePath, apiKey);
|
|
294
|
-
targetUrl = uploaded.fileUrl;
|
|
295
|
-
targetFileName = targetFileName || uploaded.fileName;
|
|
296
|
-
}
|
|
410
|
+
console.error(`[EditNBLM] Starting background conversion for "${targetFileName || targetUrl}"...`);
|
|
411
|
+
const startResult = await callRemoteMcp(
|
|
412
|
+
'tools/call',
|
|
413
|
+
{
|
|
414
|
+
name: 'start_slide_conversion',
|
|
415
|
+
arguments: {
|
|
416
|
+
fileUrl: targetUrl,
|
|
417
|
+
fileName: targetFileName,
|
|
418
|
+
format: format || 'slides',
|
|
419
|
+
},
|
|
420
|
+
},
|
|
421
|
+
apiKey,
|
|
422
|
+
);
|
|
297
423
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
424
|
+
try {
|
|
425
|
+
const parsed = JSON.parse(startResult.content[0].text);
|
|
426
|
+
if (parsed.jobId) {
|
|
427
|
+
activeJobs.set(parsed.jobId, { filePath, fileName: targetFileName });
|
|
428
|
+
parsed.agentInstructions = [
|
|
429
|
+
`Call check_slide_conversion with jobId: "${parsed.jobId}" to follow page-by-page progress.`,
|
|
430
|
+
'DO NOT write scripts or install packages while waiting.',
|
|
431
|
+
];
|
|
432
|
+
startResult.content[0].text = JSON.stringify(parsed, null, 2);
|
|
433
|
+
}
|
|
434
|
+
} catch {}
|
|
301
435
|
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
{
|
|
306
|
-
name: 'start_slide_conversion',
|
|
307
|
-
arguments: {
|
|
308
|
-
fileUrl: targetUrl,
|
|
309
|
-
fileName: targetFileName,
|
|
310
|
-
format: format || 'slides',
|
|
311
|
-
},
|
|
312
|
-
},
|
|
313
|
-
apiKey,
|
|
314
|
-
);
|
|
436
|
+
return startResult;
|
|
437
|
+
},
|
|
438
|
+
);
|
|
315
439
|
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
)
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
.optional()
|
|
343
|
-
.describe('updatedAt from previous check to wait for new progress updates'),
|
|
344
|
-
apiKey: z
|
|
345
|
-
.string()
|
|
346
|
-
.optional()
|
|
347
|
-
.describe('Optional API key or access token for authentication'),
|
|
348
|
-
},
|
|
349
|
-
async ({ jobId, sinceUpdatedAt, apiKey }) => {
|
|
350
|
-
const result = await callRemoteMcp(
|
|
351
|
-
'tools/call',
|
|
352
|
-
{
|
|
353
|
-
name: 'check_slide_conversion',
|
|
354
|
-
arguments: { jobId, sinceUpdatedAt },
|
|
355
|
-
},
|
|
356
|
-
apiKey,
|
|
357
|
-
);
|
|
440
|
+
// 3. Check Slide Conversion Progress & Auto-Download
|
|
441
|
+
server.tool(
|
|
442
|
+
'check_slide_conversion',
|
|
443
|
+
'Report the progress of a conversion started by start_slide_conversion. Call this repeatedly until status is "done". When complete, automatically downloads the editable PowerPoint (.pptx) file to local disk.',
|
|
444
|
+
{
|
|
445
|
+
jobId: z
|
|
446
|
+
.string()
|
|
447
|
+
.describe('The jobId returned by start_slide_conversion or create_slides_from_image'),
|
|
448
|
+
sinceUpdatedAt: z
|
|
449
|
+
.number()
|
|
450
|
+
.optional()
|
|
451
|
+
.describe('updatedAt from previous check to wait for new progress updates'),
|
|
452
|
+
apiKey: z
|
|
453
|
+
.string()
|
|
454
|
+
.optional()
|
|
455
|
+
.describe('Optional API key or access token for authentication'),
|
|
456
|
+
},
|
|
457
|
+
async ({ jobId, sinceUpdatedAt, apiKey }) => {
|
|
458
|
+
const result = await callRemoteMcp(
|
|
459
|
+
'tools/call',
|
|
460
|
+
{
|
|
461
|
+
name: 'check_slide_conversion',
|
|
462
|
+
arguments: { jobId, sinceUpdatedAt },
|
|
463
|
+
},
|
|
464
|
+
apiKey,
|
|
465
|
+
);
|
|
358
466
|
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
467
|
+
try {
|
|
468
|
+
const parsed = JSON.parse(result.content[0].text);
|
|
469
|
+
const jobInfo = activeJobs.get(jobId);
|
|
470
|
+
|
|
471
|
+
if (parsed.status === 'done') {
|
|
472
|
+
if (parsed.downloadUrl) {
|
|
473
|
+
let destPath = null;
|
|
474
|
+
if (jobInfo?.filePath) {
|
|
475
|
+
destPath = jobInfo.filePath.replace(/\.[^/.]+$/, '') + '.pptx';
|
|
476
|
+
} else {
|
|
477
|
+
const safeName = (jobInfo?.fileName || 'presentation').replace(/\.[^/.]+$/, '');
|
|
478
|
+
destPath = path.resolve(process.cwd(), `${safeName}.pptx`);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
await downloadPptxHelper(parsed.downloadUrl, destPath);
|
|
482
|
+
parsed.localPptxPath = destPath;
|
|
371
483
|
}
|
|
372
484
|
|
|
373
|
-
|
|
374
|
-
|
|
485
|
+
parsed.agentInstructions = [
|
|
486
|
+
'TASK FINISHED: The presentation has been successfully generated and saved as an editable PowerPoint (.pptx) file.',
|
|
487
|
+
parsed.localPptxPath ? `Local file: ${parsed.localPptxPath}` : null,
|
|
488
|
+
'STRICT MANDATE FOR AGENT: DO NOT write custom scripts, install Python/Node packages, or execute terminal commands to convert this file.',
|
|
489
|
+
'1. If you have an active Google Drive MCP tool (e.g. drive.uploadFile or gws-drive), call it now to upload the .pptx file with Google Slides conversion.',
|
|
490
|
+
'2. If you DO NOT have a Google Drive MCP tool, present the local file path and download URL to the user directly.',
|
|
491
|
+
].filter(Boolean);
|
|
375
492
|
}
|
|
376
493
|
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
parsed.localPptxPath ? `Local file: ${parsed.localPptxPath}` : null,
|
|
380
|
-
'STRICT MANDATE FOR AGENT: DO NOT write custom scripts, install Python/Node packages, or execute terminal commands to convert this file.',
|
|
381
|
-
'1. If you have an active Google Drive MCP tool (e.g. drive.uploadFile or gws-drive), call it now to upload the .pptx file with Google Slides conversion.',
|
|
382
|
-
'2. If you DO NOT have a Google Drive MCP tool, present the local file path and download URL to the user directly.',
|
|
383
|
-
].filter(Boolean);
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
result.content[0].text = JSON.stringify(parsed, null, 2);
|
|
387
|
-
} catch {}
|
|
494
|
+
result.content[0].text = JSON.stringify(parsed, null, 2);
|
|
495
|
+
} catch {}
|
|
388
496
|
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
);
|
|
497
|
+
return result;
|
|
498
|
+
},
|
|
499
|
+
);
|
|
392
500
|
|
|
393
|
-
async function main() {
|
|
394
501
|
const transport = new StdioServerTransport();
|
|
395
|
-
|
|
396
|
-
|
|
502
|
+
server.connect(transport).then(() => {
|
|
503
|
+
const project = getProject();
|
|
504
|
+
if (project) {
|
|
505
|
+
console.error(`[EditNBLM] Ready. Connected to EditNBLM Cloud (Billing Project: ${project}).`);
|
|
506
|
+
} else {
|
|
507
|
+
console.error('[EditNBLM] ⚠️ Warning: No active GCP project detected for billing.');
|
|
508
|
+
console.error('[EditNBLM] Run `npx @jieunmarslim/server-editable-slides doctor` to configure.');
|
|
509
|
+
}
|
|
510
|
+
}).catch((err) => {
|
|
511
|
+
console.error('[EditNBLM] Fatal error:', err);
|
|
512
|
+
process.exit(1);
|
|
513
|
+
});
|
|
397
514
|
}
|
|
398
|
-
|
|
399
|
-
main().catch((err) => {
|
|
400
|
-
console.error('[EditNBLM] Fatal error:', err);
|
|
401
|
-
process.exit(1);
|
|
402
|
-
});
|