@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,352 @@
|
|
|
1
|
+
import { createHmac, timingSafeEqual } from "node:crypto";
|
|
2
|
+
import { skills } from "#blokkli-build/agent-server";
|
|
3
|
+
export function send(peer, message) {
|
|
4
|
+
peer.send(JSON.stringify(message));
|
|
5
|
+
}
|
|
6
|
+
export const KEEP_RECENT_TURNS = 8;
|
|
7
|
+
export function resolveSkillLabel(label, language) {
|
|
8
|
+
if (typeof label === "string") return label;
|
|
9
|
+
if (language && language in label) {
|
|
10
|
+
return label[language] || label.en;
|
|
11
|
+
}
|
|
12
|
+
return label.en;
|
|
13
|
+
}
|
|
14
|
+
export function resolveSkills(context) {
|
|
15
|
+
return skills.map((skill) => {
|
|
16
|
+
const content = skill.getContents(context);
|
|
17
|
+
if (content === null) return null;
|
|
18
|
+
return {
|
|
19
|
+
name: skill.name,
|
|
20
|
+
label: resolveSkillLabel(skill.label, context.interfaceLanguage),
|
|
21
|
+
englishLabel: resolveSkillLabel(skill.label),
|
|
22
|
+
description: skill.description,
|
|
23
|
+
content
|
|
24
|
+
};
|
|
25
|
+
}).filter((s) => s !== null);
|
|
26
|
+
}
|
|
27
|
+
export function transformText(text) {
|
|
28
|
+
return text.replace(/ß/g, "ss");
|
|
29
|
+
}
|
|
30
|
+
export function classifyError(error) {
|
|
31
|
+
if (!(error instanceof Error)) {
|
|
32
|
+
return {
|
|
33
|
+
errorType: "unknown",
|
|
34
|
+
message: "An unexpected error occurred."
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
const detail = error.message || void 0;
|
|
38
|
+
const status = error.status;
|
|
39
|
+
if (status === void 0) {
|
|
40
|
+
if (error.constructor.name === "APIConnectionError") {
|
|
41
|
+
return {
|
|
42
|
+
errorType: "connection",
|
|
43
|
+
message: "Could not connect to the AI service.",
|
|
44
|
+
detail
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
return {
|
|
48
|
+
errorType: "unknown",
|
|
49
|
+
message: error.message || "An unexpected error occurred.",
|
|
50
|
+
detail
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
switch (status) {
|
|
54
|
+
case 401:
|
|
55
|
+
return {
|
|
56
|
+
errorType: "authentication",
|
|
57
|
+
message: "API authentication failed. Please check your API key.",
|
|
58
|
+
detail
|
|
59
|
+
};
|
|
60
|
+
case 400:
|
|
61
|
+
return {
|
|
62
|
+
errorType: "bad_request",
|
|
63
|
+
message: "The request to the AI service was invalid.",
|
|
64
|
+
detail
|
|
65
|
+
};
|
|
66
|
+
case 404:
|
|
67
|
+
return {
|
|
68
|
+
errorType: "not_found",
|
|
69
|
+
message: "The configured AI model was not found. Please check the configuration.",
|
|
70
|
+
detail
|
|
71
|
+
};
|
|
72
|
+
case 429:
|
|
73
|
+
return {
|
|
74
|
+
errorType: "rate_limit",
|
|
75
|
+
message: "Rate limit exceeded. Please wait a moment before trying again.",
|
|
76
|
+
detail
|
|
77
|
+
};
|
|
78
|
+
case 529:
|
|
79
|
+
case 503:
|
|
80
|
+
return {
|
|
81
|
+
errorType: "overloaded",
|
|
82
|
+
message: "The AI service is currently overloaded. Please try again in a moment.",
|
|
83
|
+
detail
|
|
84
|
+
};
|
|
85
|
+
default:
|
|
86
|
+
return {
|
|
87
|
+
errorType: "unknown",
|
|
88
|
+
message: `API error (${status}).`,
|
|
89
|
+
detail
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
export function findToolNameForResult(messages, userMsgIndex, toolUseId) {
|
|
94
|
+
for (let i = userMsgIndex - 1; i >= 0; i--) {
|
|
95
|
+
const msg = messages[i];
|
|
96
|
+
if (msg.role !== "assistant" || !Array.isArray(msg.content)) continue;
|
|
97
|
+
for (const block of msg.content) {
|
|
98
|
+
if (block.type === "tool_use" && block.id === toolUseId) {
|
|
99
|
+
return block.name;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
return void 0;
|
|
105
|
+
}
|
|
106
|
+
export function compressToolResult(content) {
|
|
107
|
+
try {
|
|
108
|
+
const parsed = JSON.parse(content);
|
|
109
|
+
if (parsed._summary) {
|
|
110
|
+
return JSON.stringify({ summary: parsed._summary });
|
|
111
|
+
}
|
|
112
|
+
if (parsed.label) {
|
|
113
|
+
return JSON.stringify({ summary: parsed.label });
|
|
114
|
+
}
|
|
115
|
+
if (parsed.error) {
|
|
116
|
+
return JSON.stringify({ error: parsed.error });
|
|
117
|
+
}
|
|
118
|
+
if (parsed.success !== void 0) {
|
|
119
|
+
return JSON.stringify({ success: parsed.success });
|
|
120
|
+
}
|
|
121
|
+
if (parsed.selected !== void 0) {
|
|
122
|
+
return JSON.stringify({ selected: parsed.selected });
|
|
123
|
+
}
|
|
124
|
+
return JSON.stringify({ summary: "completed" });
|
|
125
|
+
} catch {
|
|
126
|
+
return content.length > 100 ? content.slice(0, 100) + "..." : content;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
function compressVolatileToolResult(content) {
|
|
130
|
+
try {
|
|
131
|
+
const parsed = JSON.parse(content);
|
|
132
|
+
const summary = parsed._summary || "page state has changed since this query";
|
|
133
|
+
return JSON.stringify({ stale: true, summary });
|
|
134
|
+
} catch {
|
|
135
|
+
return JSON.stringify({
|
|
136
|
+
stale: true,
|
|
137
|
+
summary: "page state has changed since this query"
|
|
138
|
+
});
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
function hasMutationBetween(messages, afterIndex, beforeIndex, toolMetadata) {
|
|
142
|
+
for (let i = afterIndex + 1; i < beforeIndex; i++) {
|
|
143
|
+
const msg = messages[i];
|
|
144
|
+
if (msg.role !== "user" || !Array.isArray(msg.content)) continue;
|
|
145
|
+
for (const block of msg.content) {
|
|
146
|
+
if (block.type !== "tool_result") continue;
|
|
147
|
+
const toolName = findToolNameForResult(messages, i, block.tool_use_id);
|
|
148
|
+
if (!toolName) continue;
|
|
149
|
+
const meta = toolMetadata.get(toolName);
|
|
150
|
+
if (meta?.volatile) continue;
|
|
151
|
+
try {
|
|
152
|
+
const parsed = JSON.parse(block.content);
|
|
153
|
+
if (parsed.success !== void 0) return true;
|
|
154
|
+
} catch {
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return false;
|
|
159
|
+
}
|
|
160
|
+
export function pruneMessages(messages, keepRecentTurns, toolMetadata) {
|
|
161
|
+
if (messages.length === 0) {
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
const metadata = toolMetadata || /* @__PURE__ */ new Map();
|
|
165
|
+
let turnCount = 0;
|
|
166
|
+
const turnStartIndices = [];
|
|
167
|
+
for (let i = 0; i < messages.length; i++) {
|
|
168
|
+
const msg = messages[i];
|
|
169
|
+
if (msg.role === "user") {
|
|
170
|
+
const content = msg.content;
|
|
171
|
+
const containsToolResult = Array.isArray(content) && content.length > 0 && content.some(
|
|
172
|
+
(block) => typeof block === "object" && block !== null && "type" in block && block.type === "tool_result"
|
|
173
|
+
);
|
|
174
|
+
if (!containsToolResult) {
|
|
175
|
+
turnCount++;
|
|
176
|
+
turnStartIndices.push(i);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
if (turnCount <= keepRecentTurns) {
|
|
181
|
+
return;
|
|
182
|
+
}
|
|
183
|
+
const cutoffTurnIndex = turnCount - keepRecentTurns;
|
|
184
|
+
const cutoffMessageIndex = turnStartIndices[cutoffTurnIndex] ?? messages.length;
|
|
185
|
+
for (let i = 0; i < cutoffMessageIndex; i++) {
|
|
186
|
+
const msg = messages[i];
|
|
187
|
+
const content = msg.content;
|
|
188
|
+
if (!Array.isArray(content)) {
|
|
189
|
+
continue;
|
|
190
|
+
}
|
|
191
|
+
if (msg.role === "assistant") {
|
|
192
|
+
for (const block of content) {
|
|
193
|
+
if (block.type === "tool_use") {
|
|
194
|
+
block.input = { _pruned: true };
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
continue;
|
|
198
|
+
}
|
|
199
|
+
for (let j = content.length - 1; j >= 0; j--) {
|
|
200
|
+
const block = content[j];
|
|
201
|
+
if (block.type === "tool_result") {
|
|
202
|
+
const toolName = findToolNameForResult(messages, i, block.tool_use_id);
|
|
203
|
+
const meta = toolName ? metadata.get(toolName) : void 0;
|
|
204
|
+
if (meta?.volatile && hasMutationBetween(messages, i, messages.length, metadata)) {
|
|
205
|
+
block.content = compressVolatileToolResult(block.content);
|
|
206
|
+
} else {
|
|
207
|
+
block.content = compressToolResult(block.content);
|
|
208
|
+
}
|
|
209
|
+
} else if (block.type === "text" || block.type === "skill") {
|
|
210
|
+
content.splice(j, 1);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
const PERSISTENCE_KEEP_TURNS = 7;
|
|
216
|
+
export function pruneForPersistence(messages, keepTurns = PERSISTENCE_KEEP_TURNS) {
|
|
217
|
+
if (messages.length === 0) return [];
|
|
218
|
+
const cloned = JSON.parse(JSON.stringify(messages));
|
|
219
|
+
let turnCount = 0;
|
|
220
|
+
const turnStartIndices = [];
|
|
221
|
+
for (let i = 0; i < cloned.length; i++) {
|
|
222
|
+
const msg = cloned[i];
|
|
223
|
+
if (msg.role === "user") {
|
|
224
|
+
const content = msg.content;
|
|
225
|
+
const containsToolResult = Array.isArray(content) && content.length > 0 && content.some(
|
|
226
|
+
(block) => typeof block === "object" && block !== null && "type" in block && block.type === "tool_result"
|
|
227
|
+
);
|
|
228
|
+
if (!containsToolResult) {
|
|
229
|
+
turnCount++;
|
|
230
|
+
turnStartIndices.push(i);
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
let startIndex = 0;
|
|
235
|
+
if (turnCount > keepTurns) {
|
|
236
|
+
const cutoffTurnIndex = turnCount - keepTurns;
|
|
237
|
+
startIndex = turnStartIndices[cutoffTurnIndex] ?? 0;
|
|
238
|
+
}
|
|
239
|
+
const trimmed = cloned.slice(startIndex);
|
|
240
|
+
let lastTurnStart = 0;
|
|
241
|
+
for (let i = trimmed.length - 1; i >= 0; i--) {
|
|
242
|
+
const msg = trimmed[i];
|
|
243
|
+
if (msg.role === "user") {
|
|
244
|
+
const content = msg.content;
|
|
245
|
+
const containsToolResult = Array.isArray(content) && content.length > 0 && content.some(
|
|
246
|
+
(block) => typeof block === "object" && block !== null && "type" in block && block.type === "tool_result"
|
|
247
|
+
);
|
|
248
|
+
if (!containsToolResult) {
|
|
249
|
+
lastTurnStart = i;
|
|
250
|
+
break;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
for (let i = 0; i < trimmed.length; i++) {
|
|
255
|
+
const msg = trimmed[i];
|
|
256
|
+
const content = msg.content;
|
|
257
|
+
if (!Array.isArray(content)) continue;
|
|
258
|
+
if (msg.role === "assistant") {
|
|
259
|
+
if (i < lastTurnStart) {
|
|
260
|
+
for (const block of content) {
|
|
261
|
+
if (block.type === "tool_use") {
|
|
262
|
+
block.input = { _pruned: true };
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
for (let j = content.length - 1; j >= 0; j--) {
|
|
269
|
+
const block = content[j];
|
|
270
|
+
if (block.type === "tool_result") {
|
|
271
|
+
block.content = compressToolResult(block.content);
|
|
272
|
+
} else if (block.type === "text" && i < lastTurnStart) {
|
|
273
|
+
content.splice(j, 1);
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
return trimmed;
|
|
278
|
+
}
|
|
279
|
+
export function computeStateHash(messages, activatedLazyTools, secret) {
|
|
280
|
+
const payload = JSON.stringify(messages) + "|" + JSON.stringify(activatedLazyTools);
|
|
281
|
+
return createHmac("sha256", secret).update(payload).digest("hex");
|
|
282
|
+
}
|
|
283
|
+
export function verifyStateHash(snapshot, secret) {
|
|
284
|
+
const expected = computeStateHash(
|
|
285
|
+
snapshot.messages,
|
|
286
|
+
snapshot.activatedLazyTools,
|
|
287
|
+
secret
|
|
288
|
+
);
|
|
289
|
+
if (expected.length !== snapshot.hash.length) return false;
|
|
290
|
+
try {
|
|
291
|
+
return timingSafeEqual(
|
|
292
|
+
Buffer.from(expected, "hex"),
|
|
293
|
+
Buffer.from(snapshot.hash, "hex")
|
|
294
|
+
);
|
|
295
|
+
} catch {
|
|
296
|
+
return false;
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
export function validateMessages(messages) {
|
|
300
|
+
const issues = [];
|
|
301
|
+
for (let i = 0; i < messages.length; i++) {
|
|
302
|
+
const msg = messages[i];
|
|
303
|
+
if (i > 0 && messages[i - 1].role === msg.role) {
|
|
304
|
+
issues.push(
|
|
305
|
+
`Consecutive ${msg.role} messages at indices ${i - 1} and ${i}`
|
|
306
|
+
);
|
|
307
|
+
}
|
|
308
|
+
if (Array.isArray(msg.content) && msg.content.length === 0) {
|
|
309
|
+
issues.push(`Empty content array in ${msg.role} message at index ${i}`);
|
|
310
|
+
}
|
|
311
|
+
if (msg.role === "user" && Array.isArray(msg.content)) {
|
|
312
|
+
for (const block of msg.content) {
|
|
313
|
+
if (block.type === "tool_result") {
|
|
314
|
+
const toolName = findToolNameForResult(messages, i, block.tool_use_id);
|
|
315
|
+
if (!toolName) {
|
|
316
|
+
issues.push(
|
|
317
|
+
`Orphaned tool_result for ${block.tool_use_id} at message index ${i}`
|
|
318
|
+
);
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
if (msg.role === "assistant" && Array.isArray(msg.content)) {
|
|
324
|
+
for (const block of msg.content) {
|
|
325
|
+
if (block.type === "tool_use") {
|
|
326
|
+
const nextMsg = messages[i + 1];
|
|
327
|
+
if (!nextMsg || nextMsg.role !== "user") {
|
|
328
|
+
issues.push(
|
|
329
|
+
`tool_use "${block.name}" (${block.id}) at message index ${i} has no following user message`
|
|
330
|
+
);
|
|
331
|
+
continue;
|
|
332
|
+
}
|
|
333
|
+
if (!Array.isArray(nextMsg.content)) {
|
|
334
|
+
issues.push(
|
|
335
|
+
`tool_use "${block.name}" (${block.id}) at message index ${i} has no matching tool_result`
|
|
336
|
+
);
|
|
337
|
+
continue;
|
|
338
|
+
}
|
|
339
|
+
const hasResult = nextMsg.content.some(
|
|
340
|
+
(b) => b.type === "tool_result" && b.tool_use_id === block.id
|
|
341
|
+
);
|
|
342
|
+
if (!hasResult) {
|
|
343
|
+
issues.push(
|
|
344
|
+
`tool_use "${block.name}" (${block.id}) at message index ${i} has no matching tool_result`
|
|
345
|
+
);
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
}
|
|
351
|
+
return issues;
|
|
352
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AIProvider, ProviderConfig, StreamOptions, StreamEvent } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Anthropic/Claude AI provider implementation.
|
|
4
|
+
*/
|
|
5
|
+
export declare class AnthropicProvider implements AIProvider {
|
|
6
|
+
readonly name = "anthropic";
|
|
7
|
+
createStream(config: ProviderConfig, options: StreamOptions): AsyncIterable<StreamEvent>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Create an Anthropic provider instance.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createAnthropicProvider(): AIProvider;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import Anthropic from "@anthropic-ai/sdk";
|
|
2
|
+
function convertMessages(messages) {
|
|
3
|
+
return messages.map((msg) => {
|
|
4
|
+
if (typeof msg.content === "string") {
|
|
5
|
+
return {
|
|
6
|
+
role: msg.role,
|
|
7
|
+
content: msg.content
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
const content = msg.content.map((block) => {
|
|
11
|
+
switch (block.type) {
|
|
12
|
+
case "text":
|
|
13
|
+
case "skill":
|
|
14
|
+
return { type: "text", text: block.text };
|
|
15
|
+
case "tool_use":
|
|
16
|
+
return {
|
|
17
|
+
type: "tool_use",
|
|
18
|
+
id: block.id,
|
|
19
|
+
name: block.name,
|
|
20
|
+
input: block.input
|
|
21
|
+
};
|
|
22
|
+
case "tool_result":
|
|
23
|
+
return {
|
|
24
|
+
type: "tool_result",
|
|
25
|
+
tool_use_id: block.tool_use_id,
|
|
26
|
+
content: block.content,
|
|
27
|
+
is_error: block.is_error
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
return {
|
|
32
|
+
role: msg.role,
|
|
33
|
+
content
|
|
34
|
+
};
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
function convertSystemPrompt(blocks) {
|
|
38
|
+
return blocks.map((block) => {
|
|
39
|
+
const param = { type: "text", text: block.text };
|
|
40
|
+
if (block.cacheHint) {
|
|
41
|
+
;
|
|
42
|
+
param.cache_control = {
|
|
43
|
+
type: block.cacheHint
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
return param;
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
function convertTools(tools) {
|
|
50
|
+
return tools.map((tool, i) => {
|
|
51
|
+
const converted = {
|
|
52
|
+
name: tool.name,
|
|
53
|
+
description: tool.description,
|
|
54
|
+
input_schema: tool.input_schema
|
|
55
|
+
};
|
|
56
|
+
if (i === tools.length - 1) {
|
|
57
|
+
converted.cache_control = { type: "ephemeral" };
|
|
58
|
+
}
|
|
59
|
+
return converted;
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
export class AnthropicProvider {
|
|
63
|
+
name = "anthropic";
|
|
64
|
+
async *createStream(config, options) {
|
|
65
|
+
const client = new Anthropic({ apiKey: config.apiKey });
|
|
66
|
+
const messages = convertMessages(options.messages);
|
|
67
|
+
const tools = convertTools(options.tools);
|
|
68
|
+
yield { type: "debug_request", tools };
|
|
69
|
+
const stream = client.messages.stream({
|
|
70
|
+
model: config.model,
|
|
71
|
+
max_tokens: options.maxTokens ?? 4096,
|
|
72
|
+
system: convertSystemPrompt(options.systemPrompt),
|
|
73
|
+
messages,
|
|
74
|
+
tools
|
|
75
|
+
});
|
|
76
|
+
try {
|
|
77
|
+
for await (const event of stream) {
|
|
78
|
+
if (options.signal?.aborted) {
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
switch (event.type) {
|
|
82
|
+
case "content_block_start":
|
|
83
|
+
if (event.content_block.type === "text") {
|
|
84
|
+
yield { type: "text_start" };
|
|
85
|
+
} else if (event.content_block.type === "tool_use") {
|
|
86
|
+
yield {
|
|
87
|
+
type: "tool_use_start",
|
|
88
|
+
id: event.content_block.id,
|
|
89
|
+
name: event.content_block.name
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
93
|
+
case "content_block_delta":
|
|
94
|
+
if (event.delta.type === "text_delta") {
|
|
95
|
+
yield { type: "text_delta", text: event.delta.text };
|
|
96
|
+
} else if (event.delta.type === "input_json_delta") {
|
|
97
|
+
yield {
|
|
98
|
+
type: "tool_use_delta",
|
|
99
|
+
partial_json: event.delta.partial_json
|
|
100
|
+
};
|
|
101
|
+
}
|
|
102
|
+
break;
|
|
103
|
+
case "content_block_stop":
|
|
104
|
+
yield { type: "text_end" };
|
|
105
|
+
yield { type: "tool_use_end" };
|
|
106
|
+
break;
|
|
107
|
+
case "message_stop": {
|
|
108
|
+
const finalMessage = await stream.finalMessage();
|
|
109
|
+
yield {
|
|
110
|
+
type: "message_end",
|
|
111
|
+
stop_reason: finalMessage.stop_reason,
|
|
112
|
+
inputTokens: finalMessage.usage?.input_tokens,
|
|
113
|
+
outputTokens: finalMessage.usage?.output_tokens,
|
|
114
|
+
cacheCreationInputTokens: finalMessage.usage?.cache_creation_input_tokens ?? void 0,
|
|
115
|
+
cacheReadInputTokens: finalMessage.usage?.cache_read_input_tokens ?? void 0
|
|
116
|
+
};
|
|
117
|
+
break;
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
} catch (error) {
|
|
122
|
+
yield { type: "error", error };
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
export function createAnthropicProvider() {
|
|
127
|
+
return new AnthropicProvider();
|
|
128
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { AIProvider, ProviderConfig, StreamOptions, StreamEvent } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* OpenAI provider using the Responses API.
|
|
4
|
+
*/
|
|
5
|
+
export declare class OpenAIProvider implements AIProvider {
|
|
6
|
+
readonly name = "openai";
|
|
7
|
+
createStream(config: ProviderConfig, options: StreamOptions): AsyncIterable<StreamEvent>;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Create an OpenAI provider instance.
|
|
11
|
+
*/
|
|
12
|
+
export declare function createOpenAIProvider(): AIProvider;
|
|
@@ -0,0 +1,165 @@
|
|
|
1
|
+
import OpenAI from "openai";
|
|
2
|
+
function convertMessages(messages) {
|
|
3
|
+
const result = [];
|
|
4
|
+
for (const msg of messages) {
|
|
5
|
+
if (typeof msg.content === "string") {
|
|
6
|
+
result.push({
|
|
7
|
+
role: msg.role,
|
|
8
|
+
content: msg.content
|
|
9
|
+
});
|
|
10
|
+
continue;
|
|
11
|
+
}
|
|
12
|
+
if (msg.role === "assistant") {
|
|
13
|
+
const textParts = [];
|
|
14
|
+
for (const block of msg.content) {
|
|
15
|
+
if (block.type === "text" || block.type === "skill") {
|
|
16
|
+
textParts.push(block.text);
|
|
17
|
+
} else if (block.type === "tool_use") {
|
|
18
|
+
if (textParts.length > 0) {
|
|
19
|
+
result.push({
|
|
20
|
+
role: "assistant",
|
|
21
|
+
content: textParts.join("\n")
|
|
22
|
+
});
|
|
23
|
+
textParts.length = 0;
|
|
24
|
+
}
|
|
25
|
+
result.push({
|
|
26
|
+
type: "function_call",
|
|
27
|
+
call_id: block.id,
|
|
28
|
+
name: block.name,
|
|
29
|
+
arguments: JSON.stringify(block.input)
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
if (textParts.length > 0) {
|
|
34
|
+
result.push({
|
|
35
|
+
role: "assistant",
|
|
36
|
+
content: textParts.join("\n")
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
} else if (msg.role === "user") {
|
|
40
|
+
const textParts = [];
|
|
41
|
+
for (const block of msg.content) {
|
|
42
|
+
if (block.type === "text" || block.type === "skill") {
|
|
43
|
+
textParts.push(block.text);
|
|
44
|
+
} else if (block.type === "tool_result") {
|
|
45
|
+
if (textParts.length > 0) {
|
|
46
|
+
result.push({ role: "user", content: textParts.join("\n") });
|
|
47
|
+
textParts.length = 0;
|
|
48
|
+
}
|
|
49
|
+
result.push({
|
|
50
|
+
type: "function_call_output",
|
|
51
|
+
call_id: block.tool_use_id,
|
|
52
|
+
output: block.content
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
if (textParts.length > 0) {
|
|
57
|
+
result.push({ role: "user", content: textParts.join("\n") });
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
63
|
+
function convertTools(tools) {
|
|
64
|
+
return tools.map((tool) => ({
|
|
65
|
+
type: "function",
|
|
66
|
+
name: tool.name,
|
|
67
|
+
description: tool.description ?? null,
|
|
68
|
+
parameters: tool.input_schema,
|
|
69
|
+
strict: false
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
export class OpenAIProvider {
|
|
73
|
+
name = "openai";
|
|
74
|
+
async *createStream(config, options) {
|
|
75
|
+
const client = new OpenAI({ apiKey: config.apiKey });
|
|
76
|
+
const input = convertMessages(options.messages);
|
|
77
|
+
const tools = convertTools(options.tools);
|
|
78
|
+
yield { type: "debug_request", tools };
|
|
79
|
+
const instructions = options.systemPrompt.map((b) => b.text).join("\n\n");
|
|
80
|
+
try {
|
|
81
|
+
const stream = await client.responses.create(
|
|
82
|
+
{
|
|
83
|
+
model: config.model,
|
|
84
|
+
instructions,
|
|
85
|
+
input,
|
|
86
|
+
tools: tools.length > 0 ? tools : void 0,
|
|
87
|
+
max_output_tokens: options.maxTokens ?? 4096,
|
|
88
|
+
stream: true,
|
|
89
|
+
store: false
|
|
90
|
+
},
|
|
91
|
+
{ signal: options.signal }
|
|
92
|
+
);
|
|
93
|
+
let hasFunctionCalls = false;
|
|
94
|
+
for await (const event of stream) {
|
|
95
|
+
if (options.signal?.aborted) break;
|
|
96
|
+
switch (event.type) {
|
|
97
|
+
// Text streaming
|
|
98
|
+
case "response.content_part.added":
|
|
99
|
+
if (event.part.type === "output_text") {
|
|
100
|
+
yield { type: "text_start" };
|
|
101
|
+
}
|
|
102
|
+
break;
|
|
103
|
+
case "response.output_text.delta":
|
|
104
|
+
yield { type: "text_delta", text: event.delta };
|
|
105
|
+
break;
|
|
106
|
+
case "response.output_text.done":
|
|
107
|
+
yield { type: "text_end" };
|
|
108
|
+
break;
|
|
109
|
+
// Tool call streaming
|
|
110
|
+
case "response.output_item.added":
|
|
111
|
+
if (event.item.type === "function_call") {
|
|
112
|
+
hasFunctionCalls = true;
|
|
113
|
+
yield {
|
|
114
|
+
type: "tool_use_start",
|
|
115
|
+
id: event.item.call_id,
|
|
116
|
+
name: event.item.name
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
break;
|
|
120
|
+
case "response.function_call_arguments.delta":
|
|
121
|
+
yield { type: "tool_use_delta", partial_json: event.delta };
|
|
122
|
+
break;
|
|
123
|
+
case "response.function_call_arguments.done":
|
|
124
|
+
yield { type: "tool_use_end" };
|
|
125
|
+
break;
|
|
126
|
+
// Completion
|
|
127
|
+
case "response.completed": {
|
|
128
|
+
const usage = event.response.usage;
|
|
129
|
+
let stopReason = void 0;
|
|
130
|
+
if (hasFunctionCalls) {
|
|
131
|
+
stopReason = buildMessageEnd("tool_use", usage);
|
|
132
|
+
} else if (event.response.status === "incomplete") {
|
|
133
|
+
stopReason = buildMessageEnd("max_tokens", usage);
|
|
134
|
+
} else {
|
|
135
|
+
stopReason = buildMessageEnd("end_turn", usage);
|
|
136
|
+
}
|
|
137
|
+
yield stopReason;
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
case "response.failed":
|
|
141
|
+
yield {
|
|
142
|
+
type: "error",
|
|
143
|
+
error: new Error("OpenAI response failed")
|
|
144
|
+
};
|
|
145
|
+
break;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
} catch (error) {
|
|
149
|
+
yield { type: "error", error };
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
function buildMessageEnd(stopReason, usage) {
|
|
154
|
+
const cachedTokens = usage?.input_tokens_details?.cached_tokens ?? 0;
|
|
155
|
+
return {
|
|
156
|
+
type: "message_end",
|
|
157
|
+
stop_reason: stopReason,
|
|
158
|
+
inputTokens: usage ? usage.input_tokens - cachedTokens : void 0,
|
|
159
|
+
outputTokens: usage?.output_tokens,
|
|
160
|
+
cacheReadInputTokens: cachedTokens || void 0
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
export function createOpenAIProvider() {
|
|
164
|
+
return new OpenAIProvider();
|
|
165
|
+
}
|