@lobu/runtime-device 24.1.1 → 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.
- package/dist/component.json +1 -1
- package/dist/dependencies.bun.lock +26 -28
- package/npm-shrinkwrap.json +155 -172
- package/package.json +1 -1
- package/vendor/cli/dist/bundled-skills/lobu/SKILL.md +14 -5
- package/vendor/cli/dist/chrome-extension/accessibility-tree.js +834 -0
- package/vendor/cli/dist/chrome-extension/ambient-context.js +53 -0
- package/vendor/cli/dist/chrome-extension/auth-refresh.js +167 -0
- package/vendor/cli/dist/chrome-extension/automation-run.js +13 -0
- package/vendor/cli/dist/chrome-extension/background.js +1155 -0
- package/vendor/cli/dist/chrome-extension/bridge.js +140 -0
- package/vendor/cli/dist/chrome-extension/browser-origin-policy.js +62 -0
- package/vendor/cli/dist/chrome-extension/browser-recovery.js +260 -0
- package/vendor/cli/dist/chrome-extension/browser-url-sanitizer.js +284 -0
- package/vendor/cli/dist/chrome-extension/completion-response.js +12 -0
- package/vendor/cli/dist/chrome-extension/config.js +144 -0
- package/vendor/cli/dist/chrome-extension/connector-manifests/chrome.json +1516 -0
- package/vendor/cli/dist/chrome-extension/connector-manifests/chrome_bookmarks.json +84 -0
- package/vendor/cli/dist/chrome-extension/connector-manifests/chrome_downloads.json +86 -0
- package/vendor/cli/dist/chrome-extension/connector-manifests/chrome_history.json +78 -0
- package/vendor/cli/dist/chrome-extension/connector-manifests.js +1767 -0
- package/vendor/cli/dist/chrome-extension/console-capture.js +627 -0
- package/vendor/cli/dist/chrome-extension/control-activity.js +70 -0
- package/vendor/cli/dist/chrome-extension/debugger-lease.js +439 -0
- package/vendor/cli/dist/chrome-extension/feed-listener.js +488 -0
- package/vendor/cli/dist/chrome-extension/feed-transaction.js +48 -0
- package/vendor/cli/dist/chrome-extension/feeds.js +632 -0
- package/vendor/cli/dist/chrome-extension/focus-tab.js +25 -0
- package/vendor/cli/dist/chrome-extension/fonts/dm-mono-latin-500-normal.woff2 +0 -0
- package/vendor/cli/dist/chrome-extension/fonts/dm-sans-latin-400-normal.woff2 +0 -0
- package/vendor/cli/dist/chrome-extension/fonts/dm-sans-latin-600-normal.woff2 +0 -0
- package/vendor/cli/dist/chrome-extension/heartbeat.js +140 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-128-rec.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-128.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-16-rec.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-16.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-32-rec.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-32.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-48-rec.png +0 -0
- package/vendor/cli/dist/chrome-extension/icons/icon-48.png +0 -0
- package/vendor/cli/dist/chrome-extension/lens-page.js +135 -0
- package/vendor/cli/dist/chrome-extension/lens-target.js +20 -0
- package/vendor/cli/dist/chrome-extension/manifest.json +76 -0
- package/vendor/cli/dist/chrome-extension/network-intercept.js +657 -0
- package/vendor/cli/dist/chrome-extension/page-activation.js +120 -0
- package/vendor/cli/dist/chrome-extension/page-dialogs.js +125 -0
- package/vendor/cli/dist/chrome-extension/page-url.js +11 -0
- package/vendor/cli/dist/chrome-extension/panel-session.js +184 -0
- package/vendor/cli/dist/chrome-extension/poll-auth.js +85 -0
- package/vendor/cli/dist/chrome-extension/poll-backoff.js +22 -0
- package/vendor/cli/dist/chrome-extension/run-fence.js +117 -0
- package/vendor/cli/dist/chrome-extension/setup-status.js +71 -0
- package/vendor/cli/dist/chrome-extension/side-panel-action-click.js +65 -0
- package/vendor/cli/dist/chrome-extension/sidepanel-context.js +50 -0
- package/vendor/cli/dist/chrome-extension/sidepanel.html +680 -0
- package/vendor/cli/dist/chrome-extension/sidepanel.js +1643 -0
- package/vendor/cli/dist/chrome-extension/tab-labels.js +233 -0
- package/vendor/cli/dist/chrome-extension/tools.js +3354 -0
- package/vendor/cli/dist/chrome-extension/watch-observer.js +354 -0
- package/vendor/cli/dist/chrome-extension/watch-redact.js +96 -0
- package/vendor/cli/dist/chrome-extension/watch.js +348 -0
- package/vendor/cli/dist/commands/_lib/apply/desired-state.d.ts +6 -4
- package/vendor/cli/dist/commands/_lib/apply/desired-state.js +5 -3
- package/vendor/cli/dist/commands/_lib/apply/diff.js +4 -3
- package/vendor/cli/dist/commands/_lib/chrome-for-testing.d.ts +13 -0
- package/vendor/cli/dist/commands/_lib/chrome-for-testing.js +226 -0
- package/vendor/cli/dist/commands/_lib/device-credential.d.ts +34 -0
- package/vendor/cli/dist/commands/_lib/device-credential.js +157 -0
- package/vendor/cli/dist/commands/_lib/device-wizard.d.ts +17 -0
- package/vendor/cli/dist/commands/_lib/device-wizard.js +11 -2
- package/vendor/cli/dist/commands/_lib/native-messaging.d.ts +7 -0
- package/vendor/cli/dist/commands/_lib/native-messaging.js +40 -0
- package/vendor/cli/dist/commands/browser.d.ts +23 -0
- package/vendor/cli/dist/commands/browser.js +492 -0
- package/vendor/cli/dist/commands/call.d.ts +12 -0
- package/vendor/cli/dist/commands/call.js +48 -26
- package/vendor/cli/dist/commands/context.d.ts +3 -1
- package/vendor/cli/dist/commands/context.js +13 -2
- package/vendor/cli/dist/commands/daemon.js +2 -152
- package/vendor/cli/dist/commands/memory/_lib/errors.d.ts +4 -1
- package/vendor/cli/dist/commands/memory/_lib/errors.js +9 -1
- package/vendor/cli/dist/commands/memory/_lib/mcp.d.ts +0 -9
- package/vendor/cli/dist/commands/memory/_lib/mcp.js +1 -23
- package/vendor/cli/dist/commands/memory/_lib/memory-auth.d.ts +20 -4
- package/vendor/cli/dist/commands/memory/_lib/memory-auth.js +21 -17
- package/vendor/cli/dist/commands/memory/_lib/seed-cmd.js +6 -17
- package/vendor/cli/dist/commands/memory/run.js +4 -25
- package/vendor/cli/dist/connectors/google_gmail.ts +70 -41
- package/vendor/cli/dist/connectors/google_gmail_references.ts +406 -0
- package/vendor/cli/dist/connectors/linkedin-inbox-adapter.js +107 -36
- package/vendor/cli/dist/connectors/linkedin-inbox.ts +13 -0
- package/vendor/cli/dist/connectors/linkedin.ts +1 -1
- package/vendor/cli/dist/connectors/postgres.ts +5 -3
- package/vendor/cli/dist/connectors/reddit.ts +171 -5
- package/vendor/cli/dist/connectors/whatsapp-web-adapter.js +147 -61
- package/vendor/cli/dist/connectors/whatsapp-web-helpers.ts +6 -2
- package/vendor/cli/dist/connectors/whatsapp_web.ts +48 -17
- package/vendor/cli/dist/connectors/x-dm-adapter.js +252 -35
- package/vendor/cli/dist/connectors/x.ts +189 -13
- package/vendor/cli/dist/index.js +46 -6
- package/vendor/cli/dist/internal/device-state.d.ts +2 -0
- package/vendor/cli/dist/internal/device-state.js +4 -0
- package/vendor/cli/dist/runtime-components.json +4 -4
- package/vendor/cli/dist/templates/AGENTS.md.tmpl +3 -1
- package/vendor/cli/dist/templates/TESTING.md.tmpl +8 -8
- package/vendor/cli/package.json +1 -1
- package/vendor/connector-sdk/dist/browser-requirement.js +1 -1
- package/vendor/connector-sdk/dist/connector-types.d.ts +5 -1
- package/vendor/connector-sdk/package.json +1 -1
- package/vendor/connector-worker/dist/agent-turn/gateway-tools.d.ts +9 -0
- package/vendor/connector-worker/dist/agent-turn/gateway-tools.js +23 -2
- package/vendor/connector-worker/dist/agent-turn/guest-entry.js +14 -6
- package/vendor/connector-worker/dist/agent-turn/guest.bundle.js +62 -25
- package/vendor/connector-worker/dist/agent-turn/media-tools.d.ts +1 -0
- package/vendor/connector-worker/dist/agent-turn/media-tools.js +5 -2
- package/vendor/connector-worker/dist/bin.js +2 -0
- package/vendor/connector-worker/dist/daemon/agent-turn.js +52 -17
- package/vendor/connector-worker/dist/daemon/automation.js +2 -12
- package/vendor/connector-worker/dist/daemon/client.d.ts +8 -2
- package/vendor/connector-worker/dist/daemon/client.js +8 -1
- package/vendor/connector-worker/dist/daemon/interactive-session.js +29 -6
- package/vendor/connector-worker/dist/daemon/poll-loop.js +23 -1
- package/vendor/connector-worker/dist/daemon/terminal-delivery.d.ts +5 -10
- package/vendor/connector-worker/dist/daemon/terminal-delivery.js +55 -23
- package/vendor/connector-worker/dist/daemon/terminal-failure.js +2 -2
- package/vendor/connector-worker/dist/executor/isolate.js +3 -0
- package/vendor/connector-worker/package.json +1 -1
- package/vendor/core/dist/agent-tooling.d.ts +8 -0
- package/vendor/core/dist/agent-tooling.js +9 -1
- package/vendor/core/dist/capabilities.d.ts +1 -1
- package/vendor/core/dist/capabilities.js +5 -0
- package/vendor/core/dist/contracts/entity-reference.d.ts +3 -0
- package/vendor/core/dist/contracts/entity-reference.js +31 -0
- package/vendor/core/dist/contracts/tools/manage-automations.d.ts +3 -0
- package/vendor/core/dist/contracts/tools/manage-automations.js +3 -0
- package/vendor/core/dist/contracts/tools/manage-connections.js +1 -1
- package/vendor/core/dist/contracts/tools/manage-entity-schema.js +1 -1
- package/vendor/core/dist/contracts/tools/manage-entity.d.ts +113 -34
- package/vendor/core/dist/contracts/tools/manage-entity.js +41 -14
- package/vendor/core/dist/contracts/tools/manage-operations.d.ts +13 -4
- package/vendor/core/dist/contracts/tools/manage-operations.js +19 -7
- package/vendor/core/dist/contracts/tools/read-knowledge.d.ts +6 -1
- package/vendor/core/dist/contracts/tools/read-knowledge.js +20 -1
- package/vendor/core/dist/contracts/tools/view-attach.d.ts +1 -1
- package/vendor/core/dist/contracts/tools/view-runtime.d.ts +2 -0
- package/vendor/core/dist/contracts/tools/view-runtime.js +3 -1
- package/vendor/core/dist/contracts/worker/device-automation.d.ts +4 -9
- package/vendor/core/dist/contracts/worker/device-automation.js +10 -15
- package/vendor/core/dist/contracts/worker/protocol.d.ts +20 -0
- package/vendor/core/dist/contracts/worker/protocol.js +20 -0
- package/vendor/core/dist/reserved.d.ts +6 -3
- package/vendor/core/dist/reserved.js +6 -3
- package/vendor/core/dist/worker/auth.d.ts +3 -2
- package/vendor/core/package.json +6 -1
- package/vendor/postgres/cf/src/query.js +3 -1
- package/vendor/postgres/cjs/src/query.js +3 -1
- package/vendor/postgres/src/query.js +3 -1
- /package/vendor/postgres/{.bun-tag-2f292c6554a8475e → .bun-tag-22d644c2873790db} +0 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
// Privacy boundary for the ambient presence layer. The extension publishes
|
|
2
|
+
// only the active browser origin and a bounded title; full paths, query
|
|
3
|
+
// strings, fragments, page content, and form values never cross this bridge.
|
|
4
|
+
|
|
5
|
+
export function ambientContextForTab(tab, windowFocused = true) {
|
|
6
|
+
if (!windowFocused || !tab?.active) {
|
|
7
|
+
return { op: "active_context", active: false };
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (tab.incognito) {
|
|
11
|
+
return {
|
|
12
|
+
op: "active_context",
|
|
13
|
+
active: true,
|
|
14
|
+
incognito: true,
|
|
15
|
+
application_name: "Browser",
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
let origin = null;
|
|
20
|
+
try {
|
|
21
|
+
const parsed = new URL(tab.url ?? "");
|
|
22
|
+
if (parsed.protocol === "http:" || parsed.protocol === "https:") {
|
|
23
|
+
origin = parsed.origin;
|
|
24
|
+
}
|
|
25
|
+
} catch {
|
|
26
|
+
// Internal/new-tab URLs intentionally produce app-only context.
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const rawTitle = typeof tab.title === "string" ? tab.title.trim() : "";
|
|
30
|
+
return {
|
|
31
|
+
op: "active_context",
|
|
32
|
+
active: true,
|
|
33
|
+
incognito: false,
|
|
34
|
+
application_name: "Browser",
|
|
35
|
+
url: origin,
|
|
36
|
+
title: rawTitle ? rawTitle.slice(0, 180) : null,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function sendNativeAmbientContext(runtime, hostName, message) {
|
|
41
|
+
return new Promise((resolve) => {
|
|
42
|
+
try {
|
|
43
|
+
runtime.sendNativeMessage(hostName, message, () => {
|
|
44
|
+
// Reading lastError suppresses Chrome's unchecked-error warning when
|
|
45
|
+
// the Mac host is not installed. Ambient context is best-effort.
|
|
46
|
+
void runtime.lastError;
|
|
47
|
+
resolve();
|
|
48
|
+
});
|
|
49
|
+
} catch {
|
|
50
|
+
resolve();
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
@@ -0,0 +1,167 @@
|
|
|
1
|
+
import { grantedScopeUpdate } from "./panel-session.js";
|
|
2
|
+
|
|
3
|
+
// Access-token refresh for the MV3 service worker.
|
|
4
|
+
//
|
|
5
|
+
// The extension's access token is capped server-side (24h). When a poll 401s,
|
|
6
|
+
// the worker exchanges its refresh token for a fresh access token rather than
|
|
7
|
+
// forcing the user to re-pair by hand. The subtlety that matters — and that a
|
|
8
|
+
// momentary gateway outage on 2026-06-16 exposed in production — is *why* a
|
|
9
|
+
// refresh failed:
|
|
10
|
+
//
|
|
11
|
+
// - A definitive rejection (the refresh token was revoked or expired, i.e.
|
|
12
|
+
// the token endpoint answered 400/invalid_grant, or there is no refresh
|
|
13
|
+
// token at all) genuinely requires a re-pair. The caller tears the pairing
|
|
14
|
+
// down.
|
|
15
|
+
// - A TRANSIENT failure (gateway 5xx/503, 429 rate limit, a network blip
|
|
16
|
+
// before the request reached the server, or unreachable discovery) means
|
|
17
|
+
// the refresh never happened, so the credentials are still good. Tearing
|
|
18
|
+
// the pairing down here is the bug: the device then stops polling, goes
|
|
19
|
+
// offline after the server's 20-minute window, and never self-heals because
|
|
20
|
+
// polling stops on the now-missing credentials on every wake —
|
|
21
|
+
// only a manual re-pair recovers it.
|
|
22
|
+
//
|
|
23
|
+
// So this module classifies the outcome and the caller only wipes credentials
|
|
24
|
+
// on REFRESH_REJECTED. On REFRESH_TRANSIENT the worker keeps its credentials
|
|
25
|
+
// and retries; if it can't re-establish auth for a sustained period the caller
|
|
26
|
+
// escalates to a teardown so the re-pair CTA still surfaces (see
|
|
27
|
+
// reconnectEscalation).
|
|
28
|
+
//
|
|
29
|
+
// NOTE: the server rotates (and atomically revokes) the refresh token on every
|
|
30
|
+
// successful refresh. So a failure AFTER the server commits — e.g. the response
|
|
31
|
+
// is lost in transit, or the SW is evicted before the new token is persisted —
|
|
32
|
+
// leaves us holding a now-revoked token. We can't distinguish that from a
|
|
33
|
+
// pre-commit blip, so we classify it TRANSIENT and retry; the retry then gets
|
|
34
|
+
// 400/invalid_grant → REFRESH_REJECTED → teardown, which is the correct
|
|
35
|
+
// outcome (that pairing really is dead and needs a re-pair).
|
|
36
|
+
|
|
37
|
+
export const REFRESH_REFRESHED = "refreshed"; // new access token obtained
|
|
38
|
+
export const REFRESH_REJECTED = "rejected"; // re-pair required (revoked/expired/missing)
|
|
39
|
+
export const REFRESH_TRANSIENT = "transient"; // refresh didn't happen; retry later
|
|
40
|
+
|
|
41
|
+
// Exchange the refresh token for a fresh access token via the gateway's OAuth
|
|
42
|
+
// token endpoint (auth/oauth/routes.ts honours grant_type=refresh_token).
|
|
43
|
+
//
|
|
44
|
+
// `creds` = { refreshToken, clientId, clientSecret? } read from storage by the
|
|
45
|
+
// caller. Returns { outcome, accessToken?, refreshToken?, scope? }:
|
|
46
|
+
// - REFRESH_REFRESHED → accessToken set; refreshToken set only if the server
|
|
47
|
+
// rotated it (undefined means keep the existing one).
|
|
48
|
+
// - REFRESH_REJECTED / REFRESH_TRANSIENT → no tokens.
|
|
49
|
+
export async function refreshAccessToken(gatewayUrl, creds, { fetchImpl = fetch } = {}) {
|
|
50
|
+
const { refreshToken, clientId, clientSecret } = creds ?? {};
|
|
51
|
+
// No refresh credentials (native auto-pair / local-init store none) — only a
|
|
52
|
+
// re-pair can recover. Definitive.
|
|
53
|
+
if (!refreshToken || !clientId) return { outcome: REFRESH_REJECTED };
|
|
54
|
+
|
|
55
|
+
// One deadline covers discovery, exchange, and both response bodies.
|
|
56
|
+
const signal = AbortSignal.timeout(20_000);
|
|
57
|
+
let discovery;
|
|
58
|
+
try {
|
|
59
|
+
const res = await fetchImpl(`${gatewayUrl}/.well-known/oauth-authorization-server`, {
|
|
60
|
+
signal,
|
|
61
|
+
headers: { accept: "application/json" },
|
|
62
|
+
});
|
|
63
|
+
// Discovery unreachable/erroring is an infra problem, not a bad grant.
|
|
64
|
+
if (!res.ok) return { outcome: REFRESH_TRANSIENT };
|
|
65
|
+
discovery = await res.json();
|
|
66
|
+
} catch {
|
|
67
|
+
return { outcome: REFRESH_TRANSIENT };
|
|
68
|
+
}
|
|
69
|
+
if (!discovery?.token_endpoint) return { outcome: REFRESH_TRANSIENT };
|
|
70
|
+
|
|
71
|
+
let res;
|
|
72
|
+
try {
|
|
73
|
+
res = await fetchImpl(discovery.token_endpoint, {
|
|
74
|
+
signal,
|
|
75
|
+
method: "POST",
|
|
76
|
+
headers: { "content-type": "application/json", accept: "application/json" },
|
|
77
|
+
body: JSON.stringify({
|
|
78
|
+
grant_type: "refresh_token",
|
|
79
|
+
refresh_token: refreshToken,
|
|
80
|
+
client_id: clientId,
|
|
81
|
+
...(clientSecret ? { client_secret: clientSecret } : {}),
|
|
82
|
+
}),
|
|
83
|
+
});
|
|
84
|
+
} catch {
|
|
85
|
+
// Network failure reaching the endpoint — retry.
|
|
86
|
+
return { outcome: REFRESH_TRANSIENT };
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// The token endpoint answers 400 ONLY for a definitively bad grant
|
|
90
|
+
// (invalid_grant — refresh token revoked/expired; routes.ts:1010-1014).
|
|
91
|
+
// 429 (rate limit) and 503 ("temporarily unavailable") and any 5xx are
|
|
92
|
+
// transient and must not tear down a valid pairing.
|
|
93
|
+
if (res.status === 400) return { outcome: REFRESH_REJECTED };
|
|
94
|
+
if (!res.ok) return { outcome: REFRESH_TRANSIENT };
|
|
95
|
+
|
|
96
|
+
let body;
|
|
97
|
+
try {
|
|
98
|
+
body = await res.json();
|
|
99
|
+
} catch {
|
|
100
|
+
return { outcome: REFRESH_TRANSIENT };
|
|
101
|
+
}
|
|
102
|
+
// A 200 with no access_token is a malformed/partial response — treat it as
|
|
103
|
+
// transient rather than burning the pairing.
|
|
104
|
+
if (!body?.access_token) return { outcome: REFRESH_TRANSIENT };
|
|
105
|
+
|
|
106
|
+
return {
|
|
107
|
+
outcome: REFRESH_REFRESHED,
|
|
108
|
+
accessToken: body.access_token,
|
|
109
|
+
refreshToken: body.refresh_token, // undefined when the server didn't rotate
|
|
110
|
+
scope: body.scope, // the grant's scope; refresh never widens it
|
|
111
|
+
};
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// Refresh the pairing held in `storage` and store the result. The panel may
|
|
115
|
+
// replace the pairing while the refresh is in flight (a re-approval or
|
|
116
|
+
// re-pair, which revokes the old grant). Whatever came back then belongs to the
|
|
117
|
+
// old pairing: it must not overwrite the new tokens, and a now-revoked grant
|
|
118
|
+
// must not tear the new pairing down. That case reports REFRESHED so the
|
|
119
|
+
// caller re-polls with the new credentials.
|
|
120
|
+
export async function refreshStoredPairing(storage, keys, gatewayUrl, options) {
|
|
121
|
+
const stored = await storage.get([keys.refreshToken, keys.clientId, keys.clientSecret]);
|
|
122
|
+
const { outcome, accessToken, refreshToken, scope } = await refreshAccessToken(
|
|
123
|
+
gatewayUrl,
|
|
124
|
+
{
|
|
125
|
+
refreshToken: stored[keys.refreshToken],
|
|
126
|
+
clientId: stored[keys.clientId],
|
|
127
|
+
clientSecret: stored[keys.clientSecret],
|
|
128
|
+
},
|
|
129
|
+
options,
|
|
130
|
+
);
|
|
131
|
+
const now = await storage.get([keys.clientId]);
|
|
132
|
+
if (now[keys.clientId] !== stored[keys.clientId]) return REFRESH_REFRESHED;
|
|
133
|
+
if (outcome === REFRESH_REFRESHED) {
|
|
134
|
+
await storage.set({
|
|
135
|
+
[keys.accessToken]: accessToken,
|
|
136
|
+
// The server may rotate the refresh token; keep the existing one if it
|
|
137
|
+
// didn't return a new one.
|
|
138
|
+
...(refreshToken ? { [keys.refreshToken]: refreshToken } : {}),
|
|
139
|
+
// Lets the panel spot a pairing that needs a fresh approval.
|
|
140
|
+
...grantedScopeUpdate({ scope }),
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
return outcome;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
// How long the worker keeps quietly retrying ("reconnecting") before it gives
|
|
147
|
+
// up and tears the pairing down so the panel surfaces the re-pair CTA. Long
|
|
148
|
+
// enough to ride out gateway deploys / OAuth outages without bothering the user,
|
|
149
|
+
// short enough that a genuinely dead pairing (refresh keeps succeeding but the
|
|
150
|
+
// fresh token is rejected, or the OAuth route is persistently broken) doesn't
|
|
151
|
+
// leave them stuck "reconnecting" forever with no recovery action.
|
|
152
|
+
export const RECONNECT_ESCALATE_AFTER_MS = 5 * 60_000;
|
|
153
|
+
export const RECONNECT_WAIT = "wait"; // keep retrying; self-heals if the gateway recovers
|
|
154
|
+
export const RECONNECT_ESCALATE = "escalate"; // sustained failure → teardown + re-pair CTA
|
|
155
|
+
|
|
156
|
+
// Decide whether a 401 we couldn't resolve right now (transient refresh failure
|
|
157
|
+
// or a freshly-issued token still being rejected) should keep waiting or
|
|
158
|
+
// escalate. `since` is when the current reconnecting streak started (null if
|
|
159
|
+
// this is the first failure); `now` is the current time. Returns { action,
|
|
160
|
+
// since } where `since` is the streak-start timestamp the caller persists (and
|
|
161
|
+
// clears on the next successful poll). Pure so the threshold is unit-tested.
|
|
162
|
+
export function reconnectEscalation(since, now, afterMs = RECONNECT_ESCALATE_AFTER_MS) {
|
|
163
|
+
const start = since ?? now;
|
|
164
|
+
return now - start >= afterMs
|
|
165
|
+
? { action: RECONNECT_ESCALATE, since: start }
|
|
166
|
+
: { action: RECONNECT_WAIT, since: start };
|
|
167
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Device Automation claim detection for the Chrome worker poll lane.
|
|
3
|
+
*
|
|
4
|
+
* Server enqueues run_type="automation". Chrome is a
|
|
5
|
+
* connector/action worker only — Mac Owletto executes Automations via a local
|
|
6
|
+
* CLI. Callers must fail closed through /complete-automation, not /complete.
|
|
7
|
+
*
|
|
8
|
+
* @param {{ run_type?: string | null } | null | undefined} run
|
|
9
|
+
* @returns {boolean}
|
|
10
|
+
*/
|
|
11
|
+
export function isDeviceAutomationRun(run) {
|
|
12
|
+
return run?.run_type === "automation";
|
|
13
|
+
}
|