linkedin-relay-mcp 2.0.0 → 2.1.0

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.js CHANGED
@@ -1673,10 +1673,14 @@ function sduiEnvelope(operation, payload, states2 = []) {
1673
1673
  requestedArguments: { ...args, states: states2, screenId: SCREEN_ID, knownTemplateIds: [] }
1674
1674
  };
1675
1675
  }
1676
- function menuBody(activityId, commentId, trackingId) {
1676
+ function menuBody(ref, trackingId) {
1677
+ const { activityId, commentId, threadType } = ref;
1677
1678
  const activityUrn = { activityUrn: { activityId } };
1678
1679
  return sduiEnvelope(MENU_OP, {
1679
- commentUrn: { commentId, thread: `urn:li:activity:${activityId}` },
1680
+ // Rebuilt in the namespace it came from. A comment threaded to a ugcPost
1681
+ // given an `urn:li:activity:` thread names a different entity, and that
1682
+ // does not error — it acts on the wrong thing or finds nothing.
1683
+ commentUrn: { commentId, thread: `urn:li:${threadType}:${activityId}` },
1680
1684
  updateKey: {
1681
1685
  feedType: 3,
1682
1686
  items: [{ feedUpdateUrn: { updateUrnActivityUrn: activityUrn }, trackingId }],
@@ -1719,11 +1723,11 @@ function extractActionPayload(stream, operation) {
1719
1723
  }
1720
1724
  return null;
1721
1725
  }
1722
- async function fetchCommentMenu(activityId, commentId, trackingId, client) {
1726
+ async function fetchCommentMenu(ref, trackingId, client) {
1723
1727
  const result = await client.request({
1724
1728
  url: actionUrl(MENU_OP),
1725
1729
  method: "POST",
1726
- body: menuBody(activityId, commentId, trackingId),
1730
+ body: menuBody(ref, trackingId),
1727
1731
  spendClass: "page",
1728
1732
  operation: "commentMenu"
1729
1733
  });
@@ -1735,13 +1739,16 @@ async function fetchCommentMenu(activityId, commentId, trackingId, client) {
1735
1739
  const stream = result.classification.raw ?? "";
1736
1740
  return { ok: true, stream };
1737
1741
  }
1738
- function editStates(payload, text2) {
1739
- const named = (field) => {
1740
- const slot = payload[field];
1741
- return typeof slot?.key === "string" ? slot.key : null;
1742
+ function textStates(payload, text2) {
1743
+ const keyOf = (...names) => {
1744
+ for (const n of names) {
1745
+ const slot = payload[n];
1746
+ if (typeof slot?.key === "string") return slot.key;
1747
+ }
1748
+ return null;
1742
1749
  };
1743
- const plain = named("commentary");
1744
- const rich = named("richTextCommentary");
1750
+ const plain = keyOf("commentary", "commentFieldBinding");
1751
+ const rich = keyOf("richTextCommentary", "richCommentFieldBinding");
1745
1752
  if (plain === null || rich === null) return [];
1746
1753
  const entry2 = (key, value, protoCase) => ({
1747
1754
  key,
@@ -1755,8 +1762,11 @@ function editStates(payload, text2) {
1755
1762
  entry2(rich, { text: text2, attribute: [], $type: "TextModel", source: "local" }, "textModelForWrite")
1756
1763
  ];
1757
1764
  }
1765
+ function editStates(payload, text2) {
1766
+ return textStates(payload, text2);
1767
+ }
1758
1768
  async function runCommentAction(ref, operation, trackingId, client, newText) {
1759
- const menu = await fetchCommentMenu(ref.activityId, ref.commentId, trackingId, client);
1769
+ const menu = await fetchCommentMenu(ref, trackingId, client);
1760
1770
  if (!menu.ok) return { ok: false, code: menu.code, message: menu.message };
1761
1771
  const payload = extractActionPayload(menu.stream, operation);
1762
1772
  if (payload === null) {
@@ -1799,10 +1809,22 @@ async function runCommentAction(ref, operation, trackingId, client, newText) {
1799
1809
  return { ok: true, operation };
1800
1810
  }
1801
1811
  function parseCommentUrn(urn) {
1802
- const fsd = /^urn:li:fsd_comment:\((\d+),urn:li:activity:(\d+)\)$/.exec(urn);
1803
- if (fsd !== null) return { commentId: fsd[1], activityId: fsd[2] };
1804
- const plain = /^urn:li:comment:\((?:urn:li:)?activity:(\d+),(\d+)\)$/.exec(urn);
1805
- if (plain !== null) return { activityId: plain[1], commentId: plain[2] };
1812
+ const fsd = /^urn:li:fsd_comment:\((\d+),urn:li:(activity|ugcPost):(\d+)\)$/.exec(urn);
1813
+ if (fsd !== null) {
1814
+ return {
1815
+ commentId: fsd[1],
1816
+ threadType: fsd[2],
1817
+ activityId: fsd[3]
1818
+ };
1819
+ }
1820
+ const plain = /^urn:li:comment:\((?:urn:li:)?(activity|ugcPost):(\d+),(\d+)\)$/.exec(urn);
1821
+ if (plain !== null) {
1822
+ return {
1823
+ threadType: plain[1],
1824
+ activityId: plain[2],
1825
+ commentId: plain[3]
1826
+ };
1827
+ }
1806
1828
  return null;
1807
1829
  }
1808
1830