linkedin-relay-mcp 2.0.1 → 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 +162 -7
- package/dist/cli.js.map +1 -1
- package/dist/index.js +9 -0
- package/dist/index.js.map +1 -1
- package/dist/mcp-shim.js +9 -0
- package/dist/mcp-shim.js.map +1 -1
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -1739,13 +1739,19 @@ async function fetchCommentMenu(ref, trackingId, client) {
|
|
|
1739
1739
|
const stream = result.classification.raw ?? "";
|
|
1740
1740
|
return { ok: true, stream };
|
|
1741
1741
|
}
|
|
1742
|
-
function
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1742
|
+
function boxStateId(parent) {
|
|
1743
|
+
return `urn:li:comment:(urn:li:${parent.threadType}:${parent.activityId},${parent.commentId})`;
|
|
1744
|
+
}
|
|
1745
|
+
function textStates(payload, text2) {
|
|
1746
|
+
const keyOf = (...names) => {
|
|
1747
|
+
for (const n of names) {
|
|
1748
|
+
const slot = payload[n];
|
|
1749
|
+
if (typeof slot?.key === "string") return slot.key;
|
|
1750
|
+
}
|
|
1751
|
+
return null;
|
|
1746
1752
|
};
|
|
1747
|
-
const plain =
|
|
1748
|
-
const rich =
|
|
1753
|
+
const plain = keyOf("commentary", "commentFieldBinding");
|
|
1754
|
+
const rich = keyOf("richTextCommentary", "richCommentFieldBinding");
|
|
1749
1755
|
if (plain === null || rich === null) return [];
|
|
1750
1756
|
const entry2 = (key, value, protoCase) => ({
|
|
1751
1757
|
key,
|
|
@@ -1759,6 +1765,9 @@ function editStates(payload, text2) {
|
|
|
1759
1765
|
entry2(rich, { text: text2, attribute: [], $type: "TextModel", source: "local" }, "textModelForWrite")
|
|
1760
1766
|
];
|
|
1761
1767
|
}
|
|
1768
|
+
function editStates(payload, text2) {
|
|
1769
|
+
return textStates(payload, text2);
|
|
1770
|
+
}
|
|
1762
1771
|
async function runCommentAction(ref, operation, trackingId, client, newText) {
|
|
1763
1772
|
const menu = await fetchCommentMenu(ref, trackingId, client);
|
|
1764
1773
|
if (!menu.ok) return { ok: false, code: menu.code, message: menu.message };
|
|
@@ -1821,6 +1830,90 @@ function parseCommentUrn(urn) {
|
|
|
1821
1830
|
}
|
|
1822
1831
|
return null;
|
|
1823
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
|
+
}
|
|
1824
1917
|
|
|
1825
1918
|
// src/engine/session.ts
|
|
1826
1919
|
var SESSION_FILE = "session.json";
|
|
@@ -3002,6 +3095,15 @@ var COMMANDS = [
|
|
|
3002
3095
|
risk: "write",
|
|
3003
3096
|
implemented: true
|
|
3004
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
|
+
},
|
|
3005
3107
|
{
|
|
3006
3108
|
name: "edit",
|
|
3007
3109
|
cost: "1 read + 1 write",
|
|
@@ -3630,7 +3732,7 @@ async function runComment(postUrn2, text2, now = Date.now(), deps = terminalDeps
|
|
|
3630
3732
|
"comment",
|
|
3631
3733
|
"INVALID_INPUT",
|
|
3632
3734
|
"that is a comment urn, not a post urn",
|
|
3633
|
-
`To change its text: lnrelay edit ${postUrn2} "<text>".
|
|
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.`
|
|
3634
3736
|
);
|
|
3635
3737
|
}
|
|
3636
3738
|
const activityId = activityIdOf(postUrn2);
|
|
@@ -3764,6 +3866,57 @@ async function runReact(postUrn2, type, now = Date.now(), deps = terminalDeps(),
|
|
|
3764
3866
|
const result = await react(gated.confirmed, createLiveClient(ctx.transport.session));
|
|
3765
3867
|
return result.ok ? ok("react", { id: result.id, removed: remove }) : err("react", result.code, result.message, result.hint);
|
|
3766
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
|
+
}
|
|
3767
3920
|
|
|
3768
3921
|
// src/entry.ts
|
|
3769
3922
|
import { realpathSync } from "fs";
|
|
@@ -3921,6 +4074,8 @@ async function dispatch(argv, now) {
|
|
|
3921
4074
|
return runComment(args.positionals[0], args.positionals[1], now);
|
|
3922
4075
|
case "edit":
|
|
3923
4076
|
return runEdit(args.positionals[0], args.positionals[1], now);
|
|
4077
|
+
case "reply":
|
|
4078
|
+
return runReply(args.positionals[0], args.positionals[1], now);
|
|
3924
4079
|
case "react":
|
|
3925
4080
|
return runReact(
|
|
3926
4081
|
args.positionals[0],
|