synabun 2.3.1 → 2.4.1
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 +41 -0
- package/README.md +1 -1
- package/browser-extension/content.js +189 -0
- package/browser-extension/engine.js +508 -0
- package/browser-extension/icons/icon-128.png +0 -0
- package/browser-extension/icons/icon-16.png +0 -0
- package/browser-extension/icons/icon-32.png +0 -0
- package/browser-extension/icons/icon-48.png +0 -0
- package/browser-extension/icons/status-off-16.png +0 -0
- package/browser-extension/icons/status-off-32.png +0 -0
- package/browser-extension/icons/status-off-48.png +0 -0
- package/browser-extension/icons/status-on-16.png +0 -0
- package/browser-extension/icons/status-on-32.png +0 -0
- package/browser-extension/icons/status-on-48.png +0 -0
- package/browser-extension/manifest.json +56 -0
- package/browser-extension/popup-strings.js +250 -0
- package/browser-extension/popup-view.js +151 -0
- package/browser-extension/popup.css +166 -0
- package/browser-extension/popup.html +108 -0
- package/browser-extension/popup.js +359 -0
- package/browser-extension/protocol.js +232 -0
- package/browser-extension/service-worker.js +275 -0
- package/browser-extension/setup-content.js +36 -0
- package/browser-extension/tokens.css +326 -0
- package/docs/browser-extension-bridge.md +84 -0
- package/docs/whatsapp.md +1 -1
- package/lib/data-home-files.js +45 -0
- package/lib/data-home-migration.js +34 -58
- package/mcp-server/dist/http.d.ts +2 -0
- package/mcp-server/dist/http.d.ts.map +1 -1
- package/mcp-server/dist/http.js +9 -1
- package/mcp-server/dist/http.js.map +1 -1
- package/mcp-server/dist/index.d.ts +11 -0
- package/mcp-server/dist/index.d.ts.map +1 -1
- package/mcp-server/dist/index.js +38 -3
- package/mcp-server/dist/index.js.map +1 -1
- package/mcp-server/dist/services/browser-route-flow.d.ts +6 -2
- package/mcp-server/dist/services/browser-route-flow.d.ts.map +1 -1
- package/mcp-server/dist/services/browser-route-flow.js +10 -3
- package/mcp-server/dist/services/browser-route-flow.js.map +1 -1
- package/mcp-server/dist/services/codex-config-heal.d.ts.map +1 -1
- package/mcp-server/dist/services/codex-config-heal.js +7 -0
- package/mcp-server/dist/services/codex-config-heal.js.map +1 -1
- package/mcp-server/dist/services/neural-interface.d.ts +95 -3
- package/mcp-server/dist/services/neural-interface.d.ts.map +1 -1
- package/mcp-server/dist/services/neural-interface.js +168 -23
- package/mcp-server/dist/services/neural-interface.js.map +1 -1
- package/mcp-server/dist/services/team-context.d.ts +18 -0
- package/mcp-server/dist/services/team-context.d.ts.map +1 -0
- package/mcp-server/dist/services/team-context.js +29 -0
- package/mcp-server/dist/services/team-context.js.map +1 -0
- package/mcp-server/dist/services/tool-catalog.d.ts +5 -2
- package/mcp-server/dist/services/tool-catalog.d.ts.map +1 -1
- package/mcp-server/dist/services/tool-catalog.js +22 -6
- package/mcp-server/dist/services/tool-catalog.js.map +1 -1
- package/mcp-server/dist/services/tool-list.d.ts.map +1 -1
- package/mcp-server/dist/services/tool-list.js +4 -0
- package/mcp-server/dist/services/tool-list.js.map +1 -1
- package/mcp-server/dist/services/tool-runtime.d.ts +8 -1
- package/mcp-server/dist/services/tool-runtime.d.ts.map +1 -1
- package/mcp-server/dist/services/tool-runtime.js +18 -1
- package/mcp-server/dist/services/tool-runtime.js.map +1 -1
- package/mcp-server/dist/tools/agent-definition.d.ts +133 -0
- package/mcp-server/dist/tools/agent-definition.d.ts.map +1 -0
- package/mcp-server/dist/tools/agent-definition.js +483 -0
- package/mcp-server/dist/tools/agent-definition.js.map +1 -0
- package/mcp-server/dist/tools/agents.d.ts +92 -9
- package/mcp-server/dist/tools/agents.d.ts.map +1 -1
- package/mcp-server/dist/tools/agents.js +163 -20
- package/mcp-server/dist/tools/agents.js.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts +8 -1
- package/mcp-server/dist/tools/browser-advanced.d.ts.map +1 -1
- package/mcp-server/dist/tools/browser-advanced.js +70 -6
- package/mcp-server/dist/tools/browser-advanced.js.map +1 -1
- package/mcp-server/dist/tools/git-tools.d.ts +4 -2
- package/mcp-server/dist/tools/git-tools.d.ts.map +1 -1
- package/mcp-server/dist/tools/git-tools.js +283 -2
- package/mcp-server/dist/tools/git-tools.js.map +1 -1
- package/mcp-server/dist/tools/morelogin.d.ts +8 -2
- package/mcp-server/dist/tools/morelogin.d.ts.map +1 -1
- package/mcp-server/dist/tools/morelogin.js +22 -5
- package/mcp-server/dist/tools/morelogin.js.map +1 -1
- package/mcp-server/dist/tools/team.d.ts +32 -0
- package/mcp-server/dist/tools/team.d.ts.map +1 -0
- package/mcp-server/dist/tools/team.js +87 -0
- package/mcp-server/dist/tools/team.js.map +1 -0
- package/mcp-server/package-lock.json +2 -2
- package/mcp-server/package.json +1 -1
- package/mcp-server/src/http.ts +9 -1
- package/mcp-server/src/index.ts +34 -4
- package/mcp-server/src/services/browser-route-flow.ts +12 -5
- package/mcp-server/src/services/codex-config-heal.ts +7 -0
- package/mcp-server/src/services/neural-interface.ts +191 -29
- package/mcp-server/src/services/team-context.ts +27 -0
- package/mcp-server/src/services/tool-catalog.ts +26 -8
- package/mcp-server/src/services/tool-list.ts +4 -0
- package/mcp-server/src/services/tool-runtime.ts +21 -2
- package/mcp-server/src/tools/agent-definition.ts +458 -0
- package/mcp-server/src/tools/agents.ts +177 -19
- package/mcp-server/src/tools/browser-advanced.ts +60 -6
- package/mcp-server/src/tools/git-tools.ts +249 -3
- package/mcp-server/src/tools/morelogin.ts +20 -5
- package/mcp-server/src/tools/team.ts +97 -0
- package/neural-interface/i18n/en.json +1119 -47
- package/neural-interface/i18n/pt-BR.json +1119 -47
- package/neural-interface/lib/account-usage.js +1 -1
- package/neural-interface/lib/agents/builtins.json +207 -0
- package/neural-interface/lib/agents/density.js +101 -0
- package/neural-interface/lib/agents/forge-host.js +223 -0
- package/neural-interface/lib/agents/native-export-targets.js +190 -0
- package/neural-interface/lib/agents/native-export.js +365 -0
- package/neural-interface/lib/agents/registry.js +885 -0
- package/neural-interface/lib/agents/resolve.js +603 -0
- package/neural-interface/lib/agents/schema.js +642 -0
- package/neural-interface/lib/agents/split.js +37 -0
- package/neural-interface/lib/agents-studio-api.js +591 -0
- package/neural-interface/lib/assistant-api.js +76 -7
- package/neural-interface/lib/assistant-brains/opencode.js +60 -11
- package/neural-interface/lib/assistant-catalog.js +2 -0
- package/neural-interface/lib/assistant-continuity.js +49 -0
- package/neural-interface/lib/assistant-dispatch.js +351 -121
- package/neural-interface/lib/assistant-persona.js +105 -8
- package/neural-interface/lib/assistant-route-gate.js +24 -9
- package/neural-interface/lib/assistant-router.js +432 -47
- package/neural-interface/lib/assistant-run-tail.js +151 -0
- package/neural-interface/lib/assistant-run-wait.js +183 -0
- package/neural-interface/lib/assistant-runtime.js +449 -94
- package/neural-interface/lib/assistant-task-prompt.js +11 -2
- package/neural-interface/lib/assistant-usage.js +3 -2
- package/neural-interface/lib/automation-approval.js +2 -2
- package/neural-interface/lib/backup-service.js +64 -105
- package/neural-interface/lib/browser-close-evidence.js +80 -0
- package/neural-interface/lib/browser-default.js +210 -0
- package/neural-interface/lib/browser-extension-adapter.js +264 -0
- package/neural-interface/lib/browser-extension-bridge.js +441 -0
- package/neural-interface/lib/browser-extension-folder.js +116 -0
- package/neural-interface/lib/browser-extension-setup.js +140 -0
- package/neural-interface/lib/browser-profile-choices.js +3 -3
- package/neural-interface/lib/browser-tool-policy.js +1 -1
- package/neural-interface/lib/claude-account-links.js +301 -0
- package/neural-interface/lib/claude-accounts.js +45 -20
- package/neural-interface/lib/claude-agent-bridge.js +142 -10
- package/neural-interface/lib/claude-model-catalog.js +6 -0
- package/neural-interface/lib/claude-panel-session.js +33 -0
- package/neural-interface/lib/codex-accounts.js +67 -24
- package/neural-interface/lib/coordination/README.md +384 -0
- package/neural-interface/lib/coordination/service.js +563 -0
- package/neural-interface/lib/coordination/store.js +1138 -0
- package/neural-interface/lib/db.js +22 -1
- package/neural-interface/lib/effort-levels.js +10 -1
- package/neural-interface/lib/memory-list-page.js +49 -0
- package/neural-interface/lib/memory-list-stamp.js +60 -0
- package/neural-interface/lib/morelogin-outside-close.js +186 -0
- package/neural-interface/lib/morelogin-profile-failures.js +206 -0
- package/neural-interface/lib/morelogin-start-cooldown.js +160 -0
- package/neural-interface/lib/morelogin.js +194 -8
- package/neural-interface/lib/native-loop-runtime.js +26 -7
- package/neural-interface/lib/opencode-build-preflight.js +28 -8
- package/neural-interface/lib/opencode-native-boundary.js +83 -13
- package/neural-interface/lib/opencode-serve-records.js +14 -9
- package/neural-interface/lib/page-session.js +1 -1
- package/neural-interface/lib/peer-identity.js +73 -29
- package/neural-interface/lib/process-identity.js +68 -7
- package/neural-interface/lib/request-gate.js +3 -0
- package/neural-interface/lib/screenshot-location.js +33 -0
- package/neural-interface/lib/session-cache-builder.js +41 -3
- package/neural-interface/lib/skills/creation.js +1 -1
- package/neural-interface/lib/skills/known-bridge-digests.json +40 -0
- package/neural-interface/lib/studio-attention.js +56 -0
- package/neural-interface/lib/teams/README.md +382 -0
- package/neural-interface/lib/teams/api.js +287 -0
- package/neural-interface/lib/teams/brief.js +185 -0
- package/neural-interface/lib/teams/claims.js +315 -0
- package/neural-interface/lib/teams/git.js +293 -0
- package/neural-interface/lib/teams/index.js +122 -0
- package/neural-interface/lib/teams/integration.js +580 -0
- package/neural-interface/lib/teams/landing.js +184 -0
- package/neural-interface/lib/teams/recovery.js +256 -0
- package/neural-interface/lib/teams/scheduler.js +1474 -0
- package/neural-interface/lib/teams/schema.js +559 -0
- package/neural-interface/lib/teams/state.js +181 -0
- package/neural-interface/lib/teams/test-runner.js +86 -0
- package/neural-interface/lib/teams/test-sandbox.js +99 -0
- package/neural-interface/lib/teams/worktrees.js +757 -0
- package/neural-interface/lib/tool-permission-choices.js +226 -0
- package/neural-interface/lib/whatsapp/cards.js +24 -10
- package/neural-interface/lib/worker-confinement.js +206 -6
- package/neural-interface/package-lock.json +2 -2
- package/neural-interface/package.json +1 -1
- package/neural-interface/public/extension-setup.html +107 -0
- package/neural-interface/public/index.html +103 -12
- package/neural-interface/public/offline.html +4 -3
- package/neural-interface/public/shared/agent-runtime-options.js +3 -1
- package/neural-interface/public/shared/agents/studio/ax-agent-view.js +614 -0
- package/neural-interface/public/shared/agents/studio/ax-api.js +198 -0
- package/neural-interface/public/shared/agents/studio/ax-create-view.js +221 -0
- package/neural-interface/public/shared/agents/studio/ax-diff.js +143 -0
- package/neural-interface/public/shared/agents/studio/ax-editor-view.js +392 -0
- package/neural-interface/public/shared/agents/studio/ax-export-view.js +94 -0
- package/neural-interface/public/shared/agents/studio/ax-form.js +191 -0
- package/neural-interface/public/shared/agents/studio/ax-icons.js +87 -0
- package/neural-interface/public/shared/agents/studio/ax-library-view.js +158 -0
- package/neural-interface/public/shared/agents/studio/ax-library.js +162 -0
- package/neural-interface/public/shared/agents/studio/ax-main.js +712 -0
- package/neural-interface/public/shared/agents/studio/ax-native-export.js +35 -0
- package/neural-interface/public/shared/agents/studio/ax-options.js +198 -0
- package/neural-interface/public/shared/agents/studio/ax-review-view.js +175 -0
- package/neural-interface/public/shared/agents/studio/ax-revisions-view.js +189 -0
- package/neural-interface/public/shared/agents/studio/ax-runs-view.js +202 -0
- package/neural-interface/public/shared/agents/studio/ax-runs.js +82 -0
- package/neural-interface/public/shared/agents/studio/ax-teams-view.js +256 -0
- package/neural-interface/public/shared/agents/studio/ax-teams.js +200 -0
- package/neural-interface/public/shared/agents/studio/ax-templates.js +50 -0
- package/neural-interface/public/shared/agents/studio/ax-ui.js +194 -0
- package/neural-interface/public/shared/agents/studio/ax-views.js +170 -0
- package/neural-interface/public/shared/agy/agy-panel.js +142 -28
- package/neural-interface/public/shared/agy/agy-styles.js +25 -5
- package/neural-interface/public/shared/api.js +2 -1
- package/neural-interface/public/shared/assistant/asst-account-menu.js +13 -13
- package/neural-interface/public/shared/assistant/asst-ask-styles.js +2 -3
- package/neural-interface/public/shared/assistant/asst-brain-picker.js +91 -9
- package/neural-interface/public/shared/assistant/asst-control.js +3 -0
- package/neural-interface/public/shared/assistant/asst-interaction-hold.js +99 -0
- package/neural-interface/public/shared/assistant/asst-limit-dismissals.js +111 -0
- package/neural-interface/public/shared/assistant/asst-limit-dock.js +37 -3
- package/neural-interface/public/shared/assistant/asst-limit-wait.js +30 -7
- package/neural-interface/public/shared/assistant/asst-panel.js +177 -30
- package/neural-interface/public/shared/assistant/asst-rack-styles.js +15 -8
- package/neural-interface/public/shared/assistant/asst-render.js +37 -6
- package/neural-interface/public/shared/assistant/asst-route.js +80 -12
- package/neural-interface/public/shared/assistant/asst-routes-editor.js +148 -70
- package/neural-interface/public/shared/assistant/asst-roving.js +17 -1
- package/neural-interface/public/shared/assistant/asst-scene-styles.js +7 -2
- package/neural-interface/public/shared/assistant/asst-scenes.js +12 -1
- package/neural-interface/public/shared/assistant/asst-sidepanel.js +12 -2
- package/neural-interface/public/shared/assistant/asst-state.js +66 -1
- package/neural-interface/public/shared/assistant/asst-styles.js +98 -44
- package/neural-interface/public/shared/assistant/route-identity.js +16 -0
- package/neural-interface/public/shared/cc-dropdown.js +21 -15
- package/neural-interface/public/shared/cdx/cdx-output.js +10 -0
- package/neural-interface/public/shared/cdx/cdx-panel.js +18 -16
- package/neural-interface/public/shared/cdx/cdx-plan.js +3 -2
- package/neural-interface/public/shared/cdx/cdx-render.js +122 -45
- package/neural-interface/public/shared/cdx/cdx-requests.js +4 -4
- package/neural-interface/public/shared/cdx/cdx-styles.js +8 -36
- package/neural-interface/public/shared/cdx/cdx-tabs.js +110 -42
- package/neural-interface/public/shared/claude-panel-lazy.js +12 -0
- package/neural-interface/public/shared/code-copy.js +120 -0
- package/neural-interface/public/shared/constants.js +7 -0
- package/neural-interface/public/shared/context-menu-model.js +1 -0
- package/neural-interface/public/shared/cp/cp-markdown.js +7 -2
- package/neural-interface/public/shared/cp/cp-session-model.js +86 -5
- package/neural-interface/public/shared/cp/cp-session-settings.js +58 -30
- package/neural-interface/public/shared/cp/cp-styles.js +9 -0
- package/neural-interface/public/shared/dom-change-flag.js +66 -0
- package/neural-interface/public/shared/dom-morph.js +124 -0
- package/neural-interface/public/shared/extension-setup/es-page.css +134 -0
- package/neural-interface/public/shared/extension-setup/es-page.js +120 -0
- package/neural-interface/public/shared/extension-setup/es-view.js +100 -0
- package/neural-interface/public/shared/html-shell.js +34 -4
- package/neural-interface/public/shared/i18n.js +14 -1
- package/neural-interface/public/shared/idle-queue.js +78 -0
- package/neural-interface/public/shared/iface-config.js +227 -0
- package/neural-interface/public/shared/lazy-module.js +108 -0
- package/neural-interface/public/shared/memory-list.js +117 -0
- package/neural-interface/public/shared/morelogin-profile-choices.js +1 -1
- package/neural-interface/public/shared/morelogin-profile-field.js +3 -3
- package/neural-interface/public/shared/mtc/mtc-panel.js +3 -1
- package/neural-interface/public/shared/mtc/mtc-styles.js +4 -1
- package/neural-interface/public/shared/ocp-v2/ocp-v2-manager.js +35 -15
- package/neural-interface/public/shared/ocp-v2/ocp-v2-panel.js +77 -23
- package/neural-interface/public/shared/ocp-v2/ocp-v2-projectbar.js +3 -6
- package/neural-interface/public/shared/ocp-v2/ocp-v2-render.js +24 -21
- package/neural-interface/public/shared/ocp-v2/ocp-v2-send-logic.js +16 -5
- package/neural-interface/public/shared/ocp-v2/ocp-v2-sessions-logic.js +16 -2
- package/neural-interface/public/shared/ocp-v2/ocp-v2-styles.js +27 -43
- package/neural-interface/public/shared/ocp-v2/ocp-v2-ws.js +73 -9
- package/neural-interface/public/shared/owner-authority-view.js +4 -10
- package/neural-interface/public/shared/page-session.js +1 -1
- package/neural-interface/public/shared/schedules-view.js +2 -2
- package/neural-interface/public/shared/session-project-items.js +11 -0
- package/neural-interface/public/shared/settings/settings-ai-browser.js +119 -0
- package/neural-interface/public/shared/settings/settings-browser-extension.js +446 -0
- package/neural-interface/public/shared/settings/settings-ia.js +4 -2
- package/neural-interface/public/shared/settings/settings-morelogin-cooldown.js +63 -0
- package/neural-interface/public/shared/settings/settings-tool-permissions.js +70 -0
- package/neural-interface/public/shared/sidepanel-lazy.js +40 -0
- package/neural-interface/public/shared/sidepanel-session-status.js +8 -14
- package/neural-interface/public/shared/sidepanel-shown.js +73 -0
- package/neural-interface/public/shared/start-bridge.js +2 -2
- package/neural-interface/public/shared/storage.js +6 -1
- package/neural-interface/public/shared/studio-attention.js +83 -0
- package/neural-interface/public/shared/styles.css +694 -50
- package/neural-interface/public/shared/term-browser-tabs.js +34 -0
- package/neural-interface/public/shared/transcript-rows.js +334 -0
- package/neural-interface/public/shared/tray-auto-close.js +106 -0
- package/neural-interface/public/shared/ui-agents.js +97 -0
- package/neural-interface/public/shared/ui-antigravity-panel.js +16 -14
- package/neural-interface/public/shared/ui-automation-studio.js +3 -3
- package/neural-interface/public/shared/ui-claude-panel.js +162 -95
- package/neural-interface/public/shared/ui-code-copy.js +256 -0
- package/neural-interface/public/shared/ui-codex-panel.js +14 -10
- package/neural-interface/public/shared/ui-context-menu.js +1 -1
- package/neural-interface/public/shared/ui-file-explorer.js +2 -3
- package/neural-interface/public/shared/ui-games.js +1 -1
- package/neural-interface/public/shared/ui-loading.js +83 -19
- package/neural-interface/public/shared/ui-maritaca-panel.js +12 -11
- package/neural-interface/public/shared/ui-menubar.js +23 -0
- package/neural-interface/public/shared/ui-native-loop-router.js +50 -21
- package/neural-interface/public/shared/ui-navbar.js +15 -9
- package/neural-interface/public/shared/ui-opencode-panel-v2.js +13 -11
- package/neural-interface/public/shared/ui-owner-authority.js +48 -25
- package/neural-interface/public/shared/ui-schedules-studio.js +3 -3
- package/neural-interface/public/shared/ui-scroll-follow.js +39 -0
- package/neural-interface/public/shared/ui-sessions.js +3 -3
- package/neural-interface/public/shared/ui-settings-entry.js +55 -0
- package/neural-interface/public/shared/ui-settings.js +363 -400
- package/neural-interface/public/shared/ui-sidepanel-layout.js +44 -25
- package/neural-interface/public/shared/ui-sidepanel-session-entry.js +22 -9
- package/neural-interface/public/shared/ui-sidepanel-sessions.js +10 -2
- package/neural-interface/public/shared/ui-sidepanel-tray.js +36 -41
- package/neural-interface/public/shared/ui-sidepanel-windows.js +14 -1
- package/neural-interface/public/shared/ui-styleguide.js +10 -2
- package/neural-interface/public/shared/ui-sync.js +6 -0
- package/neural-interface/public/shared/ui-terminal.js +13 -9
- package/neural-interface/public/shared/ui-tooltip.js +28 -7
- package/neural-interface/public/shared/ui-topright-overflow.js +26 -4
- package/neural-interface/public/shared/ui-tray-columns.js +375 -0
- package/neural-interface/public/shared/ui-whiteboard.js +51 -6
- package/neural-interface/public/shared/ui-worker-end.js +28 -1
- package/neural-interface/public/shared/ui-workspaces.js +13 -0
- package/neural-interface/public/shared/window-keys.js +71 -0
- package/neural-interface/public/sw.js +4 -3
- package/neural-interface/public/variant/2d/main.js +2 -0
- package/neural-interface/public/variant/3d/app.js +620 -0
- package/neural-interface/public/variant/3d/boot-reveal.js +47 -0
- package/neural-interface/public/variant/3d/main.js +30 -544
- package/neural-interface/public/variant/3d/map-controls.js +4 -2
- package/neural-interface/public/vendor/fonts/fonts.css +508 -0
- package/neural-interface/public/vendor/fonts/inter-OFL.txt +93 -0
- package/neural-interface/public/vendor/fonts/inter-cyrillic-ext.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/inter-cyrillic.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/inter-greek-ext.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/inter-greek.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/inter-latin-ext.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/inter-latin.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/inter-vietnamese.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/jetbrains-mono-OFL.txt +93 -0
- package/neural-interface/public/vendor/fonts/jetbrains-mono-cyrillic-ext.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/jetbrains-mono-cyrillic.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/jetbrains-mono-greek.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/jetbrains-mono-latin-ext.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/jetbrains-mono-latin.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/jetbrains-mono-vietnamese.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/manifest.json +142 -0
- package/neural-interface/public/vendor/fonts/space-grotesk-OFL.txt +93 -0
- package/neural-interface/public/vendor/fonts/space-grotesk-latin-ext.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/space-grotesk-latin.woff2 +0 -0
- package/neural-interface/public/vendor/fonts/space-grotesk-vietnamese.woff2 +0 -0
- package/neural-interface/scripts/boot-graph.mjs +270 -0
- package/neural-interface/scripts/vendor-fonts.mjs +124 -0
- package/neural-interface/server.js +1083 -164
- package/npm-shrinkwrap.json +2 -2
- package/package.json +4 -1
- package/skills/agent-forge/SKILL.md +182 -0
- package/skills/agent-forge/evals/evals.json +56 -0
- package/skills/agent-forge/references/definition-fields.md +61 -0
- package/skills/agent-forge/references/examples.md +105 -0
- package/skills/agent-forge/references/instructions.md +51 -0
- package/skills/agent-forge/references/review-and-export.md +84 -0
|
@@ -0,0 +1,614 @@
|
|
|
1
|
+
// ═══════════════════════════════════════════
|
|
2
|
+
// SynaBun Neural Interface — Agents Studio: one agent
|
|
3
|
+
// ═══════════════════════════════════════════
|
|
4
|
+
//
|
|
5
|
+
// The workspace of one agent (or of a new one being made): its name, where it stands, the actions, and its tabs
|
|
6
|
+
// (Edit · Revisions · Runs · Test run). What each action does is the registry's lifecycle (docs/agents.md):
|
|
7
|
+
//
|
|
8
|
+
// Save draft a new agent: POST /agents. An agent: PATCH its draft with the etag that was read (an approved
|
|
9
|
+
// agent with no draft gets one over its current revision: the agent stays what was approved).
|
|
10
|
+
// Submit draft → in review. Approve the owner's: the draft becomes the agent's revision.
|
|
11
|
+
// Back to draft in review → draft. Withdraw the working revision, or the approved one.
|
|
12
|
+
// Duplicate · Export · Discard draft · Delete
|
|
13
|
+
//
|
|
14
|
+
// A save the server refuses because the draft changed since it was read (409 etag_conflict), or because it named no
|
|
15
|
+
// etag the server could check (428 etag_required), shows what changed on each side against what is stored now and
|
|
16
|
+
// offers the two ways out: take the stored draft, or save the owner's text over it as the new draft content. Approving shows first what the agent may do, with what changed against the last approved revision.
|
|
17
|
+
// Leaving with unsaved changes asks. Nothing is approved by saving, importing or duplicating.
|
|
18
|
+
|
|
19
|
+
import { html, setHTML, ICONS } from '../../skills/studio/sx-dom.js';
|
|
20
|
+
import { wireDropdowns } from '../../cc-dropdown.js';
|
|
21
|
+
import { formOf, blankForm, patchOf, conflictFields, mergeOverTheirs, issuesByField, isDirty, slugOf } from './ax-form.js';
|
|
22
|
+
import { agentTabs, agentKeyText } from './ax-views.js';
|
|
23
|
+
import { scopeEntries, scopeFromValue } from './ax-options.js';
|
|
24
|
+
import { standingOf } from './ax-library.js';
|
|
25
|
+
import { AX_ICONS } from './ax-icons.js';
|
|
26
|
+
import { agentMark, standingLabels, scopeTag, loadingHTML, errorHTML, errorText, diffHTML, privilegeHTML, wordsOf, dropdown, downloadText } from './ax-ui.js';
|
|
27
|
+
import { renderEditorPanel, leaveEditorPanel, formDefinition } from './ax-editor-view.js';
|
|
28
|
+
import { renderRevisionsPanel, leaveRevisionsPanel } from './ax-revisions-view.js';
|
|
29
|
+
import { renderRunsPanel, renderTestPanel, leaveRunsPanel } from './ax-runs-view.js';
|
|
30
|
+
|
|
31
|
+
import { canExportNative } from './ax-native-export.js';
|
|
32
|
+
import { exportToHost } from './ax-export-view.js';
|
|
33
|
+
|
|
34
|
+
let life = null;
|
|
35
|
+
let menuEl = null;
|
|
36
|
+
|
|
37
|
+
export function leaveAgent() {
|
|
38
|
+
life?.abort();
|
|
39
|
+
life = null;
|
|
40
|
+
menuEl?.remove();
|
|
41
|
+
menuEl = null;
|
|
42
|
+
leaveEditorPanel(); leaveRevisionsPanel(); leaveRunsPanel();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Close the workspace's menu; true when one was open. */
|
|
46
|
+
export function closeAgentMenu() {
|
|
47
|
+
if (!menuEl) return false;
|
|
48
|
+
const opener = menuEl.opener;
|
|
49
|
+
menuEl.remove();
|
|
50
|
+
menuEl = null;
|
|
51
|
+
opener?.focus?.({ preventScroll: true });
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
// ── The editor's state ──
|
|
56
|
+
|
|
57
|
+
/** A new agent's editor state. */
|
|
58
|
+
export function newEditor({ form = null, provider = '', scope = null, source = 'blank' } = {}) {
|
|
59
|
+
const start = form || blankForm({ provider, scope });
|
|
60
|
+
return { mode: 'new', key: null, agent: null, base: null, etag: null, form: start, idTouched: !!start.id && slugOf(start.name) !== start.id, dirty: !!form, editable: true, issues: null, delta: null, source, loading: false, error: null, busy: false, closed: false };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** The editor state of a stored agent, before it was read. */
|
|
64
|
+
export function agentEditor(key) {
|
|
65
|
+
return { mode: 'agent', key, agent: null, base: null, etag: null, form: blankForm(), idTouched: true, dirty: false, editable: false, issues: null, delta: null, loading: true, error: null, busy: false, closed: false };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Take the server's reading of an agent into the editor (GET /agents/:id, or a draft answer). */
|
|
69
|
+
export function adoptAgent(ed, agent, { validation = null, warnings = null, keepForm = false, latest = null } = {}) {
|
|
70
|
+
const draft = agent?.draftDefinition || null;
|
|
71
|
+
// An agent with nothing approved and no draft (every revision withdrawn) is read from its newest revision: a save
|
|
72
|
+
// starts a draft over that one, as the registry does.
|
|
73
|
+
const base = draft || agent?.approvedDefinition || latest || (ed.agent && !ed.agent.draftDefinition && !ed.agent.approvedDefinition ? ed.base : null) || null;
|
|
74
|
+
ed.agent = agent;
|
|
75
|
+
ed.base = base;
|
|
76
|
+
ed.etag = base?.etag || agent?.approvedEtag || null;
|
|
77
|
+
if (!keepForm) { ed.form = formOf(base); ed.dirty = false; }
|
|
78
|
+
// A revision in review is read, not written: it goes back to draft first.
|
|
79
|
+
ed.editable = !draft || draft.status === 'draft';
|
|
80
|
+
ed.issues = validation ? { byField: issuesByField(validation.errors, warnings), valid: validation.ok === true } : (keepForm ? ed.issues : null);
|
|
81
|
+
ed.loading = false;
|
|
82
|
+
ed.error = null;
|
|
83
|
+
return ed;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Read the agent again (and what its draft changed against the approved revision, for the summary's marks). */
|
|
87
|
+
export async function loadAgent(ctx, ed) {
|
|
88
|
+
const gen = ctx.gen();
|
|
89
|
+
ed.loading = !ed.agent;
|
|
90
|
+
try {
|
|
91
|
+
const res = await ctx.api.get(ed.key);
|
|
92
|
+
let latest = null;
|
|
93
|
+
if (!res.agent.draftDefinition && !res.agent.approvedDefinition) {
|
|
94
|
+
const newest = [...(res.agent.revisions || [])].reverse().find((rev) => !rev.damaged && rev.revision);
|
|
95
|
+
if (newest) { try { latest = (await ctx.api.revision(ed.key, newest.revision)).revision; } catch { latest = null; } }
|
|
96
|
+
}
|
|
97
|
+
if (!ctx.alive(gen) || ed.closed) return ed;
|
|
98
|
+
adoptAgent(ed, res.agent, { validation: res.validation, warnings: res.warnings, latest });
|
|
99
|
+
await loadDelta(ctx, ed);
|
|
100
|
+
} catch (error) {
|
|
101
|
+
if (!ctx.alive(gen) || ed.closed) return ed;
|
|
102
|
+
ed.loading = false;
|
|
103
|
+
ed.error = error;
|
|
104
|
+
}
|
|
105
|
+
return ed;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
async function loadDelta(ctx, ed) {
|
|
109
|
+
ed.delta = null;
|
|
110
|
+
if (!ctx.caps.has('diff') || !ed.agent?.draftDefinition || !ed.agent?.approvedDefinition) return;
|
|
111
|
+
try { ed.delta = (await ctx.api.diff(ed.key, { from: 'approved', to: 'draft' })).diff?.privileges || null; } catch { ed.delta = null; }
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
// ── Markup ──
|
|
115
|
+
|
|
116
|
+
function actionsHTML(ctx, ed) {
|
|
117
|
+
const { t } = ctx;
|
|
118
|
+
if (ed.loading || ed.error) return '';
|
|
119
|
+
const draft = ed.agent?.draftDefinition || null;
|
|
120
|
+
const inReview = draft?.status === 'in_review';
|
|
121
|
+
const invalid = ed.issues && ed.issues.valid === false;
|
|
122
|
+
const busy = ed.busy ? html` disabled` : '';
|
|
123
|
+
const out = [];
|
|
124
|
+
if (ed.mode === 'new') {
|
|
125
|
+
out.push(html`<button type="button" class="sx-btn sx-btn--primary" data-act="save"${ed.busy || !ed.form.name.trim() ? html` disabled` : ''}>${ICONS.ok}${t('agentsStudio.action.createDraft')}</button>`);
|
|
126
|
+
return html`${out}`;
|
|
127
|
+
}
|
|
128
|
+
if (!ctx.canDraft) return '';
|
|
129
|
+
if (ed.editable) out.push(html`<button type="button" class="sx-btn${ed.dirty ? ' sx-btn--primary' : ''}" data-act="save"${ed.busy || !ed.dirty ? html` disabled` : ''} title="${t('agentsStudio.action.saveHelp')}">${t('agentsStudio.action.saveDraft')}</button>`);
|
|
130
|
+
if (inReview) out.push(html`<button type="button" class="sx-btn" data-act="back-to-draft"${busy}>${t('agentsStudio.action.backToDraft')}</button>`);
|
|
131
|
+
else if (ctx.caps.has('reviews') && (draft || ed.dirty)) out.push(html`<button type="button" class="sx-btn" data-act="submit"${ed.busy || invalid ? html` disabled` : ''} title="${invalid ? t('agentsStudio.action.fixFirst') : t('agentsStudio.action.submitHelp')}">${t('agentsStudio.action.submit')}</button>`);
|
|
132
|
+
if (ctx.caps.has('reviews') && ctx.owner && (draft || ed.dirty)) out.push(html`<button type="button" class="sx-btn${!ed.dirty ? ' sx-btn--primary' : ''}" data-act="approve"${ed.busy || invalid ? html` disabled` : ''} title="${invalid ? t('agentsStudio.action.fixFirst') : t('agentsStudio.action.approveHelp')}">${ICONS.review}${t('agentsStudio.action.approve')}</button>`);
|
|
133
|
+
out.push(html`<button type="button" class="sx-icon-btn" data-act="menu" aria-haspopup="menu" aria-expanded="false" aria-label="${t('agentsStudio.action.more')}" title="${t('agentsStudio.action.more')}"${busy}>${ICONS.more}</button>`);
|
|
134
|
+
return html`${out}`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function bannersHTML(ctx, ed) {
|
|
138
|
+
const { t } = ctx;
|
|
139
|
+
if (ed.loading || ed.error) return '';
|
|
140
|
+
const out = [];
|
|
141
|
+
const draft = ed.agent?.draftDefinition || null;
|
|
142
|
+
const approved = ed.agent?.approvedDefinition || null;
|
|
143
|
+
if (ed.mode === 'new') out.push(html`<div class="sx-banner sx-banner--draft">${ICONS.draft}<span class="sx-banner-text">${t('agentsStudio.banner.new')}</span></div>`);
|
|
144
|
+
else if (draft?.status === 'in_review') out.push(html`<div class="sx-banner sx-banner--warn">${ICONS.review}<span class="sx-banner-text">${t('agentsStudio.banner.inReview')}${draft && ed.agent?.draft?.review?.note ? html`<span class="sx-banner-lines"><span>${t('agentsStudio.banner.note', { note: ed.agent.draft.review.note })}</span></span>` : ''}</span></div>`);
|
|
145
|
+
else if (draft && approved) out.push(html`<div class="sx-banner sx-banner--draft">${ICONS.draft}<span class="sx-banner-text">${t('agentsStudio.banner.draftOverApproved', { draft: draft.revision, approved: approved.revision })}${ed.agent?.draft?.review?.returnNote ? html`<span class="sx-banner-lines"><span>${t('agentsStudio.banner.returned', { note: ed.agent.draft.review.returnNote })}</span></span>` : ''}</span></div>`);
|
|
146
|
+
else if (draft) out.push(html`<div class="sx-banner sx-banner--draft">${ICONS.draft}<span class="sx-banner-text">${t('agentsStudio.banner.draftOnly')}${ed.agent?.draft?.review?.returnNote ? html`<span class="sx-banner-lines"><span>${t('agentsStudio.banner.returned', { note: ed.agent.draft.review.returnNote })}</span></span>` : ''}</span></div>`);
|
|
147
|
+
else if (approved) out.push(html`<div class="sx-banner sx-banner--ok">${ICONS.ok}<span class="sx-banner-text">${t('agentsStudio.banner.approved', { n: approved.revision })}</span></div>`);
|
|
148
|
+
else out.push(html`<div class="sx-banner">${ICONS.off}<span class="sx-banner-text">${t('agentsStudio.banner.withdrawn')}</span></div>`);
|
|
149
|
+
if (ed.agent?.damaged) out.push(html`<div class="sx-banner sx-banner--warn">${ICONS.warn}<span class="sx-banner-text">${t('agentsStudio.damagedHelp')}</span></div>`);
|
|
150
|
+
if (ed.mode === 'agent' && !ctx.canDraft) out.push(html`<div class="sx-banner">${ICONS.lock}<span class="sx-banner-text">${t('agentsStudio.banner.readOnly')}</span></div>`);
|
|
151
|
+
return html`${out}`;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
function headHTML(ctx, ed) {
|
|
155
|
+
const { t } = ctx;
|
|
156
|
+
const shown = ed.mode === 'new' ? { name: ed.form.name, icon: ed.form.icon, color: ed.form.color } : (ed.agent || { name: ed.key.id });
|
|
157
|
+
const title = ed.mode === 'new' ? (ed.form.name || t('agentsStudio.editor.newTitle')) : (ed.form.name || ed.agent?.name || ed.key.id);
|
|
158
|
+
const from = ctx.view.place === 'agent' ? ctx.view.from : 'library';
|
|
159
|
+
const tabs = ed.mode === 'agent' ? agentTabs(ctx.capsKnown ? ctx.caps : null) : [];
|
|
160
|
+
return html`<header class="sx-ws-head ax-ws-head">
|
|
161
|
+
<nav class="sx-crumb" aria-label="${t('agentsStudio.editor.crumb')}"><button type="button" class="sx-link" data-act="back">${ICONS.back}${t(`agentsStudio.rail.${ed.mode === 'new' ? 'create' : from}`)}</button></nav>
|
|
162
|
+
<div class="sx-ws-title">
|
|
163
|
+
<span id="ax-ws-mark">${agentMark(ed.mode === 'new' ? { icon: ed.form.icon, color: ed.form.color } : { icon: ed.form.icon ?? shown.icon, color: ed.form.color ?? shown.color }, 20)}</span>
|
|
164
|
+
<h3 class="sx-ws-name" id="ax-ws-name" tabindex="-1">${title}</h3>
|
|
165
|
+
${ed.mode === 'agent' && ed.agent ? html`<span class="ax-ws-state">${standingLabels(t, ed.agent)}</span>${scopeTag(t, ed.key.scope, ctx.info?.projects)}` : ed.mode === 'new' ? html`<span class="sx-label ax-status ax-status--draft">${t('agentsStudio.editor.unsavedNew')}</span>` : ''}
|
|
166
|
+
<span class="sx-label ax-dirty" id="ax-dirty"${ed.dirty && ed.mode === 'agent' ? '' : html` hidden`}>${t('agentsStudio.editor.unsaved')}</span>
|
|
167
|
+
<span class="sx-spacer"></span>
|
|
168
|
+
<span class="sx-row ax-actions" id="ax-actions">${actionsHTML(ctx, ed)}</span>
|
|
169
|
+
</div>
|
|
170
|
+
${tabs.length > 1 ? html`<div class="sx-tabs" role="tablist" aria-label="${title}">${tabs.map((tab) => html`<button type="button" class="sx-tab" role="tab" id="ax-tab-${tab}" data-act="tab" data-tab="${tab}" aria-selected="${ctx.view.tab === tab ? 'true' : 'false'}" aria-controls="ax-tabpanel" tabindex="${ctx.view.tab === tab ? '0' : '-1'}">${t(`agentsStudio.tab.${tab}`)}</button>`)}</div>` : ''}
|
|
171
|
+
</header>`;
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
// ── Actions ──
|
|
175
|
+
|
|
176
|
+
const fileName = (key) => `agent-${key.id}${key.scope?.kind === 'project' ? '-project' : ''}.json`;
|
|
177
|
+
|
|
178
|
+
/** Save the form. True when what is stored is now what the form shows. */
|
|
179
|
+
export async function saveEditor(ctx, ed) {
|
|
180
|
+
const { t } = ctx;
|
|
181
|
+
if (ed.busy) return false;
|
|
182
|
+
ed.busy = true;
|
|
183
|
+
ed.onState?.();
|
|
184
|
+
try {
|
|
185
|
+
if (ed.mode === 'new') {
|
|
186
|
+
const res = await ctx.api.create(formDefinition(ed));
|
|
187
|
+
ed.dirty = false;
|
|
188
|
+
ctx.toast(t('agentsStudio.toast.created', { name: res.draft?.name || res.agent?.id }));
|
|
189
|
+
await ctx.adopted({ id: res.agent.id, scope: res.agent.scope });
|
|
190
|
+
return true;
|
|
191
|
+
}
|
|
192
|
+
const patch = patchOf(ed.base, ed.form);
|
|
193
|
+
if (!Object.keys(patch).length) { ed.dirty = false; return true; }
|
|
194
|
+
const res = await ctx.api.updateDraft(ed.key, patch, ed.etag);
|
|
195
|
+
adoptAgent(ed, res.agent, { validation: res.validation, warnings: res.warnings });
|
|
196
|
+
await loadDelta(ctx, ed);
|
|
197
|
+
ctx.toast(t('agentsStudio.toast.saved'));
|
|
198
|
+
ctx.changed();
|
|
199
|
+
return true;
|
|
200
|
+
} catch (error) {
|
|
201
|
+
// 428: the save named no etag the server could check (a form read before its draft existed, a page out of step):
|
|
202
|
+
// the same question as a conflict, against what is stored now, so nothing is written over unseen.
|
|
203
|
+
if (error.conflict || error.etagRequired) return resolveConflict(ctx, ed, error);
|
|
204
|
+
if (error.status === 409 && error.code === 'not_editable') { ctx.toast(t('agentsStudio.toast.inReview'), 'error'); await loadAgent(ctx, ed); return false; }
|
|
205
|
+
if (error.errors?.length) { ed.issues = { byField: issuesByField(error.errors, []), valid: false }; ed.redraw?.({ keepFocus: true }); }
|
|
206
|
+
ctx.toast(t('agentsStudio.toast.saveFailed', { error: errorText(t, error) }), 'error');
|
|
207
|
+
return false;
|
|
208
|
+
} finally {
|
|
209
|
+
ed.busy = false;
|
|
210
|
+
ed.onState?.();
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* The draft changed since it was read. Show what changed on each side; the owner takes the stored draft, or saves
|
|
216
|
+
* its own text over it (the fields changed here, written over what is stored now, against the etag that is current).
|
|
217
|
+
*/
|
|
218
|
+
async function resolveConflict(ctx, ed, error) {
|
|
219
|
+
const { t } = ctx;
|
|
220
|
+
let theirs = error.current;
|
|
221
|
+
let etag = error.currentEtag;
|
|
222
|
+
if (!theirs) {
|
|
223
|
+
try { const res = await ctx.api.get(ed.key); theirs = res.agent.draftDefinition || res.agent.approvedDefinition; etag = theirs?.etag || null; } catch { theirs = null; }
|
|
224
|
+
}
|
|
225
|
+
if (!theirs) { ctx.toast(t('agentsStudio.toast.saveFailed', { error: errorText(t, error) }), 'error'); return false; }
|
|
226
|
+
const fields = conflictFields(ed.base, ed.form, theirs);
|
|
227
|
+
const there = fields.filter((f) => f.theirs && !f.clash);
|
|
228
|
+
const here = fields.filter((f) => f.mine && !f.theirs);
|
|
229
|
+
const both = fields.filter((f) => f.clash);
|
|
230
|
+
const name = (f) => t(`agentsStudio.field.${f.field}`);
|
|
231
|
+
const extra = document.createElement('div');
|
|
232
|
+
setHTML(extra, html`<dl class="ax-conflict">
|
|
233
|
+
${there.length ? html`<div><dt>${t('agentsStudio.conflict.changedThere')}</dt><dd>${there.map(name).join(', ')}</dd></div>` : ''}
|
|
234
|
+
${here.length ? html`<div><dt>${t('agentsStudio.conflict.changedHere')}</dt><dd>${here.map(name).join(', ')}</dd></div>` : ''}
|
|
235
|
+
${both.length ? html`<div class="is-clash"><dt>${t('agentsStudio.conflict.changedBoth')}</dt><dd>${both.map(name).join(', ')}</dd></div>` : ''}
|
|
236
|
+
${!fields.length ? html`<div><dt>${t('agentsStudio.conflict.sameContent')}</dt><dd></dd></div>` : ''}
|
|
237
|
+
</dl>`);
|
|
238
|
+
const locked = theirs.status === 'in_review';
|
|
239
|
+
const answer = await ctx.ask({
|
|
240
|
+
title: t('agentsStudio.conflict.title'),
|
|
241
|
+
lines: [t('agentsStudio.conflict.help'), locked ? t('agentsStudio.conflict.inReview') : (both.length ? t('agentsStudio.conflict.overwriteHelp') : t('agentsStudio.conflict.mergeHelp'))],
|
|
242
|
+
extra, className: 'ax-dlg',
|
|
243
|
+
buttons: [{ id: 'cancel', label: t('agentsStudio.action.cancel') }, { id: 'reload', label: t('agentsStudio.conflict.reload') }, ...(locked ? [] : [{ id: 'overwrite', label: t('agentsStudio.conflict.overwrite'), kind: 'primary' }])],
|
|
244
|
+
focus: 'reload',
|
|
245
|
+
});
|
|
246
|
+
if (answer === 'reload') {
|
|
247
|
+
await loadAgent(ctx, ed);
|
|
248
|
+
ctx.toast(t('agentsStudio.toast.reloaded'));
|
|
249
|
+
ctx.render({ keepFocus: true });
|
|
250
|
+
return false;
|
|
251
|
+
}
|
|
252
|
+
if (answer !== 'overwrite') return false;
|
|
253
|
+
const mine = mergeOverTheirs(ed.base, ed.form, theirs);
|
|
254
|
+
try {
|
|
255
|
+
const res = await ctx.api.updateDraft(ed.key, patchOf(theirs, mine), etag);
|
|
256
|
+
adoptAgent(ed, res.agent, { validation: res.validation, warnings: res.warnings });
|
|
257
|
+
await loadDelta(ctx, ed);
|
|
258
|
+
ctx.toast(t('agentsStudio.toast.savedOver'));
|
|
259
|
+
ctx.changed();
|
|
260
|
+
ctx.render({ keepFocus: true });
|
|
261
|
+
return true;
|
|
262
|
+
} catch (again) {
|
|
263
|
+
ctx.toast(t('agentsStudio.toast.saveFailed', { error: errorText(t, again) }), 'error');
|
|
264
|
+
return false;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/** What a refused transition says. */
|
|
269
|
+
const FAILED = Object.freeze({
|
|
270
|
+
approve: 'agentsStudio.toast.approveFailed', submit: 'agentsStudio.toast.submitFailed', backToDraft: 'agentsStudio.toast.backToDraftFailed',
|
|
271
|
+
withdraw: 'agentsStudio.toast.withdrawFailed', discard: 'agentsStudio.toast.discardFailed', delete: 'agentsStudio.toast.deleteFailed',
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
/** Run one of the workspace's transitions, saving first when the form has changes. */
|
|
275
|
+
async function transition(ctx, ed, name, run, { needsSave = true } = {}) {
|
|
276
|
+
const { t } = ctx;
|
|
277
|
+
if (ed.busy) return false;
|
|
278
|
+
if (needsSave && ed.dirty && !(await saveEditor(ctx, ed))) return false;
|
|
279
|
+
ed.busy = true;
|
|
280
|
+
ed.onState?.();
|
|
281
|
+
try {
|
|
282
|
+
await run();
|
|
283
|
+
return true;
|
|
284
|
+
} catch (error) {
|
|
285
|
+
// A transition (an approval above all) belongs to the content that was read: without a valid etag it is read again.
|
|
286
|
+
if (error.conflict || error.etagRequired) { ctx.toast(t('agentsStudio.toast.changedElsewhere'), 'error'); await loadAgent(ctx, ed); ctx.render({ keepFocus: true }); return false; }
|
|
287
|
+
if (error.errors?.length) { ed.issues = { byField: issuesByField(error.errors, []), valid: false }; ctx.render({ keepFocus: true }); }
|
|
288
|
+
ctx.toast(t(FAILED[name], { error: errorText(t, error) }), 'error');
|
|
289
|
+
return false;
|
|
290
|
+
} finally {
|
|
291
|
+
ed.busy = false;
|
|
292
|
+
ed.onState?.();
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
/** The approval's question: what this agent may do, and what changed against the last approved revision. */
|
|
297
|
+
export async function confirmApproval(ctx, key, definition, approved) {
|
|
298
|
+
const { t } = ctx;
|
|
299
|
+
let diff = null;
|
|
300
|
+
if (ctx.caps.has('diff')) { try { diff = (await ctx.api.diff(key, { to: 'draft' })).diff; } catch { diff = null; } }
|
|
301
|
+
const words = wordsOf(t, { projects: ctx.info?.projects });
|
|
302
|
+
const extra = document.createElement('div');
|
|
303
|
+
extra.className = 'ax-approve';
|
|
304
|
+
setHTML(extra, html`
|
|
305
|
+
<h4 class="sx-section-title">${t('agentsStudio.privilege.title')}</h4>
|
|
306
|
+
${privilegeHTML(t, definition, approved, diff?.privileges || null, words)}
|
|
307
|
+
${diff && diff.from ? html`<details class="sx-details ax-approve-diff"><summary>${t('agentsStudio.approve.showChanges')}</summary>${diffHTML(t, diff, words, { open: false })}</details>` : ''}`);
|
|
308
|
+
const wider = diff?.privileges?.escalates === true && !!approved;
|
|
309
|
+
const answer = await ctx.ask({
|
|
310
|
+
title: t('agentsStudio.approve.title', { name: definition.name || key.id, n: definition.revision ?? '' }),
|
|
311
|
+
lines: [approved ? t('agentsStudio.approve.helpNext', { n: approved.revision }) : t('agentsStudio.approve.helpFirst'), wider ? t('agentsStudio.approve.wider') : null],
|
|
312
|
+
extra, wide: true, className: `ax-dlg${wider ? ' ax-dlg--wider' : ''}`,
|
|
313
|
+
buttons: [{ id: 'cancel', label: t('agentsStudio.action.cancel') }, { id: 'approve', label: t('agentsStudio.action.approve'), kind: 'primary' }],
|
|
314
|
+
focus: wider ? 'cancel' : 'approve',
|
|
315
|
+
});
|
|
316
|
+
return answer === 'approve';
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
async function approve(ctx, ed) {
|
|
320
|
+
const { t } = ctx;
|
|
321
|
+
if (ed.dirty && !(await saveEditor(ctx, ed))) return;
|
|
322
|
+
const draft = ed.agent?.draftDefinition;
|
|
323
|
+
if (!draft) return;
|
|
324
|
+
if (!(await confirmApproval(ctx, ed.key, draft, ed.agent.approvedDefinition))) return;
|
|
325
|
+
const done = await transition(ctx, ed, 'approve', async () => {
|
|
326
|
+
const res = await ctx.api.approve(ed.key, { etag: draft.etag });
|
|
327
|
+
ctx.toast(t('agentsStudio.toast.approved', { name: res.revision?.name || ed.key.id, n: res.revision?.revision ?? '' }));
|
|
328
|
+
}, { needsSave: false });
|
|
329
|
+
if (done) { await loadAgent(ctx, ed); ctx.changed(); ctx.render(); }
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
async function submit(ctx, ed) {
|
|
333
|
+
const { t } = ctx;
|
|
334
|
+
if (ed.dirty && !(await saveEditor(ctx, ed))) return;
|
|
335
|
+
// An approved agent with no draft has nothing to send: a draft is opened over it first.
|
|
336
|
+
const done = await transition(ctx, ed, 'submit', async () => {
|
|
337
|
+
if (!ed.agent?.draftDefinition) { const opened = await ctx.api.openDraft(ed.key); adoptAgent(ed, opened.agent, { validation: opened.validation, warnings: opened.warnings }); }
|
|
338
|
+
await ctx.api.submit(ed.key, { etag: ed.etag });
|
|
339
|
+
ctx.toast(t('agentsStudio.toast.submitted'));
|
|
340
|
+
}, { needsSave: false });
|
|
341
|
+
if (done) { await loadAgent(ctx, ed); ctx.changed(); ctx.render(); }
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
async function backToDraft(ctx, ed) {
|
|
345
|
+
const { t } = ctx;
|
|
346
|
+
const done = await transition(ctx, ed, 'backToDraft', async () => {
|
|
347
|
+
await ctx.api.requestChanges(ed.key, { etag: ed.etag });
|
|
348
|
+
ctx.toast(t('agentsStudio.toast.backToDraft'));
|
|
349
|
+
}, { needsSave: false });
|
|
350
|
+
if (done) { await loadAgent(ctx, ed); ctx.changed(); ctx.render(); }
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
async function withdraw(ctx, ed) {
|
|
354
|
+
const { t } = ctx;
|
|
355
|
+
const draft = ed.agent?.draftDefinition;
|
|
356
|
+
const approved = ed.agent?.approvedDefinition;
|
|
357
|
+
const approvedCount = (ed.agent?.revisions || []).filter((r) => r.status === 'approved').length;
|
|
358
|
+
let all = null;
|
|
359
|
+
let extra = null;
|
|
360
|
+
if (approvedCount > 0 && (draft || approvedCount > 1)) {
|
|
361
|
+
extra = document.createElement('label');
|
|
362
|
+
extra.className = 'sx-choice ax-dlg-choice';
|
|
363
|
+
all = document.createElement('input');
|
|
364
|
+
all.type = 'checkbox';
|
|
365
|
+
all.className = 'sx-check';
|
|
366
|
+
const span = document.createElement('span');
|
|
367
|
+
span.textContent = t('agentsStudio.withdraw.all');
|
|
368
|
+
extra.append(all, span);
|
|
369
|
+
}
|
|
370
|
+
const answer = await ctx.ask({
|
|
371
|
+
title: t('agentsStudio.withdraw.title', { name: ed.agent?.name || ed.key.id }),
|
|
372
|
+
lines: [draft ? t('agentsStudio.withdraw.draft', { n: draft.revision }) : approved ? t('agentsStudio.withdraw.approved', { n: approved.revision }) : t('agentsStudio.withdraw.nothing'), t('agentsStudio.withdraw.kept')],
|
|
373
|
+
extra, className: 'ax-dlg',
|
|
374
|
+
buttons: [{ id: 'cancel', label: t('agentsStudio.action.cancel') }, { id: 'withdraw', label: t('agentsStudio.action.withdraw'), kind: 'danger', disabled: !draft && !approved }],
|
|
375
|
+
focus: 'cancel',
|
|
376
|
+
});
|
|
377
|
+
if (answer !== 'withdraw') return;
|
|
378
|
+
let gone = false;
|
|
379
|
+
const done = await transition(ctx, ed, 'withdraw', async () => {
|
|
380
|
+
const res = await ctx.api.withdraw(ed.key, { all: all?.checked === true });
|
|
381
|
+
gone = !res.agent;
|
|
382
|
+
ctx.toast(t(res.discarded && !res.withdrawn?.length ? 'agentsStudio.toast.discarded' : 'agentsStudio.toast.withdrawn'));
|
|
383
|
+
}, { needsSave: false });
|
|
384
|
+
if (!done) return;
|
|
385
|
+
ed.dirty = false;
|
|
386
|
+
ctx.changed();
|
|
387
|
+
if (gone) { ctx.go({ type: 'back' }, { force: true }); return; }
|
|
388
|
+
await loadAgent(ctx, ed);
|
|
389
|
+
ctx.render();
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
async function discardDraft(ctx, ed) {
|
|
393
|
+
const { t } = ctx;
|
|
394
|
+
const answer = await ctx.ask({
|
|
395
|
+
title: t('agentsStudio.discard.title'),
|
|
396
|
+
lines: [ed.agent?.approvedDefinition ? t('agentsStudio.discard.keepsApproved', { n: ed.agent.approvedDefinition.revision }) : t('agentsStudio.discard.removesAgent')],
|
|
397
|
+
className: 'ax-dlg',
|
|
398
|
+
buttons: [{ id: 'cancel', label: t('agentsStudio.action.cancel') }, { id: 'discard', label: t('agentsStudio.action.discardDraft'), kind: 'danger' }],
|
|
399
|
+
focus: 'cancel',
|
|
400
|
+
});
|
|
401
|
+
if (answer !== 'discard') return;
|
|
402
|
+
let removed = false;
|
|
403
|
+
const done = await transition(ctx, ed, 'discard', async () => {
|
|
404
|
+
const res = await ctx.api.discardDraft(ed.key, ed.agent?.draftDefinition?.etag || null);
|
|
405
|
+
removed = res.removed === true;
|
|
406
|
+
ctx.toast(t('agentsStudio.toast.discarded'));
|
|
407
|
+
}, { needsSave: false });
|
|
408
|
+
if (!done) return;
|
|
409
|
+
ed.dirty = false;
|
|
410
|
+
ctx.changed();
|
|
411
|
+
if (removed) { ctx.go({ type: 'back' }, { force: true }); return; }
|
|
412
|
+
await loadAgent(ctx, ed);
|
|
413
|
+
ctx.render();
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
async function remove(ctx, ed) {
|
|
417
|
+
const { t } = ctx;
|
|
418
|
+
const answer = await ctx.ask({
|
|
419
|
+
title: t('agentsStudio.delete.title', { name: ed.agent?.name || ed.key.id }),
|
|
420
|
+
lines: [t('agentsStudio.delete.help'), t('agentsStudio.delete.runsKeep')],
|
|
421
|
+
className: 'ax-dlg',
|
|
422
|
+
buttons: [{ id: 'cancel', label: t('agentsStudio.action.cancel') }, { id: 'delete', label: t('agentsStudio.action.delete'), kind: 'danger' }],
|
|
423
|
+
focus: 'cancel',
|
|
424
|
+
});
|
|
425
|
+
if (answer !== 'delete') return;
|
|
426
|
+
const done = await transition(ctx, ed, 'delete', async () => {
|
|
427
|
+
await ctx.api.remove(ed.key);
|
|
428
|
+
ctx.toast(t('agentsStudio.toast.deleted', { name: ed.agent?.name || ed.key.id }));
|
|
429
|
+
}, { needsSave: false });
|
|
430
|
+
if (!done) return;
|
|
431
|
+
ed.dirty = false;
|
|
432
|
+
ctx.changed();
|
|
433
|
+
ctx.go({ type: 'back' }, { force: true });
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
/** Ask for the id and the library of a copy, then make it and open it. */
|
|
437
|
+
export async function duplicateAgent(ctx, key, name) {
|
|
438
|
+
const { t } = ctx;
|
|
439
|
+
const extra = document.createElement('div');
|
|
440
|
+
extra.className = 'ax-dlg-form';
|
|
441
|
+
const life2 = new AbortController();
|
|
442
|
+
const suggested = `${key.id}-copy`.slice(0, Number(ctx.info?.limits?.id) || 64);
|
|
443
|
+
setHTML(extra, html`
|
|
444
|
+
<div class="sx-field"><label class="sx-field-label" for="ax-dup-id">${t('agentsStudio.duplicate.id')}</label><input type="text" class="sx-input sx-mono" id="ax-dup-id" value="${suggested}" autocomplete="off" spellcheck="false" autocapitalize="off"><p class="sx-field-note sx-err-text" id="ax-dup-error" role="alert" hidden></p></div>
|
|
445
|
+
<div class="sx-field"><span class="sx-field-label" id="ax-dup-scope-label">${t('agentsStudio.duplicate.scope')}</span>${dropdown('ax-dup-scope', scopeEntries(ctx.info?.projects || [], key.scope, { globalLabel: t('agentsStudio.scope.globalLibrary'), projectsLabel: t('agentsStudio.scope.pinTo') }), { labelledBy: 'ax-dup-scope-label' })}</div>`);
|
|
446
|
+
let made = null;
|
|
447
|
+
const answer = await ctx.ask({
|
|
448
|
+
title: t('agentsStudio.duplicate.title', { name: name || key.id }),
|
|
449
|
+
lines: [t('agentsStudio.duplicate.help')],
|
|
450
|
+
extra, className: 'ax-dlg',
|
|
451
|
+
buttons: [{ id: 'cancel', label: t('agentsStudio.action.cancel') }, { id: 'copy', label: t('agentsStudio.action.duplicate'), kind: 'primary' }],
|
|
452
|
+
onOpen: (ui) => {
|
|
453
|
+
wireDropdowns(ui.box, { signal: life2.signal });
|
|
454
|
+
const input = ui.box.querySelector('#ax-dup-id');
|
|
455
|
+
input.focus(); input.select();
|
|
456
|
+
input.addEventListener('keydown', (e) => { if (e.key === 'Enter') { e.preventDefault(); ui.byId.get('copy')?.click(); } }, { signal: life2.signal });
|
|
457
|
+
},
|
|
458
|
+
// The copy is made while the question is open: a refusal (an id that is taken) is said in it.
|
|
459
|
+
accept: (id, ui) => {
|
|
460
|
+
if (id !== 'copy') return true;
|
|
461
|
+
if (made) return true;
|
|
462
|
+
const input = ui.box.querySelector('#ax-dup-id');
|
|
463
|
+
const note = ui.box.querySelector('#ax-dup-error');
|
|
464
|
+
const scope = scopeFromValue(ui.box.querySelector('#ax-dup-scope').value);
|
|
465
|
+
ui.setDisabled('copy', true);
|
|
466
|
+
ctx.api.copy(key, { id: input.value.trim().toLowerCase(), scope }).then((res) => { made = res; ui.done('copy'); }, (error) => {
|
|
467
|
+
note.hidden = false;
|
|
468
|
+
note.textContent = errorText(t, error);
|
|
469
|
+
ui.setDisabled('copy', false);
|
|
470
|
+
input.focus();
|
|
471
|
+
});
|
|
472
|
+
return false;
|
|
473
|
+
},
|
|
474
|
+
});
|
|
475
|
+
life2.abort();
|
|
476
|
+
if (answer !== 'copy' || !made) return null;
|
|
477
|
+
ctx.toast(t('agentsStudio.toast.duplicated', { id: made.agent.id }));
|
|
478
|
+
ctx.changed();
|
|
479
|
+
return { id: made.agent.id, scope: made.agent.scope };
|
|
480
|
+
}
|
|
481
|
+
|
|
482
|
+
async function exportAgent(ctx, ed) {
|
|
483
|
+
const { t } = ctx;
|
|
484
|
+
try {
|
|
485
|
+
const res = await ctx.api.exportAgent(ed.key);
|
|
486
|
+
downloadText(fileName(ed.key), `${JSON.stringify(res.bundle, null, 2)}\n`);
|
|
487
|
+
ctx.toast(ctx.tp('agentsStudio.toast.exported', res.bundle?.agents?.length ?? 1));
|
|
488
|
+
} catch (error) { ctx.toast(t('agentsStudio.toast.exportFailed', { error: errorText(t, error) }), 'error'); }
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
function openMenu(ctx, ed, opener, head) {
|
|
492
|
+
const { t } = ctx;
|
|
493
|
+
if (closeAgentMenu()) return;
|
|
494
|
+
const draft = ed.agent?.draftDefinition;
|
|
495
|
+
const s = standingOf(ed.agent);
|
|
496
|
+
const items = [
|
|
497
|
+
ctx.caps.has('copy') ? { id: 'duplicate', label: t('agentsStudio.action.duplicate') } : null,
|
|
498
|
+
ctx.caps.has('export') ? { id: 'export', label: t('agentsStudio.action.export') } : null,
|
|
499
|
+
canExportNative(ctx, ed.agent) ? { id: 'native-export', label: t('agentsStudio.nativeExport.action') } : null,
|
|
500
|
+
draft?.status === 'draft' ? { id: 'discard', label: t('agentsStudio.action.discardDraft'), danger: true } : null,
|
|
501
|
+
ctx.owner && ed.agent?.source !== 'builtin' && (draft || s.status === 'approved') ? { id: 'withdraw', label: t('agentsStudio.action.withdrawMenu'), danger: true } : null,
|
|
502
|
+
ctx.owner && ed.agent?.source !== 'builtin' ? { id: 'delete', label: t('agentsStudio.action.delete'), danger: true } : null,
|
|
503
|
+
].filter(Boolean);
|
|
504
|
+
const el = document.createElement('div');
|
|
505
|
+
el.className = 'sx-menu ax-menu';
|
|
506
|
+
el.setAttribute('role', 'menu');
|
|
507
|
+
el.setAttribute('aria-label', t('agentsStudio.action.more'));
|
|
508
|
+
setHTML(el, html`${items.map((i, n) => html`<button type="button" role="menuitem" class="sx-menu-item${i.danger ? ' sx-menu-item--danger' : ''}" data-item="${i.id}" tabindex="${n === 0 ? '0' : '-1'}">${i.label}</button>`)}`);
|
|
509
|
+
el.opener = opener;
|
|
510
|
+
head.append(el);
|
|
511
|
+
menuEl = el;
|
|
512
|
+
opener.setAttribute('aria-expanded', 'true');
|
|
513
|
+
el.querySelector('[role="menuitem"]')?.focus();
|
|
514
|
+
el.addEventListener('keydown', (e) => {
|
|
515
|
+
const list = [...el.querySelectorAll('[role="menuitem"]')];
|
|
516
|
+
const at = list.indexOf(document.activeElement);
|
|
517
|
+
if (e.key === 'ArrowDown' || e.key === 'ArrowUp') { e.preventDefault(); list[(at + (e.key === 'ArrowDown' ? 1 : -1) + list.length) % list.length]?.focus(); }
|
|
518
|
+
else if (e.key === 'Home') { e.preventDefault(); list[0]?.focus(); } else if (e.key === 'End') { e.preventDefault(); list.at(-1)?.focus(); }
|
|
519
|
+
else if (e.key === 'Tab') closeAgentMenu();
|
|
520
|
+
});
|
|
521
|
+
el.addEventListener('click', async (e) => {
|
|
522
|
+
const item = e.target.closest('[data-item]')?.dataset.item;
|
|
523
|
+
if (!item) return;
|
|
524
|
+
opener.setAttribute('aria-expanded', 'false');
|
|
525
|
+
closeAgentMenu();
|
|
526
|
+
if (item === 'duplicate') { const made = await duplicateAgent(ctx, ed.key, ed.agent?.name); if (made) ctx.go({ type: 'agent', key: made, tab: 'edit' }); }
|
|
527
|
+
else if (item === 'export') exportAgent(ctx, ed);
|
|
528
|
+
else if (item === 'native-export') exportToHost(ctx, ed);
|
|
529
|
+
else if (item === 'discard') discardDraft(ctx, ed);
|
|
530
|
+
else if (item === 'withdraw') withdraw(ctx, ed);
|
|
531
|
+
else if (item === 'delete') remove(ctx, ed);
|
|
532
|
+
});
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
// ── Drawing ──
|
|
536
|
+
|
|
537
|
+
/** Draw the workspace of the editor state `ed` in the main area. */
|
|
538
|
+
export function renderAgent(main, ctx, ed) {
|
|
539
|
+
leaveAgent();
|
|
540
|
+
life = new AbortController();
|
|
541
|
+
const { signal } = life;
|
|
542
|
+
const { t } = ctx;
|
|
543
|
+
const tab = ed.mode === 'new' ? 'edit' : ctx.view.tab;
|
|
544
|
+
setHTML(main, html`<section class="sx-place ax-place ax-ws" aria-labelledby="ax-ws-name">
|
|
545
|
+
${headHTML(ctx, ed)}
|
|
546
|
+
<div class="sx-banners" id="ax-banners">${bannersHTML(ctx, ed)}</div>
|
|
547
|
+
<div class="sx-tabpanel ax-tabpanel" id="ax-tabpanel" role="tabpanel" tabindex="-1"${ed.mode === 'agent' ? html` aria-labelledby="ax-tab-${tab}"` : html` aria-label="${t('agentsStudio.tab.edit')}"`}></div>
|
|
548
|
+
</section>`);
|
|
549
|
+
const panel = main.querySelector('#ax-tabpanel');
|
|
550
|
+
const head = main.querySelector('.ax-ws-head');
|
|
551
|
+
|
|
552
|
+
// The header follows the form (its name, its mark, whether something is unsaved, which actions are open).
|
|
553
|
+
ed.onState = () => {
|
|
554
|
+
if (!head.isConnected) return;
|
|
555
|
+
const dirty = head.querySelector('#ax-dirty');
|
|
556
|
+
if (dirty) dirty.hidden = !(ed.dirty && ed.mode === 'agent');
|
|
557
|
+
const name = head.querySelector('#ax-ws-name');
|
|
558
|
+
const title = ed.mode === 'new' ? (ed.form.name || t('agentsStudio.editor.newTitle')) : (ed.form.name || ed.agent?.name || ed.key.id);
|
|
559
|
+
if (name && name.textContent !== title) name.textContent = title;
|
|
560
|
+
setHTML(head.querySelector('#ax-ws-mark'), agentMark({ icon: ed.form.icon, color: ed.form.color }, 20));
|
|
561
|
+
const actions = head.querySelector('#ax-actions');
|
|
562
|
+
const focused = actions.contains(document.activeElement) ? document.activeElement.dataset.act : null;
|
|
563
|
+
setHTML(actions, actionsHTML(ctx, ed));
|
|
564
|
+
if (focused) actions.querySelector(`[data-act="${focused}"]`)?.focus({ preventScroll: true });
|
|
565
|
+
};
|
|
566
|
+
|
|
567
|
+
if (ed.loading) setHTML(panel, loadingHTML(t));
|
|
568
|
+
else if (ed.error) setHTML(panel, errorHTML(t, ed.error));
|
|
569
|
+
else if (tab === 'revisions') renderRevisionsPanel(panel, ctx, ed);
|
|
570
|
+
else if (tab === 'runs') renderRunsPanel(panel, ctx, ed);
|
|
571
|
+
else if (tab === 'test') renderTestPanel(panel, ctx, ed);
|
|
572
|
+
else renderEditorPanel(panel, ctx, ed);
|
|
573
|
+
|
|
574
|
+
main.addEventListener('click', (e) => {
|
|
575
|
+
const el = e.target.closest?.('[data-act]');
|
|
576
|
+
if (menuEl && !menuEl.contains(e.target) && el?.dataset.act !== 'menu') closeAgentMenu();
|
|
577
|
+
if (!el || !main.contains(el) || el.disabled) return;
|
|
578
|
+
const act = el.dataset.act;
|
|
579
|
+
if (act === 'back') ctx.go({ type: 'back' });
|
|
580
|
+
else if (act === 'tab') ctx.go({ type: 'tab', tab: el.dataset.tab });
|
|
581
|
+
else if (act === 'save') saveEditor(ctx, ed).then((ok) => { if (ok && ed.mode === 'agent') ctx.render({ keepFocus: true }); });
|
|
582
|
+
else if (act === 'submit') submit(ctx, ed);
|
|
583
|
+
else if (act === 'approve') approve(ctx, ed);
|
|
584
|
+
else if (act === 'back-to-draft') backToDraft(ctx, ed);
|
|
585
|
+
else if (act === 'menu') openMenu(ctx, ed, el, head);
|
|
586
|
+
else if (act === 'retry') loadAgent(ctx, ed).then(() => ctx.render());
|
|
587
|
+
}, { signal });
|
|
588
|
+
// Tabs: the arrows move between them.
|
|
589
|
+
main.addEventListener('keydown', (e) => {
|
|
590
|
+
const tabEl = e.target.closest?.('[role="tab"]');
|
|
591
|
+
if (!tabEl || !['ArrowRight', 'ArrowLeft', 'Home', 'End'].includes(e.key)) return;
|
|
592
|
+
const list = [...main.querySelectorAll('[role="tab"]')];
|
|
593
|
+
const at = list.indexOf(tabEl);
|
|
594
|
+
const to = e.key === 'Home' ? 0 : e.key === 'End' ? list.length - 1 : (at + (e.key === 'ArrowRight' ? 1 : -1) + list.length) % list.length;
|
|
595
|
+
e.preventDefault();
|
|
596
|
+
list[to]?.focus();
|
|
597
|
+
list[to]?.click();
|
|
598
|
+
}, { signal });
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
/** Ctrl/⌘+S saves the form. True when the key was taken. */
|
|
602
|
+
export function agentShortcut(e, ctx, ed, mac) {
|
|
603
|
+
const mod = mac ? e.metaKey : e.ctrlKey;
|
|
604
|
+
if (!mod || e.altKey || e.key.toLowerCase() !== 's' || !ed || ed.loading || ed.error) return false;
|
|
605
|
+
if (ed.mode === 'agent' && (!ed.editable || !ed.dirty)) return true;
|
|
606
|
+
if (ed.mode === 'agent' && ctx.view.tab !== 'edit') return true;
|
|
607
|
+
saveEditor(ctx, ed).then((ok) => { if (ok && ed.mode === 'agent') ctx.render({ keepFocus: true }); });
|
|
608
|
+
return true;
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
/** Whether leaving this editor would lose something. */
|
|
612
|
+
export const editorDirty = (ed) => !!ed && !ed.closed && ed.dirty === true && (ed.mode === 'agent' ? isDirty(ed.base, ed.form) : true);
|
|
613
|
+
|
|
614
|
+
export { agentKeyText };
|