@de-otio/epimethian-mcp 4.1.0 → 4.1.2

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/cli/index.js CHANGED
@@ -45259,12 +45259,21 @@ async function deletePage(pageId) {
45259
45259
  }
45260
45260
  async function searchPages(cql, limit) {
45261
45261
  const cfg = await getConfig();
45262
- const url = new URL(`${cfg.apiV1}/content/search`);
45262
+ const url = new URL(`${cfg.url}/wiki/rest/api/search`);
45263
45263
  url.searchParams.set("cql", cql);
45264
45264
  url.searchParams.set("limit", String(limit));
45265
45265
  const res = await confluenceRequest(url.toString());
45266
45266
  const raw = await res.json();
45267
- return PagesResultSchema.parse(raw).results;
45267
+ const results = [];
45268
+ for (const r of raw.results ?? []) {
45269
+ const page = r.content ?? r;
45270
+ if (r.excerpt) page.excerpt = r.excerpt;
45271
+ try {
45272
+ results.push(PageSchema.parse(page));
45273
+ } catch {
45274
+ }
45275
+ }
45276
+ return results;
45268
45277
  }
45269
45278
  async function listPages(spaceId, limit, status) {
45270
45279
  const raw = await v2Get("/pages", {
@@ -45365,27 +45374,29 @@ function extractHeadings(storageHtml) {
45365
45374
  }
45366
45375
  return lines.length > 0 ? lines.join("\n") : "(no headings found)";
45367
45376
  }
45377
+ function findHeadingInTree(root, headingText) {
45378
+ const allHeadings = root.querySelectorAll("h1, h2, h3, h4, h5, h6");
45379
+ for (const heading of allHeadings) {
45380
+ if (heading.text.trim().toLowerCase() !== headingText.toLowerCase()) continue;
45381
+ const tagMatch = heading.tagName.match(/^H([1-6])$/i);
45382
+ if (!tagMatch) continue;
45383
+ const parent = heading.parentNode;
45384
+ const siblings = parent.childNodes;
45385
+ const startIdx = siblings.indexOf(heading);
45386
+ if (startIdx === -1) continue;
45387
+ return { siblings, startIdx, headingLevel: parseInt(tagMatch[1], 10) };
45388
+ }
45389
+ return null;
45390
+ }
45368
45391
  function extractSection(storageHtml, headingText) {
45369
45392
  const { parse: parse3 } = require_dist2();
45370
45393
  const root = parse3(storageHtml);
45371
- const topLevelNodes = root.childNodes;
45372
- let startIdx = -1;
45373
- let headingLevel = 0;
45374
- for (let i = 0; i < topLevelNodes.length; i++) {
45375
- const node = topLevelNodes[i];
45376
- if (node.nodeType !== 1) continue;
45377
- const el = node;
45378
- const tagMatch = el.tagName?.match(/^H([1-6])$/i);
45379
- if (tagMatch && el.text.trim().toLowerCase() === headingText.toLowerCase()) {
45380
- startIdx = i;
45381
- headingLevel = parseInt(tagMatch[1], 10);
45382
- break;
45383
- }
45384
- }
45385
- if (startIdx === -1) return null;
45386
- let endIdx = topLevelNodes.length;
45387
- for (let i = startIdx + 1; i < topLevelNodes.length; i++) {
45388
- const node = topLevelNodes[i];
45394
+ const found = findHeadingInTree(root, headingText);
45395
+ if (!found) return null;
45396
+ const { siblings, startIdx, headingLevel } = found;
45397
+ let endIdx = siblings.length;
45398
+ for (let i = startIdx + 1; i < siblings.length; i++) {
45399
+ const node = siblings[i];
45389
45400
  if (node.nodeType !== 1) continue;
45390
45401
  const el = node;
45391
45402
  const tagMatch = el.tagName?.match(/^H([1-6])$/i);
@@ -45394,30 +45405,18 @@ function extractSection(storageHtml, headingText) {
45394
45405
  break;
45395
45406
  }
45396
45407
  }
45397
- const sectionNodes = topLevelNodes.slice(startIdx, endIdx);
45408
+ const sectionNodes = siblings.slice(startIdx, endIdx);
45398
45409
  return sectionNodes.map((n) => n.toString()).join("");
45399
45410
  }
45400
45411
  function replaceSection(storageHtml, headingText, newContent) {
45401
45412
  const { parse: parse3 } = require_dist2();
45402
45413
  const root = parse3(storageHtml);
45403
- const topLevelNodes = root.childNodes;
45404
- let startIdx = -1;
45405
- let headingLevel = 0;
45406
- for (let i = 0; i < topLevelNodes.length; i++) {
45407
- const node = topLevelNodes[i];
45408
- if (node.nodeType !== 1) continue;
45409
- const el = node;
45410
- const tagMatch = el.tagName?.match(/^H([1-6])$/i);
45411
- if (tagMatch && el.text.trim().toLowerCase() === headingText.toLowerCase()) {
45412
- startIdx = i;
45413
- headingLevel = parseInt(tagMatch[1], 10);
45414
- break;
45415
- }
45416
- }
45417
- if (startIdx === -1) return null;
45418
- let endIdx = topLevelNodes.length;
45419
- for (let i = startIdx + 1; i < topLevelNodes.length; i++) {
45420
- const node = topLevelNodes[i];
45414
+ const found = findHeadingInTree(root, headingText);
45415
+ if (!found) return null;
45416
+ const { siblings, startIdx, headingLevel } = found;
45417
+ let endIdx = siblings.length;
45418
+ for (let i = startIdx + 1; i < siblings.length; i++) {
45419
+ const node = siblings[i];
45421
45420
  if (node.nodeType !== 1) continue;
45422
45421
  const el = node;
45423
45422
  const tagMatch = el.tagName?.match(/^H([1-6])$/i);
@@ -45426,10 +45425,12 @@ function replaceSection(storageHtml, headingText, newContent) {
45426
45425
  break;
45427
45426
  }
45428
45427
  }
45429
- const before = topLevelNodes.slice(0, startIdx);
45430
- const heading = topLevelNodes[startIdx];
45431
- const after = topLevelNodes.slice(endIdx);
45432
- return before.map((n) => n.toString()).join("") + heading.toString() + newContent + after.map((n) => n.toString()).join("");
45428
+ const before = siblings.slice(0, startIdx);
45429
+ const heading = siblings[startIdx];
45430
+ const after = siblings.slice(endIdx);
45431
+ const parent = heading.parentNode;
45432
+ parent.innerHTML = before.map((n) => n.toString()).join("") + heading.toString() + newContent + after.map((n) => n.toString()).join("");
45433
+ return root.toString();
45433
45434
  }
45434
45435
  function truncateStorageFormat(storageHtml, maxLength) {
45435
45436
  if (storageHtml.length <= maxLength) return storageHtml;