@kimdayoun/hwpx-mcp 0.3.4 → 0.3.5
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/CHANGELOG.md +49 -2
- package/README.md +2 -2
- package/dist/HwpxDocument.d.ts +16 -0
- package/dist/HwpxDocument.js +110 -29
- package/dist/HwpxParser.d.ts +13 -0
- package/dist/HwpxParser.js +50 -1
- package/dist/ToolResult.d.ts +14 -0
- package/dist/ToolResult.js +27 -0
- package/dist/index.js +438 -456
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -42,6 +42,7 @@ const path = __importStar(require("path"));
|
|
|
42
42
|
const HwpxDocument_1 = require("./HwpxDocument");
|
|
43
43
|
const HangingIndentCalculator_1 = require("./HangingIndentCalculator");
|
|
44
44
|
const XmlWellFormed_1 = require("./XmlWellFormed");
|
|
45
|
+
const ToolResult_1 = require("./ToolResult");
|
|
45
46
|
const MCP_VERSION = require('../package.json').version;
|
|
46
47
|
console.error(`[HWPX MCP] Server starting - ${MCP_VERSION} - ${new Date().toISOString()}`);
|
|
47
48
|
// Document storage
|
|
@@ -277,7 +278,7 @@ Example workflow for templates:
|
|
|
277
278
|
3. Save - all original formatting preserved
|
|
278
279
|
|
|
279
280
|
⚠️ If you need to CHANGE alignment/style, use set_paragraph_style instead.
|
|
280
|
-
⚠️
|
|
281
|
+
⚠️ With run_index 0 (default) the whole paragraph is replaced: the new text takes the FIRST run's character shape and the other runs are emptied. To keep a bold/plain split, use update_paragraph_text_preserve_styles.`,
|
|
281
282
|
inputSchema: {
|
|
282
283
|
type: 'object',
|
|
283
284
|
properties: {
|
|
@@ -2155,17 +2156,8 @@ const requiredArgsByTool = new Map(tools.map(tool => [
|
|
|
2155
2156
|
tool.name,
|
|
2156
2157
|
(tool.inputSchema?.required) ?? [],
|
|
2157
2158
|
]));
|
|
2158
|
-
/**
|
|
2159
|
-
* Report the exact missing arguments instead of letting the handler fail with a
|
|
2160
|
-
* generic message. `section_index` is declared required on the insert/update
|
|
2161
|
-
* tools, but omitting it used to surface as "Failed to insert paragraph", which
|
|
2162
|
-
* reads like document corruption and sends callers off inspecting the file.
|
|
2163
|
-
*/
|
|
2164
2159
|
function findMissingArgs(toolName, args) {
|
|
2165
|
-
|
|
2166
|
-
if (!required || required.length === 0)
|
|
2167
|
-
return [];
|
|
2168
|
-
return required.filter(key => args?.[key] === undefined || args?.[key] === null);
|
|
2160
|
+
return (0, ToolResult_1.findMissingArgs)(requiredArgsByTool, toolName, args);
|
|
2169
2161
|
}
|
|
2170
2162
|
// ============================================================
|
|
2171
2163
|
// Tool Handlers
|
|
@@ -2174,7 +2166,7 @@ server.setRequestHandler(types_js_1.CallToolRequestSchema, async (request) => {
|
|
|
2174
2166
|
const { name, arguments: args } = request.params;
|
|
2175
2167
|
const missing = findMissingArgs(name, args);
|
|
2176
2168
|
if (missing.length > 0) {
|
|
2177
|
-
return error(`Missing required argument${missing.length > 1 ? 's' : ''} for ${name}: ${missing.join(', ')}`);
|
|
2169
|
+
return (0, ToolResult_1.error)(`Missing required argument${missing.length > 1 ? 's' : ''} for ${name}: ${missing.join(', ')}`);
|
|
2178
2170
|
}
|
|
2179
2171
|
try {
|
|
2180
2172
|
switch (name) {
|
|
@@ -2330,21 +2322,21 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
2330
2322
|
const known = Object.keys(guides);
|
|
2331
2323
|
const guide = guides[workflow];
|
|
2332
2324
|
if (!guide) {
|
|
2333
|
-
return error(`Unknown workflow "${workflow}". Available: ${known.join(', ')}`);
|
|
2325
|
+
return (0, ToolResult_1.error)(`Unknown workflow "${workflow}". Available: ${known.join(', ')}`);
|
|
2334
2326
|
}
|
|
2335
|
-
return success({ workflow, available_workflows: known, guide });
|
|
2327
|
+
return (0, ToolResult_1.success)({ workflow, available_workflows: known, guide });
|
|
2336
2328
|
}
|
|
2337
2329
|
// === Document Management ===
|
|
2338
2330
|
case 'open_document': {
|
|
2339
2331
|
const filePath = args?.file_path;
|
|
2340
2332
|
if (!filePath)
|
|
2341
|
-
return error('file_path is required');
|
|
2333
|
+
return (0, ToolResult_1.error)('file_path is required');
|
|
2342
2334
|
const absolutePath = path.resolve(filePath);
|
|
2343
2335
|
const data = fs.readFileSync(absolutePath);
|
|
2344
2336
|
const docId = generateId();
|
|
2345
2337
|
const doc = await HwpxDocument_1.HwpxDocument.createFromBuffer(docId, absolutePath, data);
|
|
2346
2338
|
openDocuments.set(docId, doc);
|
|
2347
|
-
return success({
|
|
2339
|
+
return (0, ToolResult_1.success)({
|
|
2348
2340
|
doc_id: docId,
|
|
2349
2341
|
format: doc.format,
|
|
2350
2342
|
path: absolutePath,
|
|
@@ -2355,17 +2347,17 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
2355
2347
|
case 'close_document': {
|
|
2356
2348
|
const docId = args?.doc_id;
|
|
2357
2349
|
if (openDocuments.delete(docId)) {
|
|
2358
|
-
return success({ message: 'Document closed' });
|
|
2350
|
+
return (0, ToolResult_1.success)({ message: 'Document closed' });
|
|
2359
2351
|
}
|
|
2360
|
-
return error('Document not found');
|
|
2352
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2361
2353
|
}
|
|
2362
2354
|
case 'save_document': {
|
|
2363
2355
|
const docId = args?.doc_id;
|
|
2364
2356
|
const doc = getDoc(docId);
|
|
2365
2357
|
if (!doc)
|
|
2366
|
-
return error('Document not found');
|
|
2358
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2367
2359
|
if (doc.format === 'hwp')
|
|
2368
|
-
return error('HWP files are read-only');
|
|
2360
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
2369
2361
|
// Use document lock to ensure all pending updates complete before save
|
|
2370
2362
|
return await withDocumentLock(docId, async () => {
|
|
2371
2363
|
// `file_path` is the parameter name used by open_document/create_document,
|
|
@@ -2373,7 +2365,7 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
2373
2365
|
// falling back to the document's own path.
|
|
2374
2366
|
const requestedPath = args?.output_path || args?.file_path;
|
|
2375
2367
|
if (!requestedPath && !doc.hasPath) {
|
|
2376
|
-
return error('output_path is required for a document created with create_document; ' +
|
|
2368
|
+
return (0, ToolResult_1.error)('output_path is required for a document created with create_document; ' +
|
|
2377
2369
|
'it has no location on disk yet');
|
|
2378
2370
|
}
|
|
2379
2371
|
const savePath = path.resolve(requestedPath || doc.path);
|
|
@@ -2382,7 +2374,7 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
2382
2374
|
let backupPath = null;
|
|
2383
2375
|
const saveDirectory = path.dirname(savePath);
|
|
2384
2376
|
if (!fs.existsSync(saveDirectory)) {
|
|
2385
|
-
return error(`Directory does not exist: ${saveDirectory}`);
|
|
2377
|
+
return (0, ToolResult_1.error)(`Directory does not exist: ${saveDirectory}`);
|
|
2386
2378
|
}
|
|
2387
2379
|
// A private directory prevents pre-created .tmp symlinks from redirecting writes.
|
|
2388
2380
|
const tempDirectory = fs.mkdtempSync(path.join(saveDirectory, '.hwpx-save-'));
|
|
@@ -2392,7 +2384,7 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
2392
2384
|
backupPath = savePath + '.bak';
|
|
2393
2385
|
const existingBackup = fs.lstatSync(backupPath, { throwIfNoEntry: false });
|
|
2394
2386
|
if (existingBackup && !existingBackup.isFile()) {
|
|
2395
|
-
return error('Backup destination must be a regular file');
|
|
2387
|
+
return (0, ToolResult_1.error)('Backup destination must be a regular file');
|
|
2396
2388
|
}
|
|
2397
2389
|
const stagedBackup = path.join(tempDirectory, 'backup.hwpx');
|
|
2398
2390
|
fs.copyFileSync(savePath, stagedBackup, fs.constants.COPYFILE_EXCL);
|
|
@@ -2440,15 +2432,15 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
2440
2432
|
}
|
|
2441
2433
|
// Restore from backup if exists
|
|
2442
2434
|
if (backupPath && fs.existsSync(backupPath)) {
|
|
2443
|
-
return error(`Save verification failed, backup preserved: ${verifyErr}`);
|
|
2435
|
+
return (0, ToolResult_1.error)(`Save verification failed, backup preserved: ${verifyErr}`);
|
|
2444
2436
|
}
|
|
2445
|
-
return error(`Save verification failed: ${verifyErr}`);
|
|
2437
|
+
return (0, ToolResult_1.error)(`Save verification failed: ${verifyErr}`);
|
|
2446
2438
|
}
|
|
2447
2439
|
}
|
|
2448
2440
|
// Do not unlink first: a failed rename must leave the original document intact.
|
|
2449
2441
|
fs.renameSync(tempPath, savePath);
|
|
2450
2442
|
doc.setPath(savePath);
|
|
2451
|
-
return success({
|
|
2443
|
+
return (0, ToolResult_1.success)({
|
|
2452
2444
|
message: `Saved to ${savePath}`,
|
|
2453
2445
|
path: savePath,
|
|
2454
2446
|
backup_created: backupPath ? true : false,
|
|
@@ -2457,7 +2449,7 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
2457
2449
|
});
|
|
2458
2450
|
}
|
|
2459
2451
|
catch (saveErr) {
|
|
2460
|
-
return error(`Save failed; original document preserved: ${saveErr}`);
|
|
2452
|
+
return (0, ToolResult_1.error)(`Save failed; original document preserved: ${saveErr}`);
|
|
2461
2453
|
}
|
|
2462
2454
|
finally {
|
|
2463
2455
|
fs.rmSync(tempDirectory, { recursive: true, force: true });
|
|
@@ -2471,33 +2463,33 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
2471
2463
|
format: d.format,
|
|
2472
2464
|
isDirty: d.isDirty,
|
|
2473
2465
|
}));
|
|
2474
|
-
return success({ documents: docs });
|
|
2466
|
+
return (0, ToolResult_1.success)({ documents: docs });
|
|
2475
2467
|
}
|
|
2476
2468
|
// === Document Info ===
|
|
2477
2469
|
case 'get_document_text': {
|
|
2478
2470
|
const doc = getDoc(args?.doc_id);
|
|
2479
2471
|
if (!doc)
|
|
2480
|
-
return error('Document not found');
|
|
2481
|
-
return success({ text: doc.getAllText() });
|
|
2472
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2473
|
+
return (0, ToolResult_1.success)({ text: doc.getAllText() });
|
|
2482
2474
|
}
|
|
2483
2475
|
case 'get_document_structure': {
|
|
2484
2476
|
const doc = getDoc(args?.doc_id);
|
|
2485
2477
|
if (!doc)
|
|
2486
|
-
return error('Document not found');
|
|
2487
|
-
return success(doc.getStructure());
|
|
2478
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2479
|
+
return (0, ToolResult_1.success)(doc.getStructure());
|
|
2488
2480
|
}
|
|
2489
2481
|
case 'get_document_metadata': {
|
|
2490
2482
|
const doc = getDoc(args?.doc_id);
|
|
2491
2483
|
if (!doc)
|
|
2492
|
-
return error('Document not found');
|
|
2493
|
-
return success({ metadata: doc.getMetadata() });
|
|
2484
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2485
|
+
return (0, ToolResult_1.success)({ metadata: doc.getMetadata() });
|
|
2494
2486
|
}
|
|
2495
2487
|
case 'set_document_metadata': {
|
|
2496
2488
|
const doc = getDoc(args?.doc_id);
|
|
2497
2489
|
if (!doc)
|
|
2498
|
-
return error('Document not found');
|
|
2490
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2499
2491
|
if (doc.format === 'hwp')
|
|
2500
|
-
return error('HWP files are read-only');
|
|
2492
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
2501
2493
|
const metadata = {};
|
|
2502
2494
|
if (args?.title)
|
|
2503
2495
|
metadata.title = args.title;
|
|
@@ -2508,36 +2500,36 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
2508
2500
|
if (args?.description)
|
|
2509
2501
|
metadata.description = args.description;
|
|
2510
2502
|
doc.setMetadata(metadata);
|
|
2511
|
-
return success({ metadata: doc.getMetadata() });
|
|
2503
|
+
return (0, ToolResult_1.success)({ metadata: doc.getMetadata() });
|
|
2512
2504
|
}
|
|
2513
2505
|
// === Paragraph Operations ===
|
|
2514
2506
|
case 'get_paragraphs': {
|
|
2515
2507
|
const doc = getDoc(args?.doc_id);
|
|
2516
2508
|
if (!doc)
|
|
2517
|
-
return error('Document not found');
|
|
2509
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2518
2510
|
const sectionIndex = args?.section_index;
|
|
2519
2511
|
const paragraphs = doc.getParagraphs(sectionIndex);
|
|
2520
|
-
return success({ paragraphs });
|
|
2512
|
+
return (0, ToolResult_1.success)({ paragraphs });
|
|
2521
2513
|
}
|
|
2522
2514
|
case 'get_paragraph': {
|
|
2523
2515
|
const doc = getDoc(args?.doc_id);
|
|
2524
2516
|
if (!doc)
|
|
2525
|
-
return error('Document not found');
|
|
2517
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2526
2518
|
const result = doc.getParagraph(args?.section_index, args?.paragraph_index);
|
|
2527
2519
|
if (!result)
|
|
2528
|
-
return error('Paragraph not found');
|
|
2529
|
-
return success(result);
|
|
2520
|
+
return (0, ToolResult_1.error)('Paragraph not found');
|
|
2521
|
+
return (0, ToolResult_1.success)(result);
|
|
2530
2522
|
}
|
|
2531
2523
|
case 'insert_paragraph': {
|
|
2532
2524
|
const doc = getDoc(args?.doc_id);
|
|
2533
2525
|
if (!doc)
|
|
2534
|
-
return error('Document not found');
|
|
2526
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2535
2527
|
if (doc.format === 'hwp')
|
|
2536
|
-
return error('HWP files are read-only');
|
|
2528
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
2537
2529
|
const sectionIndex = args?.section_index;
|
|
2538
2530
|
const index = doc.insertParagraph(sectionIndex, args?.after_index, args?.text);
|
|
2539
2531
|
if (index === -1)
|
|
2540
|
-
return error('Failed to insert paragraph');
|
|
2532
|
+
return (0, ToolResult_1.error)('Failed to insert paragraph');
|
|
2541
2533
|
// Auto hanging indent (default: true)
|
|
2542
2534
|
const autoHangingIndent = args?.auto_hanging_indent !== false;
|
|
2543
2535
|
let indentPt = 0;
|
|
@@ -2546,68 +2538,68 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
2546
2538
|
indentPt = await doc.setAutoHangingIndentAsync(sectionIndex, index, 10);
|
|
2547
2539
|
}
|
|
2548
2540
|
if (indentPt > 0) {
|
|
2549
|
-
return success({ message: `Paragraph inserted with hanging indent: ${indentPt.toFixed(2)}pt`, index, indent_pt: indentPt });
|
|
2541
|
+
return (0, ToolResult_1.success)({ message: `Paragraph inserted with hanging indent: ${indentPt.toFixed(2)}pt`, index, indent_pt: indentPt });
|
|
2550
2542
|
}
|
|
2551
|
-
return success({ message: 'Paragraph inserted', index });
|
|
2543
|
+
return (0, ToolResult_1.success)({ message: 'Paragraph inserted', index });
|
|
2552
2544
|
}
|
|
2553
2545
|
case 'delete_paragraph': {
|
|
2554
2546
|
const doc = getDoc(args?.doc_id);
|
|
2555
2547
|
if (!doc)
|
|
2556
|
-
return error('Document not found');
|
|
2548
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2557
2549
|
if (doc.format === 'hwp')
|
|
2558
|
-
return error('HWP files are read-only');
|
|
2550
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
2559
2551
|
if (doc.deleteParagraph(args?.section_index, args?.paragraph_index)) {
|
|
2560
|
-
return success({ message: 'Paragraph deleted' });
|
|
2552
|
+
return (0, ToolResult_1.success)({ message: 'Paragraph deleted' });
|
|
2561
2553
|
}
|
|
2562
|
-
return error('Failed to delete paragraph');
|
|
2554
|
+
return (0, ToolResult_1.error)('Failed to delete paragraph');
|
|
2563
2555
|
}
|
|
2564
2556
|
case 'update_paragraph_text': {
|
|
2565
2557
|
const doc = getDoc(args?.doc_id);
|
|
2566
2558
|
if (!doc)
|
|
2567
|
-
return error('Document not found');
|
|
2559
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2568
2560
|
if (doc.format === 'hwp')
|
|
2569
|
-
return error('HWP files are read-only');
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
//
|
|
2574
|
-
|
|
2575
|
-
|
|
2576
|
-
|
|
2577
|
-
|
|
2578
|
-
|
|
2579
|
-
|
|
2580
|
-
|
|
2581
|
-
return success({ message: 'Paragraph updated' });
|
|
2561
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
2562
|
+
// Always replace through updateParagraphText. Replacing run 0 means
|
|
2563
|
+
// "replace the whole paragraph": the text goes into the first run and
|
|
2564
|
+
// the other runs are emptied, so it takes the first run's character
|
|
2565
|
+
// shape. This handler used to send any multi-run paragraph to
|
|
2566
|
+
// updateParagraphTextPreserveStyles, which spreads the new text across
|
|
2567
|
+
// the old runs by length — a paragraph with a plain run and a bold run,
|
|
2568
|
+
// replaced wholesale, came out bold from the middle on (reported
|
|
2569
|
+
// 2026-09-24, and still true in 0.3.4 because the fix only reached
|
|
2570
|
+
// updateParagraphText). Keeping each run's style is what
|
|
2571
|
+
// update_paragraph_text_preserve_styles is for.
|
|
2572
|
+
doc.updateParagraphText(args?.section_index, args?.paragraph_index, args?.run_index ?? 0, args?.text);
|
|
2573
|
+
return (0, ToolResult_1.success)({ message: 'Paragraph updated' });
|
|
2582
2574
|
}
|
|
2583
2575
|
case 'update_paragraph_text_preserve_styles': {
|
|
2584
2576
|
const doc = getDoc(args?.doc_id);
|
|
2585
2577
|
if (!doc)
|
|
2586
|
-
return error('Document not found');
|
|
2578
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2587
2579
|
if (doc.format === 'hwp')
|
|
2588
|
-
return error('HWP files are read-only');
|
|
2580
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
2589
2581
|
const result = doc.updateParagraphTextPreserveStyles(args?.section_index, args?.paragraph_index, args?.text);
|
|
2590
2582
|
if (result) {
|
|
2591
|
-
return success({ message: 'Paragraph text updated with preserved styles' });
|
|
2583
|
+
return (0, ToolResult_1.success)({ message: 'Paragraph text updated with preserved styles' });
|
|
2592
2584
|
}
|
|
2593
|
-
return error('Failed to update paragraph (not found or no runs)');
|
|
2585
|
+
return (0, ToolResult_1.error)('Failed to update paragraph (not found or no runs)');
|
|
2594
2586
|
}
|
|
2595
2587
|
case 'append_text_to_paragraph': {
|
|
2596
2588
|
const doc = getDoc(args?.doc_id);
|
|
2597
2589
|
if (!doc)
|
|
2598
|
-
return error('Document not found');
|
|
2590
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2599
2591
|
if (doc.format === 'hwp')
|
|
2600
|
-
return error('HWP files are read-only');
|
|
2592
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
2601
2593
|
doc.appendTextToParagraph(args?.section_index, args?.paragraph_index, args?.text);
|
|
2602
|
-
return success({ message: 'Text appended' });
|
|
2594
|
+
return (0, ToolResult_1.success)({ message: 'Text appended' });
|
|
2603
2595
|
}
|
|
2604
2596
|
// === Character Styling ===
|
|
2605
2597
|
case 'set_text_style': {
|
|
2606
2598
|
const doc = getDoc(args?.doc_id);
|
|
2607
2599
|
if (!doc)
|
|
2608
|
-
return error('Document not found');
|
|
2600
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2609
2601
|
if (doc.format === 'hwp')
|
|
2610
|
-
return error('HWP files are read-only');
|
|
2602
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
2611
2603
|
const style = {};
|
|
2612
2604
|
if (args?.bold !== undefined)
|
|
2613
2605
|
style.bold = args.bold;
|
|
@@ -2626,22 +2618,22 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
2626
2618
|
if (args?.background_color)
|
|
2627
2619
|
style.backgroundColor = args.background_color;
|
|
2628
2620
|
doc.applyCharacterStyle(args?.section_index, args?.paragraph_index, args?.run_index ?? 0, style);
|
|
2629
|
-
return success({ message: 'Text style applied' });
|
|
2621
|
+
return (0, ToolResult_1.success)({ message: 'Text style applied' });
|
|
2630
2622
|
}
|
|
2631
2623
|
case 'get_text_style': {
|
|
2632
2624
|
const doc = getDoc(args?.doc_id);
|
|
2633
2625
|
if (!doc)
|
|
2634
|
-
return error('Document not found');
|
|
2626
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2635
2627
|
const style = doc.getCharacterStyle(args?.section_index, args?.paragraph_index, args?.run_index);
|
|
2636
|
-
return success({ style });
|
|
2628
|
+
return (0, ToolResult_1.success)({ style });
|
|
2637
2629
|
}
|
|
2638
2630
|
// === Paragraph Styling ===
|
|
2639
2631
|
case 'set_paragraph_style': {
|
|
2640
2632
|
const doc = getDoc(args?.doc_id);
|
|
2641
2633
|
if (!doc)
|
|
2642
|
-
return error('Document not found');
|
|
2634
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2643
2635
|
if (doc.format === 'hwp')
|
|
2644
|
-
return error('HWP files are read-only');
|
|
2636
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
2645
2637
|
const style = {};
|
|
2646
2638
|
if (args?.align)
|
|
2647
2639
|
style.align = args.align;
|
|
@@ -2658,85 +2650,85 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
2658
2650
|
if (args?.first_line_indent)
|
|
2659
2651
|
style.firstLineIndent = args.first_line_indent;
|
|
2660
2652
|
doc.applyParagraphStyle(args?.section_index, args?.paragraph_index, style);
|
|
2661
|
-
return success({ message: 'Paragraph style applied' });
|
|
2653
|
+
return (0, ToolResult_1.success)({ message: 'Paragraph style applied' });
|
|
2662
2654
|
}
|
|
2663
2655
|
case 'get_paragraph_style': {
|
|
2664
2656
|
const doc = getDoc(args?.doc_id);
|
|
2665
2657
|
if (!doc)
|
|
2666
|
-
return error('Document not found');
|
|
2658
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2667
2659
|
const style = doc.getParagraphStyle(args?.section_index, args?.paragraph_index);
|
|
2668
|
-
return success({ style });
|
|
2660
|
+
return (0, ToolResult_1.success)({ style });
|
|
2669
2661
|
}
|
|
2670
2662
|
// === Hanging Indent (내어쓰기) ===
|
|
2671
2663
|
case 'set_hanging_indent': {
|
|
2672
2664
|
const doc = getDoc(args?.doc_id);
|
|
2673
2665
|
if (!doc)
|
|
2674
|
-
return error('Document not found');
|
|
2666
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2675
2667
|
if (doc.format === 'hwp')
|
|
2676
|
-
return error('HWP files are read-only');
|
|
2668
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
2677
2669
|
const result = doc.setHangingIndent(args?.section_index, args?.paragraph_index, args?.indent_pt);
|
|
2678
2670
|
if (!result)
|
|
2679
|
-
return error('Failed to set hanging indent. Check section/paragraph indices and indent value (must be positive).');
|
|
2680
|
-
return success({ message: `Hanging indent set to ${args?.indent_pt}pt` });
|
|
2671
|
+
return (0, ToolResult_1.error)('Failed to set hanging indent. Check section/paragraph indices and indent value (must be positive).');
|
|
2672
|
+
return (0, ToolResult_1.success)({ message: `Hanging indent set to ${args?.indent_pt}pt` });
|
|
2681
2673
|
}
|
|
2682
2674
|
case 'get_hanging_indent': {
|
|
2683
2675
|
const doc = getDoc(args?.doc_id);
|
|
2684
2676
|
if (!doc)
|
|
2685
|
-
return error('Document not found');
|
|
2677
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2686
2678
|
const indent = doc.getHangingIndent(args?.section_index, args?.paragraph_index);
|
|
2687
2679
|
if (indent === null)
|
|
2688
|
-
return error('Invalid section or paragraph index');
|
|
2689
|
-
return success({ hanging_indent_pt: indent });
|
|
2680
|
+
return (0, ToolResult_1.error)('Invalid section or paragraph index');
|
|
2681
|
+
return (0, ToolResult_1.success)({ hanging_indent_pt: indent });
|
|
2690
2682
|
}
|
|
2691
2683
|
case 'remove_hanging_indent': {
|
|
2692
2684
|
const doc = getDoc(args?.doc_id);
|
|
2693
2685
|
if (!doc)
|
|
2694
|
-
return error('Document not found');
|
|
2686
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2695
2687
|
if (doc.format === 'hwp')
|
|
2696
|
-
return error('HWP files are read-only');
|
|
2688
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
2697
2689
|
const result = doc.removeHangingIndent(args?.section_index, args?.paragraph_index);
|
|
2698
2690
|
if (!result)
|
|
2699
|
-
return error('Failed to remove hanging indent. Check section/paragraph indices.');
|
|
2700
|
-
return success({ message: 'Hanging indent removed' });
|
|
2691
|
+
return (0, ToolResult_1.error)('Failed to remove hanging indent. Check section/paragraph indices.');
|
|
2692
|
+
return (0, ToolResult_1.success)({ message: 'Hanging indent removed' });
|
|
2701
2693
|
}
|
|
2702
2694
|
// === Table Cell Hanging Indent (테이블 셀 내어쓰기) ===
|
|
2703
2695
|
case 'set_table_cell_hanging_indent': {
|
|
2704
2696
|
const doc = getDoc(args?.doc_id);
|
|
2705
2697
|
if (!doc)
|
|
2706
|
-
return error('Document not found');
|
|
2698
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2707
2699
|
if (doc.format === 'hwp')
|
|
2708
|
-
return error('HWP files are read-only');
|
|
2700
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
2709
2701
|
const result = doc.setTableCellHangingIndent(args?.section_index, args?.table_index, args?.row, args?.col, args?.paragraph_index, args?.indent_pt);
|
|
2710
2702
|
if (!result)
|
|
2711
|
-
return error('Failed to set hanging indent. Check indices and indent value (must be positive).');
|
|
2712
|
-
return success({ message: `Table cell hanging indent set to ${args?.indent_pt}pt` });
|
|
2703
|
+
return (0, ToolResult_1.error)('Failed to set hanging indent. Check indices and indent value (must be positive).');
|
|
2704
|
+
return (0, ToolResult_1.success)({ message: `Table cell hanging indent set to ${args?.indent_pt}pt` });
|
|
2713
2705
|
}
|
|
2714
2706
|
case 'get_table_cell_hanging_indent': {
|
|
2715
2707
|
const doc = getDoc(args?.doc_id);
|
|
2716
2708
|
if (!doc)
|
|
2717
|
-
return error('Document not found');
|
|
2709
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2718
2710
|
const indent = doc.getTableCellHangingIndent(args?.section_index, args?.table_index, args?.row, args?.col, args?.paragraph_index);
|
|
2719
2711
|
if (indent === null)
|
|
2720
|
-
return error('Invalid indices (section, table, row, col, or paragraph)');
|
|
2721
|
-
return success({ hanging_indent_pt: indent });
|
|
2712
|
+
return (0, ToolResult_1.error)('Invalid indices (section, table, row, col, or paragraph)');
|
|
2713
|
+
return (0, ToolResult_1.success)({ hanging_indent_pt: indent });
|
|
2722
2714
|
}
|
|
2723
2715
|
case 'remove_table_cell_hanging_indent': {
|
|
2724
2716
|
const doc = getDoc(args?.doc_id);
|
|
2725
2717
|
if (!doc)
|
|
2726
|
-
return error('Document not found');
|
|
2718
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2727
2719
|
if (doc.format === 'hwp')
|
|
2728
|
-
return error('HWP files are read-only');
|
|
2720
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
2729
2721
|
const result = doc.removeTableCellHangingIndent(args?.section_index, args?.table_index, args?.row, args?.col, args?.paragraph_index);
|
|
2730
2722
|
if (!result)
|
|
2731
|
-
return error('Failed to remove hanging indent. Check indices.');
|
|
2732
|
-
return success({ message: 'Table cell hanging indent removed' });
|
|
2723
|
+
return (0, ToolResult_1.error)('Failed to remove hanging indent. Check indices.');
|
|
2724
|
+
return (0, ToolResult_1.success)({ message: 'Table cell hanging indent removed' });
|
|
2733
2725
|
}
|
|
2734
2726
|
case 'set_auto_hanging_indent': {
|
|
2735
2727
|
const doc = getDoc(args?.doc_id);
|
|
2736
2728
|
if (!doc)
|
|
2737
|
-
return error('Document not found');
|
|
2729
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2738
2730
|
if (doc.format === 'hwp')
|
|
2739
|
-
return error('HWP files are read-only');
|
|
2731
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
2740
2732
|
// Use async version to read actual font size from document
|
|
2741
2733
|
const fontSizeArg = args?.font_size;
|
|
2742
2734
|
const indentPt = fontSizeArg !== undefined
|
|
@@ -2744,16 +2736,16 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
2744
2736
|
: await doc.setAutoHangingIndentAsync(args?.section_index, args?.paragraph_index, 10 // fallback font size
|
|
2745
2737
|
);
|
|
2746
2738
|
if (indentPt === 0) {
|
|
2747
|
-
return success({ message: 'No marker detected in paragraph text. No hanging indent applied.', indent_pt: 0 });
|
|
2739
|
+
return (0, ToolResult_1.success)({ message: 'No marker detected in paragraph text. No hanging indent applied.', indent_pt: 0 });
|
|
2748
2740
|
}
|
|
2749
|
-
return success({ message: `Auto hanging indent applied: ${indentPt.toFixed(2)}pt`, indent_pt: indentPt });
|
|
2741
|
+
return (0, ToolResult_1.success)({ message: `Auto hanging indent applied: ${indentPt.toFixed(2)}pt`, indent_pt: indentPt });
|
|
2750
2742
|
}
|
|
2751
2743
|
case 'set_table_cell_auto_hanging_indent': {
|
|
2752
2744
|
const doc = getDoc(args?.doc_id);
|
|
2753
2745
|
if (!doc)
|
|
2754
|
-
return error('Document not found');
|
|
2746
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2755
2747
|
if (doc.format === 'hwp')
|
|
2756
|
-
return error('HWP files are read-only');
|
|
2748
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
2757
2749
|
// Use async version to read actual font size from document
|
|
2758
2750
|
const fontSizeArg = args?.font_size;
|
|
2759
2751
|
const indentPt = fontSizeArg !== undefined
|
|
@@ -2761,21 +2753,21 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
2761
2753
|
: await doc.setTableCellAutoHangingIndentAsync(args?.section_index, args?.table_index, args?.row, args?.col, args?.paragraph_index, 10 // fallback font size
|
|
2762
2754
|
);
|
|
2763
2755
|
if (indentPt === 0) {
|
|
2764
|
-
return success({ message: 'No marker detected in cell text. No hanging indent applied.', indent_pt: 0 });
|
|
2756
|
+
return (0, ToolResult_1.success)({ message: 'No marker detected in cell text. No hanging indent applied.', indent_pt: 0 });
|
|
2765
2757
|
}
|
|
2766
|
-
return success({ message: `Auto hanging indent applied to cell: ${indentPt.toFixed(2)}pt`, indent_pt: indentPt });
|
|
2758
|
+
return (0, ToolResult_1.success)({ message: `Auto hanging indent applied to cell: ${indentPt.toFixed(2)}pt`, indent_pt: indentPt });
|
|
2767
2759
|
}
|
|
2768
2760
|
// === Search & Replace ===
|
|
2769
2761
|
case 'search_text': {
|
|
2770
2762
|
const doc = getDoc(args?.doc_id);
|
|
2771
2763
|
if (!doc)
|
|
2772
|
-
return error('Document not found');
|
|
2764
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2773
2765
|
const results = doc.searchText(args?.query, {
|
|
2774
2766
|
caseSensitive: args?.case_sensitive,
|
|
2775
2767
|
regex: args?.regex,
|
|
2776
2768
|
includeTables: args?.include_tables !== false, // default true
|
|
2777
2769
|
});
|
|
2778
|
-
return success({
|
|
2770
|
+
return (0, ToolResult_1.success)({
|
|
2779
2771
|
query: args?.query,
|
|
2780
2772
|
total_matches: results.reduce((sum, r) => sum + r.count, 0),
|
|
2781
2773
|
locations: results,
|
|
@@ -2784,47 +2776,47 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
2784
2776
|
case 'replace_text': {
|
|
2785
2777
|
const doc = getDoc(args?.doc_id);
|
|
2786
2778
|
if (!doc)
|
|
2787
|
-
return error('Document not found');
|
|
2779
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2788
2780
|
if (doc.format === 'hwp')
|
|
2789
|
-
return error('HWP files are read-only');
|
|
2781
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
2790
2782
|
const count = doc.replaceText(args?.old_text, args?.new_text, {
|
|
2791
2783
|
caseSensitive: args?.case_sensitive,
|
|
2792
2784
|
regex: args?.regex,
|
|
2793
2785
|
replaceAll: args?.replace_all ?? true,
|
|
2794
2786
|
});
|
|
2795
|
-
return success({ message: `Replaced ${count} occurrence(s)`, count });
|
|
2787
|
+
return (0, ToolResult_1.success)({ message: `Replaced ${count} occurrence(s)`, count });
|
|
2796
2788
|
}
|
|
2797
2789
|
case 'batch_replace': {
|
|
2798
2790
|
const doc = getDoc(args?.doc_id);
|
|
2799
2791
|
if (!doc)
|
|
2800
|
-
return error('Document not found');
|
|
2792
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2801
2793
|
if (doc.format === 'hwp')
|
|
2802
|
-
return error('HWP files are read-only');
|
|
2794
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
2803
2795
|
const replacements = args?.replacements;
|
|
2804
2796
|
if (!replacements)
|
|
2805
|
-
return error('replacements array is required');
|
|
2797
|
+
return (0, ToolResult_1.error)('replacements array is required');
|
|
2806
2798
|
const results = [];
|
|
2807
2799
|
for (const { old_text, new_text } of replacements) {
|
|
2808
2800
|
const count = doc.replaceText(old_text, new_text);
|
|
2809
2801
|
results.push({ old_text, new_text, count });
|
|
2810
2802
|
}
|
|
2811
|
-
return success({ results });
|
|
2803
|
+
return (0, ToolResult_1.success)({ results });
|
|
2812
2804
|
}
|
|
2813
2805
|
case 'replace_text_in_cell': {
|
|
2814
2806
|
const doc = getDoc(args?.doc_id);
|
|
2815
2807
|
if (!doc)
|
|
2816
|
-
return error('Document not found');
|
|
2808
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2817
2809
|
if (doc.format === 'hwp')
|
|
2818
|
-
return error('HWP files are read-only');
|
|
2810
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
2819
2811
|
const result = doc.replaceTextInCell(args?.section_index, args?.table_index, args?.row, args?.col, args?.old_text, args?.new_text, {
|
|
2820
2812
|
caseSensitive: args?.case_sensitive,
|
|
2821
2813
|
regex: args?.regex,
|
|
2822
2814
|
replaceAll: args?.replace_all ?? true,
|
|
2823
2815
|
});
|
|
2824
2816
|
if (!result.success) {
|
|
2825
|
-
return error(result.error || 'Replace failed');
|
|
2817
|
+
return (0, ToolResult_1.error)(result.error || 'Replace failed');
|
|
2826
2818
|
}
|
|
2827
|
-
return success({
|
|
2819
|
+
return (0, ToolResult_1.success)({
|
|
2828
2820
|
message: `Replaced ${result.count} occurrence(s) in cell [${args?.row}, ${args?.col}]`,
|
|
2829
2821
|
count: result.count,
|
|
2830
2822
|
});
|
|
@@ -2833,105 +2825,105 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
2833
2825
|
case 'get_tables': {
|
|
2834
2826
|
const doc = getDoc(args?.doc_id);
|
|
2835
2827
|
if (!doc)
|
|
2836
|
-
return error('Document not found');
|
|
2837
|
-
return success({ tables: doc.getTables() });
|
|
2828
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2829
|
+
return (0, ToolResult_1.success)({ tables: doc.getTables() });
|
|
2838
2830
|
}
|
|
2839
2831
|
case 'get_table_map': {
|
|
2840
2832
|
const doc = getDoc(args?.doc_id);
|
|
2841
2833
|
if (!doc)
|
|
2842
|
-
return error('Document not found');
|
|
2843
|
-
return success({ table_map: doc.getTableMap() });
|
|
2834
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2835
|
+
return (0, ToolResult_1.success)({ table_map: doc.getTableMap() });
|
|
2844
2836
|
}
|
|
2845
2837
|
case 'find_empty_tables': {
|
|
2846
2838
|
const doc = getDoc(args?.doc_id);
|
|
2847
2839
|
if (!doc)
|
|
2848
|
-
return error('Document not found');
|
|
2849
|
-
return success({ empty_tables: doc.findEmptyTables() });
|
|
2840
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2841
|
+
return (0, ToolResult_1.success)({ empty_tables: doc.findEmptyTables() });
|
|
2850
2842
|
}
|
|
2851
2843
|
case 'get_tables_by_section': {
|
|
2852
2844
|
const doc = getDoc(args?.doc_id);
|
|
2853
2845
|
if (!doc)
|
|
2854
|
-
return error('Document not found');
|
|
2846
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2855
2847
|
const sectionIndex = args?.section_index;
|
|
2856
2848
|
if (typeof sectionIndex !== 'number')
|
|
2857
|
-
return error('section_index is required');
|
|
2858
|
-
return success({ tables: doc.getTablesBySection(sectionIndex) });
|
|
2849
|
+
return (0, ToolResult_1.error)('section_index is required');
|
|
2850
|
+
return (0, ToolResult_1.success)({ tables: doc.getTablesBySection(sectionIndex) });
|
|
2859
2851
|
}
|
|
2860
2852
|
case 'find_table_by_header': {
|
|
2861
2853
|
const doc = getDoc(args?.doc_id);
|
|
2862
2854
|
if (!doc)
|
|
2863
|
-
return error('Document not found');
|
|
2855
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2864
2856
|
const searchText = args?.search_text;
|
|
2865
2857
|
if (!searchText)
|
|
2866
|
-
return error('search_text is required');
|
|
2867
|
-
return success({ tables: doc.findTableByHeader(searchText) });
|
|
2858
|
+
return (0, ToolResult_1.error)('search_text is required');
|
|
2859
|
+
return (0, ToolResult_1.success)({ tables: doc.findTableByHeader(searchText) });
|
|
2868
2860
|
}
|
|
2869
2861
|
case 'get_tables_summary': {
|
|
2870
2862
|
const doc = getDoc(args?.doc_id);
|
|
2871
2863
|
if (!doc)
|
|
2872
|
-
return error('Document not found');
|
|
2864
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2873
2865
|
const startIndex = args?.start_index;
|
|
2874
2866
|
const endIndex = args?.end_index;
|
|
2875
|
-
return success({ tables: doc.getTablesSummary(startIndex, endIndex) });
|
|
2867
|
+
return (0, ToolResult_1.success)({ tables: doc.getTablesSummary(startIndex, endIndex) });
|
|
2876
2868
|
}
|
|
2877
2869
|
case 'get_document_outline': {
|
|
2878
2870
|
const doc = getDoc(args?.doc_id);
|
|
2879
2871
|
if (!doc)
|
|
2880
|
-
return error('Document not found');
|
|
2881
|
-
return success({ outline: doc.getDocumentOutline() });
|
|
2872
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2873
|
+
return (0, ToolResult_1.success)({ outline: doc.getDocumentOutline() });
|
|
2882
2874
|
}
|
|
2883
2875
|
// === Position/Index Helper Handlers ===
|
|
2884
2876
|
case 'get_element_index_for_table': {
|
|
2885
2877
|
const doc = getDoc(args?.doc_id);
|
|
2886
2878
|
if (!doc)
|
|
2887
|
-
return error('Document not found');
|
|
2879
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2888
2880
|
const tableIndex = args?.table_index;
|
|
2889
2881
|
if (typeof tableIndex !== 'number')
|
|
2890
|
-
return error('table_index is required');
|
|
2882
|
+
return (0, ToolResult_1.error)('table_index is required');
|
|
2891
2883
|
const result = doc.getElementIndexForTable(tableIndex);
|
|
2892
2884
|
if (!result)
|
|
2893
|
-
return error(`Table ${tableIndex} not found`);
|
|
2894
|
-
return success(result);
|
|
2885
|
+
return (0, ToolResult_1.error)(`Table ${tableIndex} not found`);
|
|
2886
|
+
return (0, ToolResult_1.success)(result);
|
|
2895
2887
|
}
|
|
2896
2888
|
case 'find_paragraph_by_text': {
|
|
2897
2889
|
const doc = getDoc(args?.doc_id);
|
|
2898
2890
|
if (!doc)
|
|
2899
|
-
return error('Document not found');
|
|
2891
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2900
2892
|
const searchText = args?.search_text;
|
|
2901
2893
|
if (!searchText)
|
|
2902
|
-
return error('search_text is required');
|
|
2894
|
+
return (0, ToolResult_1.error)('search_text is required');
|
|
2903
2895
|
const sectionIndex = args?.section_index;
|
|
2904
2896
|
const results = doc.findParagraphByText(searchText, sectionIndex);
|
|
2905
|
-
return success({ matches: results, count: results.length });
|
|
2897
|
+
return (0, ToolResult_1.success)({ matches: results, count: results.length });
|
|
2906
2898
|
}
|
|
2907
2899
|
case 'get_insert_context': {
|
|
2908
2900
|
const doc = getDoc(args?.doc_id);
|
|
2909
2901
|
if (!doc)
|
|
2910
|
-
return error('Document not found');
|
|
2902
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2911
2903
|
const sectionIdx = args?.section_index;
|
|
2912
2904
|
const elementIdx = args?.element_index;
|
|
2913
2905
|
if (typeof sectionIdx !== 'number')
|
|
2914
|
-
return error('section_index is required');
|
|
2906
|
+
return (0, ToolResult_1.error)('section_index is required');
|
|
2915
2907
|
if (typeof elementIdx !== 'number')
|
|
2916
|
-
return error('element_index is required');
|
|
2908
|
+
return (0, ToolResult_1.error)('element_index is required');
|
|
2917
2909
|
const contextRange = args?.context_range;
|
|
2918
2910
|
const result = doc.getInsertContext(sectionIdx, elementIdx, contextRange);
|
|
2919
2911
|
if (!result)
|
|
2920
|
-
return error('Invalid section or element index');
|
|
2921
|
-
return success(result);
|
|
2912
|
+
return (0, ToolResult_1.error)('Invalid section or element index');
|
|
2913
|
+
return (0, ToolResult_1.success)(result);
|
|
2922
2914
|
}
|
|
2923
2915
|
case 'find_insert_position_after_header': {
|
|
2924
2916
|
const doc = getDoc(args?.doc_id);
|
|
2925
2917
|
if (!doc)
|
|
2926
|
-
return error('Document not found');
|
|
2918
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2927
2919
|
const headerText = args?.header_text;
|
|
2928
2920
|
if (!headerText)
|
|
2929
|
-
return error('header_text is required');
|
|
2921
|
+
return (0, ToolResult_1.error)('header_text is required');
|
|
2930
2922
|
const searchIn = args?.search_in || 'all';
|
|
2931
2923
|
const result = doc.findInsertPositionAfterHeader(headerText, searchIn);
|
|
2932
2924
|
if (!result)
|
|
2933
|
-
return error(`Text "${headerText}" not found in ${searchIn === 'all' ? 'paragraphs or table cells' : searchIn}`);
|
|
2934
|
-
return success({
|
|
2925
|
+
return (0, ToolResult_1.error)(`Text "${headerText}" not found in ${searchIn === 'all' ? 'paragraphs or table cells' : searchIn}`);
|
|
2926
|
+
return (0, ToolResult_1.success)({
|
|
2935
2927
|
...result,
|
|
2936
2928
|
usage_hint: result.found_in === 'table_cell'
|
|
2937
2929
|
? `Found in table cell. Use section_index=${result.section_index} and after_index=${result.insert_after} to insert AFTER this table, or use insert_image_in_cell with table_index=${result.table_info?.table_index}, row=${result.table_info?.row}, col=${result.table_info?.col} to insert INSIDE this cell.`
|
|
@@ -2941,14 +2933,14 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
2941
2933
|
case 'find_insert_position_after_table': {
|
|
2942
2934
|
const doc = getDoc(args?.doc_id);
|
|
2943
2935
|
if (!doc)
|
|
2944
|
-
return error('Document not found');
|
|
2936
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2945
2937
|
const tableIndex = args?.table_index;
|
|
2946
2938
|
if (typeof tableIndex !== 'number')
|
|
2947
|
-
return error('table_index is required');
|
|
2939
|
+
return (0, ToolResult_1.error)('table_index is required');
|
|
2948
2940
|
const result = doc.findInsertPositionAfterTable(tableIndex);
|
|
2949
2941
|
if (!result)
|
|
2950
|
-
return error(`Table ${tableIndex} not found`);
|
|
2951
|
-
return success({
|
|
2942
|
+
return (0, ToolResult_1.error)(`Table ${tableIndex} not found`);
|
|
2943
|
+
return (0, ToolResult_1.success)({
|
|
2952
2944
|
...result,
|
|
2953
2945
|
usage_hint: `Use section_index=${result.section_index} and after_index=${result.insert_after} in insert_image/render_mermaid`,
|
|
2954
2946
|
});
|
|
@@ -2956,28 +2948,28 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
2956
2948
|
case 'get_table': {
|
|
2957
2949
|
const doc = getDoc(args?.doc_id);
|
|
2958
2950
|
if (!doc)
|
|
2959
|
-
return error('Document not found');
|
|
2951
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2960
2952
|
const table = doc.getTable(args?.section_index, args?.table_index);
|
|
2961
2953
|
if (!table)
|
|
2962
|
-
return error('Table not found');
|
|
2963
|
-
return success(table);
|
|
2954
|
+
return (0, ToolResult_1.error)('Table not found');
|
|
2955
|
+
return (0, ToolResult_1.success)(table);
|
|
2964
2956
|
}
|
|
2965
2957
|
case 'get_table_cell': {
|
|
2966
2958
|
const doc = getDoc(args?.doc_id);
|
|
2967
2959
|
if (!doc)
|
|
2968
|
-
return error('Document not found');
|
|
2960
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2969
2961
|
const cell = doc.getTableCell(args?.section_index, args?.table_index, args?.row, args?.col);
|
|
2970
2962
|
if (!cell)
|
|
2971
|
-
return error('Cell not found');
|
|
2972
|
-
return success(cell);
|
|
2963
|
+
return (0, ToolResult_1.error)('Cell not found');
|
|
2964
|
+
return (0, ToolResult_1.success)(cell);
|
|
2973
2965
|
}
|
|
2974
2966
|
case 'update_table_cell': {
|
|
2975
2967
|
const docId = args?.doc_id;
|
|
2976
2968
|
const doc = getDoc(docId);
|
|
2977
2969
|
if (!doc)
|
|
2978
|
-
return error('Document not found');
|
|
2970
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
2979
2971
|
if (doc.format === 'hwp')
|
|
2980
|
-
return error('HWP files are read-only');
|
|
2972
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
2981
2973
|
// Use document lock to prevent race conditions during parallel updates
|
|
2982
2974
|
return await withDocumentLock(docId, async () => {
|
|
2983
2975
|
const sectionIndex = args?.section_index;
|
|
@@ -2986,7 +2978,7 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
2986
2978
|
const col = args?.col;
|
|
2987
2979
|
const charShapeId = args?.char_shape_id;
|
|
2988
2980
|
if (!doc.updateTableCell(sectionIndex, tableIndex, row, col, args?.text, charShapeId)) {
|
|
2989
|
-
return error('Failed to update cell');
|
|
2981
|
+
return (0, ToolResult_1.error)('Failed to update cell');
|
|
2990
2982
|
}
|
|
2991
2983
|
// Auto hanging indent (default: true)
|
|
2992
2984
|
// Apply to ALL lines in the text, not just the first paragraph
|
|
@@ -3009,73 +3001,73 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
3009
3001
|
}
|
|
3010
3002
|
}
|
|
3011
3003
|
if (appliedIndents.length > 0) {
|
|
3012
|
-
return success({
|
|
3004
|
+
return (0, ToolResult_1.success)({
|
|
3013
3005
|
message: `Cell updated with hanging indent applied to ${appliedIndents.length} paragraph(s)`,
|
|
3014
3006
|
indent_pts: appliedIndents
|
|
3015
3007
|
});
|
|
3016
3008
|
}
|
|
3017
|
-
return success({ message: 'Cell updated' });
|
|
3009
|
+
return (0, ToolResult_1.success)({ message: 'Cell updated' });
|
|
3018
3010
|
});
|
|
3019
3011
|
}
|
|
3020
3012
|
case 'find_cell_by_label': {
|
|
3021
3013
|
const doc = getDoc(args?.doc_id);
|
|
3022
3014
|
if (!doc)
|
|
3023
|
-
return error('Document not found');
|
|
3015
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3024
3016
|
const results = doc.findCellByLabel(args?.label_text, args?.direction);
|
|
3025
|
-
return success({ matches: results, count: results.length });
|
|
3017
|
+
return (0, ToolResult_1.success)({ matches: results, count: results.length });
|
|
3026
3018
|
}
|
|
3027
3019
|
case 'fill_by_path': {
|
|
3028
3020
|
const docId = args?.doc_id;
|
|
3029
3021
|
const doc = getDoc(docId);
|
|
3030
3022
|
if (!doc)
|
|
3031
|
-
return error('Document not found');
|
|
3023
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3032
3024
|
if (doc.format === 'hwp')
|
|
3033
|
-
return error('HWP files are read-only');
|
|
3025
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3034
3026
|
// Use document lock to prevent race conditions
|
|
3035
3027
|
return await withDocumentLock(docId, async () => {
|
|
3036
3028
|
const result = doc.fillByPath(args?.mappings);
|
|
3037
|
-
return success(result);
|
|
3029
|
+
return (0, ToolResult_1.success)(result);
|
|
3038
3030
|
});
|
|
3039
3031
|
}
|
|
3040
3032
|
case 'get_cell_context': {
|
|
3041
3033
|
const doc = getDoc(args?.doc_id);
|
|
3042
3034
|
if (!doc)
|
|
3043
|
-
return error('Document not found');
|
|
3035
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3044
3036
|
const globalIdx = args?.table_index;
|
|
3045
3037
|
const location = doc.convertGlobalToLocalTableIndex(globalIdx);
|
|
3046
3038
|
if (!location) {
|
|
3047
|
-
return error(`Table with global index ${globalIdx} not found`);
|
|
3039
|
+
return (0, ToolResult_1.error)(`Table with global index ${globalIdx} not found`);
|
|
3048
3040
|
}
|
|
3049
3041
|
const context = doc.getCellContext(globalIdx, args?.row, args?.col, args?.depth);
|
|
3050
3042
|
if (!context) {
|
|
3051
|
-
return error('Failed to get cell context');
|
|
3043
|
+
return (0, ToolResult_1.error)('Failed to get cell context');
|
|
3052
3044
|
}
|
|
3053
|
-
return success(context);
|
|
3045
|
+
return (0, ToolResult_1.success)(context);
|
|
3054
3046
|
}
|
|
3055
3047
|
case 'batch_fill_table': {
|
|
3056
3048
|
const docId = args?.doc_id;
|
|
3057
3049
|
const doc = getDoc(docId);
|
|
3058
3050
|
if (!doc)
|
|
3059
|
-
return error('Document not found');
|
|
3051
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3060
3052
|
if (doc.format === 'hwp')
|
|
3061
|
-
return error('HWP files are read-only');
|
|
3053
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3062
3054
|
// Use document lock to prevent race conditions
|
|
3063
3055
|
return await withDocumentLock(docId, async () => {
|
|
3064
3056
|
const globalIdx = args?.table_index;
|
|
3065
3057
|
const location = doc.convertGlobalToLocalTableIndex(globalIdx);
|
|
3066
3058
|
if (!location) {
|
|
3067
|
-
return error(`Table with global index ${globalIdx} not found`);
|
|
3059
|
+
return (0, ToolResult_1.error)(`Table with global index ${globalIdx} not found`);
|
|
3068
3060
|
}
|
|
3069
3061
|
const result = doc.batchFillTable(globalIdx, args?.data, args?.start_row, args?.start_col);
|
|
3070
|
-
return success(result);
|
|
3062
|
+
return (0, ToolResult_1.success)(result);
|
|
3071
3063
|
});
|
|
3072
3064
|
}
|
|
3073
3065
|
case 'set_cell_properties': {
|
|
3074
3066
|
const doc = getDoc(args?.doc_id);
|
|
3075
3067
|
if (!doc)
|
|
3076
|
-
return error('Document not found');
|
|
3068
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3077
3069
|
if (doc.format === 'hwp')
|
|
3078
|
-
return error('HWP files are read-only');
|
|
3070
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3079
3071
|
const props = {};
|
|
3080
3072
|
if (args?.width)
|
|
3081
3073
|
props.width = args.width;
|
|
@@ -3086,70 +3078,70 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
3086
3078
|
if (args?.vertical_align)
|
|
3087
3079
|
props.verticalAlign = args.vertical_align;
|
|
3088
3080
|
if (doc.setCellProperties(args?.section_index, args?.table_index, args?.row, args?.col, props)) {
|
|
3089
|
-
return success({ message: 'Cell properties updated' });
|
|
3081
|
+
return (0, ToolResult_1.success)({ message: 'Cell properties updated' });
|
|
3090
3082
|
}
|
|
3091
|
-
return error('Failed to update cell properties');
|
|
3083
|
+
return (0, ToolResult_1.error)('Failed to update cell properties');
|
|
3092
3084
|
}
|
|
3093
3085
|
case 'merge_cells': {
|
|
3094
3086
|
const doc = getDoc(args?.doc_id);
|
|
3095
3087
|
if (!doc)
|
|
3096
|
-
return error('Document not found');
|
|
3088
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3097
3089
|
if (doc.format === 'hwp')
|
|
3098
|
-
return error('HWP files are read-only');
|
|
3090
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3099
3091
|
if (doc.mergeCells(args?.section_index, args?.table_index, args?.start_row, args?.start_col, args?.end_row, args?.end_col)) {
|
|
3100
3092
|
const colSpan = args?.end_col - args?.start_col + 1;
|
|
3101
3093
|
const rowSpan = args?.end_row - args?.start_row + 1;
|
|
3102
|
-
return success({
|
|
3094
|
+
return (0, ToolResult_1.success)({
|
|
3103
3095
|
message: `Cells merged successfully`,
|
|
3104
3096
|
colSpan,
|
|
3105
3097
|
rowSpan,
|
|
3106
3098
|
masterCell: { row: args?.start_row, col: args?.start_col }
|
|
3107
3099
|
});
|
|
3108
3100
|
}
|
|
3109
|
-
return error('Failed to merge cells. Check that the range is valid and cells are not already merged.');
|
|
3101
|
+
return (0, ToolResult_1.error)('Failed to merge cells. Check that the range is valid and cells are not already merged.');
|
|
3110
3102
|
}
|
|
3111
3103
|
case 'split_cell': {
|
|
3112
3104
|
const doc = getDoc(args?.doc_id);
|
|
3113
3105
|
if (!doc)
|
|
3114
|
-
return error('Document not found');
|
|
3106
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3115
3107
|
if (doc.format === 'hwp')
|
|
3116
|
-
return error('HWP files are read-only');
|
|
3108
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3117
3109
|
if (doc.splitCell(args?.section_index, args?.table_index, args?.row, args?.col)) {
|
|
3118
|
-
return success({
|
|
3110
|
+
return (0, ToolResult_1.success)({
|
|
3119
3111
|
message: `Cell split successfully`,
|
|
3120
3112
|
cell: { row: args?.row, col: args?.col }
|
|
3121
3113
|
});
|
|
3122
3114
|
}
|
|
3123
|
-
return error('Failed to split cell. Check that the cell is actually merged (colSpan > 1 or rowSpan > 1).');
|
|
3115
|
+
return (0, ToolResult_1.error)('Failed to split cell. Check that the cell is actually merged (colSpan > 1 or rowSpan > 1).');
|
|
3124
3116
|
}
|
|
3125
3117
|
case 'insert_table_row': {
|
|
3126
3118
|
const doc = getDoc(args?.doc_id);
|
|
3127
3119
|
if (!doc)
|
|
3128
|
-
return error('Document not found');
|
|
3120
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3129
3121
|
if (doc.format === 'hwp')
|
|
3130
|
-
return error('HWP files are read-only');
|
|
3122
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3131
3123
|
if (doc.insertTableRow(args?.section_index, args?.table_index, args?.after_row, args?.cell_texts)) {
|
|
3132
|
-
return success({ message: 'Row inserted' });
|
|
3124
|
+
return (0, ToolResult_1.success)({ message: 'Row inserted' });
|
|
3133
3125
|
}
|
|
3134
|
-
return error('Failed to insert row');
|
|
3126
|
+
return (0, ToolResult_1.error)('Failed to insert row');
|
|
3135
3127
|
}
|
|
3136
3128
|
case 'delete_table': {
|
|
3137
3129
|
const doc = getDoc(args?.doc_id);
|
|
3138
3130
|
if (!doc)
|
|
3139
|
-
return error('Document not found');
|
|
3131
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3140
3132
|
if (doc.format === 'hwp')
|
|
3141
|
-
return error('HWP files are read-only');
|
|
3133
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3142
3134
|
if (doc.deleteTable(args?.section_index, args?.table_index)) {
|
|
3143
|
-
return success({ message: 'Table deleted' });
|
|
3135
|
+
return (0, ToolResult_1.success)({ message: 'Table deleted' });
|
|
3144
3136
|
}
|
|
3145
|
-
return error('Failed to delete table');
|
|
3137
|
+
return (0, ToolResult_1.error)('Failed to delete table');
|
|
3146
3138
|
}
|
|
3147
3139
|
case 'delete_table_row': {
|
|
3148
3140
|
const doc = getDoc(args?.doc_id);
|
|
3149
3141
|
if (!doc)
|
|
3150
|
-
return error('Document not found');
|
|
3142
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3151
3143
|
if (doc.format === 'hwp')
|
|
3152
|
-
return error('HWP files are read-only');
|
|
3144
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3153
3145
|
const sectionIndex = args?.section_index;
|
|
3154
3146
|
const tableIndex = args?.table_index;
|
|
3155
3147
|
const allTables = doc.getTables();
|
|
@@ -3157,57 +3149,57 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
3157
3149
|
const wasOnlyRow = table && table.rows === 1;
|
|
3158
3150
|
if (doc.deleteTableRow(args?.section_index, args?.table_index, args?.row_index)) {
|
|
3159
3151
|
if (wasOnlyRow) {
|
|
3160
|
-
return success({ message: 'Table deleted (was only row)' });
|
|
3152
|
+
return (0, ToolResult_1.success)({ message: 'Table deleted (was only row)' });
|
|
3161
3153
|
}
|
|
3162
|
-
return success({ message: 'Row deleted' });
|
|
3154
|
+
return (0, ToolResult_1.success)({ message: 'Row deleted' });
|
|
3163
3155
|
}
|
|
3164
|
-
return error('Failed to delete row');
|
|
3156
|
+
return (0, ToolResult_1.error)('Failed to delete row');
|
|
3165
3157
|
}
|
|
3166
3158
|
case 'insert_table_column': {
|
|
3167
3159
|
const doc = getDoc(args?.doc_id);
|
|
3168
3160
|
if (!doc)
|
|
3169
|
-
return error('Document not found');
|
|
3161
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3170
3162
|
if (doc.format === 'hwp')
|
|
3171
|
-
return error('HWP files are read-only');
|
|
3163
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3172
3164
|
if (doc.insertTableColumn(args?.section_index, args?.table_index, args?.after_col)) {
|
|
3173
|
-
return success({ message: 'Column inserted' });
|
|
3165
|
+
return (0, ToolResult_1.success)({ message: 'Column inserted' });
|
|
3174
3166
|
}
|
|
3175
|
-
return error('Failed to insert column');
|
|
3167
|
+
return (0, ToolResult_1.error)('Failed to insert column');
|
|
3176
3168
|
}
|
|
3177
3169
|
case 'delete_table_column': {
|
|
3178
3170
|
const doc = getDoc(args?.doc_id);
|
|
3179
3171
|
if (!doc)
|
|
3180
|
-
return error('Document not found');
|
|
3172
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3181
3173
|
if (doc.format === 'hwp')
|
|
3182
|
-
return error('HWP files are read-only');
|
|
3174
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3183
3175
|
if (doc.deleteTableColumn(args?.section_index, args?.table_index, args?.col_index)) {
|
|
3184
|
-
return success({ message: 'Column deleted' });
|
|
3176
|
+
return (0, ToolResult_1.success)({ message: 'Column deleted' });
|
|
3185
3177
|
}
|
|
3186
|
-
return error('Failed to delete column');
|
|
3178
|
+
return (0, ToolResult_1.error)('Failed to delete column');
|
|
3187
3179
|
}
|
|
3188
3180
|
case 'get_table_as_csv': {
|
|
3189
3181
|
const doc = getDoc(args?.doc_id);
|
|
3190
3182
|
if (!doc)
|
|
3191
|
-
return error('Document not found');
|
|
3183
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3192
3184
|
const csv = doc.getTableAsCsv(args?.section_index, args?.table_index, args?.delimiter || ',');
|
|
3193
3185
|
if (!csv)
|
|
3194
|
-
return error('Table not found');
|
|
3195
|
-
return success({ csv });
|
|
3186
|
+
return (0, ToolResult_1.error)('Table not found');
|
|
3187
|
+
return (0, ToolResult_1.success)({ csv });
|
|
3196
3188
|
}
|
|
3197
3189
|
// === Page Settings ===
|
|
3198
3190
|
case 'get_page_settings': {
|
|
3199
3191
|
const doc = getDoc(args?.doc_id);
|
|
3200
3192
|
if (!doc)
|
|
3201
|
-
return error('Document not found');
|
|
3193
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3202
3194
|
const settings = doc.getPageSettings(args?.section_index || 0);
|
|
3203
|
-
return success({ settings });
|
|
3195
|
+
return (0, ToolResult_1.success)({ settings });
|
|
3204
3196
|
}
|
|
3205
3197
|
case 'set_page_settings': {
|
|
3206
3198
|
const doc = getDoc(args?.doc_id);
|
|
3207
3199
|
if (!doc)
|
|
3208
|
-
return error('Document not found');
|
|
3200
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3209
3201
|
if (doc.format === 'hwp')
|
|
3210
|
-
return error('HWP files are read-only');
|
|
3202
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3211
3203
|
const settings = {};
|
|
3212
3204
|
if (args?.width)
|
|
3213
3205
|
settings.width = args.width;
|
|
@@ -3224,85 +3216,85 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
3224
3216
|
if (args?.orientation)
|
|
3225
3217
|
settings.orientation = args.orientation;
|
|
3226
3218
|
if (doc.setPageSettings(args?.section_index || 0, settings)) {
|
|
3227
|
-
return success({ message: 'Page settings updated' });
|
|
3219
|
+
return (0, ToolResult_1.success)({ message: 'Page settings updated' });
|
|
3228
3220
|
}
|
|
3229
|
-
return error('Failed to update page settings');
|
|
3221
|
+
return (0, ToolResult_1.error)('Failed to update page settings');
|
|
3230
3222
|
}
|
|
3231
3223
|
// === Copy/Move ===
|
|
3232
3224
|
case 'copy_paragraph': {
|
|
3233
3225
|
const doc = getDoc(args?.doc_id);
|
|
3234
3226
|
if (!doc)
|
|
3235
|
-
return error('Document not found');
|
|
3227
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3236
3228
|
if (doc.format === 'hwp')
|
|
3237
|
-
return error('HWP files are read-only');
|
|
3229
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3238
3230
|
if (doc.copyParagraph(args?.source_section, args?.source_paragraph, args?.target_section, args?.target_after)) {
|
|
3239
|
-
return success({ message: 'Paragraph copied' });
|
|
3231
|
+
return (0, ToolResult_1.success)({ message: 'Paragraph copied' });
|
|
3240
3232
|
}
|
|
3241
|
-
return error('Failed to copy paragraph');
|
|
3233
|
+
return (0, ToolResult_1.error)('Failed to copy paragraph');
|
|
3242
3234
|
}
|
|
3243
3235
|
case 'move_paragraph': {
|
|
3244
3236
|
const doc = getDoc(args?.doc_id);
|
|
3245
3237
|
if (!doc)
|
|
3246
|
-
return error('Document not found');
|
|
3238
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3247
3239
|
if (doc.format === 'hwp')
|
|
3248
|
-
return error('HWP files are read-only');
|
|
3240
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3249
3241
|
if (doc.moveParagraph(args?.source_section, args?.source_paragraph, args?.target_section, args?.target_after)) {
|
|
3250
|
-
return success({ message: 'Paragraph moved' });
|
|
3242
|
+
return (0, ToolResult_1.success)({ message: 'Paragraph moved' });
|
|
3251
3243
|
}
|
|
3252
|
-
return error('Failed to move paragraph');
|
|
3244
|
+
return (0, ToolResult_1.error)('Failed to move paragraph');
|
|
3253
3245
|
}
|
|
3254
3246
|
case 'move_table': {
|
|
3255
3247
|
const doc = getDoc(args?.doc_id);
|
|
3256
3248
|
if (!doc)
|
|
3257
|
-
return error('Document not found');
|
|
3249
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3258
3250
|
if (doc.format === 'hwp')
|
|
3259
|
-
return error('HWP files are read-only');
|
|
3251
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3260
3252
|
const result = doc.moveTable(args?.section_index, args?.table_index, args?.target_section_index, args?.target_after_index);
|
|
3261
3253
|
if (result.success) {
|
|
3262
|
-
return success({ message: 'Table move scheduled. Changes will be applied on save.' });
|
|
3254
|
+
return (0, ToolResult_1.success)({ message: 'Table move scheduled. Changes will be applied on save.' });
|
|
3263
3255
|
}
|
|
3264
|
-
return error(result.error || 'Failed to move table');
|
|
3256
|
+
return (0, ToolResult_1.error)(result.error || 'Failed to move table');
|
|
3265
3257
|
}
|
|
3266
3258
|
case 'copy_table': {
|
|
3267
3259
|
const doc = getDoc(args?.doc_id);
|
|
3268
3260
|
if (!doc)
|
|
3269
|
-
return error('Document not found');
|
|
3261
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3270
3262
|
if (doc.format === 'hwp')
|
|
3271
|
-
return error('HWP files are read-only');
|
|
3263
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3272
3264
|
const result = doc.copyTable(args?.section_index, args?.table_index, args?.target_section_index, args?.target_after_index);
|
|
3273
3265
|
if (result.success) {
|
|
3274
|
-
return success({ message: 'Table copy scheduled. Changes will be applied on save.' });
|
|
3266
|
+
return (0, ToolResult_1.success)({ message: 'Table copy scheduled. Changes will be applied on save.' });
|
|
3275
3267
|
}
|
|
3276
|
-
return error(result.error || 'Failed to copy table');
|
|
3268
|
+
return (0, ToolResult_1.error)(result.error || 'Failed to copy table');
|
|
3277
3269
|
}
|
|
3278
3270
|
// === Statistics ===
|
|
3279
3271
|
case 'get_word_count': {
|
|
3280
3272
|
const doc = getDoc(args?.doc_id);
|
|
3281
3273
|
if (!doc)
|
|
3282
|
-
return error('Document not found');
|
|
3283
|
-
return success(doc.getWordCount());
|
|
3274
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3275
|
+
return (0, ToolResult_1.success)(doc.getWordCount());
|
|
3284
3276
|
}
|
|
3285
3277
|
// === Images ===
|
|
3286
3278
|
case 'get_images': {
|
|
3287
3279
|
const doc = getDoc(args?.doc_id);
|
|
3288
3280
|
if (!doc)
|
|
3289
|
-
return error('Document not found');
|
|
3290
|
-
return success({ images: doc.getImages() });
|
|
3281
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3282
|
+
return (0, ToolResult_1.success)({ images: doc.getImages() });
|
|
3291
3283
|
}
|
|
3292
3284
|
// === Export ===
|
|
3293
3285
|
case 'export_to_text': {
|
|
3294
3286
|
const doc = getDoc(args?.doc_id);
|
|
3295
3287
|
if (!doc)
|
|
3296
|
-
return error('Document not found');
|
|
3288
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3297
3289
|
const text = doc.getAllText();
|
|
3298
3290
|
const outputPath = args?.output_path;
|
|
3299
3291
|
fs.writeFileSync(outputPath, text, 'utf-8');
|
|
3300
|
-
return success({ message: `Exported to ${outputPath}`, characters: text.length });
|
|
3292
|
+
return (0, ToolResult_1.success)({ message: `Exported to ${outputPath}`, characters: text.length });
|
|
3301
3293
|
}
|
|
3302
3294
|
case 'export_to_html': {
|
|
3303
3295
|
const doc = getDoc(args?.doc_id);
|
|
3304
3296
|
if (!doc)
|
|
3305
|
-
return error('Document not found');
|
|
3297
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3306
3298
|
let html = '<!DOCTYPE html><html><head><meta charset="UTF-8">';
|
|
3307
3299
|
html += '<style>body{font-family:sans-serif;max-width:800px;margin:0 auto;padding:20px;}table{border-collapse:collapse;width:100%;}td,th{border:1px solid #ccc;padding:8px;}</style>';
|
|
3308
3300
|
html += '</head><body>';
|
|
@@ -3331,13 +3323,13 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
3331
3323
|
html += '</body></html>';
|
|
3332
3324
|
const outputPath = args?.output_path;
|
|
3333
3325
|
fs.writeFileSync(outputPath, html, 'utf-8');
|
|
3334
|
-
return success({ message: `Exported to ${outputPath}` });
|
|
3326
|
+
return (0, ToolResult_1.success)({ message: `Exported to ${outputPath}` });
|
|
3335
3327
|
}
|
|
3336
3328
|
// === Undo/Redo ===
|
|
3337
3329
|
case 'undo': {
|
|
3338
3330
|
const doc = getDoc(args?.doc_id);
|
|
3339
3331
|
if (!doc)
|
|
3340
|
-
return error('Document not found');
|
|
3332
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3341
3333
|
const count = args?.count || 1;
|
|
3342
3334
|
let undoneCount = 0;
|
|
3343
3335
|
for (let i = 0; i < count; i++) {
|
|
@@ -3349,19 +3341,19 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
3349
3341
|
}
|
|
3350
3342
|
}
|
|
3351
3343
|
if (undoneCount > 0) {
|
|
3352
|
-
return success({
|
|
3344
|
+
return (0, ToolResult_1.success)({
|
|
3353
3345
|
message: `Undo successful (${undoneCount}/${count})`,
|
|
3354
3346
|
undone_count: undoneCount,
|
|
3355
3347
|
canUndo: doc.canUndo(),
|
|
3356
3348
|
canRedo: doc.canRedo()
|
|
3357
3349
|
});
|
|
3358
3350
|
}
|
|
3359
|
-
return error('Nothing to undo');
|
|
3351
|
+
return (0, ToolResult_1.error)('Nothing to undo');
|
|
3360
3352
|
}
|
|
3361
3353
|
case 'redo': {
|
|
3362
3354
|
const doc = getDoc(args?.doc_id);
|
|
3363
3355
|
if (!doc)
|
|
3364
|
-
return error('Document not found');
|
|
3356
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3365
3357
|
const count = args?.count || 1;
|
|
3366
3358
|
let redoneCount = 0;
|
|
3367
3359
|
for (let i = 0; i < count; i++) {
|
|
@@ -3373,155 +3365,155 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
3373
3365
|
}
|
|
3374
3366
|
}
|
|
3375
3367
|
if (redoneCount > 0) {
|
|
3376
|
-
return success({
|
|
3368
|
+
return (0, ToolResult_1.success)({
|
|
3377
3369
|
message: `Redo successful (${redoneCount}/${count})`,
|
|
3378
3370
|
redone_count: redoneCount,
|
|
3379
3371
|
canUndo: doc.canUndo(),
|
|
3380
3372
|
canRedo: doc.canRedo()
|
|
3381
3373
|
});
|
|
3382
3374
|
}
|
|
3383
|
-
return error('Nothing to redo');
|
|
3375
|
+
return (0, ToolResult_1.error)('Nothing to redo');
|
|
3384
3376
|
}
|
|
3385
3377
|
// === Table Creation ===
|
|
3386
3378
|
case 'insert_table': {
|
|
3387
3379
|
const doc = getDoc(args?.doc_id);
|
|
3388
3380
|
if (!doc)
|
|
3389
|
-
return error('Document not found');
|
|
3381
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3390
3382
|
if (doc.format === 'hwp')
|
|
3391
|
-
return error('HWP files are read-only');
|
|
3383
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3392
3384
|
const result = doc.insertTable(args?.section_index, args?.after_index, args?.rows, args?.cols, { width: args?.width });
|
|
3393
3385
|
if (!result)
|
|
3394
|
-
return error('Failed to insert table');
|
|
3395
|
-
return success({ message: 'Table inserted', tableIndex: result.tableIndex });
|
|
3386
|
+
return (0, ToolResult_1.error)('Failed to insert table');
|
|
3387
|
+
return (0, ToolResult_1.success)({ message: 'Table inserted', tableIndex: result.tableIndex });
|
|
3396
3388
|
}
|
|
3397
3389
|
case 'insert_nested_table': {
|
|
3398
3390
|
const doc = getDoc(args?.doc_id);
|
|
3399
3391
|
if (!doc)
|
|
3400
|
-
return error('Document not found');
|
|
3392
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3401
3393
|
if (doc.format === 'hwp')
|
|
3402
|
-
return error('HWP files are read-only');
|
|
3394
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3403
3395
|
const result = doc.insertNestedTable(args?.section_index, args?.parent_table_index, args?.row, args?.col, args?.nested_rows, args?.nested_cols, { data: args?.data });
|
|
3404
3396
|
if (!result.success)
|
|
3405
|
-
return error(result.error || 'Failed to insert nested table');
|
|
3406
|
-
return success({ message: 'Nested table inserted successfully' });
|
|
3397
|
+
return (0, ToolResult_1.error)(result.error || 'Failed to insert nested table');
|
|
3398
|
+
return (0, ToolResult_1.success)({ message: 'Nested table inserted successfully' });
|
|
3407
3399
|
}
|
|
3408
3400
|
// === Header/Footer ===
|
|
3409
3401
|
case 'get_header': {
|
|
3410
3402
|
const doc = getDoc(args?.doc_id);
|
|
3411
3403
|
if (!doc)
|
|
3412
|
-
return error('Document not found');
|
|
3404
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3413
3405
|
const result = doc.getHeader(args?.section_index || 0);
|
|
3414
|
-
return success({ header: result });
|
|
3406
|
+
return (0, ToolResult_1.success)({ header: result });
|
|
3415
3407
|
}
|
|
3416
3408
|
case 'set_header': {
|
|
3417
3409
|
const doc = getDoc(args?.doc_id);
|
|
3418
3410
|
if (!doc)
|
|
3419
|
-
return error('Document not found');
|
|
3411
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3420
3412
|
if (doc.format === 'hwp')
|
|
3421
|
-
return error('HWP files are read-only');
|
|
3413
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3422
3414
|
if (doc.setHeader(args?.section_index || 0, args?.text)) {
|
|
3423
|
-
return success({ message: 'Header set successfully' });
|
|
3415
|
+
return (0, ToolResult_1.success)({ message: 'Header set successfully' });
|
|
3424
3416
|
}
|
|
3425
|
-
return error('Failed to set header');
|
|
3417
|
+
return (0, ToolResult_1.error)('Failed to set header');
|
|
3426
3418
|
}
|
|
3427
3419
|
case 'get_footer': {
|
|
3428
3420
|
const doc = getDoc(args?.doc_id);
|
|
3429
3421
|
if (!doc)
|
|
3430
|
-
return error('Document not found');
|
|
3422
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3431
3423
|
const result = doc.getFooter(args?.section_index || 0);
|
|
3432
|
-
return success({ footer: result });
|
|
3424
|
+
return (0, ToolResult_1.success)({ footer: result });
|
|
3433
3425
|
}
|
|
3434
3426
|
case 'set_footer': {
|
|
3435
3427
|
const doc = getDoc(args?.doc_id);
|
|
3436
3428
|
if (!doc)
|
|
3437
|
-
return error('Document not found');
|
|
3429
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3438
3430
|
if (doc.format === 'hwp')
|
|
3439
|
-
return error('HWP files are read-only');
|
|
3431
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3440
3432
|
if (doc.setFooter(args?.section_index || 0, args?.text)) {
|
|
3441
|
-
return success({ message: 'Footer set successfully' });
|
|
3433
|
+
return (0, ToolResult_1.success)({ message: 'Footer set successfully' });
|
|
3442
3434
|
}
|
|
3443
|
-
return error('Failed to set footer');
|
|
3435
|
+
return (0, ToolResult_1.error)('Failed to set footer');
|
|
3444
3436
|
}
|
|
3445
3437
|
// === Footnotes/Endnotes ===
|
|
3446
3438
|
case 'get_footnotes': {
|
|
3447
3439
|
const doc = getDoc(args?.doc_id);
|
|
3448
3440
|
if (!doc)
|
|
3449
|
-
return error('Document not found');
|
|
3450
|
-
return success({ footnotes: doc.getFootnotes() });
|
|
3441
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3442
|
+
return (0, ToolResult_1.success)({ footnotes: doc.getFootnotes() });
|
|
3451
3443
|
}
|
|
3452
3444
|
case 'insert_footnote': {
|
|
3453
3445
|
const doc = getDoc(args?.doc_id);
|
|
3454
3446
|
if (!doc)
|
|
3455
|
-
return error('Document not found');
|
|
3447
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3456
3448
|
if (doc.format === 'hwp')
|
|
3457
|
-
return error('HWP files are read-only');
|
|
3449
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3458
3450
|
const result = doc.insertFootnote(args?.section_index, args?.paragraph_index, args?.text);
|
|
3459
3451
|
if (!result)
|
|
3460
|
-
return error('Failed to insert footnote');
|
|
3461
|
-
return success({ message: 'Footnote inserted', id: result.id });
|
|
3452
|
+
return (0, ToolResult_1.error)('Failed to insert footnote');
|
|
3453
|
+
return (0, ToolResult_1.success)({ message: 'Footnote inserted', id: result.id });
|
|
3462
3454
|
}
|
|
3463
3455
|
case 'get_endnotes': {
|
|
3464
3456
|
const doc = getDoc(args?.doc_id);
|
|
3465
3457
|
if (!doc)
|
|
3466
|
-
return error('Document not found');
|
|
3467
|
-
return success({ endnotes: doc.getEndnotes() });
|
|
3458
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3459
|
+
return (0, ToolResult_1.success)({ endnotes: doc.getEndnotes() });
|
|
3468
3460
|
}
|
|
3469
3461
|
case 'insert_endnote': {
|
|
3470
3462
|
const doc = getDoc(args?.doc_id);
|
|
3471
3463
|
if (!doc)
|
|
3472
|
-
return error('Document not found');
|
|
3464
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3473
3465
|
if (doc.format === 'hwp')
|
|
3474
|
-
return error('HWP files are read-only');
|
|
3466
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3475
3467
|
const result = doc.insertEndnote(args?.section_index, args?.paragraph_index, args?.text);
|
|
3476
3468
|
if (!result)
|
|
3477
|
-
return error('Failed to insert endnote');
|
|
3478
|
-
return success({ message: 'Endnote inserted', id: result.id });
|
|
3469
|
+
return (0, ToolResult_1.error)('Failed to insert endnote');
|
|
3470
|
+
return (0, ToolResult_1.success)({ message: 'Endnote inserted', id: result.id });
|
|
3479
3471
|
}
|
|
3480
3472
|
// === Bookmarks/Hyperlinks ===
|
|
3481
3473
|
case 'get_bookmarks': {
|
|
3482
3474
|
const doc = getDoc(args?.doc_id);
|
|
3483
3475
|
if (!doc)
|
|
3484
|
-
return error('Document not found');
|
|
3485
|
-
return success({ bookmarks: doc.getBookmarks() });
|
|
3476
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3477
|
+
return (0, ToolResult_1.success)({ bookmarks: doc.getBookmarks() });
|
|
3486
3478
|
}
|
|
3487
3479
|
case 'insert_bookmark': {
|
|
3488
3480
|
const doc = getDoc(args?.doc_id);
|
|
3489
3481
|
if (!doc)
|
|
3490
|
-
return error('Document not found');
|
|
3482
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3491
3483
|
if (doc.format === 'hwp')
|
|
3492
|
-
return error('HWP files are read-only');
|
|
3484
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3493
3485
|
if (doc.insertBookmark(args?.section_index, args?.paragraph_index, args?.name)) {
|
|
3494
|
-
return success({ message: 'Bookmark inserted' });
|
|
3486
|
+
return (0, ToolResult_1.success)({ message: 'Bookmark inserted' });
|
|
3495
3487
|
}
|
|
3496
|
-
return error('Failed to insert bookmark');
|
|
3488
|
+
return (0, ToolResult_1.error)('Failed to insert bookmark');
|
|
3497
3489
|
}
|
|
3498
3490
|
case 'get_hyperlinks': {
|
|
3499
3491
|
const doc = getDoc(args?.doc_id);
|
|
3500
3492
|
if (!doc)
|
|
3501
|
-
return error('Document not found');
|
|
3502
|
-
return success({ hyperlinks: doc.getHyperlinks() });
|
|
3493
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3494
|
+
return (0, ToolResult_1.success)({ hyperlinks: doc.getHyperlinks() });
|
|
3503
3495
|
}
|
|
3504
3496
|
case 'insert_hyperlink': {
|
|
3505
3497
|
const doc = getDoc(args?.doc_id);
|
|
3506
3498
|
if (!doc)
|
|
3507
|
-
return error('Document not found');
|
|
3499
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3508
3500
|
if (doc.format === 'hwp')
|
|
3509
|
-
return error('HWP files are read-only');
|
|
3501
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3510
3502
|
if (doc.insertHyperlink(args?.section_index, args?.paragraph_index, args?.url, args?.text)) {
|
|
3511
|
-
return success({ message: 'Hyperlink inserted' });
|
|
3503
|
+
return (0, ToolResult_1.success)({ message: 'Hyperlink inserted' });
|
|
3512
3504
|
}
|
|
3513
|
-
return error('Failed to insert hyperlink');
|
|
3505
|
+
return (0, ToolResult_1.error)('Failed to insert hyperlink');
|
|
3514
3506
|
}
|
|
3515
3507
|
// === Image Operations ===
|
|
3516
3508
|
case 'insert_image': {
|
|
3517
3509
|
const doc = getDoc(args?.doc_id);
|
|
3518
3510
|
if (!doc)
|
|
3519
|
-
return error('Document not found');
|
|
3511
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3520
3512
|
if (doc.format === 'hwp')
|
|
3521
|
-
return error('HWP files are read-only');
|
|
3513
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3522
3514
|
const imagePath = args?.image_path;
|
|
3523
3515
|
if (!fs.existsSync(imagePath))
|
|
3524
|
-
return error('Image file not found');
|
|
3516
|
+
return (0, ToolResult_1.error)('Image file not found');
|
|
3525
3517
|
// Resolve position using after_table, after_header, or direct indices
|
|
3526
3518
|
let sectionIndex = args?.section_index;
|
|
3527
3519
|
let afterIndex = args?.after_index;
|
|
@@ -3532,7 +3524,7 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
3532
3524
|
// Insert after a specific table
|
|
3533
3525
|
const pos = doc.findInsertPositionAfterTable(afterTable);
|
|
3534
3526
|
if (!pos)
|
|
3535
|
-
return error(`Table ${afterTable} not found`);
|
|
3527
|
+
return (0, ToolResult_1.error)(`Table ${afterTable} not found`);
|
|
3536
3528
|
sectionIndex = pos.section_index;
|
|
3537
3529
|
afterIndex = pos.insert_after;
|
|
3538
3530
|
insertedAfter = `table ${afterTable} ("${pos.table_info.header.substring(0, 50)}")`;
|
|
@@ -3541,7 +3533,7 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
3541
3533
|
// Insert after a header paragraph
|
|
3542
3534
|
const pos = doc.findInsertPositionAfterHeader(afterHeader);
|
|
3543
3535
|
if (!pos)
|
|
3544
|
-
return error(`Header "${afterHeader}" not found`);
|
|
3536
|
+
return (0, ToolResult_1.error)(`Header "${afterHeader}" not found`);
|
|
3545
3537
|
sectionIndex = pos.section_index;
|
|
3546
3538
|
afterIndex = pos.insert_after;
|
|
3547
3539
|
insertedAfter = `header "${pos.header_found.substring(0, 50)}"`;
|
|
@@ -3549,9 +3541,9 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
3549
3541
|
else {
|
|
3550
3542
|
// Use direct indices
|
|
3551
3543
|
if (sectionIndex === undefined)
|
|
3552
|
-
return error('section_index is required when not using after_table or after_header');
|
|
3544
|
+
return (0, ToolResult_1.error)('section_index is required when not using after_table or after_header');
|
|
3553
3545
|
if (afterIndex === undefined)
|
|
3554
|
-
return error('after_index is required when not using after_table or after_header');
|
|
3546
|
+
return (0, ToolResult_1.error)('after_index is required when not using after_table or after_header');
|
|
3555
3547
|
insertedAfter = `element ${afterIndex}`;
|
|
3556
3548
|
}
|
|
3557
3549
|
const imageData = fs.readFileSync(imagePath);
|
|
@@ -3587,10 +3579,10 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
3587
3579
|
headerText: afterHeader, // Pass header text for precise XML positioning
|
|
3588
3580
|
});
|
|
3589
3581
|
if (!result)
|
|
3590
|
-
return error('Failed to insert image');
|
|
3582
|
+
return (0, ToolResult_1.error)('Failed to insert image');
|
|
3591
3583
|
// Get context around insertion point for verification
|
|
3592
3584
|
const context = doc.getInsertContext(sectionIndex, afterIndex + 1, 1);
|
|
3593
|
-
return success({
|
|
3585
|
+
return (0, ToolResult_1.success)({
|
|
3594
3586
|
message: `Image inserted after ${insertedAfter}`,
|
|
3595
3587
|
id: result.id,
|
|
3596
3588
|
actualWidth: result.actualWidth,
|
|
@@ -3606,43 +3598,43 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
3606
3598
|
case 'update_image_size': {
|
|
3607
3599
|
const doc = getDoc(args?.doc_id);
|
|
3608
3600
|
if (!doc)
|
|
3609
|
-
return error('Document not found');
|
|
3601
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3610
3602
|
if (doc.format === 'hwp')
|
|
3611
|
-
return error('HWP files are read-only');
|
|
3603
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3612
3604
|
// Find image ID from section and index
|
|
3613
3605
|
const images = doc.getImages();
|
|
3614
3606
|
const imageIndex = args?.image_index;
|
|
3615
3607
|
if (imageIndex < 0 || imageIndex >= images.length)
|
|
3616
|
-
return error('Image not found');
|
|
3608
|
+
return (0, ToolResult_1.error)('Image not found');
|
|
3617
3609
|
if (doc.updateImageSize(images[imageIndex].id, args?.width, args?.height)) {
|
|
3618
|
-
return success({ message: 'Image size updated' });
|
|
3610
|
+
return (0, ToolResult_1.success)({ message: 'Image size updated' });
|
|
3619
3611
|
}
|
|
3620
|
-
return error('Failed to update image size');
|
|
3612
|
+
return (0, ToolResult_1.error)('Failed to update image size');
|
|
3621
3613
|
}
|
|
3622
3614
|
case 'delete_image': {
|
|
3623
3615
|
const doc = getDoc(args?.doc_id);
|
|
3624
3616
|
if (!doc)
|
|
3625
|
-
return error('Document not found');
|
|
3617
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3626
3618
|
if (doc.format === 'hwp')
|
|
3627
|
-
return error('HWP files are read-only');
|
|
3619
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3628
3620
|
const images = doc.getImages();
|
|
3629
3621
|
const imageIndex = args?.image_index;
|
|
3630
3622
|
if (imageIndex < 0 || imageIndex >= images.length)
|
|
3631
|
-
return error('Image not found');
|
|
3623
|
+
return (0, ToolResult_1.error)('Image not found');
|
|
3632
3624
|
if (doc.deleteImage(images[imageIndex].id)) {
|
|
3633
|
-
return success({ message: 'Image deleted' });
|
|
3625
|
+
return (0, ToolResult_1.success)({ message: 'Image deleted' });
|
|
3634
3626
|
}
|
|
3635
|
-
return error('Failed to delete image');
|
|
3627
|
+
return (0, ToolResult_1.error)('Failed to delete image');
|
|
3636
3628
|
}
|
|
3637
3629
|
case 'render_mermaid': {
|
|
3638
3630
|
const doc = getDoc(args?.doc_id);
|
|
3639
3631
|
if (!doc)
|
|
3640
|
-
return error('Document not found');
|
|
3632
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3641
3633
|
if (doc.format === 'hwp')
|
|
3642
|
-
return error('HWP files are read-only');
|
|
3634
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3643
3635
|
const mermaidCode = args?.mermaid_code;
|
|
3644
3636
|
if (!mermaidCode)
|
|
3645
|
-
return error('Mermaid code is required');
|
|
3637
|
+
return (0, ToolResult_1.error)('Mermaid code is required');
|
|
3646
3638
|
// Resolve position using after_table, after_header, or direct indices
|
|
3647
3639
|
let sectionIndex = args?.section_index;
|
|
3648
3640
|
let afterIndex = args?.after_index;
|
|
@@ -3653,7 +3645,7 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
3653
3645
|
// Insert after a specific table
|
|
3654
3646
|
const pos = doc.findInsertPositionAfterTable(afterTable);
|
|
3655
3647
|
if (!pos)
|
|
3656
|
-
return error(`Table ${afterTable} not found`);
|
|
3648
|
+
return (0, ToolResult_1.error)(`Table ${afterTable} not found`);
|
|
3657
3649
|
sectionIndex = pos.section_index;
|
|
3658
3650
|
afterIndex = pos.insert_after;
|
|
3659
3651
|
insertedAfter = `table ${afterTable} ("${pos.table_info.header.substring(0, 50)}")`;
|
|
@@ -3662,7 +3654,7 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
3662
3654
|
// Insert after a header paragraph
|
|
3663
3655
|
const pos = doc.findInsertPositionAfterHeader(afterHeader);
|
|
3664
3656
|
if (!pos)
|
|
3665
|
-
return error(`Header "${afterHeader}" not found`);
|
|
3657
|
+
return (0, ToolResult_1.error)(`Header "${afterHeader}" not found`);
|
|
3666
3658
|
sectionIndex = pos.section_index;
|
|
3667
3659
|
afterIndex = pos.insert_after;
|
|
3668
3660
|
insertedAfter = `header "${pos.header_found.substring(0, 50)}"`;
|
|
@@ -3671,7 +3663,7 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
3671
3663
|
// Use direct indices (default section to 0)
|
|
3672
3664
|
sectionIndex = sectionIndex ?? 0;
|
|
3673
3665
|
if (afterIndex === undefined)
|
|
3674
|
-
return error('after_index is required when not using after_table or after_header');
|
|
3666
|
+
return (0, ToolResult_1.error)('after_index is required when not using after_table or after_header');
|
|
3675
3667
|
insertedAfter = `element ${afterIndex}`;
|
|
3676
3668
|
}
|
|
3677
3669
|
// Build position options from args
|
|
@@ -3699,7 +3691,7 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
3699
3691
|
if (result.success) {
|
|
3700
3692
|
// Get context around insertion point for verification
|
|
3701
3693
|
const context = doc.getInsertContext(sectionIndex, afterIndex + 1, 1);
|
|
3702
|
-
return success({
|
|
3694
|
+
return (0, ToolResult_1.success)({
|
|
3703
3695
|
message: `Mermaid diagram inserted after ${insertedAfter}`,
|
|
3704
3696
|
image_id: result.imageId,
|
|
3705
3697
|
actualWidth: result.actualWidth,
|
|
@@ -3712,24 +3704,24 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
3712
3704
|
} : undefined,
|
|
3713
3705
|
});
|
|
3714
3706
|
}
|
|
3715
|
-
return error(result.error || 'Failed to render Mermaid diagram');
|
|
3707
|
+
return (0, ToolResult_1.error)(result.error || 'Failed to render Mermaid diagram');
|
|
3716
3708
|
}
|
|
3717
3709
|
case 'insert_image_in_cell': {
|
|
3718
3710
|
const doc = getDoc(args?.doc_id);
|
|
3719
3711
|
if (!doc)
|
|
3720
|
-
return error('Document not found');
|
|
3712
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3721
3713
|
if (doc.format === 'hwp')
|
|
3722
|
-
return error('HWP files are read-only');
|
|
3714
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3723
3715
|
const imagePath = args?.image_path;
|
|
3724
3716
|
if (!fs.existsSync(imagePath))
|
|
3725
|
-
return error('Image file not found');
|
|
3717
|
+
return (0, ToolResult_1.error)('Image file not found');
|
|
3726
3718
|
const globalTblIdx = args?.table_index;
|
|
3727
3719
|
const rowIdx = args?.row;
|
|
3728
3720
|
const colIdx = args?.col;
|
|
3729
3721
|
// Convert global table index to section and local index
|
|
3730
3722
|
const tableLocation = doc.convertGlobalToLocalTableIndex(globalTblIdx);
|
|
3731
3723
|
if (!tableLocation) {
|
|
3732
|
-
return error(`Table with global index ${globalTblIdx} not found. Use get_table_map to find valid table indices.`);
|
|
3724
|
+
return (0, ToolResult_1.error)(`Table with global index ${globalTblIdx} not found. Use get_table_map to find valid table indices.`);
|
|
3733
3725
|
}
|
|
3734
3726
|
const { section_index: secIdx, local_index: localTblIdx } = tableLocation;
|
|
3735
3727
|
const imageData = fs.readFileSync(imagePath);
|
|
@@ -3751,14 +3743,14 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
3751
3743
|
afterText,
|
|
3752
3744
|
});
|
|
3753
3745
|
if (!result)
|
|
3754
|
-
return error('Failed to insert image in cell. Check row/col indices.');
|
|
3746
|
+
return (0, ToolResult_1.error)('Failed to insert image in cell. Check row/col indices.');
|
|
3755
3747
|
// Get cell content for context using getTableCell
|
|
3756
3748
|
const cellInfo = doc.getTableCell(secIdx, localTblIdx, rowIdx, colIdx);
|
|
3757
3749
|
const cellText = cellInfo?.text?.substring(0, 30) || '';
|
|
3758
3750
|
const positionInfo = afterText
|
|
3759
3751
|
? `after paragraph containing "${afterText}"`
|
|
3760
3752
|
: 'at the beginning';
|
|
3761
|
-
return success({
|
|
3753
|
+
return (0, ToolResult_1.success)({
|
|
3762
3754
|
message: `Image inserted in cell [${rowIdx}, ${colIdx}] of table ${globalTblIdx} ${positionInfo}`,
|
|
3763
3755
|
id: result.id,
|
|
3764
3756
|
actualWidth: result.actualWidth,
|
|
@@ -3769,19 +3761,19 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
3769
3761
|
case 'render_mermaid_in_cell': {
|
|
3770
3762
|
const doc = getDoc(args?.doc_id);
|
|
3771
3763
|
if (!doc)
|
|
3772
|
-
return error('Document not found');
|
|
3764
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3773
3765
|
if (doc.format === 'hwp')
|
|
3774
|
-
return error('HWP files are read-only');
|
|
3766
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3775
3767
|
const mermaidCode = args?.mermaid_code;
|
|
3776
3768
|
if (!mermaidCode)
|
|
3777
|
-
return error('Mermaid code is required');
|
|
3769
|
+
return (0, ToolResult_1.error)('Mermaid code is required');
|
|
3778
3770
|
const globalTblIdx = args?.table_index;
|
|
3779
3771
|
const rowIdx = args?.row;
|
|
3780
3772
|
const colIdx = args?.col;
|
|
3781
3773
|
// Convert global table index to section and local index
|
|
3782
3774
|
const tableLocation = doc.convertGlobalToLocalTableIndex(globalTblIdx);
|
|
3783
3775
|
if (!tableLocation) {
|
|
3784
|
-
return error(`Table with global index ${globalTblIdx} not found. Use get_table_map to find valid table indices.`);
|
|
3776
|
+
return (0, ToolResult_1.error)(`Table with global index ${globalTblIdx} not found. Use get_table_map to find valid table indices.`);
|
|
3785
3777
|
}
|
|
3786
3778
|
const { section_index: secIdx, local_index: localTblIdx } = tableLocation;
|
|
3787
3779
|
// Fetch Mermaid diagram from mermaid.ink API using pako compression (same as renderMermaidToImage)
|
|
@@ -3808,7 +3800,7 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
3808
3800
|
try {
|
|
3809
3801
|
const response = await fetch(url);
|
|
3810
3802
|
if (!response.ok) {
|
|
3811
|
-
return error(`Failed to render Mermaid diagram: ${response.statusText}`);
|
|
3803
|
+
return (0, ToolResult_1.error)(`Failed to render Mermaid diagram: ${response.statusText}`);
|
|
3812
3804
|
}
|
|
3813
3805
|
const imageBuffer = Buffer.from(await response.arrayBuffer());
|
|
3814
3806
|
const afterText = args?.after_text;
|
|
@@ -3821,14 +3813,14 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
3821
3813
|
afterText,
|
|
3822
3814
|
});
|
|
3823
3815
|
if (!result)
|
|
3824
|
-
return error('Failed to insert Mermaid diagram in cell. Check row/col indices.');
|
|
3816
|
+
return (0, ToolResult_1.error)('Failed to insert Mermaid diagram in cell. Check row/col indices.');
|
|
3825
3817
|
// Get cell content for context using getTableCell
|
|
3826
3818
|
const cellInfo = doc.getTableCell(secIdx, localTblIdx, rowIdx, colIdx);
|
|
3827
3819
|
const cellText = cellInfo?.text?.substring(0, 30) || '';
|
|
3828
3820
|
const positionInfo = afterText
|
|
3829
3821
|
? `after paragraph containing "${afterText}"`
|
|
3830
3822
|
: 'at the beginning';
|
|
3831
|
-
return success({
|
|
3823
|
+
return (0, ToolResult_1.success)({
|
|
3832
3824
|
message: `Mermaid diagram inserted in cell [${rowIdx}, ${colIdx}] of table ${globalTblIdx} ${positionInfo}`,
|
|
3833
3825
|
image_id: result.id,
|
|
3834
3826
|
actualWidth: result.actualWidth,
|
|
@@ -3838,202 +3830,202 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
3838
3830
|
}
|
|
3839
3831
|
catch (err) {
|
|
3840
3832
|
const errorMessage = err instanceof Error ? err.message : String(err);
|
|
3841
|
-
return error(`Failed to fetch Mermaid diagram: ${errorMessage}`);
|
|
3833
|
+
return (0, ToolResult_1.error)(`Failed to fetch Mermaid diagram: ${errorMessage}`);
|
|
3842
3834
|
}
|
|
3843
3835
|
}
|
|
3844
3836
|
// === Drawing Objects ===
|
|
3845
3837
|
case 'insert_line': {
|
|
3846
3838
|
const doc = getDoc(args?.doc_id);
|
|
3847
3839
|
if (!doc)
|
|
3848
|
-
return error('Document not found');
|
|
3840
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3849
3841
|
if (doc.format === 'hwp')
|
|
3850
|
-
return error('HWP files are read-only');
|
|
3842
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3851
3843
|
const result = doc.insertLine(args?.section_index, args?.x1, args?.y1, args?.x2, args?.y2, {
|
|
3852
3844
|
color: args?.stroke_color,
|
|
3853
3845
|
width: args?.stroke_width,
|
|
3854
3846
|
});
|
|
3855
3847
|
if (!result)
|
|
3856
|
-
return error('Failed to insert line');
|
|
3857
|
-
return success({ message: 'Line inserted', id: result.id });
|
|
3848
|
+
return (0, ToolResult_1.error)('Failed to insert line');
|
|
3849
|
+
return (0, ToolResult_1.success)({ message: 'Line inserted', id: result.id });
|
|
3858
3850
|
}
|
|
3859
3851
|
case 'insert_rect': {
|
|
3860
3852
|
const doc = getDoc(args?.doc_id);
|
|
3861
3853
|
if (!doc)
|
|
3862
|
-
return error('Document not found');
|
|
3854
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3863
3855
|
if (doc.format === 'hwp')
|
|
3864
|
-
return error('HWP files are read-only');
|
|
3856
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3865
3857
|
const result = doc.insertRect(args?.section_index, args?.x, args?.y, args?.width, args?.height, {
|
|
3866
3858
|
fillColor: args?.fill_color,
|
|
3867
3859
|
strokeColor: args?.stroke_color,
|
|
3868
3860
|
});
|
|
3869
3861
|
if (!result)
|
|
3870
|
-
return error('Failed to insert rectangle');
|
|
3871
|
-
return success({ message: 'Rectangle inserted', id: result.id });
|
|
3862
|
+
return (0, ToolResult_1.error)('Failed to insert rectangle');
|
|
3863
|
+
return (0, ToolResult_1.success)({ message: 'Rectangle inserted', id: result.id });
|
|
3872
3864
|
}
|
|
3873
3865
|
case 'insert_ellipse': {
|
|
3874
3866
|
const doc = getDoc(args?.doc_id);
|
|
3875
3867
|
if (!doc)
|
|
3876
|
-
return error('Document not found');
|
|
3868
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3877
3869
|
if (doc.format === 'hwp')
|
|
3878
|
-
return error('HWP files are read-only');
|
|
3870
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3879
3871
|
const result = doc.insertEllipse(args?.section_index, args?.cx, args?.cy, args?.rx, args?.ry, {
|
|
3880
3872
|
fillColor: args?.fill_color,
|
|
3881
3873
|
strokeColor: args?.stroke_color,
|
|
3882
3874
|
});
|
|
3883
3875
|
if (!result)
|
|
3884
|
-
return error('Failed to insert ellipse');
|
|
3885
|
-
return success({ message: 'Ellipse inserted', id: result.id });
|
|
3876
|
+
return (0, ToolResult_1.error)('Failed to insert ellipse');
|
|
3877
|
+
return (0, ToolResult_1.success)({ message: 'Ellipse inserted', id: result.id });
|
|
3886
3878
|
}
|
|
3887
3879
|
// === Equations ===
|
|
3888
3880
|
case 'get_equations': {
|
|
3889
3881
|
const doc = getDoc(args?.doc_id);
|
|
3890
3882
|
if (!doc)
|
|
3891
|
-
return error('Document not found');
|
|
3892
|
-
return success({ equations: doc.getEquations() });
|
|
3883
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3884
|
+
return (0, ToolResult_1.success)({ equations: doc.getEquations() });
|
|
3893
3885
|
}
|
|
3894
3886
|
case 'insert_equation': {
|
|
3895
3887
|
const doc = getDoc(args?.doc_id);
|
|
3896
3888
|
if (!doc)
|
|
3897
|
-
return error('Document not found');
|
|
3889
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3898
3890
|
if (doc.format === 'hwp')
|
|
3899
|
-
return error('HWP files are read-only');
|
|
3891
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3900
3892
|
const result = doc.insertEquation(args?.section_index, args?.after_index, args?.script);
|
|
3901
3893
|
if (!result)
|
|
3902
|
-
return error('Failed to insert equation');
|
|
3903
|
-
return success({ message: 'Equation inserted', id: result.id });
|
|
3894
|
+
return (0, ToolResult_1.error)('Failed to insert equation');
|
|
3895
|
+
return (0, ToolResult_1.success)({ message: 'Equation inserted', id: result.id });
|
|
3904
3896
|
}
|
|
3905
3897
|
// === Memos ===
|
|
3906
3898
|
case 'get_memos': {
|
|
3907
3899
|
const doc = getDoc(args?.doc_id);
|
|
3908
3900
|
if (!doc)
|
|
3909
|
-
return error('Document not found');
|
|
3910
|
-
return success({ memos: doc.getMemos() });
|
|
3901
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3902
|
+
return (0, ToolResult_1.success)({ memos: doc.getMemos() });
|
|
3911
3903
|
}
|
|
3912
3904
|
case 'insert_memo': {
|
|
3913
3905
|
const doc = getDoc(args?.doc_id);
|
|
3914
3906
|
if (!doc)
|
|
3915
|
-
return error('Document not found');
|
|
3907
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3916
3908
|
if (doc.format === 'hwp')
|
|
3917
|
-
return error('HWP files are read-only');
|
|
3909
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3918
3910
|
const result = doc.insertMemo(args?.section_index, args?.paragraph_index, args?.content, args?.author);
|
|
3919
3911
|
if (!result)
|
|
3920
|
-
return error('Failed to insert memo');
|
|
3921
|
-
return success({ message: 'Memo inserted', id: result.id });
|
|
3912
|
+
return (0, ToolResult_1.error)('Failed to insert memo');
|
|
3913
|
+
return (0, ToolResult_1.success)({ message: 'Memo inserted', id: result.id });
|
|
3922
3914
|
}
|
|
3923
3915
|
case 'delete_memo': {
|
|
3924
3916
|
const doc = getDoc(args?.doc_id);
|
|
3925
3917
|
if (!doc)
|
|
3926
|
-
return error('Document not found');
|
|
3918
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3927
3919
|
if (doc.format === 'hwp')
|
|
3928
|
-
return error('HWP files are read-only');
|
|
3920
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3929
3921
|
if (doc.deleteMemo(args?.memo_id)) {
|
|
3930
|
-
return success({ message: 'Memo deleted' });
|
|
3922
|
+
return (0, ToolResult_1.success)({ message: 'Memo deleted' });
|
|
3931
3923
|
}
|
|
3932
|
-
return error('Failed to delete memo');
|
|
3924
|
+
return (0, ToolResult_1.error)('Failed to delete memo');
|
|
3933
3925
|
}
|
|
3934
3926
|
// === Sections ===
|
|
3935
3927
|
case 'get_sections': {
|
|
3936
3928
|
const doc = getDoc(args?.doc_id);
|
|
3937
3929
|
if (!doc)
|
|
3938
|
-
return error('Document not found');
|
|
3939
|
-
return success({ sections: doc.getSections() });
|
|
3930
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3931
|
+
return (0, ToolResult_1.success)({ sections: doc.getSections() });
|
|
3940
3932
|
}
|
|
3941
3933
|
case 'insert_section': {
|
|
3942
3934
|
const doc = getDoc(args?.doc_id);
|
|
3943
3935
|
if (!doc)
|
|
3944
|
-
return error('Document not found');
|
|
3936
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3945
3937
|
if (doc.format === 'hwp')
|
|
3946
|
-
return error('HWP files are read-only');
|
|
3938
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3947
3939
|
const newIndex = doc.insertSection(args?.after_index);
|
|
3948
|
-
return success({ message: 'Section inserted', index: newIndex });
|
|
3940
|
+
return (0, ToolResult_1.success)({ message: 'Section inserted', index: newIndex });
|
|
3949
3941
|
}
|
|
3950
3942
|
case 'delete_section': {
|
|
3951
3943
|
const doc = getDoc(args?.doc_id);
|
|
3952
3944
|
if (!doc)
|
|
3953
|
-
return error('Document not found');
|
|
3945
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3954
3946
|
if (doc.format === 'hwp')
|
|
3955
|
-
return error('HWP files are read-only');
|
|
3947
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3956
3948
|
if (doc.deleteSection(args?.section_index)) {
|
|
3957
|
-
return success({ message: 'Section deleted' });
|
|
3949
|
+
return (0, ToolResult_1.success)({ message: 'Section deleted' });
|
|
3958
3950
|
}
|
|
3959
|
-
return error('Failed to delete section');
|
|
3951
|
+
return (0, ToolResult_1.error)('Failed to delete section');
|
|
3960
3952
|
}
|
|
3961
3953
|
case 'get_section_xml': {
|
|
3962
3954
|
const doc = getDoc(args?.doc_id);
|
|
3963
3955
|
if (!doc)
|
|
3964
|
-
return error('Document not found');
|
|
3956
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3965
3957
|
const sectionIndex = args?.section_index ?? 0;
|
|
3966
3958
|
const xml = await doc.getSectionXml(sectionIndex);
|
|
3967
3959
|
if (xml === null) {
|
|
3968
|
-
return error(`Section ${sectionIndex} not found or document is HWP format`);
|
|
3960
|
+
return (0, ToolResult_1.error)(`Section ${sectionIndex} not found or document is HWP format`);
|
|
3969
3961
|
}
|
|
3970
|
-
return success({ section_index: sectionIndex, xml });
|
|
3962
|
+
return (0, ToolResult_1.success)({ section_index: sectionIndex, xml });
|
|
3971
3963
|
}
|
|
3972
3964
|
case 'set_section_xml': {
|
|
3973
3965
|
const doc = getDoc(args?.doc_id);
|
|
3974
3966
|
if (!doc)
|
|
3975
|
-
return error('Document not found');
|
|
3967
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3976
3968
|
if (doc.format === 'hwp')
|
|
3977
|
-
return error('HWP files are read-only');
|
|
3969
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
3978
3970
|
const sectionIndex = args?.section_index ?? 0;
|
|
3979
3971
|
const xml = args?.xml;
|
|
3980
3972
|
const validate = args?.validate ?? true;
|
|
3981
3973
|
if (!xml) {
|
|
3982
|
-
return error('XML content is required');
|
|
3974
|
+
return (0, ToolResult_1.error)('XML content is required');
|
|
3983
3975
|
}
|
|
3984
3976
|
const result = await doc.setSectionXml(sectionIndex, xml, validate);
|
|
3985
3977
|
if (result.success) {
|
|
3986
|
-
return success({ message: `Section ${sectionIndex} XML replaced successfully` });
|
|
3978
|
+
return (0, ToolResult_1.success)({ message: `Section ${sectionIndex} XML replaced successfully` });
|
|
3987
3979
|
}
|
|
3988
|
-
return error(result.error || 'Failed to set section XML');
|
|
3980
|
+
return (0, ToolResult_1.error)(result.error || 'Failed to set section XML');
|
|
3989
3981
|
}
|
|
3990
3982
|
// === Styles ===
|
|
3991
3983
|
case 'get_styles': {
|
|
3992
3984
|
const doc = getDoc(args?.doc_id);
|
|
3993
3985
|
if (!doc)
|
|
3994
|
-
return error('Document not found');
|
|
3995
|
-
return success({ styles: doc.getStyles() });
|
|
3986
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3987
|
+
return (0, ToolResult_1.success)({ styles: doc.getStyles() });
|
|
3996
3988
|
}
|
|
3997
3989
|
case 'get_char_shapes': {
|
|
3998
3990
|
const doc = getDoc(args?.doc_id);
|
|
3999
3991
|
if (!doc)
|
|
4000
|
-
return error('Document not found');
|
|
4001
|
-
return success({ charShapes: doc.getCharShapes() });
|
|
3992
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3993
|
+
return (0, ToolResult_1.success)({ charShapes: doc.getCharShapes() });
|
|
4002
3994
|
}
|
|
4003
3995
|
case 'get_para_shapes': {
|
|
4004
3996
|
const doc = getDoc(args?.doc_id);
|
|
4005
3997
|
if (!doc)
|
|
4006
|
-
return error('Document not found');
|
|
4007
|
-
return success({ paraShapes: doc.getParaShapes() });
|
|
3998
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
3999
|
+
return (0, ToolResult_1.success)({ paraShapes: doc.getParaShapes() });
|
|
4008
4000
|
}
|
|
4009
4001
|
case 'apply_style': {
|
|
4010
4002
|
const doc = getDoc(args?.doc_id);
|
|
4011
4003
|
if (!doc)
|
|
4012
|
-
return error('Document not found');
|
|
4004
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
4013
4005
|
if (doc.format === 'hwp')
|
|
4014
|
-
return error('HWP files are read-only');
|
|
4006
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
4015
4007
|
if (doc.applyStyle(args?.section_index, args?.paragraph_index, args?.style_id)) {
|
|
4016
|
-
return success({ message: 'Style applied' });
|
|
4008
|
+
return (0, ToolResult_1.success)({ message: 'Style applied' });
|
|
4017
4009
|
}
|
|
4018
|
-
return error('Failed to apply style');
|
|
4010
|
+
return (0, ToolResult_1.error)('Failed to apply style');
|
|
4019
4011
|
}
|
|
4020
4012
|
// === Column Definition ===
|
|
4021
4013
|
case 'get_column_def': {
|
|
4022
4014
|
const doc = getDoc(args?.doc_id);
|
|
4023
4015
|
if (!doc)
|
|
4024
|
-
return error('Document not found');
|
|
4025
|
-
return success({ columnDef: doc.getColumnDef(args?.section_index || 0) });
|
|
4016
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
4017
|
+
return (0, ToolResult_1.success)({ columnDef: doc.getColumnDef(args?.section_index || 0) });
|
|
4026
4018
|
}
|
|
4027
4019
|
case 'set_column_def': {
|
|
4028
4020
|
const doc = getDoc(args?.doc_id);
|
|
4029
4021
|
if (!doc)
|
|
4030
|
-
return error('Document not found');
|
|
4022
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
4031
4023
|
if (doc.format === 'hwp')
|
|
4032
|
-
return error('HWP files are read-only');
|
|
4024
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
4033
4025
|
if (doc.setColumnDef(args?.section_index || 0, args?.count, args?.gap)) {
|
|
4034
|
-
return success({ message: 'Column definition set' });
|
|
4026
|
+
return (0, ToolResult_1.success)({ message: 'Column definition set' });
|
|
4035
4027
|
}
|
|
4036
|
-
return error('Failed to set column definition');
|
|
4028
|
+
return (0, ToolResult_1.error)('Failed to set column definition');
|
|
4037
4029
|
}
|
|
4038
4030
|
// === Create New Document ===
|
|
4039
4031
|
case 'create_document': {
|
|
@@ -4047,12 +4039,12 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
4047
4039
|
plannedPath = path.resolve(requestedPath);
|
|
4048
4040
|
const parentDirectory = path.dirname(plannedPath);
|
|
4049
4041
|
if (!fs.existsSync(parentDirectory)) {
|
|
4050
|
-
return error(`Directory does not exist: ${parentDirectory}`);
|
|
4042
|
+
return (0, ToolResult_1.error)(`Directory does not exist: ${parentDirectory}`);
|
|
4051
4043
|
}
|
|
4052
4044
|
doc.setPath(plannedPath);
|
|
4053
4045
|
}
|
|
4054
4046
|
openDocuments.set(docId, doc);
|
|
4055
|
-
return success({
|
|
4047
|
+
return (0, ToolResult_1.success)({
|
|
4056
4048
|
doc_id: docId,
|
|
4057
4049
|
format: 'hwpx',
|
|
4058
4050
|
path: plannedPath,
|
|
@@ -4065,10 +4057,10 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
4065
4057
|
case 'analyze_xml': {
|
|
4066
4058
|
const doc = getDoc(args?.doc_id);
|
|
4067
4059
|
if (!doc)
|
|
4068
|
-
return error('Document not found');
|
|
4060
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
4069
4061
|
const sectionIndex = args?.section_index;
|
|
4070
4062
|
const result = await doc.analyzeXml(sectionIndex);
|
|
4071
|
-
return success({
|
|
4063
|
+
return (0, ToolResult_1.success)({
|
|
4072
4064
|
has_issues: result.hasIssues,
|
|
4073
4065
|
summary: result.summary,
|
|
4074
4066
|
sections: result.sections.map(s => ({
|
|
@@ -4081,18 +4073,18 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
4081
4073
|
case 'repair_xml': {
|
|
4082
4074
|
const doc = getDoc(args?.doc_id);
|
|
4083
4075
|
if (!doc)
|
|
4084
|
-
return error('Document not found');
|
|
4076
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
4085
4077
|
if (doc.format === 'hwp')
|
|
4086
|
-
return error('HWP files are read-only');
|
|
4078
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
4087
4079
|
const sectionIndex = args?.section_index;
|
|
4088
4080
|
if (sectionIndex === undefined)
|
|
4089
|
-
return error('section_index is required');
|
|
4081
|
+
return (0, ToolResult_1.error)('section_index is required');
|
|
4090
4082
|
const result = await doc.repairXml(sectionIndex, {
|
|
4091
4083
|
removeOrphanCloseTags: args?.remove_orphan_close_tags,
|
|
4092
4084
|
fixTableStructure: args?.fix_table_structure,
|
|
4093
4085
|
backup: args?.backup,
|
|
4094
4086
|
});
|
|
4095
|
-
return success({
|
|
4087
|
+
return (0, ToolResult_1.success)({
|
|
4096
4088
|
success: result.success,
|
|
4097
4089
|
message: result.message,
|
|
4098
4090
|
repairs_applied: result.repairsApplied,
|
|
@@ -4102,14 +4094,14 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
4102
4094
|
case 'get_raw_section_xml': {
|
|
4103
4095
|
const doc = getDoc(args?.doc_id);
|
|
4104
4096
|
if (!doc)
|
|
4105
|
-
return error('Document not found');
|
|
4097
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
4106
4098
|
const sectionIndex = args?.section_index;
|
|
4107
4099
|
if (sectionIndex === undefined)
|
|
4108
|
-
return error('section_index is required');
|
|
4100
|
+
return (0, ToolResult_1.error)('section_index is required');
|
|
4109
4101
|
const xml = await doc.getRawSectionXml(sectionIndex);
|
|
4110
4102
|
if (xml === null)
|
|
4111
|
-
return error(`Section ${sectionIndex} not found`);
|
|
4112
|
-
return success({
|
|
4103
|
+
return (0, ToolResult_1.error)(`Section ${sectionIndex} not found`);
|
|
4104
|
+
return (0, ToolResult_1.success)({
|
|
4113
4105
|
section_index: sectionIndex,
|
|
4114
4106
|
xml_length: xml.length,
|
|
4115
4107
|
xml: xml,
|
|
@@ -4118,25 +4110,25 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
4118
4110
|
case 'set_raw_section_xml': {
|
|
4119
4111
|
const doc = getDoc(args?.doc_id);
|
|
4120
4112
|
if (!doc)
|
|
4121
|
-
return error('Document not found');
|
|
4113
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
4122
4114
|
if (doc.format === 'hwp')
|
|
4123
|
-
return error('HWP files are read-only');
|
|
4115
|
+
return (0, ToolResult_1.error)('HWP files are read-only');
|
|
4124
4116
|
const sectionIndex = args?.section_index;
|
|
4125
4117
|
const xml = args?.xml;
|
|
4126
4118
|
const validate = args?.validate !== false; // default: true
|
|
4127
4119
|
if (sectionIndex === undefined)
|
|
4128
|
-
return error('section_index is required');
|
|
4120
|
+
return (0, ToolResult_1.error)('section_index is required');
|
|
4129
4121
|
if (!xml)
|
|
4130
|
-
return error('xml is required');
|
|
4122
|
+
return (0, ToolResult_1.error)('xml is required');
|
|
4131
4123
|
const result = await doc.setRawSectionXml(sectionIndex, xml, validate);
|
|
4132
4124
|
if (result.success) {
|
|
4133
|
-
return success({
|
|
4125
|
+
return (0, ToolResult_1.success)({
|
|
4134
4126
|
success: true,
|
|
4135
4127
|
message: result.message,
|
|
4136
4128
|
});
|
|
4137
4129
|
}
|
|
4138
4130
|
else {
|
|
4139
|
-
return success({
|
|
4131
|
+
return (0, ToolResult_1.success)({
|
|
4140
4132
|
success: false,
|
|
4141
4133
|
message: result.message,
|
|
4142
4134
|
issues: result.issues,
|
|
@@ -4147,11 +4139,11 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
4147
4139
|
case 'chunk_document': {
|
|
4148
4140
|
const doc = getDoc(args?.doc_id);
|
|
4149
4141
|
if (!doc)
|
|
4150
|
-
return error('Document not found');
|
|
4142
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
4151
4143
|
const chunkSize = args?.chunk_size || 500;
|
|
4152
4144
|
const overlap = args?.overlap || 100;
|
|
4153
4145
|
const chunks = doc.chunkDocument(chunkSize, overlap);
|
|
4154
|
-
return success({
|
|
4146
|
+
return (0, ToolResult_1.success)({
|
|
4155
4147
|
total_chunks: chunks.length,
|
|
4156
4148
|
chunk_size: chunkSize,
|
|
4157
4149
|
overlap: overlap,
|
|
@@ -4170,14 +4162,14 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
4170
4162
|
case 'search_chunks': {
|
|
4171
4163
|
const doc = getDoc(args?.doc_id);
|
|
4172
4164
|
if (!doc)
|
|
4173
|
-
return error('Document not found');
|
|
4165
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
4174
4166
|
const query = args?.query;
|
|
4175
4167
|
if (!query)
|
|
4176
|
-
return error('query is required');
|
|
4168
|
+
return (0, ToolResult_1.error)('query is required');
|
|
4177
4169
|
const topK = args?.top_k || 5;
|
|
4178
4170
|
const minScore = args?.min_score || 0.1;
|
|
4179
4171
|
const results = doc.searchChunks(query, topK, minScore);
|
|
4180
|
-
return success({
|
|
4172
|
+
return (0, ToolResult_1.success)({
|
|
4181
4173
|
query,
|
|
4182
4174
|
total_results: results.length,
|
|
4183
4175
|
results: results.map(r => ({
|
|
@@ -4199,14 +4191,14 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
4199
4191
|
case 'get_chunk_context': {
|
|
4200
4192
|
const doc = getDoc(args?.doc_id);
|
|
4201
4193
|
if (!doc)
|
|
4202
|
-
return error('Document not found');
|
|
4194
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
4203
4195
|
const chunkId = args?.chunk_id;
|
|
4204
4196
|
if (!chunkId)
|
|
4205
|
-
return error('chunk_id is required');
|
|
4197
|
+
return (0, ToolResult_1.error)('chunk_id is required');
|
|
4206
4198
|
const before = args?.before || 1;
|
|
4207
4199
|
const after = args?.after || 1;
|
|
4208
4200
|
const context = doc.getChunkContext(chunkId, before, after);
|
|
4209
|
-
return success({
|
|
4201
|
+
return (0, ToolResult_1.success)({
|
|
4210
4202
|
center_index: context.centerIndex,
|
|
4211
4203
|
total_chunks: context.chunks.length,
|
|
4212
4204
|
chunks: context.chunks.map(c => ({
|
|
@@ -4223,9 +4215,9 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
4223
4215
|
case 'extract_toc': {
|
|
4224
4216
|
const doc = getDoc(args?.doc_id);
|
|
4225
4217
|
if (!doc)
|
|
4226
|
-
return error('Document not found');
|
|
4218
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
4227
4219
|
const toc = doc.extractToc();
|
|
4228
|
-
return success({
|
|
4220
|
+
return (0, ToolResult_1.success)({
|
|
4229
4221
|
total_entries: toc.length,
|
|
4230
4222
|
toc: toc.map(t => ({
|
|
4231
4223
|
level: t.level,
|
|
@@ -4239,9 +4231,9 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
4239
4231
|
case 'build_position_index': {
|
|
4240
4232
|
const doc = getDoc(args?.doc_id);
|
|
4241
4233
|
if (!doc)
|
|
4242
|
-
return error('Document not found');
|
|
4234
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
4243
4235
|
const index = doc.buildPositionIndex();
|
|
4244
|
-
return success({
|
|
4236
|
+
return (0, ToolResult_1.success)({
|
|
4245
4237
|
total_entries: index.length,
|
|
4246
4238
|
index: index.map(e => ({
|
|
4247
4239
|
id: e.id,
|
|
@@ -4258,9 +4250,9 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
4258
4250
|
case 'get_position_index': {
|
|
4259
4251
|
const doc = getDoc(args?.doc_id);
|
|
4260
4252
|
if (!doc)
|
|
4261
|
-
return error('Document not found');
|
|
4253
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
4262
4254
|
const index = doc.getPositionIndex();
|
|
4263
|
-
return success({
|
|
4255
|
+
return (0, ToolResult_1.success)({
|
|
4264
4256
|
total_entries: index.length,
|
|
4265
4257
|
index: index.map(e => ({
|
|
4266
4258
|
id: e.id,
|
|
@@ -4277,13 +4269,13 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
4277
4269
|
case 'search_position_index': {
|
|
4278
4270
|
const doc = getDoc(args?.doc_id);
|
|
4279
4271
|
if (!doc)
|
|
4280
|
-
return error('Document not found');
|
|
4272
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
4281
4273
|
const query = args?.query;
|
|
4282
4274
|
if (!query)
|
|
4283
|
-
return error('query is required');
|
|
4275
|
+
return (0, ToolResult_1.error)('query is required');
|
|
4284
4276
|
const type = args?.type;
|
|
4285
4277
|
const results = doc.searchPositionIndex(query, type);
|
|
4286
|
-
return success({
|
|
4278
|
+
return (0, ToolResult_1.success)({
|
|
4287
4279
|
query,
|
|
4288
4280
|
type_filter: type || 'all',
|
|
4289
4281
|
total_results: results.length,
|
|
@@ -4302,15 +4294,15 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
4302
4294
|
case 'get_chunk_at_offset': {
|
|
4303
4295
|
const doc = getDoc(args?.doc_id);
|
|
4304
4296
|
if (!doc)
|
|
4305
|
-
return error('Document not found');
|
|
4297
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
4306
4298
|
const offset = args?.offset;
|
|
4307
4299
|
if (offset === undefined)
|
|
4308
|
-
return error('offset is required');
|
|
4300
|
+
return (0, ToolResult_1.error)('offset is required');
|
|
4309
4301
|
const chunk = doc.getChunkAtOffset(offset);
|
|
4310
4302
|
if (!chunk) {
|
|
4311
|
-
return success({ found: false, message: 'No chunk found at this offset' });
|
|
4303
|
+
return (0, ToolResult_1.success)({ found: false, message: 'No chunk found at this offset' });
|
|
4312
4304
|
}
|
|
4313
|
-
return success({
|
|
4305
|
+
return (0, ToolResult_1.success)({
|
|
4314
4306
|
found: true,
|
|
4315
4307
|
chunk: {
|
|
4316
4308
|
id: chunk.id,
|
|
@@ -4326,16 +4318,16 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
4326
4318
|
case 'invalidate_reading_cache': {
|
|
4327
4319
|
const doc = getDoc(args?.doc_id);
|
|
4328
4320
|
if (!doc)
|
|
4329
|
-
return error('Document not found');
|
|
4321
|
+
return (0, ToolResult_1.error)('Document not found');
|
|
4330
4322
|
doc.invalidateReadingCache();
|
|
4331
|
-
return success({ success: true, message: 'Reading cache invalidated' });
|
|
4323
|
+
return (0, ToolResult_1.success)({ success: true, message: 'Reading cache invalidated' });
|
|
4332
4324
|
}
|
|
4333
4325
|
default:
|
|
4334
|
-
return error(`Unknown tool: ${name}`);
|
|
4326
|
+
return (0, ToolResult_1.error)(`Unknown tool: ${name}`);
|
|
4335
4327
|
}
|
|
4336
4328
|
}
|
|
4337
4329
|
catch (err) {
|
|
4338
|
-
return error(err.message);
|
|
4330
|
+
return (0, ToolResult_1.error)(err.message);
|
|
4339
4331
|
}
|
|
4340
4332
|
});
|
|
4341
4333
|
// ============================================================
|
|
@@ -4344,16 +4336,6 @@ Call get_tool_guide with: template, table, image, search, read, create`
|
|
|
4344
4336
|
function getDoc(docId) {
|
|
4345
4337
|
return openDocuments.get(docId);
|
|
4346
4338
|
}
|
|
4347
|
-
function success(data) {
|
|
4348
|
-
return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] };
|
|
4349
|
-
}
|
|
4350
|
-
function error(message) {
|
|
4351
|
-
// isError tells the MCP client the call failed. Without it, a missing
|
|
4352
|
-
// argument or a refused write came back as a normal result whose body merely
|
|
4353
|
-
// contained {"error": …}, and agents treated it as success (reported
|
|
4354
|
-
// 2026-09-24). The JSON body is kept for clients that read it.
|
|
4355
|
-
return { content: [{ type: 'text', text: JSON.stringify({ error: message }) }], isError: true };
|
|
4356
|
-
}
|
|
4357
4339
|
function escapeHtml(text) {
|
|
4358
4340
|
return text
|
|
4359
4341
|
.replace(/&/g, '&')
|