@lobu/runtime-device 24.1.1 → 24.3.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 (194) hide show
  1. package/dist/component.json +1 -1
  2. package/dist/dependencies.bun.lock +46 -134
  3. package/npm-shrinkwrap.json +229 -730
  4. package/package.json +1 -1
  5. package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +20 -5
  6. package/vendor/cli/dist/chrome-extension/accessibility-tree.js +834 -0
  7. package/vendor/cli/dist/chrome-extension/ambient-context.js +53 -0
  8. package/vendor/cli/dist/chrome-extension/auth-refresh.js +167 -0
  9. package/vendor/cli/dist/chrome-extension/automation-run.js +13 -0
  10. package/vendor/cli/dist/chrome-extension/background.js +1155 -0
  11. package/vendor/cli/dist/chrome-extension/bridge.js +140 -0
  12. package/vendor/cli/dist/chrome-extension/browser-origin-policy.js +62 -0
  13. package/vendor/cli/dist/chrome-extension/browser-recovery.js +260 -0
  14. package/vendor/cli/dist/chrome-extension/browser-url-sanitizer.js +284 -0
  15. package/vendor/cli/dist/chrome-extension/completion-response.js +12 -0
  16. package/vendor/cli/dist/chrome-extension/config.js +144 -0
  17. package/vendor/cli/dist/chrome-extension/connector-manifests/chrome.json +1516 -0
  18. package/vendor/cli/dist/chrome-extension/connector-manifests/chrome_bookmarks.json +84 -0
  19. package/vendor/cli/dist/chrome-extension/connector-manifests/chrome_downloads.json +86 -0
  20. package/vendor/cli/dist/chrome-extension/connector-manifests/chrome_history.json +78 -0
  21. package/vendor/cli/dist/chrome-extension/connector-manifests.js +1767 -0
  22. package/vendor/cli/dist/chrome-extension/console-capture.js +627 -0
  23. package/vendor/cli/dist/chrome-extension/control-activity.js +70 -0
  24. package/vendor/cli/dist/chrome-extension/debugger-lease.js +439 -0
  25. package/vendor/cli/dist/chrome-extension/feed-listener.js +488 -0
  26. package/vendor/cli/dist/chrome-extension/feed-transaction.js +48 -0
  27. package/vendor/cli/dist/chrome-extension/feeds.js +632 -0
  28. package/vendor/cli/dist/chrome-extension/focus-tab.js +25 -0
  29. package/vendor/cli/dist/chrome-extension/fonts/dm-mono-latin-500-normal.woff2 +0 -0
  30. package/vendor/cli/dist/chrome-extension/fonts/dm-sans-latin-400-normal.woff2 +0 -0
  31. package/vendor/cli/dist/chrome-extension/fonts/dm-sans-latin-600-normal.woff2 +0 -0
  32. package/vendor/cli/dist/chrome-extension/heartbeat.js +140 -0
  33. package/vendor/cli/dist/chrome-extension/icons/icon-128-rec.png +0 -0
  34. package/vendor/cli/dist/chrome-extension/icons/icon-128.png +0 -0
  35. package/vendor/cli/dist/chrome-extension/icons/icon-16-rec.png +0 -0
  36. package/vendor/cli/dist/chrome-extension/icons/icon-16.png +0 -0
  37. package/vendor/cli/dist/chrome-extension/icons/icon-32-rec.png +0 -0
  38. package/vendor/cli/dist/chrome-extension/icons/icon-32.png +0 -0
  39. package/vendor/cli/dist/chrome-extension/icons/icon-48-rec.png +0 -0
  40. package/vendor/cli/dist/chrome-extension/icons/icon-48.png +0 -0
  41. package/vendor/cli/dist/chrome-extension/lens-page.js +135 -0
  42. package/vendor/cli/dist/chrome-extension/lens-target.js +20 -0
  43. package/vendor/cli/dist/chrome-extension/manifest.json +76 -0
  44. package/vendor/cli/dist/chrome-extension/network-intercept.js +657 -0
  45. package/vendor/cli/dist/chrome-extension/page-activation.js +120 -0
  46. package/vendor/cli/dist/chrome-extension/page-dialogs.js +125 -0
  47. package/vendor/cli/dist/chrome-extension/page-url.js +11 -0
  48. package/vendor/cli/dist/chrome-extension/panel-session.js +184 -0
  49. package/vendor/cli/dist/chrome-extension/poll-auth.js +85 -0
  50. package/vendor/cli/dist/chrome-extension/poll-backoff.js +22 -0
  51. package/vendor/cli/dist/chrome-extension/run-fence.js +117 -0
  52. package/vendor/cli/dist/chrome-extension/setup-status.js +71 -0
  53. package/vendor/cli/dist/chrome-extension/side-panel-action-click.js +65 -0
  54. package/vendor/cli/dist/chrome-extension/sidepanel-context.js +50 -0
  55. package/vendor/cli/dist/chrome-extension/sidepanel.html +680 -0
  56. package/vendor/cli/dist/chrome-extension/sidepanel.js +1643 -0
  57. package/vendor/cli/dist/chrome-extension/tab-labels.js +233 -0
  58. package/vendor/cli/dist/chrome-extension/tools.js +3354 -0
  59. package/vendor/cli/dist/chrome-extension/watch-observer.js +354 -0
  60. package/vendor/cli/dist/chrome-extension/watch-redact.js +96 -0
  61. package/vendor/cli/dist/chrome-extension/watch.js +348 -0
  62. package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +6 -4
  63. package/vendor/cli/dist/commands/_lib/apply/desired-state.js +5 -3
  64. package/vendor/cli/dist/commands/_lib/apply/diff.js +4 -3
  65. package/vendor/cli/dist/commands/_lib/chrome-for-testing.d.ts +13 -0
  66. package/vendor/cli/dist/commands/_lib/chrome-for-testing.js +226 -0
  67. package/vendor/cli/dist/commands/_lib/device-credential.d.ts +34 -0
  68. package/vendor/cli/dist/commands/_lib/device-credential.js +157 -0
  69. package/vendor/cli/dist/commands/_lib/device-wizard.d.ts +17 -0
  70. package/vendor/cli/dist/commands/_lib/device-wizard.js +11 -2
  71. package/vendor/cli/dist/commands/_lib/native-messaging.d.ts +7 -0
  72. package/vendor/cli/dist/commands/_lib/native-messaging.js +40 -0
  73. package/vendor/cli/dist/commands/browser.d.ts +23 -0
  74. package/vendor/cli/dist/commands/browser.js +492 -0
  75. package/vendor/cli/dist/commands/call.d.ts +12 -0
  76. package/vendor/cli/dist/commands/call.js +48 -26
  77. package/vendor/cli/dist/commands/chat.d.ts +0 -12
  78. package/vendor/cli/dist/commands/chat.js +1 -1
  79. package/vendor/cli/dist/commands/context.d.ts +3 -1
  80. package/vendor/cli/dist/commands/context.js +13 -2
  81. package/vendor/cli/dist/commands/daemon.js +38 -171
  82. package/vendor/cli/dist/commands/doctor.d.ts +0 -6
  83. package/vendor/cli/dist/commands/doctor.js +1 -1
  84. package/vendor/cli/dist/commands/memory/_lib/errors.d.ts +4 -1
  85. package/vendor/cli/dist/commands/memory/_lib/errors.js +9 -1
  86. package/vendor/cli/dist/commands/memory/_lib/mcp.d.ts +0 -9
  87. package/vendor/cli/dist/commands/memory/_lib/mcp.js +1 -23
  88. package/vendor/cli/dist/commands/memory/_lib/memory-auth.d.ts +20 -4
  89. package/vendor/cli/dist/commands/memory/_lib/memory-auth.js +21 -17
  90. package/vendor/cli/dist/commands/memory/_lib/seed-cmd.d.ts +0 -8
  91. package/vendor/cli/dist/commands/memory/_lib/seed-cmd.js +7 -18
  92. package/vendor/cli/dist/commands/memory/run.js +4 -25
  93. package/vendor/cli/dist/config/define.d.ts +1 -1
  94. package/vendor/cli/dist/connectors/gchat.ts +31 -1
  95. package/vendor/cli/dist/connectors/google_gmail.ts +70 -41
  96. package/vendor/cli/dist/connectors/google_gmail_references.ts +406 -0
  97. package/vendor/cli/dist/connectors/linkedin-inbox-adapter.js +107 -36
  98. package/vendor/cli/dist/connectors/linkedin-inbox.ts +13 -0
  99. package/vendor/cli/dist/connectors/linkedin.ts +1 -1
  100. package/vendor/cli/dist/connectors/postgres.ts +14 -8
  101. package/vendor/cli/dist/connectors/reddit.ts +171 -5
  102. package/vendor/cli/dist/connectors/whatsapp-web-adapter.js +147 -61
  103. package/vendor/cli/dist/connectors/whatsapp-web-helpers.ts +6 -2
  104. package/vendor/cli/dist/connectors/whatsapp_web.ts +48 -17
  105. package/vendor/cli/dist/connectors/x-dm-adapter.js +252 -35
  106. package/vendor/cli/dist/connectors/x.ts +189 -13
  107. package/vendor/cli/dist/index.js +46 -6
  108. package/vendor/cli/dist/internal/cli-update-check.d.ts +33 -0
  109. package/vendor/cli/dist/internal/cli-update-check.js +98 -0
  110. package/vendor/cli/dist/internal/credentials.js +10 -36
  111. package/vendor/cli/dist/internal/device-state.d.ts +2 -0
  112. package/vendor/cli/dist/internal/device-state.js +4 -0
  113. package/vendor/cli/dist/internal/gateway-url.d.ts +0 -8
  114. package/vendor/cli/dist/internal/gateway-url.js +1 -1
  115. package/vendor/cli/dist/runtime-components.json +4 -4
  116. package/vendor/cli/dist/templates/AGENTS.md.tmpl +3 -1
  117. package/vendor/cli/dist/templates/TESTING.md.tmpl +8 -8
  118. package/vendor/cli/package.json +1 -1
  119. package/vendor/connector-sdk/dist/browser-requirement.js +1 -1
  120. package/vendor/connector-sdk/dist/connector-types.d.ts +34 -1
  121. package/vendor/connector-sdk/dist/index.d.ts +3 -1
  122. package/vendor/connector-sdk/dist/index.js +4 -0
  123. package/vendor/connector-sdk/dist/redact.d.ts +10 -0
  124. package/vendor/{connector-worker/dist/executor → connector-sdk/dist}/redact.js +0 -49
  125. package/vendor/connector-sdk/dist/types.d.ts +2 -1
  126. package/vendor/connector-sdk/package.json +6 -1
  127. package/vendor/connector-worker/dist/agent-turn/gateway-tools.d.ts +9 -0
  128. package/vendor/connector-worker/dist/agent-turn/gateway-tools.js +23 -2
  129. package/vendor/connector-worker/dist/agent-turn/guest-entry.js +14 -6
  130. package/vendor/connector-worker/dist/agent-turn/guest.bundle.js +62 -25
  131. package/vendor/connector-worker/dist/agent-turn/media-tools.d.ts +1 -0
  132. package/vendor/connector-worker/dist/agent-turn/media-tools.js +5 -2
  133. package/vendor/connector-worker/dist/bin.js +2 -0
  134. package/vendor/connector-worker/dist/daemon/acp-adapters/THIRD_PARTY_LICENSES.txt +1 -1
  135. package/vendor/connector-worker/dist/daemon/acp-adapters/claude.js +7339 -2136
  136. package/vendor/connector-worker/dist/daemon/agent-turn.js +52 -17
  137. package/vendor/connector-worker/dist/daemon/automation.js +3 -13
  138. package/vendor/connector-worker/dist/daemon/client.d.ts +23 -3
  139. package/vendor/connector-worker/dist/daemon/client.js +59 -5
  140. package/vendor/connector-worker/dist/daemon/executor.d.ts +0 -28
  141. package/vendor/connector-worker/dist/daemon/executor.js +27 -12
  142. package/vendor/connector-worker/dist/daemon/index.d.ts +1 -1
  143. package/vendor/connector-worker/dist/daemon/index.js +1 -1
  144. package/vendor/connector-worker/dist/daemon/interactive-session.js +29 -6
  145. package/vendor/connector-worker/dist/daemon/poll-loop.js +29 -2
  146. package/vendor/connector-worker/dist/daemon/start.d.ts +0 -1
  147. package/vendor/connector-worker/dist/daemon/start.js +1 -1
  148. package/vendor/connector-worker/dist/daemon/terminal-delivery.d.ts +6 -10
  149. package/vendor/connector-worker/dist/daemon/terminal-delivery.js +59 -23
  150. package/vendor/connector-worker/dist/daemon/terminal-failure.js +2 -2
  151. package/vendor/connector-worker/dist/executor/isolate.js +4 -1
  152. package/vendor/connector-worker/dist/isolate/bridge.d.ts +6 -2
  153. package/vendor/connector-worker/dist/isolate/bridge.js +14 -8
  154. package/vendor/connector-worker/package.json +2 -2
  155. package/vendor/core/dist/agent-tooling.d.ts +8 -0
  156. package/vendor/core/dist/agent-tooling.js +9 -1
  157. package/vendor/core/dist/capabilities.d.ts +1 -1
  158. package/vendor/core/dist/capabilities.js +5 -0
  159. package/vendor/core/dist/connector-query-errors.d.ts +6 -0
  160. package/vendor/core/dist/connector-query-errors.js +4 -0
  161. package/vendor/core/dist/contracts/entity-reference.d.ts +3 -0
  162. package/vendor/core/dist/contracts/entity-reference.js +31 -0
  163. package/vendor/core/dist/contracts/tools/manage-automations.d.ts +3 -0
  164. package/vendor/core/dist/contracts/tools/manage-automations.js +4 -1
  165. package/vendor/core/dist/contracts/tools/manage-connections.js +1 -1
  166. package/vendor/core/dist/contracts/tools/manage-entity-schema.js +2 -2
  167. package/vendor/core/dist/contracts/tools/manage-entity.d.ts +117 -34
  168. package/vendor/core/dist/contracts/tools/manage-entity.js +47 -14
  169. package/vendor/core/dist/contracts/tools/manage-operations.d.ts +13 -4
  170. package/vendor/core/dist/contracts/tools/manage-operations.js +19 -7
  171. package/vendor/core/dist/contracts/tools/read-knowledge.d.ts +6 -1
  172. package/vendor/core/dist/contracts/tools/read-knowledge.js +20 -1
  173. package/vendor/core/dist/contracts/tools/view-attach.d.ts +1 -1
  174. package/vendor/core/dist/contracts/tools/view-runtime.d.ts +2 -0
  175. package/vendor/core/dist/contracts/tools/view-runtime.js +3 -1
  176. package/vendor/core/dist/contracts/worker/device-automation.d.ts +4 -9
  177. package/vendor/core/dist/contracts/worker/device-automation.js +10 -15
  178. package/vendor/core/dist/contracts/worker/protocol.d.ts +20 -0
  179. package/vendor/core/dist/contracts/worker/protocol.js +20 -0
  180. package/vendor/core/dist/errors.d.ts +0 -20
  181. package/vendor/core/dist/errors.js +1 -25
  182. package/vendor/core/dist/otel.js +38 -10
  183. package/vendor/core/dist/reserved.d.ts +6 -3
  184. package/vendor/core/dist/reserved.js +6 -3
  185. package/vendor/core/dist/utils/ajv.js +3 -1
  186. package/vendor/core/dist/worker/auth.d.ts +3 -2
  187. package/vendor/core/package.json +31 -5
  188. package/vendor/postgres/cf/src/query.js +3 -1
  189. package/vendor/postgres/cjs/src/query.js +3 -1
  190. package/vendor/postgres/src/query.js +3 -1
  191. package/vendor/connector-worker/dist/executor/http-status.d.ts +0 -16
  192. package/vendor/connector-worker/dist/executor/http-status.js +0 -21
  193. package/vendor/connector-worker/dist/executor/redact.d.ts +0 -29
  194. /package/vendor/postgres/{.bun-tag-2f292c6554a8475e → .bun-tag-22d644c2873790db} +0 -0
@@ -57,6 +57,14 @@ export function linkedInInboxProgram() {
57
57
  fail("Account identity is unavailable");
58
58
  return urn.replace("fs_miniProfile", "fsd_profile");
59
59
  }
60
+ async function boundAccount(expected) {
61
+ if (typeof expected !== "string" || !/^urn:li:fs_miniProfile:.+$/.test(expected))
62
+ fail("Source requires the connection's saved account; reconnect this source");
63
+ const member = await account();
64
+ if (expected.replace(/^urn:li:fs_miniProfile:/, "urn:li:fsd_profile:") !== member)
65
+ fail("Source does not match the connection's saved account; reconnect this source");
66
+ return member;
67
+ }
60
68
  const PAGE_MAILBOX = /^urn:li:fsd_pageMailbox:[0-9]+$/;
61
69
  const NOT_ADMIN =
62
70
  "The signed-in LinkedIn account does not administer this page inbox";
@@ -83,8 +91,8 @@ export function linkedInInboxProgram() {
83
91
  // The inbox one feed reads: the signed-in member's own ("me", the default),
84
92
  // or a company page's mailbox the member administers. `member` is the
85
93
  // signed-in account, which must not change while the inbox is in use.
86
- async function inboxOf(selected) {
87
- const member = await account();
94
+ async function inboxOf(selected, expected) {
95
+ const member = await boundAccount(expected);
88
96
  if (selected === undefined || selected === null || selected === "me")
89
97
  return { mailbox: member, member, page: false };
90
98
  if (typeof selected !== "string" || !PAGE_MAILBOX.test(selected))
@@ -656,7 +664,7 @@ export function linkedInInboxProgram() {
656
664
  }
657
665
  async function read(input) {
658
666
  const inbox = await inboxOf(
659
- input.feed === "live_messages" ? input.inbox : undefined
667
+ input.feed === "live_messages" ? input.inbox : undefined, input.expected_account
660
668
  );
661
669
  const mailbox = inbox.mailbox;
662
670
  const cursor = cursorOf(input.cursor, input.feed, inbox);
@@ -713,6 +721,17 @@ export function linkedInInboxProgram() {
713
721
  .map((byte) => byte.toString(16).padStart(2, "0"))
714
722
  .join("");
715
723
  }
724
+ // Keep SHA-256 fingerprints losslessly in base64url inside checkpoints.
725
+ // Batch checkpoints carry both predecessor and successor, so hex would
726
+ // exhaust the transport budget before a large interrupted pass can resume.
727
+ function compactHash(value) {
728
+ if (typeof value !== "string" || !/^[a-f0-9]{64}$/.test(value)) return value;
729
+ return btoa(String.fromCharCode(...value.match(/../g).map(byte => parseInt(byte, 16))))
730
+ .replaceAll("+", "-").replaceAll("/", "_").replace(/=+$/, "");
731
+ }
732
+ function compactSeen(seen) {
733
+ return Object.fromEntries(Object.entries(seen ?? {}).map(([key, value]) => [compactHash(key), Array.isArray(value) ? [compactHash(value[0]), value[1]] : compactHash(value)]));
734
+ }
716
735
  // One observation pass is bounded source work. Message catch-up resumes from
717
736
  // its checkpoint; notifications reorder at the top and report a gap instead.
718
737
  const NOTIFICATION_PAGES_PER_PASS = 10;
@@ -753,7 +772,7 @@ export function linkedInInboxProgram() {
753
772
  }
754
773
  payload = next;
755
774
  }
756
- // `seen` is the whole position: an unchanged inbox repeats its checkpoint.
775
+ // `seen` records source position; the delivery layer also carries a monotonic generation.
757
776
  return {};
758
777
  }
759
778
  async function catchUpConversation(
@@ -844,14 +863,19 @@ export function linkedInInboxProgram() {
844
863
  async function snapshot(feed, previous, inbox) {
845
864
  const observedAt = Date.now();
846
865
  const observed = new Map();
866
+ const previousSeen = compactSeen(previous?.seen);
847
867
  const events = [];
848
868
  // Returns whether the previous checkpoint already held this identity.
849
869
  async function observe(row, eventType, resourceType, revisionText) {
850
870
  const identity = await digest(row.id);
851
871
  const revision =
852
872
  revisionText === undefined ? identity : await digest(revisionText);
853
- const prior = previous?.seen[identity];
854
- if (previous && prior !== revision && !observed.has(identity)) {
873
+ const key = compactHash(identity);
874
+ const fingerprint = revisionText === undefined ? "1" : compactHash(revision);
875
+ const stored = previousSeen[key];
876
+ const prior = Array.isArray(stored) ? stored[0] : stored;
877
+ const unchanged = prior === fingerprint || (revisionText === undefined && prior === key);
878
+ if (previous && !unchanged && !observed.has(key)) {
855
879
  events.push({
856
880
  id: `${identity}:${revision}`,
857
881
  event_type: eventType,
@@ -860,8 +884,12 @@ export function linkedInInboxProgram() {
860
884
  occurred_at: row.occurred_at ?? new Date(observedAt).toISOString(),
861
885
  });
862
886
  }
863
- observed.set(identity, revision);
864
- return prior !== undefined;
887
+ // Overlapping pages must checkpoint the same revision we emitted first.
888
+ if (!observed.has(key)) observed.set(key, fingerprint);
889
+ // Accepted chunks suppress repeats, but newly accepted items are not
890
+ // the original catch-up boundary. Otherwise a rebind stops on page one
891
+ // before reaching unfinished provider pages.
892
+ return Array.isArray(stored) ? stored[1] === true : prior !== undefined;
865
893
  }
866
894
  // The provider cannot show what lies beyond this position. Report it once
867
895
  // per position and advance, rather than retrying or claiming completeness.
@@ -890,41 +918,84 @@ export function linkedInInboxProgram() {
890
918
  seen: Object.fromEntries(
891
919
  [
892
920
  ...observed,
893
- ...Object.entries(previous?.seen ?? {}).filter(
921
+ ...Object.entries(previousSeen).filter(
894
922
  ([identity]) => !observed.has(identity)
895
923
  ),
896
- ].slice(0, SEEN_LIMIT)
924
+ ].slice(0, feed === "notifications" ? Math.max(SEEN_LIMIT, observed.size) : SEEN_LIMIT).map(([key, value]) => [key, Array.isArray(value) ? value[0] : value])
897
925
  ),
898
926
  };
899
- return { checkpoint, events, more };
927
+ return { checkpoint, events, more, observed };
900
928
  }
901
- // Ordered batches of at most 500 references and 128 KiB. Only the final
902
- // batch carries the checkpoint, so an interruption cannot skip references.
929
+ // Each accepted chunk commits only its own seen identities. Source position
930
+ // advances on the final chunk; a rebind can safely rescan the unfinished page.
903
931
  async function batchesOf(feed, previous, result) {
904
- const next = { linkedin_inbox: result.checkpoint };
905
932
  const { events } = result;
906
- const base = `${feed}:${await digest(JSON.stringify([previous, next, events]))}`;
907
- const size = (batch) =>
908
- new TextEncoder().encode(JSON.stringify(batch)).length;
933
+ const prior = previous?.linkedin_inbox;
934
+ const epoch = prior?.observation_epoch ?? (prior
935
+ ? await digest(JSON.stringify(["legacy-observation", prior]))
936
+ : crypto.randomUUID());
937
+ let generation = prior?.observation_generation ?? 0;
938
+ if (!Number.isSafeInteger(generation) || generation < 0)
939
+ fail("Invalid observation generation");
940
+ const size = (batch) => new TextEncoder().encode(JSON.stringify(batch)).length;
909
941
  const batches = [];
942
+ let cursor = previous;
910
943
  for (let offset = 0; ; ) {
911
- const through = (end) => ({
912
- id: `${base}:${offset}`,
913
- events: events.slice(offset, end),
914
- ...(end === events.length
915
- ? { checkpoint: { previous, next }, more: result.more }
916
- : {}),
917
- });
944
+ const nextGeneration = events.length || !prior?.observation_epoch ? generation + 1 : generation;
945
+ if (!Number.isSafeInteger(nextGeneration)) fail("Observation generation exhausted");
946
+ const observedEvents = await Promise.all(events.slice(offset, offset + BATCH_EVENTS).map(async (event) => ({
947
+ ...event,
948
+ id: event.event_type === "notification.changed"
949
+ ? await digest(JSON.stringify([epoch, nextGeneration, event.id])) : event.id,
950
+ })));
951
+ const through = async (end) => {
952
+ const final = end === events.length;
953
+ let seen = compactSeen(cursor?.linkedin_inbox?.seen);
954
+ for (const event of events.slice(offset, end)) {
955
+ const identity = compactHash(await digest(event.resource_ref));
956
+ if (result.observed.has(identity)) {
957
+ const prior = seen[identity];
958
+ const anchor = Array.isArray(prior) ? prior[1] : prior !== undefined;
959
+ seen[identity] = [result.observed.get(identity), anchor];
960
+ }
961
+ }
962
+ // Keep the prior completed pass's bounded anchors until this pass ends.
963
+ // Only provisional message IDs can be evicted safely: native-ID replay
964
+ // dedupes, while evicting an original anchor invents a new source gap.
965
+ // Mutable notification fingerprints survive the entire unfinished pass.
966
+ if (feed === "live_messages") {
967
+ const entries = Object.entries(seen);
968
+ const original = ([, value]) => !Array.isArray(value) || value[1] === true;
969
+ seen = Object.fromEntries([
970
+ ...entries.filter(original),
971
+ ...entries.filter((entry) => !original(entry)).slice(-SEEN_LIMIT),
972
+ ]);
973
+ }
974
+ const next = { linkedin_inbox: {
975
+ ...(final ? result.checkpoint : { ...prior, seen }),
976
+ observation_epoch: epoch,
977
+ observation_generation: nextGeneration,
978
+ } };
979
+ const slice = observedEvents.slice(0, end - offset);
980
+ return {
981
+ id: `${feed}:${epoch}:${nextGeneration}:${await digest(JSON.stringify([cursor, next, slice]))}`,
982
+ events: slice,
983
+ checkpoint: { previous: cursor, next },
984
+ ...(final ? { more: result.more } : {}),
985
+ };
986
+ };
918
987
  let end = Math.min(offset + BATCH_EVENTS, events.length);
919
- let batch = through(end);
988
+ let batch = await through(end);
920
989
  while (size(batch) > BATCH_BYTES && end - offset > 1) {
921
990
  end = offset + Math.floor((end - offset) / 2);
922
- batch = through(end);
991
+ batch = await through(end);
923
992
  }
924
993
  if (size(batch) > BATCH_BYTES)
925
994
  fail("Source reference batch exceeds the browser record limit");
926
995
  batches.push(batch);
927
996
  if (end === events.length) return batches;
997
+ cursor = batch.checkpoint.next;
998
+ generation++;
928
999
  offset = end;
929
1000
  }
930
1001
  }
@@ -1010,11 +1081,11 @@ export function linkedInInboxProgram() {
1010
1081
  "LinkedIn source delivery was rejected; reattach from the durable checkpoint"
1011
1082
  );
1012
1083
  if (event.data.ok && listener.batches.length) {
1013
- // Receipt means the browser durably buffered the batch. Only the server
1014
- // commits the final batch's checkpoint; a reattach starts from that value.
1084
+ // The page receipt means buffered, not committed. A reattach uses the
1085
+ // server's durable per-chunk checkpoint; observation identities survive replay.
1015
1086
  const done = listener.batches.shift();
1016
1087
  if (done.checkpoint) listener.checkpoint = done.checkpoint.next;
1017
- else post(listener, listener.batches[0]);
1088
+ if (listener.batches.length) post(listener, listener.batches[0]);
1018
1089
  }
1019
1090
  }
1020
1091
  // Direct send, approved ONLY for replying to direct messages on accounts the
@@ -1046,9 +1117,9 @@ export function linkedInInboxProgram() {
1046
1117
  // `conversation_id` is a thread id of the member's own inbox, or a full
1047
1118
  // conversation URN whose mailbox names the inbox the reply leaves from: the
1048
1119
  // member's own or a page the member administers.
1049
- async function sendTarget(given) {
1120
+ async function sendTarget(given, expected) {
1050
1121
  if (typeof given === "string" && /^[A-Za-z0-9_-]+=*$/.test(given)) {
1051
- const member = await account();
1122
+ const member = await boundAccount(expected);
1052
1123
  return { inbox: { mailbox: member, member, page: false }, thread: given };
1053
1124
  }
1054
1125
  const match =
@@ -1061,14 +1132,14 @@ export function linkedInInboxProgram() {
1061
1132
  "conversation_id must be a LinkedIn conversation thread id or conversation URN"
1062
1133
  );
1063
1134
  if (PAGE_MAILBOX.test(match[1]))
1064
- return { inbox: await inboxOf(match[1]), thread: match[2] };
1065
- const member = await account();
1135
+ return { inbox: await inboxOf(match[1], expected), thread: match[2] };
1136
+ const member = await boundAccount(expected);
1066
1137
  if (match[1] !== member)
1067
1138
  fail("The conversation belongs to another LinkedIn account; not sending");
1068
1139
  return { inbox: { mailbox: member, member, page: false }, thread: match[2] };
1069
1140
  }
1070
1141
  async function send(input) {
1071
- const { inbox, thread } = await sendTarget(input.conversation_id);
1142
+ const { inbox, thread } = await sendTarget(input.conversation_id, input.expected_account);
1072
1143
  const mailbox = inbox.mailbox;
1073
1144
  const text = typeof input.text === "string" ? input.text.trim() : "";
1074
1145
  if (!text || text.length > 3000)
@@ -1145,7 +1216,7 @@ export function linkedInInboxProgram() {
1145
1216
  if (!input.bridge_id || !input.token)
1146
1217
  fail("Source subscription binding is required");
1147
1218
  const inbox = await inboxOf(
1148
- input.feed === "live_messages" ? input.inbox : undefined
1219
+ input.feed === "live_messages" ? input.inbox : undefined, input.expected_account
1149
1220
  );
1150
1221
  const previous = input.checkpoint?.linkedin_inbox;
1151
1222
  // A mailbox change restarts the baseline, but never permits a changed sign-in.
@@ -1164,7 +1235,7 @@ export function linkedInInboxProgram() {
1164
1235
  inbox,
1165
1236
  // The last posted record; only its receipt may advance delivery.
1166
1237
  sequence: 0,
1167
- // The checkpoint the next snapshot starts from, set by the final batch's receipt.
1238
+ // The checkpoint the next snapshot starts from, set by each batch receipt.
1168
1239
  checkpoint: input.checkpoint ?? null,
1169
1240
  // Undelivered batches of the current snapshot, in order.
1170
1241
  batches: [],
@@ -34,6 +34,13 @@ function inboxOf(feedKey: string, config: unknown): unknown {
34
34
  : undefined;
35
35
  }
36
36
 
37
+ function savedAccount(ctx: { sessionState?: Record<string, unknown> | null }): string {
38
+ const account = ctx.sessionState?.account_id;
39
+ if (typeof account !== "string" || !/^urn:li:fs_miniProfile:.+$/.test(account))
40
+ throw new Error("LinkedIn source requires the connection's saved account; reconnect this source");
41
+ return account;
42
+ }
43
+
37
44
  async function readyTab(browser: ChromeActionDispatcher): Promise<number> {
38
45
  // Opening the inbox itself marks conversations seen. A scrape-owned neutral
39
46
  // tab supplies authentication without changing notification/message state.
@@ -81,12 +88,14 @@ export async function sendLinkedInMessage(
81
88
  ctx: ActionContext
82
89
  ): Promise<ActionResult> {
83
90
  try {
91
+ const expectedAccount = savedAccount(ctx);
84
92
  const browser = requireBrowser(ctx);
85
93
  const output = await invoke<Record<string, unknown>>(
86
94
  browser,
87
95
  await readyTab(browser),
88
96
  "send",
89
97
  {
98
+ expected_account: expectedAccount,
90
99
  conversation_id: ctx.input.conversation_id,
91
100
  text: ctx.input.text,
92
101
  idempotency_key: ctx.input.idempotency_key,
@@ -116,8 +125,10 @@ export async function readLinkedInInbox<F>(
116
125
  } else {
117
126
  assertInboxSourceRead(ctx, "LinkedIn");
118
127
  }
128
+ const expectedAccount = savedAccount(ctx);
119
129
  const browser = requireBrowser(ctx);
120
130
  return invoke(browser, await readyTab(browser), "read", {
131
+ expected_account: expectedAccount,
121
132
  feed: ctx.feedKey,
122
133
  inbox: inboxOf(ctx.feedKey, ctx.config),
123
134
  query: ctx.query,
@@ -130,6 +141,7 @@ export async function observeLinkedInInbox<
130
141
  C extends LinkedInInboxCheckpoint,
131
142
  F,
132
143
  >(ctx: FeedObserveContext<C, F>): Promise<void> {
144
+ const expectedAccount = savedAccount(ctx);
133
145
  const browser = requireBrowser(ctx);
134
146
  const tabId = await readyTab(browser);
135
147
  const binding = await browser.dispatch<{
@@ -150,6 +162,7 @@ export async function observeLinkedInInbox<
150
162
  feed: ctx.feedKey,
151
163
  inbox: inboxOf(ctx.feedKey, ctx.config),
152
164
  checkpoint: ctx.checkpoint,
165
+ expected_account: expectedAccount,
153
166
  bridge_id: binding.bridge_id,
154
167
  token: binding.token,
155
168
  });
@@ -2933,7 +2933,7 @@ export default class LinkedInConnector extends ConnectorRuntime<
2933
2933
  name: "LinkedIn",
2934
2934
  description:
2935
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.",
2936
- version: "3.20.1",
2936
+ version: "3.20.2",
2937
2937
  faviconDomain: "linkedin.com",
2938
2938
  // Live feeds bind a signed-in Chrome account. Local takeout imports need no browser.
2939
2939
  browser: {
@@ -227,6 +227,10 @@ function hasTopLevelLimitOrOffset(sql: string): boolean {
227
227
  return false;
228
228
  }
229
229
 
230
+ function queryValidationError(message: string) {
231
+ return Object.assign(new Error(message), { status: 400 });
232
+ }
233
+
230
234
  /**
231
235
  * Shared read-only gate for both the memory feed (sync) and live query(). It is
232
236
  * a structural check, NOT a SQL parser: the HARD write seal is the read-only
@@ -248,20 +252,20 @@ function hasTopLevelLimitOrOffset(sql: string): boolean {
248
252
  */
249
253
  function validateReadOnlySelect(raw: string): string {
250
254
  const stripped = raw.trim().replace(/;\s*$/, '');
251
- if (!stripped) throw new Error('query is empty');
255
+ if (!stripped) throw queryValidationError('query is empty');
252
256
  if (stripped.includes(';')) {
253
- throw new Error('query must be a single statement (no embedded ";").');
257
+ throw queryValidationError('query must be a single statement (no embedded ";").');
254
258
  }
255
259
  if (/\$\d/.test(stripped) || /(^|[^:]):[A-Za-z_]/.test(stripped)) {
256
- throw new Error('query must not contain bind parameters ($1, :name).');
260
+ throw queryValidationError('query must not contain bind parameters ($1, :name).');
257
261
  }
258
262
  // Allow a leading "(" for "(SELECT …) UNION …" / parenthesized selects.
259
263
  const head = stripped.replace(/^\s*\(+\s*/, '');
260
264
  if (!/^(select|with)\b/i.test(head)) {
261
- throw new Error('query must be a single read-only SELECT (or WITH … SELECT).');
265
+ throw queryValidationError('query must be a single read-only SELECT (or WITH … SELECT).');
262
266
  }
263
267
  if (hasTopLevelLimitOrOffset(stripped)) {
264
- throw new Error(
268
+ throw queryValidationError(
265
269
  'query must not include a top-level LIMIT/OFFSET — the connector adds pagination automatically (an inner LIMIT inside a subquery is fine).',
266
270
  );
267
271
  }
@@ -354,7 +358,7 @@ export default class PostgresConnector extends ConnectorRuntime {
354
358
  description:
355
359
  'Bring your own PostgreSQL database as memory, read a configured feed directly, or run governed connection-level SQL.',
356
360
  version: '1.1.0',
357
- queryCapabilities: { exactMatch: true, selection: true },
361
+ queryCapabilities: { exactMatch: true, verbatimExactMatch: true, selection: true },
358
362
  faviconDomain: 'postgresql.org',
359
363
  authSchema: {
360
364
  methods: [
@@ -530,7 +534,7 @@ export default class PostgresConnector extends ConnectorRuntime {
530
534
  const bind = (value: string) => { params.push(value); return `$${params.length}::text`; };
531
535
  let where = '';
532
536
  if (ctx.exactMatch) {
533
- const { columns, value } = ctx.exactMatch;
537
+ const { columns, value, verbatim } = ctx.exactMatch;
534
538
  if (!columns.length) throw new Error('exactMatch.columns must not be empty');
535
539
  for (const column of columns) assertIdentifier(column, 'exactMatch.column');
536
540
  const projection = await tx.unsafe(`SELECT * FROM (\n${baseSql}\n) q LIMIT 0`);
@@ -541,7 +545,9 @@ export default class PostgresConnector extends ConnectorRuntime {
541
545
  if (!candidates.some(isScalar)) {
542
546
  throw Object.assign(new Error('Exact-match identity must be a scalar; project a text key in the source query'), { status: 400 });
543
547
  }
544
- const textMatch = (ref: string) => `btrim(${ref}, ${bind('\t\n\v\f\r \u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\ufeff')}) = ${bind(value)}`;
548
+ const textMatch = (ref: string) => verbatim
549
+ ? `${ref} = ${bind(value)}`
550
+ : `btrim(${ref}, ${bind('\t\n\v\f\r \u00a0\u1680\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u2028\u2029\u202f\u205f\u3000\ufeff')}) = ${bind(value)}`;
545
551
  const numberMatch = (ref: string, cast: string) => Number.isFinite(Number(value)) && String(Number(value)) === value
546
552
  ? `${ref} = ${bind(value)}::${cast}` : 'FALSE';
547
553
  const cases = candidates.map((column) => {
@@ -1,9 +1,9 @@
1
1
  /**
2
2
  * Reddit Connector (V1 runtime)
3
3
  *
4
- * Fetches posts and comments from Reddit subreddits or search queries, and the
5
- * connected user's home feed. Supports both authenticated (OAuth) and
6
- * unauthenticated (public JSON API) modes.
4
+ * Fetches posts and comments from Reddit subreddits or search queries, the
5
+ * connected user's home feed, and inbox notification references. Supports
6
+ * both authenticated (OAuth) and unauthenticated (public JSON API) modes.
7
7
  */
8
8
 
9
9
  import {
@@ -12,8 +12,11 @@ import {
12
12
  calculateEngagementScore,
13
13
  createHttpClient,
14
14
  type EventEnvelope,
15
+ type FeedReadContext,
16
+ type FeedReadResult,
15
17
  HttpStatusError,
16
18
  paginateByCursor,
19
+ sleep,
17
20
  type SyncContext,
18
21
  type SyncResult,
19
22
  } from '@lobu/connector-sdk';
@@ -71,6 +74,35 @@ interface RedditCheckpoint {
71
74
  last_timestamp?: string;
72
75
  pagination_token?: string;
73
76
  pagination_cutoff?: string;
77
+ inbox_head?: string | null;
78
+ }
79
+
80
+ interface RedditInboxItem {
81
+ kind: string;
82
+ data: {
83
+ name: string;
84
+ author?: string | null;
85
+ subject?: string;
86
+ body?: string;
87
+ context?: string;
88
+ created_utc: number;
89
+ new?: boolean;
90
+ };
91
+ }
92
+
93
+ interface RedditInboxListing {
94
+ data: { children: RedditInboxItem[]; after: string | null };
95
+ }
96
+
97
+ function inboxUrl(item: RedditInboxItem): string {
98
+ const fallback = `https://www.reddit.com/message/messages/${encodeURIComponent(item.data.name.slice(3))}`;
99
+ if (!item.data.context) return fallback;
100
+ try {
101
+ const url = new URL(item.data.context, 'https://www.reddit.com');
102
+ return url.origin === 'https://www.reddit.com' ? url.href : fallback;
103
+ } catch {
104
+ return fallback;
105
+ }
74
106
  }
75
107
 
76
108
  // Use the gateway's URI format check: WHATWG URL parsing also accepts non-URI characters.
@@ -92,8 +124,8 @@ export default class RedditConnector extends ConnectorRuntime {
92
124
  key: 'reddit',
93
125
  name: 'Reddit',
94
126
  description:
95
- "Fetches posts and comments from Reddit subreddits or search queries, and the connected user's home feed.",
96
- version: '1.2.1',
127
+ "Fetches posts and comments from Reddit subreddits or search queries, the connected user's home feed, and inbox notification references.",
128
+ version: '1.3.0',
97
129
  faviconDomain: 'reddit.com',
98
130
  authSchema: {
99
131
  methods: [
@@ -101,6 +133,8 @@ export default class RedditConnector extends ConnectorRuntime {
101
133
  type: 'oauth',
102
134
  provider: 'reddit',
103
135
  requiredScopes: ['identity', 'read', 'history'],
136
+ // Explicit reconnect requests for new scopes use method optionalScopes.
137
+ optionalScopes: ['privatemessages'],
104
138
  loginScopes: ['identity'],
105
139
  setupInstructions:
106
140
  'Create a Reddit app at https://www.reddit.com/prefs/apps — choose "web app" as the type. Set the redirect URI to {{redirect_uri}}, then copy the client ID and secret below.',
@@ -111,6 +145,29 @@ export default class RedditConnector extends ConnectorRuntime {
111
145
  ],
112
146
  },
113
147
  feeds: {
148
+ inbox: {
149
+ key: 'inbox',
150
+ name: 'Inbox notifications',
151
+ description:
152
+ 'Capture metadata-only references to the OAuth inbox (comment/post replies, mentions and legacy private messages exposed by Reddit). Read original bodies explicitly from the source. Does not mark messages read. Chat, reactions and the modern notification bell are not covered by this API.',
153
+ requiredScopes: ['privatemessages'],
154
+ sync: (ctx) => this.syncInbox(ctx),
155
+ read: (ctx) => this.readInbox(ctx),
156
+ eventKinds: {
157
+ inbox_notification: {
158
+ description: 'A source reference to an item in the Reddit OAuth inbox',
159
+ metadataSchema: {
160
+ type: 'object',
161
+ properties: {
162
+ source_id: { type: 'string' },
163
+ source_kind: { type: 'string' },
164
+ category: { type: 'string' },
165
+ },
166
+ required: ['source_id', 'source_kind', 'category'],
167
+ },
168
+ },
169
+ },
170
+ },
114
171
  posts: {
115
172
  key: 'posts',
116
173
  name: 'Posts',
@@ -301,6 +358,115 @@ export default class RedditConnector extends ConnectorRuntime {
301
358
  private readonly RATE_LIMIT_MS = 1000;
302
359
  private readonly USER_AGENT = 'Lobu-Connector/1.0.0';
303
360
 
361
+ private async inboxPage(
362
+ ctx: Pick<FeedReadContext, 'credentials'>,
363
+ after?: string,
364
+ limit = 100,
365
+ ): Promise<RedditInboxListing['data']> {
366
+ const token = ctx.credentials?.accessToken;
367
+ if (!token) throw new Error('Reddit inbox requires user OAuth with the privatemessages scope.');
368
+ const params = new URLSearchParams({ limit: String(limit), mark: 'false', raw_json: '1' });
369
+ if (after) params.set('after', after);
370
+ const http = createHttpClient({ token, headers: { 'User-Agent': this.USER_AGENT }, errorPrefix: 'Reddit inbox' });
371
+ const response = await http.get<RedditInboxListing>(`https://oauth.reddit.com/message/inbox?${params}`);
372
+ // An access/error page must not be mistaken for an exhausted inbox.
373
+ if (!response.data || !Array.isArray(response.data.children)
374
+ || !(response.data.after === null || typeof response.data.after === 'string')) {
375
+ throw new Error('Reddit returned an invalid inbox listing.');
376
+ }
377
+ for (const item of response.data.children) {
378
+ if (!item.data || !/^t[14]_[A-Za-z0-9]+$/.test(item.data.name)
379
+ || !item.data.name.startsWith(`${item.kind}_`)
380
+ || !Number.isFinite(item.data.created_utc)) {
381
+ throw new Error('Reddit returned an invalid inbox item identity or date.');
382
+ }
383
+ }
384
+ return response.data;
385
+ }
386
+
387
+ private async readInbox(ctx: FeedReadContext): Promise<FeedReadResult> {
388
+ if (ctx.window || ctx.query || ctx.match || (ctx.offset ?? 0) > 0 || ctx.sort) {
389
+ throw new Error('Reddit inbox reads support cursor pagination only; query, window, match, offset and sort are unsupported.');
390
+ }
391
+ const page = await this.inboxPage(ctx, ctx.cursor, Math.max(1, Math.min(100, Math.trunc(ctx.limit ?? 25))));
392
+ if (page.after && page.after === ctx.cursor) throw new Error('Reddit inbox cursor did not advance.');
393
+ return {
394
+ rows: page.children.map(item => ({
395
+ id: item.data.name, kind: item.kind, subject: item.data.subject ?? null,
396
+ body: item.data.body ?? null, author: item.data.author ?? null,
397
+ occurred_at: new Date(item.data.created_utc * 1000).toISOString(),
398
+ unread: item.data.new ?? null, url: inboxUrl(item),
399
+ })),
400
+ nextCursor: page.after ?? undefined,
401
+ };
402
+ }
403
+
404
+ private async syncInbox(ctx: SyncContext): Promise<SyncResult> {
405
+ const saved = (ctx.checkpoint?.pagination_token as string | undefined) ?? undefined;
406
+ const previousHead = ctx.checkpoint?.inbox_head;
407
+ let head: string | undefined;
408
+ let catchingUp = !!saved;
409
+ const seenCursors = new Set<string>();
410
+ const seenItems = new Set<string>();
411
+ const events: EventEnvelope[] = [];
412
+ let after: string | undefined;
413
+ let exhausted = false;
414
+ // Old checkpoints have no evidence that the refreshed head meets the tail.
415
+ // Rewalk from the head instead of skipping an unobserved arrival interval.
416
+ let cursorReset = !!saved && !previousHead;
417
+ for (let page = 0; page < this.MAX_PAGES; page++) {
418
+ if (page) await sleep(this.RATE_LIMIT_MS);
419
+ if (after) seenCursors.add(after);
420
+ let listing: RedditInboxListing['data'];
421
+ try {
422
+ listing = await this.inboxPage(ctx, after);
423
+ } catch (error) {
424
+ // A deleted saved anchor must not wedge capture indefinitely. Rewalk
425
+ // the retained inbox once; auth, permission and quota failures propagate.
426
+ if (!cursorReset && after && after === saved && error instanceof HttpStatusError
427
+ && [400, 404].includes(error.status)) {
428
+ cursorReset = true;
429
+ after = undefined;
430
+ seenCursors.clear();
431
+ continue;
432
+ }
433
+ throw error;
434
+ }
435
+ head ??= listing.children[0]?.data.name;
436
+ for (const item of listing.children) {
437
+ if (seenItems.has(item.data.name)) continue;
438
+ seenItems.add(item.data.name);
439
+ const category = item.kind === 't4' ? 'private_message' : 'comment_notification';
440
+ events.push({
441
+ origin_id: `reddit_inbox_${item.data.name}`, origin_type: 'inbox_notification',
442
+ payload_text: '',
443
+ title: item.kind === 't4' ? 'Reddit private message' : 'Reddit comment notification',
444
+ source_url: inboxUrl(item), occurred_at: new Date(item.data.created_utc * 1000),
445
+ metadata: { source_id: item.data.name, source_kind: item.kind, category },
446
+ });
447
+ }
448
+ after = listing.after ?? undefined;
449
+ // Re-read every arrival page through the prior head before resuming the
450
+ // unfinished history sweep. A deleted/missing boundary falls back to a
451
+ // bounded full sweep; occurrence time cannot safely exclude older items.
452
+ if (catchingUp && listing.children.some(item => item.data.name === previousHead)) {
453
+ catchingUp = false;
454
+ if (after && saved) after = saved;
455
+ }
456
+ if (!after) {
457
+ exhausted = true;
458
+ break;
459
+ }
460
+ if (seenCursors.has(after)) throw new Error('Reddit inbox cursor did not advance.');
461
+ }
462
+ await ctx.commit(events, { pagination_token: after ?? null, inbox_head: head ?? null });
463
+ // A reset on the final request leaves no cursor but still needs a new sweep.
464
+ return { status: exhausted ? 'complete' : 'more', metadata: {
465
+ items_found: events.length,
466
+ ...(cursorReset ? { cursor_reset: true } : {}),
467
+ } };
468
+ }
469
+
304
470
  // -------------------------------------------------------------------------
305
471
  // sync
306
472
  // -------------------------------------------------------------------------