@lobu/runtime-device 24.1.0 → 24.2.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 (159) hide show
  1. package/dist/component.json +1 -1
  2. package/dist/dependencies.bun.lock +26 -28
  3. package/npm-shrinkwrap.json +155 -172
  4. package/package.json +1 -1
  5. package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +14 -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/apply/render.js +4 -14
  66. package/vendor/cli/dist/commands/_lib/chrome-for-testing.d.ts +13 -0
  67. package/vendor/cli/dist/commands/_lib/chrome-for-testing.js +226 -0
  68. package/vendor/cli/dist/commands/_lib/device-credential.d.ts +34 -0
  69. package/vendor/cli/dist/commands/_lib/device-credential.js +157 -0
  70. package/vendor/cli/dist/commands/_lib/device-wizard.d.ts +17 -0
  71. package/vendor/cli/dist/commands/_lib/device-wizard.js +11 -2
  72. package/vendor/cli/dist/commands/_lib/native-messaging.d.ts +7 -0
  73. package/vendor/cli/dist/commands/_lib/native-messaging.js +40 -0
  74. package/vendor/cli/dist/commands/browser.d.ts +23 -0
  75. package/vendor/cli/dist/commands/browser.js +492 -0
  76. package/vendor/cli/dist/commands/call.d.ts +12 -0
  77. package/vendor/cli/dist/commands/call.js +48 -26
  78. package/vendor/cli/dist/commands/context.d.ts +3 -1
  79. package/vendor/cli/dist/commands/context.js +13 -2
  80. package/vendor/cli/dist/commands/daemon.js +2 -152
  81. package/vendor/cli/dist/commands/memory/_lib/errors.d.ts +4 -1
  82. package/vendor/cli/dist/commands/memory/_lib/errors.js +9 -1
  83. package/vendor/cli/dist/commands/memory/_lib/mcp.d.ts +0 -9
  84. package/vendor/cli/dist/commands/memory/_lib/mcp.js +1 -23
  85. package/vendor/cli/dist/commands/memory/_lib/memory-auth.d.ts +20 -4
  86. package/vendor/cli/dist/commands/memory/_lib/memory-auth.js +21 -17
  87. package/vendor/cli/dist/commands/memory/_lib/seed-cmd.js +6 -17
  88. package/vendor/cli/dist/commands/memory/run.js +4 -25
  89. package/vendor/cli/dist/connectors/google_gmail.ts +70 -41
  90. package/vendor/cli/dist/connectors/google_gmail_references.ts +406 -0
  91. package/vendor/cli/dist/connectors/linkedin-inbox-adapter.js +107 -36
  92. package/vendor/cli/dist/connectors/linkedin-inbox.ts +13 -0
  93. package/vendor/cli/dist/connectors/linkedin.ts +1 -1
  94. package/vendor/cli/dist/connectors/postgres.ts +5 -3
  95. package/vendor/cli/dist/connectors/reddit.ts +171 -5
  96. package/vendor/cli/dist/connectors/whatsapp-web-adapter.js +147 -61
  97. package/vendor/cli/dist/connectors/whatsapp-web-helpers.ts +6 -2
  98. package/vendor/cli/dist/connectors/whatsapp_web.ts +48 -17
  99. package/vendor/cli/dist/connectors/x-dm-adapter.js +252 -35
  100. package/vendor/cli/dist/connectors/x.ts +189 -13
  101. package/vendor/cli/dist/index.js +46 -6
  102. package/vendor/cli/dist/internal/device-state.d.ts +2 -0
  103. package/vendor/cli/dist/internal/device-state.js +4 -0
  104. package/vendor/cli/dist/runtime-components.json +4 -4
  105. package/vendor/cli/dist/templates/AGENTS.md.tmpl +3 -1
  106. package/vendor/cli/dist/templates/TESTING.md.tmpl +8 -8
  107. package/vendor/cli/package.json +1 -1
  108. package/vendor/connector-sdk/dist/browser-requirement.js +1 -1
  109. package/vendor/connector-sdk/dist/connector-types.d.ts +5 -1
  110. package/vendor/connector-sdk/package.json +1 -1
  111. package/vendor/connector-worker/dist/agent-turn/gateway-tools.d.ts +9 -0
  112. package/vendor/connector-worker/dist/agent-turn/gateway-tools.js +23 -2
  113. package/vendor/connector-worker/dist/agent-turn/guest-entry.js +14 -6
  114. package/vendor/connector-worker/dist/agent-turn/guest.bundle.js +62 -25
  115. package/vendor/connector-worker/dist/agent-turn/media-tools.d.ts +1 -0
  116. package/vendor/connector-worker/dist/agent-turn/media-tools.js +5 -2
  117. package/vendor/connector-worker/dist/bin.js +2 -0
  118. package/vendor/connector-worker/dist/daemon/agent-turn.js +52 -17
  119. package/vendor/connector-worker/dist/daemon/automation.js +2 -12
  120. package/vendor/connector-worker/dist/daemon/client.d.ts +8 -2
  121. package/vendor/connector-worker/dist/daemon/client.js +8 -1
  122. package/vendor/connector-worker/dist/daemon/interactive-session.js +29 -6
  123. package/vendor/connector-worker/dist/daemon/poll-loop.js +23 -1
  124. package/vendor/connector-worker/dist/daemon/terminal-delivery.d.ts +5 -10
  125. package/vendor/connector-worker/dist/daemon/terminal-delivery.js +55 -23
  126. package/vendor/connector-worker/dist/daemon/terminal-failure.js +2 -2
  127. package/vendor/connector-worker/dist/executor/isolate.js +3 -0
  128. package/vendor/connector-worker/package.json +1 -1
  129. package/vendor/core/dist/agent-tooling.d.ts +8 -0
  130. package/vendor/core/dist/agent-tooling.js +9 -1
  131. package/vendor/core/dist/capabilities.d.ts +1 -1
  132. package/vendor/core/dist/capabilities.js +5 -0
  133. package/vendor/core/dist/contracts/entity-reference.d.ts +3 -0
  134. package/vendor/core/dist/contracts/entity-reference.js +31 -0
  135. package/vendor/core/dist/contracts/tools/manage-automations.d.ts +3 -0
  136. package/vendor/core/dist/contracts/tools/manage-automations.js +3 -0
  137. package/vendor/core/dist/contracts/tools/manage-connections.js +1 -1
  138. package/vendor/core/dist/contracts/tools/manage-entity-schema.js +1 -1
  139. package/vendor/core/dist/contracts/tools/manage-entity.d.ts +113 -34
  140. package/vendor/core/dist/contracts/tools/manage-entity.js +41 -14
  141. package/vendor/core/dist/contracts/tools/manage-operations.d.ts +13 -4
  142. package/vendor/core/dist/contracts/tools/manage-operations.js +19 -7
  143. package/vendor/core/dist/contracts/tools/read-knowledge.d.ts +6 -1
  144. package/vendor/core/dist/contracts/tools/read-knowledge.js +20 -1
  145. package/vendor/core/dist/contracts/tools/view-attach.d.ts +1 -1
  146. package/vendor/core/dist/contracts/tools/view-runtime.d.ts +2 -0
  147. package/vendor/core/dist/contracts/tools/view-runtime.js +3 -1
  148. package/vendor/core/dist/contracts/worker/device-automation.d.ts +4 -9
  149. package/vendor/core/dist/contracts/worker/device-automation.js +10 -15
  150. package/vendor/core/dist/contracts/worker/protocol.d.ts +20 -0
  151. package/vendor/core/dist/contracts/worker/protocol.js +20 -0
  152. package/vendor/core/dist/reserved.d.ts +6 -3
  153. package/vendor/core/dist/reserved.js +6 -3
  154. package/vendor/core/dist/worker/auth.d.ts +3 -2
  155. package/vendor/core/package.json +6 -1
  156. package/vendor/postgres/cf/src/query.js +3 -1
  157. package/vendor/postgres/cjs/src/query.js +3 -1
  158. package/vendor/postgres/src/query.js +3 -1
  159. /package/vendor/postgres/{.bun-tag-2f292c6554a8475e → .bun-tag-22d644c2873790db} +0 -0
@@ -0,0 +1,284 @@
1
+ // Central policy for browser URLs and URL-like text emitted by Chrome feeds.
2
+
3
+ const SENSITIVE_QUERY_KEYS = new Set([
4
+ "apikey",
5
+ "accesstoken",
6
+ "assertion",
7
+ "authorization",
8
+ "authorizationcode",
9
+ "authtoken",
10
+ "awsaccesskeyid",
11
+ "clientsecret",
12
+ "code",
13
+ "codeverifier",
14
+ "credential",
15
+ "credentials",
16
+ "devicecode",
17
+ "googleaccessid",
18
+ "idtoken",
19
+ "jwt",
20
+ "oauthtoken",
21
+ "oauthtokensecret",
22
+ "oauthverifier",
23
+ "passcode",
24
+ "password",
25
+ "passwd",
26
+ "refreshtoken",
27
+ "requesttoken",
28
+ "samlresponse",
29
+ "secret",
30
+ "sessionstate",
31
+ "sessiontoken",
32
+ "sig",
33
+ "signature",
34
+ "ssotoken",
35
+ "state",
36
+ "token",
37
+ "tokensecret",
38
+ "usercode",
39
+ "xamzcredential",
40
+ "xamzsecuritytoken",
41
+ "xamzsignature",
42
+ "xgoogcredential",
43
+ "xgoogsignature",
44
+ ]);
45
+
46
+ const MAX_NESTED_URL_DEPTH = 2;
47
+ const MAX_NESTED_DECODES = 3;
48
+ const MAX_RECORD_DEPTH = 16;
49
+ const SCHEME_URL_RE = /^[a-z][a-z\d+.-]*:[^\s"'<>]+$/i;
50
+ const ENCODED_SCHEME_RE = /^[a-z][a-z\d+.-]*%(?:25)*3a/i;
51
+ const URL_LIKE_RE = /\b[a-z][a-z\d+.-]*:[^\s"'<>]+/gi;
52
+ const RELATIVE_URL_LIKE_RE = /(^|[\s([])(\/{1,2}[^\s"'<>]+)/g;
53
+ const URL_FIELDS = new Set([
54
+ "url",
55
+ "from_url",
56
+ "source_url",
57
+ "referrer",
58
+ "form_action",
59
+ ]);
60
+
61
+ function decodeKey(value) {
62
+ try {
63
+ return decodeURIComponent(value.replaceAll("+", " "))
64
+ .toLowerCase()
65
+ .replace(/[^a-z\d]/g, "");
66
+ } catch {
67
+ return value.toLowerCase().replace(/[^a-z\d]/g, "");
68
+ }
69
+ }
70
+
71
+ function decodeValue(value) {
72
+ try {
73
+ return decodeURIComponent(value);
74
+ } catch {
75
+ return null;
76
+ }
77
+ }
78
+
79
+ function findNestedUrl(value) {
80
+ let decoded = value;
81
+ for (let count = 0; count <= MAX_NESTED_DECODES; count += 1) {
82
+ // Stop at the first URL-shaped layer. Decoding farther would alter the
83
+ // nested URL's own percent escapes rather than remove an outer wrapper.
84
+ if (looksLikeUrl(decoded)) return { value: decoded, count };
85
+ if (count === MAX_NESTED_DECODES) {
86
+ if (ENCODED_SCHEME_RE.test(decoded)) return { tooDeep: true };
87
+ break;
88
+ }
89
+ const next = decodeValue(decoded);
90
+ if (next === null || next === decoded) break;
91
+ decoded = next;
92
+ }
93
+ return null;
94
+ }
95
+
96
+ function looksLikeUrl(value) {
97
+ return SCHEME_URL_RE.test(value);
98
+ }
99
+
100
+ function sanitizeNestedUrlValue(value, depth) {
101
+ const decoded = findNestedUrl(value);
102
+ if (!decoded) return value;
103
+ if (decoded.tooDeep) return "about:REDACTED";
104
+ // A URL nested beyond the recursion budget is opaque to this sanitizer.
105
+ // Drop that value instead of retaining a possibly encoded credential.
106
+ if (depth >= MAX_NESTED_URL_DEPTH) return "about:REDACTED";
107
+ const nested = sanitizeBrowserUrl(decoded.value, depth + 1);
108
+ if (nested === decoded.value) return value;
109
+ return restoreEncodingLayers(nested, decoded.count);
110
+ }
111
+
112
+ function sanitizeParameterSection(section, depth) {
113
+ const parts = section.split(/([&;])/);
114
+ for (let i = 0; i < parts.length; i += 2) {
115
+ const part = parts[i];
116
+ const equals = part.indexOf("=");
117
+ if (equals < 0) continue;
118
+ const key = part.slice(0, equals);
119
+ const value = part.slice(equals + 1);
120
+ if (SENSITIVE_QUERY_KEYS.has(decodeKey(key))) {
121
+ parts[i] = `${key}=REDACTED`;
122
+ continue;
123
+ }
124
+ const nested = sanitizeNestedUrlValue(value, depth);
125
+ if (nested !== value) parts[i] = `${key}=${nested}`;
126
+ }
127
+ return parts.join("");
128
+ }
129
+
130
+ function sanitizeFragment(fragment, depth) {
131
+ if (looksLikeUrl(fragment)) return sanitizeBrowserUrl(fragment, depth + 1);
132
+ const queryIndex = fragment.indexOf("?");
133
+ if (queryIndex < 0) return sanitizeParameterSection(fragment, depth);
134
+ return `${fragment.slice(0, queryIndex + 1)}${sanitizeParameterSection(
135
+ fragment.slice(queryIndex + 1),
136
+ depth,
137
+ )}`;
138
+ }
139
+
140
+ function splitTrailingTextPunctuation(match) {
141
+ const unmatchedClosers = {
142
+ ")": Math.max(0, match.split(")").length - match.split("(").length),
143
+ "]": Math.max(0, match.split("]").length - match.split("[").length),
144
+ "}": Math.max(0, match.split("}").length - match.split("{").length),
145
+ };
146
+ let end = match.length;
147
+ while (end > 0) {
148
+ const char = match[end - 1];
149
+ if (char === "." || char === "," || char === "!" || char === "?") {
150
+ end -= 1;
151
+ continue;
152
+ }
153
+ if (Object.hasOwn(unmatchedClosers, char) && unmatchedClosers[char] > 0) {
154
+ unmatchedClosers[char] -= 1;
155
+ end -= 1;
156
+ continue;
157
+ }
158
+ break;
159
+ }
160
+ return { url: match.slice(0, end), suffix: match.slice(end) };
161
+ }
162
+
163
+ function sanitizeTextMatches(value, depth) {
164
+ if (depth > MAX_NESTED_URL_DEPTH) return value;
165
+ const absoluteSanitized = value.replace(URL_LIKE_RE, (match) => {
166
+ const { url, suffix } = splitTrailingTextPunctuation(match);
167
+ return `${sanitizeBrowserUrl(url, depth)}${suffix}`;
168
+ });
169
+ return absoluteSanitized.replace(
170
+ RELATIVE_URL_LIKE_RE,
171
+ (_match, prefix, relativeUrl) => {
172
+ const { url, suffix } = splitTrailingTextPunctuation(relativeUrl);
173
+ return `${prefix}${sanitizeBrowserUrl(url, depth)}${suffix}`;
174
+ },
175
+ );
176
+ }
177
+
178
+ function restoreEncodingLayers(value, count) {
179
+ let encoded = value;
180
+ for (let layer = 0; layer < count; layer += 1) {
181
+ encoded = encodeURIComponent(encoded);
182
+ }
183
+ return encoded;
184
+ }
185
+
186
+ function sanitizeEncodedText(value, depth) {
187
+ let decoded = value;
188
+ for (let count = 1; count <= MAX_NESTED_DECODES; count += 1) {
189
+ const next = decodeValue(decoded);
190
+ if (next === null || next === decoded) break;
191
+ const sanitized = sanitizeTextMatches(next, depth);
192
+ if (sanitized !== next) return restoreEncodingLayers(sanitized, count);
193
+ decoded = next;
194
+ }
195
+ return value;
196
+ }
197
+
198
+ function sanitizeDataUrl(value, depth) {
199
+ const comma = value.indexOf(",");
200
+ if (comma < 0) return null;
201
+ const prefix = value.slice(0, comma + 1);
202
+ if (depth >= MAX_NESTED_URL_DEPTH) return `${prefix}REDACTED`;
203
+ const payload = value.slice(comma + 1);
204
+ if (/;base64$/i.test(value.slice(0, comma))) {
205
+ try {
206
+ const decoded = atob(payload);
207
+ const sanitized = sanitizeTextMatches(decoded, depth + 1);
208
+ const encodedSanitized = sanitizeEncodedText(sanitized, depth + 1);
209
+ if (encodedSanitized !== decoded) {
210
+ return `${prefix}${btoa(encodedSanitized)}`;
211
+ }
212
+ } catch {
213
+ // Preserve malformed data payloads; literal URL-like text is still
214
+ // handled below without attempting an unbounded recovery decode.
215
+ }
216
+ }
217
+ const nested = sanitizeNestedUrlValue(payload, depth);
218
+ if (nested !== payload) return `${prefix}${nested}`;
219
+ const literal = sanitizeTextMatches(payload, depth + 1);
220
+ if (literal !== payload) return `${prefix}${literal}`;
221
+ return `${prefix}${sanitizeEncodedText(payload, depth + 1)}`;
222
+ }
223
+
224
+ function sanitizeBrowserUrl(value, depth = 0) {
225
+ if (typeof value !== "string" || depth > MAX_NESTED_URL_DEPTH) return value;
226
+ if (/^data:/i.test(value)) {
227
+ const sanitizedData = sanitizeDataUrl(value, depth);
228
+ if (sanitizedData !== null) return sanitizedData;
229
+ }
230
+
231
+ const hashIndex = value.indexOf("#");
232
+ const beforeHash = hashIndex >= 0 ? value.slice(0, hashIndex) : value;
233
+ const hash = hashIndex >= 0 ? value.slice(hashIndex + 1) : null;
234
+ const queryIndex = beforeHash.indexOf("?");
235
+ const base = queryIndex >= 0 ? beforeHash.slice(0, queryIndex) : beforeHash;
236
+ const query = queryIndex >= 0 ? beforeHash.slice(queryIndex + 1) : null;
237
+ let result = base;
238
+
239
+ if (query !== null) result += `?${sanitizeParameterSection(query, depth)}`;
240
+ if (hash !== null) {
241
+ result += `#${sanitizeFragment(hash, depth)}`;
242
+ }
243
+ return result;
244
+ }
245
+
246
+ export function sanitizeBrowserText(value) {
247
+ if (typeof value !== "string") return value;
248
+ return sanitizeTextMatches(value, 0);
249
+ }
250
+
251
+ function sanitizeRecord(value, depth, ancestors) {
252
+ if (Array.isArray(value)) {
253
+ if (depth >= MAX_RECORD_DEPTH || ancestors.has(value)) return "[REDACTED]";
254
+ ancestors.add(value);
255
+ const result = value.map((entry) => sanitizeRecord(entry, depth + 1, ancestors));
256
+ ancestors.delete(value);
257
+ return result;
258
+ }
259
+ if (!value || typeof value !== "object") return sanitizeBrowserText(value);
260
+ if (depth >= MAX_RECORD_DEPTH || ancestors.has(value)) return "[REDACTED]";
261
+ ancestors.add(value);
262
+ const result = {};
263
+ for (const [key, entry] of Object.entries(value)) {
264
+ result[key] = URL_FIELDS.has(key.toLowerCase())
265
+ ? sanitizeBrowserUrl(entry)
266
+ : sanitizeRecord(entry, depth + 1, ancestors);
267
+ }
268
+ ancestors.delete(value);
269
+ return result;
270
+ }
271
+
272
+ export function sanitizeBrowserRecord(value) {
273
+ return sanitizeRecord(value, 0, new WeakSet());
274
+ }
275
+
276
+ export async function digestBrowserIdentity(value) {
277
+ const encoded = new TextEncoder().encode(JSON.stringify(value));
278
+ const digest = await crypto.subtle.digest("SHA-256", encoded);
279
+ return Array.from(new Uint8Array(digest), (byte) =>
280
+ byte.toString(16).padStart(2, "0"),
281
+ ).join("");
282
+ }
283
+
284
+ export { sanitizeBrowserUrl };
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Completion endpoints use HTTP 200 for a semantic rejection such as a late
3
+ * worker finishing a run the server already timed out. Treat that response as
4
+ * unconfirmed; transport success alone must never clear local run health.
5
+ */
6
+ export function assertCompletionAccepted(response) {
7
+ if (!response || typeof response !== "object" || response.success !== false) {
8
+ return response;
9
+ }
10
+ const detail = response.reason ?? response.error ?? "rejected";
11
+ throw new Error(`Run completion rejected: ${String(detail)}`);
12
+ }
@@ -0,0 +1,144 @@
1
+ // Build-time-ish config for the extension. Edited at packaging time per
2
+ // channel (dev / preview / production). Service worker imports this; do not
3
+ // fetch remote config — MV3 forbids remote code, and a runtime fetch is
4
+ // indistinguishable from one to a reviewer.
5
+ //
6
+ // The gateway URL is configurable at first run — Lobu users self-host, so the
7
+ // extension can't ship with a fixed origin. DEFAULT_GATEWAY_URL is only the
8
+ // pre-fill/fallback: native auto-pair discovers the real URL from the Mac app
9
+ // when it's present (local or cloud), and self-hosters type their own. So the
10
+ // fallback is the hosted Lobu Cloud gateway, not a loopback URL nothing serves.
11
+ // The value the user confirms is persisted under STORAGE_KEY_GATEWAY_URL.
12
+ export const DEFAULT_GATEWAY_URL = "https://app.lobu.ai";
13
+
14
+ export const STORAGE_KEY_GATEWAY_URL = "owletto.gatewayUrl";
15
+
16
+ function isLoopbackHost(hostname) {
17
+ return (
18
+ hostname === "localhost" ||
19
+ hostname === "127.0.0.1" ||
20
+ hostname === "::1" ||
21
+ hostname === "[::1]"
22
+ );
23
+ }
24
+
25
+ // Loopback hosts can legitimately use http (local dev). For anything else,
26
+ // force https: the cloud and self-hosted gateways redirect http→https, and
27
+ // the redirect kills CORS — a stored http:// URL means the extension can
28
+ // never successfully fetch from the gateway, and the granted host
29
+ // permission (for the http origin) doesn't cover the redirected https
30
+ // origin. Normalizing here makes save + read both produce the form that
31
+ // will actually work, regardless of what the user typed.
32
+ export function normalizeGatewayBase(raw) {
33
+ if (typeof raw !== "string") return null;
34
+ let url;
35
+ try {
36
+ url = new URL(raw);
37
+ } catch {
38
+ return null;
39
+ }
40
+ if (!/^https?:$/.test(url.protocol)) return null;
41
+ if (url.protocol === "http:" && !isLoopbackHost(url.hostname)) {
42
+ url.protocol = "https:";
43
+ }
44
+ return `${url.protocol}//${url.host}`;
45
+ }
46
+
47
+ // Callers also catch HTTP, parsing, and local storage failures. Confirm that
48
+ // CORS itself fails before offering a site grant to bypass it.
49
+ export async function serverBlocksExtension(
50
+ base,
51
+ { chromeApi = chrome, fetchFn = fetch } = {},
52
+ ) {
53
+ if (await chromeApi.permissions.contains({ origins: [`${base}/*`] })) {
54
+ return false;
55
+ }
56
+ try {
57
+ await fetchFn(`${base}/`, {
58
+ mode: "cors",
59
+ signal: AbortSignal.timeout(5000),
60
+ });
61
+ return false;
62
+ } catch {
63
+ // Distinguish a reachable server that refuses CORS from a network outage.
64
+ }
65
+ try {
66
+ await fetchFn(`${base}/`, {
67
+ mode: "no-cors",
68
+ signal: AbortSignal.timeout(5000),
69
+ });
70
+ return true;
71
+ } catch {
72
+ return false;
73
+ }
74
+ }
75
+
76
+ export async function getGatewayUrl() {
77
+ const stored = await chrome.storage.local.get(STORAGE_KEY_GATEWAY_URL);
78
+ const raw = stored[STORAGE_KEY_GATEWAY_URL];
79
+ if (!raw) return null;
80
+ // Existing installs that paired with an http:// URL still have it in
81
+ // storage. Normalize on read so the runtime fetch uses https. The next
82
+ // pair-save overwrites the stored value with the canonical form.
83
+ return normalizeGatewayBase(raw) ?? raw;
84
+ }
85
+
86
+ // The sidepanel iframes the WHOLE app at the gateway's root — the same UI you
87
+ // get opening the gateway URL in a regular tab. It mounts via the gateway's
88
+ // /api/extension-bootstrap page (see mountEmbeddedApp in sidepanel.js), which
89
+ // exchanges the token for a Better Auth session token and stashes it for the
90
+ // SPA to send as Authorization: Bearer. Auth note: as a cross-site iframe (its
91
+ // top-level is chrome-extension://) it can't rely on a session cookie, and it
92
+ // can't see the extension's stored PAT or the user's main-tab session — so the
93
+ // in-iframe bootstrap is the only way to sign it in.
94
+
95
+ export const DEFAULT_CAPABILITIES = [
96
+ "browser.tabs",
97
+ "browser.scripting",
98
+ "browser.debugger",
99
+ // notifications is a regular (non-optional) manifest permission, so it's
100
+ // always granted — advertise it unconditionally.
101
+ "browser.notifications",
102
+ ];
103
+
104
+ // Chrome optional permissions → Lobu capability strings. Granted via
105
+ // chrome.permissions.request() from the sidepanel (user gesture required).
106
+ export const OPTIONAL_CAPABILITIES = {
107
+ history: "browser.history",
108
+ bookmarks: "browser.bookmarks",
109
+ downloads: "browser.downloads",
110
+ };
111
+
112
+ // Action-level grants inside an already-paired chrome connector. These do
113
+ // NOT map to Chrome optional permissions (tabs is baseline) and are NOT
114
+ // platform capabilities advertised on poll / matched via required_capability.
115
+ // They live only in extension storage and are enforced by the tool that
116
+ // needs them (e.g. close_user_tabs).
117
+ export const TABS_MANAGE_SCOPE = "tabs.manage";
118
+ export const ACTION_GRANTS_KEY = "owletto.action_grants";
119
+
120
+ /**
121
+ * @param {typeof chrome} chromeApi
122
+ * @param {string} scope
123
+ */
124
+ export async function isActionGrantEnabled(chromeApi, scope) {
125
+ const stored = await chromeApi.storage.local.get(ACTION_GRANTS_KEY);
126
+ const map = stored[ACTION_GRANTS_KEY];
127
+ return !!(map && typeof map === "object" && map[scope] === true);
128
+ }
129
+
130
+ /**
131
+ * @param {typeof chrome} chromeApi
132
+ * @param {string} scope
133
+ * @param {boolean} granted
134
+ */
135
+ export async function setActionGrantEnabled(chromeApi, scope, granted) {
136
+ const stored = await chromeApi.storage.local.get(ACTION_GRANTS_KEY);
137
+ const map =
138
+ stored[ACTION_GRANTS_KEY] && typeof stored[ACTION_GRANTS_KEY] === "object"
139
+ ? { ...stored[ACTION_GRANTS_KEY] }
140
+ : {};
141
+ if (granted) map[scope] = true;
142
+ else delete map[scope];
143
+ await chromeApi.storage.local.set({ [ACTION_GRANTS_KEY]: map });
144
+ }