painapple-code 1.0.0rc1__py3-none-any.whl
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.
- painapple_code/__init__.py +30 -0
- painapple_code/__main__.py +13 -0
- painapple_code/_version.py +24 -0
- painapple_code/auth_middleware.py +507 -0
- painapple_code/bridge_paths.py +1028 -0
- painapple_code/cli/__init__.py +32 -0
- painapple_code/cli/docker/__init__.py +116 -0
- painapple_code/cli/docker/commands.py +757 -0
- painapple_code/cli/docker/config.py +364 -0
- painapple_code/cli/docker/runtime.py +88 -0
- painapple_code/cli/docker/wizard.py +415 -0
- painapple_code/cli/ui.py +404 -0
- painapple_code/cost_analytics.py +884 -0
- painapple_code/data/models.defaults.yaml +15 -0
- painapple_code/data/models.yaml +15 -0
- painapple_code/data/presets.defaults.json +32 -0
- painapple_code/data/strings.yaml +1573 -0
- painapple_code/helpers.py +140 -0
- painapple_code/prompt_explorer.py +984 -0
- painapple_code/providers/__init__.py +215 -0
- painapple_code/providers/base.py +515 -0
- painapple_code/providers/claude/__init__.py +69 -0
- painapple_code/providers/claude/capabilities.py +167 -0
- painapple_code/providers/claude/errors.py +66 -0
- painapple_code/providers/claude/launch.py +47 -0
- painapple_code/providers/claude/summary.py +83 -0
- painapple_code/providers/claude/translate.py +61 -0
- painapple_code/routes/__init__.py +0 -0
- painapple_code/routes/api_agents.py +440 -0
- painapple_code/routes/api_bridge.py +132 -0
- painapple_code/routes/api_bridge_commit_sections.py +127 -0
- painapple_code/routes/api_bridge_config.py +506 -0
- painapple_code/routes/api_bridge_session_prefs.py +212 -0
- painapple_code/routes/api_browser.py +521 -0
- painapple_code/routes/api_commands.py +368 -0
- painapple_code/routes/api_costs.py +128 -0
- painapple_code/routes/api_exec.py +50 -0
- painapple_code/routes/api_files.py +493 -0
- painapple_code/routes/api_git.py +651 -0
- painapple_code/routes/api_logs.py +532 -0
- painapple_code/routes/api_plugins.py +273 -0
- painapple_code/routes/api_project_config.py +294 -0
- painapple_code/routes/api_prompts.py +231 -0
- painapple_code/routes/api_session_stash.py +205 -0
- painapple_code/routes/api_session_welcome.py +138 -0
- painapple_code/routes/api_sessions.py +540 -0
- painapple_code/routes/api_shadow.py +323 -0
- painapple_code/routes/api_shadow_db.py +473 -0
- painapple_code/routes/api_shadow_files.py +327 -0
- painapple_code/routes/api_shadow_search.py +476 -0
- painapple_code/routes/api_skills.py +609 -0
- painapple_code/routes/api_tasks.py +138 -0
- painapple_code/routes/api_terminal.py +589 -0
- painapple_code/routes/api_upload.py +213 -0
- painapple_code/routes/api_viewer.py +188 -0
- painapple_code/routes/dependencies.py +17 -0
- painapple_code/routes/ws_chat.py +679 -0
- painapple_code/server.py +1349 -0
- painapple_code/server_logging.py +242 -0
- painapple_code/services/__init__.py +0 -0
- painapple_code/services/agent_session.py +2236 -0
- painapple_code/session_store.py +254 -0
- painapple_code/session_store_core.py +820 -0
- painapple_code/session_store_migration.py +144 -0
- painapple_code/shadow_db.py +760 -0
- painapple_code/shadow_db_plans.py +369 -0
- painapple_code/shadow_db_queries.py +595 -0
- painapple_code/shadow_db_schema.py +676 -0
- painapple_code/shadow_git.py +1133 -0
- painapple_code/shadow_git_frontmatter.py +314 -0
- painapple_code/shadow_git_sections.py +520 -0
- painapple_code/shadow_git_summary.py +457 -0
- painapple_code/shadow_parser.py +560 -0
- painapple_code/static/css/00-variables.css +177 -0
- painapple_code/static/css/01-base.css +150 -0
- painapple_code/static/css/02-tooltips.css +36 -0
- painapple_code/static/css/09-left-rail.css +311 -0
- painapple_code/static/css/10-header.css +691 -0
- painapple_code/static/css/11-connection-bar.css +120 -0
- painapple_code/static/css/20-messages.css +739 -0
- painapple_code/static/css/21-tool-blocks.css +2326 -0
- painapple_code/static/css/22-edit-diff.css +574 -0
- painapple_code/static/css/23-thinking.css +1570 -0
- painapple_code/static/css/24-background-tasks.css +355 -0
- painapple_code/static/css/25-context-block.css +252 -0
- painapple_code/static/css/30-markdown.css +531 -0
- painapple_code/static/css/40-input.css +1955 -0
- painapple_code/static/css/41-autocomplete.css +127 -0
- painapple_code/static/css/42-activity-strip.css +88 -0
- painapple_code/static/css/43-file-autocomplete.css +136 -0
- painapple_code/static/css/44-snippets-autocomplete.css +237 -0
- painapple_code/static/css/45-selection-bar.css +362 -0
- painapple_code/static/css/46-keyboard-bar.css +119 -0
- painapple_code/static/css/47-keyboard-longpress.css +116 -0
- painapple_code/static/css/47-token-profile.css +105 -0
- painapple_code/static/css/50-welcome.css +2969 -0
- painapple_code/static/css/51-modals.css +294 -0
- painapple_code/static/css/52-utilities.css +77 -0
- painapple_code/static/css/53-image-upload.css +415 -0
- painapple_code/static/css/54-todo-list.css +102 -0
- painapple_code/static/css/55-file-upload.css +113 -0
- painapple_code/static/css/56-chat-navigator.css +218 -0
- painapple_code/static/css/56-plan-approval.css +204 -0
- painapple_code/static/css/56-question-form.css +496 -0
- painapple_code/static/css/57-swipe-indicator.css +95 -0
- painapple_code/static/css/58-session-families.css +626 -0
- painapple_code/static/css/61-log-explorer.css +683 -0
- painapple_code/static/css/62-json-tree.css +411 -0
- painapple_code/static/css/62-skills-widget.css +648 -0
- painapple_code/static/css/63-commands-widget.css +30 -0
- painapple_code/static/css/63-plugins-widget.css +174 -0
- painapple_code/static/css/63-terminal.css +514 -0
- painapple_code/static/css/65-snippets-widget.css +425 -0
- painapple_code/static/css/66-active-sessions.css +979 -0
- painapple_code/static/css/66-agents-widget.css +265 -0
- painapple_code/static/css/66-file-explorer-widget.css +854 -0
- painapple_code/static/css/66-git-panel.css +795 -0
- painapple_code/static/css/67-diff-viewer.css +576 -0
- painapple_code/static/css/67-editor-view.css +675 -0
- painapple_code/static/css/67-file-preview-widget.css +1317 -0
- painapple_code/static/css/68-browser-widget.css +254 -0
- painapple_code/static/css/68-compare-wizard.css +355 -0
- painapple_code/static/css/68-csv-preview.css +106 -0
- painapple_code/static/css/68-helpers-install-widget.css +437 -0
- painapple_code/static/css/68-terminal-view.css +98 -0
- painapple_code/static/css/68-uploads-widget.css +163 -0
- painapple_code/static/css/69-cost-analytics.css +537 -0
- painapple_code/static/css/70-config-panel.css +3227 -0
- painapple_code/static/css/70-excalidraw.css +136 -0
- painapple_code/static/css/70-prompt-explorer.css +782 -0
- painapple_code/static/css/71-chart.css +111 -0
- painapple_code/static/css/72-discussion-sidebar.css +685 -0
- painapple_code/static/css/74-debug-logs.css +656 -0
- painapple_code/static/css/76-history-explorer.css +680 -0
- painapple_code/static/css/80-open-dialog.css +146 -0
- painapple_code/static/css/80-quick-switcher.css +260 -0
- painapple_code/static/css/80-widget-system.css +1733 -0
- painapple_code/static/css/81-quick-actions.css +1011 -0
- painapple_code/static/css/82-context-popover.css +1180 -0
- painapple_code/static/css/83-context-menu.css +300 -0
- painapple_code/static/css/85-lazy-loading.css +102 -0
- painapple_code/static/css/86-zen-mode.css +708 -0
- painapple_code/static/css/87-grid-switcher.css +341 -0
- painapple_code/static/css/login.css +198 -0
- painapple_code/static/feature-triage.html +1208 -0
- painapple_code/static/icons/apple-touch-icon.png +0 -0
- painapple_code/static/icons/favicon-32.png +0 -0
- painapple_code/static/icons/favicon.ico +0 -0
- painapple_code/static/icons/icon-128.png +0 -0
- painapple_code/static/icons/icon-144.png +0 -0
- painapple_code/static/icons/icon-152.png +0 -0
- painapple_code/static/icons/icon-180.png +0 -0
- painapple_code/static/icons/icon-192.png +0 -0
- painapple_code/static/icons/icon-384.png +0 -0
- painapple_code/static/icons/icon-512.png +0 -0
- painapple_code/static/icons/icon-72.png +0 -0
- painapple_code/static/icons/icon-96.png +0 -0
- painapple_code/static/js/activity-strip.js +181 -0
- painapple_code/static/js/app-context.js +157 -0
- painapple_code/static/js/app.js +5875 -0
- painapple_code/static/js/auth-fetch.js +46 -0
- painapple_code/static/js/background-tasks.js +274 -0
- painapple_code/static/js/caret-position.js +171 -0
- painapple_code/static/js/chat-navigator.js +683 -0
- painapple_code/static/js/chat-search.js +323 -0
- painapple_code/static/js/command-executor.js +172 -0
- painapple_code/static/js/command-store.js +497 -0
- painapple_code/static/js/components.js +982 -0
- painapple_code/static/js/config.js +158 -0
- painapple_code/static/js/context-menu.js +570 -0
- painapple_code/static/js/controllers/chat-controller.js +3667 -0
- painapple_code/static/js/controllers/dialog-controller.js +185 -0
- painapple_code/static/js/controllers/tab-controller.js +1505 -0
- painapple_code/static/js/controllers/thinking-controller.js +905 -0
- painapple_code/static/js/diff-utils.js +484 -0
- painapple_code/static/js/editor-view.js +597 -0
- painapple_code/static/js/effort-settings.js +369 -0
- painapple_code/static/js/file-autocomplete.js +515 -0
- painapple_code/static/js/file-tabs.js +120 -0
- painapple_code/static/js/gestures.js +448 -0
- painapple_code/static/js/grid-switcher.js +332 -0
- painapple_code/static/js/input-handler.js +922 -0
- painapple_code/static/js/keyboard-bar.js +495 -0
- painapple_code/static/js/linkify-utils.js +200 -0
- painapple_code/static/js/open-dialog.js +870 -0
- painapple_code/static/js/orphan-terminals.js +366 -0
- painapple_code/static/js/perf-marks.js +102 -0
- painapple_code/static/js/permission-settings.js +347 -0
- painapple_code/static/js/preview/json-tree.js +213 -0
- painapple_code/static/js/preview/preview-edit.js +366 -0
- painapple_code/static/js/preview/preview-events.js +239 -0
- painapple_code/static/js/preview/preview-history.js +533 -0
- painapple_code/static/js/preview/preview-inline-edit.js +785 -0
- painapple_code/static/js/preview/preview-poll.js +102 -0
- painapple_code/static/js/preview/preview-render.js +445 -0
- painapple_code/static/js/preview/preview-search.js +391 -0
- painapple_code/static/js/preview/preview-state.js +175 -0
- painapple_code/static/js/preview/preview-utils.js +244 -0
- painapple_code/static/js/preview-plugins/chart-plugin.js +22 -0
- painapple_code/static/js/preview-plugins/csv-plugin.js +188 -0
- painapple_code/static/js/preview-plugins/excalidraw-plugin.js +25 -0
- painapple_code/static/js/preview-plugins/html-plugin.js +104 -0
- painapple_code/static/js/preview-plugins/image-plugin.js +20 -0
- painapple_code/static/js/preview-plugins/index.js +32 -0
- painapple_code/static/js/preview-plugins/json-plugin.js +131 -0
- painapple_code/static/js/preview-plugins/jsonl-plugin.js +170 -0
- painapple_code/static/js/preview-plugins/markdown-plugin.js +76 -0
- painapple_code/static/js/preview-plugins/panzoom-plugin.js +62 -0
- painapple_code/static/js/preview-plugins/plugin-helpers.js +264 -0
- painapple_code/static/js/prompt-favorites.js +187 -0
- painapple_code/static/js/quick-actions-menu.js +1708 -0
- painapple_code/static/js/quick-actions-registry.js +1147 -0
- painapple_code/static/js/quick-switcher/controller.js +217 -0
- painapple_code/static/js/quick-switcher/fuzzy-scorer.js +123 -0
- painapple_code/static/js/quick-switcher/index.js +28 -0
- painapple_code/static/js/quick-switcher/providers/base-provider.js +51 -0
- painapple_code/static/js/quick-switcher/providers/command-provider.js +56 -0
- painapple_code/static/js/quick-switcher/providers/file-provider.js +296 -0
- painapple_code/static/js/quick-switcher/providers/panel-provider.js +130 -0
- painapple_code/static/js/quick-switcher/providers/project-provider.js +254 -0
- painapple_code/static/js/quick-switcher/providers/skills-provider.js +108 -0
- painapple_code/static/js/quick-switcher/registry.js +69 -0
- painapple_code/static/js/quick-switcher/ui/item.js +54 -0
- painapple_code/static/js/quick-switcher/ui/picker.js +350 -0
- painapple_code/static/js/recent-opens.js +40 -0
- painapple_code/static/js/scroll-manager.js +488 -0
- painapple_code/static/js/scroll-state-machine.js +359 -0
- painapple_code/static/js/selection/action-bar.js +749 -0
- painapple_code/static/js/selection/index.js +15 -0
- painapple_code/static/js/selection/selection-handler.js +779 -0
- painapple_code/static/js/selection/state.js +107 -0
- painapple_code/static/js/session/agent-progress.js +202 -0
- painapple_code/static/js/session/handle-agent-message.js +448 -0
- painapple_code/static/js/session/handle-message.js +435 -0
- painapple_code/static/js/session/interactive.js +305 -0
- painapple_code/static/js/session/message-store.js +204 -0
- painapple_code/static/js/session/messages.js +244 -0
- painapple_code/static/js/session/persistence.js +111 -0
- painapple_code/static/js/session/restore.js +123 -0
- painapple_code/static/js/session/sync.js +227 -0
- painapple_code/static/js/session-container-pool.js +340 -0
- painapple_code/static/js/session.js +912 -0
- painapple_code/static/js/shortcut-hints.js +240 -0
- painapple_code/static/js/shortcuts.js +929 -0
- painapple_code/static/js/skills-autocomplete.js +262 -0
- painapple_code/static/js/snippets-autocomplete.js +738 -0
- painapple_code/static/js/stash-ui.js +458 -0
- painapple_code/static/js/stash.js +555 -0
- painapple_code/static/js/status-bar.js +737 -0
- painapple_code/static/js/token-profile.js +250 -0
- painapple_code/static/js/tool-renderer-blocks.js +1576 -0
- painapple_code/static/js/tool-renderer-thinking.js +819 -0
- painapple_code/static/js/tool-renderer.js +1473 -0
- painapple_code/static/js/tooltips.js +193 -0
- painapple_code/static/js/upload-manager.js +688 -0
- painapple_code/static/js/utils.js +453 -0
- painapple_code/static/js/welcome/api.js +356 -0
- painapple_code/static/js/welcome/cards.js +547 -0
- painapple_code/static/js/welcome/context-menu.js +563 -0
- painapple_code/static/js/welcome/families.js +763 -0
- painapple_code/static/js/welcome/preview.js +234 -0
- painapple_code/static/js/welcome/state.js +128 -0
- painapple_code/static/js/welcome.js +1777 -0
- painapple_code/static/js/widget-system/base-widget.js +708 -0
- painapple_code/static/js/widget-system/device-manager.js +178 -0
- painapple_code/static/js/widget-system/event-bus.js +152 -0
- painapple_code/static/js/widget-system/icons.js +114 -0
- painapple_code/static/js/widget-system/index.js +49 -0
- painapple_code/static/js/widget-system/init.js +54 -0
- painapple_code/static/js/widget-system/types/bottom-sheet.js +307 -0
- painapple_code/static/js/widget-system/types/floating.js +813 -0
- painapple_code/static/js/widget-system/types/index.js +40 -0
- painapple_code/static/js/widget-system/types/modal.js +147 -0
- painapple_code/static/js/widget-system/types/sidebar.js +158 -0
- painapple_code/static/js/widget-system/types/tab.js +146 -0
- painapple_code/static/js/widget-system/types/top-sheet.js +203 -0
- painapple_code/static/js/widget-system/widget-manager.js +1170 -0
- painapple_code/static/js/widgets/active-sessions-widget.js +748 -0
- painapple_code/static/js/widgets/agents-widget.js +897 -0
- painapple_code/static/js/widgets/browser-widget.js +409 -0
- painapple_code/static/js/widgets/commands-widget.js +694 -0
- painapple_code/static/js/widgets/config/commit-sections.js +449 -0
- painapple_code/static/js/widgets/config/dir-autocomplete.js +223 -0
- painapple_code/static/js/widgets/config/gestures.js +161 -0
- painapple_code/static/js/widgets/config/models-tab.js +296 -0
- painapple_code/static/js/widgets/config/quick-actions-tab.js +641 -0
- painapple_code/static/js/widgets/config/shortcut-editor.js +587 -0
- painapple_code/static/js/widgets/config/state.js +483 -0
- painapple_code/static/js/widgets/config/system-controls.js +304 -0
- painapple_code/static/js/widgets/config-widget.js +1384 -0
- painapple_code/static/js/widgets/cost-analytics-widget.js +629 -0
- painapple_code/static/js/widgets/debug-widget.js +693 -0
- painapple_code/static/js/widgets/diff-viewer-widget.js +1606 -0
- painapple_code/static/js/widgets/discussion-widget.js +1074 -0
- painapple_code/static/js/widgets/file-explorer-widget.js +2147 -0
- painapple_code/static/js/widgets/file-preview-widget.js +754 -0
- painapple_code/static/js/widgets/git-widget.js +793 -0
- painapple_code/static/js/widgets/helpers-install-widget.js +569 -0
- painapple_code/static/js/widgets/history-explorer-widget.js +2699 -0
- painapple_code/static/js/widgets/image-preview-widget.js +433 -0
- painapple_code/static/js/widgets/index.js +162 -0
- painapple_code/static/js/widgets/log-explorer-widget.js +1002 -0
- painapple_code/static/js/widgets/plugins-widget.js +305 -0
- painapple_code/static/js/widgets/prompt-explorer-widget.js +833 -0
- painapple_code/static/js/widgets/skills-widget.js +843 -0
- painapple_code/static/js/widgets/snippets-widget.js +479 -0
- painapple_code/static/js/widgets/sub-agents-widget.js +335 -0
- painapple_code/static/js/widgets/tasks-widget.js +381 -0
- painapple_code/static/js/widgets/terminal/connection.js +283 -0
- painapple_code/static/js/widgets/terminal/gestures.js +330 -0
- painapple_code/static/js/widgets/terminal/init.js +518 -0
- painapple_code/static/js/widgets/terminal/link-providers.js +440 -0
- painapple_code/static/js/widgets/terminal/render.js +159 -0
- painapple_code/static/js/widgets/terminal/size.js +54 -0
- painapple_code/static/js/widgets/terminal/state.js +210 -0
- painapple_code/static/js/widgets/terminal-widget.js +791 -0
- painapple_code/static/js/widgets/uploads-widget.js +309 -0
- painapple_code/static/js/widgets/zen-widget.js +999 -0
- painapple_code/static/login.html +156 -0
- painapple_code/static/manifest.json +73 -0
- painapple_code/static/sw.js +277 -0
- painapple_code/static/vendor/README.md +49 -0
- painapple_code/static/vendor/codemirror.js +32 -0
- painapple_code/static/vendor/github-markdown-dark.min.css +1124 -0
- painapple_code/static/vendor/highlight-github-dark.min.css +10 -0
- painapple_code/static/vendor/highlight-lang-dockerfile.min.js +8 -0
- painapple_code/static/vendor/highlight-lang-nginx.min.js +21 -0
- painapple_code/static/vendor/highlight-lang-properties.min.js +10 -0
- painapple_code/static/vendor/highlight-lang-scala.min.js +28 -0
- painapple_code/static/vendor/highlight.min.js +1213 -0
- painapple_code/static/vendor/marked.min.js +6 -0
- painapple_code/static/vendor/xterm-addon-fit.js +2 -0
- painapple_code/static/vendor/xterm.css +209 -0
- painapple_code/static/vendor/xterm.js +2 -0
- painapple_code/static/web-client.html +660 -0
- painapple_code/subprocess_registry.py +535 -0
- painapple_code/tls_cert.py +86 -0
- painapple_code/tools/agents/shadow-git-helper.md +399 -0
- painapple_code/tools/excalidraw-to-svg.js +143 -0
- painapple_code/tools/install-helpers.sh +148 -0
- painapple_code/tools/shadow-git +262 -0
- painapple_code/tools/shadow-query +108 -0
- painapple_code/tools/vegalite-to-svg.js +79 -0
- painapple_code/turn_query.py +766 -0
- painapple_code/turn_tracker.py +194 -0
- painapple_code/utils/__init__.py +0 -0
- painapple_code/utils/agent_cli.py +297 -0
- painapple_code/utils/chart.py +103 -0
- painapple_code/utils/excalidraw.py +107 -0
- painapple_code/utils/file_paths.py +340 -0
- painapple_code/utils/generate_icons.py +154 -0
- painapple_code/utils/token_profiles.py +83 -0
- painapple_code/viewer_templates.py +647 -0
- painapple_code/welcome_search.py +829 -0
- painapple_code-1.0.0rc1.dist-info/METADATA +382 -0
- painapple_code-1.0.0rc1.dist-info/RECORD +362 -0
- painapple_code-1.0.0rc1.dist-info/WHEEL +5 -0
- painapple_code-1.0.0rc1.dist-info/entry_points.txt +2 -0
- painapple_code-1.0.0rc1.dist-info/licenses/LICENSE +661 -0
- painapple_code-1.0.0rc1.dist-info/scm_file_list.json +476 -0
- painapple_code-1.0.0rc1.dist-info/scm_version.json +8 -0
- painapple_code-1.0.0rc1.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,897 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Agents Manager Widget
|
|
3
|
+
*
|
|
4
|
+
* Floating widget that lists agent definition files (project + personal) with
|
|
5
|
+
* search, scope pills, and an inline raw editor for the agent's `.md` body.
|
|
6
|
+
*
|
|
7
|
+
* Mirrors `skills-widget.js` in shape, but for flat `<name>.md` files in
|
|
8
|
+
* `~/.claude/agents/` (personal) and `<cwd>/.claude/agents/` (project).
|
|
9
|
+
*
|
|
10
|
+
* Distinct from the Sub-Agents widget (`sub-agents-widget.js`), which is a
|
|
11
|
+
* runtime monitor for Task-tool invocations.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import S from '../strings.js';
|
|
15
|
+
import { escapeHtml } from '../utils.js';
|
|
16
|
+
import { CONFIG, debug } from '../config.js';
|
|
17
|
+
import { WidgetManager } from '../widget-system/index.js';
|
|
18
|
+
import {
|
|
19
|
+
loadAgentPatterns,
|
|
20
|
+
saveAgentPatterns,
|
|
21
|
+
DEFAULT_AGENT_PATTERN,
|
|
22
|
+
loadDisabledAgents,
|
|
23
|
+
saveDisabledAgents,
|
|
24
|
+
} from '../snippets-autocomplete.js';
|
|
25
|
+
|
|
26
|
+
const PREF_KEY_CURRENT = 'agents-current-project-only';
|
|
27
|
+
const PREF_KEY_VIEW = 'agents-view-mode';
|
|
28
|
+
const PREF_KEY_SETTINGS_OPEN = 'agents-settings-section-open';
|
|
29
|
+
|
|
30
|
+
const state = {
|
|
31
|
+
container: null,
|
|
32
|
+
agents: [],
|
|
33
|
+
counts: { project: 0, personal: 0 },
|
|
34
|
+
loading: false,
|
|
35
|
+
error: null,
|
|
36
|
+
search: '',
|
|
37
|
+
originFilter: 'all',
|
|
38
|
+
currentProjectOnly: loadCurrentProjectOnly(),
|
|
39
|
+
viewMode: loadViewMode(),
|
|
40
|
+
expandedId: null,
|
|
41
|
+
editorState: null,
|
|
42
|
+
lastFetchKey: null,
|
|
43
|
+
settingsOpen: loadSettingsOpen(),
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
function loadCurrentProjectOnly() {
|
|
47
|
+
try { return localStorage.getItem(PREF_KEY_CURRENT) === 'true'; }
|
|
48
|
+
catch { return false; }
|
|
49
|
+
}
|
|
50
|
+
function saveCurrentProjectOnly(v) {
|
|
51
|
+
try { localStorage.setItem(PREF_KEY_CURRENT, v ? 'true' : 'false'); } catch {}
|
|
52
|
+
}
|
|
53
|
+
function loadViewMode() {
|
|
54
|
+
try { return localStorage.getItem(PREF_KEY_VIEW) === 'list' ? 'list' : 'grid'; }
|
|
55
|
+
catch { return 'grid'; }
|
|
56
|
+
}
|
|
57
|
+
function saveViewMode(v) {
|
|
58
|
+
try { localStorage.setItem(PREF_KEY_VIEW, v); } catch {}
|
|
59
|
+
}
|
|
60
|
+
function loadSettingsOpen() {
|
|
61
|
+
try { return localStorage.getItem(PREF_KEY_SETTINGS_OPEN) !== 'false'; }
|
|
62
|
+
catch { return true; }
|
|
63
|
+
}
|
|
64
|
+
function saveSettingsOpen(v) {
|
|
65
|
+
try { localStorage.setItem(PREF_KEY_SETTINGS_OPEN, v ? 'true' : 'false'); } catch {}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// ══════════════════════════════════════════════════════════════════
|
|
69
|
+
// DATA LOADING
|
|
70
|
+
// ══════════════════════════════════════════════════════════════════
|
|
71
|
+
|
|
72
|
+
async function loadAgents() {
|
|
73
|
+
const cwd = window.app?.activeSession?.cwd || '/';
|
|
74
|
+
state.loading = true;
|
|
75
|
+
state.error = null;
|
|
76
|
+
state.lastFetchKey = cwd;
|
|
77
|
+
renderShell();
|
|
78
|
+
try {
|
|
79
|
+
const r = await fetch(`${CONFIG.API_BASE}/api/agents?cwd=${encodeURIComponent(cwd)}`);
|
|
80
|
+
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
|
81
|
+
const data = await r.json();
|
|
82
|
+
state.agents = data.agents || [];
|
|
83
|
+
state.counts = data.counts || { project: 0, personal: 0 };
|
|
84
|
+
} catch (e) {
|
|
85
|
+
state.error = String(e.message || e);
|
|
86
|
+
} finally {
|
|
87
|
+
state.loading = false;
|
|
88
|
+
renderShell();
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// ══════════════════════════════════════════════════════════════════
|
|
93
|
+
// FILTERING
|
|
94
|
+
// ══════════════════════════════════════════════════════════════════
|
|
95
|
+
|
|
96
|
+
function filteredAgents() {
|
|
97
|
+
const q = state.search.trim().toLowerCase();
|
|
98
|
+
const origin = state.originFilter;
|
|
99
|
+
return state.agents.filter(a => {
|
|
100
|
+
if (state.currentProjectOnly && a.scope !== 'project') return false;
|
|
101
|
+
if (origin !== 'all' && a.scope !== origin) return false;
|
|
102
|
+
if (!q) return true;
|
|
103
|
+
if (a.name.toLowerCase().includes(q)) return true;
|
|
104
|
+
if ((a.description || '').toLowerCase().includes(q)) return true;
|
|
105
|
+
if ((a.body_preview || '').toLowerCase().includes(q)) return true;
|
|
106
|
+
return false;
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// ══════════════════════════════════════════════════════════════════
|
|
111
|
+
// RENDERING
|
|
112
|
+
// ══════════════════════════════════════════════════════════════════
|
|
113
|
+
|
|
114
|
+
const ICONS = {
|
|
115
|
+
folder: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M22 19a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h5l2 3h9a2 2 0 0 1 2 2z"/></svg>',
|
|
116
|
+
layers: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M12 2L2 7l10 5 10-5-10-5z"/><path d="M2 17l10 5 10-5"/><path d="M2 12l10 5 10-5"/></svg>',
|
|
117
|
+
document: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/><polyline points="14 2 14 8 20 8"/></svg>',
|
|
118
|
+
eye: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z"/><circle cx="12" cy="12" r="3"/></svg>',
|
|
119
|
+
eyeOff: '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><path d="M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94M9.9 4.24A9.12 9.12 0 0 1 12 4c7 0 11 8 11 8a18.5 18.5 0 0 1-2.16 3.19m-6.72-1.07a3 3 0 1 1-4.24-4.24"/><line x1="1" y1="1" x2="23" y2="23"/></svg>',
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
function scopeIcon(scope) {
|
|
123
|
+
if (scope === 'project') return ICONS.folder;
|
|
124
|
+
if (scope === 'personal') return ICONS.layers;
|
|
125
|
+
return ICONS.document;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
function renderShell() {
|
|
129
|
+
if (!state.container) return;
|
|
130
|
+
|
|
131
|
+
const filtered = filteredAgents();
|
|
132
|
+
const aw = S.agents_widget;
|
|
133
|
+
|
|
134
|
+
const pills = ['all', 'project', 'personal'].map(k => {
|
|
135
|
+
const label = aw.filters[k];
|
|
136
|
+
const count = k === 'all' ? state.agents.length : (state.counts[k] ?? 0);
|
|
137
|
+
const active = state.originFilter === k ? 'active' : '';
|
|
138
|
+
return `<button class="sk-pill ${active}" data-filter="${k}">
|
|
139
|
+
<span class="sk-pill-label">${label}</span>
|
|
140
|
+
<span class="sk-pill-count">${count}</span>
|
|
141
|
+
</button>`;
|
|
142
|
+
}).join('');
|
|
143
|
+
|
|
144
|
+
state.container.innerHTML = `
|
|
145
|
+
${renderSettingsSection()}
|
|
146
|
+
<div class="sk-toolbar">
|
|
147
|
+
<div class="sk-search-wrap">
|
|
148
|
+
<svg class="sk-search-icon" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
149
|
+
<circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/>
|
|
150
|
+
</svg>
|
|
151
|
+
<input type="text" class="sk-search" placeholder="${aw.search_placeholder}"
|
|
152
|
+
value="${escapeHtml(state.search)}" autocomplete="off" spellcheck="false" />
|
|
153
|
+
</div>
|
|
154
|
+
<label class="sk-current-toggle" title="${escapeHtml(aw.current_project_tooltip)}">
|
|
155
|
+
<input type="checkbox" ${state.currentProjectOnly ? 'checked' : ''} />
|
|
156
|
+
<span>${aw.current_project_label}</span>
|
|
157
|
+
</label>
|
|
158
|
+
<div class="sk-view-toggle">
|
|
159
|
+
<button class="sk-view-btn ${state.viewMode === 'grid' ? 'active' : ''}" data-view="grid" title="${aw.view_grid}" data-tooltip="${aw.view_grid}">
|
|
160
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><rect x="3" y="3" width="7" height="7"/><rect x="14" y="3" width="7" height="7"/><rect x="14" y="14" width="7" height="7"/><rect x="3" y="14" width="7" height="7"/></svg>
|
|
161
|
+
</button>
|
|
162
|
+
<button class="sk-view-btn ${state.viewMode === 'list' ? 'active' : ''}" data-view="list" title="${aw.view_list}" data-tooltip="${aw.view_list}">
|
|
163
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="8" y1="6" x2="21" y2="6"/><line x1="8" y1="12" x2="21" y2="12"/><line x1="8" y1="18" x2="21" y2="18"/><line x1="3" y1="6" x2="3.01" y2="6"/><line x1="3" y1="12" x2="3.01" y2="12"/><line x1="3" y1="18" x2="3.01" y2="18"/></svg>
|
|
164
|
+
</button>
|
|
165
|
+
</div>
|
|
166
|
+
<button class="sk-new-btn" data-tooltip="${aw.actions.new_tooltip}" title="${aw.actions.new_tooltip}">
|
|
167
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2"><line x1="12" y1="5" x2="12" y2="19"/><line x1="5" y1="12" x2="19" y2="12"/></svg>
|
|
168
|
+
<span>${aw.actions.new}</span>
|
|
169
|
+
</button>
|
|
170
|
+
</div>
|
|
171
|
+
<div class="sk-pills">${pills}</div>
|
|
172
|
+
<div class="sk-body sk-body--${state.viewMode}">
|
|
173
|
+
${renderBody(filtered)}
|
|
174
|
+
</div>
|
|
175
|
+
`;
|
|
176
|
+
|
|
177
|
+
attachSettingsHandlers();
|
|
178
|
+
attachToolbarHandlers();
|
|
179
|
+
attachCardHandlers();
|
|
180
|
+
if (state.expandedId) {
|
|
181
|
+
mountEditor(state.expandedId);
|
|
182
|
+
if (state._scrollToExpanded) {
|
|
183
|
+
state._scrollToExpanded = false;
|
|
184
|
+
requestAnimationFrame(() => {
|
|
185
|
+
state.container?.querySelector(`.sk-card[data-id="${CSS.escape(state.expandedId)}"]`)
|
|
186
|
+
?.scrollIntoView({ block: 'start', behavior: 'smooth' });
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
function renderSettingsSection() {
|
|
193
|
+
const patterns = loadAgentPatterns();
|
|
194
|
+
const currentPattern = patterns.global !== DEFAULT_AGENT_PATTERN ? patterns.global : '';
|
|
195
|
+
const open = state.settingsOpen;
|
|
196
|
+
|
|
197
|
+
return `
|
|
198
|
+
<div class="ag-settings ${open ? '' : 'collapsed'}">
|
|
199
|
+
<button class="ag-settings-header" type="button" aria-expanded="${open}">
|
|
200
|
+
<svg class="ag-settings-chevron" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
201
|
+
<polyline points="6 9 12 15 18 9"/>
|
|
202
|
+
</svg>
|
|
203
|
+
<span class="ag-settings-title">${S.settings.sections.agent_pattern}</span>
|
|
204
|
+
</button>
|
|
205
|
+
<div class="ag-settings-body">
|
|
206
|
+
<p class="ag-settings-hint">Use <code>{agent}</code> as placeholder for agent name</p>
|
|
207
|
+
<div class="ag-pattern-row">
|
|
208
|
+
<input type="text" id="ag-global-pattern" class="ag-pattern-input"
|
|
209
|
+
placeholder="${escapeHtml(DEFAULT_AGENT_PATTERN)}"
|
|
210
|
+
value="${escapeHtml(currentPattern)}">
|
|
211
|
+
<button class="ag-pattern-reset" id="ag-reset-pattern" data-tooltip="Reset to default" type="button">
|
|
212
|
+
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
|
|
213
|
+
<path d="M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8"/>
|
|
214
|
+
<path d="M3 3v5h5"/>
|
|
215
|
+
</svg>
|
|
216
|
+
</button>
|
|
217
|
+
</div>
|
|
218
|
+
</div>
|
|
219
|
+
</div>
|
|
220
|
+
`;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
function attachSettingsHandlers() {
|
|
224
|
+
const root = state.container;
|
|
225
|
+
if (!root) return;
|
|
226
|
+
|
|
227
|
+
root.querySelector('.ag-settings-header')?.addEventListener('click', () => {
|
|
228
|
+
state.settingsOpen = !state.settingsOpen;
|
|
229
|
+
saveSettingsOpen(state.settingsOpen);
|
|
230
|
+
renderShell();
|
|
231
|
+
});
|
|
232
|
+
|
|
233
|
+
const patternInput = root.querySelector('#ag-global-pattern');
|
|
234
|
+
const persistPattern = () => {
|
|
235
|
+
const value = patternInput.value.trim();
|
|
236
|
+
const patterns = loadAgentPatterns();
|
|
237
|
+
patterns.global = value || DEFAULT_AGENT_PATTERN;
|
|
238
|
+
saveAgentPatterns(patterns);
|
|
239
|
+
};
|
|
240
|
+
patternInput?.addEventListener('change', persistPattern);
|
|
241
|
+
patternInput?.addEventListener('blur', persistPattern);
|
|
242
|
+
|
|
243
|
+
root.querySelector('#ag-reset-pattern')?.addEventListener('click', () => {
|
|
244
|
+
const patterns = loadAgentPatterns();
|
|
245
|
+
patterns.global = DEFAULT_AGENT_PATTERN;
|
|
246
|
+
saveAgentPatterns(patterns);
|
|
247
|
+
if (patternInput) patternInput.value = '';
|
|
248
|
+
});
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function renderBody(filtered) {
|
|
252
|
+
const aw = S.agents_widget;
|
|
253
|
+
if (state.loading && state.agents.length === 0) {
|
|
254
|
+
return `<div class="sk-empty">Loading…</div>`;
|
|
255
|
+
}
|
|
256
|
+
if (state.error) {
|
|
257
|
+
return `<div class="sk-empty sk-error">${escapeHtml(aw.load_failed.replace('{error}', state.error))}</div>`;
|
|
258
|
+
}
|
|
259
|
+
if (filtered.length === 0) {
|
|
260
|
+
const msg = state.search
|
|
261
|
+
? aw.empty.no_match
|
|
262
|
+
: state.currentProjectOnly && state.counts.project === 0
|
|
263
|
+
? aw.empty.no_project
|
|
264
|
+
: aw.empty.no_agents;
|
|
265
|
+
return `<div class="sk-empty">${escapeHtml(msg)}</div>`;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
const groups = { project: [], personal: [] };
|
|
269
|
+
for (const a of filtered) {
|
|
270
|
+
(groups[a.scope] || (groups[a.scope] = [])).push(a);
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const out = [];
|
|
274
|
+
for (const scope of ['project', 'personal']) {
|
|
275
|
+
const arr = groups[scope];
|
|
276
|
+
if (!arr || arr.length === 0) continue;
|
|
277
|
+
out.push(`<div class="sk-group" data-scope="${scope}">
|
|
278
|
+
<div class="sk-group-header">
|
|
279
|
+
<span class="sk-group-icon">${scopeIcon(scope)}</span>
|
|
280
|
+
<span class="sk-group-label">${aw.groups[scope]}</span>
|
|
281
|
+
<span class="sk-group-count">${arr.length}</span>
|
|
282
|
+
</div>
|
|
283
|
+
<div class="sk-gallery">
|
|
284
|
+
${arr.map(renderCard).join('')}
|
|
285
|
+
</div>
|
|
286
|
+
</div>`);
|
|
287
|
+
}
|
|
288
|
+
return out.join('');
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
function renderCard(a) {
|
|
292
|
+
const aw = S.agents_widget;
|
|
293
|
+
const name = escapeHtml(a.name);
|
|
294
|
+
const desc = a.description
|
|
295
|
+
? escapeHtml(a.description)
|
|
296
|
+
: `<em>${aw.meta.no_description}</em>`;
|
|
297
|
+
|
|
298
|
+
const tools = typeof a.frontmatter?.tools === 'string'
|
|
299
|
+
? a.frontmatter.tools.split(',').map(s => s.trim()).filter(Boolean)
|
|
300
|
+
: Array.isArray(a.frontmatter?.tools) ? a.frontmatter.tools : [];
|
|
301
|
+
const toolsCount = tools.length;
|
|
302
|
+
const model = a.frontmatter?.model || '';
|
|
303
|
+
|
|
304
|
+
const shadowed = a.shadowed_by
|
|
305
|
+
? `<span class="sk-shadow" title="Shadowed by ${escapeHtml(a.shadowed_by)}">⚠</span>`
|
|
306
|
+
: '';
|
|
307
|
+
|
|
308
|
+
const meta = [
|
|
309
|
+
toolsCount ? `<span class="sk-meta-chip" title="${escapeHtml(tools.join(', '))}">⚙ ${aw.meta.tools_count.replace('{n}', toolsCount)}</span>` : '',
|
|
310
|
+
model ? `<span class="sk-meta-chip">${escapeHtml(model)}</span>` : '',
|
|
311
|
+
].filter(Boolean).join('');
|
|
312
|
+
|
|
313
|
+
const expanded = state.expandedId === a.id ? 'sk-card--expanded' : '';
|
|
314
|
+
|
|
315
|
+
const hidden = loadDisabledAgents().has(a.id);
|
|
316
|
+
const st = aw.suggest_toggle;
|
|
317
|
+
const eyeBtn = `<button class="sk-card-eye${hidden ? ' is-hidden' : ''}" data-eye-id="${escapeHtml(a.id)}" type="button"
|
|
318
|
+
data-tooltip="${escapeHtml(hidden ? st.show_tooltip : st.hide_tooltip)}"
|
|
319
|
+
title="${escapeHtml(hidden ? st.show_tooltip : st.hide_tooltip)}"
|
|
320
|
+
aria-label="${escapeHtml(hidden ? st.show_label : st.hide_label)}">${hidden ? ICONS.eyeOff : ICONS.eye}</button>`;
|
|
321
|
+
|
|
322
|
+
return `
|
|
323
|
+
<div class="sk-card sk-card--${a.scope} ${expanded}${hidden ? ' sk-card--hidden' : ''}" data-id="${escapeHtml(a.id)}" data-scope="${a.scope}">
|
|
324
|
+
<div class="sk-card-head">
|
|
325
|
+
<span class="sk-card-icon">${scopeIcon(a.scope)}</span>
|
|
326
|
+
<span class="sk-card-name">${name}</span>
|
|
327
|
+
<span class="sk-card-badges">${shadowed}</span>
|
|
328
|
+
${eyeBtn}
|
|
329
|
+
</div>
|
|
330
|
+
<p class="sk-card-desc">${desc}</p>
|
|
331
|
+
${meta ? `<div class="sk-card-meta">${meta}</div>` : ''}
|
|
332
|
+
<div class="sk-card-detail" data-detail-for="${escapeHtml(a.id)}"></div>
|
|
333
|
+
</div>
|
|
334
|
+
`;
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function renderEditor(agent, detail) {
|
|
338
|
+
const aw = S.agents_widget;
|
|
339
|
+
const dirty = state.editorState?.dirty;
|
|
340
|
+
return `
|
|
341
|
+
<div class="sk-editor" data-id="${escapeHtml(agent.id)}">
|
|
342
|
+
<div class="sk-editor-head">
|
|
343
|
+
<span class="sk-editor-path" title="${escapeHtml(detail.path)}">${escapeHtml(detail.path)}</span>
|
|
344
|
+
${dirty ? `<span class="sk-editor-dirty">${aw.editor.dirty_indicator}</span>` : ''}
|
|
345
|
+
</div>
|
|
346
|
+
<textarea class="sk-editor-textarea" spellcheck="false">${escapeHtml(detail.raw)}</textarea>
|
|
347
|
+
<div class="sk-editor-foot">
|
|
348
|
+
<button class="sk-btn sk-btn--ghost sk-cancel-btn">${aw.actions.cancel}</button>
|
|
349
|
+
<button class="sk-btn sk-btn--ghost sk-open-full-btn">${aw.actions.open_full_editor}</button>
|
|
350
|
+
<button class="sk-btn sk-btn--primary sk-save-btn" ${dirty ? '' : 'disabled'}>${aw.actions.save}</button>
|
|
351
|
+
</div>
|
|
352
|
+
</div>
|
|
353
|
+
`;
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// ══════════════════════════════════════════════════════════════════
|
|
357
|
+
// EVENT HANDLERS
|
|
358
|
+
// ══════════════════════════════════════════════════════════════════
|
|
359
|
+
|
|
360
|
+
function attachToolbarHandlers() {
|
|
361
|
+
const root = state.container;
|
|
362
|
+
if (!root) return;
|
|
363
|
+
|
|
364
|
+
const search = root.querySelector('.sk-search');
|
|
365
|
+
if (search) {
|
|
366
|
+
let focused = document.activeElement === search;
|
|
367
|
+
search.addEventListener('input', (e) => {
|
|
368
|
+
state.search = e.target.value;
|
|
369
|
+
rerenderBodyOnly();
|
|
370
|
+
});
|
|
371
|
+
if (focused) {
|
|
372
|
+
const len = search.value.length;
|
|
373
|
+
search.focus();
|
|
374
|
+
search.setSelectionRange(len, len);
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
root.querySelector('.sk-current-toggle input')?.addEventListener('change', (e) => {
|
|
379
|
+
state.currentProjectOnly = e.target.checked;
|
|
380
|
+
saveCurrentProjectOnly(state.currentProjectOnly);
|
|
381
|
+
rerenderBodyOnly();
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
root.querySelectorAll('.sk-pill').forEach(btn => {
|
|
385
|
+
btn.addEventListener('click', () => {
|
|
386
|
+
state.originFilter = btn.dataset.filter;
|
|
387
|
+
renderShell();
|
|
388
|
+
});
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
root.querySelectorAll('.sk-view-btn').forEach(btn => {
|
|
392
|
+
btn.addEventListener('click', () => {
|
|
393
|
+
const next = btn.dataset.view;
|
|
394
|
+
if (next === state.viewMode) return;
|
|
395
|
+
state.viewMode = next;
|
|
396
|
+
saveViewMode(next);
|
|
397
|
+
renderShell();
|
|
398
|
+
});
|
|
399
|
+
});
|
|
400
|
+
|
|
401
|
+
root.querySelector('.sk-new-btn')?.addEventListener('click', () => {
|
|
402
|
+
openNewAgentModal();
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
function rerenderBodyOnly() {
|
|
407
|
+
const body = state.container?.querySelector('.sk-body');
|
|
408
|
+
if (!body) return renderShell();
|
|
409
|
+
const filtered = filteredAgents();
|
|
410
|
+
body.className = `sk-body sk-body--${state.viewMode}`;
|
|
411
|
+
body.innerHTML = renderBody(filtered);
|
|
412
|
+
attachCardHandlers();
|
|
413
|
+
if (state.expandedId) mountEditor(state.expandedId);
|
|
414
|
+
}
|
|
415
|
+
|
|
416
|
+
function attachCardHandlers() {
|
|
417
|
+
const root = state.container;
|
|
418
|
+
if (!root) return;
|
|
419
|
+
|
|
420
|
+
root.querySelectorAll('.sk-card-eye').forEach(btn => {
|
|
421
|
+
btn.addEventListener('click', (e) => {
|
|
422
|
+
e.stopPropagation();
|
|
423
|
+
toggleAgentSuggest(btn.dataset.eyeId);
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
|
|
427
|
+
root.querySelectorAll('.sk-card').forEach(card => {
|
|
428
|
+
card.addEventListener('click', async (e) => {
|
|
429
|
+
if (e.target.closest('.sk-card-detail')) return;
|
|
430
|
+
const id = card.dataset.id;
|
|
431
|
+
if (state.expandedId === id) {
|
|
432
|
+
state.expandedId = null;
|
|
433
|
+
state.editorState = null;
|
|
434
|
+
rerenderBodyOnly();
|
|
435
|
+
return;
|
|
436
|
+
}
|
|
437
|
+
state.expandedId = id;
|
|
438
|
+
state.editorState = null;
|
|
439
|
+
rerenderBodyOnly();
|
|
440
|
+
await mountEditor(id);
|
|
441
|
+
});
|
|
442
|
+
|
|
443
|
+
card.addEventListener('contextmenu', (e) => {
|
|
444
|
+
e.preventDefault();
|
|
445
|
+
const id = card.dataset.id;
|
|
446
|
+
const agent = state.agents.find(a => a.id === id);
|
|
447
|
+
if (agent) showCardContextMenu(e.clientX, e.clientY, agent);
|
|
448
|
+
});
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
async function mountEditor(id) {
|
|
453
|
+
const [scope, ...rest] = id.split(':');
|
|
454
|
+
const name = rest.join(':');
|
|
455
|
+
const card = state.container?.querySelector(`.sk-card[data-id="${CSS.escape(id)}"]`);
|
|
456
|
+
const detailEl = card?.querySelector('.sk-card-detail');
|
|
457
|
+
if (!detailEl) return;
|
|
458
|
+
|
|
459
|
+
if (detailEl.dataset.mounted === '1' && state.editorState) return;
|
|
460
|
+
|
|
461
|
+
detailEl.innerHTML = `<div class="sk-editor-loading">Loading…</div>`;
|
|
462
|
+
detailEl.dataset.mounted = '1';
|
|
463
|
+
|
|
464
|
+
const agent = state.agents.find(a => a.id === id);
|
|
465
|
+
if (!agent) return;
|
|
466
|
+
|
|
467
|
+
let detail;
|
|
468
|
+
try {
|
|
469
|
+
const cwd = window.app?.activeSession?.cwd || '/';
|
|
470
|
+
const r = await fetch(`${CONFIG.API_BASE}/api/agents/${encodeURIComponent(scope)}/${encodeURIComponent(name)}?cwd=${encodeURIComponent(cwd)}`);
|
|
471
|
+
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
|
472
|
+
detail = await r.json();
|
|
473
|
+
} catch (e) {
|
|
474
|
+
detailEl.innerHTML = `<div class="sk-editor-error">${escapeHtml('Failed to load: ' + e.message)}</div>`;
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
|
|
478
|
+
state.editorState = {
|
|
479
|
+
raw: detail.raw,
|
|
480
|
+
original: detail.raw,
|
|
481
|
+
dirty: false,
|
|
482
|
+
mtime: detail.mtime,
|
|
483
|
+
saving: false,
|
|
484
|
+
};
|
|
485
|
+
detailEl.innerHTML = renderEditor(agent, detail);
|
|
486
|
+
bindEditorHandlers(detailEl, agent, detail);
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
function bindEditorHandlers(root, agent /*, detail */) {
|
|
490
|
+
const ta = root.querySelector('.sk-editor-textarea');
|
|
491
|
+
const saveBtn = root.querySelector('.sk-save-btn');
|
|
492
|
+
const cancelBtn = root.querySelector('.sk-cancel-btn');
|
|
493
|
+
const openFullBtn = root.querySelector('.sk-open-full-btn');
|
|
494
|
+
|
|
495
|
+
ta?.addEventListener('input', (e) => {
|
|
496
|
+
if (!state.editorState) return;
|
|
497
|
+
state.editorState.raw = e.target.value;
|
|
498
|
+
const nowDirty = state.editorState.raw !== state.editorState.original;
|
|
499
|
+
if (nowDirty !== state.editorState.dirty) {
|
|
500
|
+
state.editorState.dirty = nowDirty;
|
|
501
|
+
const editor = root.querySelector('.sk-editor');
|
|
502
|
+
editor?.classList.toggle('sk-editor--dirty', nowDirty);
|
|
503
|
+
if (saveBtn) saveBtn.disabled = !nowDirty;
|
|
504
|
+
const existing = root.querySelector('.sk-editor-dirty');
|
|
505
|
+
if (nowDirty && !existing) {
|
|
506
|
+
root.querySelector('.sk-editor-head')
|
|
507
|
+
?.insertAdjacentHTML('beforeend', `<span class="sk-editor-dirty">${S.agents_widget.editor.dirty_indicator}</span>`);
|
|
508
|
+
} else if (!nowDirty && existing) {
|
|
509
|
+
existing.remove();
|
|
510
|
+
}
|
|
511
|
+
}
|
|
512
|
+
});
|
|
513
|
+
|
|
514
|
+
cancelBtn?.addEventListener('click', () => {
|
|
515
|
+
if (state.editorState?.dirty && !confirm(S.agents_widget.editor.discard_confirm)) return;
|
|
516
|
+
state.expandedId = null;
|
|
517
|
+
state.editorState = null;
|
|
518
|
+
rerenderBodyOnly();
|
|
519
|
+
});
|
|
520
|
+
|
|
521
|
+
openFullBtn?.addEventListener('click', () => {
|
|
522
|
+
const WM = window.WidgetManager;
|
|
523
|
+
if (WM && typeof WM.open === 'function') {
|
|
524
|
+
WM.open('file-preview', { filePath: agent.path });
|
|
525
|
+
}
|
|
526
|
+
});
|
|
527
|
+
|
|
528
|
+
saveBtn?.addEventListener('click', async () => {
|
|
529
|
+
if (!state.editorState || state.editorState.saving) return;
|
|
530
|
+
state.editorState.saving = true;
|
|
531
|
+
saveBtn.disabled = true;
|
|
532
|
+
saveBtn.textContent = '…';
|
|
533
|
+
try {
|
|
534
|
+
const cwd = window.app?.activeSession?.cwd || '/';
|
|
535
|
+
const r = await fetch(`${CONFIG.API_BASE}/api/agents/${encodeURIComponent(agent.scope)}/${encodeURIComponent(agent.name)}?cwd=${encodeURIComponent(cwd)}`, {
|
|
536
|
+
method: 'PUT',
|
|
537
|
+
headers: { 'Content-Type': 'application/json' },
|
|
538
|
+
body: JSON.stringify({
|
|
539
|
+
raw: state.editorState.raw,
|
|
540
|
+
expected_mtime: state.editorState.mtime,
|
|
541
|
+
}),
|
|
542
|
+
});
|
|
543
|
+
if (!r.ok) {
|
|
544
|
+
const body = await r.json().catch(() => ({}));
|
|
545
|
+
throw new Error(body.detail || `HTTP ${r.status}`);
|
|
546
|
+
}
|
|
547
|
+
const result = await r.json();
|
|
548
|
+
state.editorState.original = state.editorState.raw;
|
|
549
|
+
state.editorState.dirty = false;
|
|
550
|
+
state.editorState.mtime = result.mtime;
|
|
551
|
+
window.app?.showToast?.(S.agents_widget.toast.saved.replace('{name}', agent.name));
|
|
552
|
+
await loadAgents();
|
|
553
|
+
} catch (e) {
|
|
554
|
+
alert(S.agents_widget.editor.save_failed.replace('{error}', e.message));
|
|
555
|
+
} finally {
|
|
556
|
+
if (state.editorState) state.editorState.saving = false;
|
|
557
|
+
const b = state.container?.querySelector(`.sk-card[data-id="${CSS.escape(agent.id)}"] .sk-save-btn`);
|
|
558
|
+
if (b) {
|
|
559
|
+
b.textContent = S.agents_widget.actions.save;
|
|
560
|
+
b.disabled = !state.editorState?.dirty;
|
|
561
|
+
}
|
|
562
|
+
}
|
|
563
|
+
});
|
|
564
|
+
}
|
|
565
|
+
|
|
566
|
+
// ══════════════════════════════════════════════════════════════════
|
|
567
|
+
// CONTEXT MENU + ACTIONS
|
|
568
|
+
// ══════════════════════════════════════════════════════════════════
|
|
569
|
+
|
|
570
|
+
/**
|
|
571
|
+
* Toggle whether an agent is suggested in the `#` autocomplete. The hidden
|
|
572
|
+
* set is shared with snippets-autocomplete (server-backed `disabled_agents`),
|
|
573
|
+
* keyed by the `scope:name` agent id.
|
|
574
|
+
*/
|
|
575
|
+
function toggleAgentSuggest(id) {
|
|
576
|
+
const aw = S.agents_widget;
|
|
577
|
+
const disabled = new Set(loadDisabledAgents());
|
|
578
|
+
const willHide = !disabled.has(id);
|
|
579
|
+
if (willHide) disabled.add(id);
|
|
580
|
+
else disabled.delete(id);
|
|
581
|
+
saveDisabledAgents(disabled);
|
|
582
|
+
|
|
583
|
+
const agent = state.agents.find(a => a.id === id);
|
|
584
|
+
const name = agent?.name || id;
|
|
585
|
+
window.app?.showToast?.(
|
|
586
|
+
(willHide ? aw.toast.hidden_from_suggest : aw.toast.shown_in_suggest).replace('{name}', name)
|
|
587
|
+
);
|
|
588
|
+
rerenderBodyOnly();
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
function showCardContextMenu(x, y, agent) {
|
|
592
|
+
const aw = S.agents_widget;
|
|
593
|
+
const menu = window.app?.contextMenu;
|
|
594
|
+
const items = [];
|
|
595
|
+
|
|
596
|
+
items.push({
|
|
597
|
+
label: aw.actions.copy_name,
|
|
598
|
+
action: () => {
|
|
599
|
+
if (navigator.clipboard) navigator.clipboard.writeText(agent.name);
|
|
600
|
+
window.app?.showToast?.(aw.toast.copied_name.replace('{name}', agent.name));
|
|
601
|
+
},
|
|
602
|
+
});
|
|
603
|
+
items.push({
|
|
604
|
+
label: aw.actions.copy_path,
|
|
605
|
+
action: () => {
|
|
606
|
+
if (navigator.clipboard) navigator.clipboard.writeText(agent.path);
|
|
607
|
+
window.app?.showToast?.(aw.toast.copied_path);
|
|
608
|
+
},
|
|
609
|
+
});
|
|
610
|
+
|
|
611
|
+
items.push({ separator: true });
|
|
612
|
+
|
|
613
|
+
items.push({
|
|
614
|
+
label: loadDisabledAgents().has(agent.id)
|
|
615
|
+
? aw.actions.show_in_suggest
|
|
616
|
+
: aw.actions.hide_from_suggest,
|
|
617
|
+
action: () => toggleAgentSuggest(agent.id),
|
|
618
|
+
});
|
|
619
|
+
|
|
620
|
+
items.push({ separator: true });
|
|
621
|
+
|
|
622
|
+
items.push({
|
|
623
|
+
label: aw.actions.duplicate_to_project,
|
|
624
|
+
action: () => duplicateAgent(agent, 'project'),
|
|
625
|
+
});
|
|
626
|
+
items.push({
|
|
627
|
+
label: aw.actions.duplicate_to_personal,
|
|
628
|
+
action: () => duplicateAgent(agent, 'personal'),
|
|
629
|
+
});
|
|
630
|
+
|
|
631
|
+
items.push({ separator: true });
|
|
632
|
+
items.push({
|
|
633
|
+
label: aw.actions.delete,
|
|
634
|
+
action: () => deleteAgent(agent),
|
|
635
|
+
});
|
|
636
|
+
|
|
637
|
+
if (!menu || typeof menu.show !== 'function') return;
|
|
638
|
+
menu.show(x, y, items);
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
async function duplicateAgent(agent, targetScope) {
|
|
642
|
+
const aw = S.agents_widget;
|
|
643
|
+
const cwd = window.app?.activeSession?.cwd || '/';
|
|
644
|
+
try {
|
|
645
|
+
const r = await fetch(
|
|
646
|
+
`${CONFIG.API_BASE}/api/agents/${encodeURIComponent(agent.scope)}/${encodeURIComponent(agent.name)}/duplicate?cwd=${encodeURIComponent(cwd)}`,
|
|
647
|
+
{
|
|
648
|
+
method: 'POST',
|
|
649
|
+
headers: { 'Content-Type': 'application/json' },
|
|
650
|
+
body: JSON.stringify({ target_scope: targetScope }),
|
|
651
|
+
}
|
|
652
|
+
);
|
|
653
|
+
if (!r.ok) {
|
|
654
|
+
const b = await r.json().catch(() => ({}));
|
|
655
|
+
throw new Error(b.detail || `HTTP ${r.status}`);
|
|
656
|
+
}
|
|
657
|
+
const result = await r.json();
|
|
658
|
+
window.app?.showToast?.(aw.toast.duplicated.replace('{name}', result.name));
|
|
659
|
+
state.expandedId = result.id;
|
|
660
|
+
state.editorState = null;
|
|
661
|
+
await loadAgents();
|
|
662
|
+
await mountEditor(result.id);
|
|
663
|
+
scrollCardIntoView(result.id);
|
|
664
|
+
} catch (e) {
|
|
665
|
+
alert(aw.toast.duplicate_failed.replace('{error}', e.message));
|
|
666
|
+
}
|
|
667
|
+
}
|
|
668
|
+
|
|
669
|
+
async function deleteAgent(agent) {
|
|
670
|
+
const aw = S.agents_widget;
|
|
671
|
+
const cwd = window.app?.activeSession?.cwd || '/';
|
|
672
|
+
const msg = aw.confirm.delete.replace('{name}', agent.name);
|
|
673
|
+
if (!confirm(msg)) return;
|
|
674
|
+
try {
|
|
675
|
+
const r = await fetch(
|
|
676
|
+
`${CONFIG.API_BASE}/api/agents/${encodeURIComponent(agent.scope)}/${encodeURIComponent(agent.name)}?cwd=${encodeURIComponent(cwd)}`,
|
|
677
|
+
{ method: 'DELETE' }
|
|
678
|
+
);
|
|
679
|
+
if (!r.ok) {
|
|
680
|
+
const b = await r.json().catch(() => ({}));
|
|
681
|
+
throw new Error(b.detail || `HTTP ${r.status}`);
|
|
682
|
+
}
|
|
683
|
+
window.app?.showToast?.(aw.toast.deleted.replace('{name}', agent.name));
|
|
684
|
+
if (state.expandedId === agent.id) {
|
|
685
|
+
state.expandedId = null;
|
|
686
|
+
state.editorState = null;
|
|
687
|
+
}
|
|
688
|
+
await loadAgents();
|
|
689
|
+
} catch (e) {
|
|
690
|
+
alert(aw.toast.delete_failed.replace('{error}', e.message));
|
|
691
|
+
}
|
|
692
|
+
}
|
|
693
|
+
|
|
694
|
+
function scrollCardIntoView(id) {
|
|
695
|
+
requestAnimationFrame(() => {
|
|
696
|
+
state.container
|
|
697
|
+
?.querySelector(`.sk-card[data-id="${CSS.escape(id)}"]`)
|
|
698
|
+
?.scrollIntoView({ behavior: 'smooth', block: 'center' });
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
// ══════════════════════════════════════════════════════════════════
|
|
703
|
+
// NEW AGENT MODAL
|
|
704
|
+
// ══════════════════════════════════════════════════════════════════
|
|
705
|
+
|
|
706
|
+
const TEMPLATES = ['blank', 'researcher', 'reviewer', 'implementer'];
|
|
707
|
+
|
|
708
|
+
function openNewAgentModal() {
|
|
709
|
+
const aw = S.agents_widget;
|
|
710
|
+
const c = aw.create;
|
|
711
|
+
|
|
712
|
+
document.querySelector('.sk-modal-backdrop')?.remove();
|
|
713
|
+
|
|
714
|
+
const backdrop = document.createElement('div');
|
|
715
|
+
backdrop.className = 'sk-modal-backdrop';
|
|
716
|
+
|
|
717
|
+
const templateOptions = TEMPLATES.map((t) => `
|
|
718
|
+
<label class="sk-tpl-option">
|
|
719
|
+
<input type="radio" name="sk-tpl" value="${t}" ${t === 'blank' ? 'checked' : ''} />
|
|
720
|
+
<div class="sk-tpl-content">
|
|
721
|
+
<div class="sk-tpl-label">${c.templates[t]}</div>
|
|
722
|
+
<div class="sk-tpl-desc">${c.templates[`${t}_desc`]}</div>
|
|
723
|
+
</div>
|
|
724
|
+
</label>
|
|
725
|
+
`).join('');
|
|
726
|
+
|
|
727
|
+
backdrop.innerHTML = `
|
|
728
|
+
<div class="sk-modal" role="dialog" aria-modal="true">
|
|
729
|
+
<div class="sk-modal-head">
|
|
730
|
+
<h3>${c.title}</h3>
|
|
731
|
+
<button class="sk-modal-close" aria-label="Close">×</button>
|
|
732
|
+
</div>
|
|
733
|
+
<div class="sk-modal-body">
|
|
734
|
+
<div class="sk-form-row">
|
|
735
|
+
<label>${c.scope_label}</label>
|
|
736
|
+
<div class="sk-scope-picker">
|
|
737
|
+
<label><input type="radio" name="sk-scope" value="project" checked /> Project</label>
|
|
738
|
+
<label><input type="radio" name="sk-scope" value="personal" /> Personal (~/.claude)</label>
|
|
739
|
+
</div>
|
|
740
|
+
</div>
|
|
741
|
+
<div class="sk-form-row">
|
|
742
|
+
<label for="sk-new-name">${c.name_label}</label>
|
|
743
|
+
<input type="text" id="sk-new-name" class="sk-input" placeholder="${c.name_placeholder}" autocomplete="off" spellcheck="false" />
|
|
744
|
+
<div class="sk-form-hint">${c.name_hint}</div>
|
|
745
|
+
<div class="sk-form-error" id="sk-new-name-error"></div>
|
|
746
|
+
</div>
|
|
747
|
+
<div class="sk-form-row">
|
|
748
|
+
<label for="sk-new-desc">${c.description_label}</label>
|
|
749
|
+
<textarea id="sk-new-desc" class="sk-input sk-textarea-short" rows="2" placeholder="${c.description_placeholder}"></textarea>
|
|
750
|
+
<div class="sk-form-hint">${c.description_hint}</div>
|
|
751
|
+
</div>
|
|
752
|
+
<div class="sk-form-row">
|
|
753
|
+
<label>${c.template_label}</label>
|
|
754
|
+
<div class="sk-tpl-list">${templateOptions}</div>
|
|
755
|
+
</div>
|
|
756
|
+
</div>
|
|
757
|
+
<div class="sk-modal-foot">
|
|
758
|
+
<button class="sk-btn sk-btn--ghost sk-modal-cancel">${aw.actions.cancel}</button>
|
|
759
|
+
<button class="sk-btn sk-btn--primary sk-modal-submit">${c.submit}</button>
|
|
760
|
+
</div>
|
|
761
|
+
</div>
|
|
762
|
+
`;
|
|
763
|
+
|
|
764
|
+
document.body.appendChild(backdrop);
|
|
765
|
+
|
|
766
|
+
const closeModal = () => backdrop.remove();
|
|
767
|
+
backdrop.addEventListener('click', (e) => {
|
|
768
|
+
if (e.target === backdrop) closeModal();
|
|
769
|
+
});
|
|
770
|
+
backdrop.querySelector('.sk-modal-close')?.addEventListener('click', closeModal);
|
|
771
|
+
backdrop.querySelector('.sk-modal-cancel')?.addEventListener('click', closeModal);
|
|
772
|
+
|
|
773
|
+
const nameInput = backdrop.querySelector('#sk-new-name');
|
|
774
|
+
const errEl = backdrop.querySelector('#sk-new-name-error');
|
|
775
|
+
nameInput?.focus();
|
|
776
|
+
|
|
777
|
+
backdrop.addEventListener('keydown', (e) => {
|
|
778
|
+
if (e.key === 'Escape') closeModal();
|
|
779
|
+
if (e.key === 'Enter' && (e.target === nameInput || e.ctrlKey || e.metaKey)) {
|
|
780
|
+
e.preventDefault();
|
|
781
|
+
backdrop.querySelector('.sk-modal-submit')?.click();
|
|
782
|
+
}
|
|
783
|
+
});
|
|
784
|
+
|
|
785
|
+
backdrop.querySelector('.sk-modal-submit')?.addEventListener('click', async () => {
|
|
786
|
+
const nm = (nameInput?.value || '').trim();
|
|
787
|
+
const scope = backdrop.querySelector('input[name="sk-scope"]:checked')?.value;
|
|
788
|
+
const desc = (backdrop.querySelector('#sk-new-desc')?.value || '').trim();
|
|
789
|
+
const template = backdrop.querySelector('input[name="sk-tpl"]:checked')?.value || 'blank';
|
|
790
|
+
|
|
791
|
+
errEl.textContent = '';
|
|
792
|
+
if (!/^[a-z][a-z0-9-]{0,63}$/.test(nm)) {
|
|
793
|
+
errEl.textContent = c.name_hint;
|
|
794
|
+
nameInput?.focus();
|
|
795
|
+
return;
|
|
796
|
+
}
|
|
797
|
+
await createAgent({ scope, name: nm, description: desc, template });
|
|
798
|
+
closeModal();
|
|
799
|
+
});
|
|
800
|
+
}
|
|
801
|
+
|
|
802
|
+
async function createAgent({ scope, name, description, template }) {
|
|
803
|
+
const aw = S.agents_widget;
|
|
804
|
+
const cwd = window.app?.activeSession?.cwd || '/';
|
|
805
|
+
try {
|
|
806
|
+
const r = await fetch(
|
|
807
|
+
`${CONFIG.API_BASE}/api/agents/${encodeURIComponent(scope)}/${encodeURIComponent(name)}?cwd=${encodeURIComponent(cwd)}`,
|
|
808
|
+
{
|
|
809
|
+
method: 'POST',
|
|
810
|
+
headers: { 'Content-Type': 'application/json' },
|
|
811
|
+
body: JSON.stringify({ description, template }),
|
|
812
|
+
}
|
|
813
|
+
);
|
|
814
|
+
if (!r.ok) {
|
|
815
|
+
const b = await r.json().catch(() => ({}));
|
|
816
|
+
throw new Error(b.detail || `HTTP ${r.status}`);
|
|
817
|
+
}
|
|
818
|
+
const result = await r.json();
|
|
819
|
+
window.app?.showToast?.(aw.create.created.replace('{name}', result.name));
|
|
820
|
+
if (state.originFilter !== 'all' && state.originFilter !== scope) {
|
|
821
|
+
state.originFilter = 'all';
|
|
822
|
+
}
|
|
823
|
+
if (scope === 'personal' && state.currentProjectOnly) {
|
|
824
|
+
state.currentProjectOnly = false;
|
|
825
|
+
saveCurrentProjectOnly(false);
|
|
826
|
+
}
|
|
827
|
+
state.expandedId = result.id;
|
|
828
|
+
state.editorState = null;
|
|
829
|
+
await loadAgents();
|
|
830
|
+
await mountEditor(result.id);
|
|
831
|
+
scrollCardIntoView(result.id);
|
|
832
|
+
} catch (e) {
|
|
833
|
+
alert(aw.create.create_failed.replace('{error}', e.message));
|
|
834
|
+
}
|
|
835
|
+
}
|
|
836
|
+
|
|
837
|
+
// ══════════════════════════════════════════════════════════════════
|
|
838
|
+
// REGISTRATION
|
|
839
|
+
// ══════════════════════════════════════════════════════════════════
|
|
840
|
+
|
|
841
|
+
export function registerAgentsWidget() {
|
|
842
|
+
WidgetManager.register('agents', {
|
|
843
|
+
title: S.widgets.titles.agents,
|
|
844
|
+
icon: 'brain',
|
|
845
|
+
type: 'floating',
|
|
846
|
+
scope: 'global',
|
|
847
|
+
defaultWidth: 760,
|
|
848
|
+
defaultHeight: 620,
|
|
849
|
+
|
|
850
|
+
headerActions: [
|
|
851
|
+
{
|
|
852
|
+
icon: 'refresh',
|
|
853
|
+
title: S.agents_widget.refresh_tooltip,
|
|
854
|
+
onClick: () => loadAgents(),
|
|
855
|
+
},
|
|
856
|
+
],
|
|
857
|
+
|
|
858
|
+
render(container, ctx) {
|
|
859
|
+
state.container = container;
|
|
860
|
+
container.classList.add('skills-widget');
|
|
861
|
+
if (ctx?.expandAgentId) {
|
|
862
|
+
state.search = '';
|
|
863
|
+
state.originFilter = 'all';
|
|
864
|
+
state.currentProjectOnly = false;
|
|
865
|
+
state.expandedId = ctx.expandAgentId;
|
|
866
|
+
state.editorState = null;
|
|
867
|
+
state._scrollToExpanded = true;
|
|
868
|
+
}
|
|
869
|
+
loadAgents();
|
|
870
|
+
},
|
|
871
|
+
|
|
872
|
+
onOpen() {
|
|
873
|
+
loadAgents();
|
|
874
|
+
requestAnimationFrame(() => {
|
|
875
|
+
state.container?.querySelector('.sk-search')?.focus();
|
|
876
|
+
});
|
|
877
|
+
},
|
|
878
|
+
|
|
879
|
+
onClose() {
|
|
880
|
+
state.expandedId = null;
|
|
881
|
+
state.editorState = null;
|
|
882
|
+
},
|
|
883
|
+
});
|
|
884
|
+
|
|
885
|
+
debug.log('[AgentsWidget] registered');
|
|
886
|
+
}
|
|
887
|
+
|
|
888
|
+
export const AgentsWidget = {
|
|
889
|
+
open: () => WidgetManager.open('agents'),
|
|
890
|
+
close: () => WidgetManager.close('agents'),
|
|
891
|
+
toggle: () => WidgetManager.toggle('agents'),
|
|
892
|
+
reload: () => loadAgents(),
|
|
893
|
+
};
|
|
894
|
+
|
|
895
|
+
if (typeof window !== 'undefined') {
|
|
896
|
+
window.__agentsWidgetReload = () => loadAgents();
|
|
897
|
+
}
|