synabun 2.4.2 → 2.4.3
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 +20 -0
- package/README.md +1 -1
- package/docs/browser-extension-bridge.md +23 -3
- package/lib/release-npm-ci.mjs +23 -1
- package/mcp-server/dist/services/neural-interface.js +1 -1
- package/mcp-server/dist/services/neural-interface.js.map +1 -1
- package/mcp-server/dist/tools/browser-extension-setup.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-extension-setup.js +8 -2
- package/mcp-server/dist/tools/browser-extension-setup.js.map +1 -1
- package/mcp-server/package-lock.json +5 -5
- package/mcp-server/package.json +1 -1
- package/mcp-server/src/services/neural-interface.ts +1 -1
- package/mcp-server/src/tools/browser-extension-setup.ts +8 -2
- package/neural-interface/i18n/en.json +50 -1
- package/neural-interface/i18n/pt-BR.json +57 -8
- package/neural-interface/lib/assistant-api.js +33 -0
- package/neural-interface/lib/assistant-brains/opencode.js +121 -7
- package/neural-interface/lib/assistant-dispatch.js +26 -2
- package/neural-interface/lib/assistant-envelope.js +40 -0
- package/neural-interface/lib/assistant-runtime.js +95 -10
- package/neural-interface/lib/browser-extension-adapter.js +1 -3
- package/neural-interface/lib/browser-extension-archive.js +149 -0
- package/neural-interface/lib/browser-extension-bridge.js +7 -4
- package/neural-interface/lib/browser-extension-folder.js +596 -76
- package/neural-interface/lib/browser-extension-package.js +200 -0
- package/neural-interface/lib/browser-extension-pin.js +84 -0
- package/neural-interface/lib/browser-extension-pin.json +33 -0
- package/neural-interface/lib/browser-extension-setup.js +105 -18
- package/neural-interface/lib/cli-install.js +23 -3
- package/neural-interface/lib/cli-update-planner.js +67 -4
- package/neural-interface/lib/native-loop-providers.js +10 -1
- package/neural-interface/lib/native-loop-runtime.js +20 -2
- package/neural-interface/lib/opencode-shell-read.js +107 -0
- package/neural-interface/lib/opencode-stop-failures.js +40 -0
- package/neural-interface/lib/opencode-turn-release.js +173 -0
- package/neural-interface/lib/opencode-v2-client.js +4 -1
- package/neural-interface/lib/opencode-v2-ws-requests.js +34 -0
- package/neural-interface/lib/opencode2-client.js +341 -6
- package/neural-interface/lib/opencode2-translate.js +161 -4
- package/neural-interface/lib/terminal-token-redaction.js +83 -0
- package/neural-interface/lib/whatsapp/bridge.js +52 -6
- package/neural-interface/package-lock.json +5 -5
- package/neural-interface/package.json +1 -1
- package/neural-interface/public/extension-setup.html +5 -2
- package/neural-interface/public/shared/agy/agy-panel.js +38 -10
- package/neural-interface/public/shared/assistant/asst-api.js +25 -0
- package/neural-interface/public/shared/assistant/asst-panel.js +69 -1
- package/neural-interface/public/shared/assistant/asst-rack-styles.js +23 -0
- package/neural-interface/public/shared/assistant/asst-render.js +138 -6
- package/neural-interface/public/shared/assistant/asst-shell-logic.js +200 -0
- package/neural-interface/public/shared/assistant/asst-shell.js +111 -0
- package/neural-interface/public/shared/assistant/asst-styles.js +1 -0
- package/neural-interface/public/shared/cdx/cdx-tabs.js +25 -0
- package/neural-interface/public/shared/extension-setup/es-page.js +10 -4
- package/neural-interface/public/shared/extension-setup/es-view.js +25 -10
- package/neural-interface/public/shared/mtc/mtc-panel.js +17 -2
- package/neural-interface/public/shared/ocp-v2/ocp-v2-events.js +5 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-manager.js +1 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +34 -2
- package/neural-interface/public/shared/ocp-v2/ocp-v2-rehydrate.js +7 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +26 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-send.js +39 -6
- package/neural-interface/public/shared/ocp-v2/ocp-v2-session-actions.js +20 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-block.js +165 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-shell-logic.js +346 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-shell.js +108 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-state.js +49 -3
- package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +40 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-tools-logic.js +20 -5
- package/neural-interface/public/shared/ocp-v2/ocp-v2-tools.js +7 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +7 -2
- package/neural-interface/public/shared/settings/settings-browser-extension.js +54 -12
- package/neural-interface/public/shared/shell-stop-view.js +83 -0
- package/neural-interface/public/shared/tour/tour-actor.js +14 -3
- package/neural-interface/public/shared/tray-auto-close.js +36 -6
- package/neural-interface/public/shared/ui-claude-panel.js +20 -0
- package/neural-interface/public/shared/ui-native-loop-router.js +45 -3
- package/neural-interface/public/shared/ui-scroll-follow.js +4 -0
- package/neural-interface/server.js +249 -35
- package/npm-shrinkwrap.json +5 -5
- package/package.json +1 -2
- package/browser-extension/content.js +0 -231
- package/browser-extension/engine.js +0 -658
- package/browser-extension/icons/icon-128.png +0 -0
- package/browser-extension/icons/icon-16.png +0 -0
- package/browser-extension/icons/icon-32.png +0 -0
- package/browser-extension/icons/icon-48.png +0 -0
- package/browser-extension/icons/status-off-16.png +0 -0
- package/browser-extension/icons/status-off-32.png +0 -0
- package/browser-extension/icons/status-off-48.png +0 -0
- package/browser-extension/icons/status-on-16.png +0 -0
- package/browser-extension/icons/status-on-32.png +0 -0
- package/browser-extension/icons/status-on-48.png +0 -0
- package/browser-extension/manifest.json +0 -58
- package/browser-extension/popup-strings.js +0 -250
- package/browser-extension/popup-view.js +0 -151
- package/browser-extension/popup.css +0 -166
- package/browser-extension/popup.html +0 -108
- package/browser-extension/popup.js +0 -359
- package/browser-extension/service-worker.js +0 -283
- package/browser-extension/setup-content.js +0 -36
- package/browser-extension/tokens.css +0 -326
- /package/{browser-extension/protocol.js → neural-interface/lib/browser-extension-protocol.js} +0 -0
|
@@ -1,231 +0,0 @@
|
|
|
1
|
-
// Isolated world only. No page message relay, eval, cookies, storage or credential access.
|
|
2
|
-
(() => {
|
|
3
|
-
if (globalThis.__synabunBridgeInstalled) return;
|
|
4
|
-
globalThis.__synabunBridgeInstalled = true;
|
|
5
|
-
let generation = crypto.randomUUID().replaceAll('-', ''), documentUrl = location.href;
|
|
6
|
-
const uploadParts = new Map();
|
|
7
|
-
const refs = new Map(), ids = new WeakMap(); let serial = 0, navigation = null;
|
|
8
|
-
function invalidate() { refs.clear(); generation = crypto.randomUUID().replaceAll('-', ''); documentUrl = location.href; }
|
|
9
|
-
globalThis.addEventListener?.('pageshow', event => { if (event.persisted) invalidate(); });
|
|
10
|
-
const error = code => { throw Object.assign(new Error(code), { code }); };
|
|
11
|
-
const removed = records => {
|
|
12
|
-
for (const r of records) for (const node of r.removedNodes) {
|
|
13
|
-
for (const [ref, el] of refs) if (el === node || node.contains?.(el)) refs.delete(ref);
|
|
14
|
-
}
|
|
15
|
-
};
|
|
16
|
-
const observer = new MutationObserver(removed);
|
|
17
|
-
observer.observe(document, { childList: true, subtree: true });
|
|
18
|
-
// Uploads stay in the approved origin. Open shadow roots and same-origin frames can own hidden inputs.
|
|
19
|
-
function uploadMatches(selector) {
|
|
20
|
-
const matches = [], roots = [document];
|
|
21
|
-
for (const root of roots) {
|
|
22
|
-
for (const match of root.querySelectorAll(selector)) matches.push(match);
|
|
23
|
-
for (const node of root.querySelectorAll('*')) {
|
|
24
|
-
if (node.shadowRoot) roots.push(node.shadowRoot);
|
|
25
|
-
if (node.localName === 'iframe') {
|
|
26
|
-
const doc = node.contentDocument;
|
|
27
|
-
if (doc && doc.defaultView?.origin === location.origin) roots.push(doc);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
}
|
|
31
|
-
return matches;
|
|
32
|
-
}
|
|
33
|
-
function target(args, active = false, query = selector => document.querySelectorAll(selector)) {
|
|
34
|
-
removed(observer.takeRecords());
|
|
35
|
-
if (args.ref) {
|
|
36
|
-
const el = refs.get(args.ref);
|
|
37
|
-
if (!args.ref.startsWith(`e${generation}_`) || !el?.isConnected) error('STALE_REF');
|
|
38
|
-
return el;
|
|
39
|
-
}
|
|
40
|
-
if (!args.selector && active) return document.activeElement;
|
|
41
|
-
const found = query(args.selector || 'body');
|
|
42
|
-
if (!found.length) error('NO_MATCH');
|
|
43
|
-
if (found.length > 1 && args.nthMatch === undefined) error('AMBIGUOUS_TARGET');
|
|
44
|
-
const el = found[args.nthMatch || 0]; if (!el) error('NO_MATCH'); return el;
|
|
45
|
-
}
|
|
46
|
-
function safeNode(el) {
|
|
47
|
-
if (el?.matches('input[type=password],input[autocomplete=current-password],input[autocomplete=new-password],input[autocomplete=one-time-code]')) error('UNSUPPORTED_IN_EXTENSION_MODE');
|
|
48
|
-
}
|
|
49
|
-
// SynaBun's own addresses (protocol.js controlSurface, repeated here: a content script cannot import). A loopback or
|
|
50
|
-
// unspecified address, localhost, or one of this computer's names, on one of SynaBun's ports; or a public alias.
|
|
51
|
-
const bare = h => String(h || '').toLowerCase().replace(/^\[|\]$/g, '').replace(/\.$/, '');
|
|
52
|
-
function synabunAddress(u, blocked = {}) {
|
|
53
|
-
const host = bare(u.hostname), port = Number(u.port || (u.protocol === 'https:' ? 443 : 80));
|
|
54
|
-
if ((blocked.blockedHosts || []).some(x => bare(x) === host)) return true;
|
|
55
|
-
if (!(blocked.blockedPorts || []).includes(port)) return false;
|
|
56
|
-
return host === 'localhost' || host.endsWith('.localhost') || host === '0.0.0.0' || host === '::' || host === '::1'
|
|
57
|
-
|| /^127\.\d+\.\d+\.\d+$/.test(host) || /^::ffff:(127\.|0\.0\.0\.0$)/.test(host) || /^::ffff:7f[0-9a-f]{2}:/.test(host)
|
|
58
|
-
|| (blocked.selfHosts || []).some(x => bare(x) === host);
|
|
59
|
-
}
|
|
60
|
-
// Where a link or a form may lead. Restricted mode: an approved site only. Full control (`sites` null): any http(s)
|
|
61
|
-
// page but SynaBun's own, and the page's own script links (javascript:, mailto:, tel:); never a browser page.
|
|
62
|
-
function checkedUrl(url, sites, blocked) {
|
|
63
|
-
const u = new URL(url, location.href);
|
|
64
|
-
if (sites === null) {
|
|
65
|
-
if (['javascript:', 'mailto:', 'tel:'].includes(u.protocol)) return;
|
|
66
|
-
if (!['http:', 'https:'].includes(u.protocol)) error('RESTRICTED_PAGE');
|
|
67
|
-
if (synabunAddress(u, blocked)) error('SYNABUN_PAGE_BLOCKED');
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
if (!['http:', 'https:'].includes(u.protocol) || !sites.includes(u.origin) || u.username || u.password) error('SITE_NOT_APPROVED');
|
|
71
|
-
}
|
|
72
|
-
// The page this command runs on is one the mode allows.
|
|
73
|
-
function pageAllowed(sites, blocked) {
|
|
74
|
-
if (sites === null) { if (synabunAddress(new URL(location.href), blocked)) error('SYNABUN_PAGE_BLOCKED'); }
|
|
75
|
-
else if (!sites.includes(location.origin)) error('SITE_NOT_APPROVED');
|
|
76
|
-
}
|
|
77
|
-
const event = (el, name) => el.dispatchEvent(new Event(name, { bubbles: true }));
|
|
78
|
-
function acceptsFile(file, spec) {
|
|
79
|
-
const tokens = (spec || '').toLowerCase().split(',').map(s => s.trim()).filter(Boolean);
|
|
80
|
-
return !tokens.length || tokens.some(token => token === '*/*' || token === file.type ||
|
|
81
|
-
(token.startsWith('.') && file.name.toLowerCase().endsWith(token)) ||
|
|
82
|
-
(token.endsWith('/*') && file.type.startsWith(token.slice(0, -1))));
|
|
83
|
-
}
|
|
84
|
-
function uploadFiles(args, due) {
|
|
85
|
-
const parts = uploadParts.get(args.uploadId);
|
|
86
|
-
uploadParts.delete(args.uploadId);
|
|
87
|
-
if (!args.metadata || args.metadata.length !== args.files.length) error('UPLOAD_METADATA_UNAVAILABLE');
|
|
88
|
-
// Resolve the current input after the last async transfer. Keep selection and dispatch in its realm.
|
|
89
|
-
const el = target(args, false, uploadMatches);
|
|
90
|
-
if (args.ref && el.ownerDocument !== document) error('STALE_REF');
|
|
91
|
-
safeNode(el);
|
|
92
|
-
if (!el.matches('input[type=file]')) error('NO_MATCH');
|
|
93
|
-
if (el.matches(':disabled')) error('UPLOAD_DISABLED');
|
|
94
|
-
if (!el.multiple && args.files.length > 1) error('UPLOAD_MULTIPLE');
|
|
95
|
-
const view = el.ownerDocument.defaultView;
|
|
96
|
-
const transfer = new view.DataTransfer();
|
|
97
|
-
args.files.forEach((name, index) => {
|
|
98
|
-
const { size, type, lastModified } = args.metadata[index];
|
|
99
|
-
const file = new view.File(parts?.[index] || [], name, { type, lastModified });
|
|
100
|
-
if (file.size !== size) error('OPERATION_FAILED');
|
|
101
|
-
if (!acceptsFile(file, el.accept)) error('UPLOAD_ACCEPT_MISMATCH');
|
|
102
|
-
transfer.items.add(file);
|
|
103
|
-
});
|
|
104
|
-
due();
|
|
105
|
-
el.files = transfer.files;
|
|
106
|
-
// Take the receipt before a synchronous change listener consumes the selection or clears the control.
|
|
107
|
-
const files = Array.from(el.files, ({ name, type, size }) => ({ name, type, size }));
|
|
108
|
-
if (files.length !== args.files.length || files.some((file, i) =>
|
|
109
|
-
file.name !== args.files[i] || file.type !== args.metadata[i].type || file.size !== args.metadata[i].size)) error('UPLOAD_ASSIGNMENT_FAILED');
|
|
110
|
-
for (const name of ['input', 'change']) el.dispatchEvent(new view.Event(name, { bubbles: true, composed: true }));
|
|
111
|
-
return files;
|
|
112
|
-
}
|
|
113
|
-
function setValue(el, value) {
|
|
114
|
-
safeNode(el);
|
|
115
|
-
if (el.isContentEditable) el.textContent = value;
|
|
116
|
-
else {
|
|
117
|
-
const prototype = el instanceof HTMLTextAreaElement ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
|
|
118
|
-
const setter = Object.getOwnPropertyDescriptor(prototype, 'value')?.set;
|
|
119
|
-
if (!setter) error('UNSUPPORTED_IN_EXTENSION_MODE'); setter.call(el, value);
|
|
120
|
-
}
|
|
121
|
-
event(el, 'input'); event(el, 'change');
|
|
122
|
-
}
|
|
123
|
-
async function execute({ op, args, sites, blocked, downloads, nav, until }) {
|
|
124
|
-
// A message from before full control carries a site list; one with neither refuses everything.
|
|
125
|
-
if (sites !== null && !Array.isArray(sites)) error('SITE_NOT_APPROVED');
|
|
126
|
-
// The command's deadline as a system-clock time. Checked on arrival and right before every page effect: an action
|
|
127
|
-
// dispatched just before the deadline but delivered (or reached) after it does nothing. A missing one refuses all.
|
|
128
|
-
const due = () => { if (!(typeof until === 'number' && Date.now() < until)) error('TIMEOUT'); };
|
|
129
|
-
due();
|
|
130
|
-
pageAllowed(sites, blocked);
|
|
131
|
-
if (documentUrl !== location.href) invalidate();
|
|
132
|
-
// The engine changes the tab's token on every back/forward. A document that survived the traversal (bfcache, or
|
|
133
|
-
// a same-document entry with the same URL) still gets a new generation, so no earlier ref acts on it.
|
|
134
|
-
if (typeof nav === 'string' && nav !== navigation) { if (navigation !== null) invalidate(); navigation = nav; }
|
|
135
|
-
const state = () => ({ ok: true, url: location.href, title: document.title.slice(0, 1000) });
|
|
136
|
-
if (op === 'snapshot') {
|
|
137
|
-
const root = args.selector ? target(args) : document.body;
|
|
138
|
-
const nodes = [root, ...root.querySelectorAll('a,button,input,textarea,select,[role],[contenteditable],h1,h2,h3,p,li')];
|
|
139
|
-
const lines = []; let size = 0;
|
|
140
|
-
for (const el of nodes.slice(0, 3000)) {
|
|
141
|
-
if (!el.isConnected || el.hidden || !el.getClientRects().length || el.matches('input[type=hidden],input[type=password]')) continue;
|
|
142
|
-
let ref = ids.get(el);
|
|
143
|
-
if (!ref || !refs.has(ref)) { ref = `e${generation}_${++serial}`; ids.set(el, ref); refs.set(ref, el); }
|
|
144
|
-
const role = el.getAttribute('role') || ({ A: 'link', BUTTON: 'button', INPUT: 'textbox', SELECT: 'combobox', TEXTAREA: 'textbox' }[el.tagName]) || el.tagName.toLowerCase();
|
|
145
|
-
const label = (el.getAttribute('aria-label') || el.getAttribute('placeholder') || el.innerText || '').trim().replace(/\s+/g, ' ').slice(0, 300);
|
|
146
|
-
const line = `- ${role} ${JSON.stringify(label)} [ref=${ref}]`;
|
|
147
|
-
if (size + line.length > Math.min(args.maxChars || 30000, 100000)) break;
|
|
148
|
-
size += line.length + 1; lines.push(line);
|
|
149
|
-
}
|
|
150
|
-
return { ...state(), mode: 'ai', snapshotId: generation, snapshotText: lines.join('\n') };
|
|
151
|
-
}
|
|
152
|
-
if (op === 'content') {
|
|
153
|
-
const root = args.selector ? target(args) : document.body;
|
|
154
|
-
const content = (root.innerText || '').slice(args.offset || 0, (args.offset || 0) + Math.min(args.maxChars || 30000, 100000));
|
|
155
|
-
return { ...state(), content, text: content };
|
|
156
|
-
}
|
|
157
|
-
if (op === 'wait') {
|
|
158
|
-
// A wait never runs past the deadline: one that would answers TIMEOUT there (decided up front, so a timer that
|
|
159
|
-
// wakes a fraction of a millisecond early cannot turn it into a success).
|
|
160
|
-
if (!args.selector) {
|
|
161
|
-
const ms = Math.min(args.timeout ?? 1000, 15000), left = until - Date.now();
|
|
162
|
-
await new Promise(r => setTimeout(r, Math.max(0, Math.min(ms, left))));
|
|
163
|
-
if (ms >= left) error('TIMEOUT');
|
|
164
|
-
due(); return state();
|
|
165
|
-
}
|
|
166
|
-
const end = Math.min(Date.now() + Math.min(args.timeout ?? 5000, 15000), until);
|
|
167
|
-
do {
|
|
168
|
-
due(); pageAllowed(sites, blocked);
|
|
169
|
-
const el = args.selector ? document.querySelector(args.selector) : document.body;
|
|
170
|
-
const visible = !!el?.getClientRects().length;
|
|
171
|
-
if ((args.state === 'hidden' || args.state === 'detached') ? !el || !visible : !!el && (args.state === 'attached' || visible)) return state();
|
|
172
|
-
await new Promise(r => setTimeout(r, 100));
|
|
173
|
-
} while (Date.now() < end);
|
|
174
|
-
error('TIMEOUT');
|
|
175
|
-
}
|
|
176
|
-
if (op === 'scroll') {
|
|
177
|
-
const el = args.selector || args.ref ? target(args) : document.scrollingElement;
|
|
178
|
-
const amount = Math.min(args.distance ?? 600, 10000);
|
|
179
|
-
due(); el.scrollBy({ top: ['up', 'down'].includes(args.direction) ? amount * (args.direction === 'up' ? -1 : 1) : 0,
|
|
180
|
-
left: ['left', 'right'].includes(args.direction) ? amount * (args.direction === 'left' ? -1 : 1) : 0, behavior: 'instant' }); return state();
|
|
181
|
-
}
|
|
182
|
-
if (op === 'upload') {
|
|
183
|
-
const files = uploadFiles(args, due);
|
|
184
|
-
return { ...state(), files };
|
|
185
|
-
}
|
|
186
|
-
const el = target(args, ['type', 'press'].includes(op)); safeNode(el);
|
|
187
|
-
if (op === 'click') {
|
|
188
|
-
const link = el.closest('a[href]'); if (link) {
|
|
189
|
-
checkedUrl(link.href, sites, blocked);
|
|
190
|
-
if (link.hasAttribute('download')) {
|
|
191
|
-
if (!downloads) error('PERMISSION_REQUIRED');
|
|
192
|
-
return { ...state(), downloadUrl: link.href };
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
if (el.form) checkedUrl(el.form.action || location.href, sites, blocked);
|
|
196
|
-
due(); el.click();
|
|
197
|
-
} else if (op === 'hover') {
|
|
198
|
-
due(); el.dispatchEvent(new MouseEvent('mouseover', { bubbles: true })); el.dispatchEvent(new MouseEvent('mouseenter'));
|
|
199
|
-
} else if (op === 'fill') { due(); setValue(el, args.value || ''); }
|
|
200
|
-
else if (op === 'type') { due(); el.focus(); setValue(el, (el.isContentEditable ? el.textContent : el.value || '') + (args.text || '')); }
|
|
201
|
-
else if (op === 'select') {
|
|
202
|
-
if (!(el instanceof HTMLSelectElement) || ![...el.options].some(o => o.value === args.value)) error('NO_MATCH');
|
|
203
|
-
due(); el.value = args.value; event(el, 'input'); event(el, 'change');
|
|
204
|
-
} else if (op === 'press') {
|
|
205
|
-
if (!['Enter', 'Escape', 'ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight', 'Tab', 'Backspace', 'Delete'].includes(args.key)) error('UNSUPPORTED_IN_EXTENSION_MODE');
|
|
206
|
-
due(); el.dispatchEvent(new KeyboardEvent('keydown', { key: args.key, bubbles: true }));
|
|
207
|
-
el.dispatchEvent(new KeyboardEvent('keyup', { key: args.key, bubbles: true }));
|
|
208
|
-
} else error('UNSUPPORTED_IN_EXTENSION_MODE');
|
|
209
|
-
return state();
|
|
210
|
-
}
|
|
211
|
-
chrome.runtime.onMessage.addListener((message, sender, respond) => {
|
|
212
|
-
if (sender.id !== chrome.runtime.id) return;
|
|
213
|
-
if (message?.kind === 'synabun-upload-part') {
|
|
214
|
-
const { id, index, data, until } = message;
|
|
215
|
-
if (!(Date.now() < until)) { respond({ ok: false, code: 'TIMEOUT' }); return; }
|
|
216
|
-
if (!uploadParts.has(id)) {
|
|
217
|
-
uploadParts.set(id, []);
|
|
218
|
-
setTimeout(() => uploadParts.delete(id), until - Date.now());
|
|
219
|
-
}
|
|
220
|
-
const parts = uploadParts.get(id);
|
|
221
|
-
const decoded = atob(data);
|
|
222
|
-
const bytes = new Uint8Array(decoded.length);
|
|
223
|
-
for (let i = 0; i < decoded.length; i++) bytes[i] = decoded.charCodeAt(i);
|
|
224
|
-
(parts[index] ||= []).push(bytes);
|
|
225
|
-
respond({ ok: true }); return;
|
|
226
|
-
}
|
|
227
|
-
if (message?.kind !== 'synabun-fixed-command') return;
|
|
228
|
-
execute(message).then(respond, error => respond({ ok: false, code: error.code || 'OPERATION_FAILED' }));
|
|
229
|
-
return true;
|
|
230
|
-
});
|
|
231
|
-
})();
|