@blokkli/editor 2.0.0-alpha.32 → 2.0.0-alpha.34
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 +5 -27
- package/dist/module.json +1 -1
- package/dist/module.mjs +430 -10823
- 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 +8 -2
- package/package.json +29 -7
|
@@ -0,0 +1,734 @@
|
|
|
1
|
+
import { buildSystemPrompt, buildSystemPromptText } from "./agentPrompt.js";
|
|
2
|
+
import { provider, models } from "#blokkli-build/agent-server";
|
|
3
|
+
import {
|
|
4
|
+
send,
|
|
5
|
+
KEEP_RECENT_TURNS,
|
|
6
|
+
resolveSkills,
|
|
7
|
+
transformText,
|
|
8
|
+
classifyError,
|
|
9
|
+
pruneMessages,
|
|
10
|
+
pruneForPersistence,
|
|
11
|
+
computeStateHash,
|
|
12
|
+
verifyStateHash,
|
|
13
|
+
validateMessages
|
|
14
|
+
} from "./helpers.js";
|
|
15
|
+
import { buildDefinition } from "./server-tools/index.js";
|
|
16
|
+
import loadSkillTool from "./server-tools/load_skill/index.js";
|
|
17
|
+
import loadToolsTool from "./server-tools/load_tools/index.js";
|
|
18
|
+
import createPlanTool from "./server-tools/create_plan/index.js";
|
|
19
|
+
import completePlanStepTool from "./server-tools/complete_plan_step/index.js";
|
|
20
|
+
const serverTools = [
|
|
21
|
+
loadSkillTool,
|
|
22
|
+
loadToolsTool,
|
|
23
|
+
createPlanTool,
|
|
24
|
+
completePlanStepTool
|
|
25
|
+
];
|
|
26
|
+
export class Session {
|
|
27
|
+
messages = [];
|
|
28
|
+
pendingToolCalls = /* @__PURE__ */ new Map();
|
|
29
|
+
abortController = null;
|
|
30
|
+
isProcessing = false;
|
|
31
|
+
/** Eager tools sent to the LLM on every turn */
|
|
32
|
+
tools = [];
|
|
33
|
+
/** Lazy tools held back until activated via load_tools */
|
|
34
|
+
lazyTools = [];
|
|
35
|
+
/** Names of lazy tools that have been activated via load_tools */
|
|
36
|
+
activatedLazyTools = /* @__PURE__ */ new Set();
|
|
37
|
+
/** Names of skills that have been loaded via load_skill */
|
|
38
|
+
loadedSkills = /* @__PURE__ */ new Set();
|
|
39
|
+
/** Page context received from client on init */
|
|
40
|
+
pageContext;
|
|
41
|
+
/** Current plan (null when no plan is active) */
|
|
42
|
+
plan = null;
|
|
43
|
+
/** Pending plan approval promise resolver */
|
|
44
|
+
pendingPlanApproval = null;
|
|
45
|
+
/** Last tools payload sent to the provider (for transcript debugging) */
|
|
46
|
+
lastProviderTools = null;
|
|
47
|
+
// --------------------------------------------------------------------------
|
|
48
|
+
// Public methods
|
|
49
|
+
// --------------------------------------------------------------------------
|
|
50
|
+
init(tools, pageContext) {
|
|
51
|
+
this.tools = tools.filter((t) => !t.lazy);
|
|
52
|
+
this.lazyTools = tools.filter((t) => !!t.lazy);
|
|
53
|
+
this.activatedLazyTools = /* @__PURE__ */ new Set();
|
|
54
|
+
this.loadedSkills = /* @__PURE__ */ new Set();
|
|
55
|
+
this.pageContext = pageContext;
|
|
56
|
+
}
|
|
57
|
+
start(peer, prompt, apiKey, authSecret, selectedUuids) {
|
|
58
|
+
if (this.isProcessing) {
|
|
59
|
+
send(peer, {
|
|
60
|
+
type: "error",
|
|
61
|
+
errorType: "bad_request",
|
|
62
|
+
message: "Agent is already processing a request"
|
|
63
|
+
});
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
this.runAgentLoop(peer, prompt, apiKey, authSecret, selectedUuids);
|
|
67
|
+
}
|
|
68
|
+
resolveToolResult(callId, result) {
|
|
69
|
+
const pending = this.pendingToolCalls.get(callId);
|
|
70
|
+
if (pending) {
|
|
71
|
+
pending.resolve(result);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
cancel(peer) {
|
|
75
|
+
this.abortController?.abort();
|
|
76
|
+
for (const pending of this.pendingToolCalls.values()) {
|
|
77
|
+
pending.reject(new Error("Cancelled"));
|
|
78
|
+
}
|
|
79
|
+
this.pendingToolCalls.clear();
|
|
80
|
+
if (this.pendingPlanApproval) {
|
|
81
|
+
this.pendingPlanApproval.resolve(false);
|
|
82
|
+
this.pendingPlanApproval = null;
|
|
83
|
+
}
|
|
84
|
+
send(peer, { type: "done" });
|
|
85
|
+
}
|
|
86
|
+
acceptChanges(peer, authSecret) {
|
|
87
|
+
this.safePushUserMessage(`[System: Changes accepted and applied.]`);
|
|
88
|
+
send(peer, { type: "done", message: "Changes accepted" });
|
|
89
|
+
this.sendConversationState(peer, authSecret);
|
|
90
|
+
}
|
|
91
|
+
rejectChanges(peer, authSecret) {
|
|
92
|
+
this.safePushUserMessage(
|
|
93
|
+
`[System: Changes rejected. All pending changes have been reverted. The page is back to its previous state.]`
|
|
94
|
+
);
|
|
95
|
+
send(peer, { type: "done", message: "Changes rejected" });
|
|
96
|
+
this.sendConversationState(peer, authSecret);
|
|
97
|
+
}
|
|
98
|
+
approvePlan() {
|
|
99
|
+
if (this.pendingPlanApproval) {
|
|
100
|
+
this.pendingPlanApproval.resolve(true);
|
|
101
|
+
this.pendingPlanApproval = null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
rejectPlan() {
|
|
105
|
+
if (this.pendingPlanApproval) {
|
|
106
|
+
this.pendingPlanApproval.resolve(false);
|
|
107
|
+
this.pendingPlanApproval = null;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
getTranscript(peer) {
|
|
111
|
+
send(peer, {
|
|
112
|
+
type: "transcript",
|
|
113
|
+
content: this.buildTranscript()
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
newConversation(peer, authSecret) {
|
|
117
|
+
this.abortController?.abort();
|
|
118
|
+
this.messages = [];
|
|
119
|
+
this.activatedLazyTools.clear();
|
|
120
|
+
this.loadedSkills.clear();
|
|
121
|
+
this.plan = null;
|
|
122
|
+
if (this.pendingPlanApproval) {
|
|
123
|
+
this.pendingPlanApproval.resolve(false);
|
|
124
|
+
this.pendingPlanApproval = null;
|
|
125
|
+
}
|
|
126
|
+
send(peer, { type: "done" });
|
|
127
|
+
this.sendConversationState(peer, authSecret);
|
|
128
|
+
}
|
|
129
|
+
cleanup() {
|
|
130
|
+
this.abortController?.abort();
|
|
131
|
+
for (const pending of this.pendingToolCalls.values()) {
|
|
132
|
+
pending.reject(new Error("Session closed"));
|
|
133
|
+
}
|
|
134
|
+
this.pendingToolCalls.clear();
|
|
135
|
+
if (this.pendingPlanApproval) {
|
|
136
|
+
this.pendingPlanApproval.resolve(false);
|
|
137
|
+
this.pendingPlanApproval = null;
|
|
138
|
+
}
|
|
139
|
+
this.plan = null;
|
|
140
|
+
this.messages = [];
|
|
141
|
+
this.tools = [];
|
|
142
|
+
this.lazyTools = [];
|
|
143
|
+
this.activatedLazyTools.clear();
|
|
144
|
+
this.loadedSkills.clear();
|
|
145
|
+
this.pageContext = void 0;
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Build a persistence snapshot and send it to the client.
|
|
149
|
+
*/
|
|
150
|
+
sendConversationState(peer, authSecret) {
|
|
151
|
+
const state = this.getConversationStateForPersistence(authSecret);
|
|
152
|
+
send(peer, { type: "conversation_state", state });
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
* Create an aggressively pruned snapshot of the current conversation
|
|
156
|
+
* for client-side persistence.
|
|
157
|
+
*/
|
|
158
|
+
getConversationStateForPersistence(authSecret) {
|
|
159
|
+
const prunedMessages = pruneForPersistence(this.messages);
|
|
160
|
+
const activatedLazyTools = Array.from(this.activatedLazyTools);
|
|
161
|
+
const hash = computeStateHash(
|
|
162
|
+
prunedMessages,
|
|
163
|
+
activatedLazyTools,
|
|
164
|
+
authSecret
|
|
165
|
+
);
|
|
166
|
+
return {
|
|
167
|
+
messages: prunedMessages,
|
|
168
|
+
activatedLazyTools,
|
|
169
|
+
hash
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Restore conversation state from a client-provided snapshot.
|
|
174
|
+
* Verifies HMAC integrity before loading.
|
|
175
|
+
*/
|
|
176
|
+
restoreConversation(state, authSecret) {
|
|
177
|
+
if (!verifyStateHash(state, authSecret)) {
|
|
178
|
+
return { success: false, reason: "Invalid state hash" };
|
|
179
|
+
}
|
|
180
|
+
const issues = validateMessages(state.messages);
|
|
181
|
+
if (issues.length > 0) {
|
|
182
|
+
return { success: false, reason: "Invalid message structure" };
|
|
183
|
+
}
|
|
184
|
+
this.messages = state.messages;
|
|
185
|
+
const validLazyToolNames = new Set(this.lazyTools.map((t) => t.name));
|
|
186
|
+
this.activatedLazyTools = new Set(
|
|
187
|
+
state.activatedLazyTools.filter((name) => validLazyToolNames.has(name))
|
|
188
|
+
);
|
|
189
|
+
this.plan = null;
|
|
190
|
+
return { success: true };
|
|
191
|
+
}
|
|
192
|
+
// --------------------------------------------------------------------------
|
|
193
|
+
// Private methods
|
|
194
|
+
// --------------------------------------------------------------------------
|
|
195
|
+
/**
|
|
196
|
+
* Convert the server plan to a client-facing plan (strips descriptions).
|
|
197
|
+
*/
|
|
198
|
+
toClientPlan() {
|
|
199
|
+
if (!this.plan) return null;
|
|
200
|
+
return {
|
|
201
|
+
title: this.plan.title,
|
|
202
|
+
steps: this.plan.steps.map(
|
|
203
|
+
(s) => ({
|
|
204
|
+
label: s.label,
|
|
205
|
+
status: s.status
|
|
206
|
+
})
|
|
207
|
+
)
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
/**
|
|
211
|
+
* Build an ActivePlanContext from the current plan state,
|
|
212
|
+
* or undefined if no plan step is in progress.
|
|
213
|
+
*/
|
|
214
|
+
getActivePlanContext() {
|
|
215
|
+
const currentStep = this.plan?.steps.find((s) => s.status === "in_progress");
|
|
216
|
+
if (!this.plan || !currentStep) return void 0;
|
|
217
|
+
return {
|
|
218
|
+
title: this.plan.title,
|
|
219
|
+
totalSteps: this.plan.steps.length,
|
|
220
|
+
completedSteps: this.plan.steps.filter((s) => s.status === "completed").length,
|
|
221
|
+
currentStep: {
|
|
222
|
+
label: currentStep.label,
|
|
223
|
+
description: currentStep.description
|
|
224
|
+
},
|
|
225
|
+
remainingSteps: this.plan.steps.filter((s) => s.status === "pending").map((s) => s.label)
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Wait for the user to approve or reject the plan.
|
|
230
|
+
*/
|
|
231
|
+
waitForPlanApproval() {
|
|
232
|
+
return new Promise((resolve) => {
|
|
233
|
+
this.pendingPlanApproval = { resolve };
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
async runAgentLoop(peer, prompt, apiKey, authSecret, selectedUuids) {
|
|
237
|
+
if (this.tools.length === 0) {
|
|
238
|
+
send(peer, {
|
|
239
|
+
type: "error",
|
|
240
|
+
errorType: "bad_request",
|
|
241
|
+
message: "No tools available. Client must send init message with tools first."
|
|
242
|
+
});
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
if (!this.pageContext) {
|
|
246
|
+
send(peer, {
|
|
247
|
+
type: "error",
|
|
248
|
+
errorType: "bad_request",
|
|
249
|
+
message: "No page context available. Client must send init message with pageContext first."
|
|
250
|
+
});
|
|
251
|
+
return;
|
|
252
|
+
}
|
|
253
|
+
const resolvedSkills = resolveSkills(this.pageContext);
|
|
254
|
+
const lazyToolSummaries = this.lazyTools.map((t) => ({
|
|
255
|
+
name: t.name,
|
|
256
|
+
description: t.description
|
|
257
|
+
}));
|
|
258
|
+
const userParts = [];
|
|
259
|
+
if (selectedUuids?.length) {
|
|
260
|
+
userParts.push(
|
|
261
|
+
`[User has selected the following paragraphs: ${selectedUuids.join(", ")}]`
|
|
262
|
+
);
|
|
263
|
+
}
|
|
264
|
+
userParts.push(prompt);
|
|
265
|
+
const userMessage = {
|
|
266
|
+
role: "user",
|
|
267
|
+
content: userParts.join("\n\n")
|
|
268
|
+
};
|
|
269
|
+
this.messages.push(userMessage);
|
|
270
|
+
this.abortController = new AbortController();
|
|
271
|
+
this.isProcessing = true;
|
|
272
|
+
let toolCallCounter = 0;
|
|
273
|
+
let planRetryCount = 0;
|
|
274
|
+
let streamRetryCount = 0;
|
|
275
|
+
const MAX_STREAM_RETRIES = 1;
|
|
276
|
+
try {
|
|
277
|
+
while (true) {
|
|
278
|
+
if (this.abortController.signal.aborted) {
|
|
279
|
+
break;
|
|
280
|
+
}
|
|
281
|
+
send(peer, { type: "thinking" });
|
|
282
|
+
const assistantContent = [];
|
|
283
|
+
const toolResults = [];
|
|
284
|
+
const extraBlocks = [];
|
|
285
|
+
let messagesCommittedByPlanTool = false;
|
|
286
|
+
let currentToolUse = null;
|
|
287
|
+
let currentTextContent = "";
|
|
288
|
+
let inTextBlock = false;
|
|
289
|
+
const activatedTools = this.lazyTools.filter(
|
|
290
|
+
(t) => this.activatedLazyTools.has(t.name)
|
|
291
|
+
);
|
|
292
|
+
const unloadedLazyTools = this.lazyTools.filter(
|
|
293
|
+
(t) => !this.activatedLazyTools.has(t.name)
|
|
294
|
+
);
|
|
295
|
+
const defCtx = {
|
|
296
|
+
resolvedSkills,
|
|
297
|
+
plan: this.plan,
|
|
298
|
+
unloadedLazyTools
|
|
299
|
+
};
|
|
300
|
+
const serverToolDefs = serverTools.map((t) => buildDefinition(t, defCtx)).filter((d) => d !== null);
|
|
301
|
+
const allTools = [...serverToolDefs, ...this.tools, ...activatedTools];
|
|
302
|
+
const systemPrompt = buildSystemPrompt(
|
|
303
|
+
this.pageContext,
|
|
304
|
+
resolvedSkills,
|
|
305
|
+
lazyToolSummaries,
|
|
306
|
+
this.getActivePlanContext(),
|
|
307
|
+
this.loadedSkills
|
|
308
|
+
);
|
|
309
|
+
const stream = provider.createStream(
|
|
310
|
+
{
|
|
311
|
+
apiKey,
|
|
312
|
+
model: (models.find((m) => m.isDefault) || models[0]).name
|
|
313
|
+
},
|
|
314
|
+
{
|
|
315
|
+
systemPrompt,
|
|
316
|
+
messages: this.messages,
|
|
317
|
+
tools: allTools,
|
|
318
|
+
maxTokens: 4096,
|
|
319
|
+
signal: this.abortController.signal
|
|
320
|
+
}
|
|
321
|
+
);
|
|
322
|
+
try {
|
|
323
|
+
for await (const event of stream) {
|
|
324
|
+
if (this.abortController?.signal.aborted) {
|
|
325
|
+
break;
|
|
326
|
+
}
|
|
327
|
+
switch (event.type) {
|
|
328
|
+
case "debug_request":
|
|
329
|
+
this.lastProviderTools = event.tools;
|
|
330
|
+
break;
|
|
331
|
+
case "text_start":
|
|
332
|
+
inTextBlock = true;
|
|
333
|
+
currentTextContent = "";
|
|
334
|
+
break;
|
|
335
|
+
case "text_delta":
|
|
336
|
+
if (inTextBlock) {
|
|
337
|
+
const transformed = transformText(event.text);
|
|
338
|
+
currentTextContent += transformed;
|
|
339
|
+
send(peer, { type: "text_delta", content: transformed });
|
|
340
|
+
}
|
|
341
|
+
break;
|
|
342
|
+
case "text_end":
|
|
343
|
+
if (inTextBlock && currentTextContent) {
|
|
344
|
+
assistantContent.push({
|
|
345
|
+
type: "text",
|
|
346
|
+
text: currentTextContent
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
currentTextContent = "";
|
|
350
|
+
inTextBlock = false;
|
|
351
|
+
break;
|
|
352
|
+
case "tool_use_start":
|
|
353
|
+
currentToolUse = {
|
|
354
|
+
id: event.id,
|
|
355
|
+
name: event.name,
|
|
356
|
+
inputJson: ""
|
|
357
|
+
};
|
|
358
|
+
break;
|
|
359
|
+
case "tool_use_delta":
|
|
360
|
+
if (currentToolUse) {
|
|
361
|
+
currentToolUse.inputJson += event.partial_json;
|
|
362
|
+
}
|
|
363
|
+
break;
|
|
364
|
+
case "tool_use_end":
|
|
365
|
+
if (currentToolUse) {
|
|
366
|
+
let input;
|
|
367
|
+
try {
|
|
368
|
+
input = JSON.parse(currentToolUse.inputJson || "{}");
|
|
369
|
+
} catch {
|
|
370
|
+
input = {};
|
|
371
|
+
assistantContent.push({
|
|
372
|
+
type: "tool_use",
|
|
373
|
+
id: currentToolUse.id,
|
|
374
|
+
name: currentToolUse.name,
|
|
375
|
+
input
|
|
376
|
+
});
|
|
377
|
+
toolResults.push({
|
|
378
|
+
type: "tool_result",
|
|
379
|
+
tool_use_id: currentToolUse.id,
|
|
380
|
+
content: JSON.stringify({
|
|
381
|
+
error: "Your tool call produced malformed JSON input. Please try again."
|
|
382
|
+
}),
|
|
383
|
+
is_error: true
|
|
384
|
+
});
|
|
385
|
+
currentToolUse = null;
|
|
386
|
+
break;
|
|
387
|
+
}
|
|
388
|
+
const callId = `tc_${toolCallCounter++}`;
|
|
389
|
+
assistantContent.push({
|
|
390
|
+
type: "tool_use",
|
|
391
|
+
id: currentToolUse.id,
|
|
392
|
+
name: currentToolUse.name,
|
|
393
|
+
input
|
|
394
|
+
});
|
|
395
|
+
const matchedServerTool = serverTools.find(
|
|
396
|
+
(t) => t.name === currentToolUse.name
|
|
397
|
+
);
|
|
398
|
+
if (matchedServerTool) {
|
|
399
|
+
if (matchedServerTool.isAvailable && !matchedServerTool.isAvailable(defCtx)) {
|
|
400
|
+
toolResults.push({
|
|
401
|
+
type: "tool_result",
|
|
402
|
+
tool_use_id: currentToolUse.id,
|
|
403
|
+
content: JSON.stringify({
|
|
404
|
+
error: "This tool is not available right now."
|
|
405
|
+
}),
|
|
406
|
+
is_error: true
|
|
407
|
+
});
|
|
408
|
+
currentToolUse = null;
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
const handlerCtx = {
|
|
412
|
+
toolUseId: currentToolUse.id,
|
|
413
|
+
send: (msg) => send(peer, msg),
|
|
414
|
+
resolvedSkills,
|
|
415
|
+
lazyTools: this.lazyTools,
|
|
416
|
+
activatedLazyTools: this.activatedLazyTools,
|
|
417
|
+
loadedSkills: this.loadedSkills,
|
|
418
|
+
plan: this.plan,
|
|
419
|
+
setPlan: (p) => {
|
|
420
|
+
this.plan = p;
|
|
421
|
+
},
|
|
422
|
+
toClientPlan: () => this.toClientPlan(),
|
|
423
|
+
waitForPlanApproval: () => this.waitForPlanApproval(),
|
|
424
|
+
assistantContent,
|
|
425
|
+
commitMessagesEarly: (toolResult) => {
|
|
426
|
+
if (assistantContent.length) {
|
|
427
|
+
this.messages.push({
|
|
428
|
+
role: "assistant",
|
|
429
|
+
content: [...assistantContent]
|
|
430
|
+
});
|
|
431
|
+
assistantContent.length = 0;
|
|
432
|
+
}
|
|
433
|
+
this.messages.push({
|
|
434
|
+
role: "user",
|
|
435
|
+
content: [toolResult]
|
|
436
|
+
});
|
|
437
|
+
},
|
|
438
|
+
updateLastToolResult: (toolUseId, content) => {
|
|
439
|
+
const lastMsg = this.messages[this.messages.length - 1];
|
|
440
|
+
if (lastMsg.role === "user" && Array.isArray(lastMsg.content)) {
|
|
441
|
+
const resultBlock = lastMsg.content.find(
|
|
442
|
+
(b) => b.type === "tool_result" && b.tool_use_id === toolUseId
|
|
443
|
+
);
|
|
444
|
+
if (resultBlock && resultBlock.type === "tool_result") {
|
|
445
|
+
resultBlock.content = content;
|
|
446
|
+
}
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
try {
|
|
451
|
+
const parsed = matchedServerTool.inputSchema(defCtx).parse(input);
|
|
452
|
+
const result = await matchedServerTool.handle(
|
|
453
|
+
handlerCtx,
|
|
454
|
+
parsed
|
|
455
|
+
);
|
|
456
|
+
toolResults.push(...result.toolResults);
|
|
457
|
+
if (result.extraBlocks) {
|
|
458
|
+
extraBlocks.push(...result.extraBlocks);
|
|
459
|
+
}
|
|
460
|
+
if (result.messagesCommitted) {
|
|
461
|
+
messagesCommittedByPlanTool = true;
|
|
462
|
+
}
|
|
463
|
+
} catch (e) {
|
|
464
|
+
toolResults.push({
|
|
465
|
+
type: "tool_result",
|
|
466
|
+
tool_use_id: currentToolUse.id,
|
|
467
|
+
content: JSON.stringify({
|
|
468
|
+
error: `Invalid input: ${e.message}`
|
|
469
|
+
}),
|
|
470
|
+
is_error: true
|
|
471
|
+
});
|
|
472
|
+
}
|
|
473
|
+
currentToolUse = null;
|
|
474
|
+
break;
|
|
475
|
+
}
|
|
476
|
+
send(peer, {
|
|
477
|
+
type: "tool_call",
|
|
478
|
+
callId,
|
|
479
|
+
tool: currentToolUse.name,
|
|
480
|
+
params: input
|
|
481
|
+
});
|
|
482
|
+
try {
|
|
483
|
+
const clientResult = await this.waitForToolResult(callId);
|
|
484
|
+
if (clientResult.error) {
|
|
485
|
+
toolResults.push({
|
|
486
|
+
type: "tool_result",
|
|
487
|
+
tool_use_id: currentToolUse.id,
|
|
488
|
+
content: JSON.stringify({
|
|
489
|
+
error: clientResult.error
|
|
490
|
+
}),
|
|
491
|
+
is_error: true
|
|
492
|
+
});
|
|
493
|
+
} else {
|
|
494
|
+
let resultForLLM = clientResult.result;
|
|
495
|
+
if (typeof resultForLLM === "object" && resultForLLM !== null && "agentMessage" in resultForLLM) {
|
|
496
|
+
const { agentMessage, ...rest } = resultForLLM;
|
|
497
|
+
resultForLLM = { ...rest, label: agentMessage };
|
|
498
|
+
}
|
|
499
|
+
toolResults.push({
|
|
500
|
+
type: "tool_result",
|
|
501
|
+
tool_use_id: currentToolUse.id,
|
|
502
|
+
content: JSON.stringify(resultForLLM)
|
|
503
|
+
});
|
|
504
|
+
}
|
|
505
|
+
} catch (error) {
|
|
506
|
+
toolResults.push({
|
|
507
|
+
type: "tool_result",
|
|
508
|
+
tool_use_id: currentToolUse.id,
|
|
509
|
+
content: JSON.stringify({
|
|
510
|
+
error: error.message
|
|
511
|
+
}),
|
|
512
|
+
is_error: true
|
|
513
|
+
});
|
|
514
|
+
}
|
|
515
|
+
currentToolUse = null;
|
|
516
|
+
}
|
|
517
|
+
break;
|
|
518
|
+
case "message_end":
|
|
519
|
+
if (event.inputTokens !== void 0 && event.outputTokens !== void 0) {
|
|
520
|
+
const defaultModel = models.find((m) => m.isDefault) || models[0];
|
|
521
|
+
send(peer, {
|
|
522
|
+
type: "usage",
|
|
523
|
+
usage: {
|
|
524
|
+
inputTokens: event.inputTokens,
|
|
525
|
+
outputTokens: event.outputTokens,
|
|
526
|
+
cacheCreationInputTokens: event.cacheCreationInputTokens ?? 0,
|
|
527
|
+
cacheReadInputTokens: event.cacheReadInputTokens ?? 0,
|
|
528
|
+
pricing: defaultModel?.pricing ?? null
|
|
529
|
+
}
|
|
530
|
+
});
|
|
531
|
+
}
|
|
532
|
+
break;
|
|
533
|
+
case "error":
|
|
534
|
+
throw event.error;
|
|
535
|
+
}
|
|
536
|
+
}
|
|
537
|
+
} catch (streamError) {
|
|
538
|
+
const isApiError = typeof streamError.status === "number";
|
|
539
|
+
const isRetryable = !isApiError && toolResults.length === 0;
|
|
540
|
+
if (isRetryable && streamRetryCount < MAX_STREAM_RETRIES) {
|
|
541
|
+
streamRetryCount++;
|
|
542
|
+
console.warn(
|
|
543
|
+
`[blokkli agent] Transient stream error, retrying (attempt ${streamRetryCount}/${MAX_STREAM_RETRIES}):`,
|
|
544
|
+
streamError
|
|
545
|
+
);
|
|
546
|
+
continue;
|
|
547
|
+
}
|
|
548
|
+
if (isRetryable && this.messages[this.messages.length - 1] === userMessage) {
|
|
549
|
+
this.messages.pop();
|
|
550
|
+
console.error(
|
|
551
|
+
"[blokkli agent] Transient stream error, retries exhausted:",
|
|
552
|
+
streamError
|
|
553
|
+
);
|
|
554
|
+
const classified = classifyError(streamError);
|
|
555
|
+
send(peer, { type: "error", ...classified, retryable: true });
|
|
556
|
+
break;
|
|
557
|
+
}
|
|
558
|
+
throw streamError;
|
|
559
|
+
}
|
|
560
|
+
if (this.abortController?.signal.aborted) {
|
|
561
|
+
break;
|
|
562
|
+
}
|
|
563
|
+
if (messagesCommittedByPlanTool) {
|
|
564
|
+
continue;
|
|
565
|
+
}
|
|
566
|
+
if (assistantContent.length) {
|
|
567
|
+
this.messages.push({
|
|
568
|
+
role: "assistant",
|
|
569
|
+
content: assistantContent
|
|
570
|
+
});
|
|
571
|
+
}
|
|
572
|
+
if (toolResults.length) {
|
|
573
|
+
this.messages.push({
|
|
574
|
+
role: "user",
|
|
575
|
+
content: [...toolResults, ...extraBlocks]
|
|
576
|
+
});
|
|
577
|
+
planRetryCount = 0;
|
|
578
|
+
streamRetryCount = 0;
|
|
579
|
+
}
|
|
580
|
+
if (toolResults.length === 0) {
|
|
581
|
+
const hasActivePlan = this.plan && this.plan.steps.some((s) => s.status === "in_progress");
|
|
582
|
+
if (hasActivePlan && planRetryCount < 2) {
|
|
583
|
+
planRetryCount++;
|
|
584
|
+
this.safePushUserMessage("[Continue with the plan.]");
|
|
585
|
+
continue;
|
|
586
|
+
}
|
|
587
|
+
const finalMessage = assistantContent.filter(
|
|
588
|
+
(c) => c.type === "text"
|
|
589
|
+
).map((t) => t.text).join("\n").trim();
|
|
590
|
+
send(peer, { type: "done", message: finalMessage || void 0 });
|
|
591
|
+
break;
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
} catch (error) {
|
|
595
|
+
if (error.name !== "AbortError" && !this.abortController?.signal.aborted) {
|
|
596
|
+
console.error("Agent loop error:", error);
|
|
597
|
+
const classified = classifyError(error);
|
|
598
|
+
send(peer, { type: "error", ...classified });
|
|
599
|
+
}
|
|
600
|
+
} finally {
|
|
601
|
+
this.isProcessing = false;
|
|
602
|
+
this.abortController = null;
|
|
603
|
+
pruneMessages(
|
|
604
|
+
this.messages,
|
|
605
|
+
KEEP_RECENT_TURNS,
|
|
606
|
+
this.buildToolMetadataMap()
|
|
607
|
+
);
|
|
608
|
+
if (this.loadedSkills.size > 0) {
|
|
609
|
+
this.reconcileLoadedSkills();
|
|
610
|
+
}
|
|
611
|
+
this.sendConversationState(peer, authSecret);
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
waitForToolResult(callId) {
|
|
615
|
+
return new Promise((resolve, reject) => {
|
|
616
|
+
this.pendingToolCalls.set(callId, {
|
|
617
|
+
resolve: (result) => {
|
|
618
|
+
this.pendingToolCalls.delete(callId);
|
|
619
|
+
resolve(result);
|
|
620
|
+
},
|
|
621
|
+
reject: (error) => {
|
|
622
|
+
this.pendingToolCalls.delete(callId);
|
|
623
|
+
reject(error);
|
|
624
|
+
}
|
|
625
|
+
});
|
|
626
|
+
});
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Bug 3 fix: safely push a user message, merging with the last message
|
|
630
|
+
* if it's also a user message to avoid consecutive same-role messages.
|
|
631
|
+
*/
|
|
632
|
+
safePushUserMessage(text) {
|
|
633
|
+
const lastMessage = this.messages[this.messages.length - 1];
|
|
634
|
+
if (lastMessage && lastMessage.role === "user") {
|
|
635
|
+
if (typeof lastMessage.content === "string") {
|
|
636
|
+
lastMessage.content = lastMessage.content + "\n" + text;
|
|
637
|
+
} else {
|
|
638
|
+
lastMessage.content.push({ type: "text", text });
|
|
639
|
+
}
|
|
640
|
+
} else {
|
|
641
|
+
this.messages.push({ role: "user", content: text });
|
|
642
|
+
}
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Remove skills from loadedSkills whose text content has been pruned
|
|
646
|
+
* from the conversation messages.
|
|
647
|
+
*/
|
|
648
|
+
reconcileLoadedSkills() {
|
|
649
|
+
const presentSkills = /* @__PURE__ */ new Set();
|
|
650
|
+
for (const msg of this.messages) {
|
|
651
|
+
if (msg.role !== "user" || !Array.isArray(msg.content)) continue;
|
|
652
|
+
for (const block of msg.content) {
|
|
653
|
+
if (block.type === "skill") {
|
|
654
|
+
presentSkills.add(block.name);
|
|
655
|
+
}
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
for (const name of this.loadedSkills) {
|
|
659
|
+
if (!presentSkills.has(name)) {
|
|
660
|
+
this.loadedSkills.delete(name);
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
/**
|
|
665
|
+
* Build a map of tool name to pruning metadata from all known tools.
|
|
666
|
+
*/
|
|
667
|
+
buildToolMetadataMap() {
|
|
668
|
+
const map = /* @__PURE__ */ new Map();
|
|
669
|
+
for (const tool of [...this.tools, ...this.lazyTools]) {
|
|
670
|
+
if (tool.volatile) {
|
|
671
|
+
map.set(tool.name, { volatile: true });
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
return map;
|
|
675
|
+
}
|
|
676
|
+
buildTranscript() {
|
|
677
|
+
const lines = [];
|
|
678
|
+
let systemPrompt = "(No page context available)";
|
|
679
|
+
if (this.pageContext) {
|
|
680
|
+
const resolvedSkills = resolveSkills(this.pageContext);
|
|
681
|
+
const lazyToolSummaries = this.lazyTools.map((t) => ({
|
|
682
|
+
name: t.name,
|
|
683
|
+
description: t.description
|
|
684
|
+
}));
|
|
685
|
+
systemPrompt = buildSystemPromptText(
|
|
686
|
+
this.pageContext,
|
|
687
|
+
resolvedSkills,
|
|
688
|
+
lazyToolSummaries,
|
|
689
|
+
this.getActivePlanContext()
|
|
690
|
+
);
|
|
691
|
+
}
|
|
692
|
+
lines.push("=".repeat(80));
|
|
693
|
+
lines.push("SYSTEM PROMPT");
|
|
694
|
+
lines.push("=".repeat(80));
|
|
695
|
+
lines.push(systemPrompt);
|
|
696
|
+
lines.push("");
|
|
697
|
+
if (this.lastProviderTools) {
|
|
698
|
+
lines.push("=".repeat(80));
|
|
699
|
+
lines.push("TOOLS (exact payload sent to provider)");
|
|
700
|
+
lines.push("=".repeat(80));
|
|
701
|
+
lines.push(JSON.stringify(this.lastProviderTools, null, 2));
|
|
702
|
+
lines.push("");
|
|
703
|
+
}
|
|
704
|
+
for (const message of this.messages) {
|
|
705
|
+
lines.push("=".repeat(80));
|
|
706
|
+
lines.push(`${message.role.toUpperCase()}`);
|
|
707
|
+
lines.push("=".repeat(80));
|
|
708
|
+
if (typeof message.content === "string") {
|
|
709
|
+
lines.push(message.content);
|
|
710
|
+
} else if (Array.isArray(message.content)) {
|
|
711
|
+
for (const block of message.content) {
|
|
712
|
+
if (block.type === "text") {
|
|
713
|
+
lines.push(block.text);
|
|
714
|
+
} else if (block.type === "skill") {
|
|
715
|
+
lines.push(`[Skill: ${block.name}]`);
|
|
716
|
+
lines.push(block.text);
|
|
717
|
+
} else if (block.type === "tool_use") {
|
|
718
|
+
lines.push(`[Tool Call: ${block.name}]`);
|
|
719
|
+
lines.push(JSON.stringify(block.input, null, 2));
|
|
720
|
+
} else if (block.type === "tool_result") {
|
|
721
|
+
lines.push(`[Tool Result: ${block.tool_use_id}]`);
|
|
722
|
+
try {
|
|
723
|
+
lines.push(JSON.stringify(JSON.parse(block.content), null, 2));
|
|
724
|
+
} catch {
|
|
725
|
+
lines.push(block.content);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
lines.push("");
|
|
731
|
+
}
|
|
732
|
+
return lines.join("\n");
|
|
733
|
+
}
|
|
734
|
+
}
|