@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,233 @@
|
|
|
1
|
+
// Agent tab labels: who opened a tab and who last used it.
|
|
2
|
+
//
|
|
3
|
+
// A label is a description, not a lock. Every agent may see and drive every
|
|
4
|
+
// labelled tab; a tab WITHOUT a label belongs to the user (or predates a
|
|
5
|
+
// browser restart) and needs a grant before an agent may mutate it.
|
|
6
|
+
//
|
|
7
|
+
// Labels live in chrome.storage.local, keyed by Chrome's target UUID, not its
|
|
8
|
+
// reusable numeric tab id. The target survives extension reloads, navigation,
|
|
9
|
+
// and discard, but a restored browser session creates new targets. Reads join
|
|
10
|
+
// against live targets so stale disk records cannot authorize a different tab,
|
|
11
|
+
// even if cleanup fails. No lifecycle timing or startup event is trusted.
|
|
12
|
+
// Nothing here closes tabs or reads group membership.
|
|
13
|
+
|
|
14
|
+
import { controlSource } from "./control-activity.js";
|
|
15
|
+
|
|
16
|
+
export const TAB_LABELS_KEY = "owletto.tab_labels";
|
|
17
|
+
|
|
18
|
+
// Storage left behind by the retired group-ownership model. Removed once on
|
|
19
|
+
// install/update; nothing reads them.
|
|
20
|
+
const RETIRED_TAB_STORAGE_KEYS = [
|
|
21
|
+
"owletto.tabgroups",
|
|
22
|
+
"owletto.tabgroups.v1",
|
|
23
|
+
"owletto.tabgroups.v2",
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
let labelMutation = Promise.resolve();
|
|
27
|
+
const LOCKS = new Map();
|
|
28
|
+
|
|
29
|
+
/** Run `fn` after every earlier call for the same key has settled. */
|
|
30
|
+
export function withKeyLock(key, fn) {
|
|
31
|
+
const previous = LOCKS.get(key) ?? Promise.resolve();
|
|
32
|
+
const next = previous.then(fn, fn);
|
|
33
|
+
const tail = next.catch(() => {});
|
|
34
|
+
LOCKS.set(key, tail);
|
|
35
|
+
void tail.then(() => {
|
|
36
|
+
if (LOCKS.get(key) === tail) LOCKS.delete(key);
|
|
37
|
+
});
|
|
38
|
+
return next;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
async function labelSnapshot() {
|
|
42
|
+
const [stored, live] = await Promise.all([
|
|
43
|
+
chrome.storage.local.get(TAB_LABELS_KEY),
|
|
44
|
+
chrome.debugger.getTargets(),
|
|
45
|
+
]);
|
|
46
|
+
const persisted = stored?.[TAB_LABELS_KEY] ?? {};
|
|
47
|
+
const targets = new Map(live
|
|
48
|
+
.filter((target) => target.type === "page" && Number.isInteger(target.tabId))
|
|
49
|
+
.map((target) => [target.tabId, target.id]));
|
|
50
|
+
const labels = Object.fromEntries([...targets]
|
|
51
|
+
.filter(([, targetId]) => persisted[targetId])
|
|
52
|
+
.map(([tabId, targetId]) => [tabId, persisted[targetId]]));
|
|
53
|
+
return { labels, targets };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export async function readTabLabels() {
|
|
57
|
+
return (await labelSnapshot()).labels;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
// storage.local has no compare-and-swap, so serialize read-modify-write.
|
|
61
|
+
function mutateLabels(mutator) {
|
|
62
|
+
const next = labelMutation
|
|
63
|
+
.catch(() => {})
|
|
64
|
+
.then(async () => {
|
|
65
|
+
const { labels, targets } = await labelSnapshot();
|
|
66
|
+
mutator(labels, targets);
|
|
67
|
+
const persisted = Object.fromEntries([...targets]
|
|
68
|
+
.filter(([tabId]) => labels[tabId])
|
|
69
|
+
.map(([tabId, targetId]) => [targetId, labels[tabId]]));
|
|
70
|
+
await chrome.storage.local.set({ [TAB_LABELS_KEY]: persisted });
|
|
71
|
+
});
|
|
72
|
+
labelMutation = next.catch(() => {});
|
|
73
|
+
return next;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** The acting agent, from the trusted identifiers the gateway stamps on a run. */
|
|
77
|
+
export function actorFromRunCtx(runCtx) {
|
|
78
|
+
return {
|
|
79
|
+
agent: controlSource(runCtx?.sourceAttribution).actor,
|
|
80
|
+
session: runCtx?.browserFlowId ?? null,
|
|
81
|
+
run: runCtx?.holderRunId ?? runCtx?.runId ?? null,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
export async function labelTab(tabId, runCtx, { kind = "task", site = null } = {}) {
|
|
86
|
+
const by = actorFromRunCtx(runCtx);
|
|
87
|
+
const at = Date.now();
|
|
88
|
+
await mutateLabels((labels, targets) => {
|
|
89
|
+
if (!targets.has(tabId)) throw new Error(`No browser target for tab ${tabId}`);
|
|
90
|
+
labels[String(tabId)] = {
|
|
91
|
+
opened_by: by,
|
|
92
|
+
opened_at: at,
|
|
93
|
+
last_used_by: by,
|
|
94
|
+
last_used_at: at,
|
|
95
|
+
kind,
|
|
96
|
+
site,
|
|
97
|
+
};
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/** Record use by an agent. No-op for an unlabelled (user) tab. */
|
|
102
|
+
export async function touchTabLabel(tabId, runCtx) {
|
|
103
|
+
if (typeof tabId !== "number") return;
|
|
104
|
+
const by = actorFromRunCtx(runCtx);
|
|
105
|
+
await mutateLabels((labels) => {
|
|
106
|
+
const label = labels[String(tabId)];
|
|
107
|
+
if (!label) return;
|
|
108
|
+
Object.assign(label, { last_used_by: by, last_used_at: Date.now() });
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** Remember the site a task tab was last sent to, for navigate's reuse. */
|
|
113
|
+
export async function noteTaskSite(tabId, site) {
|
|
114
|
+
if (site == null) return;
|
|
115
|
+
await mutateLabels((labels) => {
|
|
116
|
+
const label = labels[String(tabId)];
|
|
117
|
+
if (label?.kind === "task") label.site = site;
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
export async function forgetTabLabel(tabId) {
|
|
122
|
+
await mutateLabels((labels) => {
|
|
123
|
+
delete labels[String(tabId)];
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/**
|
|
128
|
+
* Registrable site for a URL, or null when it has none (about:blank, chrome:).
|
|
129
|
+
* A configured allowedOrigins root wins, so `*.revolut.com` keys every Revolut
|
|
130
|
+
* host together. Otherwise approximate eTLD+1 without a suffix list: the last
|
|
131
|
+
* two labels, or three under a two-letter country code with a generic second
|
|
132
|
+
* level (example.co.uk).
|
|
133
|
+
*/
|
|
134
|
+
export function siteKeyFor(url, allowedOrigins = []) {
|
|
135
|
+
let parsed;
|
|
136
|
+
try {
|
|
137
|
+
parsed = new URL(url);
|
|
138
|
+
} catch {
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return null;
|
|
142
|
+
const host = parsed.hostname.toLowerCase().replace(/\.$/, "");
|
|
143
|
+
const roots = allowedOrigins
|
|
144
|
+
.map((pattern) => String(pattern).toLowerCase().replace(/^\*\./, ""))
|
|
145
|
+
.filter((root) => host === root || host.endsWith(`.${root}`))
|
|
146
|
+
.sort((a, b) => a.split(".").length - b.split(".").length);
|
|
147
|
+
if (roots.length > 0) return roots[0];
|
|
148
|
+
if (/^[\d.]+$/.test(host) || host.includes(":") || !host.includes(".")) return host;
|
|
149
|
+
const parts = host.split(".");
|
|
150
|
+
const generic = ["co", "com", "org", "net", "ac", "gov", "edu"];
|
|
151
|
+
const take =
|
|
152
|
+
parts.length >= 3 &&
|
|
153
|
+
parts.at(-1).length === 2 &&
|
|
154
|
+
generic.includes(parts.at(-2))
|
|
155
|
+
? 3
|
|
156
|
+
: 2;
|
|
157
|
+
return parts.slice(-take).join(".");
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
/** True when the tab's live http(s) URL is on `site` or one of its subdomains. */
|
|
161
|
+
export function tabIsOnSite(tab, site) {
|
|
162
|
+
const url = tab?.pendingUrl || tab?.url;
|
|
163
|
+
if (!url || !site) return false;
|
|
164
|
+
try {
|
|
165
|
+
const parsed = new URL(url);
|
|
166
|
+
if (parsed.protocol !== "http:" && parsed.protocol !== "https:") return false;
|
|
167
|
+
const host = parsed.hostname.toLowerCase().replace(/\.$/, "");
|
|
168
|
+
return host === site || host.endsWith(`.${site}`);
|
|
169
|
+
} catch {
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* A label that still describes the tab. A warm tab is labelled for one site;
|
|
176
|
+
* once the user takes it elsewhere it is their tab again, so the label no
|
|
177
|
+
* longer counts. A fresh warm tab sits on about:blank until its first load.
|
|
178
|
+
*/
|
|
179
|
+
export function effectiveLabel(label, tab) {
|
|
180
|
+
if (!label || !tab) return null;
|
|
181
|
+
const onBlank = (tab.pendingUrl || tab.url) === "about:blank";
|
|
182
|
+
if (label.kind === "warm" && !onBlank && !tabIsOnSite(tab, label.site))
|
|
183
|
+
return null;
|
|
184
|
+
return label;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
/** The tab's live agent label, or null for a user tab (or a gone one). */
|
|
188
|
+
export async function agentLabelFor(chromeApi, tabId) {
|
|
189
|
+
if (typeof tabId !== "number") return null;
|
|
190
|
+
const label = (await readTabLabels())[String(tabId)];
|
|
191
|
+
if (!label) return null;
|
|
192
|
+
const tab = await chromeApi.tabs.get(tabId).catch(() => null);
|
|
193
|
+
return effectiveLabel(label, tab);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* Put a tab in the group with exactly this title in its window, creating the
|
|
198
|
+
* group when there is none. Live Chrome state only — no stored group ids — so a
|
|
199
|
+
* restart or a user-renamed group can never leave a dangling record.
|
|
200
|
+
*/
|
|
201
|
+
export async function joinGroup(chromeApi, tabId, rawTitle) {
|
|
202
|
+
const title = String(rawTitle).trim();
|
|
203
|
+
if (!title) return null;
|
|
204
|
+
const tab = await chromeApi.tabs.get(tabId);
|
|
205
|
+
return withKeyLock(`group:${tab.windowId}:${title}`, async () => {
|
|
206
|
+
// tabGroups.query treats `title` as a pattern; compare exactly instead.
|
|
207
|
+
const existing = (
|
|
208
|
+
await chromeApi.tabGroups.query({ windowId: tab.windowId })
|
|
209
|
+
).find((group) => group.title === title);
|
|
210
|
+
if (existing) {
|
|
211
|
+
if (tab.groupId !== existing.id)
|
|
212
|
+
await chromeApi.tabs.group({ groupId: existing.id, tabIds: [tabId] });
|
|
213
|
+
return existing.id;
|
|
214
|
+
}
|
|
215
|
+
const groupId = await chromeApi.tabs.group({
|
|
216
|
+
tabIds: [tabId],
|
|
217
|
+
createProperties: { windowId: tab.windowId },
|
|
218
|
+
});
|
|
219
|
+
await chromeApi.tabGroups.update(groupId, { title });
|
|
220
|
+
return groupId;
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
export function installTabLabelListeners(chromeApi) {
|
|
225
|
+
chromeApi.tabs.onRemoved.addListener((tabId) => {
|
|
226
|
+
void forgetTabLabel(tabId).catch(() => {});
|
|
227
|
+
});
|
|
228
|
+
// Numeric id changes need no storage rewrite: reads resolve the target's
|
|
229
|
+
// current tabId. A new target never inherits another target's authority.
|
|
230
|
+
chromeApi.runtime.onInstalled.addListener(() => {
|
|
231
|
+
void chromeApi.storage.local.remove(RETIRED_TAB_STORAGE_KEYS).catch(() => {});
|
|
232
|
+
});
|
|
233
|
+
}
|