synabun 2.2.2 → 2.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +26 -0
- package/README.md +1 -1
- package/docs/whatsapp.md +52 -20
- package/lib/mcp-build.js +519 -0
- package/lib/mcp-dist.js +10 -4
- package/lib/server-supervisor.js +7 -1
- package/lib/virustotal.mjs +4 -2
- package/mcp-server/dist/http.d.ts +38 -0
- package/mcp-server/dist/http.d.ts.map +1 -1
- package/mcp-server/dist/http.js +75 -7
- package/mcp-server/dist/http.js.map +1 -1
- package/mcp-server/dist/services/browser-route-flow.d.ts +3 -2
- package/mcp-server/dist/services/browser-route-flow.d.ts.map +1 -1
- package/mcp-server/dist/services/browser-route-flow.js +4 -3
- package/mcp-server/dist/services/browser-route-flow.js.map +1 -1
- package/mcp-server/dist/services/embedding-service.d.ts.map +1 -1
- package/mcp-server/dist/services/embedding-service.js +2 -1
- package/mcp-server/dist/services/embedding-service.js.map +1 -1
- package/mcp-server/dist/services/neural-interface.d.ts +21 -0
- package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
- package/mcp-server/dist/services/neural-interface.js +76 -4
- package/mcp-server/dist/services/neural-interface.js.map +1 -1
- package/mcp-server/dist/services/tool-catalog.js +2 -2
- package/mcp-server/dist/services/tool-catalog.js.map +1 -1
- package/mcp-server/dist/tools/agents.d.ts +3 -2
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +6 -4
- package/mcp-server/dist/tools/agents.js.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts +3 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.js +30 -8
- package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
- package/mcp-server/dist/tools/browser-navigate.d.ts +3 -3
- package/mcp-server/dist/tools/browser-navigate.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-navigate.js +19 -16
- package/mcp-server/dist/tools/browser-navigate.js.map +1 -1
- package/mcp-server/dist/tools/browser-observe.d.ts +2 -1
- package/mcp-server/dist/tools/browser-observe.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-observe.js +61 -20
- package/mcp-server/dist/tools/browser-observe.js.map +1 -1
- package/mcp-server/dist/tools/morelogin.d.ts +13 -3
- package/mcp-server/dist/tools/morelogin.d.ts.map +1 -1
- package/mcp-server/dist/tools/morelogin.js +81 -20
- package/mcp-server/dist/tools/morelogin.js.map +1 -1
- package/mcp-server/dist/tools/youtube/upload.d.ts.map +1 -1
- package/mcp-server/dist/tools/youtube/upload.js +225 -88
- package/mcp-server/dist/tools/youtube/upload.js.map +1 -1
- package/mcp-server/package-lock.json +2 -2
- package/mcp-server/package.json +1 -1
- package/mcp-server/src/http.ts +79 -7
- package/mcp-server/src/services/browser-route-flow.ts +4 -3
- package/mcp-server/src/services/embedding-service.ts +2 -1
- package/mcp-server/src/services/neural-interface.ts +77 -4
- package/mcp-server/src/services/tool-catalog.ts +2 -2
- package/mcp-server/src/tools/agents.ts +8 -4
- package/mcp-server/src/tools/browser-advanced.ts +29 -8
- package/mcp-server/src/tools/browser-navigate.ts +19 -16
- package/mcp-server/src/tools/browser-observe.ts +62 -20
- package/mcp-server/src/tools/morelogin.ts +81 -20
- package/mcp-server/src/tools/youtube/upload.ts +218 -99
- package/neural-interface/i18n/en.json +631 -123
- package/neural-interface/i18n/pt-BR.json +518 -10
- package/neural-interface/lib/assistant-api.js +26 -0
- package/neural-interface/lib/assistant-brains/claude.js +5 -0
- package/neural-interface/lib/assistant-catalog.js +114 -1
- package/neural-interface/lib/assistant-dispatch.js +71 -1
- package/neural-interface/lib/assistant-persona.js +14 -7
- package/neural-interface/lib/assistant-router.js +6 -4
- package/neural-interface/lib/assistant-runtime.js +3 -0
- package/neural-interface/lib/assistant-task-prompt.js +5 -0
- package/neural-interface/lib/automation-approval.js +249 -0
- package/neural-interface/lib/automation-browser-owner-access.js +82 -0
- package/neural-interface/lib/backup-service.js +16 -1
- package/neural-interface/lib/browser-background-tab.js +72 -3
- package/neural-interface/lib/browser-extraction.js +106 -45
- package/neural-interface/lib/browser-profile-choices.js +143 -0
- package/neural-interface/lib/browser-profiles.js +142 -0
- package/neural-interface/lib/browser-tab-recovery.js +153 -0
- package/neural-interface/lib/browser-tool-policy.js +2 -0
- package/neural-interface/lib/chromium-on-device-model.js +67 -0
- package/neural-interface/lib/claude-agent-bridge.js +7 -4
- package/neural-interface/lib/claude-model-catalog.js +12 -0
- package/neural-interface/lib/effort-levels.js +28 -2
- package/neural-interface/lib/local-profile-proxy.js +362 -0
- package/neural-interface/lib/local-profiles.js +929 -0
- package/neural-interface/lib/loop-logger.js +25 -4
- package/neural-interface/lib/maritaca/api.js +179 -0
- package/neural-interface/lib/maritaca/attachments.js +44 -0
- package/neural-interface/lib/maritaca/client.js +362 -0
- package/neural-interface/lib/maritaca/key-store.js +122 -0
- package/neural-interface/lib/maritaca/models.js +181 -0
- package/neural-interface/lib/maritaca/modes.js +39 -0
- package/neural-interface/lib/maritaca/opencode-proxy.js +236 -0
- package/neural-interface/lib/maritaca/opencode-stream.js +345 -0
- package/neural-interface/lib/maritaca/opencode.js +218 -0
- package/neural-interface/lib/maritaca/panel-bridge.js +273 -0
- package/neural-interface/lib/maritaca/sessions.js +198 -0
- package/neural-interface/lib/morelogin-agent-profiles.js +149 -0
- package/neural-interface/lib/morelogin.js +278 -14
- package/neural-interface/lib/native-loop-providers.js +3 -1
- package/neural-interface/lib/owner-authority.js +30 -12
- package/neural-interface/lib/page-session.js +43 -17
- package/neural-interface/lib/request-gate.js +2 -0
- package/neural-interface/lib/system-activity.js +1 -1
- package/neural-interface/lib/terminal-tokens.js +82 -5
- package/neural-interface/package-lock.json +3 -2
- package/neural-interface/package.json +2 -1
- package/neural-interface/public/assets/mascot/README.md +11 -0
- package/neural-interface/public/assets/mascot/ask.gif +0 -0
- package/neural-interface/public/assets/mascot/ask.png +0 -0
- package/neural-interface/public/assets/mascot/blocked.gif +0 -0
- package/neural-interface/public/assets/mascot/blocked.png +0 -0
- package/neural-interface/public/assets/mascot/budget.gif +0 -0
- package/neural-interface/public/assets/mascot/budget.png +0 -0
- package/neural-interface/public/assets/mascot/computer.gif +0 -0
- package/neural-interface/public/assets/mascot/computer.png +0 -0
- package/neural-interface/public/assets/mascot/edit.gif +0 -0
- package/neural-interface/public/assets/mascot/edit.png +0 -0
- package/neural-interface/public/assets/mascot/error.gif +0 -0
- package/neural-interface/public/assets/mascot/error.png +0 -0
- package/neural-interface/public/assets/mascot/hover-attention.gif +0 -0
- package/neural-interface/public/assets/mascot/hover-attention.png +0 -0
- package/neural-interface/public/assets/mascot/idle-hero.gif +0 -0
- package/neural-interface/public/assets/mascot/idle-hero.png +0 -0
- package/neural-interface/public/assets/mascot/idle.gif +0 -0
- package/neural-interface/public/assets/mascot/idle.png +0 -0
- package/neural-interface/public/assets/mascot/manifest.json +254 -0
- package/neural-interface/public/assets/mascot/mcp.gif +0 -0
- package/neural-interface/public/assets/mascot/mcp.png +0 -0
- package/neural-interface/public/assets/mascot/memory.gif +0 -0
- package/neural-interface/public/assets/mascot/memory.png +0 -0
- package/neural-interface/public/assets/mascot/offline.gif +0 -0
- package/neural-interface/public/assets/mascot/offline.png +0 -0
- package/neural-interface/public/assets/mascot/pick.gif +0 -0
- package/neural-interface/public/assets/mascot/pick.png +0 -0
- package/neural-interface/public/assets/mascot/plan.gif +0 -0
- package/neural-interface/public/assets/mascot/plan.png +0 -0
- package/neural-interface/public/assets/mascot/present.gif +0 -0
- package/neural-interface/public/assets/mascot/present.png +0 -0
- package/neural-interface/public/assets/mascot/project.gif +0 -0
- package/neural-interface/public/assets/mascot/project.png +0 -0
- package/neural-interface/public/assets/mascot/read.gif +0 -0
- package/neural-interface/public/assets/mascot/read.png +0 -0
- package/neural-interface/public/assets/mascot/runs.gif +0 -0
- package/neural-interface/public/assets/mascot/runs.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/automation.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/automation.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/browser.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/browser.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/code.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/code.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/complex.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/complex.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/computer.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/computer.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/design.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/design.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/edit.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/edit.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/generic.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/generic.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/image_gen.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/image_gen.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/manifest.json +173 -0
- package/neural-interface/public/assets/mascot/scenes/memory.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/memory.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/quick.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/quick.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/read.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/read.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/research.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/research.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/review.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/review.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/search.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/search.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/shell.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/shell.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/thinking.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/thinking.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/video_gen.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/video_gen.png +0 -0
- package/neural-interface/public/assets/mascot/scenes/web.gif +0 -0
- package/neural-interface/public/assets/mascot/scenes/web.png +0 -0
- package/neural-interface/public/assets/mascot/search.gif +0 -0
- package/neural-interface/public/assets/mascot/search.png +0 -0
- package/neural-interface/public/assets/mascot/shell.gif +0 -0
- package/neural-interface/public/assets/mascot/shell.png +0 -0
- package/neural-interface/public/assets/mascot/skill.gif +0 -0
- package/neural-interface/public/assets/mascot/skill.png +0 -0
- package/neural-interface/public/assets/mascot/sleep.gif +0 -0
- package/neural-interface/public/assets/mascot/sleep.png +0 -0
- package/neural-interface/public/assets/mascot/subagent.gif +0 -0
- package/neural-interface/public/assets/mascot/subagent.png +0 -0
- package/neural-interface/public/assets/mascot/success.gif +0 -0
- package/neural-interface/public/assets/mascot/success.png +0 -0
- package/neural-interface/public/assets/mascot/think.gif +0 -0
- package/neural-interface/public/assets/mascot/think.png +0 -0
- package/neural-interface/public/assets/mascot/wait.gif +0 -0
- package/neural-interface/public/assets/mascot/wait.png +0 -0
- package/neural-interface/public/assets/mascot/watch.gif +0 -0
- package/neural-interface/public/assets/mascot/watch.png +0 -0
- package/neural-interface/public/assets/mascot/web.gif +0 -0
- package/neural-interface/public/assets/mascot/web.png +0 -0
- package/neural-interface/public/onboarding.html +14 -1
- package/neural-interface/public/shared/agent-runtime-options.js +49 -8
- package/neural-interface/public/shared/agy/agy-panel.js +2 -2
- package/neural-interface/public/shared/api.js +4 -4
- package/neural-interface/public/shared/assistant/asst-ask-styles.js +8 -8
- package/neural-interface/public/shared/assistant/asst-ask.js +1 -1
- package/neural-interface/public/shared/assistant/asst-brain-picker.js +99 -9
- package/neural-interface/public/shared/assistant/asst-control.js +1 -1
- package/neural-interface/public/shared/assistant/asst-limit-wait.js +4 -4
- package/neural-interface/public/shared/assistant/asst-panel.js +6 -2
- package/neural-interface/public/shared/assistant/asst-rack-styles.js +4 -4
- package/neural-interface/public/shared/assistant/asst-render.js +6 -6
- package/neural-interface/public/shared/assistant/asst-route-models.js +64 -4
- package/neural-interface/public/shared/assistant/asst-route.js +24 -7
- package/neural-interface/public/shared/assistant/asst-routes-editor.js +154 -39
- package/neural-interface/public/shared/assistant/asst-run-stage.js +3 -3
- package/neural-interface/public/shared/assistant/asst-scene-styles.js +8 -111
- package/neural-interface/public/shared/assistant/asst-scenes.js +46 -318
- package/neural-interface/public/shared/assistant/asst-sidepanel.js +2 -2
- package/neural-interface/public/shared/assistant/asst-state.js +72 -2
- package/neural-interface/public/shared/assistant/asst-styles.js +58 -14
- package/neural-interface/public/shared/automation-approval-view.js +75 -0
- package/neural-interface/public/shared/cdx/cdx-panel.js +2 -2
- package/neural-interface/public/shared/context-menu-model.js +2 -0
- package/neural-interface/public/shared/editor/editor-panel-logic.js +10 -0
- package/neural-interface/public/shared/editor/editor-panel.js +10 -2
- package/neural-interface/public/shared/html-shell.js +30 -22
- package/neural-interface/public/shared/morelogin-profile-choices.js +107 -0
- package/neural-interface/public/shared/morelogin-profile-field.js +186 -0
- package/neural-interface/public/shared/mtc/mtc-client.js +181 -0
- package/neural-interface/public/shared/mtc/mtc-compose.js +40 -0
- package/neural-interface/public/shared/mtc/mtc-copy.js +253 -0
- package/neural-interface/public/shared/mtc/mtc-logic.js +478 -0
- package/neural-interface/public/shared/mtc/mtc-panel.js +1354 -0
- package/neural-interface/public/shared/mtc/mtc-render.js +172 -0
- package/neural-interface/public/shared/mtc/mtc-styles.js +437 -0
- package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +6 -2
- package/neural-interface/public/shared/provider-icons.js +3 -0
- package/neural-interface/public/shared/schedules-view.js +7 -0
- package/neural-interface/public/shared/server-back.js +50 -0
- package/neural-interface/public/shared/settings/settings-browser-owner-access.js +72 -0
- package/neural-interface/public/shared/settings/settings-data.js +1 -0
- package/neural-interface/public/shared/settings/settings-ia.js +3 -1
- package/neural-interface/public/shared/settings/settings-local-profiles.js +153 -0
- package/neural-interface/public/shared/settings/settings-maritaca-opencode.js +105 -0
- package/neural-interface/public/shared/sidepanel-session-status.js +16 -2
- package/neural-interface/public/shared/state.js +1 -1
- package/neural-interface/public/shared/styles.css +356 -157
- package/neural-interface/public/shared/synabun-mascot-assets.js +67 -0
- package/neural-interface/public/shared/synabun-mascot.js +136 -12
- package/neural-interface/public/shared/synabun-ticker.js +3 -0
- package/neural-interface/public/shared/topright-overflow-logic.js +1 -0
- package/neural-interface/public/shared/ui-automation-approval.js +188 -0
- package/neural-interface/public/shared/ui-automation-studio.js +130 -90
- package/neural-interface/public/shared/ui-claude-panel.js +50 -2
- package/neural-interface/public/shared/ui-maritaca-panel.js +15 -0
- package/neural-interface/public/shared/ui-navbar.js +17 -0
- package/neural-interface/public/shared/ui-panels.js +3 -1
- package/neural-interface/public/shared/ui-schedules-studio.js +118 -17
- package/neural-interface/public/shared/ui-scroll-follow.js +3 -0
- package/neural-interface/public/shared/ui-settings.js +590 -27
- package/neural-interface/public/shared/ui-sidepanel-session-entry.js +8 -2
- package/neural-interface/public/shared/ui-sidepanel-sessions.js +3 -3
- package/neural-interface/public/shared/ui-sidepanel-tray.js +24 -0
- package/neural-interface/public/shared/ui-sidepanel-windows.js +1 -1
- package/neural-interface/scripts/build-mascot-assets.mjs +30 -0
- package/neural-interface/server.js +1784 -195
- package/npm-shrinkwrap.json +5 -17
- package/package.json +5 -6
- package/postinstall.js +38 -39
- package/setup.js +33 -31
- package/skills/synabun/modules/changelog.md +14 -0
|
@@ -8,31 +8,61 @@ import { text } from './response.js';
|
|
|
8
8
|
// ═══════════════════════════════════════════
|
|
9
9
|
|
|
10
10
|
export const moreloginSchema = {
|
|
11
|
-
action: z.enum(['status', 'list', 'create', 'start', 'stop', 'use_default']).describe(
|
|
12
|
-
'MoreLogin action. "status" = installed/running
|
|
11
|
+
action: z.enum(['status', 'list', 'create', 'start', 'stop', 'use', 'use_default']).describe(
|
|
12
|
+
'MoreLogin action. "status" = installed/running, the default profile and the profile you work in. "list" = browser profiles (environments). "create" = new profile. "use" = work in a profile yourself: from now on YOUR browser_* tools (with or without session and tab ids) open and drive pages in that profile, in a tab of your own; nobody else moves, and it works while other automations use the default or any other profile. Pass envId or name; envId "default" goes back to the default profile. Your next browser call opens your tab there (the profile is started then) and your tab in the profile you left is closed. Only a profile the owner allowed agents to choose can be used ("list" and "status" say which; none is allowed until the owner switches one on): a refusal with MORELOGIN_PROFILE_NOT_ALLOWED means the profile is not on the owner\'s list, so tell the user to switch it on in SynaBun → Settings → Connected tools → MoreLogin → MoreLogin profiles → "Agents may choose" and stop; never use another profile or browser instead. The same list holds for "start": it is refused with MORELOGIN_PROFILE_NOT_ALLOWED for a profile that is not on it. "start"/"stop" = launch/close a profile without working in it (stop closes every tab in that browser: you may stop only a profile you started or have a tab in, and never while other automations have a tab in it). "use_default" is always refused: the default AI browser is the owner\'s choice (Settings → Browser); to work in another profile, call "use". "use" works for any session of SynaBun\'s MCP that proves its id: a run SynaBun started, a side panel, or a CLI window\'s own session of SynaBun\'s HTTP MCP. "start" is for a run SynaBun started; the owner does the rest in Settings → Browser.'
|
|
13
13
|
),
|
|
14
14
|
envId: z.string().optional().describe(
|
|
15
|
-
'MoreLogin environment
|
|
15
|
+
'Profile id (a MoreLogin environment id, or a local profile id that starts with "lp-"): required for start and stop; for "use" pass it or name ("default" = back to the default profile). Get ids from the "list" action.'
|
|
16
16
|
),
|
|
17
17
|
name: z.string().optional().describe(
|
|
18
|
-
'
|
|
18
|
+
'A profile name: the profile to work in ("use" action, as "list" shows it), or the name of a new profile ("create", default "SynaBun").'
|
|
19
19
|
),
|
|
20
20
|
};
|
|
21
21
|
|
|
22
22
|
export const moreloginDescription =
|
|
23
|
-
'Manage MoreLogin (anti-detect, multi-account browser) profiles. Actions: "status" (is MoreLogin installed/running,
|
|
23
|
+
'Manage MoreLogin (anti-detect, multi-account browser) profiles and pick the one you work in. Actions: "status" (is MoreLogin installed/running, the default profile, the profile you work in), "list" (profiles), "create" (new profile), "use" (work in a profile yourself: your browser_* tools drive it from then on, in your own tab, without changing the default or disturbing any other session; several sessions can work in different profiles at the same time), "start"/"stop" (launch/close a profile). "use" and "start" take only a profile the owner allowed agents to choose. "use_default" is always refused: the default AI browser is the owner\'s choice in Settings → Browser. To work in a profile other than the default, call "use" with its envId or name, then use the browser tools as usual: never tell the user you cannot control a second profile, and never change the default for that. You can choose only a profile the owner allowed agents to choose (the list is the owner\'s, in SynaBun\'s Settings; it is empty until the owner switches a profile on, and "list" / "status" show it). When "use" or "start" is refused because the profile is not on that list, nothing was opened, started or changed: tell the user which profile to switch on and where (SynaBun → Settings → Connected tools → MoreLogin → MoreLogin profiles → "Agents may choose"), and do not work in another profile or browser instead. Only Chrome-type profiles can be driven. Requires the MoreLogin desktop app to be running with its local API enabled. Profiles of two kinds are listed and used the same way, by the same ids: MoreLogin profiles, and local profiles (a Chrome SynaBun runs itself on this computer, with its own cookies, proxy, language and timezone; "list" marks them "local"; they work with MoreLogin closed or not installed). Both are on the same owner\'s list of profiles agents may choose. Local profiles are created, edited and deleted by the owner in Settings only; "create" makes a MoreLogin profile.';
|
|
24
24
|
|
|
25
|
-
interface MlEnv { id: string; name: string; status?: string }
|
|
25
|
+
interface MlEnv { id: string; name: string; status?: string; browser?: string | null; agentsMayChoose?: boolean; kind?: string }
|
|
26
|
+
|
|
27
|
+
/** Whether an id is a local profile's (neural-interface/lib/local-profiles.js: `lp-` and 12 hex characters). */
|
|
28
|
+
export function isLocalProfileId(id: unknown): boolean {
|
|
29
|
+
return typeof id === 'string' && /^lp-[0-9a-f]{12}$/.test(id);
|
|
30
|
+
}
|
|
31
|
+
/** "local profile" for one of SynaBun's own profiles, "MoreLogin env" for every other id. */
|
|
32
|
+
const profileNoun = (id: unknown) => (isLocalProfileId(id) ? 'local profile' : 'MoreLogin env');
|
|
33
|
+
/** What "status" adds about SynaBun's local profiles (`localProfileCount`; a server from before them says nothing). */
|
|
34
|
+
function localProfilesNote(count: unknown): string {
|
|
35
|
+
const n = Number(count);
|
|
36
|
+
return Number.isFinite(n) && n > 0 ? ` SynaBun also has ${n} local profile(s) of its own, which need no MoreLogin ("list" shows them).` : '';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** Where the owner edits the list of profiles agents may choose (neural-interface/lib/morelogin-agent-profiles.js). */
|
|
40
|
+
export const AGENT_PROFILES_WHERE = 'SynaBun → Settings → Connected tools → MoreLogin → MoreLogin profiles → "Agents may choose"';
|
|
41
|
+
|
|
42
|
+
/** The owner's list as one sentence for "status" and "list" (`agentProfiles` of the server's answer). */
|
|
43
|
+
export function agentProfilesLine(list: unknown): string {
|
|
44
|
+
if (!Array.isArray(list)) return 'This SynaBun server does not say which profiles agents may choose (it was started before that list existed).';
|
|
45
|
+
const rows = (list as Array<{ envId?: unknown; name?: unknown }>).filter(row => row && row.envId);
|
|
46
|
+
if (!rows.length) return `Profiles agents may choose: none. The owner has allowed no profile, so "use", browser_session create with moreloginProfile and agent_dispatch morelogin_profile are refused for every profile; the default profile still works. The owner allows one in ${AGENT_PROFILES_WHERE}.`;
|
|
47
|
+
return `Profiles agents may choose (the owner's list): ${rows.map(row => (typeof row.name === 'string' && row.name ? `${row.name} (id ${row.envId})` : `id ${row.envId}`)).join(', ')}. Any other profile is refused; the owner adds one in ${AGENT_PROFILES_WHERE}.`;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** What "use_default" answers: agents never change the default AI browser (finding 1 of the re-review of 2026-11-11). */
|
|
51
|
+
export const USE_DEFAULT_REFUSAL = 'use_default refused: the default AI browser (the default MoreLogin profile) is the owner\'s choice, made in SynaBun → Settings → Browser, and no agent or session can change it, whatever the profile. Nothing was changed. To work in another MoreLogin profile yourself, call morelogin with action "use" and its envId or name: only your own browser tools move there. Tell the user: if every automation should use that profile by default, set it in Settings → Browser.';
|
|
26
52
|
|
|
27
53
|
export async function handleMoreLogin(args: { action: string; envId?: string; name?: string }) {
|
|
28
54
|
switch (args.action) {
|
|
29
55
|
case 'status': {
|
|
30
56
|
const r = await ni.moreloginStatus();
|
|
31
|
-
const
|
|
57
|
+
const mine = r.yourProfile as { envId?: string; name?: string | null; refused?: string } | undefined;
|
|
58
|
+
const def = `${r.isDefault && r.defaultEnvId ? `default AI browser = env ${r.defaultEnvId}` : 'no MoreLogin default set'}${mine?.envId ? `; you work in ${mine.name ? `"${mine.name}" (env ${mine.envId})` : `env ${mine.envId}`} (your own choice or your run's profile, not the default)` : ''}.${mine?.refused ? ` Your browser calls are refused there: ${mine.refused}` : ''} ${agentProfilesLine(r.agentProfiles)}`.replace(/\.$/, '');
|
|
32
59
|
// An API that answered with an error is running: say what it rejected, never "unreachable".
|
|
33
|
-
|
|
34
|
-
if (r.running) return text(`MoreLogin running on port ${r.port}. ${r.profileCount} profile(s). ${def}
|
|
60
|
+
const local = localProfilesNote(r.localProfileCount);
|
|
61
|
+
if (r.running && r.apiError) return text(`MoreLogin running on port ${r.port}, API rejected: ${r.apiError}. ${r.profileCount || 0} profile(s). ${def}.${local}`);
|
|
62
|
+
if (r.running) return text(`MoreLogin running on port ${r.port}. ${r.profileCount} profile(s). ${def}.${local}`);
|
|
35
63
|
if (!r.installed && r.port == null && r.error) return text(`MoreLogin unreachable: ${r.error}`);
|
|
64
|
+
// MoreLogin is closed or absent, and SynaBun's own local profiles work all the same: say both, with the list.
|
|
65
|
+
if (local) return text(`${r.installed ? `MoreLogin is installed but its local API is not running on port ${r.port}` : 'MoreLogin is not installed'}.${local} ${def}.`);
|
|
36
66
|
if (!r.installed) return text('MoreLogin is not installed (no app in a known folder and nothing answers on its port). Install it from https://www.morelogin.com, or set MORELOGIN_APP_PATH to a MoreLogin.exe in a custom folder.');
|
|
37
67
|
return text(`MoreLogin is installed but its local API is not running on port ${r.port}. Open the MoreLogin app and enable Settings → API & MCP.${r.error ? ` (${r.error})` : ''}`);
|
|
38
68
|
}
|
|
@@ -41,42 +71,73 @@ export async function handleMoreLogin(args: { action: string; envId?: string; na
|
|
|
41
71
|
if (r.error) return text(`MoreLogin list failed: ${r.error}`);
|
|
42
72
|
const envs = (r.envs || []) as MlEnv[];
|
|
43
73
|
if (!envs.length) return text('No MoreLogin profiles found. Create one with action "create" (or one is auto-created on first use).');
|
|
44
|
-
|
|
74
|
+
// Each profile says whether the owner allowed agents to choose it, so nobody has to try to find out.
|
|
75
|
+
const mark = (e: MlEnv) => (e.browser === 'firefox' ? 'Firefox-type, cannot be driven' : e.agentsMayChoose === true ? 'agents may choose it' : e.agentsMayChoose === false ? 'not allowed for agents' : null);
|
|
76
|
+
// Local profiles (SynaBun's own Chrome on this computer) are listed with MoreLogin's and say their kind; the
|
|
77
|
+
// same ids work for "use", "start" and "stop". With none, the list reads as it always did.
|
|
78
|
+
const anyLocal = envs.some(e => e.kind === 'local');
|
|
79
|
+
const kind = (e: MlEnv) => (anyLocal ? ` — ${e.kind === 'local' ? 'local' : 'MoreLogin'}` : '');
|
|
80
|
+
const missing = typeof r.moreloginError === 'string' && r.moreloginError ? `\nMoreLogin's own profiles are not listed: ${r.moreloginError}` : '';
|
|
81
|
+
return text(`${anyLocal ? 'Profiles (MoreLogin and local)' : 'MoreLogin profiles'}:\n` + envs.map(e => ` • ${e.name} (id ${e.id})${kind(e)}${e.status ? ` — ${e.status}` : ''}${mark(e) ? ` — ${mark(e)}` : ''}`).join('\n') + `${missing}\n${agentProfilesLine(r.agentProfiles)}`);
|
|
45
82
|
}
|
|
46
83
|
case 'create': {
|
|
47
84
|
const r = await ni.moreloginCreate(args.name);
|
|
48
|
-
|
|
85
|
+
// MoreLogin's plan holds no more profiles: a local profile needs no slot, and only the owner creates one.
|
|
86
|
+
if (r.error) return text(`Create failed: ${r.error}${r.code === 'MORELOGIN_PLAN_LIMIT' ? '\nNothing was created. A local profile is created by the owner in SynaBun → Settings → Connected tools → MoreLogin, never by an agent: tell the user, and stop there.' : ''}`);
|
|
49
87
|
const ids = (r.ids || []) as string[];
|
|
50
88
|
return text(`Created MoreLogin profile${ids.length ? ` (id ${ids.join(', ')})` : ''}.`);
|
|
51
89
|
}
|
|
52
90
|
case 'start': {
|
|
53
91
|
if (!args.envId) return text('envId is required for the "start" action. Use "list" to get ids.');
|
|
54
92
|
const r = await ni.moreloginStart(args.envId);
|
|
55
|
-
|
|
93
|
+
// A profile off the owner's list is not started for an agent (server: POST /api/morelogin/start, B1 of the 2026-11-10 re-review).
|
|
94
|
+
if (r.error) return text(`Start failed: ${r.error}${r.code === 'MORELOGIN_PROFILE_NOT_ALLOWED' ? '\nNothing was started. Tell the user what to switch on, and stop there.' : ''}`);
|
|
56
95
|
// The owner's page gets the profile's debugging port; an automation does not (a raw CDP connection would drive
|
|
57
|
-
// the profile past every check SynaBun makes), and needs none: the browser tools drive the
|
|
58
|
-
return text(`Started
|
|
96
|
+
// the profile past every check SynaBun makes), and needs none: the browser tools drive the profile it works in.
|
|
97
|
+
return text(`Started ${profileNoun(args.envId)} ${args.envId}${r.debugPort ? ` (debug port ${r.debugPort})` : ''}. Starting a profile does not move your browser tools there: to work in it, call morelogin with action "use" and this envId.`);
|
|
59
98
|
}
|
|
60
99
|
case 'stop': {
|
|
61
100
|
if (!args.envId) return text('envId is required for the "stop" action.');
|
|
62
101
|
const r = await ni.moreloginStop(args.envId);
|
|
63
102
|
if (r.error) return text(`Stop failed: ${r.error}`);
|
|
64
|
-
return text(`Stopped
|
|
103
|
+
return text(`Stopped ${profileNoun(args.envId)} ${args.envId}.`);
|
|
104
|
+
}
|
|
105
|
+
case 'use': {
|
|
106
|
+
const toDefault = (args.envId || '').trim().toLowerCase() === 'default' || (!args.envId && (args.name || '').trim().toLowerCase() === 'default');
|
|
107
|
+
if (!toDefault && !args.envId && !args.name) return text('The "use" action needs envId or name (the "list" action gives both), or envId "default" to go back to the default profile.');
|
|
108
|
+
const r = await ni.useSessionProfile(toDefault ? { default: true } : { ...(args.envId ? { envId: args.envId } : {}), ...(args.name ? { name: args.name } : {}) });
|
|
109
|
+
if (r.error) return text(`use failed: ${r.error}\nNothing changed: you still work where you did. Never fall back to another profile or browser by yourself.${r.code === 'MORELOGIN_PROFILE_NOT_ALLOWED' ? ' Tell the user what to switch on, and stop there.' : ''}`);
|
|
110
|
+
return text(useAnswer(r));
|
|
65
111
|
}
|
|
66
112
|
case 'use_default': {
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
return text(
|
|
113
|
+
// Finding 1 of the re-review of 2026-11-11: the default AI browser is the owner's choice alone, for every caller
|
|
114
|
+
// and every profile. The tool answers without asking the server, which refuses it too (403
|
|
115
|
+
// MORELOGIN_DEFAULT_OWNER_ONLY in POST /api/morelogin/use-default) for anything that is not the owner's page.
|
|
116
|
+
return text(USE_DEFAULT_REFUSAL);
|
|
71
117
|
}
|
|
72
118
|
default:
|
|
73
119
|
return text(`Unknown action: ${args.action}`);
|
|
74
120
|
}
|
|
75
121
|
}
|
|
76
122
|
|
|
123
|
+
/** What "use" answers: where the caller works now, what was closed, and what its next browser call does. */
|
|
124
|
+
export function useAnswer(r: Record<string, unknown>): string {
|
|
125
|
+
const label = (envId: unknown, name: unknown) => (isLocalProfileId(envId)
|
|
126
|
+
? (typeof name === 'string' && name ? `local profile "${name}" (id ${envId})` : `local profile ${envId}`)
|
|
127
|
+
: (typeof name === 'string' && name ? `MoreLogin profile "${name}" (env ${envId})` : `MoreLogin profile env ${envId}`));
|
|
128
|
+
const now = r.default === true ? 'the default browser profile (Settings → Browser)' : label(r.envId, r.name);
|
|
129
|
+
if (r.changed !== true) return `You already work in ${now}. Nothing changed.`;
|
|
130
|
+
const released = Array.isArray(r.released) ? r.released as Array<{ sessionId?: string; tabId?: string | null }> : [];
|
|
131
|
+
const closed = released.filter(x => x && x.tabId).map(x => `tab ${x.tabId} of session ${x.sessionId}`);
|
|
132
|
+
const lines = [`You now work in ${now}. Only your own browser tools moved: the default AI browser and every other session are unchanged.`];
|
|
133
|
+
if (closed.length) lines.push(`Your ${closed.join(', ')} in the profile you left ${closed.length === 1 ? 'was' : 'were'} released: do not pass those ids again.`);
|
|
134
|
+
lines.push('Your next browser call (browser_navigate with a URL, without ids) opens a tab of your own there; the profile is started then if it is not running, which can take a minute or two. If it cannot start, that call fails and names the profile: report it, never switch to another profile or browser by yourself.');
|
|
135
|
+
return lines.join('\n');
|
|
136
|
+
}
|
|
137
|
+
|
|
77
138
|
/**
|
|
78
139
|
* Register the MoreLogin MCP tool on the given server instance.
|
|
79
|
-
* Single tool with action-based dispatch: status, list, create, start, stop, use_default.
|
|
140
|
+
* Single tool with action-based dispatch: status, list, create, start, stop, use, use_default (always refused).
|
|
80
141
|
*/
|
|
81
142
|
export function registerMoreLoginTools(server: McpServer) {
|
|
82
143
|
return [
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
* look successful).
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
+
import { statSync } from 'node:fs';
|
|
17
18
|
import { z } from 'zod/v3';
|
|
18
19
|
import { v4 as uuidv4 } from 'uuid';
|
|
19
20
|
import * as ni from '../../services/neural-interface.js';
|
|
@@ -25,7 +26,7 @@ import type { MemoryPayload } from '../../types.js';
|
|
|
25
26
|
import { text } from '../response.js';
|
|
26
27
|
import {
|
|
27
28
|
STUDIO_BASE, resolve, ensureAuth, wait, pollFor, safeNavigate,
|
|
28
|
-
clickStudio, fillStudio,
|
|
29
|
+
clickStudio, fillStudio, type Resolved,
|
|
29
30
|
} from './helpers.js';
|
|
30
31
|
import { TRAILER_CATEGORY, ledgerTags } from './dedup.js';
|
|
31
32
|
|
|
@@ -52,7 +53,9 @@ export const youtubeUploadSchema = {
|
|
|
52
53
|
export const youtubeUploadDescription =
|
|
53
54
|
'Upload a local video file to YouTube Studio, publish it, and record it to the youtube-videos dedup ledger. ' +
|
|
54
55
|
'Opens Create → Upload, sets the file, fills title/description/tags, advances the wizard, sets visibility, clicks Done, then verifies the wizard closed and resolves the new video id. [mutating — publishes to the channel]. ' +
|
|
55
|
-
'Pass game/igdbId/appid/sourceTrailerId so the upload is remembered and never re-posted. Default visibility=private so you can schedule afterwards with youtube_schedule.'
|
|
56
|
+
'Pass game/igdbId/appid/sourceTrailerId so the upload is remembered and never re-posted. Default visibility=private so you can schedule afterwards with youtube_schedule. ' +
|
|
57
|
+
'Result JSON: state = "published" (the tool clicked Publish/Save and Studio confirmed it; visibility is then the one applied), "draft" (a video row exists but is NOT published: see draftReason, e.g. processing/checks still running or the publish step not reached; finish it in Studio with Edit draft → Visibility → Publish once processing ends, never re-upload) or "upload_not_confirmed" (no evidence a row exists; check Studio → Content before any retry). ' +
|
|
58
|
+
'videoId is read only from this upload\'s own dialog; idConfirmed=false with videoId null means no trustworthy id was found (never a guess). videoRowExists tells you whether a duplicate upload would be created by retrying.';
|
|
56
59
|
|
|
57
60
|
async function ensureOnStudio(r: Resolved): Promise<string | null> {
|
|
58
61
|
const res = await ni.evaluate(r.sessionId, `location.href`, r.tabId);
|
|
@@ -117,6 +120,86 @@ async function recordTrailerLedger(idy: {
|
|
|
117
120
|
}
|
|
118
121
|
}
|
|
119
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Read the upload dialog's own state. Everything is scoped to
|
|
125
|
+
* ytcp-uploads-dialog (and the share dialog Studio shows after Publish/Save),
|
|
126
|
+
* never the page: the old reader matched the first youtu.be link anywhere in
|
|
127
|
+
* document.body, which picked up other videos of the channel.
|
|
128
|
+
*/
|
|
129
|
+
const DIALOG_PROBE = `(() => {
|
|
130
|
+
const ID = /(?:youtu\\.be\\/|\\/shorts\\/|watch\\?v=|\\/video\\/)([A-Za-z0-9_-]{11})(?![A-Za-z0-9_-])/;
|
|
131
|
+
const deepAll = (root, sel, out) => {
|
|
132
|
+
if (!root) return out;
|
|
133
|
+
root.querySelectorAll(sel).forEach((el) => out.push(el));
|
|
134
|
+
root.querySelectorAll('*').forEach((el) => { if (el.shadowRoot) deepAll(el.shadowRoot, sel, out); });
|
|
135
|
+
return out;
|
|
136
|
+
};
|
|
137
|
+
const visible = (el) => !!el && !el.hidden && el.getAttribute('aria-hidden') !== 'true' && !!(el.offsetWidth || el.offsetHeight || el.getClientRects().length);
|
|
138
|
+
const idIn = (root) => {
|
|
139
|
+
if (!root) return null;
|
|
140
|
+
for (const a of deepAll(root, 'a[href]', [])) { const m = (a.getAttribute('href') || '').match(ID); if (m) return m[1]; }
|
|
141
|
+
for (const el of deepAll(root, '[video-id],[data-video-id]', [])) {
|
|
142
|
+
const v = el.getAttribute('video-id') || el.getAttribute('data-video-id');
|
|
143
|
+
if (v && /^[A-Za-z0-9_-]{11}$/.test(v)) return v;
|
|
144
|
+
}
|
|
145
|
+
return null;
|
|
146
|
+
};
|
|
147
|
+
const dialog = deepAll(document, 'ytcp-uploads-dialog', []).find(visible) || null;
|
|
148
|
+
const share = deepAll(document, 'ytcp-video-share-dialog', []).find(visible) || null;
|
|
149
|
+
const prechecks = deepAll(document, 'ytcp-prechecks-warning-dialog', []).find(visible) || null;
|
|
150
|
+
const progress = dialog ? (deepAll(dialog, 'ytcp-video-upload-progress', [])[0] || null) : null;
|
|
151
|
+
const progressText = progress ? (progress.innerText || progress.textContent || '').replace(/\\s+/g, ' ').trim() : '';
|
|
152
|
+
const pm = progressText.match(/(\\d{1,3})\\s?%/);
|
|
153
|
+
const done = dialog ? (deepAll(dialog, '#done-button', [])[0] || null) : null;
|
|
154
|
+
const doneDisabled = done ? (done.hasAttribute('disabled') || done.getAttribute('aria-disabled') === 'true') : null;
|
|
155
|
+
const uploadingAttr = progress ? (progress.hasAttribute('uploading') || progress.getAttribute('upload-status') === 'UPLOADING') : false;
|
|
156
|
+
const uploadingWord = /upload|envi|carreg/i.test(progressText) && !!pm;
|
|
157
|
+
return {
|
|
158
|
+
dialogOpen: !!dialog,
|
|
159
|
+
shareOpen: !!share,
|
|
160
|
+
prechecksOpen: !!prechecks,
|
|
161
|
+
id: idIn(share) || idIn(dialog),
|
|
162
|
+
percent: pm ? Number(pm[1]) : null,
|
|
163
|
+
uploading: uploadingAttr || uploadingWord,
|
|
164
|
+
progressText: progressText.slice(0, 160),
|
|
165
|
+
doneDisabled,
|
|
166
|
+
formVisible: !!dialog && deepAll(dialog, '#title-textarea', []).some(visible),
|
|
167
|
+
};
|
|
168
|
+
})()`;
|
|
169
|
+
|
|
170
|
+
type DialogState = {
|
|
171
|
+
dialogOpen: boolean; shareOpen: boolean; prechecksOpen: boolean; id: string | null;
|
|
172
|
+
percent: number | null; uploading: boolean; progressText: string; doneDisabled: boolean | null; formVisible: boolean;
|
|
173
|
+
};
|
|
174
|
+
|
|
175
|
+
async function probe(r: Resolved): Promise<DialogState | null> {
|
|
176
|
+
const res = await ni.evaluate(r.sessionId, DIALOG_PROBE, r.tabId);
|
|
177
|
+
if (res.error || !res.result || typeof res.result !== 'object') return null;
|
|
178
|
+
return res.result as DialogState;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** Wait until the file transfer itself is over (no longer "uploading"), bounded by a size-aware limit. */
|
|
182
|
+
async function waitForTransfer(r: Resolved, limitMs: number): Promise<{ finished: boolean; last: DialogState | null }> {
|
|
183
|
+
const start = Date.now();
|
|
184
|
+
let last: DialogState | null = null;
|
|
185
|
+
while (Date.now() - start < limitMs) {
|
|
186
|
+
last = await probe(r);
|
|
187
|
+
if (last && last.dialogOpen && last.formVisible && !last.uploading) return { finished: true, last };
|
|
188
|
+
if (last && !last.dialogOpen) return { finished: false, last };
|
|
189
|
+
await wait(2000);
|
|
190
|
+
}
|
|
191
|
+
return { finished: false, last };
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
function sizeAwareLimitMs(filePath: string): number {
|
|
195
|
+
let bytes = 0;
|
|
196
|
+
try { bytes = statSync(filePath).size; } catch { /* unknown size */ }
|
|
197
|
+
// Assume a slow 0.25 MB/s upstream, plus 2 minutes; cap at 45 minutes.
|
|
198
|
+
return Math.min(45 * 60_000, 120_000 + Math.ceil(bytes / (0.25 * 1024 * 1024)) * 1000);
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
type UploadState = 'published' | 'draft' | 'upload_not_confirmed';
|
|
202
|
+
|
|
120
203
|
export async function handleYoutubeUpload(args: {
|
|
121
204
|
filePath: string;
|
|
122
205
|
title: string;
|
|
@@ -138,53 +221,57 @@ export async function handleYoutubeUpload(args: {
|
|
|
138
221
|
const onErr = await ensureOnStudio(r);
|
|
139
222
|
if (onErr) return text(onErr);
|
|
140
223
|
|
|
224
|
+
const requested = args.visibility || 'private';
|
|
225
|
+
const title = args.title.slice(0, 100);
|
|
226
|
+
const limitMs = sizeAwareLimitMs(args.filePath);
|
|
227
|
+
let videoId: string | null = null;
|
|
228
|
+
const notes: string[] = [];
|
|
229
|
+
const noteId = (s: DialogState | null) => { if (!videoId && s?.id) videoId = s.id; };
|
|
230
|
+
|
|
141
231
|
// 1) Open the Create menu → Upload videos.
|
|
142
|
-
// #create-icon is locale-independent in most builds; fall back to aria-label
|
|
143
|
-
// and class-based selectors for PT-BR and other locales where the id is absent.
|
|
144
232
|
let create = await clickStudio(r, '#create-icon', 'Create');
|
|
145
|
-
if (!create.ok)
|
|
146
|
-
|
|
147
|
-
}
|
|
148
|
-
if (!create.ok) {
|
|
149
|
-
create = await clickStudio(r, 'ytcp-button[class*="CreateIcon"]', 'Criar');
|
|
150
|
-
}
|
|
233
|
+
if (!create.ok) create = await clickStudio(r, 'button[aria-label="Criar"]', 'Criar');
|
|
234
|
+
if (!create.ok) create = await clickStudio(r, 'ytcp-button[class*="CreateIcon"]', 'Criar');
|
|
151
235
|
if (!create.ok) return text(`Could not open the Create menu: ${create.error}`);
|
|
152
236
|
await wait(700);
|
|
153
|
-
// The first item in the create menu is "Upload videos" (PT-BR: "Enviar vídeos").
|
|
154
237
|
const uploadItem = await clickStudio(r, 'tp-yt-paper-item#text-item-0', 'Upload videos');
|
|
155
238
|
if (!uploadItem.ok) {
|
|
156
|
-
// Fallback 1: some Studio builds expose a direct upload button id.
|
|
157
239
|
const alt = await clickStudio(r, '#upload-button', 'Upload videos');
|
|
158
240
|
if (!alt.ok) {
|
|
159
|
-
// Fallback 2: PT-BR locale — click first menuitem by role.
|
|
160
241
|
const altPt = await clickStudio(r, '[role="menuitem"]:first-of-type', 'Enviar vídeos');
|
|
161
242
|
if (!altPt.ok) return text(`Could not find the "Upload videos" menu item: ${uploadItem.error}`);
|
|
162
243
|
}
|
|
163
244
|
}
|
|
164
245
|
|
|
165
|
-
// 2) Set the file
|
|
246
|
+
// 2) Set the file. A timeout here does not mean the upload failed: YouTube
|
|
247
|
+
// often has the file already, so look at the dialog before giving up.
|
|
166
248
|
const waitInput = await ni.waitFor(r.sessionId, { selector: 'input[type="file"]', state: 'attached', timeout: 15000 }, r.tabId);
|
|
167
249
|
if (waitInput.error) return text(`Upload dialog did not open: ${waitInput.error}`);
|
|
168
250
|
const up = await ni.upload(r.sessionId, 'input[type="file"]', [args.filePath], undefined, r.tabId);
|
|
169
|
-
if (up.error)
|
|
251
|
+
if (up.error) notes.push(`File input step reported: ${up.error}. Checked the dialog to see whether the upload started anyway.`);
|
|
170
252
|
|
|
171
|
-
// 3) Wait for the details form
|
|
172
|
-
const formReady = await ni.waitFor(r.sessionId, { selector: '#title-textarea', state: 'visible', timeout: 30000 }, r.tabId);
|
|
173
|
-
if (formReady.error)
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
253
|
+
// 3) Wait for the details form of THIS upload.
|
|
254
|
+
const formReady = await ni.waitFor(r.sessionId, { selector: '#title-textarea', state: 'visible', timeout: up.error ? 90000 : 30000 }, r.tabId);
|
|
255
|
+
if (formReady.error) {
|
|
256
|
+
const s = await probe(r);
|
|
257
|
+
noteId(s);
|
|
258
|
+
const started = !!(s && s.dialogOpen && (s.formVisible || s.percent != null || s.id));
|
|
259
|
+
return result({
|
|
260
|
+
state: started ? 'draft' : 'upload_not_confirmed',
|
|
261
|
+
draftReason: started ? 'details form did not finish loading; the upload dialog is still open' : null,
|
|
262
|
+
videoRowExists: started ? true : 'unknown',
|
|
263
|
+
notes: [...notes, `Details form did not appear: ${formReady.error}.`, started
|
|
264
|
+
? 'The upload started: do NOT upload again. Leave the tab on Studio and finish the draft there.'
|
|
265
|
+
: 'No sign of the upload in the dialog. Check Studio → Content before any retry.'],
|
|
266
|
+
});
|
|
183
267
|
}
|
|
268
|
+
await wait(800);
|
|
269
|
+
noteId(await probe(r));
|
|
184
270
|
|
|
185
|
-
// 6)
|
|
186
|
-
|
|
187
|
-
|
|
271
|
+
// 4–6) Metadata.
|
|
272
|
+
const titleOk = await fillStudio(r, '#title-textarea #textbox', title, 'Add a title that describes your video');
|
|
273
|
+
if (!titleOk.ok) notes.push(`Could not set the title: ${titleOk.error}.`);
|
|
274
|
+
if (args.description) await fillStudio(r, '#description-textarea #textbox', args.description, 'Tell viewers about your video');
|
|
188
275
|
if (args.tags && args.tags.length) {
|
|
189
276
|
await clickStudio(r, '#toggle-button', 'Show more');
|
|
190
277
|
await wait(700);
|
|
@@ -192,97 +279,129 @@ export async function handleYoutubeUpload(args: {
|
|
|
192
279
|
const t = tag.trim();
|
|
193
280
|
if (!t) continue;
|
|
194
281
|
const typed = await ni.type(r.sessionId, '#tags-container #text-input', `${t},`, undefined, r.tabId, 'Tags', 'insert');
|
|
195
|
-
if (typed.error) break;
|
|
282
|
+
if (typed.error) break;
|
|
196
283
|
await wait(150);
|
|
197
284
|
}
|
|
198
285
|
await ni.pressKey(r.sessionId, 'Enter', r.tabId);
|
|
199
286
|
await wait(300);
|
|
200
287
|
}
|
|
201
288
|
|
|
202
|
-
// 7) Audience
|
|
289
|
+
// 7) Audience.
|
|
203
290
|
const kidsName = args.madeForKids ? 'VIDEO_MADE_FOR_KIDS_MFK' : 'VIDEO_MADE_FOR_KIDS_NOT_MFK';
|
|
204
291
|
await clickStudio(r, `tp-yt-paper-radio-button[name="${kidsName}"]`, args.madeForKids ? 'Yes, it\'s made for kids' : 'No, it\'s not made for kids');
|
|
205
292
|
await wait(400);
|
|
206
293
|
|
|
207
|
-
// 8)
|
|
294
|
+
// 8) Let the transfer itself finish before anything can close the dialog.
|
|
295
|
+
const transfer = await waitForTransfer(r, limitMs);
|
|
296
|
+
noteId(transfer.last);
|
|
297
|
+
if (!transfer.finished) {
|
|
298
|
+
const open = !!transfer.last?.dialogOpen;
|
|
299
|
+
return result({
|
|
300
|
+
state: open ? 'draft' : 'upload_not_confirmed',
|
|
301
|
+
draftReason: open ? `file transfer still running after ${Math.round(limitMs / 60000)} min (${transfer.last?.progressText || 'no progress text'})` : null,
|
|
302
|
+
videoRowExists: open ? true : 'unknown',
|
|
303
|
+
notes: [...notes, open
|
|
304
|
+
? 'The upload is in progress: do NOT upload again and do not leave the Studio tab until it reaches 100%.'
|
|
305
|
+
: 'The upload dialog closed before the transfer was confirmed. Check Studio → Content before any retry.'],
|
|
306
|
+
});
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
// 9) Advance the wizard to Visibility.
|
|
208
310
|
for (let step = 0; step < 3; step++) {
|
|
209
311
|
const next = await clickStudio(r, '#next-button', 'Next');
|
|
210
312
|
if (!next.ok) break;
|
|
211
313
|
await wait(900);
|
|
212
314
|
}
|
|
213
|
-
|
|
214
|
-
// 9) Visibility radio. Wait for the radio group itself (locale-independent
|
|
215
|
-
// name= attribute, shadow-DOM-pierced by Playwright) rather than localized text.
|
|
216
|
-
const vis = (args.visibility || 'private').toUpperCase();
|
|
315
|
+
const vis = requested.toUpperCase();
|
|
217
316
|
const visReady = await ni.waitFor(r.sessionId, { selector: `tp-yt-paper-radio-button[name="${vis}"]`, state: 'visible', timeout: 12000 }, r.tabId);
|
|
218
|
-
|
|
219
|
-
|
|
317
|
+
const visClick = visReady.error ? { ok: false, error: visReady.error } : await clickStudio(r, `tp-yt-paper-radio-button[name="${vis}"]`, vis.charAt(0) + vis.slice(1).toLowerCase());
|
|
318
|
+
noteId(await probe(r));
|
|
319
|
+
if (!visClick.ok) {
|
|
320
|
+
return result({
|
|
321
|
+
state: 'draft',
|
|
322
|
+
draftReason: `publish step not reached: visibility ${vis} could not be selected (${visClick.error})`,
|
|
323
|
+
videoRowExists: true,
|
|
324
|
+
notes,
|
|
325
|
+
});
|
|
220
326
|
}
|
|
221
|
-
const visClick = await clickStudio(r, `tp-yt-paper-radio-button[name="${vis}"]`, vis.charAt(0) + vis.slice(1).toLowerCase());
|
|
222
|
-
if (!visClick.ok) return text(`Could not select visibility ${vis}: ${visClick.error}.`);
|
|
223
327
|
await wait(500);
|
|
224
328
|
|
|
225
|
-
// 10) Publish /
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
// 12) Confirm the wizard actually finished (dialog closed) — the honest
|
|
244
|
-
// success signal. Don't claim a post that didn't complete.
|
|
245
|
-
const closed = await ni.waitFor(r.sessionId, { selector: '#title-textarea', state: 'hidden', timeout: 12000 }, r.tabId);
|
|
246
|
-
const publishConfirmed = !closed.error;
|
|
247
|
-
|
|
248
|
-
// 13) Fallback id resolution from the content grid (navigates away — only once
|
|
249
|
-
// publishing is confirmed, so the just-uploaded video is the newest row).
|
|
250
|
-
if (!videoId && publishConfirmed) {
|
|
251
|
-
videoId = await resolveLatestUploadedVideoId(r);
|
|
329
|
+
// 10) Publish / Save, only when Studio enables the button (it stays
|
|
330
|
+
// disabled while processing or checks run). Wait a bounded time for that.
|
|
331
|
+
const enableDeadline = Date.now() + Math.min(limitMs, 10 * 60_000);
|
|
332
|
+
let s = await probe(r);
|
|
333
|
+
while (s && s.doneDisabled && Date.now() < enableDeadline) { await wait(3000); s = await probe(r); }
|
|
334
|
+
noteId(s);
|
|
335
|
+
if (!s || s.doneDisabled) {
|
|
336
|
+
return result({
|
|
337
|
+
state: 'draft',
|
|
338
|
+
draftReason: 'processing or checks still running: the Publish/Save button stayed disabled',
|
|
339
|
+
videoRowExists: true,
|
|
340
|
+
notes,
|
|
341
|
+
});
|
|
342
|
+
}
|
|
343
|
+
const done = await clickStudio(r, '#done-button', requested === 'public' ? 'Publish' : 'Save');
|
|
344
|
+
if (!done.ok) {
|
|
345
|
+
return result({ state: 'draft', draftReason: `publish step not completed: could not click Publish/Save (${done.error})`, videoRowExists: true, notes });
|
|
252
346
|
}
|
|
253
347
|
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
348
|
+
// 11) Confirmation: Studio's share dialog ("Video published" / "saved").
|
|
349
|
+
let confirmed = false;
|
|
350
|
+
let prechecks = false;
|
|
351
|
+
const confirmDeadline = Date.now() + 30000;
|
|
352
|
+
while (Date.now() < confirmDeadline) {
|
|
353
|
+
await wait(1000);
|
|
354
|
+
const c = await probe(r);
|
|
355
|
+
if (!c) continue;
|
|
356
|
+
noteId(c);
|
|
357
|
+
if (c.shareOpen) { confirmed = true; if (c.id) videoId = c.id; break; }
|
|
358
|
+
if (c.prechecksOpen) { prechecks = true; break; }
|
|
359
|
+
}
|
|
360
|
+
if (!confirmed) {
|
|
361
|
+
return result({
|
|
362
|
+
state: 'draft',
|
|
363
|
+
draftReason: prechecks
|
|
364
|
+
? 'checks still running: Studio asked for confirmation before publishing; nothing was confirmed'
|
|
365
|
+
: 'Publish/Save was clicked but Studio showed no confirmation (dialog closed or still saving)',
|
|
366
|
+
videoRowExists: true,
|
|
367
|
+
notes,
|
|
270
368
|
});
|
|
271
369
|
}
|
|
370
|
+
return result({ state: 'published', draftReason: null, videoRowExists: true, notes });
|
|
272
371
|
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
372
|
+
async function result(o: { state: UploadState; draftReason: string | null; videoRowExists: boolean | 'unknown'; notes: string[] }) {
|
|
373
|
+
const idConfirmed = !!videoId;
|
|
374
|
+
const hasIdentity = !!(args.game || args.igdbId != null || args.appid != null || args.sourceTrailerId);
|
|
375
|
+
let recordedMemoryId: string | null = null;
|
|
376
|
+
// A row exists (published or draft): record it so the trailer is not re-posted.
|
|
377
|
+
if (o.videoRowExists === true && hasIdentity) {
|
|
378
|
+
recordedMemoryId = await recordTrailerLedger({
|
|
379
|
+
game: args.game, igdbId: args.igdbId, appid: args.appid, sourceTrailerId: args.sourceTrailerId,
|
|
380
|
+
source: args.source, videoId, title,
|
|
381
|
+
visibility: o.state === 'published' ? requested : 'draft',
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
const summary = o.state === 'published'
|
|
385
|
+
? `Published as ${requested} and confirmed by Studio.`
|
|
386
|
+
: o.state === 'draft'
|
|
387
|
+
? `Uploaded but NOT published (draft): ${o.draftReason}. Finish it in Studio (Edit draft → Visibility → Publish) once processing ends; do not upload again.`
|
|
388
|
+
: 'Upload not confirmed. Check Studio → Content before any retry to avoid a duplicate.';
|
|
389
|
+
return text(JSON.stringify({
|
|
390
|
+
state: o.state,
|
|
391
|
+
uploaded: o.videoRowExists === true,
|
|
392
|
+
published: o.state === 'published',
|
|
393
|
+
videoRowExists: o.videoRowExists,
|
|
394
|
+
videoId,
|
|
395
|
+
idConfirmed,
|
|
396
|
+
visibility: o.state === 'published' ? requested : null,
|
|
397
|
+
requestedVisibility: requested,
|
|
398
|
+
draftReason: o.draftReason,
|
|
399
|
+
title,
|
|
400
|
+
recordedMemoryId,
|
|
401
|
+
ledger: recordedMemoryId
|
|
402
|
+
? 'Recorded to youtube-videos (dedup ledger).'
|
|
403
|
+
: (hasIdentity ? 'No confirmed video row — ledger NOT recorded.' : 'No game/igdbId/appid/sourceTrailerId passed — ledger NOT recorded.'),
|
|
404
|
+
note: [summary, idConfirmed ? `Video id ${videoId} (read from this upload's dialog).` : 'No trustworthy video id could be read from this upload\'s dialog: videoId is null. Find it in Studio → Content (the draft\'s edit URL).', ...o.notes].join(' '),
|
|
405
|
+
}, null, 2));
|
|
406
|
+
}
|
|
288
407
|
}
|