synabun 2.4.3 → 2.4.5
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/CHANGELOG.md +36 -0
- package/README.md +1 -1
- package/docs/browser-extension-bridge.md +66 -36
- package/docs/whatsapp.md +3 -3
- package/mcp-server/dist/http.d.ts.map +1 -1
- package/mcp-server/dist/http.js +8 -1
- package/mcp-server/dist/http.js.map +1 -1
- package/mcp-server/dist/services/identity.d.ts +2 -0
- package/mcp-server/dist/services/identity.d.ts.map +1 -1
- package/mcp-server/dist/services/identity.js +4 -0
- package/mcp-server/dist/services/identity.js.map +1 -1
- package/mcp-server/dist/services/memory-client.d.ts +5 -0
- package/mcp-server/dist/services/memory-client.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-client.js +21 -2
- package/mcp-server/dist/services/memory-client.js.map +1 -1
- package/mcp-server/dist/services/memory-writer.d.ts +3 -0
- package/mcp-server/dist/services/memory-writer.d.ts.map +1 -1
- package/mcp-server/dist/services/memory-writer.js +7 -1
- package/mcp-server/dist/services/memory-writer.js.map +1 -1
- package/mcp-server/dist/services/neural-interface.d.ts +12 -1
- package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
- package/mcp-server/dist/services/neural-interface.js +68 -17
- package/mcp-server/dist/services/neural-interface.js.map +1 -1
- package/mcp-server/dist/services/typesafe-config.d.ts +38 -2
- package/mcp-server/dist/services/typesafe-config.d.ts.map +1 -1
- package/mcp-server/dist/services/typesafe-config.js +260 -8
- package/mcp-server/dist/services/typesafe-config.js.map +1 -1
- package/mcp-server/dist/tools/agent-definition.d.ts +2 -2
- package/mcp-server/dist/tools/agents.d.ts +19 -4
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +85 -17
- package/mcp-server/dist/tools/agents.js.map +1 -1
- package/mcp-server/dist/tools/browser-observe.d.ts +11 -0
- package/mcp-server/dist/tools/browser-observe.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-observe.js +113 -27
- package/mcp-server/dist/tools/browser-observe.js.map +1 -1
- package/mcp-server/dist/tools/browser-readers.d.ts +6 -0
- package/mcp-server/dist/tools/browser-readers.d.ts.map +1 -0
- package/mcp-server/dist/tools/browser-readers.js +17 -0
- package/mcp-server/dist/tools/browser-readers.js.map +1 -0
- package/mcp-server/dist/tools/remember.d.ts.map +1 -1
- package/mcp-server/dist/tools/remember.js +6 -2
- package/mcp-server/dist/tools/remember.js.map +1 -1
- package/mcp-server/dist/tools/youtube/analytics.d.ts +4 -0
- package/mcp-server/dist/tools/youtube/analytics.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/analytics.js +25 -20
- package/mcp-server/dist/tools/youtube/analytics.js.map +1 -1
- package/mcp-server/dist/tools/youtube/helpers.d.ts +5 -1
- package/mcp-server/dist/tools/youtube/helpers.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/helpers.js +7 -3
- package/mcp-server/dist/tools/youtube/helpers.js.map +1 -1
- package/mcp-server/dist/tools/youtube/navigate.d.ts +2 -0
- package/mcp-server/dist/tools/youtube/navigate.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/navigate.js +5 -3
- package/mcp-server/dist/tools/youtube/navigate.js.map +1 -1
- package/mcp-server/dist/tools/youtube/playlist.js +2 -2
- package/mcp-server/dist/tools/youtube/playlist.js.map +1 -1
- package/mcp-server/dist/tools/youtube/readers.d.ts +4 -0
- package/mcp-server/dist/tools/youtube/readers.d.ts.map +1 -0
- package/mcp-server/dist/tools/youtube/readers.js +15 -0
- package/mcp-server/dist/tools/youtube/readers.js.map +1 -0
- package/mcp-server/package-lock.json +2 -2
- package/mcp-server/package.json +1 -1
- package/mcp-server/src/http.ts +8 -1
- package/mcp-server/src/services/identity.ts +5 -0
- package/mcp-server/src/services/memory-client.ts +32 -12
- package/mcp-server/src/services/memory-writer.ts +5 -2
- package/mcp-server/src/services/neural-interface.ts +67 -19
- package/mcp-server/src/services/typesafe-config.ts +268 -7
- package/mcp-server/src/tools/agents.ts +79 -17
- package/mcp-server/src/tools/browser-observe.ts +117 -28
- package/mcp-server/src/tools/browser-readers.ts +19 -0
- package/mcp-server/src/tools/remember.ts +6 -1
- package/mcp-server/src/tools/youtube/analytics.ts +26 -28
- package/mcp-server/src/tools/youtube/helpers.ts +8 -2
- package/mcp-server/src/tools/youtube/navigate.ts +6 -7
- package/mcp-server/src/tools/youtube/playlist.ts +2 -2
- package/mcp-server/src/tools/youtube/readers.ts +15 -0
- package/neural-interface/i18n/en.json +487 -8
- package/neural-interface/i18n/pt-BR.json +487 -8
- package/neural-interface/lib/agents-studio-api.js +7 -2
- package/neural-interface/lib/antigravity/home.js +43 -8
- package/neural-interface/lib/antigravity/tool-call.js +14 -0
- package/neural-interface/lib/assistant-api.js +90 -0
- package/neural-interface/lib/assistant-brains/antigravity.js +4 -2
- package/neural-interface/lib/assistant-brains/claude.js +10 -0
- package/neural-interface/lib/assistant-dispatch.js +276 -42
- package/neural-interface/lib/assistant-memory.js +3 -1
- package/neural-interface/lib/assistant-persona.js +14 -3
- package/neural-interface/lib/assistant-route-gate.js +11 -2
- package/neural-interface/lib/assistant-router.js +18 -8
- package/neural-interface/lib/assistant-runtime.js +103 -6
- package/neural-interface/lib/assistant-spilled-output.js +53 -0
- package/neural-interface/lib/assistant-task-prompt.js +15 -2
- package/neural-interface/lib/browser-connection-state.js +20 -0
- package/neural-interface/lib/browser-default.js +22 -2
- package/neural-interface/lib/browser-extension-adapter.js +221 -15
- package/neural-interface/lib/browser-extension-bridge.js +89 -9
- package/neural-interface/lib/browser-extension-folder.js +50 -11
- package/neural-interface/lib/browser-extension-package.js +6 -5
- package/neural-interface/lib/browser-extension-pin.json +15 -13
- package/neural-interface/lib/browser-extension-protocol.js +141 -14
- package/neural-interface/lib/browser-extension-setup.js +210 -40
- package/neural-interface/lib/browser-extension-update.js +104 -0
- package/neural-interface/lib/browser-extraction.js +38 -14
- package/neural-interface/lib/claude-bg-tasks.js +183 -0
- package/neural-interface/lib/claude-history.js +12 -1
- package/neural-interface/lib/confined-fs.js +25 -0
- package/neural-interface/lib/coordination/operations.js +2 -0
- package/neural-interface/lib/db.js +39 -16
- package/neural-interface/lib/editor-completion-opencode.js +2 -2
- package/neural-interface/lib/git-bash/manager.js +28 -3
- package/neural-interface/lib/git-status-runner.js +31 -3
- package/neural-interface/lib/loop-inventory.js +162 -0
- package/neural-interface/lib/loop-stall.js +74 -4
- package/neural-interface/lib/memory-session-capture.js +157 -66
- package/neural-interface/lib/native-loop-providers.js +73 -13
- package/neural-interface/lib/native-loop-runtime.js +3 -0
- package/neural-interface/lib/opencode-protocol.js +4 -2
- package/neural-interface/lib/peer-identity.js +62 -16
- package/neural-interface/lib/remote-policy.js +24 -7
- package/neural-interface/lib/session-cache-builder.js +66 -18
- package/neural-interface/lib/session-capture-gate.js +42 -0
- package/neural-interface/lib/session-indexer.js +28 -20
- package/neural-interface/lib/teams/README.md +22 -1
- package/neural-interface/lib/teams/api.js +79 -6
- package/neural-interface/lib/teams/index.js +2 -0
- package/neural-interface/lib/teams/recovery.js +68 -0
- package/neural-interface/lib/teams/scheduler.js +352 -31
- package/neural-interface/lib/teams/worktrees.js +123 -30
- package/neural-interface/lib/ui-blob-api.js +14 -5
- package/neural-interface/lib/ui-blob-store.js +302 -39
- package/neural-interface/package-lock.json +2 -2
- package/neural-interface/package.json +1 -1
- package/neural-interface/public/extension-setup.html +7 -2
- package/neural-interface/public/shared/agents/studio/ax-api.js +16 -0
- package/neural-interface/public/shared/agents/studio/ax-teams-view.js +318 -13
- package/neural-interface/public/shared/agents/studio/ax-teams.js +141 -9
- package/neural-interface/public/shared/assistant/asst-agents-dock.js +4 -0
- package/neural-interface/public/shared/assistant/asst-api.js +42 -0
- package/neural-interface/public/shared/assistant/asst-composer.js +85 -12
- package/neural-interface/public/shared/assistant/asst-panel.js +285 -10
- package/neural-interface/public/shared/assistant/asst-render.js +205 -4
- package/neural-interface/public/shared/assistant/asst-scenes.js +12 -0
- package/neural-interface/public/shared/assistant/asst-sidepanel.js +18 -1
- package/neural-interface/public/shared/assistant/asst-state.js +241 -2
- package/neural-interface/public/shared/assistant/asst-steer.js +294 -0
- package/neural-interface/public/shared/assistant/asst-styles.js +20 -0
- package/neural-interface/public/shared/bg-tasks/bg-tasks-claude.js +147 -0
- package/neural-interface/public/shared/bg-tasks/bg-tasks-model.js +527 -0
- package/neural-interface/public/shared/bg-tasks/bg-tasks-panel.js +161 -0
- package/neural-interface/public/shared/bg-tasks/bg-tasks-view.js +508 -0
- package/neural-interface/public/shared/browser-extension-updates.js +90 -0
- package/neural-interface/public/shared/cp/cp-bg-tasks.js +130 -0
- package/neural-interface/public/shared/extension-setup/es-page.js +41 -15
- package/neural-interface/public/shared/extension-setup/es-view.js +51 -11
- package/neural-interface/public/shared/extension-update-view.js +34 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-logic.js +8 -4
- package/neural-interface/public/shared/settings/settings-ai-browser.js +23 -3
- package/neural-interface/public/shared/settings/settings-browser-extension.js +581 -197
- package/neural-interface/public/shared/settings/settings-extension-diagrams.js +116 -0
- package/neural-interface/public/shared/settings/settings-extension-guide.js +222 -0
- package/neural-interface/public/shared/settings/settings-extension-update.js +114 -0
- package/neural-interface/public/shared/settings/settings-ia.js +2 -2
- package/neural-interface/public/shared/settings/settings-shell.js +5 -0
- package/neural-interface/public/shared/styles.css +200 -13
- package/neural-interface/public/shared/ui-claude-panel.js +110 -1
- package/neural-interface/public/shared/ui-notifications.js +23 -4
- package/neural-interface/public/shared/ui-settings-entry.js +6 -0
- package/neural-interface/public/shared/ui-settings.js +48 -11
- package/neural-interface/public/shared/ui-tray-columns.js +9 -2
- package/neural-interface/public/shared/worker-end.js +18 -0
- package/neural-interface/scripts/patch-node-pty.mjs +151 -0
- package/neural-interface/scripts/rebuild-pty.js +10 -0
- package/neural-interface/server.js +503 -281
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -417,20 +417,47 @@ function writeTree(dir, files) {
|
|
|
417
417
|
if (files.some(f => f.rel.startsWith('icons/'))) syncDir(join(dir, 'icons'));
|
|
418
418
|
syncDir(dir);
|
|
419
419
|
}
|
|
420
|
+
// Recognize an ordinary upgrade for the reload prompt only. Installation always verifies against the NEW pin.
|
|
421
|
+
// If the old manifest, contents or recorded installation disagree, keep the manual repair confirmation.
|
|
422
|
+
function previousInstall(paths, marker, previous, pin) {
|
|
423
|
+
if (!previous?.version || previous.version !== marker?.version || compareVersions(previous.version, pin.version) >= 0) return null;
|
|
424
|
+
const names = list(paths.folder);
|
|
425
|
+
if (!names || names.length > EXTENSION_MAX_FILES) return null;
|
|
426
|
+
const pathsInOrder = names.filter(name => name !== 'icons').sort();
|
|
427
|
+
if (names.includes('icons')) {
|
|
428
|
+
const icons = join(paths.folder, 'icons');
|
|
429
|
+
let info;
|
|
430
|
+
try { info = lstatOrNull(icons); } catch { return null; }
|
|
431
|
+
if (!info?.isDirectory() || !ownedSafely(info, paths.system)) return null;
|
|
432
|
+
const children = list(icons);
|
|
433
|
+
if (!children || children.length + pathsInOrder.length > EXTENSION_MAX_FILES) return null;
|
|
434
|
+
pathsInOrder.push(...children.sort().map(name => `icons/${name}`));
|
|
435
|
+
}
|
|
436
|
+
const digest = createHash('sha256');
|
|
437
|
+
for (const rel of pathsInOrder) {
|
|
438
|
+
if (!extensionFileAllowed(rel)) return null;
|
|
439
|
+
const bytes = readRegular(join(paths.folder, rel));
|
|
440
|
+
if (!bytes || (rel === 'manifest.json' && manifestOf(bytes)?.key !== pin.key)) return null;
|
|
441
|
+
digest.update(rel).update('\0').update(bytes).update('\0');
|
|
442
|
+
}
|
|
443
|
+
return digest.digest('hex') === marker.digest ? previous.version : null;
|
|
444
|
+
}
|
|
420
445
|
// The Reload the marker asks for after a replacement (`reload`), until the setup page sees the extension running again
|
|
421
|
-
// (confirmExtensionReload),
|
|
446
|
+
// (confirmExtensionReload), the new version authenticates (confirmExtensionVersion), or the owner confirms a repair.
|
|
422
447
|
// `repair`: the folder held files that were not the pinned extension (changed, added or
|
|
423
|
-
// deleted,
|
|
448
|
+
// deleted, or an unrecognized version) and they were replaced: the browser may still run them, at any version. `fromPort`: the
|
|
424
449
|
// same extension on another port, whose old manifest the browser keeps until a Reload. A Reload asked for before and
|
|
425
450
|
// not yet seen is kept (a repair stays a repair). A first install (no folder) asks for none.
|
|
426
|
-
function reloadAfter(pending, previous, port) {
|
|
451
|
+
function reloadAfter(pending, previous, port, fromVersion) {
|
|
427
452
|
const kept = pending && typeof pending === 'object' && !Array.isArray(pending) ? pending : null;
|
|
453
|
+
if (fromVersion && !kept?.repair) return { reload: { fromVersion } };
|
|
428
454
|
const repair = previous?.state === 'other' || kept?.repair === true;
|
|
429
455
|
const fromPort = previous?.state === 'pinned' && previous.port !== port ? previous.port : Number.isInteger(kept?.fromPort) ? kept.fromPort : null;
|
|
430
456
|
if (!repair && fromPort === null && !kept) return {};
|
|
431
|
-
return { reload: { ...(fromPort !== null ? { fromPort } : {}), ...(repair ? { repair: true } : {})
|
|
457
|
+
return { reload: { ...(fromPort !== null ? { fromPort } : {}), ...(repair ? { repair: true } : {}),
|
|
458
|
+
...(!repair && kept?.fromVersion ? { fromVersion: kept.fromVersion } : {}) } };
|
|
432
459
|
}
|
|
433
|
-
const reloadReasonOf = reload => (!reload ? null : reload.repair === true ? 'repair' : 'port');
|
|
460
|
+
const reloadReasonOf = reload => (!reload ? null : reload.repair === true ? 'repair' : reload.fromVersion ? 'version' : 'port');
|
|
434
461
|
// The verified files into the browser's path for `port`, as one transaction. `previous`: what inspectTree said of the
|
|
435
462
|
// folder that is there. Returns the marker written.
|
|
436
463
|
function place(paths, { files, port, pin, now, io, previous }) {
|
|
@@ -442,8 +469,10 @@ function place(paths, { files, port, pin, now, io, previous }) {
|
|
|
442
469
|
io.step('staged');
|
|
443
470
|
const live = identity(paths.folder);
|
|
444
471
|
const mode = live ? 'renames' : 'place';
|
|
472
|
+
const oldMarker = readJson(paths.marker);
|
|
473
|
+
const fromVersion = previous?.state === 'other' ? previousInstall(paths, oldMarker, previous, pin) : null;
|
|
445
474
|
const marker = { v: 1, version: pin.version, digest: folderDigest(wanted), appPort: port, preparedAt: now(), package: pin.sha256,
|
|
446
|
-
...reloadAfter(
|
|
475
|
+
...reloadAfter(oldMarker?.reload, previous, port, fromVersion) };
|
|
447
476
|
const j = { v: 1, mode, staging: basename(staging), retired: mode === 'renames' ? `unpacked.${hex()}.old` : null, next: identity(staging), previous: live,
|
|
448
477
|
previousVerified: previous?.state === 'pinned', marker };
|
|
449
478
|
try { writeDurably(paths.journal, Buffer.from(JSON.stringify(j)), io); } catch (error) { unstage(error); }
|
|
@@ -582,7 +611,7 @@ export function cachedExtensionPackage({ home, pin = EXTENSION_PIN }) {
|
|
|
582
611
|
export function extensionWorkDir(home) { return installRoot(home, { create: true }).root; }
|
|
583
612
|
|
|
584
613
|
// The marker's pending Reload removed under the lock, when `clears(reload, marker)` says so. Returns whether it was.
|
|
585
|
-
function clearReload(home, io, clears) {
|
|
614
|
+
function clearReload(home, io, clears, remaining = () => null) {
|
|
586
615
|
let paths;
|
|
587
616
|
try { paths = installRoot(home); } catch { return false; }
|
|
588
617
|
if (!paths) return false;
|
|
@@ -590,7 +619,9 @@ function clearReload(home, io, clears) {
|
|
|
590
619
|
return withLock(paths, () => {
|
|
591
620
|
const marker = readJson(paths.marker);
|
|
592
621
|
if (!marker?.reload || !clears(marker.reload, marker)) return false;
|
|
593
|
-
const { reload
|
|
622
|
+
const { reload, ...rest } = marker;
|
|
623
|
+
const pending = remaining(reload);
|
|
624
|
+
if (pending) rest.reload = pending;
|
|
594
625
|
writeDurably(paths.marker, Buffer.from(JSON.stringify(rest)), io);
|
|
595
626
|
return true;
|
|
596
627
|
});
|
|
@@ -607,7 +638,14 @@ function clearReload(home, io, clears) {
|
|
|
607
638
|
* (reconcileMarker carries it).
|
|
608
639
|
*/
|
|
609
640
|
export function confirmExtensionReload({ home, appPort, io: given = {} }) {
|
|
610
|
-
return clearReload(home, ioOf(given), (reload, marker) => reload.repair !== true && marker.appPort === Number(appPort));
|
|
641
|
+
return clearReload(home, ioOf(given), (reload, marker) => !reload.fromVersion && reload.repair !== true && marker.appPort === Number(appPort));
|
|
642
|
+
}
|
|
643
|
+
|
|
644
|
+
// A newly authenticated browser reported the installed version. This clears only an ordinary version upgrade.
|
|
645
|
+
export function confirmExtensionVersion({ home, version, io: given = {} }) {
|
|
646
|
+
// A same-version port change after this upgrade still needs the content script on the new port.
|
|
647
|
+
return clearReload(home, ioOf(given), (reload, marker) => !!reload.fromVersion && !reload.repair && marker.version === version,
|
|
648
|
+
reload => Number.isInteger(reload.fromPort) ? { fromPort: reload.fromPort } : null);
|
|
611
649
|
}
|
|
612
650
|
|
|
613
651
|
/**
|
|
@@ -622,7 +660,8 @@ export function confirmExtensionRepairReload({ home, io: given = {} }) {
|
|
|
622
660
|
|
|
623
661
|
/**
|
|
624
662
|
* What the folder's marker says, without writing or verifying: { folder, version, prepared, present, appPort,
|
|
625
|
-
* preparedAt, package, reloadPending, reloadReason }. `reloadReason`: '
|
|
663
|
+
* preparedAt, package, reloadPending, reloadReason, fromVersion? }. `reloadReason`: 'version' for an upgrade from an
|
|
664
|
+
* intact recorded installation, 'repair' (files that were not the pinned
|
|
626
665
|
* extension were replaced) or 'port' (only the setup port changed), while a Reload is pending; else null. For display
|
|
627
666
|
* only: whether the folder is the pinned extension is inspectExtensionFolder's answer, never this one.
|
|
628
667
|
*/
|
|
@@ -632,5 +671,5 @@ export function extensionFolderState(home) {
|
|
|
632
671
|
try { const info = lstatSync(folder); present = info.isDirectory() && !info.isSymbolicLink() && lstatSync(join(folder, 'manifest.json')).isFile(); } catch { present = false; }
|
|
633
672
|
return { folder, version: typeof marker?.version === 'string' ? marker.version : null, prepared: !!marker, present, appPort: marker?.appPort ?? null,
|
|
634
673
|
preparedAt: marker?.preparedAt ?? null, package: typeof marker?.package === 'string' ? marker.package : null, reloadPending: !!marker?.reload,
|
|
635
|
-
reloadReason: reloadReasonOf(marker?.reload), root };
|
|
674
|
+
reloadReason: reloadReasonOf(marker?.reload), ...(marker?.reload?.fromVersion ? { fromVersion: marker.reload.fromVersion } : {}), root };
|
|
636
675
|
}
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
import { readFileSync, rmSync } from 'node:fs';
|
|
26
26
|
import { join } from 'node:path';
|
|
27
27
|
import { downloadFile } from './cli-install.js';
|
|
28
|
-
import { cachedExtensionPackage, confirmExtensionReload, confirmExtensionRepairReload, downloadWorkName, extensionFolderState, extensionWorkDir, inspectExtensionFolder, prepareExtensionFolder, retargetExtensionFolder, verifiedPackageFiles } from './browser-extension-folder.js';
|
|
28
|
+
import { cachedExtensionPackage, confirmExtensionReload, confirmExtensionRepairReload, confirmExtensionVersion, downloadWorkName, extensionFolderState, extensionWorkDir, inspectExtensionFolder, prepareExtensionFolder, retargetExtensionFolder, verifiedPackageFiles } from './browser-extension-folder.js';
|
|
29
29
|
import { EXTENSION_PACKAGE_HOST, EXTENSION_PIN, pinProblems } from './browser-extension-pin.js';
|
|
30
30
|
|
|
31
31
|
/** What a failed download or check is called (the setup's error codes; lib/browser-extension-setup.js has the words). */
|
|
@@ -97,21 +97,21 @@ export function createExtensionPackage({ home, appPort, pin = EXTENSION_PIN, fet
|
|
|
97
97
|
* version, or a file changed, added or deleted), 'unsafe' (its root is a link, another user's or writable by others:
|
|
98
98
|
* nothing is done there), or null (the pinned extension; at most its port is set, with no download).
|
|
99
99
|
*/
|
|
100
|
-
function needs() {
|
|
101
|
-
const state = look().state;
|
|
100
|
+
function needs(state = look().state) {
|
|
102
101
|
return state === 'missing' ? 'install' : state === 'other' ? 'update' : state === 'unsafe' ? 'unsafe' : null;
|
|
103
102
|
}
|
|
104
103
|
function status() {
|
|
105
|
-
const state = extensionFolderState(home), need = needs(), shown = state.present ? state : null;
|
|
104
|
+
const inspected = look(), state = extensionFolderState(home), need = needs(inspected.state), shown = state.present ? state : null;
|
|
106
105
|
const failed = need === 'unsafe' ? { code: 'EXTENSION_FOLDER_UNSAFE', reason: 'check', at: null } : !job && last && !last.ok && need ? last : null;
|
|
107
106
|
return {
|
|
108
|
-
pinnedVersion: pin.version, folderVersion: shown ?
|
|
107
|
+
pinnedVersion: pin.version, folderVersion: shown ? inspected.version : null, folder: shown ? shown.folder : null, needs: need,
|
|
109
108
|
phase: job ? 'downloading' : failed ? 'failed' : 'idle',
|
|
110
109
|
...(job ? { received: job.received, total: job.total, reason: job.reason } : {}),
|
|
111
110
|
...(!job && failed ? { code: failed.code, reason: failed.reason, at: failed.at } : {}),
|
|
112
111
|
// A Reload the folder's marker asks for (a port change, or a repair: lib/browser-extension-folder.js), until the
|
|
113
112
|
// setup page sees the extension running again (confirmReload), or for a repair until the owner confirms it in
|
|
114
113
|
// Settings (confirmRepairReload).
|
|
114
|
+
...(state.fromVersion ? { fromVersion: state.fromVersion } : {}),
|
|
115
115
|
...(state.reloadPending ? { reloadPending: true, reloadReason: state.reloadReason } : {}),
|
|
116
116
|
};
|
|
117
117
|
}
|
|
@@ -193,6 +193,7 @@ export function createExtensionPackage({ home, appPort, pin = EXTENSION_PIN, fet
|
|
|
193
193
|
*/
|
|
194
194
|
retarget: settle,
|
|
195
195
|
/** The setup page saw the extension on this port: a Reload a port change asked for is done (never a repair's). */
|
|
196
|
+
confirmVersion: version => confirmExtensionVersion({ home, version }),
|
|
196
197
|
confirmReload: () => confirmExtensionReload({ home, appPort: port() }),
|
|
197
198
|
/** The owner confirmed in Settings that they reloaded the extension after a repair: that Reload is done. */
|
|
198
199
|
confirmRepairReload: () => confirmExtensionRepairReload({ home }),
|
|
@@ -2,13 +2,13 @@
|
|
|
2
2
|
"$comment": "The one SynaBun Browser Bridge this app release works with (docs/browser-extension-bridge.md -> Where the extension comes from). The app downloads exactly this file when the owner presses \"Connect your browser\" and installs it only when its size and SHA-256 are these. files is the SHA-256 of every file in it (the manifest with its setup content script set to port 1): the folder the browser loads counts as this extension only when it holds exactly these files. version, url, sha256, size and files are written by `node scripts/extension/check-browser-extension-pin.mjs --write` from the zip built out of browser-extension/ (Dev only); never edit them by hand. key is the extension's public key (its manifest's `key`): the extension ID is derived from it and never changes.",
|
|
3
3
|
"name": "SynaBun Browser Bridge",
|
|
4
4
|
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsDPDDuBTQq9nQgulmTSvzujxyOMZ7A7ttMSXtbIwup/X3kOlbkqoJEqQRGGJeb7+cNBSiiDBA5lhS0oYc9YeFcwNCucNMvGawDGblbQzDWEmn9dDK1krFVXWqNHVPIrEWlzCD2swXmIE2FCjMd5zw6dSRmmxu7VgE6bzvuOgB/W/oeOAyCsEDhDRDLBkjmb+yCsuexiXRWoempPsvAVhxhE8zEQJ1e8ChlFMtpOXSobU+YDgKYfcFy9Fbmk/o6M6B9y5zSlzs/HYIu7xvcCwjZI457idVMRxxAT6J/kXytmfKe/zbi5IO5/i0x9SCA1HRvt8K3nJqoH03h4TOvFwOwIDAQAB",
|
|
5
|
-
"version": "1.
|
|
6
|
-
"url": "https://synabun.ai/Public/downloads/browser-extension/synabun-browser-bridge-1.
|
|
7
|
-
"sha256": "
|
|
8
|
-
"size":
|
|
5
|
+
"version": "1.6.0",
|
|
6
|
+
"url": "https://synabun.ai/Public/downloads/browser-extension/synabun-browser-bridge-1.6.0.zip",
|
|
7
|
+
"sha256": "50c51c85b1c49ae3054091cc797087850259fdc8091af4a6b5f40a5bd0fa8379",
|
|
8
|
+
"size": 321390,
|
|
9
9
|
"files": {
|
|
10
|
-
"content.js": "
|
|
11
|
-
"engine.js": "
|
|
10
|
+
"content.js": "86db13f9688e4501e1d031491e841862382142c6bf04782f8862e1b35fb797c6",
|
|
11
|
+
"engine.js": "acd421f91f0f6fb40c2af3a09ab954c6e962e0932b641639380c094cdb736cec",
|
|
12
12
|
"icons/icon-128.png": "0749c9c8b40090232e0a234443c634117275598630ec06f4834d20bcad2b6841",
|
|
13
13
|
"icons/icon-16.png": "e91f674029855c7ea4bc6ca045087fe867ddba706209707060379c4832c15422",
|
|
14
14
|
"icons/icon-32.png": "5cc0916b2557a8d13c479a7e3a0170584be4c2f58cf770899c1be1aea106fe53",
|
|
@@ -19,14 +19,16 @@
|
|
|
19
19
|
"icons/status-on-16.png": "c9cbb6e4211f918b2179a796908cf9ebcf7cb5723d9aaa38a93486c2e3b0cd3e",
|
|
20
20
|
"icons/status-on-32.png": "b67d8fb865e02754ca0d1f1f2e0ead08655340a4ad93511e52ff65db4d487ed7",
|
|
21
21
|
"icons/status-on-48.png": "c9f306fb5dcbd6a919e5169e3c87c618116bad54858b434b02245dcd1a40b269",
|
|
22
|
-
"manifest.json": "
|
|
23
|
-
"popup-strings.js": "
|
|
24
|
-
"popup-view.js": "
|
|
22
|
+
"manifest.json": "6abfa17bb9c48b9779f448ba6a13d6e8ba99e3858697fec8b79921e0cde3a24b",
|
|
23
|
+
"popup-strings.js": "b9d6a147a15dae32b2513437f5de39ec77e8a1ca899086c0092ba31d30dea3d4",
|
|
24
|
+
"popup-view.js": "c5834c2ff19c2cd86fe6954c7a20f154f8804173a022d16910d893bf52491322",
|
|
25
25
|
"popup.css": "d6a6c5442942bede66f315accef476c591ad71ea4ac09b51d689a622753208f1",
|
|
26
|
-
"popup.html": "
|
|
27
|
-
"popup.js": "
|
|
28
|
-
"protocol.js": "
|
|
29
|
-
"
|
|
26
|
+
"popup.html": "a2dc445a70a8f3430cc4219ab506c7f942bf36c1bd4f6bc85a07e3d1f619cc24",
|
|
27
|
+
"popup.js": "4d60c643c2adc7d0ee0654e9fe2c5b621259531899a52f64d3b855c98ab82f97",
|
|
28
|
+
"protocol.js": "b92490cd264eb4f1eb99e8d425bd6a2d0cdf25d2bca07cd3ba313e0d292e7bef",
|
|
29
|
+
"readers-generated.js": "43c4a56f2a195f67712fea55eb12e3d5390082190d5d0b41e41751590f649619",
|
|
30
|
+
"readers.js": "19b7ed04289a2341cdca1035b7fc11bf95d35a31ff48da14097832eb2295e199",
|
|
31
|
+
"service-worker.js": "44e529ebe65ccd16b546543257197b448955ae9f11f58efed8b9de6acfd7626a",
|
|
30
32
|
"setup-content.js": "9cb56f6f046af294328c03a080cefc58052ee405366eff5f3d70bb1ea02dbabe",
|
|
31
33
|
"tokens.css": "a27f691794d844cb81b98b45e12863b102e06e9f0a3c722ba96b69b84d3c5a3f"
|
|
32
34
|
}
|
|
@@ -34,9 +34,10 @@ export const EVALUATE_RESULT_MAX = 1000000;
|
|
|
34
34
|
// 'MAIN' is the page's own JavaScript world (its globals are visible); 'USER_SCRIPT' is Chrome's separate world for
|
|
35
35
|
// user scripts (the DOM, none of the page's globals, exempt from the page's CSP).
|
|
36
36
|
export const EVALUATE_WORLDS = ['MAIN', 'USER_SCRIPT'];
|
|
37
|
-
// wait with loadState: 'load' (the tab finished loading)
|
|
38
|
-
// NETWORK_IDLE_QUIET ms, as Playwright counts it),
|
|
39
|
-
|
|
37
|
+
// wait with loadState: 'load' (the tab finished loading), 'networkidle' (also no request of the tab in flight for
|
|
38
|
+
// NETWORK_IDLE_QUIET ms, as Playwright counts it) or, from READS_SINCE, 'domcontentloaded' (the document was parsed:
|
|
39
|
+
// its readyState is no longer 'loading'), within args.timeout (default, most).
|
|
40
|
+
export const LOAD_STATES = ['load', 'networkidle', 'domcontentloaded'];
|
|
40
41
|
export const NETWORK_IDLE_QUIET = 500;
|
|
41
42
|
export const NETWORK_IDLE_TIMEOUT = 15000;
|
|
42
43
|
export const NETWORK_IDLE_TIMEOUT_MAX = 60000;
|
|
@@ -163,15 +164,84 @@ export function inventory(value) {
|
|
|
163
164
|
}
|
|
164
165
|
return value;
|
|
165
166
|
}
|
|
166
|
-
export const COMMANDS = ['create', 'claim', 'release', 'navigate', 'back', 'forward', 'reload', 'snapshot', 'click', 'hover', 'fill', 'type', 'press', 'select', 'scroll', 'wait', 'content', 'screenshot', 'upload', 'download', 'evaluate', 'revokeTab', 'revokeSite', 'disconnect', 'revoke', 'mode', 'reset'];
|
|
167
|
+
export const COMMANDS = ['create', 'claim', 'release', 'navigate', 'back', 'forward', 'reload', 'snapshot', 'click', 'hover', 'fill', 'type', 'press', 'select', 'scroll', 'wait', 'content', 'screenshot', 'upload', 'download', 'evaluate', 'read', 'revokeTab', 'revokeSite', 'disconnect', 'revoke', 'mode', 'reset', 'selfReload'];
|
|
167
168
|
// The first extension version that knows `evaluate` and `wait` with `loadState`. An older one ends the connection on a
|
|
168
169
|
// command it does not know, so the server never sends it one (it answers EXTENSION_RELOAD_REQUIRED itself).
|
|
169
170
|
export const LONG_OPS_SINCE = '1.4.0';
|
|
171
|
+
// The first extension version that reloads itself on the owner's one click (Settings → Update now).
|
|
172
|
+
export const SELF_RELOAD_SINCE = '1.5.0';
|
|
173
|
+
// ── Readers (1.5.0): fixed, read-only page functions shipped in the extension ──
|
|
174
|
+
// `read` runs one of READER_IDS in the agent's tab through chrome.scripting.executeScript({ func }) in the isolated
|
|
175
|
+
// world: no page JavaScript, no "Allow User Scripts", no debugger. A reader is named by its id and nothing else; its
|
|
176
|
+
// arguments are plain data (a CSS selector for the page readers, a scroll step for the paged extractors), never code.
|
|
177
|
+
// The functions are browser-extension/readers.js and readers-generated.js (generated from the extractors the MCP
|
|
178
|
+
// server sends the Playwright backend: scripts/extension/build-browser-readers.mjs). An id not on this list is
|
|
179
|
+
// INVALID_MESSAGE on both sides. `snapshot` with `offset` and `wait` with loadState 'domcontentloaded' came with it.
|
|
180
|
+
export const READS_SINCE = '1.5.0';
|
|
181
|
+
export const READER_IDS = Object.freeze([
|
|
182
|
+
// The page itself: its text (innerText), its main content as cleaned HTML (the server turns it into Markdown), its address.
|
|
183
|
+
'page.text', 'page.html', 'page.url',
|
|
184
|
+
// Paged extractors: one read of what the page shows, and a scroll of the feed between reads.
|
|
185
|
+
'x.tweets', 'fb.posts', 'fb.groups', 'tiktok.feed', 'tiktok.search', 'tiktok.studio', 'wa.chats', 'wa.messages',
|
|
186
|
+
'ig.feed', 'ig.reels', 'ig.search', 'li.feed', 'li.notifications', 'li.search_people', 'li.jobs',
|
|
187
|
+
// One-shot readers.
|
|
188
|
+
'tiktok.profile', 'tiktok.account', 'ig.profile', 'ig.post', 'li.profile', 'li.post', 'li.messages', 'li.network', 'fb.composer_state',
|
|
189
|
+
'youtube.channel_id', 'youtube.channel_ready', 'youtube.channel_name', 'youtube.videos',
|
|
190
|
+
]);
|
|
191
|
+
// The readers that take a scroll step (their feed scrolls between reads); every other one only reads.
|
|
192
|
+
export const PAGED_READERS = Object.freeze(['x.tweets', 'fb.posts', 'fb.groups', 'tiktok.feed', 'tiktok.search', 'tiktok.studio', 'wa.chats', 'wa.messages',
|
|
193
|
+
'ig.feed', 'ig.reels', 'ig.search', 'li.feed', 'li.notifications', 'li.search_people', 'li.jobs']);
|
|
194
|
+
export const READ_STEPS = ['read', 'scroll'];
|
|
195
|
+
// The most text a page reader answers with (characters): the server pages it (maxChars / offset) as it does a
|
|
196
|
+
// Playwright page's.
|
|
197
|
+
export const READ_TEXT_MAX = 1000000;
|
|
198
|
+
// The extension version an operation needs (null: any paired one). The server answers EXTENSION_RELOAD_REQUIRED itself
|
|
199
|
+
// for an older peer, which would otherwise end the connection on the command or argument it does not know.
|
|
200
|
+
export function requiredVersion(op, args = {}) {
|
|
201
|
+
if (op === 'read' || op === 'wait' && args?.loadState === 'domcontentloaded' || op === 'snapshot' && args?.offset !== undefined) return READS_SINCE;
|
|
202
|
+
if (longOp(op, args)) return LONG_OPS_SINCE;
|
|
203
|
+
return null;
|
|
204
|
+
}
|
|
205
|
+
// ── Uploads: the type of a file, from its name ──
|
|
206
|
+
// A file input and the site behind it read a File's `type` (TikTok Studio refuses a video whose type is not a video
|
|
207
|
+
// one). The extension gives every file it assigns the type this fixed table names for its extension, whatever the
|
|
208
|
+
// transport said; an extension the table does not know is application/octet-stream.
|
|
209
|
+
export const UPLOAD_TYPES = Object.freeze({
|
|
210
|
+
mp4: 'video/mp4', m4v: 'video/x-m4v', mov: 'video/quicktime', webm: 'video/webm', mkv: 'video/x-matroska', avi: 'video/x-msvideo',
|
|
211
|
+
mpeg: 'video/mpeg', mpg: 'video/mpeg', '3gp': 'video/3gpp',
|
|
212
|
+
png: 'image/png', jpg: 'image/jpeg', jpeg: 'image/jpeg', gif: 'image/gif', webp: 'image/webp', avif: 'image/avif', heic: 'image/heic',
|
|
213
|
+
heif: 'image/heif', bmp: 'image/bmp', svg: 'image/svg+xml', ico: 'image/x-icon', tif: 'image/tiff', tiff: 'image/tiff',
|
|
214
|
+
mp3: 'audio/mpeg', m4a: 'audio/mp4', aac: 'audio/aac', wav: 'audio/wav', ogg: 'audio/ogg', oga: 'audio/ogg', opus: 'audio/opus', flac: 'audio/flac',
|
|
215
|
+
pdf: 'application/pdf', txt: 'text/plain', md: 'text/markdown', csv: 'text/csv', tsv: 'text/tab-separated-values', html: 'text/html', htm: 'text/html',
|
|
216
|
+
json: 'application/json', xml: 'application/xml', zip: 'application/zip', srt: 'application/x-subrip', vtt: 'text/vtt',
|
|
217
|
+
doc: 'application/msword', docx: 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
|
|
218
|
+
xls: 'application/vnd.ms-excel', xlsx: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
|
|
219
|
+
ppt: 'application/vnd.ms-powerpoint', pptx: 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
|
|
220
|
+
});
|
|
221
|
+
// The extension of a file name as Node's path.extname reads it: after the last dot of the last path segment, never a
|
|
222
|
+
// leading dot ('.mp4' has none).
|
|
223
|
+
export function uploadType(name) {
|
|
224
|
+
const base = String(name || '').split(/[\\/]/).pop(), dot = base.lastIndexOf('.');
|
|
225
|
+
const ext = dot > 0 ? base.slice(dot + 1).toLowerCase() : '';
|
|
226
|
+
return Object.hasOwn(UPLOAD_TYPES, ext) ? UPLOAD_TYPES[ext] : 'application/octet-stream';
|
|
227
|
+
}
|
|
228
|
+
// What the browser itself said when it refused an operation (a Chrome API's error message), carried inside the
|
|
229
|
+
// answer's `error` text after the code's own sentence: `… The browser said: "No current window".` Never a page's
|
|
230
|
+
// content: only messages of chrome.* calls are put there, on one line, cut to DETAIL_MAX characters.
|
|
231
|
+
export const DETAIL_MAX = 300;
|
|
232
|
+
export function cleanDetail(value) {
|
|
233
|
+
const text = String(value?.message ?? value ?? '').replace(/[\u0000-\u001f\u007f]+/g, ' ').replace(/"/g, "'").trim();
|
|
234
|
+
return text.slice(0, DETAIL_MAX);
|
|
235
|
+
}
|
|
236
|
+
export function errorDetail(result) {
|
|
237
|
+
const match = /The browser said: "([^"]*)"\.$/.exec(typeof result?.error === 'string' ? result.error : '');
|
|
238
|
+
return match ? match[1] : '';
|
|
239
|
+
}
|
|
170
240
|
export const HISTORY = ['back', 'forward'];
|
|
171
241
|
// The owner's control messages: revocations, the mode (full control or restricted) and `reset` (a restarted server
|
|
172
242
|
// hands back every tab agents of its previous process held). They overtake queued commands on both sides, are never
|
|
173
243
|
// cancelled themselves, and carry the owner's name only: nothing an agent sends can be one.
|
|
174
|
-
export const CONTROL = ['revokeTab', 'revokeSite', 'disconnect', 'revoke', 'mode', 'reset'];
|
|
244
|
+
export const CONTROL = ['revokeTab', 'revokeSite', 'disconnect', 'revoke', 'mode', 'reset', 'selfReload'];
|
|
175
245
|
export function command(value) {
|
|
176
246
|
object(value, ['type', 'id', 'op', 'tab', 'owner', 'args', 'blockedHosts', 'blockedPorts', 'selfHosts', 'deadline']);
|
|
177
247
|
if (value.type !== 'command' || !COMMANDS.includes(value.op)) fail('UNSUPPORTED_IN_EXTENSION_MODE');
|
|
@@ -185,8 +255,14 @@ export function command(value) {
|
|
|
185
255
|
if (value[key] !== undefined && (!Array.isArray(value[key]) || value[key].length > 200 || value[key].some(h => typeof h !== 'string' || h.length > 253 || !/^[a-zA-Z0-9.:%-]+$/.test(h)))) fail('INVALID_MESSAGE');
|
|
186
256
|
}
|
|
187
257
|
if (value.blockedPorts !== undefined && (!Array.isArray(value.blockedPorts) || value.blockedPorts.length > 32 || value.blockedPorts.some(p => !Number.isSafeInteger(p) || p < 1 || p > 65535))) fail('INVALID_MESSAGE');
|
|
258
|
+
if (value.op === 'selfReload') {
|
|
259
|
+
if (value.owner !== 'owner' || value.tab !== null) fail('NOT_OWNED');
|
|
260
|
+
object(value.args, ['allowBusy']);
|
|
261
|
+
if (typeof value.args.allowBusy !== 'boolean' || value.deadline > COMMAND_WAIT) fail('INVALID_MESSAGE');
|
|
262
|
+
return value;
|
|
263
|
+
}
|
|
188
264
|
const a = value.args; object(a, ['url', 'ref', 'selector', 'nthMatch', 'value', 'text', 'key', 'direction', 'distance', 'maxChars', 'offset', 'timeout', 'state', 'files', 'site', 'fullControl', 'version',
|
|
189
|
-
'expression', 'body', 'params', 'world', 'frame', 'loadState']);
|
|
265
|
+
'expression', 'body', 'params', 'world', 'frame', 'loadState', 'reader', 'step']);
|
|
190
266
|
if (value.deadline > commandWait(value.op, a)) fail('INVALID_MESSAGE');
|
|
191
267
|
for (const [k, v] of Object.entries(a)) {
|
|
192
268
|
if (k === 'fullControl') { if (typeof v !== 'boolean') fail('INVALID_MESSAGE'); }
|
|
@@ -195,6 +271,9 @@ export function command(value) {
|
|
|
195
271
|
else if (k === 'frame') { if (!Number.isSafeInteger(v) || v < 0 || v > 2147483647) fail('INVALID_MESSAGE'); }
|
|
196
272
|
else if (k === 'expression' || k === 'body') string(v, EVALUATE_SCRIPT_MAX);
|
|
197
273
|
else if (k === 'params') string(v, EVALUATE_PARAMS_MAX);
|
|
274
|
+
// A reader is one id of a closed list, never anything that names or carries code.
|
|
275
|
+
else if (k === 'reader') { if (typeof v !== 'string' || !READER_IDS.includes(v)) fail('INVALID_MESSAGE'); }
|
|
276
|
+
else if (k === 'step') { if (!READ_STEPS.includes(v)) fail('INVALID_MESSAGE'); }
|
|
198
277
|
else if (['nthMatch', 'distance', 'maxChars', 'offset', 'timeout'].includes(k)) {
|
|
199
278
|
if (!Number.isSafeInteger(v) || v < 0 || v > 1000000) fail('INVALID_MESSAGE');
|
|
200
279
|
} else if (k === 'files') {
|
|
@@ -230,20 +309,61 @@ export function command(value) {
|
|
|
230
309
|
if (!Array.isArray(list)) fail('INVALID_MESSAGE');
|
|
231
310
|
}
|
|
232
311
|
} else if (evaluate.some(k => a[k] !== undefined)) fail('INVALID_MESSAGE');
|
|
312
|
+
// read: a reader of the agent's tab (`reader`), a page reader's scope (`selector`), a paged extractor's scroll
|
|
313
|
+
// (`step` 'scroll' with `distance` and `direction`), and nothing else.
|
|
314
|
+
if (value.op === 'read') {
|
|
315
|
+
if (value.tab === null || typeof a.reader !== 'string') fail('INVALID_MESSAGE');
|
|
316
|
+
if (Object.keys(a).some(k => !['reader', 'step', 'selector', 'distance', 'direction'].includes(k))) fail('INVALID_MESSAGE');
|
|
317
|
+
if (a.step === 'scroll' ? a.selector !== undefined || !PAGED_READERS.includes(a.reader) : a.distance !== undefined || a.direction !== undefined) fail('INVALID_MESSAGE');
|
|
318
|
+
if (a.selector !== undefined && !['page.text', 'page.html'].includes(a.reader)) fail('INVALID_MESSAGE');
|
|
319
|
+
} else if (a.reader !== undefined || a.step !== undefined) fail('INVALID_MESSAGE');
|
|
233
320
|
// A load-state wait names the state and, at most, its timeout: it waits for the tab, not for an element.
|
|
234
321
|
if (a.loadState !== undefined && (value.op !== 'wait' || value.tab === null || !LOAD_STATES.includes(a.loadState)
|
|
235
322
|
|| Object.keys(a).some(k => k !== 'loadState' && k !== 'timeout'))) fail('INVALID_MESSAGE');
|
|
236
323
|
return value;
|
|
237
324
|
}
|
|
325
|
+
// ── Capabilities (1.6.0): what this browser lets the extension do, as the extension saw it ──
|
|
326
|
+
// `{ type: 'capabilities', capabilities: { v, userScripts: { state, execute }, browser: { brands, major, platform } } }`,
|
|
327
|
+
// from the extension only, on the authenticated channel: after its first inventory of a connection and after every
|
|
328
|
+
// pong. It is an observation, never an action: the extension asks the user scripts API for its registered scripts
|
|
329
|
+
// (getScripts) and looks whether `execute` exists, and runs nothing in any tab to learn it. `state`: 'ready' (Allow User Scripts on, `execute` there),
|
|
330
|
+
// 'disabled' (the API is missing or refuses: the switch, before Chrome 138 Developer mode, is off), 'unsupported' (on,
|
|
331
|
+
// but the browser predates userScripts.execute, Chrome 135), 'error' (the check itself failed). `brands` are the
|
|
332
|
+
// browser's names from navigator.userAgentData without its GREASE entries, `major` its Chromium version, `platform`
|
|
333
|
+
// the operating system it names; any of them may be unknown ([] or null).
|
|
334
|
+
// The server never sends this type: an extension from before 1.6.0 ends the connection on a type it does not know, so
|
|
335
|
+
// a fresh observation is asked for with an ordinary ping.
|
|
336
|
+
export const CAPABILITIES_SINCE = '1.6.0';
|
|
337
|
+
export const CAPABILITIES_VERSION = 1;
|
|
338
|
+
export const USER_SCRIPT_STATES = Object.freeze(['ready', 'disabled', 'unsupported', 'error']);
|
|
339
|
+
export const BROWSER_BRANDS_MAX = 6;
|
|
340
|
+
export const BROWSER_NAME = /^[A-Za-z0-9 ._()-]{1,40}$/;
|
|
341
|
+
export const PLATFORM_NAME = /^[A-Za-z0-9 ._()-]{1,16}$/;
|
|
342
|
+
export function capabilityReport(value) {
|
|
343
|
+
object(value, ['v', 'userScripts', 'browser']);
|
|
344
|
+
if (value.v !== CAPABILITIES_VERSION) fail('INVALID_MESSAGE');
|
|
345
|
+
object(value.userScripts, ['state', 'execute']);
|
|
346
|
+
if (!USER_SCRIPT_STATES.includes(value.userScripts.state) || typeof value.userScripts.execute !== 'boolean') fail('INVALID_MESSAGE');
|
|
347
|
+
const b = value.browser; object(b, ['brands', 'major', 'platform']);
|
|
348
|
+
if (!Array.isArray(b.brands) || b.brands.length > BROWSER_BRANDS_MAX || b.brands.some(name => typeof name !== 'string' || !BROWSER_NAME.test(name))) fail('INVALID_MESSAGE');
|
|
349
|
+
if (b.major !== null && (!Number.isSafeInteger(b.major) || b.major < 1 || b.major > 999)) fail('INVALID_MESSAGE');
|
|
350
|
+
if (b.platform !== null && (typeof b.platform !== 'string' || !PLATFORM_NAME.test(b.platform))) fail('INVALID_MESSAGE');
|
|
351
|
+
return value;
|
|
352
|
+
}
|
|
238
353
|
export function payload(value) {
|
|
239
|
-
if (value?.type === '
|
|
354
|
+
if (value?.type === 'updateStatus') {
|
|
355
|
+
object(value, ['type', 'version', 'runsActive']);
|
|
356
|
+
if (typeof value.runsActive !== 'boolean' || (value.version !== null && !/^\d{1,5}(\.\d{1,5}){0,3}$/.test(string(value.version, 23)))) fail('INVALID_MESSAGE');
|
|
357
|
+
} else if (value?.type === 'state') { object(value, ['type', 'inventory']); inventory(value.inventory); }
|
|
240
358
|
else if (value?.type === 'result') {
|
|
241
359
|
object(value, ['type', 'id', 'result', 'inventory']); handle(value.id); inventory(value.inventory);
|
|
242
360
|
// evaluate adds `value` (the JSON text of the script's result), `truncated` with `valueLength` (the result was
|
|
243
361
|
// longer than its cap: `value` is then the beginning of that JSON text, not valid JSON) and, with code PAGE_ERROR,
|
|
244
362
|
// `errorMessage` and `errorStack` (what the page's script threw). A load-state wait adds `loadState`.
|
|
363
|
+
// read (1.5.0) adds `loading` (a paged extractor's feed showed a loading marker); a snapshot asked with an `offset`
|
|
364
|
+
// adds `snapshotTotal` (characters of the whole snapshot) and `snapshotNext` (the offset of what did not fit).
|
|
245
365
|
object(value.result, ['ok', 'code', 'error', 'url', 'title', 'snapshotText', 'mode', 'snapshotId', 'content', 'text', 'base64', 'mimeType', 'tab', 'downloadId', 'files',
|
|
246
|
-
'value', 'truncated', 'valueLength', 'errorMessage', 'errorStack', 'loadState']);
|
|
366
|
+
'value', 'truncated', 'valueLength', 'errorMessage', 'errorStack', 'loadState', 'loading', 'snapshotTotal', 'snapshotNext']);
|
|
247
367
|
if (typeof value.result.ok !== 'boolean') fail('INVALID_MESSAGE');
|
|
248
368
|
for (const [k, v] of Object.entries(value.result)) {
|
|
249
369
|
if (k === 'ok') continue;
|
|
@@ -258,17 +378,19 @@ export function payload(value) {
|
|
|
258
378
|
}
|
|
259
379
|
if (total > MAX_FILE) fail('INVALID_MESSAGE');
|
|
260
380
|
} else if (k === 'downloadId') { if (!Number.isSafeInteger(v)) fail('INVALID_MESSAGE'); }
|
|
261
|
-
else if (
|
|
262
|
-
else if (k === 'truncated') { if (typeof v !== 'boolean') fail('INVALID_MESSAGE'); }
|
|
381
|
+
else if (['valueLength', 'snapshotTotal', 'snapshotNext'].includes(k)) { if (!Number.isSafeInteger(v) || v < 0) fail('INVALID_MESSAGE'); }
|
|
382
|
+
else if (k === 'truncated' || k === 'loading') { if (typeof v !== 'boolean') fail('INVALID_MESSAGE'); }
|
|
263
383
|
else string(v, k === 'base64' ? MAX_MESSAGE - 4096 : ['content', 'text', 'snapshotText', 'value'].includes(k) ? EVALUATE_RESULT_MAX : 8192);
|
|
264
384
|
}
|
|
265
|
-
} else if (value?.type === '
|
|
385
|
+
} else if (value?.type === 'capabilities') { object(value, ['type', 'capabilities']); capabilityReport(value.capabilities); }
|
|
386
|
+
else if (value?.type === 'ping' || value?.type === 'pong' || value?.type === 'unpair') object(value, ['type']);
|
|
266
387
|
// The server gave up on a command (its wait ended): the extension stops it, queued or running, and never starts it.
|
|
267
388
|
else if (value?.type === 'cancel') { object(value, ['type', 'id']); handle(value.id); }
|
|
268
389
|
else command(value);
|
|
269
390
|
return value;
|
|
270
391
|
}
|
|
271
392
|
export const ERROR_TEXT = Object.freeze({
|
|
393
|
+
RELOAD_BUSY: 'Automation is active. Wait for it to finish or confirm the reload.',
|
|
272
394
|
EXTENSION_NOT_CONNECTED: 'The browser extension is not connected. Open its popup and reconnect (after a SynaBun restart it reconnects by itself).',
|
|
273
395
|
NOT_CONNECTED: 'The extension disconnected. Reconnect from its popup.',
|
|
274
396
|
AUTH_FAILED: 'Authentication failed. Revoke pairing and pair again on both sides.',
|
|
@@ -284,7 +406,7 @@ export const ERROR_TEXT = Object.freeze({
|
|
|
284
406
|
NO_HISTORY_ENTRY: 'There is no page to go back or forward to in this tab. Nothing was done.',
|
|
285
407
|
STALE_REF: 'This element reference is stale. Take a fresh snapshot; no action was performed.',
|
|
286
408
|
UNSUPPORTED_IN_EXTENSION_MODE: 'This operation is unavailable with the extension backend. See docs/browser-extension-bridge.md.',
|
|
287
|
-
ACTIVE_TAB_REQUIRED: '
|
|
409
|
+
ACTIVE_TAB_REQUIRED: 'The extension captures screenshots with chrome.tabs.captureVisibleTab, which draws only the tab a window is showing (no debugger is attached, so a tab in the background cannot be drawn), and the tab was not, or stopped being, the one shown while capturing. In full control the extension brings the agent’s own tab to the front of its window for the capture: retry. In restricted mode it never does: the owner activates the tab, or switches the extension to full control. To read the page instead, use browser_snapshot or browser_content.',
|
|
288
410
|
TAB_LIMIT: 'This bridge already controls 200 tabs. Close an agent tab before opening another.',
|
|
289
411
|
TAB_BUSY: 'Chrome is editing tabs (for example during a drag). Retry navigation after the tab strip settles.',
|
|
290
412
|
NAVIGATION_FAILED: 'Chrome refused tabs.update for this navigation. Check the browser site-access policy and destination, then retry.',
|
|
@@ -309,9 +431,14 @@ export const ERROR_TEXT = Object.freeze({
|
|
|
309
431
|
PAGE_ERROR: 'The page’s script threw, or did not compile (evaluate takes one expression: wrap statements in a function, (() => { …; return value; })()). errorMessage and errorStack say what the page reported; the bridge itself did not fail.',
|
|
310
432
|
BLANK_PAGE: 'The tab shows the blank start page, where no script can run. Navigate it to an http(s) page first.',
|
|
311
433
|
FRAME_NOT_FOUND: 'The tab has no frame with this id that a script can run in (frame 0 is the top document). Nothing was run.',
|
|
312
|
-
|
|
434
|
+
READER_FAILED: 'The extension’s reader found nothing it could read on this page (the page changed under it, or is not the page this reader is for). Nothing was changed on the page; observe the tab, then retry.',
|
|
435
|
+
INVALID_SELECTOR: 'The selector is not a valid CSS selector. Nothing was read.',
|
|
436
|
+
SCROLL_TARGET_MISSING: 'The feed this extractor scrolls is not on the page (scroll container not found). Items read so far are kept.',
|
|
437
|
+
NETWORK_IDLE_UNAVAILABLE:'The extension cannot watch this browser’s network requests (its webRequest permission is not in effect). The owner reloads SynaBun Browser Bridge on the browser’s extensions page; until then wait for a selector or a fixed time instead.',
|
|
313
438
|
});
|
|
439
|
+
// `error.detail`: what the browser said (cleanDetail), appended to the code's own sentence (errorDetail reads it back).
|
|
314
440
|
export function safeError(error) {
|
|
315
441
|
const code = Object.hasOwn(ERROR_TEXT, error?.code) ? error.code : 'OPERATION_FAILED';
|
|
316
|
-
|
|
442
|
+
const detail = cleanDetail(error?.detail);
|
|
443
|
+
return { ok: false, code, error: `${code}: ${ERROR_TEXT[code]}${detail ? ` The browser said: "${detail}".` : ''}` };
|
|
317
444
|
}
|