@blokkli/editor 2.0.0-alpha.32 → 2.0.0-alpha.33
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/dist/global/constants/index.d.ts +1 -0
- package/dist/global/constants/index.js +1 -0
- package/dist/global/types/features.d.ts +4 -0
- package/dist/module.d.mts +1 -24
- package/dist/module.json +1 -1
- package/dist/module.mjs +432 -10825
- package/dist/modules/agent/index.d.mts +64 -0
- package/dist/modules/agent/index.mjs +407 -0
- package/dist/modules/agent/runtime/app/composables/agentProvider.d.ts +55 -0
- package/dist/modules/agent/runtime/app/composables/agentProvider.js +875 -0
- package/dist/modules/agent/runtime/app/composables/defineBlokkliAgentPrompt.d.ts +32 -0
- package/dist/modules/agent/runtime/app/composables/defineBlokkliAgentPrompt.js +6 -0
- package/dist/modules/agent/runtime/app/composables/defineBlokkliAgentTool.d.ts +65 -0
- package/dist/modules/agent/runtime/app/composables/defineBlokkliAgentTool.js +6 -0
- package/dist/modules/agent/runtime/app/composables/index.d.ts +4 -0
- package/dist/modules/agent/runtime/app/composables/index.js +2 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Attachment/index.d.vue.ts +12 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Attachment/index.vue +62 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Attachment/index.vue.d.ts +12 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/Item/Assistant/index.d.vue.ts +9 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/Item/Assistant/index.vue +38 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/Item/Assistant/index.vue.d.ts +9 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/Item/Error/index.d.vue.ts +14 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/Item/Error/index.vue +68 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/Item/Error/index.vue.d.ts +14 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/Item/ServerTool/index.d.vue.ts +10 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/Item/ServerTool/index.vue +72 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/Item/ServerTool/index.vue.d.ts +10 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/Item/Tool/index.d.vue.ts +13 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/Item/Tool/index.vue +37 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/Item/Tool/index.vue.d.ts +13 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/Item/Unknown/index.d.vue.ts +8 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/Item/Unknown/index.vue +17 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/Item/Unknown/index.vue.d.ts +8 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/Item/User/index.d.vue.ts +11 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/Item/User/index.vue +29 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/Item/User/index.vue.d.ts +11 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/Item/index.d.vue.ts +12 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/Item/index.vue +30 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/Item/index.vue.d.ts +12 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/Thinking/index.d.vue.ts +3 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/Thinking/index.vue +14 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/Thinking/index.vue.d.ts +3 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/index.d.vue.ts +13 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/index.vue +46 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Conversation/index.vue.d.ts +13 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/ConversationList/index.d.vue.ts +15 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/ConversationList/index.vue +50 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/ConversationList/index.vue.d.ts +15 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/DebugGallery/index.d.vue.ts +3 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/DebugGallery/index.vue +160 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/DebugGallery/index.vue.d.ts +3 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Input/Actions/DropdownItem/index.d.vue.ts +12 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Input/Actions/DropdownItem/index.vue +15 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Input/Actions/DropdownItem/index.vue.d.ts +12 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Input/Actions/TokenUsage/index.d.vue.ts +7 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Input/Actions/TokenUsage/index.vue +67 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Input/Actions/TokenUsage/index.vue.d.ts +7 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Input/Actions/index.d.vue.ts +23 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Input/Actions/index.vue +109 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Input/Actions/index.vue.d.ts +23 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Input/index.d.vue.ts +45 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Input/index.vue +120 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Input/index.vue.d.ts +45 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/PendingMutation/index.d.vue.ts +15 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/PendingMutation/index.vue +47 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/PendingMutation/index.vue.d.ts +15 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Plan/index.d.vue.ts +14 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Plan/index.vue +55 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Plan/index.vue.d.ts +14 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/ToolCard/index.d.vue.ts +25 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/ToolCard/index.vue +36 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/ToolCard/index.vue.d.ts +25 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Welcome/de.md +19 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Welcome/en.md +18 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Welcome/index.d.vue.ts +10 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Welcome/index.vue +44 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/Welcome/index.vue.d.ts +10 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/index.d.vue.ts +58 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/index.vue +274 -0
- package/dist/modules/agent/runtime/app/features/agent/Panel/index.vue.d.ts +58 -0
- package/dist/modules/agent/runtime/app/features/agent/index.d.vue.ts +3 -0
- package/dist/modules/agent/runtime/app/features/agent/index.vue +162 -0
- package/dist/modules/agent/runtime/app/features/agent/index.vue.d.ts +3 -0
- package/dist/modules/agent/runtime/app/features/agent/types.d.ts +58 -0
- package/dist/modules/agent/runtime/app/features/agent/types.js +0 -0
- package/dist/modules/agent/runtime/app/helpers/index.d.ts +55 -0
- package/dist/modules/agent/runtime/app/helpers/index.js +88 -0
- package/dist/modules/agent/runtime/app/helpers/pageStructure.d.ts +5 -0
- package/dist/modules/agent/runtime/app/helpers/pageStructure.js +106 -0
- package/dist/modules/agent/runtime/app/helpers/validation.d.ts +35 -0
- package/dist/modules/agent/runtime/app/helpers/validation.js +77 -0
- package/dist/modules/agent/runtime/app/tools/add_content_search_paragraph/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/add_content_search_paragraph/index.js +69 -0
- package/dist/modules/agent/runtime/app/tools/add_fragment/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/add_fragment/index.js +83 -0
- package/dist/modules/agent/runtime/app/tools/add_media_paragraph/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/add_media_paragraph/index.js +62 -0
- package/dist/modules/agent/runtime/app/tools/add_paragraphs/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/add_paragraphs/index.js +289 -0
- package/dist/modules/agent/runtime/app/tools/add_reusable_paragraph/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/add_reusable_paragraph/index.js +76 -0
- package/dist/modules/agent/runtime/app/tools/add_template/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/add_template/index.js +58 -0
- package/dist/modules/agent/runtime/app/tools/ask_question/Component.d.vue.ts +19 -0
- package/dist/modules/agent/runtime/app/tools/ask_question/Component.vue +113 -0
- package/dist/modules/agent/runtime/app/tools/ask_question/Component.vue.d.ts +19 -0
- package/dist/modules/agent/runtime/app/tools/ask_question/index.d.ts +17 -0
- package/dist/modules/agent/runtime/app/tools/ask_question/index.js +54 -0
- package/dist/modules/agent/runtime/app/tools/batch_rewrite_text/Component.d.vue.ts +29 -0
- package/dist/modules/agent/runtime/app/tools/batch_rewrite_text/Component.vue +190 -0
- package/dist/modules/agent/runtime/app/tools/batch_rewrite_text/Component.vue.d.ts +29 -0
- package/dist/modules/agent/runtime/app/tools/batch_rewrite_text/Item.d.vue.ts +20 -0
- package/dist/modules/agent/runtime/app/tools/batch_rewrite_text/Item.vue +90 -0
- package/dist/modules/agent/runtime/app/tools/batch_rewrite_text/Item.vue.d.ts +20 -0
- package/dist/modules/agent/runtime/app/tools/batch_rewrite_text/index.d.ts +18 -0
- package/dist/modules/agent/runtime/app/tools/batch_rewrite_text/index.js +55 -0
- package/dist/modules/agent/runtime/app/tools/delete_paragraphs/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/delete_paragraphs/index.js +47 -0
- package/dist/modules/agent/runtime/app/tools/detach_reusable_paragraph/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/detach_reusable_paragraph/index.js +47 -0
- package/dist/modules/agent/runtime/app/tools/duplicate_paragraphs/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/duplicate_paragraphs/index.js +144 -0
- package/dist/modules/agent/runtime/app/tools/find_paragraphs/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/find_paragraphs/index.js +180 -0
- package/dist/modules/agent/runtime/app/tools/get_all_fragments/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/get_all_fragments/index.js +33 -0
- package/dist/modules/agent/runtime/app/tools/get_all_page_content/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/get_all_page_content/index.js +93 -0
- package/dist/modules/agent/runtime/app/tools/get_available_bundles/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/get_available_bundles/index.js +104 -0
- package/dist/modules/agent/runtime/app/tools/get_child_paragraphs/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/get_child_paragraphs/index.js +108 -0
- package/dist/modules/agent/runtime/app/tools/get_content_fields/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/get_content_fields/index.js +192 -0
- package/dist/modules/agent/runtime/app/tools/get_mutation_history/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/get_mutation_history/index.js +102 -0
- package/dist/modules/agent/runtime/app/tools/get_page_structure/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/get_page_structure/index.js +113 -0
- package/dist/modules/agent/runtime/app/tools/get_paragraph_context/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/get_paragraph_context/index.js +275 -0
- package/dist/modules/agent/runtime/app/tools/get_paragraph_options/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/get_paragraph_options/index.js +63 -0
- package/dist/modules/agent/runtime/app/tools/get_paragraphs_in_viewport/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/get_paragraphs_in_viewport/index.js +180 -0
- package/dist/modules/agent/runtime/app/tools/get_selected_paragraphs/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/get_selected_paragraphs/index.js +46 -0
- package/dist/modules/agent/runtime/app/tools/go_to_history_index/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/go_to_history_index/index.js +54 -0
- package/dist/modules/agent/runtime/app/tools/move_paragraphs/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/move_paragraphs/index.js +69 -0
- package/dist/modules/agent/runtime/app/tools/rearrange_paragraphs/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/rearrange_paragraphs/index.js +95 -0
- package/dist/modules/agent/runtime/app/tools/replace_content_search_item/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/replace_content_search_item/index.js +80 -0
- package/dist/modules/agent/runtime/app/tools/replace_media_field/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/replace_media_field/index.js +85 -0
- package/dist/modules/agent/runtime/app/tools/schemas.d.ts +128 -0
- package/dist/modules/agent/runtime/app/tools/schemas.js +242 -0
- package/dist/modules/agent/runtime/app/tools/search_content/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/search_content/index.js +65 -0
- package/dist/modules/agent/runtime/app/tools/search_media/index.d.ts +14 -0
- package/dist/modules/agent/runtime/app/tools/search_media/index.js +60 -0
- package/dist/modules/agent/runtime/app/tools/search_reusable_paragraphs/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/search_reusable_paragraphs/index.js +75 -0
- package/dist/modules/agent/runtime/app/tools/search_templates/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/search_templates/index.js +51 -0
- package/dist/modules/agent/runtime/app/tools/search_text/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/search_text/index.js +114 -0
- package/dist/modules/agent/runtime/app/tools/select_media/Component.d.vue.ts +29 -0
- package/dist/modules/agent/runtime/app/tools/select_media/Component.vue +70 -0
- package/dist/modules/agent/runtime/app/tools/select_media/Component.vue.d.ts +29 -0
- package/dist/modules/agent/runtime/app/tools/select_media/index.d.ts +30 -0
- package/dist/modules/agent/runtime/app/tools/select_media/index.js +74 -0
- package/dist/modules/agent/runtime/app/tools/set_paragraph_options/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/set_paragraph_options/index.js +109 -0
- package/dist/modules/agent/runtime/app/tools/swap_paragraphs/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/swap_paragraphs/index.js +74 -0
- package/dist/modules/agent/runtime/app/tools/web_fetch/index.d.ts +2 -0
- package/dist/modules/agent/runtime/app/tools/web_fetch/index.js +51 -0
- package/dist/modules/agent/runtime/app/types/index.d.ts +440 -0
- package/dist/modules/agent/runtime/app/types/index.js +51 -0
- package/dist/modules/agent/runtime/server/Session.d.ts +94 -0
- package/dist/modules/agent/runtime/server/Session.js +734 -0
- package/dist/modules/agent/runtime/server/SessionManager.d.ts +21 -0
- package/dist/modules/agent/runtime/server/SessionManager.js +80 -0
- package/dist/modules/agent/runtime/server/agent.d.ts +2 -0
- package/dist/modules/agent/runtime/server/agent.js +148 -0
- package/dist/modules/agent/runtime/server/agentPrompt.d.ts +22 -0
- package/dist/modules/agent/runtime/server/agentPrompt.js +53 -0
- package/dist/modules/agent/runtime/server/default-skills/adding-new-paragraphs.d.ts +2 -0
- package/dist/modules/agent/runtime/server/default-skills/adding-new-paragraphs.js +21 -0
- package/dist/modules/agent/runtime/server/default-skills/pageReview.d.ts +2 -0
- package/dist/modules/agent/runtime/server/default-skills/pageReview.js +28 -0
- package/dist/modules/agent/runtime/server/default-skills/reusable-paragraphs.d.ts +2 -0
- package/dist/modules/agent/runtime/server/default-skills/reusable-paragraphs.js +21 -0
- package/dist/modules/agent/runtime/server/default-skills/rewriteAndTranslate.d.ts +2 -0
- package/dist/modules/agent/runtime/server/default-skills/rewriteAndTranslate.js +14 -0
- package/dist/modules/agent/runtime/server/default-system-prompts/architecture.d.ts +2 -0
- package/dist/modules/agent/runtime/server/default-system-prompts/architecture.js +39 -0
- package/dist/modules/agent/runtime/server/default-system-prompts/available-skills.d.ts +2 -0
- package/dist/modules/agent/runtime/server/default-system-prompts/available-skills.js +18 -0
- package/dist/modules/agent/runtime/server/default-system-prompts/available-tools.d.ts +2 -0
- package/dist/modules/agent/runtime/server/default-system-prompts/available-tools.js +18 -0
- package/dist/modules/agent/runtime/server/default-system-prompts/fragments.d.ts +2 -0
- package/dist/modules/agent/runtime/server/default-system-prompts/fragments.js +19 -0
- package/dist/modules/agent/runtime/server/default-system-prompts/important-rules.d.ts +2 -0
- package/dist/modules/agent/runtime/server/default-system-prompts/important-rules.js +22 -0
- package/dist/modules/agent/runtime/server/default-system-prompts/interaction.d.ts +2 -0
- package/dist/modules/agent/runtime/server/default-system-prompts/interaction.js +20 -0
- package/dist/modules/agent/runtime/server/default-system-prompts/introduction.d.ts +2 -0
- package/dist/modules/agent/runtime/server/default-system-prompts/introduction.js +14 -0
- package/dist/modules/agent/runtime/server/default-system-prompts/page-context.d.ts +2 -0
- package/dist/modules/agent/runtime/server/default-system-prompts/page-context.js +60 -0
- package/dist/modules/agent/runtime/server/default-system-prompts/paragraph-bundles.d.ts +2 -0
- package/dist/modules/agent/runtime/server/default-system-prompts/paragraph-bundles.js +37 -0
- package/dist/modules/agent/runtime/server/default-system-prompts/plan-mode.d.ts +2 -0
- package/dist/modules/agent/runtime/server/default-system-prompts/plan-mode.js +36 -0
- package/dist/modules/agent/runtime/server/default-system-prompts/security.d.ts +2 -0
- package/dist/modules/agent/runtime/server/default-system-prompts/security.js +27 -0
- package/dist/modules/agent/runtime/server/default-system-prompts/workflow.d.ts +2 -0
- package/dist/modules/agent/runtime/server/default-system-prompts/workflow.js +22 -0
- package/dist/modules/agent/runtime/server/fetch.d.ts +2 -0
- package/dist/modules/agent/runtime/server/fetch.js +127 -0
- package/dist/modules/agent/runtime/server/helpers.d.ts +77 -0
- package/dist/modules/agent/runtime/server/helpers.js +352 -0
- package/dist/modules/agent/runtime/server/providers/anthropic.d.ts +12 -0
- package/dist/modules/agent/runtime/server/providers/anthropic.js +128 -0
- package/dist/modules/agent/runtime/server/providers/openai.d.ts +12 -0
- package/dist/modules/agent/runtime/server/providers/openai.js +165 -0
- package/dist/modules/agent/runtime/server/providers/types.d.ts +74 -0
- package/dist/modules/agent/runtime/server/providers/types.js +0 -0
- package/dist/modules/agent/runtime/server/server-tools/complete_plan_step/index.d.ts +3 -0
- package/dist/modules/agent/runtime/server/server-tools/complete_plan_step/index.js +79 -0
- package/dist/modules/agent/runtime/server/server-tools/create_plan/index.d.ts +9 -0
- package/dist/modules/agent/runtime/server/server-tools/create_plan/index.js +86 -0
- package/dist/modules/agent/runtime/server/server-tools/index.d.ts +86 -0
- package/dist/modules/agent/runtime/server/server-tools/index.js +30 -0
- package/dist/modules/agent/runtime/server/server-tools/load_skill/index.d.ts +7 -0
- package/dist/modules/agent/runtime/server/server-tools/load_skill/index.js +58 -0
- package/dist/modules/agent/runtime/server/server-tools/load_tools/index.d.ts +7 -0
- package/dist/modules/agent/runtime/server/server-tools/load_tools/index.js +43 -0
- package/dist/modules/agent/runtime/server/skills/defineBlokkliAgentSkill.d.ts +23 -0
- package/dist/modules/agent/runtime/server/skills/defineBlokkliAgentSkill.js +3 -0
- package/dist/modules/agent/runtime/server/skills/index.d.ts +2 -0
- package/dist/modules/agent/runtime/server/skills/index.js +1 -0
- package/dist/modules/agent/runtime/server/skills/types.d.ts +45 -0
- package/dist/modules/agent/runtime/server/skills/types.js +0 -0
- package/dist/modules/agent/runtime/server/system-prompts/defineBlokkliAgentSystemPrompt.d.ts +21 -0
- package/dist/modules/agent/runtime/server/system-prompts/defineBlokkliAgentSystemPrompt.js +3 -0
- package/dist/modules/agent/runtime/server/system-prompts/helpers.d.ts +20 -0
- package/dist/modules/agent/runtime/server/system-prompts/helpers.js +41 -0
- package/dist/modules/agent/runtime/server/system-prompts/index.d.ts +2 -0
- package/dist/modules/agent/runtime/server/system-prompts/index.js +1 -0
- package/dist/modules/agent/runtime/server/system-prompts/types.d.ts +49 -0
- package/dist/modules/agent/runtime/server/system-prompts/types.js +0 -0
- package/dist/modules/agent/runtime/shared/placeholders.d.ts +4 -0
- package/dist/modules/agent/runtime/shared/placeholders.js +1 -0
- package/dist/modules/agent/runtime/shared/types.d.ts +426 -0
- package/dist/modules/agent/runtime/shared/types.js +147 -0
- package/dist/modules/drupal/graphql/base/query.pbConfig.graphql +27 -2
- package/dist/modules/drupal/graphql/features/agent.graphql +69 -0
- package/dist/modules/drupal/graphql/features/search.graphql +5 -0
- package/dist/modules/drupal/graphql/features/templates.graphql +36 -2
- package/dist/modules/drupal/graphql/mutations/add_multiple.graphql +25 -0
- package/dist/modules/drupal/graphql/mutations/bulk_update_field_values.graphql +15 -0
- package/dist/modules/drupal/graphql/mutations/rearrange.graphql +23 -0
- package/dist/modules/drupal/graphql/mutations/replace_entity_reference.graphql +25 -0
- package/dist/modules/drupal/graphql/mutations/swap.graphql +16 -0
- package/dist/modules/drupal/index.d.mts +18 -2
- package/dist/modules/drupal/index.mjs +60 -12
- package/dist/modules/drupal/runtime/adapter/index.js +246 -21
- package/dist/modules/drupal/runtime/components/BlokkliDrupalEditTemplate/index.d.vue.ts +9 -0
- package/dist/modules/drupal/runtime/components/BlokkliDrupalEditTemplate/index.vue +26 -0
- package/dist/modules/drupal/runtime/components/BlokkliDrupalEditTemplate/index.vue.d.ts +9 -0
- package/dist/runtime/components/Blocks/Fragment/index.vue +11 -2
- package/dist/runtime/components/BlokkliItem.vue +3 -1
- package/dist/runtime/composables/defineBlokkliFeature.d.ts +5 -3
- package/dist/runtime/composables/defineBlokkliFeature.js +2 -1
- package/dist/runtime/editor/adapter/index.d.ts +45 -4
- package/dist/runtime/editor/adapter/index.js +3 -0
- package/dist/runtime/editor/components/Actions/ItemDropdown.vue +6 -1
- package/dist/runtime/editor/components/Actions/index.vue +4 -1
- package/dist/runtime/editor/components/AddListItem/index.d.vue.ts +9 -1
- package/dist/runtime/editor/components/AddListItem/index.vue +36 -2
- package/dist/runtime/editor/components/AddListItem/index.vue.d.ts +9 -1
- package/dist/runtime/editor/components/AnimationCanvas/index.vue +17 -7
- package/dist/runtime/editor/components/ArtboardTooltip/index.d.vue.ts +3 -1
- package/dist/runtime/editor/components/ArtboardTooltip/index.vue +4 -3
- package/dist/runtime/editor/components/ArtboardTooltip/index.vue.d.ts +3 -1
- package/dist/runtime/editor/components/AutoHeight/index.d.vue.ts +16 -0
- package/dist/runtime/editor/components/AutoHeight/index.vue +32 -0
- package/dist/runtime/editor/components/AutoHeight/index.vue.d.ts +16 -0
- package/dist/runtime/editor/components/BlockPreviewItem/index.d.vue.ts +5 -1
- package/dist/runtime/editor/components/BlockPreviewItem/index.vue +10 -7
- package/dist/runtime/editor/components/BlockPreviewItem/index.vue.d.ts +5 -1
- package/dist/runtime/editor/components/BlockPreviewRenderer/index.d.vue.ts +1 -1
- package/dist/runtime/editor/components/BlockPreviewRenderer/index.vue.d.ts +1 -1
- package/dist/runtime/editor/components/Dialog/index.d.vue.ts +2 -2
- package/dist/runtime/editor/components/Dialog/index.vue.d.ts +2 -2
- package/dist/runtime/editor/components/DiffViewer/DiffValue.d.vue.ts +7 -0
- package/dist/runtime/editor/components/DiffViewer/DiffValue.vue +21 -0
- package/dist/runtime/editor/components/DiffViewer/DiffValue.vue.d.ts +7 -0
- package/dist/runtime/editor/components/DiffViewer/State.vue +4 -9
- package/dist/runtime/editor/components/EditProvider.vue +25 -4
- package/dist/runtime/editor/components/FeaturesRenderer/index.vue +26 -8
- package/dist/runtime/editor/components/FlexTextarea/index.d.vue.ts +31 -0
- package/dist/runtime/editor/components/FlexTextarea/index.vue +179 -0
- package/dist/runtime/editor/components/FlexTextarea/index.vue.d.ts +31 -0
- package/dist/runtime/editor/components/Form/Text/index.vue +23 -11
- package/dist/runtime/editor/components/Form/Toggle/index.d.vue.ts +1 -0
- package/dist/runtime/editor/components/Form/Toggle/index.vue +7 -3
- package/dist/runtime/editor/components/Form/Toggle/index.vue.d.ts +1 -0
- package/dist/runtime/editor/components/Icon/index.vue +3 -1
- package/dist/runtime/editor/components/Indicators/index.vue +20 -10
- package/dist/runtime/editor/components/ItemIcon/index.d.vue.ts +3 -0
- package/dist/runtime/editor/components/ItemIcon/index.vue +3 -2
- package/dist/runtime/editor/components/ItemIcon/index.vue.d.ts +3 -0
- package/dist/runtime/editor/components/ItemIconBox/index.vue +4 -1
- package/dist/runtime/editor/components/NestedEditorOverlay/index.d.vue.ts +3 -1
- package/dist/runtime/editor/components/NestedEditorOverlay/index.vue +150 -71
- package/dist/runtime/editor/components/NestedEditorOverlay/index.vue.d.ts +3 -1
- package/dist/runtime/editor/components/PluginConfigForm/index.vue +6 -2
- package/dist/runtime/editor/components/RelativeTime/index.d.vue.ts +3 -2
- package/dist/runtime/editor/components/RelativeTime/index.vue +21 -7
- package/dist/runtime/editor/components/RelativeTime/index.vue.d.ts +3 -2
- package/dist/runtime/editor/components/StatusIcon/index.d.vue.ts +9 -0
- package/dist/runtime/editor/components/StatusIcon/index.vue +31 -0
- package/dist/runtime/editor/components/StatusIcon/index.vue.d.ts +9 -0
- package/dist/runtime/editor/components/SystemRequirements/index.vue +5 -1
- package/dist/runtime/editor/components/Transition/Height.vue +3 -2
- package/dist/runtime/editor/components/Transition/index.d.vue.ts +1 -1
- package/dist/runtime/editor/components/Transition/index.vue +2 -1
- package/dist/runtime/editor/components/Transition/index.vue.d.ts +1 -1
- package/dist/runtime/editor/components/index.d.ts +10 -6
- package/dist/runtime/editor/components/index.js +19 -11
- package/dist/runtime/editor/composables/index.d.ts +2 -0
- package/dist/runtime/editor/composables/index.js +2 -0
- package/dist/runtime/editor/composables/onElementResize.d.ts +3 -0
- package/dist/runtime/editor/composables/onElementResize.js +37 -0
- package/dist/runtime/editor/composables/useEditableFieldOverride.d.ts +24 -0
- package/dist/runtime/editor/composables/useEditableFieldOverride.js +130 -0
- package/dist/runtime/editor/composables/useStickyToolbar.d.ts +4 -3
- package/dist/runtime/editor/composables/useStickyToolbar.js +26 -10
- package/dist/runtime/editor/css/output.css +1 -1
- package/dist/runtime/editor/events/index.d.ts +31 -0
- package/dist/runtime/editor/features/add-list/Actions/Action.d.vue.ts +8 -1
- package/dist/runtime/editor/features/add-list/Actions/Action.vue +7 -1
- package/dist/runtime/editor/features/add-list/Actions/Action.vue.d.ts +8 -1
- package/dist/runtime/editor/features/add-list/Actions/index.d.vue.ts +11 -1
- package/dist/runtime/editor/features/add-list/Actions/index.vue +29 -8
- package/dist/runtime/editor/features/add-list/Actions/index.vue.d.ts +11 -1
- package/dist/runtime/editor/features/add-list/Blocks/index.d.vue.ts +11 -2
- package/dist/runtime/editor/features/add-list/Blocks/index.vue +27 -1
- package/dist/runtime/editor/features/add-list/Blocks/index.vue.d.ts +11 -2
- package/dist/runtime/editor/features/add-list/Help/Item.d.vue.ts +12 -0
- package/dist/runtime/editor/features/add-list/Help/Item.vue +186 -0
- package/dist/runtime/editor/features/add-list/Help/Item.vue.d.ts +12 -0
- package/dist/runtime/editor/features/add-list/Help/index.d.vue.ts +13 -0
- package/dist/runtime/editor/features/add-list/Help/index.vue +127 -0
- package/dist/runtime/editor/features/add-list/Help/index.vue.d.ts +13 -0
- package/dist/runtime/editor/features/add-list/docs.md +2 -2
- package/dist/runtime/editor/features/add-list/index.vue +108 -9
- package/dist/runtime/editor/features/add-list/types.d.ts +5 -0
- package/dist/runtime/editor/features/analyze/Main.vue +4 -1
- package/dist/runtime/editor/features/analyze/Summary/Chart.vue +9 -9
- package/dist/runtime/editor/features/analyze/index.vue +2 -14
- package/dist/runtime/editor/features/analyze/types.d.ts +4 -1
- package/dist/runtime/editor/features/artboard/Renderer.vue +43 -0
- package/dist/runtime/editor/features/assistant/docs.md +5 -5
- package/dist/runtime/editor/features/breadcrumbs/index.vue +4 -1
- package/dist/runtime/editor/features/clipboard/index.vue +6 -2
- package/dist/runtime/editor/features/comments/index.vue +1 -0
- package/dist/runtime/editor/features/comments/types.d.ts +6 -0
- package/dist/runtime/editor/features/dragging-overlay/DragItems/index.d.vue.ts +2 -1
- package/dist/runtime/editor/features/dragging-overlay/DragItems/index.vue +32 -13
- package/dist/runtime/editor/features/dragging-overlay/DragItems/index.vue.d.ts +2 -1
- package/dist/runtime/editor/features/dragging-overlay/Renderer/fragment.glsl +77 -2
- package/dist/runtime/editor/features/dragging-overlay/Renderer/index.d.vue.ts +1 -0
- package/dist/runtime/editor/features/dragging-overlay/Renderer/index.vue +143 -52
- package/dist/runtime/editor/features/dragging-overlay/Renderer/index.vue.d.ts +1 -0
- package/dist/runtime/editor/features/dragging-overlay/Renderer/vertex.glsl +84 -31
- package/dist/runtime/editor/features/dragging-overlay/index.vue +3 -2
- package/dist/runtime/editor/features/edit/index.vue +7 -1
- package/dist/runtime/editor/features/editable-field/Overlay/Plaintext/index.vue +13 -23
- package/dist/runtime/editor/features/editable-field/Overlay/index.vue +10 -102
- package/dist/runtime/editor/features/editable-field/types.d.ts +12 -2
- package/dist/runtime/editor/features/entity-title/index.vue +7 -7
- package/dist/runtime/editor/features/fragments/index.vue +1 -1
- package/dist/runtime/editor/features/import-existing/Dialog/index.vue +8 -13
- package/dist/runtime/editor/features/library/ReusableDialog/index.vue +6 -1
- package/dist/runtime/editor/features/library/index.vue +14 -5
- package/dist/runtime/editor/features/library/types.d.ts +6 -0
- package/dist/runtime/editor/features/media-library/Library/Item.d.vue.ts +2 -2
- package/dist/runtime/editor/features/media-library/Library/Item.vue +17 -1
- package/dist/runtime/editor/features/media-library/Library/Item.vue.d.ts +2 -2
- package/dist/runtime/editor/features/media-library/Library/index.vue +6 -1
- package/dist/runtime/editor/features/media-library/index.vue +4 -4
- package/dist/runtime/editor/features/options/Form/index.vue +11 -43
- package/dist/runtime/editor/features/ownership/Banner/index.d.vue.ts +6 -3
- package/dist/runtime/editor/features/ownership/Banner/index.vue +10 -1
- package/dist/runtime/editor/features/ownership/Banner/index.vue.d.ts +6 -3
- package/dist/runtime/editor/features/ownership/index.vue +18 -6
- package/dist/runtime/editor/features/ownership/types.d.ts +5 -0
- package/dist/runtime/editor/features/publish/index.vue +5 -1
- package/dist/runtime/editor/features/search/Overlay/index.vue +5 -2
- package/dist/runtime/editor/features/search/index.vue +64 -3
- package/dist/runtime/editor/features/search/types.d.ts +16 -1
- package/dist/runtime/editor/features/selection/AddButtons/Renderer/index.vue +1 -3
- package/dist/runtime/editor/features/selection/AddButtons/index.vue +24 -4
- package/dist/runtime/editor/features/selection/Renderer/index.vue +5 -1
- package/dist/runtime/editor/features/selection/index.vue +5 -1
- package/dist/runtime/editor/features/settings/Dialog/index.vue +3 -1
- package/dist/runtime/editor/features/settings/index.vue +4 -1
- package/dist/runtime/editor/features/templates/CreateDialog/index.vue +21 -2
- package/dist/runtime/editor/features/templates/Dialog/Item/index.d.vue.ts +1 -1
- package/dist/runtime/editor/features/templates/Dialog/Item/index.vue +3 -3
- package/dist/runtime/editor/features/templates/Dialog/Item/index.vue.d.ts +1 -1
- package/dist/runtime/editor/features/templates/Dialog/index.vue +21 -5
- package/dist/runtime/editor/features/templates/ManageDialog/Item.d.vue.ts +8 -0
- package/dist/runtime/editor/features/templates/ManageDialog/Item.vue +147 -0
- package/dist/runtime/editor/features/templates/ManageDialog/Item.vue.d.ts +8 -0
- package/dist/runtime/editor/features/templates/ManageDialog/index.vue +30 -107
- package/dist/runtime/editor/features/templates/index.vue +7 -5
- package/dist/runtime/editor/features/templates/types.d.ts +11 -2
- package/dist/runtime/editor/features/transform/Dialog/index.vue +6 -1
- package/dist/runtime/editor/features/transform/index.vue +25 -20
- package/dist/runtime/editor/features/transform/types.d.ts +6 -4
- package/dist/runtime/editor/features/validations/index.vue +6 -1
- package/dist/runtime/editor/helpers/date/index.d.ts +1 -0
- package/dist/runtime/editor/helpers/date/index.js +3 -0
- package/dist/runtime/editor/helpers/options/index.d.ts +20 -0
- package/dist/runtime/editor/helpers/options/index.js +60 -0
- package/dist/runtime/editor/helpers/webgl/index.d.ts +5 -1
- package/dist/runtime/editor/helpers/webgl/index.js +45 -13
- package/dist/runtime/editor/icons/svg/stars.svg +1 -0
- package/dist/runtime/editor/plugins/Sidebar/Detached/index.d.vue.ts +1 -1
- package/dist/runtime/editor/plugins/Sidebar/Detached/index.vue +13 -10
- package/dist/runtime/editor/plugins/Sidebar/Detached/index.vue.d.ts +1 -1
- package/dist/runtime/editor/plugins/Sidebar/index.d.vue.ts +3 -1
- package/dist/runtime/editor/plugins/Sidebar/index.vue +14 -2
- package/dist/runtime/editor/plugins/Sidebar/index.vue.d.ts +3 -1
- package/dist/runtime/editor/providers/adapters.d.ts +33 -0
- package/dist/runtime/editor/providers/adapters.js +88 -0
- package/dist/runtime/editor/providers/animation.js +3 -0
- package/dist/runtime/editor/providers/definition.d.ts +7 -0
- package/dist/runtime/editor/providers/definition.js +6 -0
- package/dist/runtime/editor/providers/dom.d.ts +7 -0
- package/dist/runtime/editor/providers/dom.js +12 -0
- package/dist/runtime/editor/providers/permissions.d.ts +6 -0
- package/dist/runtime/editor/providers/permissions.js +9 -0
- package/dist/runtime/editor/providers/plugin.d.ts +1 -0
- package/dist/runtime/editor/providers/state.js +1 -0
- package/dist/runtime/editor/providers/texts.js +20 -6
- package/dist/runtime/editor/providers/types.d.ts +7 -0
- package/dist/runtime/editor/providers/types.js +4 -0
- package/dist/runtime/editor/providers/ui.d.ts +40 -0
- package/dist/runtime/editor/providers/ui.js +27 -1
- package/dist/runtime/editor/translations/de.json +2738 -0
- package/dist/runtime/editor/translations/fr.json +2738 -0
- package/dist/runtime/editor/translations/gsw_CH.json +2738 -0
- package/dist/runtime/editor/translations/it.json +2738 -0
- package/dist/runtime/editor/types/app.d.ts +9 -2
- package/dist/runtime/editor/types/definitions.d.ts +5 -0
- package/dist/runtime/editor/types/features.d.ts +3 -1
- package/dist/runtime/editor/types/permissions.d.ts +17 -0
- package/dist/runtime/editor/types/permissions.js +0 -0
- package/dist/runtime/types/index.d.ts +6 -0
- package/dist/shared/editor.CGf7C_0M.mjs +10 -0
- package/dist/shared/editor.DMFfaLVE.mjs +175 -0
- package/dist/shared/{editor.BKQCh70G.d.mts → editor.Iax3GCvt.d.mts} +94 -40
- package/dist/types.d.mts +7 -1
- package/package.json +29 -7
|
@@ -0,0 +1,875 @@
|
|
|
1
|
+
import { ref, readonly, watch } from "#imports";
|
|
2
|
+
import {
|
|
3
|
+
conversationItemSchema
|
|
4
|
+
} from "#blokkli/agent/app/types";
|
|
5
|
+
import {
|
|
6
|
+
createToolMap,
|
|
7
|
+
executeTool,
|
|
8
|
+
getToolCategory,
|
|
9
|
+
getToolsForServer,
|
|
10
|
+
getToolDefinition,
|
|
11
|
+
isMutationAction,
|
|
12
|
+
isQueryResult,
|
|
13
|
+
isToolError,
|
|
14
|
+
resolveTools
|
|
15
|
+
} from "#blokkli/agent/app/helpers";
|
|
16
|
+
import { mcpTools } from "#blokkli-build/agent-client";
|
|
17
|
+
import { generateUUID } from "#blokkli/editor/helpers/uuid";
|
|
18
|
+
import { itemEntityType } from "#blokkli-build/config";
|
|
19
|
+
export default function(app, adapter, agentName) {
|
|
20
|
+
const { $t, state, ui, context } = app;
|
|
21
|
+
let ws = null;
|
|
22
|
+
let reconnectTimeout = null;
|
|
23
|
+
let pingInterval = null;
|
|
24
|
+
let hasEverConnected = false;
|
|
25
|
+
const isConnected = ref(false);
|
|
26
|
+
const isReady = ref(false);
|
|
27
|
+
const hasBeenReady = ref(false);
|
|
28
|
+
let pendingPrompt = null;
|
|
29
|
+
let pendingInit = null;
|
|
30
|
+
let toolMap = {};
|
|
31
|
+
const isProcessing = ref(false);
|
|
32
|
+
const isThinking = ref(false);
|
|
33
|
+
const usageTurns = ref([]);
|
|
34
|
+
const conversation = ref([]);
|
|
35
|
+
const activeItem = ref(null);
|
|
36
|
+
const autoApprove = ref(false);
|
|
37
|
+
const pendingMutation = ref(null);
|
|
38
|
+
const pendingToolCall = ref(null);
|
|
39
|
+
let pendingToolCallResolve = null;
|
|
40
|
+
const plan = ref(null);
|
|
41
|
+
const transcriptContent = ref("");
|
|
42
|
+
const showTranscript = ref(false);
|
|
43
|
+
const activeConversationId = ref(null);
|
|
44
|
+
const conversationList = ref([]);
|
|
45
|
+
const showConversationList = ref(false);
|
|
46
|
+
async function saveCurrentConversation(serverState) {
|
|
47
|
+
if (!adapter.agentConversations) return;
|
|
48
|
+
if (!conversation.value.length) return;
|
|
49
|
+
if (!activeConversationId.value) {
|
|
50
|
+
activeConversationId.value = generateUUID();
|
|
51
|
+
}
|
|
52
|
+
const firstUser = conversation.value.find((item) => item.type === "user");
|
|
53
|
+
const titleText = firstUser && "content" in firstUser ? firstUser.content : "";
|
|
54
|
+
const title = titleText.length > 80 ? titleText.slice(0, 80) + "\u2026" : titleText;
|
|
55
|
+
try {
|
|
56
|
+
await adapter.agentConversations.upsert({
|
|
57
|
+
uuid: activeConversationId.value,
|
|
58
|
+
title,
|
|
59
|
+
clientState: JSON.stringify({
|
|
60
|
+
conversation: conversation.value.filter(
|
|
61
|
+
(item) => item.type !== "error"
|
|
62
|
+
),
|
|
63
|
+
usageTurns: usageTurns.value
|
|
64
|
+
}),
|
|
65
|
+
serverState: JSON.stringify({
|
|
66
|
+
messages: serverState.messages,
|
|
67
|
+
activatedLazyTools: serverState.activatedLazyTools
|
|
68
|
+
}),
|
|
69
|
+
hash: serverState.hash
|
|
70
|
+
});
|
|
71
|
+
} catch (e) {
|
|
72
|
+
console.warn("[blokkli agent] Failed to save conversation:", e);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
function parseConversationData(data) {
|
|
76
|
+
try {
|
|
77
|
+
const parsed = JSON.parse(data.clientState);
|
|
78
|
+
if (!parsed.conversation?.length) {
|
|
79
|
+
return null;
|
|
80
|
+
}
|
|
81
|
+
const clientConversation = parsed.conversation.map(
|
|
82
|
+
(item) => {
|
|
83
|
+
const result = conversationItemSchema.safeParse(item);
|
|
84
|
+
if (result.success) {
|
|
85
|
+
return result.data;
|
|
86
|
+
}
|
|
87
|
+
return {
|
|
88
|
+
type: "unknown",
|
|
89
|
+
id: generateId(),
|
|
90
|
+
timestamp: Date.now()
|
|
91
|
+
};
|
|
92
|
+
}
|
|
93
|
+
);
|
|
94
|
+
const serverParsed = JSON.parse(data.serverState);
|
|
95
|
+
if (!serverParsed?.messages?.length) {
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
return {
|
|
99
|
+
conversation: clientConversation,
|
|
100
|
+
usageTurns: parsed.usageTurns ?? [],
|
|
101
|
+
serverState: {
|
|
102
|
+
messages: serverParsed.messages,
|
|
103
|
+
activatedLazyTools: serverParsed.activatedLazyTools,
|
|
104
|
+
hash: data.hash
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
} catch {
|
|
108
|
+
return null;
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
async function loadConversation(uuid) {
|
|
112
|
+
if (!adapter.agentConversations) return null;
|
|
113
|
+
try {
|
|
114
|
+
const data = await adapter.agentConversations.load(uuid);
|
|
115
|
+
if (!data) return null;
|
|
116
|
+
return parseConversationData(data);
|
|
117
|
+
} catch (e) {
|
|
118
|
+
console.warn("[blokkli agent] Failed to load conversation:", e);
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
async function deleteConversation(id) {
|
|
123
|
+
if (adapter.agentConversations) {
|
|
124
|
+
try {
|
|
125
|
+
await adapter.agentConversations.delete(id);
|
|
126
|
+
} catch (e) {
|
|
127
|
+
console.warn("[blokkli agent] Failed to delete conversation:", e);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
if (activeConversationId.value === id) {
|
|
131
|
+
activeConversationId.value = null;
|
|
132
|
+
conversation.value = [];
|
|
133
|
+
activeItem.value = null;
|
|
134
|
+
isProcessing.value = false;
|
|
135
|
+
isThinking.value = false;
|
|
136
|
+
send({ type: "new_conversation" });
|
|
137
|
+
}
|
|
138
|
+
await refreshConversationList();
|
|
139
|
+
}
|
|
140
|
+
async function switchConversation(id) {
|
|
141
|
+
if (isProcessing.value) return;
|
|
142
|
+
const loaded = await loadConversation(id);
|
|
143
|
+
if (!loaded) return;
|
|
144
|
+
conversation.value = loaded.conversation;
|
|
145
|
+
usageTurns.value = loaded.usageTurns;
|
|
146
|
+
activeItem.value = null;
|
|
147
|
+
activeConversationId.value = id;
|
|
148
|
+
send({ type: "restore_conversation", state: loaded.serverState });
|
|
149
|
+
showConversationList.value = false;
|
|
150
|
+
}
|
|
151
|
+
async function refreshConversationList() {
|
|
152
|
+
if (!adapter.agentConversations) {
|
|
153
|
+
conversationList.value = [];
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
try {
|
|
157
|
+
const list = await adapter.agentConversations.list();
|
|
158
|
+
conversationList.value = list.sort(
|
|
159
|
+
(a, b) => b.updatedAt.localeCompare(a.updatedAt)
|
|
160
|
+
);
|
|
161
|
+
} catch (e) {
|
|
162
|
+
console.warn("[blokkli agent] Failed to list conversations:", e);
|
|
163
|
+
conversationList.value = [];
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
watch(isProcessing, (processing) => {
|
|
167
|
+
if (processing) {
|
|
168
|
+
ui.setTransform(agentName);
|
|
169
|
+
} else {
|
|
170
|
+
ui.setTransform(null);
|
|
171
|
+
}
|
|
172
|
+
});
|
|
173
|
+
function send(message) {
|
|
174
|
+
if (ws?.readyState === WebSocket.OPEN) {
|
|
175
|
+
ws.send(JSON.stringify(message));
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
function onWebSocketOpen() {
|
|
179
|
+
isConnected.value = true;
|
|
180
|
+
pingInterval = window.setInterval(() => {
|
|
181
|
+
send({ type: "ping" });
|
|
182
|
+
}, 3e4);
|
|
183
|
+
onConnect();
|
|
184
|
+
}
|
|
185
|
+
function onWebSocketClose() {
|
|
186
|
+
isConnected.value = false;
|
|
187
|
+
isReady.value = false;
|
|
188
|
+
isProcessing.value = false;
|
|
189
|
+
reconnectTimeout = window.setTimeout(() => {
|
|
190
|
+
if (!isConnected.value) {
|
|
191
|
+
connect();
|
|
192
|
+
}
|
|
193
|
+
}, 3e3);
|
|
194
|
+
}
|
|
195
|
+
function onWebSocketError(error) {
|
|
196
|
+
console.error("WebSocket error:", error);
|
|
197
|
+
}
|
|
198
|
+
function onWebSocketMessage(event) {
|
|
199
|
+
try {
|
|
200
|
+
const data = JSON.parse(event.data);
|
|
201
|
+
handleServerMessage(data);
|
|
202
|
+
} catch (error) {
|
|
203
|
+
console.error("Failed to parse WebSocket message:", error);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
function connect() {
|
|
207
|
+
if (hasEverConnected) return;
|
|
208
|
+
hasEverConnected = true;
|
|
209
|
+
const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
|
|
210
|
+
const url = `${protocol}//${window.location.host}/api/blokkli/agent`;
|
|
211
|
+
ws = new WebSocket(url);
|
|
212
|
+
ws.addEventListener("open", onWebSocketOpen);
|
|
213
|
+
ws.addEventListener("close", onWebSocketClose);
|
|
214
|
+
ws.addEventListener("error", onWebSocketError);
|
|
215
|
+
ws.addEventListener("message", onWebSocketMessage);
|
|
216
|
+
}
|
|
217
|
+
function disconnect() {
|
|
218
|
+
if (pingInterval) {
|
|
219
|
+
window.clearInterval(pingInterval);
|
|
220
|
+
pingInterval = null;
|
|
221
|
+
}
|
|
222
|
+
if (reconnectTimeout) {
|
|
223
|
+
window.clearTimeout(reconnectTimeout);
|
|
224
|
+
reconnectTimeout = null;
|
|
225
|
+
}
|
|
226
|
+
if (ws) {
|
|
227
|
+
ws.removeEventListener("open", onWebSocketOpen);
|
|
228
|
+
ws.removeEventListener("close", onWebSocketClose);
|
|
229
|
+
ws.removeEventListener("error", onWebSocketError);
|
|
230
|
+
ws.removeEventListener("message", onWebSocketMessage);
|
|
231
|
+
ws.close();
|
|
232
|
+
ws = null;
|
|
233
|
+
}
|
|
234
|
+
isConnected.value = false;
|
|
235
|
+
isReady.value = false;
|
|
236
|
+
ui.setTransform(null);
|
|
237
|
+
if (pendingMutation.value) {
|
|
238
|
+
if (pendingMutation.value.action.revert) {
|
|
239
|
+
pendingMutation.value.action.revert();
|
|
240
|
+
}
|
|
241
|
+
pendingMutation.value.resolve(false);
|
|
242
|
+
pendingMutation.value = null;
|
|
243
|
+
}
|
|
244
|
+
if (pendingToolCallResolve) {
|
|
245
|
+
pendingToolCallResolve({ cancelled: true });
|
|
246
|
+
pendingToolCallResolve = null;
|
|
247
|
+
}
|
|
248
|
+
pendingToolCall.value = null;
|
|
249
|
+
}
|
|
250
|
+
async function onConnect() {
|
|
251
|
+
const ctx = createToolContext();
|
|
252
|
+
const resolved = await resolveTools(mcpTools, ctx);
|
|
253
|
+
toolMap = createToolMap(resolved);
|
|
254
|
+
if (adapter.getAgentAuthToken) {
|
|
255
|
+
try {
|
|
256
|
+
const authToken = await adapter.getAgentAuthToken();
|
|
257
|
+
if (!authToken) {
|
|
258
|
+
conversation.value.push({
|
|
259
|
+
type: "error",
|
|
260
|
+
id: generateId(),
|
|
261
|
+
errorType: "unauthorized",
|
|
262
|
+
timestamp: Date.now()
|
|
263
|
+
});
|
|
264
|
+
disconnect();
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
send({ type: "authenticate", authToken });
|
|
268
|
+
pendingInit = {
|
|
269
|
+
tools: getToolsForServer(resolved, state.editMode.value, adapter),
|
|
270
|
+
pageContext: buildPageContext()
|
|
271
|
+
};
|
|
272
|
+
return;
|
|
273
|
+
} catch (e) {
|
|
274
|
+
console.error("Failed to obtain agent auth token:", e);
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
sendInit(
|
|
278
|
+
getToolsForServer(resolved, state.editMode.value, adapter),
|
|
279
|
+
buildPageContext()
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
async function sendInit(tools, pageContext) {
|
|
283
|
+
send({ type: "init", tools, pageContext });
|
|
284
|
+
isReady.value = true;
|
|
285
|
+
hasBeenReady.value = true;
|
|
286
|
+
if (adapter.agentConversations) {
|
|
287
|
+
try {
|
|
288
|
+
const latest = await adapter.agentConversations.loadLatest();
|
|
289
|
+
if (latest) {
|
|
290
|
+
const parsed = parseConversationData(latest);
|
|
291
|
+
if (parsed) {
|
|
292
|
+
activeConversationId.value = latest.uuid;
|
|
293
|
+
conversation.value = parsed.conversation;
|
|
294
|
+
usageTurns.value = parsed.usageTurns;
|
|
295
|
+
send({ type: "restore_conversation", state: parsed.serverState });
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
} catch (e) {
|
|
299
|
+
console.warn("[blokkli agent] Failed to load latest conversation:", e);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
if (pendingPrompt) {
|
|
303
|
+
const { prompt, displayPrompt, selectedUuids, attachments } = pendingPrompt;
|
|
304
|
+
pendingPrompt = null;
|
|
305
|
+
sendPrompt(prompt, displayPrompt, selectedUuids, attachments);
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
function buildPageContext() {
|
|
309
|
+
const { types, definitions } = app;
|
|
310
|
+
const bundles = [];
|
|
311
|
+
for (const bundle of types.generallyAvailableBundles) {
|
|
312
|
+
const contentFields = [
|
|
313
|
+
...types.editableFieldConfig.forEntityTypeAndBundle(itemEntityType, bundle.id).filter((f) => f.type !== "table").map((f) => ({
|
|
314
|
+
name: f.name,
|
|
315
|
+
label: f.label,
|
|
316
|
+
type: f.type === "frame" || f.type === "markup" ? "markup" : "plain"
|
|
317
|
+
})),
|
|
318
|
+
...types.droppableFieldConfig.forEntityTypeAndBundle(itemEntityType, bundle.id).map((f) => ({
|
|
319
|
+
name: f.name,
|
|
320
|
+
label: f.label,
|
|
321
|
+
type: f.type,
|
|
322
|
+
allowed: f.allowed
|
|
323
|
+
}))
|
|
324
|
+
];
|
|
325
|
+
const paragraphFields = types.fieldConfig.forEntityTypeAndBundle(itemEntityType, bundle.id).map((f) => ({
|
|
326
|
+
name: f.name,
|
|
327
|
+
label: f.label,
|
|
328
|
+
allowedBundles: f.allowedBundles,
|
|
329
|
+
cardinality: f.cardinality
|
|
330
|
+
}));
|
|
331
|
+
bundles.push({
|
|
332
|
+
id: bundle.id,
|
|
333
|
+
label: bundle.label,
|
|
334
|
+
description: bundle.description,
|
|
335
|
+
contentFields,
|
|
336
|
+
paragraphFields
|
|
337
|
+
});
|
|
338
|
+
}
|
|
339
|
+
const fragments = definitions.fragmentDefinitions.value.map((f) => ({
|
|
340
|
+
name: f.name,
|
|
341
|
+
label: f.label,
|
|
342
|
+
description: f.description
|
|
343
|
+
}));
|
|
344
|
+
const entityContentFields = [
|
|
345
|
+
...types.editableFieldConfig.forEntityTypeAndBundle(
|
|
346
|
+
context.value.entityType,
|
|
347
|
+
context.value.entityBundle
|
|
348
|
+
).filter((f) => f.type !== "table").map((f) => ({
|
|
349
|
+
name: f.name,
|
|
350
|
+
label: f.label,
|
|
351
|
+
type: f.type === "frame" || f.type === "markup" ? "markup" : "plain"
|
|
352
|
+
})),
|
|
353
|
+
...types.droppableFieldConfig.forEntityTypeAndBundle(
|
|
354
|
+
context.value.entityType,
|
|
355
|
+
context.value.entityBundle
|
|
356
|
+
).map((f) => ({
|
|
357
|
+
name: f.name,
|
|
358
|
+
label: f.label,
|
|
359
|
+
type: f.type,
|
|
360
|
+
allowed: f.allowed
|
|
361
|
+
}))
|
|
362
|
+
];
|
|
363
|
+
const pageContext = {
|
|
364
|
+
title: state.entity.value.label || "",
|
|
365
|
+
entityType: context.value.entityType,
|
|
366
|
+
entityUuid: context.value.entityUuid,
|
|
367
|
+
entityBundle: context.value.entityBundle,
|
|
368
|
+
bundleLabel: state.entity.value.bundleLabel || "",
|
|
369
|
+
itemEntityType,
|
|
370
|
+
bundles,
|
|
371
|
+
interfaceLanguage: ui.interfaceLanguage.value,
|
|
372
|
+
entityLanguage: context.value.language,
|
|
373
|
+
isPublished: state.entity.value.status ?? null,
|
|
374
|
+
editMode: state.editMode.value,
|
|
375
|
+
fragments,
|
|
376
|
+
entityContentFields
|
|
377
|
+
};
|
|
378
|
+
return pageContext;
|
|
379
|
+
}
|
|
380
|
+
function generateId() {
|
|
381
|
+
return `${Date.now()}-${Math.random().toString(36).substring(2, 9)}`;
|
|
382
|
+
}
|
|
383
|
+
function finalizeActiveItem() {
|
|
384
|
+
const item = activeItem.value;
|
|
385
|
+
if (!item) return;
|
|
386
|
+
if (item.type === "assistant" && item.content) {
|
|
387
|
+
conversation.value.push({
|
|
388
|
+
type: "assistant",
|
|
389
|
+
id: item.id,
|
|
390
|
+
content: item.content,
|
|
391
|
+
timestamp: item.timestamp
|
|
392
|
+
});
|
|
393
|
+
}
|
|
394
|
+
activeItem.value = null;
|
|
395
|
+
}
|
|
396
|
+
function handleTextContent(content) {
|
|
397
|
+
if (activeItem.value?.type === "assistant") {
|
|
398
|
+
activeItem.value = {
|
|
399
|
+
...activeItem.value,
|
|
400
|
+
content: activeItem.value.content + content
|
|
401
|
+
};
|
|
402
|
+
} else {
|
|
403
|
+
activeItem.value = {
|
|
404
|
+
type: "assistant",
|
|
405
|
+
id: generateId(),
|
|
406
|
+
content,
|
|
407
|
+
timestamp: Date.now()
|
|
408
|
+
};
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
function handleServerMessage(data) {
|
|
412
|
+
switch (data.type) {
|
|
413
|
+
case "authenticated":
|
|
414
|
+
if (pendingInit) {
|
|
415
|
+
sendInit(pendingInit.tools, pendingInit.pageContext);
|
|
416
|
+
pendingInit = null;
|
|
417
|
+
}
|
|
418
|
+
break;
|
|
419
|
+
case "thinking":
|
|
420
|
+
activeItem.value = null;
|
|
421
|
+
isThinking.value = true;
|
|
422
|
+
break;
|
|
423
|
+
case "text":
|
|
424
|
+
isThinking.value = false;
|
|
425
|
+
handleTextContent(data.content);
|
|
426
|
+
break;
|
|
427
|
+
case "text_delta":
|
|
428
|
+
isThinking.value = false;
|
|
429
|
+
handleTextContent(data.content);
|
|
430
|
+
break;
|
|
431
|
+
case "tool_call":
|
|
432
|
+
finalizeActiveItem();
|
|
433
|
+
handleToolCall(data.callId, data.tool, data.params);
|
|
434
|
+
break;
|
|
435
|
+
case "usage":
|
|
436
|
+
usageTurns.value = [...usageTurns.value, data.usage];
|
|
437
|
+
break;
|
|
438
|
+
case "done":
|
|
439
|
+
finalizeActiveItem();
|
|
440
|
+
isThinking.value = false;
|
|
441
|
+
isProcessing.value = false;
|
|
442
|
+
if (data.message) {
|
|
443
|
+
const lastItem = conversation.value[conversation.value.length - 1];
|
|
444
|
+
const isDuplicate = lastItem?.type === "assistant" && lastItem.content === data.message;
|
|
445
|
+
if (!isDuplicate) {
|
|
446
|
+
conversation.value.push({
|
|
447
|
+
type: "assistant",
|
|
448
|
+
id: generateId(),
|
|
449
|
+
content: data.message,
|
|
450
|
+
timestamp: Date.now()
|
|
451
|
+
});
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
break;
|
|
455
|
+
case "error":
|
|
456
|
+
finalizeActiveItem();
|
|
457
|
+
isThinking.value = false;
|
|
458
|
+
isProcessing.value = false;
|
|
459
|
+
if (data.detail) {
|
|
460
|
+
console.warn(`[blokkli agent] ${data.errorType} error:`, data.detail);
|
|
461
|
+
}
|
|
462
|
+
conversation.value.push({
|
|
463
|
+
type: "error",
|
|
464
|
+
id: generateId(),
|
|
465
|
+
errorType: data.errorType,
|
|
466
|
+
timestamp: Date.now(),
|
|
467
|
+
...data.retryable ? { retryable: true } : {}
|
|
468
|
+
});
|
|
469
|
+
break;
|
|
470
|
+
case "server_tool_result":
|
|
471
|
+
finalizeActiveItem();
|
|
472
|
+
conversation.value.push({
|
|
473
|
+
type: "server_tool",
|
|
474
|
+
id: generateId(),
|
|
475
|
+
tool: data.tool,
|
|
476
|
+
label: data.label,
|
|
477
|
+
timestamp: Date.now()
|
|
478
|
+
});
|
|
479
|
+
break;
|
|
480
|
+
case "plan_update":
|
|
481
|
+
if (data.plan && data.plan.steps.length > 0 && data.plan.steps.every((s) => s.status === "completed")) {
|
|
482
|
+
conversation.value.push({
|
|
483
|
+
type: "server_tool",
|
|
484
|
+
id: generateId(),
|
|
485
|
+
tool: "plan_completed",
|
|
486
|
+
label: data.plan.title,
|
|
487
|
+
timestamp: Date.now()
|
|
488
|
+
});
|
|
489
|
+
plan.value = null;
|
|
490
|
+
} else {
|
|
491
|
+
plan.value = data.plan;
|
|
492
|
+
}
|
|
493
|
+
break;
|
|
494
|
+
case "transcript":
|
|
495
|
+
transcriptContent.value = data.content;
|
|
496
|
+
showTranscript.value = true;
|
|
497
|
+
break;
|
|
498
|
+
case "conversation_state":
|
|
499
|
+
saveCurrentConversation(data.state);
|
|
500
|
+
break;
|
|
501
|
+
case "conversation_restored":
|
|
502
|
+
break;
|
|
503
|
+
case "conversation_restore_failed":
|
|
504
|
+
console.warn(
|
|
505
|
+
"[blokkli agent] Conversation restore failed:",
|
|
506
|
+
data.reason
|
|
507
|
+
);
|
|
508
|
+
conversation.value = [];
|
|
509
|
+
if (activeConversationId.value) {
|
|
510
|
+
const failedId = activeConversationId.value;
|
|
511
|
+
activeConversationId.value = null;
|
|
512
|
+
if (adapter.agentConversations) {
|
|
513
|
+
adapter.agentConversations.delete(failedId).catch(() => {
|
|
514
|
+
});
|
|
515
|
+
}
|
|
516
|
+
}
|
|
517
|
+
break;
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
async function handleToolCall(callId, tool, params) {
|
|
521
|
+
const toolDef = getToolDefinition(toolMap, tool);
|
|
522
|
+
const initialLabel = toolDef.label($t);
|
|
523
|
+
const toolId = generateId();
|
|
524
|
+
const timestamp = Date.now();
|
|
525
|
+
let currentLabel = initialLabel;
|
|
526
|
+
activeItem.value = {
|
|
527
|
+
type: "tool",
|
|
528
|
+
id: toolId,
|
|
529
|
+
callId,
|
|
530
|
+
tool,
|
|
531
|
+
label: initialLabel,
|
|
532
|
+
status: "active",
|
|
533
|
+
timestamp
|
|
534
|
+
};
|
|
535
|
+
try {
|
|
536
|
+
const result = await executeToolLocally(tool, params, (label) => {
|
|
537
|
+
currentLabel = label;
|
|
538
|
+
if (activeItem.value?.type === "tool" && activeItem.value.callId === callId) {
|
|
539
|
+
activeItem.value = { ...activeItem.value, label };
|
|
540
|
+
}
|
|
541
|
+
});
|
|
542
|
+
if (isToolError(result)) {
|
|
543
|
+
conversation.value.push({
|
|
544
|
+
type: "tool",
|
|
545
|
+
id: toolId,
|
|
546
|
+
callId,
|
|
547
|
+
tool,
|
|
548
|
+
label: currentLabel,
|
|
549
|
+
status: "error",
|
|
550
|
+
timestamp
|
|
551
|
+
});
|
|
552
|
+
activeItem.value = null;
|
|
553
|
+
send({
|
|
554
|
+
type: "tool_result",
|
|
555
|
+
callId,
|
|
556
|
+
result: null,
|
|
557
|
+
error: result.error
|
|
558
|
+
});
|
|
559
|
+
} else {
|
|
560
|
+
conversation.value.push({
|
|
561
|
+
type: "tool",
|
|
562
|
+
id: toolId,
|
|
563
|
+
callId,
|
|
564
|
+
tool,
|
|
565
|
+
label: currentLabel,
|
|
566
|
+
status: "success",
|
|
567
|
+
timestamp
|
|
568
|
+
});
|
|
569
|
+
activeItem.value = null;
|
|
570
|
+
let resultForServer = result;
|
|
571
|
+
if (toolDef.prunedSummary && typeof result === "object" && result !== null) {
|
|
572
|
+
try {
|
|
573
|
+
const summary = toolDef.prunedSummary(result);
|
|
574
|
+
if (summary) {
|
|
575
|
+
resultForServer = {
|
|
576
|
+
...result,
|
|
577
|
+
_summary: summary
|
|
578
|
+
};
|
|
579
|
+
}
|
|
580
|
+
} catch {
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
send({
|
|
584
|
+
type: "tool_result",
|
|
585
|
+
callId,
|
|
586
|
+
result: resultForServer
|
|
587
|
+
});
|
|
588
|
+
}
|
|
589
|
+
} catch (error) {
|
|
590
|
+
conversation.value.push({
|
|
591
|
+
type: "tool",
|
|
592
|
+
id: toolId,
|
|
593
|
+
callId,
|
|
594
|
+
tool,
|
|
595
|
+
label: currentLabel,
|
|
596
|
+
status: "error",
|
|
597
|
+
timestamp
|
|
598
|
+
});
|
|
599
|
+
activeItem.value = null;
|
|
600
|
+
send({
|
|
601
|
+
type: "tool_result",
|
|
602
|
+
callId,
|
|
603
|
+
result: null,
|
|
604
|
+
error: error.message
|
|
605
|
+
});
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
function createToolContext() {
|
|
609
|
+
return {
|
|
610
|
+
app,
|
|
611
|
+
itemEntityType,
|
|
612
|
+
adapter
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
function waitForToolComponent(toolName, params) {
|
|
616
|
+
return new Promise((resolve) => {
|
|
617
|
+
pendingToolCall.value = { toolName, params };
|
|
618
|
+
pendingToolCallResolve = resolve;
|
|
619
|
+
});
|
|
620
|
+
}
|
|
621
|
+
async function executeToolLocally(toolName, params, setLabel) {
|
|
622
|
+
const toolContext = createToolContext();
|
|
623
|
+
const toolDef = getToolDefinition(toolMap, toolName);
|
|
624
|
+
if (toolDef.component) {
|
|
625
|
+
const preparedParams = await executeTool(
|
|
626
|
+
toolMap,
|
|
627
|
+
toolName,
|
|
628
|
+
toolContext,
|
|
629
|
+
params
|
|
630
|
+
);
|
|
631
|
+
if (typeof preparedParams === "object" && preparedParams !== null && "error" in preparedParams) {
|
|
632
|
+
return preparedParams;
|
|
633
|
+
}
|
|
634
|
+
const result2 = await waitForToolComponent(
|
|
635
|
+
toolDef.name,
|
|
636
|
+
preparedParams
|
|
637
|
+
);
|
|
638
|
+
if (setLabel && typeof result2 === "object" && result2 !== null && "label" in result2) {
|
|
639
|
+
setLabel(result2.label);
|
|
640
|
+
}
|
|
641
|
+
return result2;
|
|
642
|
+
}
|
|
643
|
+
const category = getToolCategory(toolMap, toolName);
|
|
644
|
+
const result = await executeTool(toolMap, toolName, toolContext, params);
|
|
645
|
+
if (category === "query") {
|
|
646
|
+
if (isQueryResult(result)) {
|
|
647
|
+
if (setLabel) {
|
|
648
|
+
setLabel(result.label);
|
|
649
|
+
}
|
|
650
|
+
if (result.affectedUuids?.length) {
|
|
651
|
+
app.eventBus.emit("select", result.affectedUuids);
|
|
652
|
+
app.eventBus.emit("scrollSelectionIntoView", {});
|
|
653
|
+
}
|
|
654
|
+
return result.result;
|
|
655
|
+
}
|
|
656
|
+
return result;
|
|
657
|
+
}
|
|
658
|
+
if (typeof result === "object" && result !== null && "error" in result) {
|
|
659
|
+
return result;
|
|
660
|
+
}
|
|
661
|
+
if (!isMutationAction(result)) {
|
|
662
|
+
return { error: "Invalid mutation tool result" };
|
|
663
|
+
}
|
|
664
|
+
const action = result;
|
|
665
|
+
if (setLabel) {
|
|
666
|
+
setLabel(action.label);
|
|
667
|
+
}
|
|
668
|
+
async function applyMutation() {
|
|
669
|
+
const uuidsBefore = state.getAllUuids();
|
|
670
|
+
await state.mutateWithLoadingState(() => action.apply(adapter));
|
|
671
|
+
const newUuids = state.getAllUuids().filter((uuid) => !uuidsBefore.includes(uuid));
|
|
672
|
+
const selectUuids = newUuids.length ? newUuids : action.affectedUuids || [];
|
|
673
|
+
if (selectUuids.length) {
|
|
674
|
+
app.eventBus.emit("select", selectUuids);
|
|
675
|
+
app.eventBus.emit("scrollSelectionIntoView", {});
|
|
676
|
+
}
|
|
677
|
+
return newUuids;
|
|
678
|
+
}
|
|
679
|
+
function buildMutationResult(newUuids) {
|
|
680
|
+
const newParagraphs = action.type === "add" && newUuids.length ? newUuids.map((uuid) => {
|
|
681
|
+
const block = app.blocks.getBlock(uuid);
|
|
682
|
+
if (!block) return null;
|
|
683
|
+
const blockFieldNames = app.types.fieldConfig.forEntityTypeAndBundle(itemEntityType, block.bundle).map((f) => f.name);
|
|
684
|
+
return {
|
|
685
|
+
uuid,
|
|
686
|
+
bundle: block.bundle,
|
|
687
|
+
...blockFieldNames.length ? { paragraphFields: blockFieldNames } : {}
|
|
688
|
+
};
|
|
689
|
+
}).filter(
|
|
690
|
+
(b) => b !== null
|
|
691
|
+
) : void 0;
|
|
692
|
+
return {
|
|
693
|
+
success: true,
|
|
694
|
+
historyIndex: state.currentMutationIndex.value,
|
|
695
|
+
newParagraphs: newParagraphs?.length ? newParagraphs : void 0,
|
|
696
|
+
...action.result
|
|
697
|
+
};
|
|
698
|
+
}
|
|
699
|
+
if (autoApprove.value || !toolDef.requiresApproval) {
|
|
700
|
+
const newUuids = await applyMutation();
|
|
701
|
+
return buildMutationResult(newUuids);
|
|
702
|
+
}
|
|
703
|
+
const approved = await waitForApproval(action);
|
|
704
|
+
if (approved) {
|
|
705
|
+
const newUuids = await applyMutation();
|
|
706
|
+
return buildMutationResult(newUuids);
|
|
707
|
+
} else {
|
|
708
|
+
if (action.revert) {
|
|
709
|
+
action.revert();
|
|
710
|
+
}
|
|
711
|
+
return { success: false, rejected: true };
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
function waitForApproval(action) {
|
|
715
|
+
return new Promise((resolve) => {
|
|
716
|
+
pendingMutation.value = { action, resolve };
|
|
717
|
+
});
|
|
718
|
+
}
|
|
719
|
+
function sendPrompt(prompt, displayPrompt, selectedUuids, attachments) {
|
|
720
|
+
if (!prompt.trim() || isProcessing.value) return;
|
|
721
|
+
if (!isReady.value) {
|
|
722
|
+
pendingPrompt = { prompt, displayPrompt, selectedUuids, attachments };
|
|
723
|
+
return;
|
|
724
|
+
}
|
|
725
|
+
isProcessing.value = true;
|
|
726
|
+
if (!activeConversationId.value) {
|
|
727
|
+
activeConversationId.value = generateUUID();
|
|
728
|
+
}
|
|
729
|
+
const item = {
|
|
730
|
+
type: "user",
|
|
731
|
+
id: generateId(),
|
|
732
|
+
content: displayPrompt ?? prompt,
|
|
733
|
+
timestamp: Date.now()
|
|
734
|
+
};
|
|
735
|
+
if (attachments?.length) {
|
|
736
|
+
;
|
|
737
|
+
item.attachments = attachments;
|
|
738
|
+
}
|
|
739
|
+
conversation.value.push(item);
|
|
740
|
+
send({
|
|
741
|
+
type: "start",
|
|
742
|
+
prompt,
|
|
743
|
+
selectedUuids: selectedUuids?.length ? selectedUuids : void 0
|
|
744
|
+
});
|
|
745
|
+
}
|
|
746
|
+
function retry() {
|
|
747
|
+
if (isProcessing.value || !isReady.value) return;
|
|
748
|
+
const lastUserItem = [...conversation.value].reverse().find((item) => item.type === "user");
|
|
749
|
+
if (!lastUserItem || lastUserItem.type !== "user") return;
|
|
750
|
+
conversation.value = conversation.value.filter(
|
|
751
|
+
(item) => !(item.type === "error" && "retryable" in item && item.retryable)
|
|
752
|
+
);
|
|
753
|
+
isProcessing.value = true;
|
|
754
|
+
send({
|
|
755
|
+
type: "start",
|
|
756
|
+
prompt: lastUserItem.content
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
function approve() {
|
|
760
|
+
if (pendingMutation.value) {
|
|
761
|
+
pendingMutation.value.resolve(true);
|
|
762
|
+
pendingMutation.value = null;
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
function reject() {
|
|
766
|
+
if (pendingMutation.value) {
|
|
767
|
+
pendingMutation.value.resolve(false);
|
|
768
|
+
pendingMutation.value = null;
|
|
769
|
+
}
|
|
770
|
+
}
|
|
771
|
+
function setAutoApprove(value) {
|
|
772
|
+
autoApprove.value = value;
|
|
773
|
+
if (value) {
|
|
774
|
+
approve();
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
function cancel() {
|
|
778
|
+
if (pendingMutation.value) {
|
|
779
|
+
pendingMutation.value.resolve(false);
|
|
780
|
+
pendingMutation.value = null;
|
|
781
|
+
}
|
|
782
|
+
if (pendingToolCallResolve) {
|
|
783
|
+
pendingToolCallResolve({ cancelled: true });
|
|
784
|
+
pendingToolCallResolve = null;
|
|
785
|
+
}
|
|
786
|
+
pendingToolCall.value = null;
|
|
787
|
+
activeItem.value = null;
|
|
788
|
+
send({ type: "cancel" });
|
|
789
|
+
isProcessing.value = false;
|
|
790
|
+
conversation.value.push({
|
|
791
|
+
type: "assistant",
|
|
792
|
+
id: generateId(),
|
|
793
|
+
content: $t("aiAgentCancelled", "Cancelled"),
|
|
794
|
+
timestamp: Date.now()
|
|
795
|
+
});
|
|
796
|
+
}
|
|
797
|
+
function approvePlan() {
|
|
798
|
+
send({ type: "plan_approve" });
|
|
799
|
+
}
|
|
800
|
+
function rejectPlan() {
|
|
801
|
+
send({ type: "plan_reject" });
|
|
802
|
+
}
|
|
803
|
+
function newConversation() {
|
|
804
|
+
if (pendingMutation.value) {
|
|
805
|
+
pendingMutation.value.resolve(false);
|
|
806
|
+
pendingMutation.value = null;
|
|
807
|
+
}
|
|
808
|
+
if (pendingToolCallResolve) {
|
|
809
|
+
pendingToolCallResolve({ cancelled: true });
|
|
810
|
+
pendingToolCallResolve = null;
|
|
811
|
+
}
|
|
812
|
+
pendingToolCall.value = null;
|
|
813
|
+
conversation.value = [];
|
|
814
|
+
activeItem.value = null;
|
|
815
|
+
isProcessing.value = false;
|
|
816
|
+
isThinking.value = false;
|
|
817
|
+
activeConversationId.value = null;
|
|
818
|
+
plan.value = null;
|
|
819
|
+
usageTurns.value = [];
|
|
820
|
+
send({ type: "new_conversation" });
|
|
821
|
+
}
|
|
822
|
+
function getTranscript() {
|
|
823
|
+
send({ type: "get_transcript" });
|
|
824
|
+
}
|
|
825
|
+
function onToolComponentDone(result) {
|
|
826
|
+
if (pendingToolCallResolve) {
|
|
827
|
+
pendingToolCallResolve(result);
|
|
828
|
+
pendingToolCallResolve = null;
|
|
829
|
+
}
|
|
830
|
+
pendingToolCall.value = null;
|
|
831
|
+
}
|
|
832
|
+
return {
|
|
833
|
+
// Connection state
|
|
834
|
+
isConnected: readonly(isConnected),
|
|
835
|
+
isReady: readonly(isReady),
|
|
836
|
+
hasBeenReady: readonly(hasBeenReady),
|
|
837
|
+
connect,
|
|
838
|
+
disconnect,
|
|
839
|
+
// Conversation state
|
|
840
|
+
conversation,
|
|
841
|
+
activeItem,
|
|
842
|
+
isProcessing,
|
|
843
|
+
isThinking,
|
|
844
|
+
// Mutation/tool approval state
|
|
845
|
+
autoApprove,
|
|
846
|
+
pendingMutation,
|
|
847
|
+
pendingToolCall,
|
|
848
|
+
// Plan state
|
|
849
|
+
plan,
|
|
850
|
+
approvePlan,
|
|
851
|
+
rejectPlan,
|
|
852
|
+
// Token usage
|
|
853
|
+
usageTurns,
|
|
854
|
+
// Actions
|
|
855
|
+
sendPrompt,
|
|
856
|
+
retry,
|
|
857
|
+
approve,
|
|
858
|
+
reject,
|
|
859
|
+
setAutoApprove,
|
|
860
|
+
cancel,
|
|
861
|
+
newConversation,
|
|
862
|
+
getTranscript,
|
|
863
|
+
onToolComponentDone,
|
|
864
|
+
// Transcript dialog state
|
|
865
|
+
transcriptContent,
|
|
866
|
+
showTranscript,
|
|
867
|
+
// Conversation list
|
|
868
|
+
conversationList,
|
|
869
|
+
showConversationList,
|
|
870
|
+
activeConversationId: readonly(activeConversationId),
|
|
871
|
+
switchConversation,
|
|
872
|
+
deleteConversation,
|
|
873
|
+
refreshConversationList
|
|
874
|
+
};
|
|
875
|
+
}
|