synabun 2.4.3 → 2.4.4
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 +19 -0
- package/README.md +1 -1
- package/docs/browser-extension-bridge.md +61 -32
- 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 +11 -1
- package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
- package/mcp-server/dist/services/neural-interface.js +67 -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 +3 -1
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +11 -6
- 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 +65 -18
- package/mcp-server/src/services/typesafe-config.ts +268 -7
- package/mcp-server/src/tools/agents.ts +12 -6
- 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 +139 -0
- package/neural-interface/i18n/pt-BR.json +139 -0
- package/neural-interface/lib/assistant-api.js +90 -0
- 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 +6 -0
- package/neural-interface/lib/assistant-router.js +18 -8
- package/neural-interface/lib/assistant-runtime.js +87 -1
- 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-extension-adapter.js +221 -15
- package/neural-interface/lib/browser-extension-bridge.js +40 -7
- 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 +111 -13
- package/neural-interface/lib/browser-extension-setup.js +7 -5
- 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/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/scheduler.js +3 -2
- 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 +1 -0
- 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 +88 -0
- package/neural-interface/public/shared/cp/cp-bg-tasks.js +130 -0
- package/neural-interface/public/shared/extension-setup/es-page.js +18 -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-browser-extension.js +10 -4
- package/neural-interface/public/shared/settings/settings-extension-update.js +114 -0
- package/neural-interface/public/shared/styles.css +4 -0
- 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-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 +483 -280
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -19,6 +19,7 @@ export const browserSnapshotSchema = {
|
|
|
19
19
|
force: coerceBoolean().optional().describe('Return the full snapshot even if the page is unchanged since your last snapshot.'),
|
|
20
20
|
viewport: coerceBoolean().optional().describe('Drop off-screen nodes (legacy modes only; ignored for mode="ai" — use depth/selector instead).'),
|
|
21
21
|
maxChars: z.coerce.number().int().positive().optional().describe('Cap snapshot text in characters, excluding brief metadata (default 30000). Truncates at complete lines.'),
|
|
22
|
+
offset: z.coerce.number().int().nonnegative().optional().describe('mode="ai", extension backend (SynaBun Browser Bridge 1.5.0+): continue a long snapshot from this character offset (the "pass offset=N" a cut snapshot ends with). To read an article, prefer browser_content format="markdown".'),
|
|
22
23
|
intent: z.string().max(300).optional().describe('What you want to do on this page, in words (e.g. "open account settings"). mode="ai" only: the refs of THIS snapshot are ranked against it and the best one is named in a "Jev target:" line. Advisory — nothing is clicked, and no ref is invented.'),
|
|
23
24
|
format: z.enum(['text', 'json']).optional().describe('Only meaningful with mode="interactive": "json" = compact array.'),
|
|
24
25
|
sessionId: z.string().optional().describe('Browser session ID. If omitted, auto-selects the only open session.'),
|
|
@@ -55,7 +56,8 @@ export function formatAiSnapshotBody(
|
|
|
55
56
|
if (result.snapshotId) {
|
|
56
57
|
body = `Snapshot: ${result.snapshotId}${result.baselineId ? `; baseline: ${result.baselineId}` : ''}\n${body}`;
|
|
57
58
|
}
|
|
58
|
-
if (result.
|
|
59
|
+
if (typeof result.snapshotNextOffset === 'number') body += `\n(truncated — ${result.snapshotTotalChars} chars total, pass offset=${result.snapshotNextOffset} to continue)`;
|
|
60
|
+
else if (result.snapshotTruncated || clientTruncated) body += '\n(truncated; narrow selector/depth or raise maxChars)';
|
|
59
61
|
if (result.aiDepth) body += `\n(depth ${result.aiDepth}; set depth to override)`;
|
|
60
62
|
return body;
|
|
61
63
|
}
|
|
@@ -198,6 +200,7 @@ export async function handleBrowserSnapshot(args: {
|
|
|
198
200
|
force?: boolean;
|
|
199
201
|
viewport?: boolean;
|
|
200
202
|
maxChars?: number;
|
|
203
|
+
offset?: number;
|
|
201
204
|
intent?: string;
|
|
202
205
|
format?: SnapshotFormat;
|
|
203
206
|
sessionId?: string;
|
|
@@ -220,6 +223,7 @@ export async function handleBrowserSnapshot(args: {
|
|
|
220
223
|
baselineId: args.baselineId,
|
|
221
224
|
force: args.force,
|
|
222
225
|
...(mode === 'ai' && { maxChars }),
|
|
226
|
+
...(mode === 'ai' && args.offset !== undefined && { offset: args.offset }),
|
|
223
227
|
// Ranking needs every ref of this capture even when only a diff or "unchanged" is shown.
|
|
224
228
|
...(rank && { includeFullText: true }),
|
|
225
229
|
});
|
|
@@ -229,6 +233,7 @@ export async function handleBrowserSnapshot(args: {
|
|
|
229
233
|
let msg = `Page: ${result.url}\nTitle: "${result.title}"\n`;
|
|
230
234
|
if (args.selector) msg += `Scope: ${args.selector}\n`;
|
|
231
235
|
msg += '\n' + formatAiSnapshotBody(result, maxChars);
|
|
236
|
+
if (args.offset && result.snapshotOffset === undefined) msg += '\n(offset is not supported by this browser backend: the snapshot starts at the top. Narrow it with selector, or read the page with browser_content.)';
|
|
232
237
|
if (rank) {
|
|
233
238
|
// The refs ranked are the ones this capture minted; a second capture would replace them.
|
|
234
239
|
const delivered = typeof result.snapshotFullText === 'string' ? result.snapshotFullText : typeof result.snapshotText === 'string' && !result.snapshotIsDiff ? result.snapshotText : '';
|
|
@@ -479,6 +484,7 @@ const pagedExtractorFields = {
|
|
|
479
484
|
interface PagedArgs { scrolls?: number; minItems?: number; maxItems?: number; fields?: string[]; maxChars?: number; timeoutMs?: number }
|
|
480
485
|
|
|
481
486
|
interface PagedOpts extends PagedArgs {
|
|
487
|
+
extractor?: string; // the extension's fixed reader for this script (EXTENSION_READER_SOURCES)
|
|
482
488
|
dedupeKeys: string[]; // first non-null field is the item identity
|
|
483
489
|
scrollTarget?: string; // JS expression resolving the scroll container (default: window)
|
|
484
490
|
scrollDistance?: number; // default 1200
|
|
@@ -688,7 +694,7 @@ export async function handleBrowserExtractTweets(args: PagedArgs & { sessionId?:
|
|
|
688
694
|
const resolved = await ni.resolveSession(args.sessionId, undefined, args.tabId);
|
|
689
695
|
if ('error' in resolved) return text(resolved.error);
|
|
690
696
|
|
|
691
|
-
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, TWEET_EXTRACTOR_SCRIPT, {
|
|
697
|
+
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, TWEET_EXTRACTOR_SCRIPT, { extractor: 'x.tweets',
|
|
692
698
|
...args, dedupeKeys: ['url'],
|
|
693
699
|
});
|
|
694
700
|
if ('error' in res) return text(`Extract failed: ${res.error}`);
|
|
@@ -766,7 +772,7 @@ export async function handleBrowserExtractFbPosts(args: PagedArgs & { sessionId?
|
|
|
766
772
|
const resolved = await ni.resolveSession(args.sessionId, undefined, args.tabId);
|
|
767
773
|
if ('error' in resolved) return text(resolved.error);
|
|
768
774
|
|
|
769
|
-
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, FB_POST_EXTRACTOR_SCRIPT, {
|
|
775
|
+
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, FB_POST_EXTRACTOR_SCRIPT, { extractor: 'fb.posts',
|
|
770
776
|
...args, dedupeKeys: ['postUrl'], scrollIfEmpty: true,
|
|
771
777
|
});
|
|
772
778
|
if ('error' in res) return text(`Extract failed: ${res.error}`);
|
|
@@ -967,7 +973,7 @@ export async function handleBrowserFbComposerState(args: { sessionId?: string; t
|
|
|
967
973
|
const resolved = await ni.resolveSession(args.sessionId, undefined, args.tabId);
|
|
968
974
|
if ('error' in resolved) return text(resolved.error);
|
|
969
975
|
|
|
970
|
-
const result = await ni.evaluate(resolved.sessionId, FB_COMPOSER_STATE_SCRIPT, resolved.tabId);
|
|
976
|
+
const result = await ni.evaluate(resolved.sessionId, FB_COMPOSER_STATE_SCRIPT, resolved.tabId, { extractor: 'fb.composer_state' });
|
|
971
977
|
if (result.error) return text(`Composer state probe failed: ${result.error}`);
|
|
972
978
|
|
|
973
979
|
// Only when the probe could not decide (unknown state or action, no submit button, or a heuristic match).
|
|
@@ -1050,7 +1056,7 @@ export async function handleBrowserExtractFbGroups(args: PagedArgs & { sessionId
|
|
|
1050
1056
|
|
|
1051
1057
|
// Full-scroll the virtualized joins list, accumulating + deduping by url. Defaults harvest the
|
|
1052
1058
|
// whole list in one call; the caller can override scrolls/maxItems.
|
|
1053
|
-
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, FB_GROUPS_EXTRACTOR_SCRIPT, {
|
|
1059
|
+
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, FB_GROUPS_EXTRACTOR_SCRIPT, { extractor: 'fb.groups',
|
|
1054
1060
|
scrolls: args.scrolls ?? 10,
|
|
1055
1061
|
minItems: args.minItems,
|
|
1056
1062
|
maxItems: args.maxItems ?? 1000,
|
|
@@ -1171,7 +1177,7 @@ export async function handleBrowserExtractTiktokVideos(args: PagedArgs & { sessi
|
|
|
1171
1177
|
const resolved = await ni.resolveSession(args.sessionId, undefined, args.tabId);
|
|
1172
1178
|
if ('error' in resolved) return text(resolved.error);
|
|
1173
1179
|
|
|
1174
|
-
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, TIKTOK_FEED_EXTRACTOR_SCRIPT, {
|
|
1180
|
+
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, TIKTOK_FEED_EXTRACTOR_SCRIPT, { extractor: 'tiktok.feed',
|
|
1175
1181
|
...args, dedupeKeys: ['videoUrl', 'handle'], scrollIfEmpty: true,
|
|
1176
1182
|
});
|
|
1177
1183
|
if ('error' in res) return text(`Extract failed: ${res.error}`);
|
|
@@ -1217,7 +1223,7 @@ export async function handleBrowserExtractTiktokSearch(args: PagedArgs & { sessi
|
|
|
1217
1223
|
const resolved = await ni.resolveSession(args.sessionId, undefined, args.tabId);
|
|
1218
1224
|
if ('error' in resolved) return text(resolved.error);
|
|
1219
1225
|
|
|
1220
|
-
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, TIKTOK_SEARCH_EXTRACTOR_SCRIPT, {
|
|
1226
|
+
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, TIKTOK_SEARCH_EXTRACTOR_SCRIPT, { extractor: 'tiktok.search',
|
|
1221
1227
|
...args, dedupeKeys: ['videoUrl'], scrollIfEmpty: true,
|
|
1222
1228
|
});
|
|
1223
1229
|
if ('error' in res) return text(`Extract failed: ${res.error}`);
|
|
@@ -1265,7 +1271,7 @@ export async function handleBrowserExtractTiktokStudio(args: PagedArgs & { sessi
|
|
|
1265
1271
|
const resolved = await ni.resolveSession(args.sessionId, undefined, args.tabId);
|
|
1266
1272
|
if ('error' in resolved) return text(resolved.error);
|
|
1267
1273
|
|
|
1268
|
-
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, TIKTOK_STUDIO_EXTRACTOR_SCRIPT, {
|
|
1274
|
+
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, TIKTOK_STUDIO_EXTRACTOR_SCRIPT, { extractor: 'tiktok.studio',
|
|
1269
1275
|
...args, dedupeKeys: ['url', 'title'],
|
|
1270
1276
|
});
|
|
1271
1277
|
if ('error' in res) return text(`Extract failed: ${res.error}`);
|
|
@@ -1298,7 +1304,44 @@ const TIKTOK_PROFILE_EXTRACTOR_SCRIPT = `
|
|
|
1298
1304
|
})()
|
|
1299
1305
|
`.trim();
|
|
1300
1306
|
|
|
1307
|
+
// The signed-in account, from what any TikTok or TikTok Studio page shows of it: the navigation's profile link (its
|
|
1308
|
+
// /@handle), the account name next to it, and whether a log-in button is shown instead. Read-only, DOM only.
|
|
1309
|
+
export const TIKTOK_ACCOUNT_SCRIPT = `
|
|
1310
|
+
(() => {
|
|
1311
|
+
const clean = value => (value || '').replace(/\\s+/g, ' ').trim() || null;
|
|
1312
|
+
const handleOf = href => { const m = /\\/@([A-Za-z0-9._-]{1,64})(?:[/?#]|$)/.exec(href || ''); return m ? m[1] : null; };
|
|
1313
|
+
const loginShown = !!document.querySelector('[data-e2e="top-login-button"], [data-e2e="nav-login-button"], #header-login-button, [data-e2e="login-button"]');
|
|
1314
|
+
const candidates = [
|
|
1315
|
+
['nav-profile', document.querySelector('[data-e2e="nav-profile"]')],
|
|
1316
|
+
['profile-icon', document.querySelector('[data-e2e="profile-icon"]')],
|
|
1317
|
+
['studio-header', document.querySelector('header a[href*="/@"], [class*="AccountInfo"] a[href*="/@"], [class*="account-info"] a[href*="/@"]')],
|
|
1318
|
+
['menu', document.querySelector('nav a[href*="/@"], aside a[href*="/@"]')],
|
|
1319
|
+
];
|
|
1320
|
+
let handle = null, source = null, anchor = null;
|
|
1321
|
+
for (const [name, el] of candidates) {
|
|
1322
|
+
const link = el ? (el.matches('a[href]') ? el : el.closest('a[href]') || el.querySelector('a[href]')) : null;
|
|
1323
|
+
const found = handleOf(link ? link.getAttribute('href') : '');
|
|
1324
|
+
if (found) { handle = found; source = name; anchor = link; break; }
|
|
1325
|
+
}
|
|
1326
|
+
const nameEl = anchor && (anchor.querySelector('[data-e2e="nav-profile-name"], [class*="UserName"], [class*="Nickname"]') || null);
|
|
1327
|
+
const avatar = anchor ? anchor.querySelector('img[alt]') : null;
|
|
1328
|
+
const ownProfile = !!document.querySelector('[data-e2e="edit-profile-entrance"], [data-e2e="edit-profile-button"]');
|
|
1329
|
+
const pageHandle = clean(document.querySelector('[data-e2e="user-title"]')?.innerText);
|
|
1330
|
+
return {
|
|
1331
|
+
signedIn: !!handle && !loginShown,
|
|
1332
|
+
handle: handle ? '@' + handle : null,
|
|
1333
|
+
name: clean(nameEl?.innerText) || clean(avatar?.getAttribute('alt')),
|
|
1334
|
+
source,
|
|
1335
|
+
loginShown,
|
|
1336
|
+
onOwnProfile: ownProfile,
|
|
1337
|
+
profileTitle: ownProfile ? pageHandle : null,
|
|
1338
|
+
page: location.origin + location.pathname,
|
|
1339
|
+
};
|
|
1340
|
+
})()
|
|
1341
|
+
`.trim();
|
|
1342
|
+
|
|
1301
1343
|
export const browserExtractTiktokProfileSchema = {
|
|
1344
|
+
signedIn: coerceBoolean().optional().describe('Read the SIGNED-IN account (handle, name, whether a log-in button shows) from any TikTok or TikTok Studio page instead of a profile page. Read-only.'),
|
|
1302
1345
|
sessionId: z.string().optional().describe('Browser session ID. If omitted, auto-selects the only open session.'),
|
|
1303
1346
|
tabId: tabIdField,
|
|
1304
1347
|
};
|
|
@@ -1307,13 +1350,24 @@ export const browserExtractTiktokProfileDescription =
|
|
|
1307
1350
|
'Extract profile info and video grid from a TikTok profile page as structured JSON ' +
|
|
1308
1351
|
'(name, handle, bio, followers, following, likes, videos[{videoUrl, views}]). ' +
|
|
1309
1352
|
'Navigate to tiktok.com/@username first. Scroll down to load more videos in the grid. ' +
|
|
1310
|
-
'Use this to audit a creator profile or collect video URLs for further processing.'
|
|
1353
|
+
'Use this to audit a creator profile or collect video URLs for further processing. ' +
|
|
1354
|
+
'signedIn=true reads which account is signed in instead (an identity check; works on any TikTok page).';
|
|
1311
1355
|
|
|
1312
|
-
export async function handleBrowserExtractTiktokProfile(args: { sessionId?: string; tabId?: string }) {
|
|
1356
|
+
export async function handleBrowserExtractTiktokProfile(args: { signedIn?: boolean; sessionId?: string; tabId?: string }) {
|
|
1313
1357
|
const resolved = await ni.resolveSession(args.sessionId, undefined, args.tabId);
|
|
1314
1358
|
if ('error' in resolved) return text(resolved.error);
|
|
1315
1359
|
|
|
1316
|
-
|
|
1360
|
+
if (args.signedIn) {
|
|
1361
|
+
const account = await ni.evaluate(resolved.sessionId, TIKTOK_ACCOUNT_SCRIPT, resolved.tabId, { extractor: 'tiktok.account' });
|
|
1362
|
+
if (account.error) return text(`Extract failed: ${account.error}`);
|
|
1363
|
+
const value = account.result as Record<string, unknown> | null;
|
|
1364
|
+
if (!value || !value.handle) {
|
|
1365
|
+
return emptyExtraction(resolved, 'browser_extract_tiktok_profile', 'a TikTok page that shows the signed-in account', `No signed-in TikTok account is shown on this page${value?.loginShown ? ' (a log-in button is shown)' : ''}. Open tiktok.com or tiktok.com/tiktokstudio, then retry.`);
|
|
1366
|
+
}
|
|
1367
|
+
return text(`Signed-in account:\n\n${JSON.stringify(value)}`);
|
|
1368
|
+
}
|
|
1369
|
+
|
|
1370
|
+
const result = await ni.evaluate(resolved.sessionId, TIKTOK_PROFILE_EXTRACTOR_SCRIPT, resolved.tabId, { extractor: 'tiktok.profile' });
|
|
1317
1371
|
if (result.error) return text(`Extract failed: ${result.error}`);
|
|
1318
1372
|
|
|
1319
1373
|
const profile = result.result as Record<string, unknown>;
|
|
@@ -1363,9 +1417,9 @@ export async function handleBrowserExtractWaChats(args: PagedArgs & { sessionId?
|
|
|
1363
1417
|
const resolved = await ni.resolveSession(args.sessionId, undefined, args.tabId);
|
|
1364
1418
|
if ('error' in resolved) return text(resolved.error);
|
|
1365
1419
|
|
|
1366
|
-
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, WA_CHATS_EXTRACTOR_SCRIPT, {
|
|
1420
|
+
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, WA_CHATS_EXTRACTOR_SCRIPT, { extractor: 'wa.chats',
|
|
1367
1421
|
...args, dedupeKeys: ['name'],
|
|
1368
|
-
scrollTarget:
|
|
1422
|
+
scrollTarget: WA_CHATS_SCROLL_TARGET,
|
|
1369
1423
|
scrollDistance: 600,
|
|
1370
1424
|
});
|
|
1371
1425
|
if ('error' in res) return text(`Extract failed: ${res.error}`);
|
|
@@ -1413,9 +1467,9 @@ export async function handleBrowserExtractWaMessages(args: PagedArgs & { session
|
|
|
1413
1467
|
const resolved = await ni.resolveSession(args.sessionId, undefined, args.tabId);
|
|
1414
1468
|
if ('error' in resolved) return text(resolved.error);
|
|
1415
1469
|
|
|
1416
|
-
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, WA_MESSAGES_EXTRACTOR_SCRIPT, {
|
|
1470
|
+
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, WA_MESSAGES_EXTRACTOR_SCRIPT, { extractor: 'wa.messages',
|
|
1417
1471
|
...args, dedupeKeys: ['dataId'],
|
|
1418
|
-
scrollTarget:
|
|
1472
|
+
scrollTarget: WA_MESSAGES_SCROLL_TARGET,
|
|
1419
1473
|
scrollDirection: -1, // history loads upward
|
|
1420
1474
|
scrollDistance: 800,
|
|
1421
1475
|
});
|
|
@@ -1465,7 +1519,7 @@ export async function handleBrowserExtractIgFeed(args: PagedArgs & { sessionId?:
|
|
|
1465
1519
|
const resolved = await ni.resolveSession(args.sessionId, undefined, args.tabId);
|
|
1466
1520
|
if ('error' in resolved) return text(resolved.error);
|
|
1467
1521
|
|
|
1468
|
-
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, IG_FEED_EXTRACTOR_SCRIPT, {
|
|
1522
|
+
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, IG_FEED_EXTRACTOR_SCRIPT, { extractor: 'ig.feed',
|
|
1469
1523
|
...args, dedupeKeys: ['postUrl'], scrollIfEmpty: true,
|
|
1470
1524
|
});
|
|
1471
1525
|
if ('error' in res) return text(`Extract failed: ${res.error}`);
|
|
@@ -1528,7 +1582,7 @@ export async function handleBrowserExtractIgProfile(args: { sessionId?: string;
|
|
|
1528
1582
|
const resolved = await ni.resolveSession(args.sessionId, undefined, args.tabId);
|
|
1529
1583
|
if ('error' in resolved) return text(resolved.error);
|
|
1530
1584
|
|
|
1531
|
-
const result = await ni.evaluate(resolved.sessionId, IG_PROFILE_EXTRACTOR_SCRIPT, resolved.tabId);
|
|
1585
|
+
const result = await ni.evaluate(resolved.sessionId, IG_PROFILE_EXTRACTOR_SCRIPT, resolved.tabId, { extractor: 'ig.profile' });
|
|
1532
1586
|
if (result.error) return text(`Extract failed: ${result.error}`);
|
|
1533
1587
|
|
|
1534
1588
|
const profile = result.result as Record<string, unknown>;
|
|
@@ -1605,7 +1659,7 @@ export async function handleBrowserExtractIgPost(args: { sessionId?: string; tab
|
|
|
1605
1659
|
const resolved = await ni.resolveSession(args.sessionId, undefined, args.tabId);
|
|
1606
1660
|
if ('error' in resolved) return text(resolved.error);
|
|
1607
1661
|
|
|
1608
|
-
const result = await ni.evaluate(resolved.sessionId, IG_POST_EXTRACTOR_SCRIPT, resolved.tabId);
|
|
1662
|
+
const result = await ni.evaluate(resolved.sessionId, IG_POST_EXTRACTOR_SCRIPT, resolved.tabId, { extractor: 'ig.post' });
|
|
1609
1663
|
if (result.error) return text(`Extract failed: ${result.error}`);
|
|
1610
1664
|
|
|
1611
1665
|
const post = result.result as Record<string, unknown>;
|
|
@@ -1672,7 +1726,7 @@ export async function handleBrowserExtractIgReels(args: PagedArgs & { sessionId?
|
|
|
1672
1726
|
const resolved = await ni.resolveSession(args.sessionId, undefined, args.tabId);
|
|
1673
1727
|
if ('error' in resolved) return text(resolved.error);
|
|
1674
1728
|
|
|
1675
|
-
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, IG_REELS_EXTRACTOR_SCRIPT, {
|
|
1729
|
+
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, IG_REELS_EXTRACTOR_SCRIPT, { extractor: 'ig.reels',
|
|
1676
1730
|
...args, dedupeKeys: ['profileUrl', 'caption'],
|
|
1677
1731
|
scrollDistance: 900, // reels advance roughly one viewport per scroll
|
|
1678
1732
|
});
|
|
@@ -1709,7 +1763,7 @@ export async function handleBrowserExtractIgSearch(args: PagedArgs & { sessionId
|
|
|
1709
1763
|
const resolved = await ni.resolveSession(args.sessionId, undefined, args.tabId);
|
|
1710
1764
|
if ('error' in resolved) return text(resolved.error);
|
|
1711
1765
|
|
|
1712
|
-
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, IG_SEARCH_EXTRACTOR_SCRIPT, {
|
|
1766
|
+
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, IG_SEARCH_EXTRACTOR_SCRIPT, { extractor: 'ig.search',
|
|
1713
1767
|
...args, dedupeKeys: ['url'], scrollIfEmpty: true,
|
|
1714
1768
|
});
|
|
1715
1769
|
if ('error' in res) return text(`Extract failed: ${res.error}`);
|
|
@@ -1773,7 +1827,7 @@ export async function handleBrowserExtractLiFeed(args: PagedArgs & { sessionId?:
|
|
|
1773
1827
|
const resolved = await ni.resolveSession(args.sessionId, undefined, args.tabId);
|
|
1774
1828
|
if ('error' in resolved) return text(resolved.error);
|
|
1775
1829
|
|
|
1776
|
-
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, LI_FEED_EXTRACTOR_SCRIPT, {
|
|
1830
|
+
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, LI_FEED_EXTRACTOR_SCRIPT, { extractor: 'li.feed',
|
|
1777
1831
|
...args, dedupeKeys: ['postUrl'], scrollIfEmpty: true,
|
|
1778
1832
|
});
|
|
1779
1833
|
if ('error' in res) return text(`Extract failed: ${res.error}`);
|
|
@@ -1829,7 +1883,7 @@ export async function handleBrowserExtractLiProfile(args: { sessionId?: string;
|
|
|
1829
1883
|
const resolved = await ni.resolveSession(args.sessionId, undefined, args.tabId);
|
|
1830
1884
|
if ('error' in resolved) return text(resolved.error);
|
|
1831
1885
|
|
|
1832
|
-
const result = await ni.evaluate(resolved.sessionId, LI_PROFILE_EXTRACTOR_SCRIPT, resolved.tabId);
|
|
1886
|
+
const result = await ni.evaluate(resolved.sessionId, LI_PROFILE_EXTRACTOR_SCRIPT, resolved.tabId, { extractor: 'li.profile' });
|
|
1833
1887
|
if (result.error) return text(`Extract failed: ${result.error}`);
|
|
1834
1888
|
|
|
1835
1889
|
const profile = result.result as Record<string, unknown>;
|
|
@@ -1886,7 +1940,7 @@ export async function handleBrowserExtractLiPost(args: { sessionId?: string; tab
|
|
|
1886
1940
|
const resolved = await ni.resolveSession(args.sessionId, undefined, args.tabId);
|
|
1887
1941
|
if ('error' in resolved) return text(resolved.error);
|
|
1888
1942
|
|
|
1889
|
-
const result = await ni.evaluate(resolved.sessionId, LI_POST_EXTRACTOR_SCRIPT, resolved.tabId);
|
|
1943
|
+
const result = await ni.evaluate(resolved.sessionId, LI_POST_EXTRACTOR_SCRIPT, resolved.tabId, { extractor: 'li.post' });
|
|
1890
1944
|
if (result.error) return text(`Extract failed: ${result.error}`);
|
|
1891
1945
|
|
|
1892
1946
|
const post = result.result as Record<string, unknown>;
|
|
@@ -1928,7 +1982,7 @@ export async function handleBrowserExtractLiNotifications(args: PagedArgs & { se
|
|
|
1928
1982
|
const resolved = await ni.resolveSession(args.sessionId, undefined, args.tabId);
|
|
1929
1983
|
if ('error' in resolved) return text(resolved.error);
|
|
1930
1984
|
|
|
1931
|
-
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, LI_NOTIFICATIONS_EXTRACTOR_SCRIPT, {
|
|
1985
|
+
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, LI_NOTIFICATIONS_EXTRACTOR_SCRIPT, { extractor: 'li.notifications',
|
|
1932
1986
|
...args, dedupeKeys: ['url', 'text'],
|
|
1933
1987
|
});
|
|
1934
1988
|
if ('error' in res) return text(`Extract failed: ${res.error}`);
|
|
@@ -1979,7 +2033,7 @@ export async function handleBrowserExtractLiMessages(args: { sessionId?: string;
|
|
|
1979
2033
|
const resolved = await ni.resolveSession(args.sessionId, undefined, args.tabId);
|
|
1980
2034
|
if ('error' in resolved) return text(resolved.error);
|
|
1981
2035
|
|
|
1982
|
-
const result = await ni.evaluate(resolved.sessionId, LI_MESSAGES_EXTRACTOR_SCRIPT, resolved.tabId);
|
|
2036
|
+
const result = await ni.evaluate(resolved.sessionId, LI_MESSAGES_EXTRACTOR_SCRIPT, resolved.tabId, { extractor: 'li.messages' });
|
|
1983
2037
|
if (result.error) return text(`Extract failed: ${result.error}`);
|
|
1984
2038
|
|
|
1985
2039
|
const data = result.result as Record<string, unknown>;
|
|
@@ -2049,7 +2103,7 @@ export async function handleBrowserExtractLiSearchPeople(args: PagedArgs & { ses
|
|
|
2049
2103
|
const resolved = await ni.resolveSession(args.sessionId, undefined, args.tabId);
|
|
2050
2104
|
if ('error' in resolved) return text(resolved.error);
|
|
2051
2105
|
|
|
2052
|
-
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, LI_SEARCH_PEOPLE_EXTRACTOR_SCRIPT, {
|
|
2106
|
+
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, LI_SEARCH_PEOPLE_EXTRACTOR_SCRIPT, { extractor: 'li.search_people',
|
|
2053
2107
|
...args, dedupeKeys: ['profileUrl'],
|
|
2054
2108
|
});
|
|
2055
2109
|
if ('error' in res) return text(`Extract failed: ${res.error}`);
|
|
@@ -2123,7 +2177,7 @@ export async function handleBrowserExtractLiNetwork(args: { sessionId?: string;
|
|
|
2123
2177
|
const resolved = await ni.resolveSession(args.sessionId, undefined, args.tabId);
|
|
2124
2178
|
if ('error' in resolved) return text(resolved.error);
|
|
2125
2179
|
|
|
2126
|
-
const result = await ni.evaluate(resolved.sessionId, LI_NETWORK_EXTRACTOR_SCRIPT, resolved.tabId);
|
|
2180
|
+
const result = await ni.evaluate(resolved.sessionId, LI_NETWORK_EXTRACTOR_SCRIPT, resolved.tabId, { extractor: 'li.network' });
|
|
2127
2181
|
if (result.error) return text(`Extract failed: ${result.error}`);
|
|
2128
2182
|
|
|
2129
2183
|
const data = result.result as Record<string, unknown>;
|
|
@@ -2252,7 +2306,7 @@ export async function handleBrowserExtractLiJobs(args: PagedArgs & { sessionId?:
|
|
|
2252
2306
|
const resolved = await ni.resolveSession(args.sessionId, undefined, args.tabId);
|
|
2253
2307
|
if ('error' in resolved) return text(resolved.error);
|
|
2254
2308
|
|
|
2255
|
-
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, LI_JOBS_EXTRACTOR_SCRIPT, {
|
|
2309
|
+
const res = await runPagedExtractor(resolved.sessionId, resolved.tabId, LI_JOBS_EXTRACTOR_SCRIPT, { extractor: 'li.jobs',
|
|
2256
2310
|
...args, dedupeKeys: ['jobId', 'jobUrl'], scrollIfEmpty: true,
|
|
2257
2311
|
});
|
|
2258
2312
|
if ('error' in res) return text(`Extract failed: ${res.error}`);
|
|
@@ -2262,3 +2316,38 @@ export async function handleBrowserExtractLiJobs(args: PagedArgs & { sessionId?:
|
|
|
2262
2316
|
|
|
2263
2317
|
return text(formatExtraction('job', res));
|
|
2264
2318
|
}
|
|
2319
|
+
|
|
2320
|
+
// ── The extension backend's fixed readers ──
|
|
2321
|
+
// The extension (SynaBun Browser Bridge) never runs these strings: it ships each one as a fixed function, generated
|
|
2322
|
+
// from this table (scripts/extension/build-browser-readers.mjs → browser-extension/readers-generated.js; a test keeps
|
|
2323
|
+
// the two equal), and runs it by its id in the isolated world. The Playwright backend runs the strings themselves,
|
|
2324
|
+
// unchanged. A scroll target is the expression of the container a paged extractor scrolls (window when absent).
|
|
2325
|
+
export const WA_CHATS_SCROLL_TARGET = `document.querySelector('#pane-side')`;
|
|
2326
|
+
export const WA_MESSAGES_SCROLL_TARGET = SCROLLABLE_ANCESTOR('div.copyable-text[data-pre-plain-text]');
|
|
2327
|
+
|
|
2328
|
+
export const BROWSER_EXTRACTOR_SOURCES: Readonly<Record<string, { script: string; scrollTarget?: string }>> = Object.freeze({
|
|
2329
|
+
'x.tweets': { script: TWEET_EXTRACTOR_SCRIPT },
|
|
2330
|
+
'fb.posts': { script: FB_POST_EXTRACTOR_SCRIPT },
|
|
2331
|
+
'fb.groups': { script: FB_GROUPS_EXTRACTOR_SCRIPT },
|
|
2332
|
+
'fb.composer_state': { script: FB_COMPOSER_STATE_SCRIPT },
|
|
2333
|
+
'tiktok.feed': { script: TIKTOK_FEED_EXTRACTOR_SCRIPT },
|
|
2334
|
+
'tiktok.search': { script: TIKTOK_SEARCH_EXTRACTOR_SCRIPT },
|
|
2335
|
+
'tiktok.studio': { script: TIKTOK_STUDIO_EXTRACTOR_SCRIPT },
|
|
2336
|
+
'tiktok.profile': { script: TIKTOK_PROFILE_EXTRACTOR_SCRIPT },
|
|
2337
|
+
'tiktok.account': { script: TIKTOK_ACCOUNT_SCRIPT },
|
|
2338
|
+
'wa.chats': { script: WA_CHATS_EXTRACTOR_SCRIPT, scrollTarget: WA_CHATS_SCROLL_TARGET },
|
|
2339
|
+
'wa.messages': { script: WA_MESSAGES_EXTRACTOR_SCRIPT, scrollTarget: WA_MESSAGES_SCROLL_TARGET },
|
|
2340
|
+
'ig.feed': { script: IG_FEED_EXTRACTOR_SCRIPT },
|
|
2341
|
+
'ig.profile': { script: IG_PROFILE_EXTRACTOR_SCRIPT },
|
|
2342
|
+
'ig.post': { script: IG_POST_EXTRACTOR_SCRIPT },
|
|
2343
|
+
'ig.reels': { script: IG_REELS_EXTRACTOR_SCRIPT },
|
|
2344
|
+
'ig.search': { script: IG_SEARCH_EXTRACTOR_SCRIPT },
|
|
2345
|
+
'li.feed': { script: LI_FEED_EXTRACTOR_SCRIPT },
|
|
2346
|
+
'li.profile': { script: LI_PROFILE_EXTRACTOR_SCRIPT },
|
|
2347
|
+
'li.post': { script: LI_POST_EXTRACTOR_SCRIPT },
|
|
2348
|
+
'li.notifications': { script: LI_NOTIFICATIONS_EXTRACTOR_SCRIPT },
|
|
2349
|
+
'li.messages': { script: LI_MESSAGES_EXTRACTOR_SCRIPT },
|
|
2350
|
+
'li.search_people': { script: LI_SEARCH_PEOPLE_EXTRACTOR_SCRIPT },
|
|
2351
|
+
'li.network': { script: LI_NETWORK_EXTRACTOR_SCRIPT },
|
|
2352
|
+
'li.jobs': { script: LI_JOBS_EXTRACTOR_SCRIPT },
|
|
2353
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Every script the MCP tools send the browser that the extension backend (SynaBun Browser Bridge) serves with a fixed,
|
|
3
|
+
* read-only function of its own: one table, by reader id. The ids are the extension protocol's READER_IDS
|
|
4
|
+
* (browser-extension/protocol.js) less the page readers the extension writes by hand (page.text, page.html).
|
|
5
|
+
*
|
|
6
|
+
* The extension's functions are GENERATED from this table (`npm run mcp:build`, then
|
|
7
|
+
* `node scripts/extension/build-browser-readers.mjs`), so the Playwright backend and the extension read a page with the
|
|
8
|
+
* same source; tests/browser-readers-sync.test.ts fails when browser-extension/readers-generated.js is not what this
|
|
9
|
+
* table makes. A tool that sends one of these scripts passes its id (`extractor`), which the Playwright backend ignores.
|
|
10
|
+
*/
|
|
11
|
+
import { BROWSER_EXTRACTOR_SOURCES } from './browser-observe.js';
|
|
12
|
+
import { YOUTUBE_READER_SOURCES } from './youtube/readers.js';
|
|
13
|
+
|
|
14
|
+
export interface ReaderSource { script: string; scrollTarget?: string }
|
|
15
|
+
|
|
16
|
+
export const EXTENSION_READER_SOURCES: Readonly<Record<string, ReaderSource>> = Object.freeze({
|
|
17
|
+
...BROWSER_EXTRACTOR_SOURCES,
|
|
18
|
+
...YOUTUBE_READER_SOURCES,
|
|
19
|
+
});
|
|
@@ -199,7 +199,12 @@ export async function handleRemember(args: {
|
|
|
199
199
|
check,
|
|
200
200
|
]);
|
|
201
201
|
} catch (error) {
|
|
202
|
-
|
|
202
|
+
// Another save already holds this key (an automatic run memory, an
|
|
203
|
+
// earlier wording of the same save). Nothing new is stored and nothing
|
|
204
|
+
// failed: point at that memory so the caller can reflect on it.
|
|
205
|
+
if (error instanceof IdempotencyConflict) {
|
|
206
|
+
return text(`Already stored [${error.existingId}] under idempotency_key "${args.idempotency_key}" with other content; no new memory was created. Use \`reflect\` on [${error.existingId}] to add what is new.`);
|
|
207
|
+
}
|
|
203
208
|
throw error;
|
|
204
209
|
}
|
|
205
210
|
const { id, pending } = result;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { z } from 'zod/v3';
|
|
9
9
|
import * as ni from '../../services/neural-interface.js';
|
|
10
10
|
import { text } from '../response.js';
|
|
11
|
-
import { STUDIO_BASE, resolve, ensureAuth, wait, pollFor, safeNavigate, type Resolved } from './helpers.js';
|
|
11
|
+
import { STUDIO_BASE, resolve, ensureAuth, wait, pollFor, STUDIO_CHANNEL_READY_SCRIPT, safeNavigate, type Resolved } from './helpers.js';
|
|
12
12
|
import { channelId } from './navigate.js';
|
|
13
13
|
|
|
14
14
|
const tabId = z.string().optional().describe('Target a specific tab. Auto-resolved if omitted.');
|
|
@@ -50,6 +50,26 @@ export const youtubeChannelSchema = {
|
|
|
50
50
|
export const youtubeChannelDescription =
|
|
51
51
|
'Read channel info or list recent uploads from Studio (browser). Use action=list to dedupe the autopilot against videos already on the channel.';
|
|
52
52
|
|
|
53
|
+
/** The channel's name as Studio shows it (the fixed reader 'youtube.channel_name'). */
|
|
54
|
+
export const CHANNEL_NAME_SCRIPT = `(() => { const el = document.querySelector('#channel-name, #entity-name, ytcp-channel-info'); return el ? (el.textContent || '').trim().slice(0,120) : null; })()`;
|
|
55
|
+
/** Every upload the Studio content grid shows, shadow DOM pierced, in page order, at most 200 (the fixed reader 'youtube.videos'). */
|
|
56
|
+
export const CHANNEL_VIDEOS_SCRIPT = `(() => {
|
|
57
|
+
const byId = new Map();
|
|
58
|
+
const walk = (root) => {
|
|
59
|
+
if (!root) return;
|
|
60
|
+
root.querySelectorAll('*').forEach(el => { if (el.shadowRoot) walk(el.shadowRoot); });
|
|
61
|
+
root.querySelectorAll('a[href*="/video/"]').forEach(a => {
|
|
62
|
+
const m = (a.getAttribute('href') || '').match(/\\/video\\/([A-Za-z0-9_-]{6,})\\//);
|
|
63
|
+
if (!m) return;
|
|
64
|
+
const id = m[1];
|
|
65
|
+
const title = (a.getAttribute('aria-label') || a.textContent || '').trim().slice(0, 200);
|
|
66
|
+
if (title && !byId.has(id)) byId.set(id, title);
|
|
67
|
+
});
|
|
68
|
+
};
|
|
69
|
+
try { walk(document); } catch {}
|
|
70
|
+
return Array.from(byId, ([videoId, title]) => ({ videoId, title })).slice(0, 200);
|
|
71
|
+
})()`;
|
|
72
|
+
|
|
53
73
|
export async function handleYoutubeChannel(args: { action: 'info' | 'list'; limit?: number; sessionId?: string; tabId?: string }) {
|
|
54
74
|
const r = await resolve(args.sessionId, args.tabId);
|
|
55
75
|
if ('error' in r) return text(r.error);
|
|
@@ -59,17 +79,13 @@ export async function handleYoutubeChannel(args: { action: 'info' | 'list'; limi
|
|
|
59
79
|
await safeNavigate(r, STUDIO_BASE);
|
|
60
80
|
const authErr = await ensureAuth(r);
|
|
61
81
|
if (authErr) return text(authErr);
|
|
62
|
-
await pollFor(r,
|
|
82
|
+
await pollFor(r, STUDIO_CHANNEL_READY_SCRIPT, 12000, 400, 'youtube.channel_ready');
|
|
63
83
|
cid = await channelId(r);
|
|
64
84
|
}
|
|
65
85
|
if (!cid) return text('Could not resolve the active channel.');
|
|
66
86
|
|
|
67
87
|
if (args.action === 'info') {
|
|
68
|
-
const nameRes = await ni.evaluate(
|
|
69
|
-
r.sessionId,
|
|
70
|
-
`(() => { const el = document.querySelector('#channel-name, #entity-name, ytcp-channel-info'); return el ? (el.textContent || '').trim().slice(0,120) : null; })()`,
|
|
71
|
-
r.tabId,
|
|
72
|
-
);
|
|
88
|
+
const nameRes = await ni.evaluate(r.sessionId, CHANNEL_NAME_SCRIPT, r.tabId, { extractor: 'youtube.channel_name' });
|
|
73
89
|
return text(JSON.stringify({ channelId: cid, name: (nameRes.result as string) || null, studioUrl: `${STUDIO_BASE}/channel/${cid}` }, null, 2));
|
|
74
90
|
}
|
|
75
91
|
|
|
@@ -81,26 +97,8 @@ export async function handleYoutubeChannel(args: { action: 'info' | 'list'; limi
|
|
|
81
97
|
await wait(1800);
|
|
82
98
|
|
|
83
99
|
const limit = Math.min(Math.max(args.limit || 30, 1), 200);
|
|
84
|
-
const res = await ni.evaluate(
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
const byId = new Map();
|
|
88
|
-
const walk = (root) => {
|
|
89
|
-
if (!root) return;
|
|
90
|
-
root.querySelectorAll('*').forEach(el => { if (el.shadowRoot) walk(el.shadowRoot); });
|
|
91
|
-
root.querySelectorAll('a[href*="/video/"]').forEach(a => {
|
|
92
|
-
const m = (a.getAttribute('href') || '').match(/\\/video\\/([A-Za-z0-9_-]{6,})\\//);
|
|
93
|
-
if (!m) return;
|
|
94
|
-
const id = m[1];
|
|
95
|
-
const title = (a.getAttribute('aria-label') || a.textContent || '').trim().slice(0, 200);
|
|
96
|
-
if (title && !byId.has(id)) byId.set(id, title);
|
|
97
|
-
});
|
|
98
|
-
};
|
|
99
|
-
try { walk(document); } catch {}
|
|
100
|
-
return Array.from(byId, ([videoId, title]) => ({ videoId, title })).slice(0, ${limit});
|
|
101
|
-
})()`,
|
|
102
|
-
r.tabId,
|
|
103
|
-
);
|
|
104
|
-
const videos = (res.result as Array<{ videoId: string; title: string }>) || [];
|
|
100
|
+
const res = await ni.evaluate(r.sessionId, CHANNEL_VIDEOS_SCRIPT, r.tabId, { extractor: 'youtube.videos' });
|
|
101
|
+
// The script lists every upload the grid shows (at most 200, in page order); the limit is applied here.
|
|
102
|
+
const videos = (Array.isArray(res.result) ? res.result as Array<{ videoId: string; title: string }> : []).slice(0, limit);
|
|
105
103
|
return text(JSON.stringify({ channelId: cid, count: videos.length, videos }, null, 2));
|
|
106
104
|
}
|
|
@@ -31,9 +31,14 @@ export async function resolve(
|
|
|
31
31
|
return { sessionId: r.sessionId, tabId: r.tabId };
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
+
/** The page's address. In the extension backend the fixed reader 'page.url' answers it (no page script). */
|
|
35
|
+
export const PAGE_URL_SCRIPT = `location.href`;
|
|
36
|
+
/** Studio redirected to /channel/<UC…>: the active channel resolved (the fixed reader 'youtube.channel_ready'). */
|
|
37
|
+
export const STUDIO_CHANNEL_READY_SCRIPT = `(() => /\\/channel\\/UC/.test(location.href) ? true : null)()`;
|
|
38
|
+
|
|
34
39
|
/** Returns an error string if the session is bounced to a Google sign-in page. */
|
|
35
40
|
export async function ensureAuth(r: Resolved): Promise<string | null> {
|
|
36
|
-
const res = await ni.evaluate(r.sessionId,
|
|
41
|
+
const res = await ni.evaluate(r.sessionId, PAGE_URL_SCRIPT, r.tabId, { extractor: 'page.url' });
|
|
37
42
|
const url = String(res.result || '');
|
|
38
43
|
if (/accounts\.google\.com|\/signin|ServiceLogin/i.test(url)) {
|
|
39
44
|
return 'Not authenticated. Sign into the YouTube/Google account that owns the channel in the open browser panel, then retry.';
|
|
@@ -50,11 +55,12 @@ export async function pollFor<T = unknown>(
|
|
|
50
55
|
script: string,
|
|
51
56
|
timeoutMs = 30000,
|
|
52
57
|
interval = 400,
|
|
58
|
+
extractor?: string,
|
|
53
59
|
): Promise<T | null> {
|
|
54
60
|
const start = Date.now();
|
|
55
61
|
let last: T | null = null;
|
|
56
62
|
while (Date.now() - start < timeoutMs) {
|
|
57
|
-
const res = await ni.evaluate(r.sessionId, script, r.tabId);
|
|
63
|
+
const res = await ni.evaluate(r.sessionId, script, r.tabId, extractor ? { extractor } : undefined);
|
|
58
64
|
if (!res.error) {
|
|
59
65
|
const v = res.result as T;
|
|
60
66
|
if (v) return v;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
import { z } from 'zod/v3';
|
|
9
9
|
import * as ni from '../../services/neural-interface.js';
|
|
10
10
|
import { text } from '../response.js';
|
|
11
|
-
import { STUDIO_BASE, resolve, ensureAuth, wait, pollFor, safeNavigate, type Resolved } from './helpers.js';
|
|
11
|
+
import { STUDIO_BASE, resolve, ensureAuth, wait, pollFor, STUDIO_CHANNEL_READY_SCRIPT, safeNavigate, type Resolved } from './helpers.js';
|
|
12
12
|
|
|
13
13
|
const tabId = z.string().optional().describe('Target a specific tab. Auto-resolved if omitted.');
|
|
14
14
|
|
|
@@ -27,13 +27,12 @@ const SECTION_PATH: Record<Section, string> = {
|
|
|
27
27
|
customization: '/editing/channel',
|
|
28
28
|
};
|
|
29
29
|
|
|
30
|
+
/** The active Studio channel id (UC…) from the URL, if present (the fixed reader 'youtube.channel_id'). */
|
|
31
|
+
export const CHANNEL_ID_SCRIPT = `(() => { const m = location.href.match(/\\/channel\\/(UC[\\w-]+)/); return m ? m[1] : null; })()`;
|
|
32
|
+
|
|
30
33
|
/** Read the active Studio channel id (UC…) from the URL, if present. */
|
|
31
34
|
export async function channelId(r: Resolved): Promise<string | null> {
|
|
32
|
-
const res = await ni.evaluate(
|
|
33
|
-
r.sessionId,
|
|
34
|
-
`(() => { const m = location.href.match(/\\/channel\\/(UC[\\w-]+)/); return m ? m[1] : null; })()`,
|
|
35
|
-
r.tabId,
|
|
36
|
-
);
|
|
35
|
+
const res = await ni.evaluate(r.sessionId, CHANNEL_ID_SCRIPT, r.tabId, { extractor: 'youtube.channel_id' });
|
|
37
36
|
if (res.error) return null;
|
|
38
37
|
return (res.result as string | null) || null;
|
|
39
38
|
}
|
|
@@ -64,7 +63,7 @@ export async function handleYoutubeNavigate(args: { section: Section; sessionId?
|
|
|
64
63
|
if (nav.error) return text(`Navigation failed: ${nav.error}`);
|
|
65
64
|
const authErr = await ensureAuth(r);
|
|
66
65
|
if (authErr) return text(authErr);
|
|
67
|
-
await pollFor(r,
|
|
66
|
+
await pollFor(r, STUDIO_CHANNEL_READY_SCRIPT, 15000, 400, 'youtube.channel_ready');
|
|
68
67
|
cid = await channelId(r);
|
|
69
68
|
}
|
|
70
69
|
if (!cid) return text('Could not resolve the active channel. Make sure you are signed into a Google account that owns a YouTube channel.');
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { z } from 'zod/v3';
|
|
8
8
|
import * as ni from '../../services/neural-interface.js';
|
|
9
9
|
import { text } from '../response.js';
|
|
10
|
-
import { STUDIO_BASE, resolve, ensureAuth, wait, pollFor, safeNavigate, clickStudio, fillStudio, DEEP_TEXT_SCRIPT, type Resolved } from './helpers.js';
|
|
10
|
+
import { STUDIO_BASE, resolve, ensureAuth, wait, pollFor, STUDIO_CHANNEL_READY_SCRIPT, safeNavigate, clickStudio, fillStudio, DEEP_TEXT_SCRIPT, type Resolved } from './helpers.js';
|
|
11
11
|
import { channelId } from './navigate.js';
|
|
12
12
|
|
|
13
13
|
const tabId = z.string().optional().describe('Target a specific tab. Auto-resolved if omitted.');
|
|
@@ -28,7 +28,7 @@ async function gotoPlaylists(r: Resolved): Promise<string | null> {
|
|
|
28
28
|
let cid = await channelId(r);
|
|
29
29
|
if (!cid) {
|
|
30
30
|
await safeNavigate(r, STUDIO_BASE);
|
|
31
|
-
await pollFor(r,
|
|
31
|
+
await pollFor(r, STUDIO_CHANNEL_READY_SCRIPT, 12000, 400, 'youtube.channel_ready');
|
|
32
32
|
cid = await channelId(r);
|
|
33
33
|
}
|
|
34
34
|
if (!cid) return 'Could not resolve the active channel.';
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The read-only scripts of the YouTube Studio tools that the extension backend serves with fixed readers
|
|
3
|
+
* (../browser-readers.ts). The Playwright backend runs the strings; the extension runs the functions generated from them.
|
|
4
|
+
*/
|
|
5
|
+
import { PAGE_URL_SCRIPT, STUDIO_CHANNEL_READY_SCRIPT } from './helpers.js';
|
|
6
|
+
import { CHANNEL_ID_SCRIPT } from './navigate.js';
|
|
7
|
+
import { CHANNEL_NAME_SCRIPT, CHANNEL_VIDEOS_SCRIPT } from './analytics.js';
|
|
8
|
+
|
|
9
|
+
export const YOUTUBE_READER_SOURCES: Readonly<Record<string, { script: string }>> = Object.freeze({
|
|
10
|
+
'page.url': { script: PAGE_URL_SCRIPT },
|
|
11
|
+
'youtube.channel_id': { script: CHANNEL_ID_SCRIPT },
|
|
12
|
+
'youtube.channel_ready': { script: STUDIO_CHANNEL_READY_SCRIPT },
|
|
13
|
+
'youtube.channel_name': { script: CHANNEL_NAME_SCRIPT },
|
|
14
|
+
'youtube.videos': { script: CHANNEL_VIDEOS_SCRIPT },
|
|
15
|
+
});
|