linkedin-relay-mcp 3.7.0 → 3.9.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/mcp-shim.js CHANGED
@@ -2055,6 +2055,24 @@ var COMMANDS = [
2055
2055
  risk: "read",
2056
2056
  implemented: true
2057
2057
  },
2058
+ {
2059
+ name: "experience",
2060
+ cost: "2 calls",
2061
+ summary: "The roles on your own profile, with the position id `role edit|remove` takes.",
2062
+ usage: "lnrelay experience",
2063
+ audience: ["cli", "mcp"],
2064
+ risk: "read",
2065
+ implemented: true
2066
+ },
2067
+ {
2068
+ name: "skills",
2069
+ cost: "3 calls",
2070
+ summary: "The skills on your own profile, with the skill id `skill remove` takes.",
2071
+ usage: "lnrelay skills",
2072
+ audience: ["cli", "mcp"],
2073
+ risk: "read",
2074
+ implemented: true
2075
+ },
2058
2076
  {
2059
2077
  name: "local",
2060
2078
  cost: "free \u2014 local cache",
@@ -2146,6 +2164,24 @@ var COMMANDS = [
2146
2164
  risk: "write",
2147
2165
  implemented: true
2148
2166
  },
2167
+ {
2168
+ name: "role",
2169
+ cost: "3-4 reads + 1 write",
2170
+ summary: "Add, edit or remove a role in your Experience. Never rewrites your headline; notify network is off unless --notify.",
2171
+ usage: 'lnrelay role add --title "<t>" --company "<c>" --start YYYY-MM [--end YYYY-MM | --current]\n [--location "<l>"] [--description "<d>" | --description-file <path>] [--notify]\n lnrelay role edit <position-id> [any of the flags above]\n lnrelay role remove <position-id>\n Position ids come from `lnrelay experience`. The preview shows the role as it is and\n as it will be; the result is read back from the profile. A role with media attached\n is refused. The company is free text (not linked to a company page).',
2172
+ audience: ["cli"],
2173
+ risk: "write",
2174
+ implemented: true
2175
+ },
2176
+ {
2177
+ name: "skill",
2178
+ cost: "4-5 reads + 1 write",
2179
+ summary: "Add a skill to your profile, or remove one.",
2180
+ usage: 'lnrelay skill add "<name>"\n lnrelay skill remove <skill-id>\n Skill ids come from `lnrelay skills`. A skill is added as free text, linked to no role,\n school or project. Removing a skill removes its endorsements with it.',
2181
+ audience: ["cli"],
2182
+ risk: "write",
2183
+ implemented: true
2184
+ },
2149
2185
  {
2150
2186
  name: "react",
2151
2187
  cost: "1 call \u2014 write",
@@ -2161,9 +2197,616 @@ function mcpCommands() {
2161
2197
  return COMMANDS.filter((c) => c.audience.includes("mcp") && c.risk !== "write");
2162
2198
  }
2163
2199
 
2200
+ // src/engine/sdui-form.ts
2201
+ function balanced(s, start) {
2202
+ const open = s[start];
2203
+ const close = open === "[" ? "]" : "}";
2204
+ let depth = 0;
2205
+ let inString = false;
2206
+ let escaped = false;
2207
+ for (let i = start; i < s.length; i++) {
2208
+ const ch = s[i];
2209
+ if (escaped) escaped = false;
2210
+ else if (ch === "\\") escaped = true;
2211
+ else if (ch === '"') inString = !inString;
2212
+ else if (!inString && ch === open) depth++;
2213
+ else if (!inString && ch === close) {
2214
+ depth--;
2215
+ if (depth === 0) return s.slice(start, i + 1);
2216
+ }
2217
+ }
2218
+ return null;
2219
+ }
2220
+ function parseAt(s, start) {
2221
+ const text2 = start < 0 ? null : balanced(s, start);
2222
+ if (text2 === null) return null;
2223
+ try {
2224
+ return JSON.parse(text2);
2225
+ } catch {
2226
+ return null;
2227
+ }
2228
+ }
2229
+ function plain(v) {
2230
+ const protoCase = String(v.$case);
2231
+ const raw = v[protoCase];
2232
+ if (protoCase === "stringListValue") {
2233
+ return { protoCase, value: raw?.stringValues ?? [] };
2234
+ }
2235
+ if (protoCase === "signedLongValue" && typeof raw === "string" && raw.startsWith("$n")) {
2236
+ return { protoCase, value: { type: "bigint", value: raw.slice(2) } };
2237
+ }
2238
+ return { protoCase, value: raw };
2239
+ }
2240
+ function readModel(stream) {
2241
+ const at = stream.indexOf('"modelStates":[');
2242
+ const entries = parseAt(stream, at === -1 ? -1 : stream.indexOf("[", at));
2243
+ if (entries === null) return null;
2244
+ const model = /* @__PURE__ */ new Map();
2245
+ for (const entry2 of entries) {
2246
+ const id = entry2.key?.key?.value?.id;
2247
+ if (id !== void 0 && entry2.value !== void 0 && !model.has(id)) {
2248
+ model.set(id, plain(entry2.value));
2249
+ }
2250
+ }
2251
+ return model;
2252
+ }
2253
+ function findRequest(stream, requestId) {
2254
+ const at = stream.indexOf(`"requestId":"${requestId}","requestedArguments":`);
2255
+ if (at === -1) return null;
2256
+ const args = parseAt(
2257
+ stream,
2258
+ stream.indexOf("{", stream.indexOf('"requestedArguments":', at))
2259
+ );
2260
+ return args !== null && Array.isArray(args.requestedStateKeys) && args.payload !== void 0 ? args : null;
2261
+ }
2262
+ var unknownExpression = (what) => ({
2263
+ ok: false,
2264
+ code: "SCHEMA_DRIFT",
2265
+ message: `the form computes a value with an expression this tool does not evaluate (${what})`,
2266
+ hint: "Nothing was sent. Re-capture the form to see what it has become."
2267
+ });
2268
+ function boundId(body) {
2269
+ return body?.key?.key?.value?.id;
2270
+ }
2271
+ function str(node, model) {
2272
+ const e = node.expression;
2273
+ if (e?.$case === "stringValue") return String(e.stringValue);
2274
+ if (e?.$case === "bindableString") {
2275
+ const v = model.get(boundId(e.bindableString) ?? "")?.value;
2276
+ return typeof v === "string" ? v : "";
2277
+ }
2278
+ return null;
2279
+ }
2280
+ function bool(node, model) {
2281
+ const e = node.expression;
2282
+ const body = e?.[e?.$case ?? ""];
2283
+ switch (e?.$case) {
2284
+ case "booleanExpression":
2285
+ return bool(body, model);
2286
+ case "booleanValue":
2287
+ return e.booleanValue === true;
2288
+ case "bindableBoolean":
2289
+ return model.get(boundId(e.bindableBoolean) ?? "")?.value === true;
2290
+ case "notExpression": {
2291
+ const a = bool(body?.a ?? {}, model);
2292
+ return a === null ? null : !a;
2293
+ }
2294
+ case "orExpression":
2295
+ case "andExpression": {
2296
+ const a = bool(body?.a ?? {}, model);
2297
+ const b = bool(body?.b ?? {}, model);
2298
+ if (a === null || b === null) return null;
2299
+ return e.$case === "orExpression" ? a || b : a && b;
2300
+ }
2301
+ case "stringEqualsExpression": {
2302
+ const a = str(body?.a ?? {}, model);
2303
+ const b = str(body?.b ?? {}, model);
2304
+ if (a === null || b === null) return null;
2305
+ return body.ignoreCase === true ? a.toLowerCase() === b.toLowerCase() : a === b;
2306
+ }
2307
+ default:
2308
+ return null;
2309
+ }
2310
+ }
2311
+ function evaluate(expression, model) {
2312
+ const value = bool(expression, model);
2313
+ return value === null ? unknownExpression(JSON.stringify(expression).slice(0, 80)) : { ok: true, value };
2314
+ }
2315
+ function wireStates(keys, model, resolve) {
2316
+ const out = [];
2317
+ for (const id of keys) {
2318
+ const state = model.get(id);
2319
+ if (state === void 0) continue;
2320
+ let value = state.value;
2321
+ if (state.protoCase === "expression") {
2322
+ const r = resolve(id, state) ?? evaluate(state.value, model);
2323
+ if (!r.ok) return r;
2324
+ value = r.value;
2325
+ }
2326
+ out.push({
2327
+ key: id,
2328
+ namespace: "MemoryNamespace",
2329
+ value,
2330
+ originalProtoCase: state.protoCase,
2331
+ protoKey: { $type: "proto.sdui.Key", value: { $case: "id", id } }
2332
+ });
2333
+ }
2334
+ return out;
2335
+ }
2336
+ var keysOf = (args) => args.requestedStateKeys.map((k) => k.key.value.id);
2337
+ function requestBody(requestId, args, states, screen) {
2338
+ const requestedArguments = {
2339
+ $type: "proto.sdui.actions.requests.RequestedArguments",
2340
+ requestedStateKeys: args.requestedStateKeys,
2341
+ payload: args.payload,
2342
+ requestMetadata: { $type: "proto.sdui.common.RequestMetadata" }
2343
+ };
2344
+ return {
2345
+ requestId,
2346
+ serverRequest: {
2347
+ requestId,
2348
+ requestedArguments,
2349
+ isApfcEnabled: false,
2350
+ isStreaming: false,
2351
+ rumPageKey: ""
2352
+ },
2353
+ states,
2354
+ requestedArguments: { ...requestedArguments, states, screenId: screen, knownTemplateIds: [] }
2355
+ };
2356
+ }
2357
+ function navBody(screen, payload) {
2358
+ return {
2359
+ clientArguments: {
2360
+ $type: "proto.sdui.actions.requests.RequestedArguments",
2361
+ requestedStateKeys: [],
2362
+ payload,
2363
+ requestMetadata: { $type: "proto.sdui.common.RequestMetadata" },
2364
+ states: [],
2365
+ screenId: screen,
2366
+ knownTemplateIds: []
2367
+ },
2368
+ isModal: true
2369
+ };
2370
+ }
2371
+ function responseErrors(raw) {
2372
+ return raw.match(/"errors":\[([^\]]+)\]/)?.[1]?.slice(0, 300) ?? null;
2373
+ }
2374
+
2375
+ // src/engine/sdui-profile.ts
2376
+ var NAV_URL = "https://www.linkedin.com/flagship-web/rsc-action/actions/navigation";
2377
+ var ACTION_URL = "https://www.linkedin.com/flagship-web/rsc-action/actions/server-request";
2378
+ var PROFILE_FIELDS = {
2379
+ headline: {
2380
+ name: "headline",
2381
+ screen: "com.linkedin.sdui.flagshipnav.profile.ProfileEditIntroForm",
2382
+ save: "com.linkedin.sdui.requests.profile.saveProfileIntroForm",
2383
+ binding: "headline",
2384
+ // The web form refuses more ("Exceeded maximum length of 220 characters").
2385
+ maxLength: 220
2386
+ },
2387
+ about: {
2388
+ name: "about",
2389
+ screen: "com.linkedin.sdui.flagshipnav.profile.ProfileAboutForm",
2390
+ save: "com.linkedin.sdui.requests.profile.saveProfileAboutForm",
2391
+ binding: "about",
2392
+ maxLength: 2600
2393
+ }
2394
+ };
2395
+ var drift2 = (message) => ({
2396
+ ok: false,
2397
+ code: "SCHEMA_DRIFT",
2398
+ message,
2399
+ hint: "Re-capture the profile form with scripts/observe-write.ts (edit one character, then revert)."
2400
+ });
2401
+ async function openForm(screen, payload, client, operation) {
2402
+ const result = await client.request({
2403
+ url: `${NAV_URL}?screenId=${screen}&sduiid=${screen}`,
2404
+ method: "POST",
2405
+ body: navBody(screen, payload),
2406
+ spendClass: "page",
2407
+ operation
2408
+ });
2409
+ if (!result.ok) {
2410
+ const out = { ok: false, code: result.code, message: result.message };
2411
+ if (result.hint !== void 0) out.hint = result.hint;
2412
+ return out;
2413
+ }
2414
+ return result.classification.raw ?? "";
2415
+ }
2416
+ async function sendAction(requestId, body, client, operation, spendClass = "write") {
2417
+ const result = await client.request({
2418
+ url: `${ACTION_URL}?sduiid=${requestId}`,
2419
+ method: "POST",
2420
+ body,
2421
+ spendClass,
2422
+ operation
2423
+ });
2424
+ if (!result.ok) {
2425
+ const out = { ok: false, code: result.code, message: result.message };
2426
+ if (result.hint !== void 0) out.hint = result.hint;
2427
+ return out;
2428
+ }
2429
+ const raw = result.classification.raw ?? "";
2430
+ const errors = responseErrors(raw);
2431
+ if (errors !== null) {
2432
+ return { ok: false, code: "INVALID_INPUT", message: `LinkedIn refused it: ${errors}` };
2433
+ }
2434
+ return raw;
2435
+ }
2436
+
2437
+ // src/engine/sdui-position.ts
2438
+ var POSITION = {
2439
+ addScreen: "com.linkedin.sdui.flagshipnav.profile.ProfilePositionAddForm",
2440
+ editScreen: "com.linkedin.sdui.flagshipnav.profile.ProfilePositionDetailsEditForm",
2441
+ listScreen: "com.linkedin.sdui.flagshipnav.profile.ProfileExperienceDetails",
2442
+ media: "com.linkedin.sdui.impl.profile.components.forms.uploadPositionMedia",
2443
+ save: "com.linkedin.sdui.requests.profile.saveProfilePositionForm",
2444
+ delete: "com.linkedin.sdui.requests.profile.deleteProfilePositionForm"
2445
+ };
2446
+ var EDIT_NAV = `{"$type":"proto.sdui.actions.core.NavigateToScreen","screenId":"${POSITION.editScreen}"`;
2447
+ function listPositions(stream) {
2448
+ if (readModel(stream) === null && !stream.includes(EDIT_NAV) && !stream.includes('"rows"')) {
2449
+ return drift2("the Experience screen could not be read");
2450
+ }
2451
+ const positions = [];
2452
+ const seen = /* @__PURE__ */ new Set();
2453
+ let i = 0;
2454
+ for (; ; ) {
2455
+ i = stream.indexOf(EDIT_NAV, i);
2456
+ if (i === -1) break;
2457
+ const text2 = balanced(stream, i);
2458
+ i += EDIT_NAV.length;
2459
+ if (text2 === null) continue;
2460
+ const payload = JSON.parse(text2).requestedArguments?.payload;
2461
+ const id = payload?.positionId;
2462
+ if (typeof id !== "string" || seen.has(id) || payload === void 0) continue;
2463
+ seen.add(id);
2464
+ positions.push({ positionId: id, title: String(payload.title ?? ""), payload });
2465
+ }
2466
+ if (positions.length === 0 && !stream.includes('"rows"') && !stream.includes("Experience")) {
2467
+ return drift2("the Experience screen listed no roles and did not look like one");
2468
+ }
2469
+ return { ok: true, positions };
2470
+ }
2471
+ function readPositionForm(stream) {
2472
+ const model = readModel(stream);
2473
+ if (model === null) return drift2("the position form carried no initial values");
2474
+ const media = findRequest(stream, POSITION.media);
2475
+ const prefix = media?.payload.formIdPrefix;
2476
+ if (media === null || typeof prefix !== "string") {
2477
+ return drift2("the position form carried no save step (uploadPositionMedia)");
2478
+ }
2479
+ const del = findRequest(stream, POSITION.delete);
2480
+ return {
2481
+ ok: true,
2482
+ model,
2483
+ prefix,
2484
+ media,
2485
+ del,
2486
+ screen: del === null ? POSITION.addScreen : POSITION.editScreen
2487
+ };
2488
+ }
2489
+ function noMedia(model) {
2490
+ const count2 = [...model.entries()].find(
2491
+ ([k]) => k.endsWith("position-mediaUiCollection-mediaCount")
2492
+ )?.[1].value;
2493
+ return typeof count2 === "number" && count2 > 0 ? {
2494
+ ok: false,
2495
+ code: "NOT_IMPLEMENTED",
2496
+ message: "this role has media attached, and saving one with media has not been verified",
2497
+ hint: "Edit it in the browser for now; nothing was changed."
2498
+ } : null;
2499
+ }
2500
+ var resolver = (key) => key.endsWith("position-mediaIds") ? { ok: true, value: [] } : void 0;
2501
+ function mediaBody(form, model) {
2502
+ const refused = noMedia(model);
2503
+ if (refused !== null) return refused;
2504
+ const states = wireStates(keysOf(form.media), model, resolver);
2505
+ if (!Array.isArray(states)) return states;
2506
+ return { ok: true, body: requestBody(POSITION.media, form.media, states, form.screen) };
2507
+ }
2508
+ function saveFromReply(reply2) {
2509
+ const args = findRequest(reply2, POSITION.save);
2510
+ return args === null ? drift2("the media step did not hand back the save action") : { ok: true, args };
2511
+ }
2512
+ function positionSaveBody(save, model, screen) {
2513
+ const sending = new Map(model);
2514
+ for (const [k, v] of sending)
2515
+ if (k.endsWith("isActiveProfileFormLoading")) sending.set(k, { ...v, value: true });
2516
+ const states = wireStates(keysOf(save), sending, resolver);
2517
+ if (!Array.isArray(states)) return states;
2518
+ return { ok: true, body: requestBody(POSITION.save, save, states, screen) };
2519
+ }
2520
+ function deleteBody(form) {
2521
+ if (form.del === null)
2522
+ return drift2("this form has no delete action (it is not an existing role)");
2523
+ const states = wireStates(keysOf(form.del), form.model, resolver);
2524
+ if (!Array.isArray(states)) return states;
2525
+ return { ok: true, body: requestBody(POSITION.delete, form.del, states, form.screen) };
2526
+ }
2527
+ async function fetchPositions(vanityName, client) {
2528
+ const stream = await openForm(
2529
+ POSITION.listScreen,
2530
+ { vanityName, isVanityNameResolved: true },
2531
+ client,
2532
+ "experience-list"
2533
+ );
2534
+ return typeof stream === "string" ? listPositions(stream) : stream;
2535
+ }
2536
+ async function openPositionForm(payload, client, edit) {
2537
+ const stream = await openForm(
2538
+ edit ? POSITION.editScreen : POSITION.addScreen,
2539
+ { ...payload, isVanityNameResolved: true },
2540
+ client,
2541
+ edit ? "position-edit-form" : "position-add-form"
2542
+ );
2543
+ return typeof stream === "string" ? readPositionForm(stream) : stream;
2544
+ }
2545
+ async function sendPositionSave(form, model, client) {
2546
+ const media = mediaBody(form, model);
2547
+ if (!media.ok) return media;
2548
+ const reply2 = await sendAction(POSITION.media, media.body, client, "position-media-step", "page");
2549
+ if (typeof reply2 !== "string") return reply2;
2550
+ const save = saveFromReply(reply2);
2551
+ if (!save.ok) return save;
2552
+ const body = positionSaveBody(save.args, model, form.screen);
2553
+ if (!body.ok) return body;
2554
+ const sent = await sendAction(POSITION.save, body.body, client, "position-save");
2555
+ return typeof sent === "string" ? { ok: true } : sent;
2556
+ }
2557
+ async function sendPositionDelete(form, client) {
2558
+ const body = deleteBody(form);
2559
+ if (!body.ok) return body;
2560
+ const sent = await sendAction(POSITION.delete, body.body, client, "position-delete");
2561
+ return typeof sent === "string" ? { ok: true } : sent;
2562
+ }
2563
+
2564
+ // src/commands/gate.ts
2565
+ import { createInterface } from "readline/promises";
2566
+
2567
+ // src/commands/approval.ts
2568
+ import { appendFileSync, mkdirSync as mkdirSync3 } from "fs";
2569
+ import { dirname as dirname2 } from "path";
2570
+
2571
+ // src/commands/confirm.ts
2572
+ import { createHash } from "crypto";
2573
+
2574
+ // src/commands/write.ts
2575
+ import { readFileSync as readFileSync2, statSync } from "fs";
2576
+ import { basename } from "path";
2577
+
2578
+ // src/engine/sdui-comment.ts
2579
+ var SDUI_ACTION = "https://www.linkedin.com/flagship-web/rsc-action/actions/server-request";
2580
+ var COMMENT_URL = `${SDUI_ACTION}?sduiid=com.linkedin.sdui.comments.createComment`;
2581
+
2582
+ // src/engine/voyager-reply.ts
2583
+ var REPLY_DECORATION = "com.linkedin.voyager.dash.deco.social.NormComment-43";
2584
+ var REPLY_URL = `https://www.linkedin.com/voyager/api/voyagerSocialDashNormComments?decorationId=${REPLY_DECORATION}`;
2585
+
2586
+ // src/engine/voyager-write.ts
2587
+ import { createHash as createHash2 } from "crypto";
2588
+ var VOYAGER2 = "https://www.linkedin.com/voyager/api";
2589
+ var SHARE_URL = `${VOYAGER2}/contentcreation/normShares`;
2590
+
2591
+ // src/commands/token.ts
2592
+ import { existsSync as existsSync3, rmSync } from "fs";
2593
+
2594
+ // src/engine/oauth.ts
2595
+ var CALLBACK_PORT = 53682;
2596
+ var REDIRECT_URI = `http://localhost:${CALLBACK_PORT}/callback`;
2597
+
2598
+ // src/commands/token.ts
2599
+ var OAUTH_SETUP = [
2600
+ "Writes go over LinkedIn's OWN self-serve scope rather than the private API, which is the one",
2601
+ "legitimacy wedge an individual actually has \u2014 but the app has to be registered by you; it",
2602
+ "cannot be created on your behalf.",
2603
+ "",
2604
+ " 1. https://www.linkedin.com/developers/apps/new \u2014 create an app (any LinkedIn Page works).",
2605
+ ' 2. Products tab \u2192 add "Sign In with LinkedIn using OpenID Connect" AND "Share on LinkedIn".',
2606
+ " Both are self-serve: no partner review, no verification, no screencast.",
2607
+ ` 3. Auth tab \u2192 add redirect URL ${REDIRECT_URI}`,
2608
+ " 4. Run: lnrelay oauth login --client-id <id>",
2609
+ " (the secret is prompted for; or set LINKEDIN_CLIENT_ID / LINKEDIN_CLIENT_SECRET)"
2610
+ ].join("\n");
2611
+
2612
+ // src/commands/transport.ts
2613
+ var NO_CREDENTIAL_HINT = [
2614
+ "Two ways to write, and you need one of them:",
2615
+ "",
2616
+ " Sanctioned lnrelay oauth login --client-id <id>",
2617
+ " Needs a developer app, which needs a LinkedIn Page.",
2618
+ "",
2619
+ " Unsanctioned lnrelay login",
2620
+ " Uses the same cookies as reads. No Page needed. Breaches \xA78.2",
2621
+ " and puts the account at risk \u2014 every write still asks first."
2622
+ ].join("\n");
2623
+
2624
+ // src/commands/write.ts
2625
+ var MIN_LEAD_MS = 10 * 6e4;
2626
+ var PROFILE_HINT = `profile fields: ${Object.keys(PROFILE_FIELDS).join(", ")}`;
2627
+
2628
+ // src/commands/role.ts
2629
+ function liveRoles(session, quiet = false) {
2630
+ const client = createLiveClient(session, void 0, quiet);
2631
+ return {
2632
+ vanity: async () => {
2633
+ const me = await createEngine(session, void 0, quiet).whoami();
2634
+ if (!me.ok) return me;
2635
+ const id = me.value?.publicIdentifier;
2636
+ return typeof id === "string" && id !== "" ? { ok: true, vanity: id } : { ok: false, code: "SCHEMA_DRIFT", message: "whoami returned no public profile id" };
2637
+ },
2638
+ list: (vanity) => fetchPositions(vanity, client),
2639
+ open: (payload, edit) => openPositionForm(payload, client, edit),
2640
+ save: (form, model) => sendPositionSave(form, model, client),
2641
+ remove: (form) => sendPositionDelete(form, client)
2642
+ };
2643
+ }
2644
+ async function runExperience(quiet = false) {
2645
+ const session = loadSession();
2646
+ if (session.state !== "ok")
2647
+ return err("experience", "AUTH_FAILED", "no LinkedIn session \u2014 run `lnrelay login`");
2648
+ const roles = liveRoles(session.session, quiet);
2649
+ const me = await roles.vanity();
2650
+ if (!me.ok) return err("experience", me.code, me.message, me.hint);
2651
+ const listed = await roles.list(me.vanity);
2652
+ if (!listed.ok) return err("experience", listed.code, listed.message, listed.hint);
2653
+ return ok("experience", {
2654
+ items: listed.positions.map((p) => ({ positionId: p.positionId, title: p.title })),
2655
+ meta: { state: "complete", returnedCount: listed.positions.length }
2656
+ });
2657
+ }
2658
+
2659
+ // src/engine/sdui-skill.ts
2660
+ var SKILL = {
2661
+ addScreen: "com.linkedin.sdui.flagshipnav.profile.ProfileSkillAddForm",
2662
+ editScreen: "com.linkedin.sdui.flagshipnav.profile.ProfileSkillDetailsEditForm",
2663
+ listScreen: "com.linkedin.sdui.flagshipnav.profile.ProfileSkillDetails",
2664
+ pager: "com.linkedin.sdui.pagers.profile.details.skills",
2665
+ save: "com.linkedin.sdui.requests.profile.saveProfileSkillForm",
2666
+ delete: "com.linkedin.sdui.requests.profile.deleteProfileSkillForm"
2667
+ };
2668
+ var EDIT_NAV2 = `{"$type":"proto.sdui.actions.core.NavigateToScreen","screenId":"${SKILL.editScreen}"`;
2669
+ var TEXT2 = /"children":\["((?:[^"\\]|\\.)*)"\]/g;
2670
+ function skillsFromPage(stream) {
2671
+ if (!stream.includes(SKILL.pager) && !stream.includes(EDIT_NAV2) && !stream.includes("isPartialPage")) {
2672
+ return drift2("the skills page could not be read");
2673
+ }
2674
+ const skills = [];
2675
+ let from = 0;
2676
+ let i = 0;
2677
+ for (; ; ) {
2678
+ i = stream.indexOf(EDIT_NAV2, i);
2679
+ if (i === -1) break;
2680
+ const text2 = balanced(stream, i);
2681
+ const end = i;
2682
+ i += EDIT_NAV2.length;
2683
+ if (text2 === null) continue;
2684
+ const payload = JSON.parse(text2).requestedArguments?.payload;
2685
+ const id = payload?.skillId;
2686
+ if (typeof id !== "string" || payload === void 0 || skills.some((s) => s.skillId === id))
2687
+ continue;
2688
+ const names = [...stream.slice(from, end).matchAll(TEXT2)].map(
2689
+ (m) => JSON.parse(`"${m[1]}"`)
2690
+ );
2691
+ skills.push({ skillId: id, name: names.length === 1 ? names[0] ?? null : null, payload });
2692
+ from = end + text2.length;
2693
+ }
2694
+ return { ok: true, skills };
2695
+ }
2696
+ function pagerFrom(payload, start) {
2697
+ const args = {
2698
+ $type: "proto.sdui.actions.requests.RequestedArguments",
2699
+ requestedStateKeys: [],
2700
+ payload: { ...payload, start },
2701
+ requestMetadata: { $type: "proto.sdui.common.RequestMetadata" }
2702
+ };
2703
+ return {
2704
+ pagerId: SKILL.pager,
2705
+ clientArguments: { ...args, states: [], screenId: SKILL.listScreen, knownTemplateIds: [] },
2706
+ paginationRequest: {
2707
+ $type: "proto.sdui.actions.requests.PaginationRequest",
2708
+ pagerId: SKILL.pager,
2709
+ retryCount: 0,
2710
+ requestedArguments: args
2711
+ }
2712
+ };
2713
+ }
2714
+ function readSkillForm(stream) {
2715
+ const model = readModel(stream);
2716
+ if (model === null) return drift2("the skill form carried no initial values");
2717
+ const save = findRequest(stream, SKILL.save);
2718
+ const del = findRequest(stream, SKILL.delete);
2719
+ if (save === null && del === null)
2720
+ return drift2("the skill form carried neither a save nor a delete");
2721
+ return { ok: true, model, save, del, screen: del === null ? SKILL.addScreen : SKILL.editScreen };
2722
+ }
2723
+ var PAGER_URL2 = `https://www.linkedin.com/flagship-web/rsc-action/actions/pagination?sduiid=${SKILL.pager}`;
2724
+ var MAX_PAGES2 = 10;
2725
+ async function fetchSkills(vanityName, client) {
2726
+ const screen = await openForm(
2727
+ SKILL.listScreen,
2728
+ { vanityName, isVanityNameResolved: true },
2729
+ client,
2730
+ "skills-screen"
2731
+ );
2732
+ if (typeof screen !== "string") return screen;
2733
+ const at = screen.indexOf('"filter":"ProfileSkillCategory_ALL"');
2734
+ const open = at === -1 ? -1 : screen.lastIndexOf('"payload":{', at);
2735
+ const text2 = open === -1 ? null : balanced(screen, open + '"payload":'.length);
2736
+ if (text2 === null) return drift2("the Skills screen carried no list request");
2737
+ const payload = JSON.parse(text2);
2738
+ const count2 = typeof payload.count === "number" ? payload.count : 10;
2739
+ const skills = [];
2740
+ for (let page = 0; page < MAX_PAGES2; page++) {
2741
+ const result = await client.request({
2742
+ url: PAGER_URL2,
2743
+ method: "POST",
2744
+ body: pagerFrom(payload, skills.length),
2745
+ spendClass: "page",
2746
+ operation: "skills"
2747
+ });
2748
+ if (!result.ok) return { ok: false, code: result.code, message: result.message };
2749
+ const parsed = skillsFromPage(result.classification.raw ?? "");
2750
+ if (!parsed.ok) return parsed;
2751
+ const fresh = parsed.skills.filter((s) => !skills.some((k) => k.skillId === s.skillId));
2752
+ skills.push(...fresh);
2753
+ if (parsed.skills.length < count2 || fresh.length === 0) break;
2754
+ }
2755
+ return { ok: true, skills };
2756
+ }
2757
+ async function openSkillForm(payload, client, edit) {
2758
+ const stream = await openForm(
2759
+ edit ? SKILL.editScreen : SKILL.addScreen,
2760
+ { ...payload, isVanityNameResolved: true },
2761
+ client,
2762
+ edit ? "skill-edit-form" : "skill-add-form"
2763
+ );
2764
+ return typeof stream === "string" ? readSkillForm(stream) : stream;
2765
+ }
2766
+ async function sendSkill(body, requestId, client) {
2767
+ const sent = await sendAction(
2768
+ requestId,
2769
+ body,
2770
+ client,
2771
+ requestId === SKILL.save ? "skill-add" : "skill-remove"
2772
+ );
2773
+ return typeof sent === "string" ? { ok: true } : sent;
2774
+ }
2775
+
2776
+ // src/commands/skill.ts
2777
+ function liveSkills(session, quiet = false) {
2778
+ const client = createLiveClient(session, void 0, quiet);
2779
+ return {
2780
+ vanity: async () => {
2781
+ const me = await createEngine(session, void 0, quiet).whoami();
2782
+ if (!me.ok) return me;
2783
+ const id = me.value?.publicIdentifier;
2784
+ return typeof id === "string" && id !== "" ? { ok: true, vanity: id } : { ok: false, code: "SCHEMA_DRIFT", message: "whoami returned no public profile id" };
2785
+ },
2786
+ list: (vanity) => fetchSkills(vanity, client),
2787
+ open: (payload, edit) => openSkillForm(payload, client, edit),
2788
+ send: (body, requestId) => sendSkill(body, requestId, client)
2789
+ };
2790
+ }
2791
+ async function runSkills(quiet = false) {
2792
+ const session = loadSession();
2793
+ if (session.state !== "ok")
2794
+ return err("skills", "AUTH_FAILED", "no LinkedIn session \u2014 run `lnrelay login`");
2795
+ const skills = liveSkills(session.session, quiet);
2796
+ const me = await skills.vanity();
2797
+ if (!me.ok) return err("skills", me.code, me.message, me.hint);
2798
+ const listedSkills = await skills.list(me.vanity);
2799
+ if (!listedSkills.ok)
2800
+ return err("skills", listedSkills.code, listedSkills.message, listedSkills.hint);
2801
+ return ok("skills", {
2802
+ items: listedSkills.skills.map((s) => ({ skillId: s.skillId, name: s.name })),
2803
+ meta: { state: "complete", returnedCount: listedSkills.skills.length }
2804
+ });
2805
+ }
2806
+
2164
2807
  // src/entry.ts
2165
2808
  import { realpathSync } from "fs";
2166
- import { basename } from "path";
2809
+ import { basename as basename2 } from "path";
2167
2810
  import { fileURLToPath } from "url";
2168
2811
  function isMainModule(argv1, moduleUrl, importMetaMain) {
2169
2812
  if (importMetaMain === true) return true;
@@ -2178,7 +2821,7 @@ function isMainModule(argv1, moduleUrl, importMetaMain) {
2178
2821
  }
2179
2822
  function shouldForceEntry(argv1, binNames) {
2180
2823
  if (argv1 === void 0) return false;
2181
- return binNames.includes(basename(argv1));
2824
+ return binNames.includes(basename2(argv1));
2182
2825
  }
2183
2826
  function shouldRunAsEntry(argv1, moduleUrl, importMetaMain, binNames) {
2184
2827
  if (isMainModule(argv1, moduleUrl, importMetaMain)) {
@@ -2284,6 +2927,18 @@ function buildServer() {
2284
2927
  },
2285
2928
  async ({ query, source, since, limit }) => reply(runLocal(query, source, since, limit ?? 25))
2286
2929
  );
2930
+ server.tool(
2931
+ "experience",
2932
+ `The roles on the user's own LinkedIn profile: positionId and title. LIVE \u2014 2 calls. The positionId is what \`lnrelay role edit|remove\` takes (CLI-only; changing a role is a write the user approves). ${NO_RETRY}`,
2933
+ {},
2934
+ async () => reply(await runExperience())
2935
+ );
2936
+ server.tool(
2937
+ "skills",
2938
+ `The skills on the user's own LinkedIn profile: skillId and name. LIVE \u2014 about 3 calls. \`name\` is null when it could not be matched to its row for certain. Adding or removing a skill is the CLI-only \`lnrelay skill\`, a write the user approves. ${NO_RETRY}`,
2939
+ {},
2940
+ async () => reply(await runSkills())
2941
+ );
2287
2942
  server.tool(
2288
2943
  "scheduled",
2289
2944
  `The user's own posts waiting to publish, soonest first: urn, scheduledAt (ISO), text. LIVE \u2014 about 1 call per 10 posts. These are NOT in \`my_posts\` until they go out. Links in \`text\` show as lnkd.in short links, as LinkedIn lists them. \`text\` is null when it could not be matched to its post for certain. \`meta.claimedCount\` is LinkedIn's own count; if \`meta.state\` is not "complete", say the list may be short. ${NO_RETRY}`,