@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
@@ -0,0 +1,140 @@
1
+ // Per-run heartbeat for browser-worker runs.
2
+ //
3
+ // The connector-worker daemon (packages/connector-worker/src/daemon/executor.ts
4
+ // in the lobu repo) heartbeats every 30s while a run is in flight so the
5
+ // gateway's stale-run reaper can safely write off runs whose worker
6
+ // crashed mid-flight. The Chrome service-worker run path needs the same
7
+ // signal — without it, when the user closes a tab, the laptop sleeps,
8
+ // or the extension is killed, the corresponding `runs` row sits in
9
+ // `claimed`/`running` forever.
10
+ //
11
+ // MV3 service workers are torn down between events, so a setInterval
12
+ // won't survive a SW sleep. chrome.alarms persists across SW restarts
13
+ // and re-fires when Chrome wakes the worker — exactly the lifecycle
14
+ // guarantee we need for a long-running tab-bound run.
15
+ //
16
+ // One alarm per in-flight run, named `${HEARTBEAT_ALARM_PREFIX}<runId>`.
17
+ // Callers wire `startHeartbeatAlarm(runId)` at run start and
18
+ // `stopHeartbeatAlarm(runId)` at run completion / error / tab close.
19
+
20
+ // Mirrors the daemon's 30s cadence. Chrome 120+ enforces 30s minimum;
21
+ // earlier versions clamp to a longer period. We pin
22
+ // `minimum_chrome_version: 120` in manifest.json so this cadence is
23
+ // honoured rather than silently extended.
24
+ export const HEARTBEAT_PERIOD_MINUTES = 0.5;
25
+ export const HEARTBEAT_ALARM_PREFIX = "owletto.heartbeat.";
26
+
27
+ // Tracks runs whose executor is live in THIS service-worker instance.
28
+ // MV3 alarms persist across SW restarts, so an alarm can wake the
29
+ // worker after a crash and try to heartbeat a run whose local executor
30
+ // is gone. Without this guard the heartbeat would keep the dead run
31
+ // "alive" forever in the gateway's eyes, defeating the stale-run reaper.
32
+ // On every tick the handler checks `isRunActive(runId)`; if the run is
33
+ // not in this set the alarm is cleared and no POST is sent, so the
34
+ // gateway reaper recovers the row normally.
35
+ const activeRunIds = new Set();
36
+
37
+ function markRunActive(runId) {
38
+ activeRunIds.add(runId);
39
+ }
40
+
41
+ function markRunInactive(runId) {
42
+ activeRunIds.delete(runId);
43
+ }
44
+
45
+ export function isRunActive(runId) {
46
+ return activeRunIds.has(runId);
47
+ }
48
+
49
+ // Test-only: reset the in-memory registry between cases.
50
+ export function __resetActiveRunsForTest() {
51
+ activeRunIds.clear();
52
+ }
53
+
54
+ export function startHeartbeatAlarm(chromeApi, runId) {
55
+ markRunActive(runId);
56
+ chromeApi.alarms.create(`${HEARTBEAT_ALARM_PREFIX}${runId}`, {
57
+ periodInMinutes: HEARTBEAT_PERIOD_MINUTES,
58
+ });
59
+ }
60
+
61
+ export async function stopHeartbeatAlarm(chromeApi, runId) {
62
+ // Mark inactive synchronously first so any in-flight heartbeat tick
63
+ // that observes the registry after this point becomes a no-op even
64
+ // before chrome.alarms.clear() resolves. This closes the race where
65
+ // the alarm has already fired but sendHeartbeat hasn't yet checked
66
+ // `isRunActive`.
67
+ markRunInactive(runId);
68
+ try {
69
+ await chromeApi.alarms.clear(`${HEARTBEAT_ALARM_PREFIX}${runId}`);
70
+ } catch {
71
+ // chrome.alarms.clear can reject if the alarm doesn't exist; the
72
+ // result is the same as success for our purposes.
73
+ }
74
+ }
75
+
76
+ export function isHeartbeatAlarm(alarmName) {
77
+ return typeof alarmName === "string" && alarmName.startsWith(HEARTBEAT_ALARM_PREFIX);
78
+ }
79
+
80
+ export function runIdFromAlarmName(alarmName) {
81
+ if (!isHeartbeatAlarm(alarmName)) return null;
82
+ const n = Number(alarmName.slice(HEARTBEAT_ALARM_PREFIX.length));
83
+ return Number.isFinite(n) ? n : null;
84
+ }
85
+
86
+ // POST /api/workers/heartbeat for `runId`. The handler ignores the
87
+ // returned value; callers can `await` it just to see the network error
88
+ // surface. Guards:
89
+ //
90
+ // - If the run is not in the active registry, the alarm is cleared
91
+ // and no POST is sent. This covers two cases: (a) the SW was torn
92
+ // down and woke later — the executor isn't running here anymore,
93
+ // so let the gateway reaper recover the row; (b) the alarm tick
94
+ // fires between safeComplete's `markRunInactive` and the actual
95
+ // `chrome.alarms.clear` resolving — the registry check makes the
96
+ // tick a no-op so we never POST after completion.
97
+ // - On 4xx the alarm is stopped and the run is dropped from the
98
+ // registry (the run is already terminal server-side or the worker
99
+ // was unpaired); on 5xx we throw so the onAlarm listener logs it
100
+ // and the next 30s tick retries.
101
+ export async function sendHeartbeat(chromeApi, runId, {
102
+ gatewayUrl,
103
+ workerId,
104
+ token,
105
+ fetchImpl = fetch,
106
+ }) {
107
+ if (!isRunActive(runId)) {
108
+ await stopHeartbeatAlarm(chromeApi, runId);
109
+ return;
110
+ }
111
+ if (!gatewayUrl || !workerId || !token) {
112
+ await stopHeartbeatAlarm(chromeApi, runId);
113
+ return;
114
+ }
115
+ // Yield once before the fetch so a `stopHeartbeatAlarm` queued
116
+ // synchronously by safeComplete on the same tick observably sets
117
+ // `isRunActive(runId) = false` first. Without this, a heartbeat that
118
+ // entered sendHeartbeat in the same microtask as completion would
119
+ // still race ahead of the stop and POST after the run was marked
120
+ // complete. With it, the second `isRunActive` check below catches
121
+ // that race.
122
+ await Promise.resolve();
123
+ if (!isRunActive(runId)) {
124
+ return;
125
+ }
126
+ const res = await fetchImpl(`${gatewayUrl}/api/workers/heartbeat`, {
127
+ method: "POST",
128
+ headers: {
129
+ "content-type": "application/json",
130
+ authorization: `Bearer ${token}`,
131
+ },
132
+ body: JSON.stringify({ run_id: runId, worker_id: workerId }),
133
+ });
134
+ if (!res.ok) {
135
+ if (res.status >= 400 && res.status < 500) {
136
+ await stopHeartbeatAlarm(chromeApi, runId);
137
+ }
138
+ throw new Error(`heartbeat → ${res.status}`);
139
+ }
140
+ }
@@ -0,0 +1,135 @@
1
+ // Lobu owns the Lens UI and renders its real React attention surface into the
2
+ // Document PiP window. This content script is deliberately only a bridge:
3
+ // Chrome supplies active-page context and focuses/opens browser targets.
4
+
5
+ const LENS_CONTEXT_EVENT = "owletto:lobu-lens-context";
6
+ const LENS_OPEN_TARGET_EVENT = "owletto:lobu-lens-open-target";
7
+ const LENS_OPEN_TARGET_RESPONSE_EVENT =
8
+ "owletto:lobu-lens-open-target-response";
9
+
10
+ function runtimeMessage(message) {
11
+ return new Promise((resolve, reject) => {
12
+ chrome.runtime.sendMessage(message, (response) => {
13
+ const runtimeError = chrome.runtime.lastError;
14
+ if (runtimeError) {
15
+ reject(new Error(runtimeError.message));
16
+ return;
17
+ }
18
+ resolve(response);
19
+ });
20
+ });
21
+ }
22
+
23
+ async function bridge(message) {
24
+ const response = await runtimeMessage(message);
25
+ if (!response?.ok) {
26
+ throw new Error(response?.error || "Owletto Lens bridge failed.");
27
+ }
28
+ return response.value;
29
+ }
30
+
31
+ function parseDetail(event) {
32
+ if (!(event instanceof CustomEvent) || typeof event.detail !== "string") {
33
+ return null;
34
+ }
35
+ try {
36
+ return JSON.parse(event.detail);
37
+ } catch {
38
+ return null;
39
+ }
40
+ }
41
+
42
+ function dispatchPageEvent(name, detail) {
43
+ document.dispatchEvent(
44
+ new CustomEvent(name, { detail: JSON.stringify(detail) }),
45
+ );
46
+ }
47
+
48
+ async function refreshDebuggerState() {
49
+ const attached = Boolean(await bridge({ op: "lens-debugger-attached" }));
50
+ document.documentElement.dataset.owlettoDebuggerAttached = String(attached);
51
+ return attached;
52
+ }
53
+
54
+ function publishContext(context) {
55
+ if (context) dispatchPageEvent(LENS_CONTEXT_EVENT, context);
56
+ }
57
+
58
+ void (async () => {
59
+ document.documentElement.setAttribute("data-owletto-lens-bridge", "");
60
+ void refreshDebuggerState().catch(() => {});
61
+
62
+ document.addEventListener(
63
+ "pointerenter",
64
+ (event) => {
65
+ if (event.target?.closest?.("[data-lobu-lens-open]")) {
66
+ void refreshDebuggerState().catch(() => {});
67
+ }
68
+ },
69
+ true,
70
+ );
71
+
72
+ document.addEventListener("owletto:lobu-lens-context-request", () => {
73
+ void bridge({ op: "lens-context-get" })
74
+ .then(publishContext)
75
+ .catch(() => {});
76
+ });
77
+ document.addEventListener(LENS_OPEN_TARGET_EVENT, (event) => {
78
+ const request = parseDetail(event);
79
+ if (!request?.id) return;
80
+ if (typeof request.url !== "string" && request.focusHost !== true) return;
81
+ const operation = request.focusHost
82
+ ? { op: "lens-focus-host" }
83
+ : { op: "lens-open-target", url: request.url };
84
+ void bridge(operation)
85
+ .then(() =>
86
+ dispatchPageEvent(LENS_OPEN_TARGET_RESPONSE_EVENT, {
87
+ id: request.id,
88
+ ok: true,
89
+ }),
90
+ )
91
+ .catch((error) =>
92
+ dispatchPageEvent(LENS_OPEN_TARGET_RESPONSE_EVENT, {
93
+ id: request.id,
94
+ ok: false,
95
+ error: error instanceof Error ? error.message : String(error),
96
+ }),
97
+ );
98
+ });
99
+
100
+ chrome.runtime.onMessage.addListener((message) => {
101
+ if (message?.op === "lens-context-changed") {
102
+ publishContext(message.context);
103
+ return false;
104
+ }
105
+ return false;
106
+ });
107
+
108
+ publishContext(await bridge({ op: "lens-context-get" }).catch(() => null));
109
+ })();
110
+
111
+ // Versioned, read-only onboarding bridge. The service worker validates the
112
+ // sender origin before touching storage; the page never receives credentials.
113
+ document.addEventListener("lobu:extension-setup-request", (event) => {
114
+ const request = parseDetail(event);
115
+ if (
116
+ request?.protocolVersion !== 1 ||
117
+ typeof request.id !== "string" ||
118
+ !/^[a-zA-Z0-9-]{1,80}$/.test(request.id)
119
+ )
120
+ return;
121
+ void bridge({ op: "setup-status-get", protocolVersion: 1 })
122
+ .then((value) =>
123
+ dispatchPageEvent("lobu:extension-setup-response", {
124
+ id: request.id,
125
+ ok: true,
126
+ value,
127
+ }),
128
+ )
129
+ .catch(() =>
130
+ dispatchPageEvent("lobu:extension-setup-response", {
131
+ id: request.id,
132
+ ok: false,
133
+ }),
134
+ );
135
+ });
@@ -0,0 +1,20 @@
1
+ export function normalizeLensTarget(value) {
2
+ try {
3
+ const url = new URL(value);
4
+ if (url.protocol !== "http:" && url.protocol !== "https:") return null;
5
+ const pathname = url.pathname.replace(/\/+$/, "") || "/";
6
+ return `${url.origin}${pathname}${url.search}`;
7
+ } catch {
8
+ return null;
9
+ }
10
+ }
11
+
12
+ export function findExistingLensTab(tabs, value) {
13
+ const target = normalizeLensTarget(value);
14
+ if (!target) return null;
15
+ return (
16
+ (Array.isArray(tabs) ? tabs : []).find(
17
+ (tab) => normalizeLensTarget(tab?.url) === target,
18
+ ) ?? null
19
+ );
20
+ }
@@ -0,0 +1,76 @@
1
+ {
2
+ "manifest_version": 3,
3
+ "name": "Lobu",
4
+ "short_name": "Lobu",
5
+ "description": "Connect this Chrome profile to your Lobu agent.",
6
+ "version": "0.9.9",
7
+ "minimum_chrome_version": "120",
8
+ "incognito": "not_allowed",
9
+ "key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt7XWpX2zQlMV7aFunbz8p5DTSv+8MvCw2PSfSV56tEF4j2bsb3mKlBMBKNCxJNV+5D4l/9MgY7fEA5LmQ4pUHV+LoboQGTH8iR7wPKpnQ7U9NW7I4FL/rDlAFB2/rcgJex7/jkDNHIF4C7A0DUuDNj2Mij15Cg5pyA3Ek8Fw5B/Qfl8OvcJtcNtSpcbvGGM/uS23BW8iIlF1aFTrLuiI9NlASfbbAY0Xozb/snt0HQOl4flOIr3LF/xRFHeo/Ko+mAdGeOlBblk4T0lYlDTVsoBJsjTyYh9hn7NEOm8a5yV60z2p/wrRlEAcwp+CoO+AHweGxw5NMZbSpC6pKTKqYQIDAQAB",
10
+ "permissions": [
11
+ "tabs",
12
+ "tabGroups",
13
+ "scripting",
14
+ "activeTab",
15
+ "debugger",
16
+ "storage",
17
+ "sidePanel",
18
+ "alarms",
19
+ "nativeMessaging",
20
+ "notifications"
21
+ ],
22
+ "optional_permissions": [
23
+ "history",
24
+ "bookmarks",
25
+ "downloads"
26
+ ],
27
+ "optional_host_permissions": [],
28
+ "content_scripts": [
29
+ {
30
+ "matches": [
31
+ "https://lobu.ai/*",
32
+ "https://*.lobu.ai/*"
33
+ ],
34
+ "js": [
35
+ "lens-page.js"
36
+ ],
37
+ "run_at": "document_idle"
38
+ }
39
+ ],
40
+ "web_accessible_resources": [
41
+ {
42
+ "resources": [
43
+ "accessibility-tree.js",
44
+ "watch-observer.js"
45
+ ],
46
+ "matches": [
47
+ "<all_urls>"
48
+ ]
49
+ }
50
+ ],
51
+ "icons": {
52
+ "16": "icons/icon-16.png",
53
+ "32": "icons/icon-32.png",
54
+ "48": "icons/icon-48.png",
55
+ "128": "icons/icon-128.png"
56
+ },
57
+ "background": {
58
+ "service_worker": "background.js",
59
+ "type": "module"
60
+ },
61
+ "side_panel": {
62
+ "default_path": "sidepanel.html"
63
+ },
64
+ "action": {
65
+ "default_title": "Lobu",
66
+ "default_icon": {
67
+ "16": "icons/icon-16.png",
68
+ "32": "icons/icon-32.png",
69
+ "48": "icons/icon-48.png",
70
+ "128": "icons/icon-128.png"
71
+ }
72
+ },
73
+ "host_permissions": [
74
+ "<all_urls>"
75
+ ]
76
+ }