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