@lobu/runtime-device 23.0.0 → 24.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.
Files changed (67) hide show
  1. package/dist/component.json +1 -1
  2. package/dist/dependencies.bun.lock +30 -27
  3. package/npm-shrinkwrap.json +131 -115
  4. package/package.json +2 -1
  5. package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +73 -0
  6. package/vendor/cli/dist/commands/_lib/apply/apply-cmd.js +9 -11
  7. package/vendor/cli/dist/commands/_lib/apply/client.d.ts +3 -11
  8. package/vendor/cli/dist/commands/_lib/apply/client.js +3 -3
  9. package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +0 -6
  10. package/vendor/cli/dist/commands/_lib/apply/desired-state.js +6 -15
  11. package/vendor/cli/dist/commands/_lib/apply/diff.js +1 -0
  12. package/vendor/cli/dist/commands/_lib/apply/map-config.js +8 -0
  13. package/vendor/cli/dist/commands/_lib/view-bundler.d.ts +2 -9
  14. package/vendor/cli/dist/commands/_lib/view-bundler.js +36 -119
  15. package/vendor/cli/dist/config/define.d.ts +8 -0
  16. package/vendor/cli/dist/connectors/README.md +1 -1
  17. package/vendor/cli/dist/connectors/linkedin-inbox-adapter.js +4 -7
  18. package/vendor/cli/dist/connectors/linkedin.ts +53 -34
  19. package/vendor/cli/dist/connectors/reddit.ts +92 -20
  20. package/vendor/cli/dist/connectors/slack.ts +1 -0
  21. package/vendor/cli/dist/connectors/whatsapp-web-adapter.js +41 -11
  22. package/vendor/cli/dist/connectors/whatsapp-web-helpers.ts +1 -1
  23. package/vendor/cli/dist/connectors/whatsapp_web.ts +2 -2
  24. package/vendor/cli/dist/connectors/x-dm-adapter.js +65 -30
  25. package/vendor/cli/dist/connectors/x-identity.ts +5 -3
  26. package/vendor/cli/dist/runtime-components.json +4 -4
  27. package/vendor/cli/dist/templates/AGENTS.md.tmpl +10 -3
  28. package/vendor/cli/package.json +1 -1
  29. package/vendor/connector-sdk/package.json +1 -1
  30. package/vendor/connector-worker/dist/agent-turn/gateway-tools.d.ts +2 -2
  31. package/vendor/connector-worker/dist/agent-turn/gateway-tools.js +2 -2
  32. package/vendor/connector-worker/dist/agent-turn/guest-entry.js +34 -2
  33. package/vendor/connector-worker/dist/agent-turn/guest.bundle.js +362 -300
  34. package/vendor/connector-worker/dist/agent-turn/native-session.d.ts +12 -0
  35. package/vendor/connector-worker/dist/agent-turn/native-session.js +32 -6
  36. package/vendor/connector-worker/dist/agent-turn/types.d.ts +24 -3
  37. package/vendor/connector-worker/dist/daemon/agent-turn.js +5 -1
  38. package/vendor/connector-worker/dist/daemon/automation-acp.js +23 -11
  39. package/vendor/connector-worker/dist/daemon/automation.js +20 -15
  40. package/vendor/connector-worker/dist/isolate/prelude.js +93 -44
  41. package/vendor/connector-worker/package.json +1 -1
  42. package/vendor/core/dist/agent-policy.js +0 -3
  43. package/vendor/core/dist/agent-tooling.d.ts +1 -1
  44. package/vendor/core/dist/agent-tooling.js +3 -1
  45. package/vendor/core/dist/contracts/agent-settings.d.ts +6 -2
  46. package/vendor/core/dist/contracts/agent-settings.js +12 -1
  47. package/vendor/core/dist/contracts/tools/manage-views.d.ts +53 -234
  48. package/vendor/core/dist/contracts/tools/manage-views.js +50 -76
  49. package/vendor/core/dist/contracts/tools/view-attach.d.ts +5 -8
  50. package/vendor/core/dist/contracts/tools/view-attach.js +14 -31
  51. package/vendor/core/dist/contracts/tools/view-definition.d.ts +21 -0
  52. package/vendor/core/dist/contracts/tools/view-definition.js +165 -0
  53. package/vendor/core/dist/contracts/tools/view-runtime.d.ts +74 -0
  54. package/vendor/core/dist/contracts/tools/view-runtime.js +86 -0
  55. package/vendor/core/dist/contracts/worker/protocol.d.ts +39 -2
  56. package/vendor/core/dist/contracts/worker/protocol.js +24 -1
  57. package/vendor/core/dist/index.d.ts +1 -1
  58. package/vendor/core/dist/index.js +2 -1
  59. package/vendor/core/dist/suggestions.d.ts +15 -2
  60. package/vendor/core/dist/suggestions.js +48 -3
  61. package/vendor/core/dist/types.d.ts +26 -0
  62. package/vendor/core/dist/types.js +5 -0
  63. package/vendor/core/package.json +16 -5
  64. package/vendor/postgres/cf/src/connection.js +18 -0
  65. package/vendor/postgres/cjs/src/connection.js +18 -0
  66. package/vendor/postgres/src/connection.js +18 -0
  67. /package/vendor/postgres/{.bun-tag-f39dafdb2305d504 → .bun-tag-2f292c6554a8475e} +0 -0
@@ -556,25 +556,20 @@ export async function executePlan(ctx, pendingAuth) {
556
556
  printText(chalk.yellow(`Warning: ${warning}`));
557
557
  }
558
558
  }
559
- // 2b) Views — shipped from the load-time bundle (source + browser bundle +
560
- // metadata extracted from the module itself, hashed with the server's
561
- // function). No re-bundling here: the diff already compared the exact
562
- // hash the server will compute.
559
+ // 2b) Views — shipped from the load-time bundle (source + browser bundle,
560
+ // hashed with the server's function; the server reads the declaration
561
+ // from the source). No re-bundling here: the diff already compared the
562
+ // exact hash the server will compute.
563
563
  for (const row of rowsByKind("view")) {
564
564
  if (row.kind !== "view")
565
565
  continue;
566
566
  if (!row.desired)
567
567
  continue;
568
568
  const result = await ctx.client.setView({
569
- key: row.id,
570
- name: row.desired.key,
571
569
  source_code: row.desired.sourceCode,
572
570
  compiled_code: row.desired.compiledCode,
573
571
  source_files: row.desired.sourceFiles,
574
572
  dependencies: row.desired.dependencies,
575
- attach: row.desired.attach,
576
- params: row.desired.params,
577
- actions: row.desired.actions,
578
573
  });
579
574
  const kb = (Buffer.byteLength(row.desired.compiledCode, "utf8") / 1024).toFixed(0);
580
575
  printText(renderProgress(row.verb, "view", row.id, `${result.written ? "(pushed" : "(unchanged"}, ${kb} KB)`));
@@ -1285,8 +1280,11 @@ async function applyProject(opts, prepared) {
1285
1280
  // Provider API keys live outside the resource diff (the secret value isn't
1286
1281
  // serialized into any plan row), so a key-only `.env` change produces an
1287
1282
  // all-noop plan. Detect declared keys so the apply isn't short-circuited and
1288
- // the keys aren't silently dropped.
1289
- const hasProviderKeys = state.agents.some((a) => a.providerKeys.length > 0);
1283
+ // the keys aren't silently dropped. Keys are declared on agents, so they
1284
+ // belong to the agents family: `--only memory` must never push one (a push
1285
+ // can create the org provider row).
1286
+ const hasProviderKeys = opts.only !== "memory" &&
1287
+ state.agents.some((a) => a.providerKeys.length > 0);
1290
1288
  if (plan.counts.create === 0 &&
1291
1289
  plan.counts.update === 0 &&
1292
1290
  plan.counts.delete === 0 &&
@@ -125,18 +125,10 @@ export interface RemoteView {
125
125
  updated_at: string;
126
126
  }
127
127
  export interface SetViewPayload {
128
- key: string;
129
- name?: string;
130
- description?: string;
131
128
  source_code: string;
132
129
  compiled_code?: string;
133
130
  source_files?: SourceFiles;
134
131
  dependencies?: SourceDependencies;
135
- attach: Array<Record<string, unknown>>;
136
- params: Record<string, unknown>;
137
- actions: Record<string, {
138
- emits: string;
139
- }>;
140
132
  }
141
133
  export interface RemoteAutomation {
142
134
  slug: string;
@@ -372,9 +364,9 @@ export declare class ApplyClient {
372
364
  /** Applied views (metadata only — the list never returns bundles). */
373
365
  listViews(): Promise<RemoteView[]>;
374
366
  /**
375
- * Store a view: source + CLI-bundled browser bundle + metadata extracted
376
- * from the module itself. Returns whether a write happened (same
377
- * executable artifact is a server-side no-op).
367
+ * Store a view: source + CLI-bundled browser bundle. The server reads the
368
+ * view's key, attach, params and actions from the source. Returns whether a
369
+ * write happened (same executable artifact is a server-side no-op).
378
370
  */
379
371
  setView(payload: SetViewPayload): Promise<{
380
372
  written: boolean;
@@ -293,9 +293,9 @@ export class ApplyClient {
293
293
  return body.views ?? [];
294
294
  }
295
295
  /**
296
- * Store a view: source + CLI-bundled browser bundle + metadata extracted
297
- * from the module itself. Returns whether a write happened (same
298
- * executable artifact is a server-side no-op).
296
+ * Store a view: source + CLI-bundled browser bundle. The server reads the
297
+ * view's key, attach, params and actions from the source. Returns whether a
298
+ * write happened (same executable artifact is a server-side no-op).
299
299
  */
300
300
  async setView(payload) {
301
301
  const { body } = await this.request("POST", `/api/${this.orgSlug}/manage_views`, {
@@ -248,12 +248,6 @@ export interface DesiredView extends RetainedSource {
248
248
  sourceFile: string;
249
249
  /** Browser IIFE bundle (react, bridge, relative files, view npm deps). */
250
250
  compiledCode: string;
251
- /** Metadata extracted from the module itself. */
252
- attach: Array<Record<string, unknown>>;
253
- params: Record<string, unknown>;
254
- actions: Record<string, {
255
- emits: string;
256
- }>;
257
251
  }
258
252
  export interface DesiredAgent {
259
253
  metadata: DesiredAgentMetadata;
@@ -496,22 +496,16 @@ async function resolveViewSources(sources, cwd) {
496
496
  }
497
497
  const bundled = await bundleViewFromFile(abs, baseDir);
498
498
  sourceCode = bundled.sourceFiles.files[bundled.sourceFiles.entrypoint];
499
- const key = bundled.metadata.key;
499
+ const { key, name, description, attach, params, actions } = bundled.definition;
500
500
  if (seen.has(key)) {
501
501
  throw new ValidationError(`duplicate view key "${key}" in lobu.config.ts — each viewFromFile must resolve to a unique key`);
502
502
  }
503
503
  seen.add(key);
504
- // Hash EXACTLY what the server will store: name defaults to the key,
505
- // description defaults to empty, metadata JSON-round-tripped (the wire
506
- // drops undefined, so hash post-round-trip or equivalent declarations
507
- // compare differently), plus the digest of the bundle produced above
508
- // (which carries the relative imports the entry source alone omits).
509
- // Same function, same inputs: same hash.
510
- const name = key;
511
- const description = "";
512
- const attach = JSON.parse(JSON.stringify(bundled.metadata.attach));
513
- const params = JSON.parse(JSON.stringify(bundled.metadata.params));
514
- const actions = JSON.parse(JSON.stringify(bundled.metadata.actions));
504
+ // Hash EXACTLY what the server will store: the declaration comes from
505
+ // the same reader the server runs on save (defaults applied there), plus
506
+ // the digest of the bundle produced above (which carries the relative
507
+ // imports the entry source alone omits). Same function, same inputs:
508
+ // same hash.
515
509
  views.push({
516
510
  key,
517
511
  sourcePath: abs,
@@ -530,9 +524,6 @@ async function resolveViewSources(sources, cwd) {
530
524
  compiledCode: bundled.compiledCode,
531
525
  sourceFiles: bundled.sourceFiles,
532
526
  dependencies: bundled.dependencies,
533
- attach,
534
- params,
535
- actions,
536
527
  });
537
528
  }
538
529
  return views.sort((a, b) => a.sourceFile.localeCompare(b.sourceFile));
@@ -238,6 +238,7 @@ const SETTINGS_FIELDS = [
238
238
  "soulMd",
239
239
  "userMd",
240
240
  "identityMd",
241
+ "starters",
241
242
  ];
242
243
  function diffSettings(agentId, desired, remote) {
243
244
  const changed = [];
@@ -32,6 +32,7 @@ const AGENT_SETTINGS_FIELD_POLICY = {
32
32
  sandboxId: "unsupported",
33
33
  verboseLogging: "unsupported",
34
34
  showToolCalls: "unsupported",
35
+ starters: "mapped",
35
36
  };
36
37
  void AGENT_SETTINGS_FIELD_POLICY;
37
38
  import { CronExpressionParser } from "cron-parser";
@@ -231,6 +232,12 @@ function mapAgent(agent, env, required) {
231
232
  if (agent.nixPackages?.length) {
232
233
  settings.nixConfig = { packages: [...new Set(agent.nixPackages)] };
233
234
  }
235
+ if (agent.starters !== undefined) {
236
+ settings.starters = agent.starters.map(({ title, message }) => ({
237
+ title,
238
+ message,
239
+ }));
240
+ }
234
241
  const providerKeys = [];
235
242
  for (const provider of agent.providers ?? []) {
236
243
  if (provider.key === undefined)
@@ -282,6 +289,7 @@ function mapAgent(agent, env, required) {
282
289
  sandboxId: settings.sandboxId,
283
290
  verboseLogging: settings.verboseLogging,
284
291
  showToolCalls: settings.showToolCalls,
292
+ starters: settings.starters,
285
293
  };
286
294
  void _exhaustive;
287
295
  return { metadata, settings, providerKeys };
@@ -1,15 +1,8 @@
1
1
  import type { RetainedSource } from "@lobu/core/contracts/tools/source-files";
2
- export interface ViewMetadata {
3
- key: string;
4
- attach: Array<Record<string, unknown>>;
5
- params: Record<string, unknown>;
6
- actions: Record<string, {
7
- emits: string;
8
- }>;
9
- }
2
+ import { type ViewDefinitionRecord } from "@lobu/core/contracts/tools/view-definition";
10
3
  export interface BundledView extends RetainedSource {
11
4
  compiledCode: string;
12
- metadata: ViewMetadata;
5
+ definition: ViewDefinitionRecord;
13
6
  }
14
7
  /**
15
8
  * Bundle the view at `entry` (absolute path) for the browser. Throws when the
@@ -3,73 +3,28 @@
3
3
  *
4
4
  * The module shape is exactly one: `export const view = defineView({ key,
5
5
  * attach, … })` plus a default-export component (hooks inside, no document
6
- * access). Two esbuild passes over the same module:
6
+ * access). One esbuild pass, plus a read of the declaration:
7
7
  * 1. browser IIFE bundle of a SYNTHETIC entry that mounts the two exports
8
8
  * (`mountView(view, Default)`) — what the server stores as
9
- * `compiled_code` and inlines into the view shell. Bundled here, where
10
- * the project's node_modules exists (the same path custom connectors
11
- * use), because the server has no file context for relative imports or
12
- * view npm deps. The server compiles plain sources itself through the
13
- * same mount on its own bootstrap.
14
- * 2. a node bundle of the module in which `@lobu/views` is replaced by a
15
- * stub, imported only to read the `view` export — so `key`/`attach`/
16
- * `params`/`actions` come from the module itself. The attach line lives
17
- * in the file, never in the config.
9
+ * `compiled_code` and inlines into the view shell after its runtime
10
+ * script. React and `@lobu/views` come from that runtime, never the
11
+ * bundle (`@lobu/core/contracts/tools/view-runtime`), and the entry,
12
+ * options and runtime plugin are shared with the server. Bundled here,
13
+ * where the project's node_modules exists, so a view can also bundle npm
14
+ * deps the server cannot build.
15
+ * 2. the entry's `defineView({...})` literal, read without running the module
16
+ * by the same `readViewDefinition` the server uses on save, so the CLI's
17
+ * plan hashes exactly what the server stores. The declaration lives in the
18
+ * file, never in the config.
18
19
  *
19
- * Anything else (no `view` export, no default component, bad key) fails loud
20
- * here rather than rendering a blank frame in prod.
20
+ * Anything else (no `view` export, no default component, a non-literal
21
+ * declaration) fails loud here rather than rendering a blank frame in prod.
21
22
  */
22
- import { mkdtemp, rm, writeFile } from "node:fs/promises";
23
- import { tmpdir } from "node:os";
24
- import { basename, dirname, join, resolve } from "node:path";
25
- import { pathToFileURL } from "node:url";
26
- import { build } from "esbuild";
23
+ import { basename, dirname, resolve } from "node:path";
24
+ import { readViewDefinition, } from "@lobu/core/contracts/tools/view-definition";
25
+ import { VIEW_BUILD_OPTIONS, VIEW_RUNTIME_MODULES, viewMountEntry, viewRuntimePlugin, } from "@lobu/core/contracts/tools/view-runtime";
26
+ import { build, transform } from "esbuild";
27
27
  import { createSourceCapture } from "../../internal/connector-compiler.js";
28
- const VIEW_KEY_RE = /^[a-z0-9][a-z0-9-]{0,63}$/;
29
- const RUNTIME_MODULE_RE = /(^|\/)lobu-views(\.tsx?)?$|^@lobu\/views$/;
30
- const metadataStub = {
31
- name: "lobu-views-metadata-stub",
32
- setup(b) {
33
- b.onResolve({ filter: RUNTIME_MODULE_RE }, () => ({
34
- path: "lobu-views-stub",
35
- namespace: "lobu-views-stub",
36
- }));
37
- b.onLoad({ filter: /.*/, namespace: "lobu-views-stub" }, () => ({
38
- loader: "js",
39
- contents: `
40
- export function defineView(def) {
41
- if (!def || typeof def.key !== "string" || !def.key) {
42
- throw new Error("defineView({ key, attach, ... }) requires a non-empty key");
43
- }
44
- return def;
45
- }
46
- export function mountView() { throw new Error("mountView is not called by view modules: export const view = defineView({ ... }) plus a default-export component"); }
47
- const noHook = () => { throw new Error("hooks are not available at metadata-extraction time"); };
48
- export const useParams = noHook, useScope = noHook, useHost = noHook,
49
- useQuery = noHook, useAction = noHook;
50
- export function Provider() { throw new Error("not available at metadata-extraction time"); }
51
- export function sql(strings, ...values) { return { kind: "sql", text: String(strings[0] ?? "") }; }
52
- export function tool(name, args = {}) { return { kind: "tool", name, args }; }
53
- export function escapeLiteral(value) { return String(value); }
54
- export const defaultsFor = () => ({}), coerceParams = (_def, raw) => raw ?? {};
55
- `,
56
- }));
57
- },
58
- };
59
- function readViewExport(ns, entry) {
60
- const view = ns?.view;
61
- if (!view || typeof view !== "object") {
62
- throw new Error(`${entry}: the module must export const view = defineView({ key, attach, ... })`);
63
- }
64
- const { key } = view;
65
- if (typeof key !== "string" || !key) {
66
- throw new Error(`${entry}: defineView({ key, attach, ... }) requires a non-empty key`);
67
- }
68
- return {
69
- view: { ...view, key },
70
- hasDefault: typeof ns?.default === "function",
71
- };
72
- }
73
28
  /**
74
29
  * Bundle the view at `entry` (absolute path) for the browser. Throws when the
75
30
  * module has no `view` export, no default-export component, or an invalid
@@ -80,72 +35,33 @@ export async function bundleViewFromFile(entry, projectRoot) {
80
35
  const rel = `./${basename(entry)}`;
81
36
  const capture = createSourceCapture(entry, projectRoot);
82
37
  const browser = await build({
83
- plugins: [capture.plugin],
84
- stdin: {
85
- contents: `import { mountView } from "@lobu/views";\nimport * as mod from ${JSON.stringify(rel)};\nmountView(mod.view, mod.default);\n`,
86
- loader: "tsx",
87
- resolveDir: dir,
88
- },
89
- bundle: true,
90
- write: false,
91
- format: "iife",
92
- platform: "browser",
93
- target: ["es2022"],
94
- jsx: "automatic",
95
- minify: true,
96
- sourcemap: false,
97
- legalComments: "none",
98
- define: { "process.env.NODE_ENV": '"production"' },
99
- logLevel: "silent",
38
+ ...VIEW_BUILD_OPTIONS,
39
+ plugins: [capture.plugin, viewRuntimePlugin()],
40
+ stdin: { contents: viewMountEntry(rel), loader: "js", resolveDir: dir },
100
41
  });
101
42
  const compiledCode = browser.outputFiles?.[0]?.text ?? "";
102
43
  if (!compiledCode) {
103
44
  throw new Error(`${entry}: view bundle compiled to empty output`);
104
45
  }
105
46
  assertBundlePortable(compiledCode, entry);
106
- const node = await build({
107
- entryPoints: [entry],
108
- bundle: true,
109
- write: false,
110
- format: "esm",
111
- platform: "node",
112
- target: ["node22"],
113
- jsx: "automatic",
114
- plugins: [capture.plugin, metadataStub],
115
- define: { "process.env.NODE_ENV": '"production"' },
116
- logLevel: "silent",
117
- });
118
- const tmp = await mkdtemp(join(tmpdir(), "lobu-view-meta-"));
47
+ const source = capture.source();
48
+ const entrySource = source.sourceFiles.files[source.sourceFiles.entrypoint];
49
+ if (entrySource === undefined) {
50
+ throw new Error(`${entry}: the view entry was not captured`);
51
+ }
52
+ let definition;
119
53
  try {
120
- const file = join(tmp, "view.mjs");
121
- await writeFile(file, node.outputFiles?.[0]?.text ?? "");
122
- // A fresh temp path per call, so the ESM cache never returns a stale module.
123
- const ns = await import(pathToFileURL(file).href);
124
- const { view: def, hasDefault } = readViewExport(ns, entry);
125
- if (!hasDefault) {
126
- throw new Error(`${entry}: the module must have a default-export component`);
127
- }
128
- if (!VIEW_KEY_RE.test(def.key)) {
129
- throw new Error(`${entry}: defineView key ${JSON.stringify(def.key)} must match /^[a-z0-9][a-z0-9-]{0,63}$/`);
130
- }
131
- return {
132
- compiledCode,
133
- ...capture.source(),
134
- metadata: {
135
- key: def.key,
136
- attach: Array.isArray(def.attach) ? def.attach : [],
137
- params: def.params && typeof def.params === "object"
138
- ? def.params
139
- : {},
140
- actions: def.actions && typeof def.actions === "object"
141
- ? def.actions
142
- : {},
143
- },
144
- };
54
+ const { code } = await transform(entrySource, {
55
+ loader: "tsx",
56
+ jsx: "automatic",
57
+ logLevel: "silent",
58
+ });
59
+ definition = readViewDefinition(code);
145
60
  }
146
- finally {
147
- await rm(tmp, { recursive: true, force: true });
61
+ catch (error) {
62
+ throw new Error(`${entry}: ${error.message}`);
148
63
  }
64
+ return { compiledCode, ...source, definition };
149
65
  }
150
66
  /**
151
67
  * The `lobu run` watch set for one view: the entry plus every file esbuild
@@ -166,6 +82,7 @@ export async function collectViewWatchFiles(entry) {
166
82
  write: false,
167
83
  format: "esm",
168
84
  platform: "browser",
85
+ external: [...VIEW_RUNTIME_MODULES],
169
86
  jsx: "automatic",
170
87
  metafile: true,
171
88
  logLevel: "silent",
@@ -737,6 +737,14 @@ export interface Agent {
737
737
  guardrails?: string[];
738
738
  /** Nix packages provisioned into the worker environment. */
739
739
  nixPackages?: string[];
740
+ /**
741
+ * Up to three conversation starters, shown on an empty web chat and as
742
+ * Slack assistant thread-start prompts. `message` is sent as the user.
743
+ */
744
+ starters?: Array<{
745
+ title: string;
746
+ message: string;
747
+ }>;
740
748
  }
741
749
  export declare function defineAgent(config: Omit<Agent, "kind">): Agent;
742
750
  /**
@@ -559,7 +559,7 @@ For source-backed bundled connectors, the worker recompiles a `.ts` file after i
559
559
  | `linkedin` | browser/none | notifications, inbox messages, home feed, company updates, jobs; Data Export requires an injected CSV reader | send direct-message replies; like; prepare message/post/comment drafts |
560
560
  | `market.quotes` | none | - | quote (read-only, quotes returned to the caller, never persisted) |
561
561
  | `producthunt` | env_keys | posts & comments | - |
562
- | `reddit` | oauth/none | posts, comments, user activity | - |
562
+ | `reddit` | oauth/none | posts, comments, user activity, home feed | - |
563
563
  | `rss` | none | articles | - |
564
564
  | `x` | browser/oauth | tweets, own posts, likes, bookmarks, DMs, home timeline | prepare reply |
565
565
  | `youtube` | oauth (Google) | liked videos, playlists, subscriptions, videos | search, get_video, search_liked_videos, list_playlists, get_playlist |
@@ -96,17 +96,14 @@ export function linkedInInboxProgram() {
96
96
  }
97
97
  // Whether a message was sent from this inbox. A member inbox's own messages
98
98
  // carry the member's identity. A page inbox holds conversations between the
99
- // page and members, so the page's mailbox, the page as an organization
100
- // participant, or the signed-in admin are all the page speaking.
99
+ // page and members: a page reply's sender is the page's mailbox or the page
100
+ // as an organization participant, with the admin who sent it only as its
101
+ // actor. The signed-in admin writing as themselves is a member like any other.
101
102
  function fromMe(sender, inbox) {
102
103
  const host = sender?.hostIdentityUrn;
103
104
  if (typeof host !== "string") return null;
104
105
  if (!inbox.page) return host === inbox.mailbox;
105
- return (
106
- host === inbox.mailbox ||
107
- host === inbox.member ||
108
- !!sender.participantType?.organization
109
- );
106
+ return host === inbox.mailbox || !!sender.participantType?.organization;
110
107
  }
111
108
  // A page conversation's visitor-chosen topic, when LinkedIn shows one.
112
109
  function topicOf(conversation, inbox) {
@@ -487,9 +487,10 @@ const HOME_FEED_POST_IDENTITY_SELECTOR =
487
487
  ':is([id*="shareId="], [id*="ugcPostId="], [id*="urn:li:activity:"], [id*="-replaceableCommentTools"]):not([id^="replaceableComment_"]):not([id^="replaceableComment_"] *)';
488
488
 
489
489
  /** Current comment-tool ids encode a typed post URN, followed by the recycled
490
- * card key. Decode only the typed prefix: field 1 is activity, field 2 ugcPost;
491
- * each contains field 1 as a protobuf sint64 (ZigZag). Native comment URNs and
492
- * the corresponding live post URLs independently confirm those namespaces. */
490
+ * card key. Decode only the typed prefix: field 1 is activity, field 2 ugcPost,
491
+ * and field 3 groupPost. Each contains field 1 as a protobuf sint64 (ZigZag);
492
+ * groupPost contains the group id in field 1 and the post id in field 2.
493
+ * Native comment URNs and live post URLs confirm those namespaces. */
493
494
  function decodeHomeFeedPostIdentity(
494
495
  raw: string | undefined
495
496
  ): string | undefined {
@@ -509,25 +510,38 @@ function decodeHomeFeedPostIdentity(
509
510
  }
510
511
  const tag = bytes.charCodeAt(0);
511
512
  if (
512
- (tag !== 10 && tag !== 18) ||
513
+ (tag !== 10 && tag !== 18 && tag !== 26) ||
513
514
  bytes.length < 4 ||
514
- bytes.length > 13 ||
515
+ bytes.length > (tag === 26 ? 24 : 13) ||
515
516
  bytes.charCodeAt(1) !== bytes.length - 2 ||
516
517
  bytes.charCodeAt(2) !== 8
517
518
  ) {
518
519
  throw invalid();
519
520
  }
520
- let encoded = 0n;
521
- for (let i = 3; i < bytes.length; i++) {
522
- const byte = bytes.charCodeAt(i);
523
- const isLast = i === bytes.length - 1;
524
- if (Boolean(byte & 128) === isLast) throw invalid();
525
- encoded |= BigInt(byte & 127) << BigInt(7 * (i - 3));
526
- }
527
- if ((encoded & 1n) !== 0n || encoded >= 1n << 64n || encoded < 200_000n) {
521
+ let offset = 3;
522
+ const readId = (minimum: bigint) => {
523
+ let encoded = 0n;
524
+ for (let shift = 0; shift < 70 && offset < bytes.length; shift += 7) {
525
+ const byte = bytes.charCodeAt(offset++);
526
+ encoded |= BigInt(byte & 127) << BigInt(shift);
527
+ if (byte & 128) continue;
528
+ if ((encoded & 1n) !== 0n || encoded >= 1n << 64n || encoded < minimum) {
529
+ throw invalid();
530
+ }
531
+ return encoded >> 1n;
532
+ }
528
533
  throw invalid();
534
+ };
535
+ // Group ids can be smaller than post ids, but must still be positive.
536
+ const firstId = readId(tag === 26 ? 2n : 200_000n);
537
+ if (tag === 26) {
538
+ if (bytes.charCodeAt(offset++) !== 16) throw invalid();
539
+ const postId = readId(200_000n);
540
+ if (offset !== bytes.length) throw invalid();
541
+ return `urn:li:groupPost:${firstId}-${postId}`;
529
542
  }
530
- return `urn:li:${tag === 10 ? "activity" : "ugcPost"}:${encoded >> 1n}`;
543
+ if (offset !== bytes.length) throw invalid();
544
+ return `urn:li:${tag === 10 ? "activity" : "ugcPost"}:${firstId}`;
531
545
  }
532
546
 
533
547
  // A fenced dispatch discards every row it collected, so an oversized scrape
@@ -1227,7 +1241,7 @@ interface HomeFeedEngagement {
1227
1241
 
1228
1242
  interface HomeFeedCommentIdentity {
1229
1243
  urn: string;
1230
- parentNamespace: "activity" | "share" | "ugcPost";
1244
+ parentNamespace: ReturnType<typeof linkedInUrnNamespace>;
1231
1245
  parentId: string;
1232
1246
  commentId: string;
1233
1247
  }
@@ -1246,10 +1260,10 @@ function homeFeedPostIdentityKey(
1246
1260
  for (const raw of [context.postUrl, row.post_identity]) {
1247
1261
  if (!raw) continue;
1248
1262
  const match = raw.match(
1249
- /(?:(shareId|ugcPostId)=|urn:li:(activity|share|ugcPost):)(\d{6,})/i
1263
+ /(?:(shareId|ugcPostId)=|urn:li:(activity|share|ugcPost):)(\d{6,})|urn:li:(groupPost):(\d+-\d{6,})/i
1250
1264
  );
1251
1265
  if (!match) continue;
1252
- return `${linkedInUrnNamespace(match[1] ?? match[2] ?? "")}:${match[3]}`;
1266
+ return `${linkedInUrnNamespace(match[1] ?? match[2] ?? match[4] ?? "")}:${match[3] ?? match[5]}`;
1253
1267
  }
1254
1268
  return undefined;
1255
1269
  }
@@ -1517,11 +1531,11 @@ function buildHomeFeedRowContext(row: HomeFeedRow): HomeFeedRowContext {
1517
1531
  }
1518
1532
 
1519
1533
  const embeddedUrn = row.post_identity?.match(
1520
- /(?:(shareId|ugcPostId)=|urn:li:(activity|share|ugcPost):)(\d{6,})/i
1534
+ /(?:(shareId|ugcPostId)=|urn:li:(activity|share|ugcPost):)(\d{6,})|urn:li:(groupPost):(\d+-\d{6,})/i
1521
1535
  );
1522
- const embeddedId = embeddedUrn?.[3];
1536
+ const embeddedId = embeddedUrn?.[3] ?? embeddedUrn?.[5];
1523
1537
  const embeddedNamespace = linkedInUrnNamespace(
1524
- embeddedUrn?.[1] ?? embeddedUrn?.[2] ?? ""
1538
+ embeddedUrn?.[1] ?? embeddedUrn?.[2] ?? embeddedUrn?.[4] ?? ""
1525
1539
  );
1526
1540
  const postUrl = normalizeLinkedInPostUrl(
1527
1541
  row.post_url ??
@@ -1548,7 +1562,7 @@ function isHomeFeedRowNoise(
1548
1562
  /**
1549
1563
  * Map cs_scrape home-feed rows to event envelopes. A scraped permalink still
1550
1564
  * wins when a row carries one, but current cards expose none, so the canonical
1551
- * post identity is normally the activity/share/ugcPost id embedded in
1565
+ * post identity is normally the activity/share/ugcPost/groupPost id embedded in
1552
1566
  * `post_identity`. The scrape-only componentkey never becomes an event origin,
1553
1567
  * and a post without either durable identity is not emitted. Native comments
1554
1568
  * carry their own durable id and point at the stable parent-post origin.
@@ -1721,20 +1735,24 @@ type PrepareCommentResult = {
1721
1735
 
1722
1736
  /**
1723
1737
  * Canonical casing for the LinkedIn URN namespace an id came from. share and
1724
- * ugcPost ids live in different id spaces than activity ids, so the namespace
1725
- * has to survive normalization; /feed/update/ resolves all three.
1738
+ * ugcPost and groupPost ids live in different id spaces than activity ids, so
1739
+ * the namespace has to survive normalization; /feed/update/ resolves them all.
1726
1740
  */
1727
- function linkedInUrnNamespace(token: string): "activity" | "share" | "ugcPost" {
1741
+ function linkedInUrnNamespace(
1742
+ token: string
1743
+ ): "activity" | "share" | "ugcPost" | "groupPost" {
1728
1744
  const normalized = token.toLowerCase();
1729
1745
  if (normalized === "shareid" || normalized === "share") return "share";
1730
1746
  if (normalized === "ugcpostid" || normalized === "ugcpost") return "ugcPost";
1747
+ if (normalized === "grouppost") return "groupPost";
1731
1748
  return "activity";
1732
1749
  }
1733
1750
 
1734
1751
  /**
1735
1752
  * Normalize a post URL or activity id into a linkedin.com update URL.
1736
1753
  * Accepts full URLs, `urn:li:activity:…` / `urn:li:share:…` /
1737
- * `urn:li:ugcPost:…`, bare activity digits, or `/feed/update/…` paths.
1754
+ * `urn:li:ugcPost:…` / `urn:li:groupPost:<group>-<post>`, bare activity digits,
1755
+ * or `/feed/update/…` paths.
1738
1756
  */
1739
1757
  export function normalizeLinkedInPostUrl(input: string): string | null {
1740
1758
  const raw = input.trim();
@@ -1746,12 +1764,13 @@ export function normalizeLinkedInPostUrl(input: string): string | null {
1746
1764
  return `https://www.linkedin.com/feed/update/urn:li:activity:${bareId}`;
1747
1765
  }
1748
1766
 
1749
- // urn:li:activity:123, urn:li:share:123, urn:li:ugcPost:123, or the bare
1750
- // `activity:123` shorthand.
1751
- const urnMatch = raw.match(/(?:urn:li:)?(activity|share|ugcPost):(\d{6,})/i);
1767
+ // Post URNs or shorthand, with a compound id only for groupPost.
1768
+ const urnMatch = raw.match(
1769
+ /(?:urn:li:)?(?:(activity|share|ugcPost):(\d{6,})|(groupPost):(\d+-\d{6,}))/i
1770
+ );
1752
1771
  if (urnMatch && !raw.includes("://") && !raw.startsWith("/")) {
1753
- const ns = linkedInUrnNamespace(urnMatch[1] ?? "");
1754
- return `https://www.linkedin.com/feed/update/urn:li:${ns}:${urnMatch[2] ?? ""}`;
1772
+ const ns = linkedInUrnNamespace(urnMatch[1] ?? urnMatch[3] ?? "");
1773
+ return `https://www.linkedin.com/feed/update/urn:li:${ns}:${urnMatch[2] ?? urnMatch[4] ?? ""}`;
1755
1774
  }
1756
1775
 
1757
1776
  try {
@@ -1772,11 +1791,11 @@ export function normalizeLinkedInPostUrl(input: string): string | null {
1772
1791
  // Prefer canonical feed/update URLs when we can extract a post id, keeping
1773
1792
  // whichever URN namespace the source URL used.
1774
1793
  const urnInUrl = `${u.pathname}${u.search}`.match(
1775
- /(?:urn(?::|%3A)li(?::|%3A))?(activity|share|ugcPost)(?::|%3A|-)(\d{6,})/i
1794
+ /(?:urn(?::|%3A)li(?::|%3A))?(?:(activity|share|ugcPost)(?::|%3A|-)(\d{6,})|(groupPost)(?::|%3A|-)(\d+-\d{6,}))/i
1776
1795
  );
1777
1796
  if (urnInUrl) {
1778
- const ns = linkedInUrnNamespace(urnInUrl[1] ?? "");
1779
- return `https://www.linkedin.com/feed/update/urn:li:${ns}:${urnInUrl[2] ?? ""}`;
1797
+ const ns = linkedInUrnNamespace(urnInUrl[1] ?? urnInUrl[3] ?? "");
1798
+ return `https://www.linkedin.com/feed/update/urn:li:${ns}:${urnInUrl[2] ?? urnInUrl[4] ?? ""}`;
1780
1799
  }
1781
1800
  return null;
1782
1801
  } catch {
@@ -2914,7 +2933,7 @@ export default class LinkedInConnector extends ConnectorRuntime<
2914
2933
  name: "LinkedIn",
2915
2934
  description:
2916
2935
  "Read LinkedIn feeds, notifications, and recent inbox messages through paired Chrome. Subscribe to source changes, answer direct messages, and prepare message, post, or comment drafts for human submission. Also supports local LinkedIn Data Export CSV files.",
2917
- version: "3.20.0",
2936
+ version: "3.20.1",
2918
2937
  faviconDomain: "linkedin.com",
2919
2938
  // Live feeds bind a signed-in Chrome account. Local takeout imports need no browser.
2920
2939
  browser: {