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
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
// Raster artwork shared by live rigs and transcript stills. All names are
|
|
2
|
+
// allowlisted; tool data can never become a URL. Timing belongs to the rig.
|
|
3
|
+
// v3 (approved 2026-11-11): every file is the whole drawn character (eyes,
|
|
4
|
+
// smile and props together); the rig never draws over it.
|
|
5
|
+
const ROOT = '/assets/mascot/';
|
|
6
|
+
export const MASCOT_ASSET_VERSION = '3';
|
|
7
|
+
export const MASCOT_ASSET_POSES = Object.freeze([
|
|
8
|
+
'shell', 'read', 'edit', 'search', 'web', 'subagent', 'plan', 'memory',
|
|
9
|
+
'runs', 'computer', 'think', 'mcp', 'idle', 'sleep', 'watch', 'wait',
|
|
10
|
+
'success', 'error', 'blocked', 'offline', 'project', 'budget', 'skill',
|
|
11
|
+
'present', 'pick', 'ask',
|
|
12
|
+
]);
|
|
13
|
+
const count = (v, lo, hi, fallback) => v != null && Number.isFinite(Number(v))
|
|
14
|
+
? Math.max(lo, Math.min(hi, Math.round(Number(v)))) : fallback;
|
|
15
|
+
|
|
16
|
+
export function mascotAssetKey(pose, options = {}, { hero = false } = {}) {
|
|
17
|
+
const name = MASCOT_ASSET_POSES.includes(pose) ? pose : 'idle';
|
|
18
|
+
if (name === 'idle' && hero) return 'idle-hero';
|
|
19
|
+
if (name === 'memory' && options.mode === 'remember') return 'memory-remember';
|
|
20
|
+
if (name === 'budget' && options.unlimited) return 'budget-unlimited';
|
|
21
|
+
if (name === 'subagent') {
|
|
22
|
+
const n = count(options.count, 1, 3, 1);
|
|
23
|
+
return n === 1 ? name : `${name}-${n}`;
|
|
24
|
+
}
|
|
25
|
+
if (name === 'pick' || name === 'plan') {
|
|
26
|
+
const n = count(options.ticks, 0, 3, 1);
|
|
27
|
+
return n === 1 ? name : `${name}-${n}`;
|
|
28
|
+
}
|
|
29
|
+
return name;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
// Every file shipped (one GIF + one still PNG each); also the asset integrity
|
|
33
|
+
// test's source of truth. `hover-attention` is the empty page's one-shot.
|
|
34
|
+
export const MASCOT_ASSET_KEYS = Object.freeze([...MASCOT_ASSET_POSES, 'idle-hero', 'hover-attention']);
|
|
35
|
+
// Keys the rig still tells apart that v3 draws with the base state's art.
|
|
36
|
+
export const MASCOT_ASSET_FALLBACKS = Object.freeze({
|
|
37
|
+
'memory-remember': 'memory', 'budget-unlimited': 'budget',
|
|
38
|
+
'subagent-2': 'subagent', 'subagent-3': 'subagent',
|
|
39
|
+
'plan-0': 'plan', 'plan-2': 'plan', 'plan-3': 'plan',
|
|
40
|
+
'pick-0': 'pick', 'pick-2': 'pick', 'pick-3': 'pick',
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
/** The shipped file a key is drawn from: its own, else its base state's, else idle. */
|
|
44
|
+
export function mascotAssetFile(key) {
|
|
45
|
+
if (MASCOT_ASSET_KEYS.includes(key)) return key;
|
|
46
|
+
return Object.hasOwn(MASCOT_ASSET_FALLBACKS, key) ? MASCOT_ASSET_FALLBACKS[key] : 'idle';
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** URL of a key's art (allowlisted: an unknown key is idle). */
|
|
50
|
+
export function mascotAssetUrl(key, { animated = false } = {}) {
|
|
51
|
+
return `${ROOT}${mascotAssetFile(key)}.${animated ? 'gif' : 'png'}?v=${MASCOT_ASSET_VERSION}`;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export function mascotAsset(pose, options, { animated = false, hero = false } = {}) {
|
|
55
|
+
return mascotAssetUrl(mascotAssetKey(pose, options, { hero }), { animated });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Scene names are independent of tool input and always pass through this list.
|
|
59
|
+
export const SCENE_ASSET_KEYS = Object.freeze([
|
|
60
|
+
'quick', 'code', 'complex', 'review', 'research', 'browser', 'computer',
|
|
61
|
+
'automation', 'design', 'image_gen', 'video_gen', 'generic',
|
|
62
|
+
'edit', 'shell', 'read', 'search', 'web', 'memory', 'thinking',
|
|
63
|
+
]);
|
|
64
|
+
export function sceneAsset(scene, { animated = false } = {}) {
|
|
65
|
+
const id = SCENE_ASSET_KEYS.includes(scene) ? scene : 'generic';
|
|
66
|
+
return `${ROOT}scenes/${id}.${animated ? 'gif' : 'png'}?v=${MASCOT_ASSET_VERSION}`;
|
|
67
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// ═══════════════════════════════════════════
|
|
2
|
-
// SynaBun mascot —
|
|
2
|
+
// SynaBun mascot — generated block eyes and a smile, on the shared rig
|
|
3
3
|
// ═══════════════════════════════════════════
|
|
4
4
|
// The onboarding character (onboarding.html initEyesSVG / updateEyesSVG): the
|
|
5
5
|
// same 280×140 geometry and blink timing, as a module any page can mount, now
|
|
@@ -7,7 +7,9 @@
|
|
|
7
7
|
// function of time (poseFrame) over a few parameters per eye, the mouth and
|
|
8
8
|
// the face, plus one prop drawn in the face's own pill geometry. Rigs draw
|
|
9
9
|
// from the shared ticker (shared/synabun-ticker.js): 30 fps while a pose
|
|
10
|
-
// loops, 60 fps for blends and reactions, no frames at all while still.
|
|
10
|
+
// loops, 60 fps for blends and reactions, no frames at all while still. The
|
|
11
|
+
// task artwork plays from compact GIFs; PNGs serve stills and reduced motion.
|
|
12
|
+
// The SVG geometry remains the gaze/reaction/pointing rig and asset encoder. One
|
|
11
13
|
// loop, one pointermove listener and one IntersectionObserver serve every rig,
|
|
12
14
|
// and every rig that is active and on screen plays its own pose: N rigs move
|
|
13
15
|
// at once, each on its own clock. No rig waits for another; a host that wants
|
|
@@ -39,6 +41,7 @@
|
|
|
39
41
|
* one-shot (success, error, blocked) has played and held. The same pose with
|
|
40
42
|
* a new count or ticks keeps its loop running. `opts.unlimited` selects the
|
|
41
43
|
* budget pose's relaxed infinity variant; project peeks into a folder.
|
|
44
|
+
* `idleVariant: 'hero'` selects the richer empty-page idle artwork.
|
|
42
45
|
* The card poses (`MASCOT_CARD_POSES`, the Assistant's follow-ups and
|
|
43
46
|
* question cards): `present` (a warm smile toward what it offers), `pick`
|
|
44
47
|
* (the plan's clipboard, one tick per picked item: `opts.ticks`) and `ask`
|
|
@@ -105,9 +108,10 @@
|
|
|
105
108
|
*/
|
|
106
109
|
|
|
107
110
|
import {
|
|
108
|
-
isReducedMotion, lastInputAt, now as tickerNow, onKey, onPointer, onReducedMotionChange,
|
|
109
|
-
pointerPosition, requestFrames, subscribe,
|
|
111
|
+
clearTickerTimeout, isReducedMotion, lastInputAt, now as tickerNow, onKey, onPointer, onReducedMotionChange,
|
|
112
|
+
pointerPosition, requestFrames, subscribe, tickerPaused, tickerTimeout,
|
|
110
113
|
} from './synabun-ticker.js';
|
|
114
|
+
import { mascotAsset, mascotAssetUrl } from './synabun-mascot-assets.js';
|
|
111
115
|
|
|
112
116
|
export const MASCOT_VIEWBOX = '0 0 280 140';
|
|
113
117
|
|
|
@@ -119,14 +123,51 @@ export const MASCOT_CARD_POSES = Object.freeze(['present', 'pick', 'ask']);
|
|
|
119
123
|
export const MASCOT_POSES = Object.freeze([...MASCOT_KINDS, ...MASCOT_STATES, 'project', 'budget', 'skill', ...MASCOT_CARD_POSES]);
|
|
120
124
|
export const MASCOT_REACTIONS = Object.freeze(['hop', 'wince', 'nod', 'pop', 'startle', 'pulse', 'click']);
|
|
121
125
|
|
|
122
|
-
/**
|
|
123
|
-
|
|
126
|
+
/**
|
|
127
|
+
* GIF/PNG art (v3): each file is the whole drawn character (eyes, smile,
|
|
128
|
+
* props), one square image centred in the 280×140 box. It is never
|
|
129
|
+
* clipped into layers and nothing of the vector rig is drawn over it; the
|
|
130
|
+
* live rig moves it only as a whole (a small translate / tilt / scale).
|
|
131
|
+
*/
|
|
132
|
+
// v3 still alpha union (47,43)–(461,469), expanded for GIF cels
|
|
133
|
+
// (10,9)–(469,469). Uniform fit centres the content with vertical clearance.
|
|
134
|
+
export const ART_BOX = Object.freeze({ x: 68, y: -2, size: 144 });
|
|
135
|
+
/** Approved v3 hover-attention.gif duration. */
|
|
136
|
+
export const HOVER_ATTENTION_MS = 1740;
|
|
137
|
+
const ART_GAZE_K = 0.35; // the drawn eyes cannot move: a gaze nudges the whole image a little
|
|
138
|
+
const ART_GAZE_MAX = 6; // viewBox units
|
|
139
|
+
const clampTo = (v, m) => Math.max(-m, Math.min(m, v));
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* The whole-image transform of the art for frame `f` over the pose's own
|
|
143
|
+
* frame `base`: the face's translate / tilt (blends, reactions), a small
|
|
144
|
+
* gaze nudge and a reaction's horizontal squash as a scale. Blinks (eye
|
|
145
|
+
* height) are never applied: the GIF draws its own eyes.
|
|
146
|
+
*/
|
|
147
|
+
export function artTransform(f, base) {
|
|
148
|
+
const r = (v) => Math.round(v * 100) / 100;
|
|
149
|
+
if (!f || !base) return 'translate(0,0) rotate(0 140 70) scale(1)';
|
|
150
|
+
const eyes = (k) => ((f.eyes?.[0]?.[k] ?? 0) - (base.eyes?.[0]?.[k] ?? 0) + (f.eyes?.[1]?.[k] ?? 0) - (base.eyes?.[1]?.[k] ?? 0)) / 2;
|
|
151
|
+
const dx = (f.face.dx - base.face.dx) + clampTo(eyes('dx') * ART_GAZE_K, ART_GAZE_MAX);
|
|
152
|
+
const dy = (f.face.dy - base.face.dy) + clampTo(eyes('dy') * ART_GAZE_K, ART_GAZE_MAX);
|
|
153
|
+
const rot = f.face.rot - base.face.rot;
|
|
154
|
+
const sx = (k) => (f.eyes?.[k]?.sx ?? 1) / ((base.eyes?.[k]?.sx) || 1);
|
|
155
|
+
const s = Math.max(0.9, Math.min(1.1, (sx(0) + sx(1)) / 2));
|
|
156
|
+
return `translate(${r(dx)},${r(dy)}) rotate(${r(rot)} 140 70) translate(140,70) scale(${r(s)}) translate(-140,-70)`;
|
|
157
|
+
}
|
|
158
|
+
function artworkSvg() {
|
|
159
|
+
return `<g class="syna-art-face"><image class="syna-art" x="${ART_BOX.x}" y="${ART_BOX.y}" width="${ART_BOX.size}" height="${ART_BOX.size}" preserveAspectRatio="xMidYMid meet" href="${mascotAsset('idle')}"/></g>`;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/** Keep the original geometry for bounds, pointing arms and the encoder. */
|
|
163
|
+
export function mascotSvg({ width = 280, height = 140, className = '', artwork = true } = {}) {
|
|
124
164
|
return `<svg${className ? ` class="${className}"` : ''} viewBox="${MASCOT_VIEWBOX}" width="${width}" height="${height}" style="overflow:visible" aria-hidden="true" focusable="false">`
|
|
165
|
+
+ (artwork ? artworkSvg() : '')
|
|
125
166
|
+ '<g class="syna-face">'
|
|
126
|
-
+
|
|
127
|
-
+
|
|
128
|
-
+
|
|
129
|
-
+
|
|
167
|
+
+ `<g class="syna-eye"${artwork ? ' visibility="hidden"' : ''}><g class="syna-lid"><rect x="80" y="24" width="38" height="72" rx="19" fill="currentColor"/></g></g>`
|
|
168
|
+
+ `<g class="syna-eye"${artwork ? ' visibility="hidden"' : ''}><g class="syna-lid"><rect x="162" y="24" width="38" height="72" rx="19" fill="currentColor"/></g></g>`
|
|
169
|
+
+ `<path class="syna-mouth"${artwork ? ' visibility="hidden"' : ''} d="M118,116 Q140,130 162,116" fill="none" stroke="currentColor" stroke-opacity=".25" stroke-width="2.5" stroke-linecap="round"/>`
|
|
170
|
+
+ `<g class="syna-props"${artwork ? ' visibility="hidden"' : ''}></g>`
|
|
130
171
|
+ '</g></svg>';
|
|
131
172
|
}
|
|
132
173
|
|
|
@@ -728,6 +769,12 @@ export function poseFrame(name, t = 0, opts = {}) {
|
|
|
728
769
|
const time = Number.isFinite(t) && t > 0 ? t : 0;
|
|
729
770
|
const o = poseOptions(opts);
|
|
730
771
|
const frame = def.frame(time, o);
|
|
772
|
+
// Nonenumerable provenance lets paintMascot(stillFrame(...)) select its
|
|
773
|
+
// PNG, without changing the public frame geometry or blend calculations.
|
|
774
|
+
Object.defineProperties(frame, {
|
|
775
|
+
pose: { value: POSES[name] ? name : 'idle' },
|
|
776
|
+
poseOptions: { value: o },
|
|
777
|
+
});
|
|
731
778
|
return o.still ? markStill(frame) : frame; // the painter makes a still's prop legible at a glance
|
|
732
779
|
}
|
|
733
780
|
|
|
@@ -1939,6 +1986,11 @@ export function paintMascot(svg, frame) {
|
|
|
1939
1986
|
let painter = painters.get(svg);
|
|
1940
1987
|
if (!painter) { painter = createPainter(svg, nextUid()); painters.set(svg, painter); }
|
|
1941
1988
|
painter.paint(frame);
|
|
1989
|
+
const art = svg.querySelector('.syna-art');
|
|
1990
|
+
if (art) {
|
|
1991
|
+
const url = mascotAsset(frame.pose || frame.prop?.name || 'idle', frame.poseOptions);
|
|
1992
|
+
if (art.getAttribute('href') !== url) art.setAttribute('href', url);
|
|
1993
|
+
}
|
|
1942
1994
|
}
|
|
1943
1995
|
|
|
1944
1996
|
// ── Shared runtime: one observer and one motion listener for every rig ──
|
|
@@ -1949,6 +2001,20 @@ const rigs = new Set();
|
|
|
1949
2001
|
let stopMotionWatch = null;
|
|
1950
2002
|
let io = null;
|
|
1951
2003
|
const ioRigs = new WeakMap();
|
|
2004
|
+
let stopArtWatch = null;
|
|
2005
|
+
|
|
2006
|
+
// GIFs do not obey animation-play-state. Replace their source with a PNG
|
|
2007
|
+
// while the shared ticker is paused, including hidden tabs and window drags.
|
|
2008
|
+
// One observer serves all rigs and is released with the last one.
|
|
2009
|
+
function watchArt() {
|
|
2010
|
+
if (stopArtWatch || typeof document === 'undefined') return;
|
|
2011
|
+
const update = () => { for (const rig of rigs) rig.artChanged(); };
|
|
2012
|
+
const observer = typeof MutationObserver === 'function' && document.body
|
|
2013
|
+
? new MutationObserver(update) : null;
|
|
2014
|
+
observer?.observe(document.body, { attributes: true, attributeFilter: ['class'] });
|
|
2015
|
+
document.addEventListener('visibilitychange', update);
|
|
2016
|
+
stopArtWatch = () => { observer?.disconnect(); document.removeEventListener('visibilitychange', update); };
|
|
2017
|
+
}
|
|
1952
2018
|
|
|
1953
2019
|
function observe(el, rig) {
|
|
1954
2020
|
if (typeof IntersectionObserver !== 'function') return;
|
|
@@ -1968,6 +2034,7 @@ function unobserve(el) {
|
|
|
1968
2034
|
|
|
1969
2035
|
function register(rig) {
|
|
1970
2036
|
rigs.add(rig);
|
|
2037
|
+
watchArt();
|
|
1971
2038
|
stopMotionWatch ||= onReducedMotionChange(() => {
|
|
1972
2039
|
for (const r of Array.from(rigs)) r.motionChanged();
|
|
1973
2040
|
});
|
|
@@ -1976,6 +2043,7 @@ function register(rig) {
|
|
|
1976
2043
|
function unregister(rig) {
|
|
1977
2044
|
rigs.delete(rig);
|
|
1978
2045
|
if (!rigs.size && stopMotionWatch) { stopMotionWatch(); stopMotionWatch = null; }
|
|
2046
|
+
if (!rigs.size && stopArtWatch) { stopArtWatch(); stopArtWatch = null; }
|
|
1979
2047
|
}
|
|
1980
2048
|
|
|
1981
2049
|
const BLEND_MS = 160;
|
|
@@ -2003,6 +2071,7 @@ export function createMascot(container, options) {
|
|
|
2003
2071
|
const {
|
|
2004
2072
|
width = 128, height = 64, rangeX, rangeY, className = 'synabun-mascot',
|
|
2005
2073
|
pose: firstPose = 'idle', poseOptions: firstOptions, active: startActive, arms: armsOption,
|
|
2074
|
+
idleVariant = 'default',
|
|
2006
2075
|
} = opts || {};
|
|
2007
2076
|
const markup = mascotSvg({ width, height, className });
|
|
2008
2077
|
let svg;
|
|
@@ -2016,6 +2085,20 @@ export function createMascot(container, options) {
|
|
|
2016
2085
|
svg.remove();
|
|
2017
2086
|
}
|
|
2018
2087
|
const painter = createPainter(svg, nextUid());
|
|
2088
|
+
const art = svg.querySelector('.syna-art');
|
|
2089
|
+
const artFace = svg.querySelector('.syna-art-face');
|
|
2090
|
+
let artSource = '';
|
|
2091
|
+
// The empty page's hero: hovering it (or attention()) plays hover-attention
|
|
2092
|
+
// once over idle-hero, then idle-hero again. Never under reduced motion.
|
|
2093
|
+
const hero = idleVariant === 'hero';
|
|
2094
|
+
let attentionUntil = -Infinity;
|
|
2095
|
+
let attentionTimer = 0;
|
|
2096
|
+
let stopHover = null;
|
|
2097
|
+
if (hero && art && typeof svg.addEventListener === 'function') {
|
|
2098
|
+
const onEnter = () => attention();
|
|
2099
|
+
svg.addEventListener('pointerenter', onEnter);
|
|
2100
|
+
stopHover = () => svg.removeEventListener('pointerenter', onEnter);
|
|
2101
|
+
}
|
|
2019
2102
|
painters.set(svg, painter); // paintMascot() on a live rig's SVG reuses its props
|
|
2020
2103
|
const range = { x: Math.max(RANGE.x, Number(rangeX) || 0), y: Math.max(RANGE.y, Number(rangeY) || 0) };
|
|
2021
2104
|
|
|
@@ -2273,7 +2356,40 @@ export function createMascot(container, options) {
|
|
|
2273
2356
|
/** Paint a face frame; while an arm is out its eyes keep to MASCOT_ARM.gaze (never toward an arm). */
|
|
2274
2357
|
function paintFace(f) {
|
|
2275
2358
|
if (arms) arms.sim.prop(f?.prop?.name || null); // an arm whose shoulder this prop covers roots under it
|
|
2276
|
-
|
|
2359
|
+
const shown = arms ? armGaze(f, arms.sim.presence()) : f;
|
|
2360
|
+
painter.paint(shown);
|
|
2361
|
+
paintArt(shown);
|
|
2362
|
+
}
|
|
2363
|
+
|
|
2364
|
+
function paintArt(f = lastFrame || stillFrameNow()) {
|
|
2365
|
+
if (!art) return;
|
|
2366
|
+
const animated = animating() && !tickerPaused() && !destroyed;
|
|
2367
|
+
const attending = animated && hero && pose.name === 'idle' && tickerNow() < attentionUntil;
|
|
2368
|
+
const url = attending
|
|
2369
|
+
? mascotAssetUrl('hover-attention', { animated: true })
|
|
2370
|
+
: mascotAsset(pose.name, { ...pose.raw, ticks }, { animated, hero });
|
|
2371
|
+
// Never rewrite a running GIF's href every frame: that restarts playback.
|
|
2372
|
+
if (artSource !== url) {
|
|
2373
|
+
artSource = url;
|
|
2374
|
+
// Separate playback identities let two panels acknowledge completion
|
|
2375
|
+
// independently, and a later turn can replay the same one-shot.
|
|
2376
|
+
art.setAttribute('href', animated ? `${url}&play=${nextUid()}` : url);
|
|
2377
|
+
}
|
|
2378
|
+
if (artFace) {
|
|
2379
|
+
const value = artTransform(f, poseFrame(pose.name, poseTime(), { ...pose.raw, ticks, still: !playing() }));
|
|
2380
|
+
if (artFace.getAttribute('transform') !== value) artFace.setAttribute('transform', value);
|
|
2381
|
+
}
|
|
2382
|
+
}
|
|
2383
|
+
|
|
2384
|
+
/** Play hover-attention once over the hero's idle (no-op elsewhere or under reduced motion). */
|
|
2385
|
+
function attention() {
|
|
2386
|
+
if (destroyed || !hero || !art || !animating() || pose.name !== 'idle') return api;
|
|
2387
|
+
if (tickerNow() < attentionUntil) return api; // already playing: never restart mid-way
|
|
2388
|
+
attentionUntil = tickerNow() + HOVER_ATTENTION_MS;
|
|
2389
|
+
clearTickerTimeout(attentionTimer);
|
|
2390
|
+
attentionTimer = tickerTimeout(() => { attentionTimer = 0; if (!destroyed) paintArt(); }, HOVER_ATTENTION_MS + 20);
|
|
2391
|
+
paintArt();
|
|
2392
|
+
return api;
|
|
2277
2393
|
}
|
|
2278
2394
|
|
|
2279
2395
|
function compose() {
|
|
@@ -2642,12 +2758,17 @@ export function createMascot(container, options) {
|
|
|
2642
2758
|
function destroy() {
|
|
2643
2759
|
if (destroyed) return;
|
|
2644
2760
|
destroyed = true;
|
|
2761
|
+
paintArt();
|
|
2645
2762
|
setRate(0);
|
|
2646
2763
|
clearWake();
|
|
2647
2764
|
stopPointer?.();
|
|
2648
2765
|
stopPointer = null;
|
|
2649
2766
|
stopKey?.();
|
|
2650
2767
|
stopKey = null;
|
|
2768
|
+
stopHover?.();
|
|
2769
|
+
stopHover = null;
|
|
2770
|
+
clearTickerTimeout(attentionTimer);
|
|
2771
|
+
attentionTimer = 0;
|
|
2651
2772
|
unobserve(svg);
|
|
2652
2773
|
stopArmWatch();
|
|
2653
2774
|
svg.removeEventListener('animationend', onAnimationEnd);
|
|
@@ -2657,6 +2778,7 @@ export function createMascot(container, options) {
|
|
|
2657
2778
|
}
|
|
2658
2779
|
|
|
2659
2780
|
const rig = {
|
|
2781
|
+
artChanged() { paintArt(); },
|
|
2660
2782
|
visibilityChanged(inView) {
|
|
2661
2783
|
if (destroyed) return;
|
|
2662
2784
|
if (svg.isConnected) seenConnected = true;
|
|
@@ -2680,6 +2802,8 @@ export function createMascot(container, options) {
|
|
|
2680
2802
|
blink,
|
|
2681
2803
|
setPose,
|
|
2682
2804
|
react,
|
|
2805
|
+
/** The empty page hero only: play hover-attention once, then idle-hero again. */
|
|
2806
|
+
attention,
|
|
2683
2807
|
setActive,
|
|
2684
2808
|
point,
|
|
2685
2809
|
/** Two quick pokes toward what the arm points at (the beat landed). */
|
|
@@ -2746,7 +2870,7 @@ export function createMascot(container, options) {
|
|
|
2746
2870
|
register(rig);
|
|
2747
2871
|
svg.addEventListener('animationend', onAnimationEnd);
|
|
2748
2872
|
lastFrame = stillFrameNow();
|
|
2749
|
-
|
|
2873
|
+
paintFace(lastFrame);
|
|
2750
2874
|
observe(svg, rig);
|
|
2751
2875
|
if (animating()) {
|
|
2752
2876
|
scheduleIdle();
|
|
@@ -84,6 +84,9 @@ function cafFn() {
|
|
|
84
84
|
}
|
|
85
85
|
const later = (fn, ms) => (env?.setTimeout || globalThis.setTimeout)(fn, ms);
|
|
86
86
|
const unlater = id => (env?.clearTimeout || globalThis.clearTimeout)(id);
|
|
87
|
+
/** A timer on the ticker's clock (the injected one under test). */
|
|
88
|
+
export const tickerTimeout = (fn, ms) => later(fn, ms);
|
|
89
|
+
export const clearTickerTimeout = (id) => { if (id) unlater(id); };
|
|
87
90
|
|
|
88
91
|
function report(err) {
|
|
89
92
|
try { console.error('[synabun-ticker]', err); } catch { /* no console */ }
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
// ── The owner's review and approval of what an agent changed (re-review of 2026-11-11, finding 3) ──
|
|
2
|
+
//
|
|
3
|
+
// One dialog for both places that show a mark: the Schedules window (a schedule, and with it its template) and
|
|
4
|
+
// Automation Studio (a template). It shows what the server says will run and where (GET …/review), and its Approve
|
|
5
|
+
// button sends back the digest of exactly that review (POST …/approve). When the server answers 409 REVIEW_CHANGED
|
|
6
|
+
// (something changed after the review was served, possibly an agent) the dialog shows the fresh review instead and
|
|
7
|
+
// says so; nothing was approved. The words are in automation-approval-view.js; the strings in i18n
|
|
8
|
+
// `automationApproval.*`. The app's own markup only: no native dialog, no native select.
|
|
9
|
+
|
|
10
|
+
import { t, getLocale } from './i18n.js';
|
|
11
|
+
import { accountText, afterApprovalText, scheduleFlag, sourceText, weekdayName } from './automation-approval-view.js';
|
|
12
|
+
|
|
13
|
+
const esc = (value) => String(value ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c]));
|
|
14
|
+
|
|
15
|
+
const paths = {
|
|
16
|
+
schedule: (id) => `/api/schedules/${encodeURIComponent(id)}`,
|
|
17
|
+
template: (id) => `/api/loop/templates/${encodeURIComponent(id)}`,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
async function request(url, options = {}) {
|
|
21
|
+
const res = await fetch(url, { credentials: 'same-origin', ...options });
|
|
22
|
+
let body = null;
|
|
23
|
+
try { body = await res.json(); } catch { body = null; }
|
|
24
|
+
if (!res.ok) {
|
|
25
|
+
const err = new Error(body?.error || `HTTP ${res.status}`);
|
|
26
|
+
err.status = res.status; err.code = body?.code; err.body = body;
|
|
27
|
+
throw err;
|
|
28
|
+
}
|
|
29
|
+
return body;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** The marked schedules and templates, for the flags: { schedules: { id: summary }, templates: { id: summary } }. */
|
|
33
|
+
export async function fetchAutomationApprovals() {
|
|
34
|
+
try {
|
|
35
|
+
const body = await request('/api/automation-approvals');
|
|
36
|
+
return { schedules: body?.schedules || {}, templates: body?.templates || {} };
|
|
37
|
+
} catch {
|
|
38
|
+
// An older server (no route) or a guest: no flags from the server; the records' own marks still show.
|
|
39
|
+
return { schedules: {}, templates: {} };
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
let _open = null; // { kind, id, opener, onApproved, review, root, keydown }
|
|
44
|
+
|
|
45
|
+
function instructionsHTML(review) {
|
|
46
|
+
const ins = review.instructions || {};
|
|
47
|
+
const block = (label, text, empty) => `<section class="aap-block"><h5>${esc(label)}</h5>${text ? `<pre class="aap-text">${esc(text)}</pre>` : `<p class="aap-muted">${esc(empty)}</p>`}</section>`;
|
|
48
|
+
const parts = [];
|
|
49
|
+
if (review.kind === 'schedule') {
|
|
50
|
+
parts.push(`<p class="aap-line"><span class="aap-key">${esc(t('automationApproval.dialog.template'))}</span> ${ins.templateMissing ? `<span class="aap-warn">${esc(t('automationApproval.dialog.templateMissing'))}</span>` : esc(ins.templateName || ins.templateId || '')}${review.marks?.template ? ` <span class="aap-chip">${esc(sourceText(review.marks.templateFrom, t))}</span>` : ''}</p>`);
|
|
51
|
+
}
|
|
52
|
+
parts.push(block(t('automationApproval.dialog.task'), ins.task, t('automationApproval.dialog.none')));
|
|
53
|
+
parts.push(block(t('automationApproval.dialog.context'), ins.context, t('automationApproval.dialog.none')));
|
|
54
|
+
if (review.kind === 'schedule') {
|
|
55
|
+
const themes = Array.isArray(ins.dayThemes) ? ins.dayThemes : [];
|
|
56
|
+
parts.push(`<section class="aap-block"><h5>${esc(t('automationApproval.dialog.dayThemes'))}</h5>${themes.length
|
|
57
|
+
? themes.map((d) => `<div class="aap-theme"><span class="aap-key">${esc(weekdayName(d.day, getLocale?.() || 'en'))}${d.label ? ` · ${esc(d.label)}` : ''}</span>${d.text ? `<pre class="aap-text">${esc(d.text)}</pre>` : `<p class="aap-muted">${esc(t('automationApproval.dialog.themeNoText'))}</p>`}</div>`).join('')
|
|
58
|
+
: `<p class="aap-muted">${esc(t('automationApproval.dialog.noDayThemes'))}</p>`}</section>`);
|
|
59
|
+
if (ins.iterations != null || ins.maxMinutes != null) {
|
|
60
|
+
parts.push(`<p class="aap-line"><span class="aap-key">${esc(t('automationApproval.dialog.limits'))}</span> ${esc(t('automationApproval.dialog.limitsValue', { iterations: ins.iterations ?? '—', minutes: ins.maxMinutes ?? '—' }))}</p>`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return parts.join('');
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function accountHTML(review) {
|
|
67
|
+
if (review.kind === 'template') {
|
|
68
|
+
const used = Array.isArray(review.usedBy) ? review.usedBy : [];
|
|
69
|
+
return `<section class="aap-block"><h5>${esc(t('automationApproval.dialog.usedBy'))}</h5>${used.length
|
|
70
|
+
? `<ul class="aap-list">${used.map((u) => `<li>${esc(u.name || u.id)} · ${esc(accountText(u.account, t))}${u.marked ? ` <span class="aap-chip">${esc(t('automationApproval.dialog.scheduleAlsoMarked'))}</span>` : ''}</li>`).join('')}</ul>`
|
|
71
|
+
: `<p class="aap-muted">${esc(t('automationApproval.dialog.usedByNone'))}</p>`}</section>`;
|
|
72
|
+
}
|
|
73
|
+
const a = review.account || {};
|
|
74
|
+
const listNote = a.kind === 'morelogin'
|
|
75
|
+
? (a.onList ? t('automationApproval.dialog.onList') : t('automationApproval.dialog.offList'))
|
|
76
|
+
: '';
|
|
77
|
+
const chosen = a.kind === 'morelogin' ? (a.chosenBy === 'owner' ? t('automationApproval.dialog.chosenByOwner') : t('automationApproval.dialog.chosenByAgent')) : '';
|
|
78
|
+
return `<section class="aap-block aap-account"><h5>${esc(t('automationApproval.dialog.account'))}</h5>
|
|
79
|
+
<p class="aap-line aap-strong">${esc(accountText(a, t))}</p>
|
|
80
|
+
${chosen ? `<p class="aap-muted">${esc(chosen)}</p>` : ''}
|
|
81
|
+
${listNote ? `<p class="aap-muted">${esc(listNote)}</p>` : ''}
|
|
82
|
+
</section>`;
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function dialogHTML(review, { changed = false, error = '' } = {}) {
|
|
86
|
+
const title = review.kind === 'schedule' ? t('automationApproval.dialog.scheduleTitle') : t('automationApproval.dialog.templateTitle');
|
|
87
|
+
const flag = review.kind === 'schedule' ? scheduleFlag(review, t) : null;
|
|
88
|
+
const marked = review.needsApproval === true;
|
|
89
|
+
return `<div class="aap-dialog" role="dialog" aria-modal="true" aria-labelledby="aap-title" aria-describedby="aap-intro">
|
|
90
|
+
<h4 id="aap-title">${esc(title)}</h4>
|
|
91
|
+
<div class="aap-body">
|
|
92
|
+
<p class="aap-name">${esc(review.name || review.id)}</p>
|
|
93
|
+
${changed ? `<p class="aap-notice aap-warn" role="alert">${esc(t('automationApproval.dialog.changed'))}</p>` : ''}
|
|
94
|
+
${error ? `<p class="aap-notice aap-warn" role="alert">${esc(error)}</p>` : ''}
|
|
95
|
+
<p class="aap-help" id="aap-intro">${esc(marked ? (flag?.text || t('automationApproval.dialog.intro')) : t('automationApproval.dialog.nothing'))}</p>
|
|
96
|
+
${accountHTML(review)}
|
|
97
|
+
<h5 class="aap-section">${esc(t('automationApproval.dialog.whatRuns'))}</h5>
|
|
98
|
+
<p class="aap-muted">${esc(t('automationApproval.dialog.wholeContent'))}</p>
|
|
99
|
+
${instructionsHTML(review)}
|
|
100
|
+
${marked ? `<p class="aap-help">${esc(afterApprovalText(review, t))}</p>` : ''}
|
|
101
|
+
</div>
|
|
102
|
+
<div class="aap-actions">
|
|
103
|
+
<button type="button" class="aap-btn" data-aap="cancel">${esc(t('automationApproval.dialog.cancel'))}</button>
|
|
104
|
+
${marked ? `<button type="button" class="aap-btn aap-btn--primary" data-aap="approve">${esc(review.kind === 'schedule' && review.marks?.template && review.marks?.schedule ? t('automationApproval.dialog.approveBoth') : t('automationApproval.dialog.approve'))}</button>` : ''}
|
|
105
|
+
</div>
|
|
106
|
+
</div>`;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function render(state) {
|
|
110
|
+
if (!_open) return;
|
|
111
|
+
_open.root.innerHTML = dialogHTML(_open.review, state);
|
|
112
|
+
const focus = _open.root.querySelector('[data-aap="approve"]') || _open.root.querySelector('[data-aap="cancel"]');
|
|
113
|
+
focus?.focus();
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
export function closeApprovalDialog() {
|
|
117
|
+
if (!_open) return;
|
|
118
|
+
const { root, opener, keydown } = _open;
|
|
119
|
+
document.removeEventListener('keydown', keydown, true);
|
|
120
|
+
root.remove();
|
|
121
|
+
_open = null;
|
|
122
|
+
if (opener?.isConnected) opener.focus();
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
async function approve(button) {
|
|
126
|
+
if (!_open) return;
|
|
127
|
+
const { kind, id, review } = _open;
|
|
128
|
+
button.disabled = true;
|
|
129
|
+
try {
|
|
130
|
+
const out = await request(`${paths[kind](id)}/approve`, {
|
|
131
|
+
method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ digest: review.digest }),
|
|
132
|
+
});
|
|
133
|
+
const done = _open.onApproved;
|
|
134
|
+
closeApprovalDialog();
|
|
135
|
+
try { done?.(out); } catch { /* the caller's own refresh */ }
|
|
136
|
+
} catch (err) {
|
|
137
|
+
if (!_open) return;
|
|
138
|
+
if (err.code === 'REVIEW_CHANGED' && err.body?.review) {
|
|
139
|
+
_open.review = err.body.review;
|
|
140
|
+
render({ changed: true });
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
button.disabled = false;
|
|
144
|
+
render({ error: t('automationApproval.dialog.failed', { error: err.message }) });
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Opens the review of a schedule (and its template) or of a template.
|
|
150
|
+
* @param {{ kind: 'schedule'|'template', id: string, opener?: HTMLElement|null, onApproved?: (result) => void,
|
|
151
|
+
* onError?: (message: string) => void }} o
|
|
152
|
+
*/
|
|
153
|
+
export async function openApprovalDialog({ kind, id, opener = null, onApproved = null, onError = null }) {
|
|
154
|
+
closeApprovalDialog();
|
|
155
|
+
let review;
|
|
156
|
+
try {
|
|
157
|
+
review = (await request(`${paths[kind](id)}/review`))?.review;
|
|
158
|
+
} catch (err) {
|
|
159
|
+
onError?.(t('automationApproval.dialog.loadFailed', { error: err.message }));
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (!review) { onError?.(t('automationApproval.dialog.loadFailed', { error: 'no review' })); return; }
|
|
163
|
+
const root = document.createElement('div');
|
|
164
|
+
root.className = 'aap-modal';
|
|
165
|
+
root.addEventListener('click', (e) => {
|
|
166
|
+
const action = e.target.closest?.('[data-aap]')?.dataset.aap;
|
|
167
|
+
if (action === 'cancel') closeApprovalDialog();
|
|
168
|
+
else if (action === 'approve') approve(e.target.closest('[data-aap]'));
|
|
169
|
+
else if (e.target === root) closeApprovalDialog();
|
|
170
|
+
});
|
|
171
|
+
// Keys are the dialog's while it is open (capture phase, as the app's other popups).
|
|
172
|
+
const keydown = (e) => {
|
|
173
|
+
if (!_open) return;
|
|
174
|
+
if (e.key === 'Escape') { e.preventDefault(); e.stopPropagation(); closeApprovalDialog(); return; }
|
|
175
|
+
if (e.key === 'Tab') {
|
|
176
|
+
const items = [..._open.root.querySelectorAll('button:not([disabled])')];
|
|
177
|
+
if (!items.length) return;
|
|
178
|
+
const first = items[0]; const last = items[items.length - 1];
|
|
179
|
+
if (e.shiftKey && document.activeElement === first) { e.preventDefault(); last.focus(); }
|
|
180
|
+
else if (!e.shiftKey && document.activeElement === last) { e.preventDefault(); first.focus(); }
|
|
181
|
+
else if (!_open.root.contains(document.activeElement)) { e.preventDefault(); first.focus(); }
|
|
182
|
+
}
|
|
183
|
+
};
|
|
184
|
+
document.addEventListener('keydown', keydown, true);
|
|
185
|
+
document.body.appendChild(root);
|
|
186
|
+
_open = { kind, id, opener, onApproved, review, root, keydown };
|
|
187
|
+
render({});
|
|
188
|
+
}
|