@superblocksteam/vite-plugin-file-sync 2.0.42-next.47 → 2.0.42-next.49
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/ai-service/agent/prompts/build-base-system-prompt.d.ts +2 -1
- package/dist/ai-service/agent/prompts/build-base-system-prompt.d.ts.map +1 -1
- package/dist/ai-service/agent/prompts/build-base-system-prompt.js +31 -2
- package/dist/ai-service/agent/prompts/build-base-system-prompt.js.map +1 -1
- package/dist/ai-service/agent/subagents/apis/example-selector.d.ts +24 -0
- package/dist/ai-service/agent/subagents/apis/example-selector.d.ts.map +1 -0
- package/dist/ai-service/agent/subagents/apis/example-selector.js +104 -0
- package/dist/ai-service/agent/subagents/apis/example-selector.js.map +1 -0
- package/dist/ai-service/agent/subagents/apis/examples.d.ts +55 -0
- package/dist/ai-service/agent/subagents/apis/examples.d.ts.map +1 -0
- package/dist/ai-service/agent/subagents/apis/examples.js +1229 -0
- package/dist/ai-service/agent/subagents/apis/examples.js.map +1 -0
- package/dist/ai-service/agent/subagents/apis/generate-api-source.d.ts +83 -0
- package/dist/ai-service/agent/subagents/apis/generate-api-source.d.ts.map +1 -0
- package/dist/ai-service/agent/{apis.js → subagents/apis/generate-api-source.js} +70 -76
- package/dist/ai-service/agent/subagents/apis/generate-api-source.js.map +1 -0
- package/dist/ai-service/agent/subagents/apis/prompt-builder.d.ts +39 -0
- package/dist/ai-service/agent/subagents/apis/prompt-builder.d.ts.map +1 -0
- package/dist/ai-service/agent/subagents/apis/prompt-builder.js +115 -0
- package/dist/ai-service/agent/subagents/apis/prompt-builder.js.map +1 -0
- package/dist/ai-service/agent/{apis-static-analysis.d.ts → subagents/apis/static-analysis.d.ts} +1 -1
- package/dist/ai-service/agent/subagents/apis/static-analysis.d.ts.map +1 -0
- package/dist/ai-service/agent/{apis-static-analysis.js → subagents/apis/static-analysis.js} +3 -2
- package/dist/ai-service/agent/subagents/apis/static-analysis.js.map +1 -0
- package/dist/ai-service/agent/subagents/apis/system-prompt.d.ts +3 -0
- package/dist/ai-service/agent/subagents/apis/system-prompt.d.ts.map +1 -0
- package/dist/ai-service/agent/{apis-system-prompt.js → subagents/apis/system-prompt.js} +3 -1
- package/dist/ai-service/agent/{apis-system-prompt.js.map → subagents/apis/system-prompt.js.map} +1 -1
- package/dist/ai-service/agent/tool-message-utils.d.ts +2 -2
- package/dist/ai-service/agent/tool-message-utils.d.ts.map +1 -1
- package/dist/ai-service/agent/tool-message-utils.js +35 -6
- package/dist/ai-service/agent/tool-message-utils.js.map +1 -1
- package/dist/ai-service/agent/tools/build-add-event.d.ts +2 -4
- package/dist/ai-service/agent/tools/build-add-event.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-add-event.js +9 -8
- package/dist/ai-service/agent/tools/build-add-event.js.map +1 -1
- package/dist/ai-service/agent/tools/build-add-state-var.d.ts +2 -4
- package/dist/ai-service/agent/tools/build-add-state-var.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-add-state-var.js +6 -5
- package/dist/ai-service/agent/tools/build-add-state-var.js.map +1 -1
- package/dist/ai-service/agent/tools/build-add-timer.d.ts +2 -4
- package/dist/ai-service/agent/tools/build-add-timer.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-add-timer.js +7 -6
- package/dist/ai-service/agent/tools/build-add-timer.js.map +1 -1
- package/dist/ai-service/agent/tools/build-create-page.d.ts +2 -3
- package/dist/ai-service/agent/tools/build-create-page.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-create-page.js +11 -10
- package/dist/ai-service/agent/tools/build-create-page.js.map +1 -1
- package/dist/ai-service/agent/tools/build-debug.d.ts +1 -3
- package/dist/ai-service/agent/tools/build-debug.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-debug.js +7 -5
- package/dist/ai-service/agent/tools/build-debug.js.map +1 -1
- package/dist/ai-service/agent/tools/build-edit-file.d.ts +2 -4
- package/dist/ai-service/agent/tools/build-edit-file.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-edit-file.js +10 -7
- package/dist/ai-service/agent/tools/build-edit-file.js.map +1 -1
- package/dist/ai-service/agent/tools/build-finalize.d.ts +2 -4
- package/dist/ai-service/agent/tools/build-finalize.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-finalize.js +6 -5
- package/dist/ai-service/agent/tools/build-finalize.js.map +1 -1
- package/dist/ai-service/agent/tools/build-install-packages.d.ts +2 -4
- package/dist/ai-service/agent/tools/build-install-packages.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-install-packages.js +7 -6
- package/dist/ai-service/agent/tools/build-install-packages.js.map +1 -1
- package/dist/ai-service/agent/tools/build-list-available-components.d.ts +3 -8
- package/dist/ai-service/agent/tools/build-list-available-components.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-list-available-components.js +30 -9
- package/dist/ai-service/agent/tools/build-list-available-components.js.map +1 -1
- package/dist/ai-service/agent/tools/build-list-files.d.ts +2 -3
- package/dist/ai-service/agent/tools/build-list-files.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-list-files.js +10 -8
- package/dist/ai-service/agent/tools/build-list-files.js.map +1 -1
- package/dist/ai-service/agent/tools/build-manage-checklist.d.ts +3 -3
- package/dist/ai-service/agent/tools/build-manage-checklist.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-manage-checklist.js +9 -8
- package/dist/ai-service/agent/tools/build-manage-checklist.js.map +1 -1
- package/dist/ai-service/agent/tools/build-multi-edit-file.d.ts +2 -4
- package/dist/ai-service/agent/tools/build-multi-edit-file.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-multi-edit-file.js +9 -6
- package/dist/ai-service/agent/tools/build-multi-edit-file.js.map +1 -1
- package/dist/ai-service/agent/tools/build-read-files.d.ts +2 -4
- package/dist/ai-service/agent/tools/build-read-files.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-read-files.js +10 -8
- package/dist/ai-service/agent/tools/build-read-files.js.map +1 -1
- package/dist/ai-service/agent/tools/build-register-component-name.d.ts +2 -4
- package/dist/ai-service/agent/tools/build-register-component-name.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-register-component-name.js +9 -8
- package/dist/ai-service/agent/tools/build-register-component-name.js.map +1 -1
- package/dist/ai-service/agent/tools/build-rename-page.d.ts +2 -3
- package/dist/ai-service/agent/tools/build-rename-page.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-rename-page.js +6 -5
- package/dist/ai-service/agent/tools/build-rename-page.js.map +1 -1
- package/dist/ai-service/agent/tools/build-set-api-triggers.d.ts +2 -4
- package/dist/ai-service/agent/tools/build-set-api-triggers.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-set-api-triggers.js +6 -5
- package/dist/ai-service/agent/tools/build-set-api-triggers.js.map +1 -1
- package/dist/ai-service/agent/tools/build-update-state-var.d.ts +2 -3
- package/dist/ai-service/agent/tools/build-update-state-var.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-update-state-var.js +6 -5
- package/dist/ai-service/agent/tools/build-update-state-var.js.map +1 -1
- package/dist/ai-service/agent/tools/build-validate-icons.d.ts +2 -3
- package/dist/ai-service/agent/tools/build-validate-icons.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-validate-icons.js +8 -6
- package/dist/ai-service/agent/tools/build-validate-icons.js.map +1 -1
- package/dist/ai-service/agent/tools/build-write-file.d.ts +2 -4
- package/dist/ai-service/agent/tools/build-write-file.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/build-write-file.js +6 -5
- package/dist/ai-service/agent/tools/build-write-file.js.map +1 -1
- package/dist/ai-service/agent/tools/debug-cache.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/debug-cache.js +3 -0
- package/dist/ai-service/agent/tools/debug-cache.js.map +1 -1
- package/dist/ai-service/agent/tools/index.d.ts +23 -20
- package/dist/ai-service/agent/tools/index.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/index.js +23 -20
- package/dist/ai-service/agent/tools/index.js.map +1 -1
- package/dist/ai-service/agent/tools/integrations/execute-request.d.ts +25 -0
- package/dist/ai-service/agent/tools/integrations/execute-request.d.ts.map +1 -0
- package/dist/ai-service/agent/tools/integrations/execute-request.js +213 -0
- package/dist/ai-service/agent/tools/integrations/execute-request.js.map +1 -0
- package/dist/ai-service/agent/tools/integrations/index.d.ts +4 -0
- package/dist/ai-service/agent/tools/integrations/index.d.ts.map +1 -0
- package/dist/ai-service/agent/tools/integrations/index.js +4 -0
- package/dist/ai-service/agent/tools/integrations/index.js.map +1 -0
- package/dist/ai-service/agent/tools/integrations/internal.d.ts +3 -0
- package/dist/ai-service/agent/tools/integrations/internal.d.ts.map +1 -0
- package/dist/ai-service/agent/tools/integrations/internal.js +11 -0
- package/dist/ai-service/agent/tools/integrations/internal.js.map +1 -0
- package/dist/ai-service/agent/tools/integrations/metadata.d.ts +9 -0
- package/dist/ai-service/agent/tools/integrations/metadata.d.ts.map +1 -0
- package/dist/ai-service/agent/tools/integrations/metadata.js +57 -0
- package/dist/ai-service/agent/tools/integrations/metadata.js.map +1 -0
- package/dist/ai-service/agent/tools/integrations/run-code.d.ts +5 -0
- package/dist/ai-service/agent/tools/integrations/run-code.d.ts.map +1 -0
- package/dist/ai-service/agent/tools/integrations/run-code.js +32 -0
- package/dist/ai-service/agent/tools/integrations/run-code.js.map +1 -0
- package/dist/ai-service/agent/tools/study-current-app-state.d.ts +2 -4
- package/dist/ai-service/agent/tools/study-current-app-state.d.ts.map +1 -1
- package/dist/ai-service/agent/tools/study-current-app-state.js +10 -8
- package/dist/ai-service/agent/tools/study-current-app-state.js.map +1 -1
- package/dist/ai-service/agent/tools.d.ts +3 -281
- package/dist/ai-service/agent/tools.d.ts.map +1 -1
- package/dist/ai-service/agent/tools.js +68 -55
- package/dist/ai-service/agent/tools.js.map +1 -1
- package/dist/ai-service/agent/tools2/access-control.d.ts +119 -0
- package/dist/ai-service/agent/tools2/access-control.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/access-control.js +216 -0
- package/dist/ai-service/agent/tools2/access-control.js.map +1 -0
- package/dist/ai-service/agent/tools2/example.d.ts +13 -0
- package/dist/ai-service/agent/tools2/example.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/example.js +143 -0
- package/dist/ai-service/agent/tools2/example.js.map +1 -0
- package/dist/ai-service/agent/tools2/index.d.ts +16 -0
- package/dist/ai-service/agent/tools2/index.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/index.js +18 -0
- package/dist/ai-service/agent/tools2/index.js.map +1 -0
- package/dist/ai-service/agent/tools2/registry.d.ts +167 -0
- package/dist/ai-service/agent/tools2/registry.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/registry.js +305 -0
- package/dist/ai-service/agent/tools2/registry.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/ask-multi-choice.d.ts +12 -0
- package/dist/ai-service/agent/tools2/tools/ask-multi-choice.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/ask-multi-choice.js +73 -0
- package/dist/ai-service/agent/tools2/tools/ask-multi-choice.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/bash.d.ts +34 -0
- package/dist/ai-service/agent/tools2/tools/bash.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/bash.js +76 -0
- package/dist/ai-service/agent/tools2/tools/bash.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/edit.d.ts +14 -0
- package/dist/ai-service/agent/tools2/tools/edit.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/edit.js +60 -0
- package/dist/ai-service/agent/tools2/tools/edit.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/exit-plan-mode.d.ts +10 -0
- package/dist/ai-service/agent/tools2/tools/exit-plan-mode.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/exit-plan-mode.js +66 -0
- package/dist/ai-service/agent/tools2/tools/exit-plan-mode.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/glob.d.ts +11 -0
- package/dist/ai-service/agent/tools2/tools/glob.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/glob.js +44 -0
- package/dist/ai-service/agent/tools2/tools/glob.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/grep.d.ts +21 -0
- package/dist/ai-service/agent/tools2/tools/grep.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/grep.js +100 -0
- package/dist/ai-service/agent/tools2/tools/grep.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/index.d.ts +13 -0
- package/dist/ai-service/agent/tools2/tools/index.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/index.js +13 -0
- package/dist/ai-service/agent/tools2/tools/index.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/read.d.ts +9 -0
- package/dist/ai-service/agent/tools2/tools/read.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/read.js +43 -0
- package/dist/ai-service/agent/tools2/tools/read.js.map +1 -0
- package/dist/ai-service/agent/tools2/tools/write.d.ts +11 -0
- package/dist/ai-service/agent/tools2/tools/write.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/tools/write.js +28 -0
- package/dist/ai-service/agent/tools2/tools/write.js.map +1 -0
- package/dist/ai-service/agent/tools2/types.d.ts +148 -0
- package/dist/ai-service/agent/tools2/types.d.ts.map +1 -0
- package/dist/ai-service/agent/tools2/types.js +55 -0
- package/dist/ai-service/agent/tools2/types.js.map +1 -0
- package/dist/ai-service/agent/utils.d.ts.map +1 -1
- package/dist/ai-service/agent/utils.js +2 -0
- package/dist/ai-service/agent/utils.js.map +1 -1
- package/dist/ai-service/chat/chat-session-store.d.ts +5 -0
- package/dist/ai-service/chat/chat-session-store.d.ts.map +1 -1
- package/dist/ai-service/chat/chat-session-store.js +486 -342
- package/dist/ai-service/chat/chat-session-store.js.map +1 -1
- package/dist/ai-service/chat/extract-history.d.ts +1 -0
- package/dist/ai-service/chat/extract-history.d.ts.map +1 -1
- package/dist/ai-service/chat/extract-history.js +12 -1
- package/dist/ai-service/chat/extract-history.js.map +1 -1
- package/dist/ai-service/const.d.ts +2 -1
- package/dist/ai-service/const.d.ts.map +1 -1
- package/dist/ai-service/const.js +7 -1
- package/dist/ai-service/const.js.map +1 -1
- package/dist/ai-service/index.d.ts +8 -8
- package/dist/ai-service/index.d.ts.map +1 -1
- package/dist/ai-service/index.js.map +1 -1
- package/dist/ai-service/integrations/store.d.ts +24 -1
- package/dist/ai-service/integrations/store.d.ts.map +1 -1
- package/dist/ai-service/integrations/store.js +86 -2
- package/dist/ai-service/integrations/store.js.map +1 -1
- package/dist/ai-service/llm/context/context.d.ts +1 -1
- package/dist/ai-service/llm/context/context.js +1 -1
- package/dist/ai-service/llmobs/middleware/stream-text.js +4 -1
- package/dist/ai-service/llmobs/middleware/stream-text.js.map +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/ButtonPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/CheckboxPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/ColumnPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/ContainerPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/DatePickerPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/DropdownPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/IconPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/ImagePropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/InputPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/ModalPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/PagePropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/SectionPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/SlideoutPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/SwitchPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/TablePropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-components/TextPropsDocs.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-typedefs/Dim.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-typedefs/EventFlow.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/library-typedefs/TextStyleWithVariant.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/full-examples.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-api.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-components-rules.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-custom-components.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-data-filtering.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-event-flow.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-forms.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-layouts.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-page.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-rbac.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-routes.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-state.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/superblocks-theming-chakra-new.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/system-base.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/system-incremental.js +1 -1
- package/dist/ai-service/prompt-builder-service/static-fragments/platform-parts/system-specific-edit.js +1 -1
- package/dist/ai-service/state-machine/clark-fsm.d.ts +7 -5
- package/dist/ai-service/state-machine/clark-fsm.d.ts.map +1 -1
- package/dist/ai-service/state-machine/clark-fsm.js.map +1 -1
- package/dist/ai-service/state-machine/handlers/agent-planning.d.ts.map +1 -1
- package/dist/ai-service/state-machine/handlers/agent-planning.js +36 -9
- package/dist/ai-service/state-machine/handlers/agent-planning.js.map +1 -1
- package/dist/ai-service/state-machine/handlers/llm-generating.d.ts.map +1 -1
- package/dist/ai-service/state-machine/handlers/llm-generating.js +35 -7
- package/dist/ai-service/state-machine/handlers/llm-generating.js.map +1 -1
- package/dist/ai-service/state-machine/helpers/peer.d.ts.map +1 -1
- package/dist/ai-service/state-machine/helpers/peer.js +7 -4
- package/dist/ai-service/state-machine/helpers/peer.js.map +1 -1
- package/dist/ai-service/state-machine/mocks.d.ts +2 -3
- package/dist/ai-service/state-machine/mocks.d.ts.map +1 -1
- package/dist/ai-service/state-machine/mocks.js.map +1 -1
- package/dist/ai-service/types.d.ts +3 -0
- package/dist/ai-service/types.d.ts.map +1 -1
- package/dist/ai-service/types.js.map +1 -1
- package/package.json +7 -7
- package/dist/ai-service/agent/apis-static-analysis.d.ts.map +0 -1
- package/dist/ai-service/agent/apis-static-analysis.js.map +0 -1
- package/dist/ai-service/agent/apis-system-prompt.d.ts +0 -3
- package/dist/ai-service/agent/apis-system-prompt.d.ts.map +0 -1
- package/dist/ai-service/agent/apis.d.ts +0 -56
- package/dist/ai-service/agent/apis.d.ts.map +0 -1
- package/dist/ai-service/agent/apis.js.map +0 -1
|
@@ -1,4 +1,39 @@
|
|
|
1
|
+
var __runInitializers = (this && this.__runInitializers) || function (thisArg, initializers, value) {
|
|
2
|
+
var useValue = arguments.length > 2;
|
|
3
|
+
for (var i = 0; i < initializers.length; i++) {
|
|
4
|
+
value = useValue ? initializers[i].call(thisArg, value) : initializers[i].call(thisArg);
|
|
5
|
+
}
|
|
6
|
+
return useValue ? value : void 0;
|
|
7
|
+
};
|
|
8
|
+
var __esDecorate = (this && this.__esDecorate) || function (ctor, descriptorIn, decorators, contextIn, initializers, extraInitializers) {
|
|
9
|
+
function accept(f) { if (f !== void 0 && typeof f !== "function") throw new TypeError("Function expected"); return f; }
|
|
10
|
+
var kind = contextIn.kind, key = kind === "getter" ? "get" : kind === "setter" ? "set" : "value";
|
|
11
|
+
var target = !descriptorIn && ctor ? contextIn["static"] ? ctor : ctor.prototype : null;
|
|
12
|
+
var descriptor = descriptorIn || (target ? Object.getOwnPropertyDescriptor(target, contextIn.name) : {});
|
|
13
|
+
var _, done = false;
|
|
14
|
+
for (var i = decorators.length - 1; i >= 0; i--) {
|
|
15
|
+
var context = {};
|
|
16
|
+
for (var p in contextIn) context[p] = p === "access" ? {} : contextIn[p];
|
|
17
|
+
for (var p in contextIn.access) context.access[p] = contextIn.access[p];
|
|
18
|
+
context.addInitializer = function (f) { if (done) throw new TypeError("Cannot add initializers after decoration has completed"); extraInitializers.push(accept(f || null)); };
|
|
19
|
+
var result = (0, decorators[i])(kind === "accessor" ? { get: descriptor.get, set: descriptor.set } : descriptor[key], context);
|
|
20
|
+
if (kind === "accessor") {
|
|
21
|
+
if (result === void 0) continue;
|
|
22
|
+
if (result === null || typeof result !== "object") throw new TypeError("Object expected");
|
|
23
|
+
if (_ = accept(result.get)) descriptor.get = _;
|
|
24
|
+
if (_ = accept(result.set)) descriptor.set = _;
|
|
25
|
+
if (_ = accept(result.init)) initializers.unshift(_);
|
|
26
|
+
}
|
|
27
|
+
else if (_ = accept(result)) {
|
|
28
|
+
if (kind === "field") initializers.unshift(_);
|
|
29
|
+
else descriptor[key] = _;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (target) Object.defineProperty(target, contextIn.name, descriptor);
|
|
33
|
+
done = true;
|
|
34
|
+
};
|
|
1
35
|
import { getErrorMeta } from "../../util/logger.js";
|
|
36
|
+
import llmobs from "../llmobs/index.js";
|
|
2
37
|
import { extractProductiveHistoryForContext, getLastUserMessage, } from "./extract-history.js";
|
|
3
38
|
export function isAiChatMessage(item) {
|
|
4
39
|
return "role" in item && "content" in item;
|
|
@@ -6,396 +41,505 @@ export function isAiChatMessage(item) {
|
|
|
6
41
|
export function isAiChatSummary(item) {
|
|
7
42
|
return "summary" in item && "relevantFilePaths" in item;
|
|
8
43
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
* Validates and sanitizes the attachments array
|
|
28
|
-
* @param attachments - The attachments array to validate
|
|
29
|
-
* @returns A tuple containing:
|
|
30
|
-
* - a boolean indicating if the attachments are valid
|
|
31
|
-
* - the sanitized attachments array
|
|
32
|
-
*/
|
|
33
|
-
validateAttachments(attachments) {
|
|
34
|
-
if (!attachments) {
|
|
35
|
-
return [true, undefined];
|
|
44
|
+
let ChatSessionStore = (() => {
|
|
45
|
+
let _instanceExtraInitializers = [];
|
|
46
|
+
let _getMessages_decorators;
|
|
47
|
+
let _getLatestSummary_decorators;
|
|
48
|
+
return class ChatSessionStore {
|
|
49
|
+
static {
|
|
50
|
+
const _metadata = typeof Symbol === "function" && Symbol.metadata ? Object.create(null) : void 0;
|
|
51
|
+
_getMessages_decorators = [llmobs.decorate({
|
|
52
|
+
kind: "task",
|
|
53
|
+
name: "ChatSessionStore.getMessages",
|
|
54
|
+
})];
|
|
55
|
+
_getLatestSummary_decorators = [llmobs.decorate({
|
|
56
|
+
kind: "task",
|
|
57
|
+
name: "ChatSessionStore.getLatestSummary",
|
|
58
|
+
})];
|
|
59
|
+
__esDecorate(this, null, _getMessages_decorators, { kind: "method", name: "getMessages", static: false, private: false, access: { has: obj => "getMessages" in obj, get: obj => obj.getMessages }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
60
|
+
__esDecorate(this, null, _getLatestSummary_decorators, { kind: "method", name: "getLatestSummary", static: false, private: false, access: { has: obj => "getLatestSummary" in obj, get: obj => obj.getLatestSummary }, metadata: _metadata }, null, _instanceExtraInitializers);
|
|
61
|
+
if (_metadata) Object.defineProperty(this, Symbol.metadata, { enumerable: true, configurable: true, writable: true, value: _metadata });
|
|
36
62
|
}
|
|
37
|
-
|
|
38
|
-
|
|
63
|
+
// Approximate number of characters per token for estimating token usage
|
|
64
|
+
static CHARS_PER_TOKEN = 3.5;
|
|
65
|
+
applicationId = __runInitializers(this, _instanceExtraInitializers);
|
|
66
|
+
rpcClient;
|
|
67
|
+
logger;
|
|
68
|
+
messages;
|
|
69
|
+
inFlightLoadFromServer;
|
|
70
|
+
loadedFromServer = "no";
|
|
71
|
+
constructor(config) {
|
|
72
|
+
this.rpcClient = config.rpcClient;
|
|
73
|
+
this.applicationId = config.applicationId;
|
|
74
|
+
this.messages = [];
|
|
75
|
+
this.logger = config.logger;
|
|
76
|
+
// NOTE: This is used to serialize messages to be after any load.
|
|
77
|
+
// We initialize it as resolved to handle the prompt-from-empty-state case.
|
|
78
|
+
// TODO(ai): consider replacing this with a queue-based approach
|
|
79
|
+
this.inFlightLoadFromServer = Promise.resolve();
|
|
39
80
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
81
|
+
/***
|
|
82
|
+
* Validates and sanitizes the attachments array
|
|
83
|
+
* @param attachments - The attachments array to validate
|
|
84
|
+
* @returns A tuple containing:
|
|
85
|
+
* - a boolean indicating if the attachments are valid
|
|
86
|
+
* - the sanitized attachments array
|
|
87
|
+
*/
|
|
88
|
+
validateAttachments(attachments) {
|
|
89
|
+
if (!attachments) {
|
|
90
|
+
return [true, undefined];
|
|
91
|
+
}
|
|
92
|
+
if (typeof attachments !== "object" || !Array.isArray(attachments)) {
|
|
93
|
+
return [false, undefined];
|
|
44
94
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
if (typeof attachment
|
|
95
|
+
const validAttachments = attachments
|
|
96
|
+
.map((attachment) => {
|
|
97
|
+
if (typeof attachment !== "object" || !("type" in attachment)) {
|
|
48
98
|
return undefined;
|
|
49
99
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
100
|
+
// Validate image attachment
|
|
101
|
+
if (attachment.type === "image") {
|
|
102
|
+
if (typeof attachment.image !== "string") {
|
|
103
|
+
return undefined;
|
|
104
|
+
}
|
|
105
|
+
return {
|
|
106
|
+
type: attachment.type,
|
|
107
|
+
image: attachment.image,
|
|
108
|
+
fileName: attachment.fileName,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
return undefined;
|
|
112
|
+
})
|
|
113
|
+
.filter(Boolean);
|
|
114
|
+
return [validAttachments.length === attachments.length, validAttachments];
|
|
115
|
+
}
|
|
116
|
+
validateChatMessageV1(payload) {
|
|
117
|
+
try {
|
|
118
|
+
if (!payload || typeof payload !== "object") {
|
|
119
|
+
return null;
|
|
120
|
+
}
|
|
121
|
+
const msg = payload;
|
|
122
|
+
// Validate required fields
|
|
123
|
+
if (typeof msg.role !== "string" ||
|
|
124
|
+
!["user", "assistant", "server"].includes(msg.role)) {
|
|
125
|
+
this.logger.warn(`[ai-service] Invalid message role: ${msg.role}`);
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
if (typeof msg.content !== "string") {
|
|
129
|
+
this.logger.warn(`[ai-service] Invalid message content`);
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
if (typeof msg.type !== "string") {
|
|
133
|
+
this.logger.warn(`[ai-service] Invalid message type: ${msg.type}`);
|
|
134
|
+
return null;
|
|
135
|
+
}
|
|
136
|
+
// Validate optional fields with defaults
|
|
137
|
+
const timestamp = typeof msg.timestamp === "number" ? msg.timestamp : Date.now();
|
|
138
|
+
const group = typeof msg.group === "string" ? msg.group : undefined;
|
|
139
|
+
const status = typeof msg.status === "string" ? msg.status : undefined;
|
|
140
|
+
const action = typeof msg.action === "string" ? msg.action : undefined;
|
|
141
|
+
const [isAttachmentsValid, attachments] = this.validateAttachments(msg.attachments);
|
|
142
|
+
if (!isAttachmentsValid) {
|
|
143
|
+
this.logger.warn(`[ai-service] Invalid attachments`);
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
if (msg.type === "tool") {
|
|
147
|
+
return {
|
|
148
|
+
role: msg.role,
|
|
149
|
+
content: msg.content,
|
|
150
|
+
type: "tool",
|
|
151
|
+
id: typeof msg.id === "string" ? msg.id : undefined,
|
|
152
|
+
timestamp,
|
|
153
|
+
status: status,
|
|
154
|
+
action: action,
|
|
155
|
+
args: msg.args,
|
|
156
|
+
tool: msg.tool,
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
else if (msg.group === "checklist") {
|
|
160
|
+
if (typeof msg.checklistData !== "object") {
|
|
161
|
+
this.logger.warn(`[ai-service] Invalid checklist data`);
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
return {
|
|
165
|
+
role: msg.role,
|
|
166
|
+
content: msg.content,
|
|
167
|
+
type: "tool",
|
|
168
|
+
id: typeof msg.id === "string" ? msg.id : undefined,
|
|
169
|
+
timestamp,
|
|
170
|
+
group,
|
|
171
|
+
status,
|
|
172
|
+
action,
|
|
173
|
+
checklistData: msg.checklistData,
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
else if (msg.type === "multi_choice") {
|
|
177
|
+
if (!Array.isArray(msg.choices) || msg.choices.length === 0) {
|
|
178
|
+
this.logger.warn(`[ai-service] Invalid choices for multi_choice message`);
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
role: msg.role,
|
|
183
|
+
content: msg.content,
|
|
184
|
+
type: "multi_choice",
|
|
185
|
+
id: typeof msg.id === "string" ? msg.id : undefined,
|
|
186
|
+
timestamp,
|
|
187
|
+
choices: msg.choices,
|
|
188
|
+
selectionType: typeof msg.selectionType === "string"
|
|
189
|
+
? msg.selectionType
|
|
190
|
+
: "single",
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
else if (msg.type === "multi_choice_response") {
|
|
194
|
+
if (typeof msg.responseToMessageId !== "string") {
|
|
195
|
+
this.logger.warn(`[ai-service] Invalid responseToMessageId for multi_choice_response`);
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
if (!Array.isArray(msg.selectedChoiceIndices)) {
|
|
199
|
+
this.logger.warn(`[ai-service] Invalid selectedChoiceIndices for multi_choice_response`);
|
|
200
|
+
return null;
|
|
201
|
+
}
|
|
202
|
+
return {
|
|
203
|
+
role: msg.role,
|
|
204
|
+
content: msg.content,
|
|
205
|
+
type: "multi_choice_response",
|
|
206
|
+
id: typeof msg.id === "string" ? msg.id : undefined,
|
|
207
|
+
timestamp,
|
|
208
|
+
responseToMessageId: msg.responseToMessageId,
|
|
209
|
+
selectedChoiceIndices: msg.selectedChoiceIndices,
|
|
210
|
+
};
|
|
211
|
+
}
|
|
212
|
+
else if (msg.type === "plan_response") {
|
|
213
|
+
if (typeof msg.responseToMessageId !== "string") {
|
|
214
|
+
this.logger.warn(`[ai-service] Invalid responseToMessageId for plan_response`);
|
|
215
|
+
return null;
|
|
216
|
+
}
|
|
217
|
+
return {
|
|
218
|
+
role: msg.role,
|
|
219
|
+
content: msg.content,
|
|
220
|
+
type: "plan_response",
|
|
221
|
+
id: typeof msg.id === "string" ? msg.id : undefined,
|
|
222
|
+
timestamp,
|
|
223
|
+
responseToMessageId: msg.responseToMessageId,
|
|
224
|
+
};
|
|
225
|
+
}
|
|
92
226
|
return {
|
|
93
227
|
role: msg.role,
|
|
94
228
|
content: msg.content,
|
|
95
|
-
type:
|
|
229
|
+
type: msg.type,
|
|
230
|
+
id: typeof msg.id === "string" ? msg.id : undefined,
|
|
96
231
|
timestamp,
|
|
232
|
+
group,
|
|
97
233
|
status: status,
|
|
98
234
|
action: action,
|
|
99
|
-
|
|
100
|
-
tool: msg.tool,
|
|
235
|
+
attachments,
|
|
101
236
|
};
|
|
102
237
|
}
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
238
|
+
catch (error) {
|
|
239
|
+
this.logger.error("[ai-service] Failed to validate message payload", getErrorMeta(error));
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
validateChatSummaryV1(payload) {
|
|
244
|
+
try {
|
|
245
|
+
if (!payload || typeof payload !== "object") {
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
const summary = payload;
|
|
249
|
+
// Validate required fields
|
|
250
|
+
if (typeof summary.summary !== "string") {
|
|
251
|
+
this.logger.warn(`[ai-service] Invalid summary content`);
|
|
252
|
+
return null;
|
|
253
|
+
}
|
|
254
|
+
if (!Array.isArray(summary.relevantFilePaths)) {
|
|
255
|
+
this.logger.warn(`[ai-service] Invalid relevantFilePaths - must be array`);
|
|
256
|
+
return null;
|
|
257
|
+
}
|
|
258
|
+
if (!summary.relevantFilePaths.every((path) => typeof path === "string")) {
|
|
259
|
+
this.logger.warn(`[ai-service] Invalid relevantFilePaths - all items must be strings`);
|
|
260
|
+
return null;
|
|
261
|
+
}
|
|
262
|
+
if (!Array.isArray(summary.goals)) {
|
|
263
|
+
this.logger.warn(`[ai-service] Invalid goals - must be array`);
|
|
264
|
+
return null;
|
|
265
|
+
}
|
|
266
|
+
if (!summary.goals.every((goal) => typeof goal === "string")) {
|
|
267
|
+
this.logger.warn(`[ai-service] Invalid goals - all items must be strings`);
|
|
268
|
+
return null;
|
|
269
|
+
}
|
|
270
|
+
if (!Array.isArray(summary.decisions)) {
|
|
271
|
+
this.logger.warn(`[ai-service] Invalid decisions - must be array`);
|
|
106
272
|
return null;
|
|
107
273
|
}
|
|
274
|
+
if (!summary.decisions.every((decision) => typeof decision === "string")) {
|
|
275
|
+
this.logger.warn(`[ai-service] Invalid decisions - all items must be strings`);
|
|
276
|
+
return null;
|
|
277
|
+
}
|
|
278
|
+
// Validate optional fields with defaults
|
|
279
|
+
const timestamp = typeof summary.timestamp === "number" ? summary.timestamp : Date.now();
|
|
108
280
|
return {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
281
|
+
summary: summary.summary,
|
|
282
|
+
relevantFilePaths: summary.relevantFilePaths,
|
|
283
|
+
goals: summary.goals,
|
|
284
|
+
decisions: summary.decisions,
|
|
285
|
+
adviceToAgents: summary.adviceToAgents,
|
|
112
286
|
timestamp,
|
|
113
|
-
group,
|
|
114
|
-
status,
|
|
115
|
-
action,
|
|
116
|
-
checklistData: msg.checklistData,
|
|
117
287
|
};
|
|
118
288
|
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
content: msg.content,
|
|
122
|
-
type: msg.type,
|
|
123
|
-
timestamp,
|
|
124
|
-
group,
|
|
125
|
-
status: status,
|
|
126
|
-
action: action,
|
|
127
|
-
attachments,
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
|
-
catch (error) {
|
|
131
|
-
this.logger.error("[ai-service] Failed to validate message payload", getErrorMeta(error));
|
|
132
|
-
return null;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
validateChatSummaryV1(payload) {
|
|
136
|
-
try {
|
|
137
|
-
if (!payload || typeof payload !== "object") {
|
|
138
|
-
return null;
|
|
139
|
-
}
|
|
140
|
-
const summary = payload;
|
|
141
|
-
// Validate required fields
|
|
142
|
-
if (typeof summary.summary !== "string") {
|
|
143
|
-
this.logger.warn(`[ai-service] Invalid summary content`);
|
|
289
|
+
catch (error) {
|
|
290
|
+
this.logger.error("[ai-service] Failed to validate summary payload", getErrorMeta(error));
|
|
144
291
|
return null;
|
|
145
292
|
}
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
if (
|
|
151
|
-
|
|
152
|
-
return null;
|
|
293
|
+
}
|
|
294
|
+
validateChatItemV1(payload) {
|
|
295
|
+
// First try to validate as a message
|
|
296
|
+
const messageResult = this.validateChatMessageV1(payload);
|
|
297
|
+
if (messageResult) {
|
|
298
|
+
return messageResult;
|
|
153
299
|
}
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
300
|
+
// If not a valid message, try to validate as a summary
|
|
301
|
+
const summaryResult = this.validateChatSummaryV1(payload);
|
|
302
|
+
if (summaryResult) {
|
|
303
|
+
return summaryResult;
|
|
157
304
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
305
|
+
return null;
|
|
306
|
+
}
|
|
307
|
+
async ensureLoadedFromServer() {
|
|
308
|
+
// NOTE: we will want to re-evaluate this if/when the auth token associated with this sandbox is changed
|
|
309
|
+
// the existing solution is that each time the page loaded by the client, we re-fetch from the server,
|
|
310
|
+
// so this may be a non-issue.
|
|
311
|
+
if (this.loadedFromServer === "loaded" ||
|
|
312
|
+
this.loadedFromServer === "loading") {
|
|
313
|
+
await this.inFlightLoadFromServer;
|
|
314
|
+
return;
|
|
161
315
|
}
|
|
162
|
-
|
|
163
|
-
this.
|
|
164
|
-
|
|
316
|
+
try {
|
|
317
|
+
this.loadedFromServer = "loading";
|
|
318
|
+
this.inFlightLoadFromServer = this.rpcClient.call(async (client) => {
|
|
319
|
+
const applicationId = this.applicationId;
|
|
320
|
+
const { data } = await client.call.v1.ai.chat.getMessages({
|
|
321
|
+
applicationId,
|
|
322
|
+
});
|
|
323
|
+
this.messages =
|
|
324
|
+
data?.messages
|
|
325
|
+
.map((msg) => this.validateChatItemV1(msg.chatPayload))
|
|
326
|
+
.filter((item) => item !== null)
|
|
327
|
+
.sort((a, b) => {
|
|
328
|
+
return (a.timestamp || 0) - (b.timestamp || 0);
|
|
329
|
+
}) ?? [];
|
|
330
|
+
});
|
|
331
|
+
await this.inFlightLoadFromServer;
|
|
332
|
+
this.loadedFromServer = "loaded";
|
|
165
333
|
}
|
|
166
|
-
|
|
167
|
-
this.logger.
|
|
168
|
-
return null;
|
|
334
|
+
catch (error) {
|
|
335
|
+
this.logger.error("[ai-service] Failed to load chat messages from server", getErrorMeta(error));
|
|
169
336
|
}
|
|
170
|
-
// Validate optional fields with defaults
|
|
171
|
-
const timestamp = typeof summary.timestamp === "number" ? summary.timestamp : Date.now();
|
|
172
|
-
return {
|
|
173
|
-
summary: summary.summary,
|
|
174
|
-
relevantFilePaths: summary.relevantFilePaths,
|
|
175
|
-
goals: summary.goals,
|
|
176
|
-
decisions: summary.decisions,
|
|
177
|
-
adviceToAgents: summary.adviceToAgents,
|
|
178
|
-
timestamp,
|
|
179
|
-
};
|
|
180
337
|
}
|
|
181
|
-
|
|
182
|
-
this.
|
|
183
|
-
return
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
validateChatItemV1(payload) {
|
|
187
|
-
// First try to validate as a message
|
|
188
|
-
const messageResult = this.validateChatMessageV1(payload);
|
|
189
|
-
if (messageResult) {
|
|
190
|
-
return messageResult;
|
|
338
|
+
getLastUserMessage() {
|
|
339
|
+
const messages = this.messages.filter(isAiChatMessage);
|
|
340
|
+
return getLastUserMessage(messages);
|
|
191
341
|
}
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
return
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
}
|
|
199
|
-
async ensureLoadedFromServer() {
|
|
200
|
-
// NOTE: we will want to re-evaluate this if/when the auth token associated with this sandbox is changed
|
|
201
|
-
// the existing solution is that each time the page loaded by the client, we re-fetch from the server,
|
|
202
|
-
// so this may be a non-issue.
|
|
203
|
-
if (this.loadedFromServer === "loaded" ||
|
|
204
|
-
this.loadedFromServer === "loading") {
|
|
205
|
-
await this.inFlightLoadFromServer;
|
|
206
|
-
return;
|
|
207
|
-
}
|
|
208
|
-
try {
|
|
209
|
-
this.loadedFromServer = "loading";
|
|
210
|
-
this.inFlightLoadFromServer = this.rpcClient.call(async (client) => {
|
|
211
|
-
const applicationId = this.applicationId;
|
|
212
|
-
const { data } = await client.call.v1.ai.chat.getMessages({
|
|
213
|
-
applicationId,
|
|
214
|
-
});
|
|
215
|
-
this.messages =
|
|
216
|
-
data?.messages
|
|
217
|
-
.map((msg) => this.validateChatItemV1(msg.chatPayload))
|
|
218
|
-
.filter((item) => item !== null)
|
|
219
|
-
.sort((a, b) => {
|
|
220
|
-
return (a.timestamp || 0) - (b.timestamp || 0);
|
|
221
|
-
}) ?? [];
|
|
342
|
+
getRecentExchanges() {
|
|
343
|
+
// Filter out summaries but keep regular messages for the existing logic
|
|
344
|
+
const messages = this.messages.filter(isAiChatMessage);
|
|
345
|
+
return extractProductiveHistoryForContext(messages, {
|
|
346
|
+
maxAcceptedExchanges: 2,
|
|
347
|
+
includeRecentUnknown: true,
|
|
222
348
|
});
|
|
223
|
-
await this.inFlightLoadFromServer;
|
|
224
|
-
this.loadedFromServer = "loaded";
|
|
225
349
|
}
|
|
226
|
-
|
|
227
|
-
this.
|
|
350
|
+
async getMessages() {
|
|
351
|
+
await this.ensureLoadedFromServer();
|
|
352
|
+
return this.messages.filter(isAiChatMessage);
|
|
228
353
|
}
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
async getMessages() {
|
|
243
|
-
await this.ensureLoadedFromServer();
|
|
244
|
-
return this.messages.filter(isAiChatMessage);
|
|
245
|
-
}
|
|
246
|
-
async newChat() {
|
|
247
|
-
try {
|
|
248
|
-
await this.rpcClient.call(async (client) => {
|
|
249
|
-
const applicationId = this.applicationId;
|
|
250
|
-
return await client.call.v1.ai.chat.new({ applicationId });
|
|
251
|
-
});
|
|
252
|
-
this.messages = [];
|
|
253
|
-
}
|
|
254
|
-
catch (error) {
|
|
255
|
-
this.logger.error("[ai-service] Failed to create new chat", getErrorMeta(error));
|
|
354
|
+
async newChat() {
|
|
355
|
+
try {
|
|
356
|
+
await this.rpcClient.call(async (client) => {
|
|
357
|
+
const applicationId = this.applicationId;
|
|
358
|
+
return await client.call.v1.ai.chat.new({ applicationId });
|
|
359
|
+
});
|
|
360
|
+
this.messages = [];
|
|
361
|
+
}
|
|
362
|
+
catch (error) {
|
|
363
|
+
this.logger.error("[ai-service] Failed to create new chat", getErrorMeta(error));
|
|
364
|
+
}
|
|
256
365
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
366
|
+
async recordUser(text, options = {}) {
|
|
367
|
+
const message = {
|
|
368
|
+
role: "user",
|
|
369
|
+
content: text,
|
|
370
|
+
id: crypto.randomUUID(),
|
|
371
|
+
timestamp: Date.now(),
|
|
372
|
+
type: "text",
|
|
373
|
+
};
|
|
374
|
+
if (options.attachments) {
|
|
375
|
+
message.attachments = options.attachments;
|
|
376
|
+
}
|
|
377
|
+
await this.appendMessage(message);
|
|
267
378
|
}
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
content: "",
|
|
274
|
-
timestamp: Date.now(),
|
|
275
|
-
type: "draftAccepted",
|
|
276
|
-
};
|
|
277
|
-
await this.appendMessage(message);
|
|
278
|
-
}
|
|
279
|
-
async recordUserRejection() {
|
|
280
|
-
const message = {
|
|
281
|
-
role: "user",
|
|
282
|
-
content: "",
|
|
283
|
-
timestamp: Date.now(),
|
|
284
|
-
type: "draftRejected",
|
|
285
|
-
};
|
|
286
|
-
await this.appendMessage(message);
|
|
287
|
-
}
|
|
288
|
-
async recordAssistant(payload) {
|
|
289
|
-
let message;
|
|
290
|
-
if ("checklistData" in payload) {
|
|
291
|
-
message = {
|
|
292
|
-
role: "assistant",
|
|
293
|
-
content: payload.text,
|
|
294
|
-
type: "tool",
|
|
295
|
-
group: "checklist",
|
|
296
|
-
status: payload.status,
|
|
379
|
+
async recordUserAcceptance() {
|
|
380
|
+
const message = {
|
|
381
|
+
role: "user",
|
|
382
|
+
content: "",
|
|
383
|
+
id: crypto.randomUUID(),
|
|
297
384
|
timestamp: Date.now(),
|
|
298
|
-
|
|
385
|
+
type: "draftAccepted",
|
|
299
386
|
};
|
|
387
|
+
await this.appendMessage(message);
|
|
300
388
|
}
|
|
301
|
-
|
|
302
|
-
message = {
|
|
303
|
-
role: "
|
|
389
|
+
async recordUserRejection() {
|
|
390
|
+
const message = {
|
|
391
|
+
role: "user",
|
|
304
392
|
content: "",
|
|
305
|
-
|
|
306
|
-
|
|
393
|
+
id: crypto.randomUUID(),
|
|
394
|
+
timestamp: Date.now(),
|
|
395
|
+
type: "draftRejected",
|
|
396
|
+
};
|
|
397
|
+
await this.appendMessage(message);
|
|
398
|
+
}
|
|
399
|
+
async recordUserResponse(text, responseType, metadata) {
|
|
400
|
+
const baseMessage = {
|
|
401
|
+
role: "user",
|
|
402
|
+
content: text,
|
|
403
|
+
id: crypto.randomUUID(),
|
|
307
404
|
timestamp: Date.now(),
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
group: "group" in payload ? payload.group : "",
|
|
405
|
+
type: responseType,
|
|
406
|
+
responseToMessageId: metadata.responseToMessageId,
|
|
311
407
|
};
|
|
408
|
+
if (responseType === "multi_choice_response" &&
|
|
409
|
+
metadata.selectedChoiceIndices) {
|
|
410
|
+
baseMessage.selectedChoiceIndices =
|
|
411
|
+
metadata.selectedChoiceIndices;
|
|
412
|
+
}
|
|
413
|
+
await this.appendMessage(baseMessage);
|
|
312
414
|
}
|
|
313
|
-
|
|
314
|
-
message
|
|
415
|
+
async recordAssistant(payload) {
|
|
416
|
+
let message;
|
|
417
|
+
// Use ID from payload if present, otherwise generate new one
|
|
418
|
+
const messageId = payload.id ?? crypto.randomUUID();
|
|
419
|
+
if ("checklistData" in payload) {
|
|
420
|
+
message = {
|
|
421
|
+
role: "assistant",
|
|
422
|
+
content: payload.text,
|
|
423
|
+
type: "tool",
|
|
424
|
+
group: "checklist",
|
|
425
|
+
status: payload.status,
|
|
426
|
+
id: messageId,
|
|
427
|
+
timestamp: Date.now(),
|
|
428
|
+
checklistData: payload.checklistData,
|
|
429
|
+
};
|
|
430
|
+
}
|
|
431
|
+
else if (payload.type === "tool") {
|
|
432
|
+
message = {
|
|
433
|
+
role: "assistant",
|
|
434
|
+
content: "",
|
|
435
|
+
type: "tool",
|
|
436
|
+
status: payload.status,
|
|
437
|
+
id: messageId,
|
|
438
|
+
timestamp: Date.now(),
|
|
439
|
+
args: payload.args,
|
|
440
|
+
tool: payload.tool,
|
|
441
|
+
group: "group" in payload ? payload.group : "",
|
|
442
|
+
};
|
|
443
|
+
}
|
|
444
|
+
else {
|
|
445
|
+
message = {
|
|
446
|
+
role: "assistant",
|
|
447
|
+
content: payload.text,
|
|
448
|
+
type: payload.type || "text",
|
|
449
|
+
group: "group" in payload ? payload.group : "",
|
|
450
|
+
status: payload.status,
|
|
451
|
+
id: messageId,
|
|
452
|
+
timestamp: Date.now(),
|
|
453
|
+
...("choices" in payload && payload.choices
|
|
454
|
+
? { choices: payload.choices }
|
|
455
|
+
: {}),
|
|
456
|
+
...("selectionType" in payload && payload.selectionType
|
|
457
|
+
? { selectionType: payload.selectionType }
|
|
458
|
+
: {}),
|
|
459
|
+
};
|
|
460
|
+
}
|
|
461
|
+
await this.appendMessage(message);
|
|
462
|
+
}
|
|
463
|
+
async recordAssistantChangeInfo(payload) {
|
|
464
|
+
const message = {
|
|
315
465
|
role: "assistant",
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
466
|
+
group: payload.type,
|
|
467
|
+
content: payload.name,
|
|
468
|
+
action: payload.action,
|
|
319
469
|
status: payload.status,
|
|
470
|
+
type: "changeInfo",
|
|
471
|
+
id: crypto.randomUUID(),
|
|
320
472
|
timestamp: Date.now(),
|
|
321
473
|
};
|
|
474
|
+
await this.appendMessage(message);
|
|
322
475
|
}
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
}
|
|
337
|
-
async appendMessage(payload) {
|
|
338
|
-
await this.ensureLoadedFromServer();
|
|
339
|
-
this.messages.push(payload);
|
|
340
|
-
try {
|
|
341
|
-
await this.rpcClient.call(async (client) => {
|
|
342
|
-
const applicationId = this.applicationId;
|
|
343
|
-
return await client.call.v1.ai.chat.pushMessage({
|
|
344
|
-
applicationId,
|
|
345
|
-
payload: payload,
|
|
476
|
+
async appendMessage(message) {
|
|
477
|
+
await this.ensureLoadedFromServer();
|
|
478
|
+
this.messages.push(message);
|
|
479
|
+
const payload = {
|
|
480
|
+
...message,
|
|
481
|
+
};
|
|
482
|
+
try {
|
|
483
|
+
await this.rpcClient.call(async (client) => {
|
|
484
|
+
const applicationId = this.applicationId;
|
|
485
|
+
return await client.call.v1.ai.chat.pushMessage({
|
|
486
|
+
applicationId,
|
|
487
|
+
payload,
|
|
488
|
+
});
|
|
346
489
|
});
|
|
347
|
-
}
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
determineSummaryOutcome(summary, allMessages) {
|
|
354
|
-
// Find the index of this summary in all messages
|
|
355
|
-
const summaryIndex = allMessages.findIndex((item) => isAiChatSummary(item) &&
|
|
356
|
-
item.timestamp === summary.timestamp &&
|
|
357
|
-
item.summary === summary.summary);
|
|
358
|
-
if (summaryIndex === -1) {
|
|
359
|
-
return "unknown";
|
|
490
|
+
}
|
|
491
|
+
catch (error) {
|
|
492
|
+
this.logger.error("[ai-service] Failed to write chat message to server", getErrorMeta(error));
|
|
493
|
+
}
|
|
360
494
|
}
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
495
|
+
determineSummaryOutcome(summary, allMessages) {
|
|
496
|
+
// Find the index of this summary in all messages
|
|
497
|
+
const summaryIndex = allMessages.findIndex((item) => isAiChatSummary(item) &&
|
|
498
|
+
item.timestamp === summary.timestamp &&
|
|
499
|
+
item.summary === summary.summary);
|
|
500
|
+
if (summaryIndex === -1) {
|
|
501
|
+
return "unknown";
|
|
502
|
+
}
|
|
503
|
+
// Look for acceptance/rejection messages after this summary
|
|
504
|
+
const messagesAfterSummary = allMessages.slice(summaryIndex + 1);
|
|
505
|
+
for (const item of messagesAfterSummary) {
|
|
506
|
+
if (isAiChatMessage(item) && item.role === "user") {
|
|
507
|
+
if (item.type === "draftAccepted") {
|
|
508
|
+
return "accepted";
|
|
509
|
+
}
|
|
510
|
+
if (item.type === "draftRejected") {
|
|
511
|
+
return "rejected";
|
|
512
|
+
}
|
|
370
513
|
}
|
|
371
514
|
}
|
|
515
|
+
return "unknown";
|
|
372
516
|
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
.
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
}
|
|
517
|
+
async recordSummary(summaryData) {
|
|
518
|
+
const summaryPayload = {
|
|
519
|
+
...summaryData,
|
|
520
|
+
timestamp: Date.now(),
|
|
521
|
+
};
|
|
522
|
+
await this.appendMessage(summaryPayload);
|
|
523
|
+
}
|
|
524
|
+
async getSummaries() {
|
|
525
|
+
await this.ensureLoadedFromServer();
|
|
526
|
+
return this.messages.filter(isAiChatSummary);
|
|
527
|
+
}
|
|
528
|
+
async getLatestSummary() {
|
|
529
|
+
return (await this.getLatestSummaries(1))[0];
|
|
530
|
+
}
|
|
531
|
+
async getLatestSummaries(count) {
|
|
532
|
+
const summaries = await this.getSummaries();
|
|
533
|
+
const sortedSummaries = summaries
|
|
534
|
+
.sort((a, b) => (b.timestamp || 0) - (a.timestamp || 0))
|
|
535
|
+
.slice(0, count);
|
|
536
|
+
// Add outcome information to each summary
|
|
537
|
+
return sortedSummaries.map((summary) => ({
|
|
538
|
+
...summary,
|
|
539
|
+
outcome: this.determineSummaryOutcome(summary, this.messages),
|
|
540
|
+
}));
|
|
541
|
+
}
|
|
542
|
+
};
|
|
543
|
+
})();
|
|
544
|
+
export { ChatSessionStore };
|
|
401
545
|
//# sourceMappingURL=chat-session-store.js.map
|