linkedin-relay-mcp 2.1.0 → 2.2.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
@@ -1739,6 +1739,9 @@ async function fetchCommentMenu(ref, trackingId, client) {
1739
1739
  const stream = result.classification.raw ?? "";
1740
1740
  return { ok: true, stream };
1741
1741
  }
1742
+ function boxStateId(parent) {
1743
+ return `urn:li:comment:(urn:li:${parent.threadType}:${parent.activityId},${parent.commentId})`;
1744
+ }
1742
1745
  function textStates(payload, text2) {
1743
1746
  const keyOf = (...names) => {
1744
1747
  for (const n of names) {
@@ -1827,6 +1830,90 @@ function parseCommentUrn(urn) {
1827
1830
  }
1828
1831
  return null;
1829
1832
  }
1833
+ var SUBMIT_COMPONENT = "com.linkedin.sdui.generated.comments.dsl.impl.submitCommentButton";
1834
+ var CREATE_OP = "com.linkedin.sdui.comments.createComment";
1835
+ var COMPONENT_URL = "https://www.linkedin.com/flagship-web/rsc-action/actions/component";
1836
+ async function fetchReplyAction(postActivityId, parent, trackingId, client) {
1837
+ const activityUrn = { activityUrn: { activityId: postActivityId } };
1838
+ const body = {
1839
+ clientArguments: {
1840
+ payload: {
1841
+ collection: {
1842
+ updateKey: {
1843
+ feedType: 3,
1844
+ items: [{ feedUpdateUrn: { updateUrnActivityUrn: activityUrn }, trackingId }],
1845
+ aggregationType: 0,
1846
+ isVideoCarousel: false
1847
+ },
1848
+ threadUrn: { threadUrnActivityThreadUrn: activityUrn }
1849
+ },
1850
+ // Keying the box to the PARENT COMMENT is what makes this a reply.
1851
+ commentBoxStateId: boxStateId(parent)
1852
+ },
1853
+ states: [],
1854
+ requestMetadata: { $type: "proto.sdui.common.RequestMetadata" },
1855
+ screenId: SCREEN_ID,
1856
+ knownTemplateIds: []
1857
+ }
1858
+ };
1859
+ const result = await client.request({
1860
+ url: `${COMPONENT_URL}?componentId=${SUBMIT_COMPONENT}&sduiid=${SUBMIT_COMPONENT}`,
1861
+ method: "POST",
1862
+ body,
1863
+ spendClass: "page",
1864
+ operation: "replyBox"
1865
+ });
1866
+ if (!result.ok) return { ok: false, code: result.code, message: result.message };
1867
+ const stream = result.classification.raw ?? "";
1868
+ const payload = extractActionPayload(stream, CREATE_OP);
1869
+ if (payload === null) {
1870
+ return {
1871
+ ok: false,
1872
+ code: "NOT_IMPLEMENTED",
1873
+ message: "the reply box did not declare a createComment action",
1874
+ hint: "Replies may be closed on this post, or the component shape changed. Nothing was sent."
1875
+ };
1876
+ }
1877
+ const bound = payload.commentFieldBinding?.key;
1878
+ if (typeof bound !== "string" || !bound.includes(boxStateId(parent))) {
1879
+ return {
1880
+ ok: false,
1881
+ code: "SCHEMA_DRIFT",
1882
+ message: "the reply box came back bound to something other than the parent comment",
1883
+ hint: "Refusing to send \u2014 this is how a reply becomes a top-level comment."
1884
+ };
1885
+ }
1886
+ return { ok: true, payload };
1887
+ }
1888
+ async function replyToComment(postActivityId, parent, text2, trackingId, client) {
1889
+ const action = await fetchReplyAction(postActivityId, parent, trackingId, client);
1890
+ if (!action.ok) {
1891
+ const out = { ok: false, code: action.code, message: action.message };
1892
+ if (action.hint !== void 0) out.hint = action.hint;
1893
+ return out;
1894
+ }
1895
+ const states2 = textStates(action.payload, text2);
1896
+ if (states2.length === 0) {
1897
+ return {
1898
+ ok: false,
1899
+ code: "SCHEMA_DRIFT",
1900
+ message: "the reply box did not name its text bindings, so a reply cannot be built"
1901
+ };
1902
+ }
1903
+ const result = await client.request({
1904
+ url: actionUrl(CREATE_OP),
1905
+ method: "POST",
1906
+ body: sduiEnvelope(CREATE_OP, action.payload, states2),
1907
+ spendClass: "write",
1908
+ operation: "reply"
1909
+ });
1910
+ if (!result.ok) {
1911
+ const out = { ok: false, code: result.code, message: result.message };
1912
+ if (result.hint !== void 0) out.hint = result.hint;
1913
+ return out;
1914
+ }
1915
+ return { ok: true, operation: CREATE_OP };
1916
+ }
1830
1917
 
1831
1918
  // src/engine/session.ts
1832
1919
  var SESSION_FILE = "session.json";
@@ -3008,6 +3095,15 @@ var COMMANDS = [
3008
3095
  risk: "write",
3009
3096
  implemented: true
3010
3097
  },
3098
+ {
3099
+ name: "reply",
3100
+ cost: "1 read + 1 write",
3101
+ summary: "Reply to a comment. Its own verb \u2014 a reply and a top-level comment differ only by which binding the server hands back, so guessing is not survivable.",
3102
+ usage: 'lnrelay reply <comment-urn> "<text>"',
3103
+ audience: ["cli"],
3104
+ risk: "write",
3105
+ implemented: true
3106
+ },
3011
3107
  {
3012
3108
  name: "edit",
3013
3109
  cost: "1 read + 1 write",
@@ -3636,7 +3732,7 @@ async function runComment(postUrn2, text2, now = Date.now(), deps = terminalDeps
3636
3732
  "comment",
3637
3733
  "INVALID_INPUT",
3638
3734
  "that is a comment urn, not a post urn",
3639
- `To change its text: lnrelay edit ${postUrn2} "<text>". Replying to a comment is not implemented \u2014 pass the POST urn to add a top-level comment.`
3735
+ `To change its text: lnrelay edit ${postUrn2} "<text>". To answer it: lnrelay reply ${postUrn2} "<text>". Pass the POST urn to add a top-level comment.`
3640
3736
  );
3641
3737
  }
3642
3738
  const activityId = activityIdOf(postUrn2);
@@ -3770,6 +3866,57 @@ async function runReact(postUrn2, type, now = Date.now(), deps = terminalDeps(),
3770
3866
  const result = await react(gated.confirmed, createLiveClient(ctx.transport.session));
3771
3867
  return result.ok ? ok("react", { id: result.id, removed: remove }) : err("react", result.code, result.message, result.hint);
3772
3868
  }
3869
+ async function runReply(commentUrn, text2, now = Date.now(), deps = terminalDeps()) {
3870
+ if (commentUrn === void 0 || text2 === void 0 || text2.trim() === "") {
3871
+ return err(
3872
+ "reply",
3873
+ "INVALID_INPUT",
3874
+ "a comment urn and the reply text are required",
3875
+ 'lnrelay reply <comment-urn> "<text>"'
3876
+ );
3877
+ }
3878
+ const parent = parseCommentUrn(commentUrn);
3879
+ if (parent === null) {
3880
+ return err(
3881
+ "reply",
3882
+ "INVALID_INPUT",
3883
+ `'${commentUrn}' is not a comment urn`,
3884
+ "To comment on a POST, use `lnrelay comment <activity-urn>`. Comment urns come from `lnrelay post <activity-urn>`."
3885
+ );
3886
+ }
3887
+ if (!deps.isTty) {
3888
+ return err(
3889
+ "reply",
3890
+ "CONFIRMATION_REQUIRED",
3891
+ "replying needs a human to confirm it at an interactive terminal",
3892
+ "No terminal is attached, so nothing was sent and no network call was made."
3893
+ );
3894
+ }
3895
+ const ctx = prepare("reply", now, "voyager");
3896
+ if ("ok" in ctx) return ctx;
3897
+ if (ctx.transport.kind !== "voyager") {
3898
+ return err("reply", "NOT_IMPLEMENTED", "replying is only implemented over the private API");
3899
+ }
3900
+ const harvested = await harvest(parent.activityId, ctx.transport.session, now);
3901
+ if (!("tokens" in harvested)) return harvested;
3902
+ const plan = {
3903
+ action: "reply to a comment",
3904
+ payload: { parent: commentUrn, text: text2 },
3905
+ summary: [authorLine(ctx.transport), `replying to ${commentUrn}`, `content "${text2}"`],
3906
+ reversibility: "deletable with `lnrelay delete <the reply urn>`; the comment author is notified immediately",
3907
+ transport: "voyager"
3908
+ };
3909
+ const gated = await gate("reply", plan, ctx, deps);
3910
+ if ("ok" in gated) return gated;
3911
+ const result = await replyToComment(
3912
+ parent.activityId,
3913
+ parent,
3914
+ text2,
3915
+ harvested.tokens.trackingId,
3916
+ createLiveClient(ctx.transport.session)
3917
+ );
3918
+ return result.ok ? ok("reply", { repliedTo: commentUrn }) : err("reply", result.code, result.message, result.hint);
3919
+ }
3773
3920
 
3774
3921
  // src/entry.ts
3775
3922
  import { realpathSync } from "fs";
@@ -3927,6 +4074,8 @@ async function dispatch(argv, now) {
3927
4074
  return runComment(args.positionals[0], args.positionals[1], now);
3928
4075
  case "edit":
3929
4076
  return runEdit(args.positionals[0], args.positionals[1], now);
4077
+ case "reply":
4078
+ return runReply(args.positionals[0], args.positionals[1], now);
3930
4079
  case "react":
3931
4080
  return runReact(
3932
4081
  args.positionals[0],