linkedin-relay-mcp 1.7.0 → 2.0.1
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 +109 -31
- package/dist/cli.js.map +1 -1
- package/dist/index.js +11 -2
- package/dist/index.js.map +1 -1
- package/dist/mcp-shim.js +11 -2
- package/dist/mcp-shim.js.map +1 -1
- package/package.json +1 -1
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(
|
|
1676
|
+
function menuBody(ref, trackingId) {
|
|
1677
|
+
const { activityId, commentId, threadType } = ref;
|
|
1677
1678
|
const activityUrn = { activityUrn: { activityId } };
|
|
1678
1679
|
return sduiEnvelope(MENU_OP, {
|
|
1679
|
-
|
|
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(
|
|
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(
|
|
1730
|
+
body: menuBody(ref, trackingId),
|
|
1727
1731
|
spendClass: "page",
|
|
1728
1732
|
operation: "commentMenu"
|
|
1729
1733
|
});
|
|
@@ -1756,7 +1760,7 @@ function editStates(payload, text2) {
|
|
|
1756
1760
|
];
|
|
1757
1761
|
}
|
|
1758
1762
|
async function runCommentAction(ref, operation, trackingId, client, newText) {
|
|
1759
|
-
const menu = await fetchCommentMenu(ref
|
|
1763
|
+
const menu = await fetchCommentMenu(ref, trackingId, client);
|
|
1760
1764
|
if (!menu.ok) return { ok: false, code: menu.code, message: menu.message };
|
|
1761
1765
|
const payload = extractActionPayload(menu.stream, operation);
|
|
1762
1766
|
if (payload === null) {
|
|
@@ -1799,10 +1803,22 @@ async function runCommentAction(ref, operation, trackingId, client, newText) {
|
|
|
1799
1803
|
return { ok: true, operation };
|
|
1800
1804
|
}
|
|
1801
1805
|
function parseCommentUrn(urn) {
|
|
1802
|
-
const fsd = /^urn:li:fsd_comment:\((\d+),urn:li:activity:(\d+)\)$/.exec(urn);
|
|
1803
|
-
if (fsd !== null)
|
|
1804
|
-
|
|
1805
|
-
|
|
1806
|
+
const fsd = /^urn:li:fsd_comment:\((\d+),urn:li:(activity|ugcPost):(\d+)\)$/.exec(urn);
|
|
1807
|
+
if (fsd !== null) {
|
|
1808
|
+
return {
|
|
1809
|
+
commentId: fsd[1],
|
|
1810
|
+
threadType: fsd[2],
|
|
1811
|
+
activityId: fsd[3]
|
|
1812
|
+
};
|
|
1813
|
+
}
|
|
1814
|
+
const plain = /^urn:li:comment:\((?:urn:li:)?(activity|ugcPost):(\d+),(\d+)\)$/.exec(urn);
|
|
1815
|
+
if (plain !== null) {
|
|
1816
|
+
return {
|
|
1817
|
+
threadType: plain[1],
|
|
1818
|
+
activityId: plain[2],
|
|
1819
|
+
commentId: plain[3]
|
|
1820
|
+
};
|
|
1821
|
+
}
|
|
1806
1822
|
return null;
|
|
1807
1823
|
}
|
|
1808
1824
|
|
|
@@ -2971,8 +2987,8 @@ var COMMANDS = [
|
|
|
2971
2987
|
{
|
|
2972
2988
|
name: "comment",
|
|
2973
2989
|
cost: "1 call \u2014 write",
|
|
2974
|
-
summary: "Add a comment
|
|
2975
|
-
usage: 'lnrelay comment <activity-urn> "<text>"
|
|
2990
|
+
summary: "Add a comment to a post. Harvests its binding tokens from the rendered page; no browser needed, but it costs one heavy read.",
|
|
2991
|
+
usage: 'lnrelay comment <activity-urn> "<text>"\n Fetches the post page (~2.8 MB) to harvest a binding key and trackingId, and proves\n the key belongs to that post before asking. To change a comment, see `edit`.',
|
|
2976
2992
|
audience: ["cli"],
|
|
2977
2993
|
risk: "write",
|
|
2978
2994
|
implemented: true
|
|
@@ -2986,6 +3002,15 @@ var COMMANDS = [
|
|
|
2986
3002
|
risk: "write",
|
|
2987
3003
|
implemented: true
|
|
2988
3004
|
},
|
|
3005
|
+
{
|
|
3006
|
+
name: "edit",
|
|
3007
|
+
cost: "1 read + 1 write",
|
|
3008
|
+
summary: "Change the text of a comment you wrote. Its own verb, so a comment urn can never be mistaken for something to comment ON.",
|
|
3009
|
+
usage: 'lnrelay edit <comment-urn> "<text>"',
|
|
3010
|
+
audience: ["cli"],
|
|
3011
|
+
risk: "write",
|
|
3012
|
+
implemented: true
|
|
3013
|
+
},
|
|
2989
3014
|
{
|
|
2990
3015
|
name: "react",
|
|
2991
3016
|
cost: "1 call \u2014 write",
|
|
@@ -3600,14 +3625,21 @@ async function runComment(postUrn2, text2, now = Date.now(), deps = terminalDeps
|
|
|
3600
3625
|
'lnrelay comment <urn> "<text>"'
|
|
3601
3626
|
);
|
|
3602
3627
|
}
|
|
3603
|
-
|
|
3604
|
-
|
|
3628
|
+
if (parseCommentUrn(postUrn2) !== null) {
|
|
3629
|
+
return err(
|
|
3630
|
+
"comment",
|
|
3631
|
+
"INVALID_INPUT",
|
|
3632
|
+
"that is a comment urn, not a post urn",
|
|
3633
|
+
`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.`
|
|
3634
|
+
);
|
|
3635
|
+
}
|
|
3636
|
+
const activityId = activityIdOf(postUrn2);
|
|
3605
3637
|
if (activityId === null) {
|
|
3606
3638
|
return err(
|
|
3607
3639
|
"comment",
|
|
3608
3640
|
"INVALID_INPUT",
|
|
3609
|
-
`'${postUrn2}'
|
|
3610
|
-
"Pass urn:li:activity:<id
|
|
3641
|
+
`'${postUrn2}' does not identify a post`,
|
|
3642
|
+
"Pass urn:li:activity:<id>."
|
|
3611
3643
|
);
|
|
3612
3644
|
}
|
|
3613
3645
|
if (!deps.isTty) {
|
|
@@ -3627,26 +3659,70 @@ async function runComment(postUrn2, text2, now = Date.now(), deps = terminalDeps
|
|
|
3627
3659
|
if ("ok" in harvested && harvested.ok !== true) return harvested;
|
|
3628
3660
|
if (!("tokens" in harvested)) return harvested;
|
|
3629
3661
|
const plan = {
|
|
3630
|
-
action:
|
|
3631
|
-
payload: {
|
|
3632
|
-
|
|
3633
|
-
|
|
3634
|
-
tokens: harvested.tokens,
|
|
3635
|
-
...editing === null ? {} : { edit: editing }
|
|
3636
|
-
},
|
|
3637
|
-
summary: [
|
|
3638
|
-
authorLine(ctx.transport),
|
|
3639
|
-
`on ${postUrn2}`,
|
|
3640
|
-
`${editing === null ? "content " : "new text"} "${text2}"`
|
|
3641
|
-
],
|
|
3642
|
-
reversibility: editing === null ? "deletable with `lnrelay delete <comment-urn>`; the author is notified immediately" : "editable again; LinkedIn marks the comment edited and the original is not recoverable here",
|
|
3662
|
+
action: "comment on a post",
|
|
3663
|
+
payload: { activityId, text: text2, tokens: harvested.tokens },
|
|
3664
|
+
summary: [authorLine(ctx.transport), `on ${postUrn2}`, `content "${text2}"`],
|
|
3665
|
+
reversibility: "deletable with `lnrelay delete <comment-urn>`; the author is notified immediately",
|
|
3643
3666
|
transport: "voyager"
|
|
3644
3667
|
};
|
|
3645
3668
|
const gated = await gate("comment", plan, ctx, deps);
|
|
3646
3669
|
if ("ok" in gated) return gated;
|
|
3647
|
-
const
|
|
3648
|
-
|
|
3649
|
-
|
|
3670
|
+
const result = await comment(
|
|
3671
|
+
gated.confirmed,
|
|
3672
|
+
createLiveClient(ctx.transport.session)
|
|
3673
|
+
);
|
|
3674
|
+
return result.ok ? ok("comment", { on: postUrn2 }) : err("comment", result.code, result.message, result.hint);
|
|
3675
|
+
}
|
|
3676
|
+
async function runEdit(commentUrn, text2, now = Date.now(), deps = terminalDeps()) {
|
|
3677
|
+
if (commentUrn === void 0 || text2 === void 0 || text2.trim() === "") {
|
|
3678
|
+
return err(
|
|
3679
|
+
"edit",
|
|
3680
|
+
"INVALID_INPUT",
|
|
3681
|
+
"a comment urn and the new text are required",
|
|
3682
|
+
'lnrelay edit <comment-urn> "<text>"'
|
|
3683
|
+
);
|
|
3684
|
+
}
|
|
3685
|
+
const ref = parseCommentUrn(commentUrn);
|
|
3686
|
+
if (ref === null) {
|
|
3687
|
+
return err(
|
|
3688
|
+
"edit",
|
|
3689
|
+
"INVALID_INPUT",
|
|
3690
|
+
`'${commentUrn}' is not a comment urn`,
|
|
3691
|
+
"Only comments can be edited here \u2014 a published post cannot. Get the urn from `lnrelay post <activity-urn>`."
|
|
3692
|
+
);
|
|
3693
|
+
}
|
|
3694
|
+
if (!deps.isTty) {
|
|
3695
|
+
return err(
|
|
3696
|
+
"edit",
|
|
3697
|
+
"CONFIRMATION_REQUIRED",
|
|
3698
|
+
"editing needs a human to confirm it at an interactive terminal",
|
|
3699
|
+
"No terminal is attached, so nothing was sent and no network call was made."
|
|
3700
|
+
);
|
|
3701
|
+
}
|
|
3702
|
+
const ctx = prepare("edit", now, "voyager");
|
|
3703
|
+
if ("ok" in ctx) return ctx;
|
|
3704
|
+
if (ctx.transport.kind !== "voyager") {
|
|
3705
|
+
return err("edit", "NOT_IMPLEMENTED", "editing is only implemented over the private API");
|
|
3706
|
+
}
|
|
3707
|
+
const harvested = await harvest(ref.activityId, ctx.transport.session, now);
|
|
3708
|
+
if (!("tokens" in harvested)) return harvested;
|
|
3709
|
+
const plan = {
|
|
3710
|
+
action: "edit your comment",
|
|
3711
|
+
payload: { urn: commentUrn, text: text2 },
|
|
3712
|
+
summary: [authorLine(ctx.transport), `comment ${commentUrn}`, `new text "${text2}"`],
|
|
3713
|
+
reversibility: "editable again, but the previous text is NOT recoverable here and LinkedIn marks the comment as edited",
|
|
3714
|
+
transport: "voyager"
|
|
3715
|
+
};
|
|
3716
|
+
const gated = await gate("edit", plan, ctx, deps);
|
|
3717
|
+
if ("ok" in gated) return gated;
|
|
3718
|
+
const result = await runCommentAction(
|
|
3719
|
+
ref,
|
|
3720
|
+
UPDATE_OP,
|
|
3721
|
+
harvested.tokens.trackingId,
|
|
3722
|
+
createLiveClient(ctx.transport.session),
|
|
3723
|
+
text2
|
|
3724
|
+
);
|
|
3725
|
+
return result.ok ? ok("edit", { edited: commentUrn }) : err("edit", result.code, result.message, result.hint);
|
|
3650
3726
|
}
|
|
3651
3727
|
var REACTIONS2 = REACTIONS;
|
|
3652
3728
|
async function runReact(postUrn2, type, now = Date.now(), deps = terminalDeps(), remove = false) {
|
|
@@ -3843,6 +3919,8 @@ async function dispatch(argv, now) {
|
|
|
3843
3919
|
}
|
|
3844
3920
|
case "comment":
|
|
3845
3921
|
return runComment(args.positionals[0], args.positionals[1], now);
|
|
3922
|
+
case "edit":
|
|
3923
|
+
return runEdit(args.positionals[0], args.positionals[1], now);
|
|
3846
3924
|
case "react":
|
|
3847
3925
|
return runReact(
|
|
3848
3926
|
args.positionals[0],
|