@salsita-ai/sdk 0.50.0-develop.c33986dc44 → 0.50.0-develop.c402728d10
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/README.md +5 -1
- package/dist/admin/AdminShell.js +1 -1
- package/dist/admin/legacy-admin/Application.js +1 -1
- package/dist/application-spec/core/enhanced-json-value.d.ts +2 -31
- package/dist/application-spec/core/enhanced-json-value.js +1 -1
- package/dist/application-spec/core/index.d.ts +1 -3
- package/dist/application-spec/core/index.js +1 -1
- package/dist/application-spec/core/json-schema.d.ts +2 -52
- package/dist/application-spec/core/markers/index.d.ts +1 -1
- package/dist/application-spec/core/markers/index.js +1 -1
- package/dist/application-spec/core/markers/msg-marker.d.ts +2 -28
- package/dist/application-spec/core/markers/msg-marker.js +1 -1
- package/dist/application-spec/core/markers/raw-eval-write-marker.d.ts +1 -1
- package/dist/application-spec/core/markers/raw-eval-write-marker.js +1 -1
- package/dist/application-spec/core/markers/raw-read-write-marker.js +1 -1
- package/dist/application-spec/errors/diagnostic-codes.d.ts +8 -1
- package/dist/application-spec/errors/diagnostic-codes.js +1 -1
- package/dist/application-spec/errors/diagnostic-messages.d.ts +15 -1
- package/dist/application-spec/errors/diagnostic-messages.js +1 -1
- package/dist/application-spec/generate-application/code/project-scaffolding.js +2 -2
- package/dist/application-spec/generate-application/code/templates/index.d.ts +2 -6
- package/dist/application-spec/generate-application/code/templates/index.js +1 -1
- package/dist/application-spec/generate-application/code/templates/skills/phoenix-skill-bundle.d.ts +10 -0
- package/dist/application-spec/generate-application/code/templates/skills/phoenix-skill-bundle.js +7 -0
- package/dist/application-spec/generate-application/code/templates/skills/phoenix-skill.js +1 -1
- package/dist/application-spec/generate-application/code/templates/skills/sdk-content.d.ts +1 -1
- package/dist/application-spec/generate-application/code/templates/skills/sdk-content.js +1 -1
- package/dist/application-spec/generate-application/code/templates/story/wrapper.js +2 -4
- package/dist/application-spec/generate-application/implementations/phx-model.d.ts +1 -1
- package/dist/application-spec/generate-application/runtime/admin-runtime/admin-model-runtime.d.ts +1 -2
- package/dist/application-spec/generate-application/runtime/configurator-runtime/configurator-model-runtime.d.ts +1 -2
- package/dist/application-spec/generate-application/runtime/factory-data/factory-data-runtime.d.ts +1 -2
- package/dist/application-spec/generate-application/runtime/factory-data/recipe-defaults.d.ts +1 -1
- package/dist/application-spec/generate-application/runtime/factory-data/recipe-defaults.js +1 -1
- package/dist/application-spec/generate-application/runtime/factory-data/static-violations.d.ts +1 -2
- package/dist/application-spec/generate-application/runtime/factory-data/static-violations.js +1 -1
- package/dist/application-spec/generate-application/runtime/generate-runtime-instance.d.ts +1 -1
- package/dist/application-spec/generate-application/runtime/generate-runtime-instance.js +1 -1
- package/dist/application-spec/generate-application/runtime/sections/actions-runtime.d.ts +1 -2
- package/dist/application-spec/generate-application/runtime/sections/build-sdk-optic.d.ts +1 -1
- package/dist/application-spec/generate-application/runtime/sections/build-sdk-optic.js +1 -1
- package/dist/application-spec/generate-application/runtime/sections/build-user-bound-optic.d.ts +1 -1
- package/dist/application-spec/generate-application/runtime/sections/component-optic.d.ts +1 -2
- package/dist/application-spec/generate-application/runtime/sections/expression-runtime.d.ts +1 -2
- package/dist/application-spec/generate-application/runtime/sections/expression-runtime.js +1 -1
- package/dist/application-spec/generate-application/runtime/sections/generate-memo-eval-plan-runtime.d.ts +1 -2
- package/dist/application-spec/generate-application/runtime/sections/generate-memo-eval-plan-runtime.js +1 -1
- package/dist/application-spec/generate-application/runtime/sections/preset-runtime.d.ts +2 -3
- package/dist/application-spec/generate-application/runtime/sections/reflection-constants-runtime.d.ts +1 -1
- package/dist/application-spec/generate-application/runtime/spec-code/resolve-spec-code.d.ts +1 -1
- package/dist/application-spec/generate-application/runtime-spec/runtime-spec.d.ts +96 -31
- package/dist/application-spec/generate-application/runtime-spec/spec-code-id.d.ts +1 -1
- package/dist/application-spec/parse-application-files/merge/merged-assistant.d.ts +13 -4
- package/dist/application-spec/parse-application-files/merge/merged-assistant.js +1 -1
- package/dist/application-spec/parse-application-files/merge/merged-infra.d.ts +4 -11
- package/dist/application-spec/parse-application-files/merge/merged-transformers.d.ts +2 -4
- package/dist/application-spec/parse-application-files/parse-application-files.js +1 -1
- package/dist/application-spec/parse-application-files/raw-spec/raw-acl.d.ts +2 -2
- package/dist/application-spec/parse-application-files/raw-spec/raw-acl.js +1 -1
- package/dist/application-spec/parse-application-files/raw-spec/raw-admin-pages.d.ts +3 -24
- package/dist/application-spec/parse-application-files/raw-spec/raw-assistant.d.ts +25 -20
- package/dist/application-spec/parse-application-files/raw-spec/raw-assistant.js +1 -1
- package/dist/application-spec/parse-application-files/raw-spec/raw-expressions.d.ts +1 -1
- package/dist/application-spec/parse-application-files/raw-spec/raw-expressions.js +1 -1
- package/dist/application-spec/parse-application-files/raw-spec/raw-resources.d.ts +19 -64
- package/dist/application-spec/parse-application-files/spec/application/admin-spec/admin-pages.d.ts +3 -20
- package/dist/application-spec/parse-application-files/spec/application/admin-spec/states.d.ts +3 -5
- package/dist/application-spec/parse-application-files/spec/application/configurator-spec/states.d.ts +3 -8
- package/dist/application-spec/parse-application-files/spec/components/bindings/read-binding.d.ts +3 -13
- package/dist/application-spec/parse-application-files/spec/components/bindings/write-binding.d.ts +4 -32
- package/dist/application-spec/parse-application-files/spec/components/component-filter.d.ts +4 -10
- package/dist/application-spec/parse-application-files/spec/components/components.d.ts +3 -4
- package/dist/application-spec/parse-application-files/spec/components/index.d.ts +1 -2
- package/dist/application-spec/parse-application-files/spec/components/index.js +1 -1
- package/dist/application-spec/parse-application-files/spec/components/sdk-component-entry.d.ts +1 -1
- package/dist/application-spec/parse-application-files/spec/components/user-component-entry.d.ts +2 -3
- package/dist/application-spec/parse-application-files/spec/components/user-component-entry.js +1 -1
- package/dist/application-spec/parse-application-files/spec/components/user-components.d.ts +2 -3
- package/dist/application-spec/parse-application-files/spec/expressions/expression-read-types.d.ts +2 -2
- package/dist/application-spec/parse-application-files/spec/expressions/expressions.d.ts +7 -29
- package/dist/application-spec/parse-application-files/spec/expressions/index.d.ts +0 -1
- package/dist/application-spec/parse-application-files/spec/expressions/memo-eval-plan.d.ts +4 -71
- package/dist/application-spec/parse-application-files/spec/expressions/memo-eval-plan.js +1 -1
- package/dist/application-spec/parse-application-files/spec/expressions/user-expressions.d.ts +2 -2
- package/dist/application-spec/parse-application-files/spec/invariants/invariant.d.ts +5 -21
- package/dist/application-spec/parse-application-files/spec/invariants/invariants.d.ts +4 -14
- package/dist/application-spec/parse-application-files/spec/model/aliases.d.ts +3 -9
- package/dist/application-spec/parse-application-files/spec/model/common-types.d.ts +6 -14
- package/dist/application-spec/parse-application-files/spec/model/defaults.d.ts +6 -31
- package/dist/application-spec/parse-application-files/spec/model/entity-types.d.ts +3 -8
- package/dist/application-spec/parse-application-files/spec/model/model-version-key.d.ts +3 -3
- package/dist/application-spec/parse-application-files/spec/model/names/action-name.d.ts +3 -7
- package/dist/application-spec/parse-application-files/spec/model/names/alias-name.d.ts +3 -7
- package/dist/application-spec/parse-application-files/spec/model/names/entity-or-alias-name.d.ts +3 -8
- package/dist/application-spec/parse-application-files/spec/model/names/entity-type-name.d.ts +3 -8
- package/dist/application-spec/parse-application-files/spec/model/names/expression-name.d.ts +3 -6
- package/dist/application-spec/parse-application-files/spec/model/names/instance-name.d.ts +3 -7
- package/dist/application-spec/parse-application-files/spec/model/names/invariant-name.d.ts +3 -3
- package/dist/application-spec/parse-application-files/spec/model/names/shape-property-name.d.ts +3 -11
- package/dist/application-spec/parse-application-files/spec/model/names/violation-type-name.d.ts +3 -3
- package/dist/application-spec/parse-application-files/spec/model/presets.d.ts +6 -29
- package/dist/application-spec/parse-application-files/spec/sections/actions.d.ts +6 -23
- package/dist/application-spec/parse-application-files/spec/sections/app-metadata.d.ts +3 -18
- package/dist/application-spec/parse-application-files/spec/sections/application-version.d.ts +3 -7
- package/dist/application-spec/parse-application-files/spec/sections/assistant/assistant-schema.js +1 -1
- package/dist/application-spec/parse-application-files/spec/sections/assistant/assistant.js +1 -1
- package/dist/application-spec/parse-application-files/spec/sections/data-spec/chunks.d.ts +6 -23
- package/dist/application-spec/parse-application-files/spec/sections/data-spec/custom-data-spec.d.ts +1 -16
- package/dist/application-spec/parse-application-files/spec/sections/data-spec/data-entry-key.d.ts +3 -9
- package/dist/application-spec/parse-application-files/spec/sections/data-spec/data-spec.d.ts +1 -10
- package/dist/application-spec/parse-application-files/spec/sections/data-spec/swatch-data-spec.d.ts +1 -14
- package/dist/application-spec/parse-application-files/spec/sections/state-value.d.ts +3 -7
- package/dist/application-spec/parse-application-files/spec/sections/theme.d.ts +3 -10
- package/dist/application-spec/parse-application-files/spec/sections/transformers.d.ts +4 -11
- package/dist/application-spec/parse-application-files/spec/sections/ui.d.ts +3 -12
- package/dist/client/authorized-client.d.ts +3 -1
- package/dist/client/authorized-client.js +1 -1
- package/dist/client/contract.d.ts +30 -1
- package/dist/client/contract.js +1 -1
- package/dist/client/index.d.ts +1 -1
- package/dist/client/local-authorized-client.d.ts +3 -1
- package/dist/client/local-authorized-client.js +1 -1
- package/dist/client/memory-authorized-client.d.ts +4 -1
- package/dist/client/memory-authorized-client.js +1 -1
- package/dist/client/phoenix-api.d.ts +259 -1
- package/dist/configurator/ConfiguratorApp.js +1 -1
- package/dist/configurator/application-runtime/extensions/selectors.js +1 -1
- package/dist/configurator/application-runtime/extensions/systems/assistant-system/assistant-system.d.ts +64 -6
- package/dist/configurator/application-runtime/extensions/systems/assistant-system/assistant-system.js +1 -1
- package/dist/configurator/application-runtime/extensions/systems/assistant-system/graphql-tools.d.ts +21 -4
- package/dist/configurator/application-runtime/extensions/systems/assistant-system/graphql-tools.js +1 -1
- package/dist/configurator/application-runtime/extensions/systems/graphql-system/entity-meta.d.ts +70 -56
- package/dist/configurator/application-runtime/extensions/systems/graphql-system/entity-meta.js +1 -1
- package/dist/configurator/application-runtime/extensions/systems/graphql-system/graphql-system.d.ts +30 -9
- package/dist/configurator/application-runtime/extensions/systems/graphql-system/graphql-system.js +1 -1
- package/dist/configurator/application-runtime/extensions/systems/graphql-system/violations.d.ts +40 -0
- package/dist/configurator/application-runtime/extensions/systems/graphql-system/violations.js +1 -0
- package/dist/configurator/common/configurator-interface.d.ts +2 -2
- package/dist/configurator/common/configurator-interface.js +1 -1
- package/dist/configurator/configurator-context/configurator-hooks/index.d.ts +0 -1
- package/dist/configurator/configurator-context/configurator-hooks/index.js +1 -1
- package/dist/configurator/configurator-context/configurator-hooks/layout-hooks.js +1 -1
- package/dist/configurator/configurator-context/index.d.ts +0 -5
- package/dist/configurator/configurator-context/index.js +1 -1
- package/dist/configurator/pages/ConfiguratorNotFoundPage.js +1 -1
- package/dist/configurator/pages/LoadedConfiguratorDetailPage.js +1 -1
- package/dist/configurator/pages/NewConfiguratorPage.js +1 -1
- package/dist/configurator/pages/error-boundaries/DevContextFallback.js +1 -1
- package/dist/configurator/pages/error-boundaries/DevLoadingFallback.js +1 -1
- package/dist/configurator/ui/assistant/AssistantChips.js +1 -1
- package/dist/configurator/ui/assistant/AssistantComposer.d.ts +6 -0
- package/dist/configurator/ui/assistant/AssistantComposer.js +2 -1
- package/dist/configurator/ui/assistant/AssistantThread.js +1 -1
- package/dist/configurator/ui/assistant/attachments/MessageImages.d.ts +11 -0
- package/dist/configurator/ui/assistant/attachments/MessageImages.js +1 -0
- package/dist/configurator/ui/assistant/attachments/index.d.ts +2 -0
- package/dist/configurator/ui/assistant/attachments/index.js +1 -0
- package/dist/configurator/ui/assistant/attachments/prepare-image.d.ts +19 -0
- package/dist/configurator/ui/assistant/attachments/prepare-image.js +1 -0
- package/dist/configurator/ui/assistant/screenshots/ScreenshotThumbnails.d.ts +1 -1
- package/dist/configurator/ui/assistant/screenshots/ScreenshotThumbnails.js +1 -1
- package/dist/configurator/ui/assistant/screenshots/index.d.ts +1 -0
- package/dist/configurator/ui/assistant/screenshots/index.js +1 -1
- package/dist/configurator/ui/assistant/screenshots/tool-screenshots.d.ts +12 -4
- package/dist/configurator/ui/assistant/screenshots/tool-screenshots.js +1 -1
- package/dist/configurator/ui/assistant/screenshots/use-screenshot-src.d.ts +8 -0
- package/dist/configurator/ui/assistant/screenshots/use-screenshot-src.js +1 -0
- package/dist/configurator/ui/assistant/thread-items.d.ts +2 -0
- package/dist/configurator/ui/assistant/thread-items.js +1 -1
- package/dist/configurator/ui/assistant/tool-chip.d.ts +19 -9
- package/dist/configurator/ui/assistant/tool-chip.js +1 -1
- package/dist/configurator/ui/configurator-layout/slots/canvas/GPUAccelerationDisabled.js +1 -1
- package/dist/configurator/ui/configurator-layout/slots/canvas/WebGLNotSupported.js +1 -1
- package/dist/configurator/ui/configurator-layout/slots/readonly-banner/CloneToEditDialog.js +1 -1
- package/dist/configurator/ui/configurator-layout/universal/DesktopPreview.js +1 -1
- package/dist/configurator/ui/configurator-layout/universal/MobilePreview.js +1 -1
- package/dist/configurator/ui/legacy/chat/MobileChat.js +1 -1
- package/dist/configurator/ui/legacy/layout/common/CommonTopNavigation.js +1 -1
- package/dist/configurator/ui/legacy/layout/simple/SimpleSidebar.js +1 -1
- package/dist/configurator/ui/legacy/layout/simple/SimpleTopNavigation.js +1 -1
- package/dist/configurator/ui/legacy/layout/steps/StepsNavigation.js +1 -1
- package/dist/configurator/ui/legacy/layout/steps/StepsOwnerLayout.js +1 -1
- package/dist/configurator/ui/legacy/layout/steps/StepsSideBar.js +1 -1
- package/dist/configurator/ui/legacy/layout/tabs/TabsSidebar.js +1 -1
- package/dist/configurator/ui/phoenix-layout-elements/header/common/back-button/use-go-back-action.js +1 -1
- package/dist/configurator/ui/phoenix-layout-elements/header/common/step-navigation/StepsNavigation.js +1 -1
- package/dist/configurator/ui/phoenix-layout-elements/sidebar-footer/basic/use-basic-sidebar-footer.js +1 -1
- package/dist/configurator/ui/phoenix-layout-elements/sidebar-footer/common/PreviousStepButton.js +1 -1
- package/dist/configurator/ui/preset-layout/CategoryPresetUi.js +1 -1
- package/dist/configurator/ui/save-message-snackbars/SaveMessageSnackbars.js +1 -1
- package/dist/docs/3d-scene/cameras/custom.mdx +4 -2
- package/dist/docs/drag-and-drop/room-planner.mdx +1 -1
- package/dist/docs/index.json +1 -1
- package/dist/docs/phoenix/configurator-interface.mdx +1 -1
- package/dist/docs/phoenix/domain-model.mdx +4 -1
- package/dist/docs/phoenix/layout-slots.mdx +21 -0
- package/dist/docs/phoenix/migration-guide.mdx +3 -3
- package/dist/docs/phoenix/phoenix-cli.mdx +40 -7
- package/dist/docs/phoenix/project-structure.mdx +23 -19
- package/dist/docs/phoenix/sdk-builder-workflow.mdx +2 -2
- package/dist/docs/phoenix/webhooks.mdx +9 -1
- package/dist/domain/application/application-config.d.ts +6 -24
- package/dist/domain/application/assistant/assistant-manifest.d.ts +13 -3
- package/dist/domain/application/assistant/assistant-manifest.js +1 -1
- package/dist/domain/application/assistant/assistant-resolved-manifest.d.ts +5 -9
- package/dist/domain/application/assistant/assistant-resolved-manifest.js +1 -1
- package/dist/domain/application/assistant/build-assistant-lenses.js +1 -1
- package/dist/domain/application/assistant/build-assistant-manifest.js +1 -1
- package/dist/domain/application/assistant/generate-assistant-prompt.js +1 -1
- package/dist/domain/application/assistant/index.d.ts +3 -3
- package/dist/domain/application/assistant/index.js +1 -1
- package/dist/domain/application/assistant/session-setup/apply-assistant-setup.js +1 -1
- package/dist/domain/application/assistant/session-setup/assistant-setup-manifest.d.ts +2 -4
- package/dist/domain/application/assistant/session-setup/assistant-setup-manifest.js +1 -1
- package/dist/domain/application/assistant-mutations.js +1 -1
- package/dist/domain/available-system-components/available-system-components.d.ts +11 -0
- package/dist/domain/available-system-components/available-system-components.js +1 -0
- package/dist/domain/available-system-components/index.d.ts +1 -0
- package/dist/domain/available-system-components/index.js +1 -0
- package/dist/domain/{domain-builder.d.ts → domain-builder/domain-builder.d.ts} +2 -2
- package/dist/domain/domain-builder/domain-builder.js +1 -0
- package/dist/domain/domain-builder/index.d.ts +1 -0
- package/dist/domain/domain-builder/index.js +1 -0
- package/dist/domain/extensions/export-images/agent-screenshot.d.ts +6 -0
- package/dist/domain/extensions/export-images/agent-screenshot.js +1 -1
- package/dist/domain/extensions/export-images/index.d.ts +1 -1
- package/dist/domain/extensions/export-images/index.js +1 -1
- package/dist/domain/extensions/index.d.ts +1 -1
- package/dist/domain/extensions/index.js +1 -1
- package/dist/domain/index.d.ts +3 -2
- package/dist/domain/index.js +1 -1
- package/dist/domain/spec/application/admin-pages-section.d.ts +29 -0
- package/dist/domain/spec/application/admin-pages.d.ts +26 -0
- package/dist/domain/spec/application/admin-states.d.ts +5 -0
- package/dist/domain/spec/application/configurator-states.d.ts +8 -0
- package/dist/domain/spec/application/configurator-states.js +1 -0
- package/dist/domain/spec/application/index.d.ts +5 -0
- package/dist/domain/spec/application/index.js +1 -0
- package/dist/domain/spec/components/bindings/index.d.ts +2 -0
- package/dist/domain/spec/components/bindings/index.js +1 -0
- package/dist/domain/spec/components/bindings/read-binding.d.ts +13 -0
- package/dist/domain/spec/components/bindings/read-binding.js +1 -0
- package/dist/domain/spec/components/bindings/write-binding.d.ts +32 -0
- package/dist/domain/spec/components/bindings/write-binding.js +1 -0
- package/dist/{application-spec/parse-application-files → domain}/spec/components/component-entry.d.ts +3 -3
- package/dist/domain/spec/components/component-entry.js +1 -0
- package/dist/{application-spec/core → domain/spec}/components/component-filter.d.ts +3 -2
- package/dist/domain/spec/components/component-filters.d.ts +10 -0
- package/dist/domain/spec/components/component-filters.js +1 -0
- package/dist/domain/spec/components/components.d.ts +4 -0
- package/dist/domain/spec/components/components.js +1 -0
- package/dist/domain/spec/components/index.d.ts +6 -0
- package/dist/domain/spec/enhanced-json/enhanced-json-value.d.ts +30 -0
- package/dist/domain/spec/enhanced-json/enhanced-json-value.js +1 -0
- package/dist/domain/spec/enhanced-json/index.d.ts +1 -0
- package/dist/domain/spec/enhanced-json/index.js +1 -0
- package/dist/{application-spec/parse-application-files → domain}/spec/expressions/expression.d.ts +9 -3
- package/dist/domain/spec/expressions/expression.js +1 -0
- package/dist/domain/spec/expressions/expressions.d.ts +27 -0
- package/dist/domain/spec/expressions/expressions.js +1 -0
- package/dist/domain/spec/expressions/index.d.ts +5 -0
- package/dist/domain/spec/expressions/memo-eval-plan.d.ts +70 -0
- package/dist/domain/spec/expressions/memo-eval-plan.js +1 -0
- package/dist/domain/spec/expressions/relation-expression-params.js +1 -0
- package/dist/domain/spec/index.d.ts +9 -0
- package/dist/domain/spec/index.js +1 -0
- package/dist/domain/spec/invariants/index.d.ts +2 -0
- package/dist/domain/spec/invariants/index.js +1 -0
- package/dist/domain/spec/invariants/invariant.d.ts +24 -0
- package/dist/domain/spec/invariants/invariant.js +1 -0
- package/dist/domain/spec/invariants/invariants.d.ts +14 -0
- package/dist/domain/spec/invariants/invariants.js +1 -0
- package/dist/domain/spec/json-schema.d.ts +52 -0
- package/dist/domain/spec/json-schema.js +1 -0
- package/dist/domain/spec/markers/index.d.ts +3 -0
- package/dist/domain/spec/markers/index.js +1 -0
- package/dist/domain/spec/markers/msg-marker.d.ts +28 -0
- package/dist/domain/spec/markers/msg-marker.js +1 -0
- package/dist/domain/spec/model/aliases.d.ts +9 -0
- package/dist/domain/spec/model/aliases.js +1 -0
- package/dist/domain/spec/model/common-types.d.ts +15 -0
- package/dist/domain/spec/model/common-types.js +1 -0
- package/dist/domain/spec/model/defaults.d.ts +33 -0
- package/dist/domain/spec/model/defaults.js +1 -0
- package/dist/domain/spec/model/entity-types.d.ts +8 -0
- package/dist/domain/spec/model/entity-types.js +1 -0
- package/dist/domain/spec/model/index.d.ts +7 -0
- package/dist/domain/spec/model/index.js +1 -0
- package/dist/domain/spec/model/model-version-key.d.ts +3 -0
- package/dist/domain/spec/model/model-version-key.js +1 -0
- package/dist/domain/spec/model/names/action-name.d.ts +7 -0
- package/dist/domain/spec/model/names/action-name.js +1 -0
- package/dist/domain/spec/model/names/alias-name.d.ts +7 -0
- package/dist/domain/spec/model/names/alias-name.js +1 -0
- package/dist/domain/spec/model/names/entity-or-alias-name.d.ts +8 -0
- package/dist/domain/spec/model/names/entity-or-alias-name.js +1 -0
- package/dist/domain/spec/model/names/entity-type-name.d.ts +8 -0
- package/dist/domain/spec/model/names/entity-type-name.js +1 -0
- package/dist/domain/spec/model/names/expression-name.d.ts +6 -0
- package/dist/domain/spec/model/names/expression-name.js +1 -0
- package/dist/domain/spec/model/names/index.d.ts +9 -0
- package/dist/domain/spec/model/names/index.js +1 -0
- package/dist/domain/spec/model/names/instance-name.d.ts +7 -0
- package/dist/domain/spec/model/names/instance-name.js +1 -0
- package/dist/domain/spec/model/names/invariant-name.d.ts +3 -0
- package/dist/domain/spec/model/names/invariant-name.js +1 -0
- package/dist/domain/spec/model/names/shape-property-name.d.ts +11 -0
- package/dist/domain/spec/model/names/shape-property-name.js +1 -0
- package/dist/domain/spec/model/names/violation-type-name.d.ts +3 -0
- package/dist/domain/spec/model/names/violation-type-name.js +1 -0
- package/dist/domain/spec/model/presets.d.ts +30 -0
- package/dist/domain/spec/model/presets.js +1 -0
- package/dist/domain/spec/sections/actions.d.ts +23 -0
- package/dist/domain/spec/sections/actions.js +1 -0
- package/dist/domain/spec/sections/app-metadata.d.ts +18 -0
- package/dist/domain/spec/sections/app-metadata.js +1 -0
- package/dist/domain/spec/sections/application-version.d.ts +7 -0
- package/dist/domain/spec/sections/application-version.js +1 -0
- package/dist/domain/spec/sections/data-spec/chunks.d.ts +23 -0
- package/dist/domain/spec/sections/data-spec/chunks.js +1 -0
- package/dist/domain/spec/sections/data-spec/custom-data-spec-entry.d.ts +16 -0
- package/dist/domain/spec/sections/data-spec/custom-data-spec-entry.js +1 -0
- package/dist/domain/spec/sections/data-spec/data-entry-key.d.ts +9 -0
- package/dist/domain/spec/sections/data-spec/data-entry-key.js +1 -0
- package/dist/domain/spec/sections/data-spec/index.d.ts +5 -0
- package/dist/domain/spec/sections/data-spec/index.js +1 -0
- package/dist/domain/spec/sections/data-spec/parsed-data-spec-entries.d.ts +10 -0
- package/dist/domain/spec/sections/data-spec/parsed-data-spec-entries.js +1 -0
- package/dist/domain/spec/sections/data-spec/swatch-data-spec-entry.d.ts +14 -0
- package/dist/domain/spec/sections/data-spec/swatch-data-spec-entry.js +1 -0
- package/dist/domain/spec/sections/index.d.ts +9 -0
- package/dist/domain/spec/sections/index.js +1 -0
- package/dist/domain/spec/sections/infra/acl.d.ts +12 -0
- package/dist/domain/spec/sections/infra/acl.js +1 -0
- package/dist/domain/spec/sections/infra/index.d.ts +3 -0
- package/dist/domain/spec/sections/infra/index.js +1 -0
- package/dist/domain/spec/sections/infra/resource-entry.d.ts +46 -0
- package/dist/domain/spec/sections/infra/resource-entry.js +1 -0
- package/dist/domain/spec/sections/infra/resources-config.d.ts +10 -0
- package/dist/domain/spec/sections/infra/resources-config.js +1 -0
- package/dist/domain/spec/sections/state-value.d.ts +7 -0
- package/dist/domain/spec/sections/state-value.js +1 -0
- package/dist/domain/spec/sections/theme.d.ts +10 -0
- package/dist/domain/spec/sections/theme.js +1 -0
- package/dist/domain/spec/sections/transformers.d.ts +15 -0
- package/dist/domain/spec/sections/transformers.js +1 -0
- package/dist/domain/spec/sections/ui.d.ts +12 -0
- package/dist/domain/spec/sections/ui.js +1 -0
- package/dist/domain/system-definitions.js +1 -1
- package/dist/domain/utils/index.d.ts +2 -0
- package/dist/domain/utils/index.js +1 -0
- package/dist/editor/graphql/GraphQLPanel.js +1 -1
- package/dist/i18n/locales/cs/messages.js +1 -1
- package/dist/i18n/locales/da/messages.js +1 -1
- package/dist/i18n/locales/de/messages.js +1 -1
- package/dist/i18n/locales/de-AT/messages.js +1 -1
- package/dist/i18n/locales/en/messages.js +1 -1
- package/dist/i18n/locales/en-AU/messages.js +1 -1
- package/dist/i18n/locales/en-GB/messages.js +1 -1
- package/dist/i18n/locales/es/messages.js +1 -1
- package/dist/i18n/locales/fr/messages.js +1 -1
- package/dist/i18n/locales/hu/messages.js +1 -1
- package/dist/i18n/locales/it/messages.js +1 -1
- package/dist/i18n/locales/nl/messages.js +1 -1
- package/dist/i18n/locales/pl/messages.js +1 -1
- package/dist/i18n/locales/pt/messages.js +1 -1
- package/dist/i18n/locales/ro/messages.js +1 -1
- package/dist/i18n/locales/sk/messages.js +1 -1
- package/dist/i18n/locales/tr/messages.js +1 -1
- package/dist/legacy/domain-spec/__generated/domain-schema.d.ts +2 -2
- package/dist/legacy/phoenix-cli/services/webhook-service/transport.js +1 -1
- package/dist/legacy/phoenix-cli/services/webhook-service/tunnel.d.ts +1 -0
- package/dist/legacy/phoenix-cli/services/webhook-service/tunnel.js +1 -1
- package/dist/legacy/webhook-cli/lambda-local/index.js +1 -1
- package/dist/phoenix/application-spec/generate-application-spec-project.d.ts +1 -0
- package/dist/phoenix/application-spec/generate-application-spec-project.js +2 -2
- package/dist/phoenix/application-spec/generate-project-files.d.ts +1 -0
- package/dist/phoenix/application-spec/index.d.ts +1 -0
- package/dist/phoenix/application-spec/index.js +1 -1
- package/dist/phoenix/application-spec/resolve-deployment-data.d.ts +11 -0
- package/dist/phoenix/application-spec/resolve-deployment-data.js +2 -2
- package/dist/phoenix/bin.js +1 -1
- package/dist/phoenix/cli.js +1 -1
- package/dist/phoenix/commands/activate-deployment.js +1 -1
- package/dist/phoenix/commands/build.js +1 -1
- package/dist/phoenix/commands/changelog.js +1 -1
- package/dist/phoenix/commands/check.js +1 -1
- package/dist/phoenix/commands/clean.js +1 -1
- package/dist/phoenix/commands/cleanup-environment.js +2 -2
- package/dist/phoenix/commands/create-environment.js +1 -1
- package/dist/phoenix/commands/data.js +1 -1
- package/dist/phoenix/commands/deploy.js +1 -1
- package/dist/phoenix/commands/deployment-build-envs-command.js +1 -1
- package/dist/phoenix/commands/dev.js +4 -5
- package/dist/phoenix/commands/docs.js +1 -1
- package/dist/phoenix/commands/finish-deployment-command.js +1 -1
- package/dist/phoenix/commands/fix.js +1 -1
- package/dist/phoenix/commands/index.d.ts +1 -1
- package/dist/phoenix/commands/index.js +1 -1
- package/dist/phoenix/commands/inspect-assets.js +1 -1
- package/dist/phoenix/commands/list-environments.js +1 -1
- package/dist/phoenix/commands/login.d.ts +4 -1
- package/dist/phoenix/commands/login.js +2 -2
- package/dist/phoenix/commands/prepare-deployment-command.js +2 -2
- package/dist/phoenix/commands/register-deployment.js +1 -1
- package/dist/phoenix/commands/scene.js +1 -1
- package/dist/phoenix/commands/screenshot.js +1 -1
- package/dist/phoenix/commands/state.js +1 -1
- package/dist/phoenix/commands/story-build.js +3 -3
- package/dist/phoenix/commands/story-create.js +1 -1
- package/dist/phoenix/commands/story-dev.js +2 -2
- package/dist/phoenix/commands/sync.js +1 -1
- package/dist/phoenix/commands/variants.js +1 -1
- package/dist/phoenix/editor-server/commands-router.js +1 -1
- package/dist/phoenix/editor-server/editor-server.d.ts +2 -13
- package/dist/phoenix/editor-server/editor-server.js +1 -1
- package/dist/phoenix/editor-server/spec-router.js +1 -1
- package/dist/phoenix/editor-server/trpc.d.ts +2 -12
- package/dist/phoenix/lingui/index.d.ts +1 -0
- package/dist/phoenix/lingui/index.js +1 -0
- package/dist/phoenix/lingui/lingui.d.ts +18 -0
- package/dist/phoenix/lingui/lingui.js +1 -0
- package/dist/phoenix/services/application-spec-project-watcher.d.ts +11 -6
- package/dist/phoenix/services/application-spec-project-watcher.js +2 -2
- package/dist/phoenix/services/cli-credentials.d.ts +3 -0
- package/dist/phoenix/services/cli-credentials.js +1 -1
- package/dist/phoenix/services/cli-exit.d.ts +5 -0
- package/dist/phoenix/services/cli-exit.js +1 -0
- package/dist/phoenix/services/deployment/deployment-preparation-service.d.ts +28 -0
- package/dist/phoenix/services/deployment/deployment-preparation-service.js +1 -0
- package/dist/phoenix/{commands → services/deployment}/generated-env-markers.d.ts +1 -0
- package/dist/phoenix/services/deployment/generated-env-markers.js +1 -0
- package/dist/phoenix/services/deployment/index.d.ts +2 -0
- package/dist/phoenix/services/deployment/index.js +1 -0
- package/dist/phoenix/services/index.d.ts +5 -1
- package/dist/phoenix/services/index.js +1 -1
- package/dist/phoenix/services/lingui-watcher.js +1 -1
- package/dist/phoenix/services/phoenix-store.d.ts +3 -0
- package/dist/phoenix/services/phoenix-store.js +1 -1
- package/dist/phoenix/services/prepare-development-environment.js +1 -1
- package/dist/phoenix/services/session/editor-server-handle.d.ts +5 -0
- package/dist/phoenix/services/session/editor-server-handle.js +1 -0
- package/dist/phoenix/services/session/index.d.ts +2 -0
- package/dist/phoenix/services/session/index.js +1 -0
- package/dist/phoenix/services/session/phoenix-application.d.ts +82 -0
- package/dist/phoenix/services/session/phoenix-application.js +2 -0
- package/dist/phoenix/services/telemetry/amplitude-telemetry-transport.d.ts +9 -0
- package/dist/phoenix/services/telemetry/amplitude-telemetry-transport.js +1 -0
- package/dist/phoenix/services/telemetry/index.d.ts +3 -0
- package/dist/phoenix/services/telemetry/index.js +1 -0
- package/dist/phoenix/services/telemetry/telemetry-client.d.ts +25 -0
- package/dist/phoenix/services/telemetry/telemetry-client.js +1 -0
- package/dist/phoenix/services/telemetry/telemetry-command.d.ts +2 -0
- package/dist/phoenix/services/telemetry/telemetry-command.js +1 -0
- package/dist/phoenix/services/telemetry/telemetry-event.d.ts +44 -0
- package/dist/phoenix/services/telemetry/telemetry-event.js +1 -0
- package/dist/phoenix/services/telemetry/telemetry-state.d.ts +25 -0
- package/dist/phoenix/services/telemetry/telemetry-state.js +2 -0
- package/dist/phoenix/services/vite-config.js +1 -1
- package/dist/phoenix/services/webhook-service/transport.js +1 -1
- package/dist/phoenix/services/webhook-service/tunnel.d.ts +1 -0
- package/dist/phoenix/services/webhook-service/tunnel.js +1 -1
- package/dist/react-sdk/application-runtime/domain-application-context/chat-system.d.ts +1 -1
- package/dist/{configurator/configurator-context → react-sdk}/configurator-routing/ConfiguratorRoutingProvider.d.ts +1 -1
- package/dist/react-sdk/configurator-routing/ConfiguratorRoutingProvider.js +1 -0
- package/dist/{configurator/configurator-context → react-sdk}/configurator-routing/OnGoToIndexHandler.d.ts +1 -2
- package/dist/react-sdk/configurator-routing/OnGoToIndexHandler.js +1 -0
- package/dist/react-sdk/configurator-routing/index.d.ts +3 -0
- package/dist/{configurator/configurator-context → react-sdk}/configurator-routing/index.js +1 -1
- package/dist/{configurator/configurator-context → react-sdk}/configurator-routing/use-power-routing-lifecycle.d.ts +2 -0
- package/dist/react-sdk/configurator-routing/use-power-routing-lifecycle.js +1 -0
- package/dist/react-sdk/domain-application-context/BackendDataProvider.js +1 -1
- package/dist/react-sdk/domain-application-context/ConfigurationPersistSystemFailureHandler.js +1 -1
- package/dist/react-sdk/domain-application-context/FrontendDataProvider.js +1 -1
- package/dist/react-sdk/domain-application-context/OnPresetLoadedHandler.js +1 -0
- package/dist/react-sdk/domain-application-context/PublishedDataProvider.js +1 -1
- package/dist/react-sdk/domain-application-context/chat-hooks.d.ts +4 -0
- package/dist/react-sdk/domain-application-context/chat-hooks.js +1 -0
- package/dist/react-sdk/domain-application-context/index.d.ts +2 -0
- package/dist/react-sdk/domain-application-context/index.js +1 -1
- package/dist/react-sdk/elements/PhoenixEntityElement.js +1 -1
- package/dist/react-sdk/elements/PhoenixLayoutElement.js +1 -1
- package/dist/react-sdk/index.d.ts +5 -0
- package/dist/react-sdk/index.js +1 -1
- package/dist/react-sdk/integration/IntegrationSubscription.js +1 -0
- package/dist/react-sdk/integration/index.d.ts +1 -0
- package/dist/react-sdk/integration/index.js +1 -0
- package/dist/react-sdk/lifecycle-providers/ConfiguratorDataProvider.d.ts +8 -0
- package/dist/react-sdk/lifecycle-providers/ConfiguratorDataProvider.js +1 -0
- package/dist/react-sdk/lifecycle-providers/LifecycleProviders.js +1 -0
- package/dist/react-sdk/lifecycle-providers/index.d.ts +2 -0
- package/dist/react-sdk/lifecycle-providers/index.js +1 -0
- package/dist/react-sdk/notifications/index.d.ts +1 -0
- package/dist/react-sdk/notifications/index.js +1 -0
- package/dist/react-sdk/notifications/snackbar-action-button.d.ts +30 -0
- package/dist/react-sdk/notifications/snackbar-action-button.js +1 -0
- package/dist/react-sdk/preset-selection/PresetSelectionProvider.js +1 -0
- package/dist/react-sdk/preset-selection/index.d.ts +1 -0
- package/dist/react-sdk/preset-selection/index.js +1 -0
- package/dist/react-sdk/session/SessionServiceProvider.d.ts +5 -0
- package/dist/react-sdk/session/SessionServiceProvider.js +1 -1
- package/dist/ui-sdk/components/snackbar/Snackbar.d.ts +24 -3
- package/dist/ui-sdk/components/snackbar/Snackbar.js +1 -1
- package/dist/ui-sdk/icons/__generated/Paperclip.d.ts +3 -0
- package/dist/ui-sdk/icons/__generated/Paperclip.js +1 -0
- package/dist/ui-sdk/icons/__generated/index.d.ts +2 -0
- package/dist/ui-sdk/icons/__generated/index.js +1 -1
- package/dist/ui-sdk/icons/icons-registry.js +1 -1
- package/dist/ui-sdk/theme/types.d.ts +1 -1
- package/dist/watch/glob-matcher.d.ts +4 -4
- package/dist/watch/glob-matcher.js +1 -1
- package/dist/watch/watch.d.ts +4 -4
- package/dist/watch/watch.js +1 -1
- package/package.json +3 -3
- package/schema/domain-spec.json +22 -4
- package/dist/application-spec/core/components/index.d.ts +0 -2
- package/dist/application-spec/core/expressions/index.d.ts +0 -2
- package/dist/configurator/configurator-context/ConfiguratorDataProvider.d.ts +0 -2
- package/dist/configurator/configurator-context/ConfiguratorDataProvider.js +0 -1
- package/dist/configurator/configurator-context/IntegrationSubscription.js +0 -1
- package/dist/configurator/configurator-context/LifecycleProviders.js +0 -1
- package/dist/configurator/configurator-context/OnPresetLoadedHandler.js +0 -1
- package/dist/configurator/configurator-context/PresetSelectionProvider.js +0 -1
- package/dist/configurator/configurator-context/configurator-hooks/chat-hooks.d.ts +0 -1
- package/dist/configurator/configurator-context/configurator-hooks/chat-hooks.js +0 -1
- package/dist/configurator/configurator-context/configurator-routing/ConfiguratorRoutingProvider.js +0 -1
- package/dist/configurator/configurator-context/configurator-routing/OnGoToIndexHandler.js +0 -1
- package/dist/configurator/configurator-context/configurator-routing/index.d.ts +0 -2
- package/dist/configurator/configurator-context/configurator-routing/use-power-routing-lifecycle.js +0 -1
- package/dist/domain/available-system-components.d.ts +0 -11
- package/dist/domain/available-system-components.js +0 -1
- package/dist/domain/domain-builder.js +0 -1
- package/dist/phoenix/commands/generated-env-markers.js +0 -1
- package/dist/phoenix/services/lingui.d.ts +0 -15
- package/dist/phoenix/services/lingui.js +0 -1
- package/dist/phoenix/services/phoenix-application.d.ts +0 -21
- package/dist/phoenix/services/phoenix-application.js +0 -1
- /package/dist/{application-spec/core/expressions/relation-expression-params.js → domain/spec/application/admin-pages-section.js} +0 -0
- /package/dist/{application-spec/parse-application-files/spec/components/component-entry.js → domain/spec/application/admin-pages.js} +0 -0
- /package/dist/{application-spec/parse-application-files/spec/expressions/expression.js → domain/spec/application/admin-states.js} +0 -0
- /package/dist/{application-spec/core → domain/spec/application}/application-instance.d.ts +0 -0
- /package/dist/{application-spec/core → domain/spec/application}/application-instance.js +0 -0
- /package/dist/{application-spec/core → domain/spec}/components/component-filter.js +0 -0
- /package/dist/{application-spec/core → domain/spec}/components/index.js +0 -0
- /package/dist/{application-spec/core → domain/spec}/components/sdk-code-ref.d.ts +0 -0
- /package/dist/{application-spec/core → domain/spec}/components/sdk-code-ref.js +0 -0
- /package/dist/{application-spec/core → domain/spec}/expressions/index.js +0 -0
- /package/dist/{application-spec/core → domain/spec}/expressions/relation-expression-params.d.ts +0 -0
- /package/dist/{application-spec/core → domain/spec}/expressions/sdk-expression-implementation.d.ts +0 -0
- /package/dist/{application-spec/core → domain/spec}/expressions/sdk-expression-implementation.js +0 -0
- /package/dist/{application-spec/parse-application-files/spec/components → domain/spec/markers}/component-prop-target.d.ts +0 -0
- /package/dist/{application-spec/parse-application-files/spec/components → domain/spec/markers}/component-prop-target.js +0 -0
- /package/dist/{application-spec/core → domain/spec}/markers/eval-marker.d.ts +0 -0
- /package/dist/{application-spec/core → domain/spec}/markers/eval-marker.js +0 -0
- /package/dist/{configurator/configurator-context → react-sdk/domain-application-context}/OnPresetLoadedHandler.d.ts +0 -0
- /package/dist/{configurator/configurator-context → react-sdk/integration}/IntegrationSubscription.d.ts +0 -0
- /package/dist/{configurator/configurator-context → react-sdk/lifecycle-providers}/LifecycleProviders.d.ts +0 -0
- /package/dist/{configurator/configurator-context → react-sdk/preset-selection}/PresetSelectionProvider.d.ts +0 -0
|
@@ -56,6 +56,21 @@ export interface AssistantChatSnapshot {
|
|
|
56
56
|
/** True while that older thread is being loaded. */
|
|
57
57
|
readonly isLoadingEarlierThread: boolean;
|
|
58
58
|
}
|
|
59
|
+
/** What else the caller of {@link AssistantSystem.send} learns about the message. */
|
|
60
|
+
export interface AssistantSendOptions {
|
|
61
|
+
/**
|
|
62
|
+
* Called once the message is handed to the chat, which paints it: after its images were uploaded,
|
|
63
|
+
* and not at all when it is not sent because the thread could not be resumed or an upload failed.
|
|
64
|
+
* The composer keeps the message until then, so a message that is not sent can be sent again.
|
|
65
|
+
*/
|
|
66
|
+
readonly onSent?: () => void;
|
|
67
|
+
/**
|
|
68
|
+
* Called when a message that was handed to the chat is gone from it after all: the server refused
|
|
69
|
+
* it because the thread could not continue, the thread was resumed without it, and its images
|
|
70
|
+
* could not be uploaded into the new thread. The caller gets it back, so it can be sent again.
|
|
71
|
+
*/
|
|
72
|
+
readonly onUnsent?: () => void;
|
|
73
|
+
}
|
|
59
74
|
/** A closed thread of the conversation as the panel paints it above the thread that continues it. */
|
|
60
75
|
export interface AssistantEarlierThreadSnapshot {
|
|
61
76
|
readonly threadId: string;
|
|
@@ -136,6 +151,11 @@ export declare class AssistantSystem implements InitializableSystem {
|
|
|
136
151
|
*/
|
|
137
152
|
private readonly _applyToolCallIds;
|
|
138
153
|
private readonly _undoTipToolCallId;
|
|
154
|
+
/**
|
|
155
|
+
* Object URLs of the screenshots read so far, by image id. An uploaded image never changes, so
|
|
156
|
+
* each is read once and kept while the configuration stays loaded.
|
|
157
|
+
*/
|
|
158
|
+
private _screenshotUrls;
|
|
139
159
|
constructor(_context: AssistantSystemContext);
|
|
140
160
|
/** The conversation. It never completes, and holds the empty chat whenever no chat is active. */
|
|
141
161
|
readonly chat$: ObservableWithLastValue<AssistantChatSnapshot>;
|
|
@@ -194,6 +214,12 @@ export declare class AssistantSystem implements InitializableSystem {
|
|
|
194
214
|
* acted, which the server puts in front of the message for the model. The record is taken only
|
|
195
215
|
* when there is a chat to send it on, because taking it moves its baseline.
|
|
196
216
|
*
|
|
217
|
+
* The images the user attached go with the message: they are uploaded into the chat's thread
|
|
218
|
+
* first, and the message references them, one image part after its text each. The text part is
|
|
219
|
+
* left out of a message with images only. Each attempt to send uploads them again, into the
|
|
220
|
+
* thread it sends on. An upload that fails leaves the message unsent, with the failure as the
|
|
221
|
+
* error of the chat; `onSent` is not called then.
|
|
222
|
+
*
|
|
197
223
|
* A thread can end in a tool call that nothing will answer: its reply parked while no page was
|
|
198
224
|
* open, or the page that ran the tool was left before the result was sent. The client refuses to
|
|
199
225
|
* send while it waits on such a call, so the wait is given up first, and the server records for
|
|
@@ -204,20 +230,28 @@ export declare class AssistantSystem implements InitializableSystem {
|
|
|
204
230
|
*
|
|
205
231
|
* The chat can be out of date about that: the thread reached its size limit with the reply before
|
|
206
232
|
* this message, or the assistant's setup changed while the configurator stayed open. The server
|
|
207
|
-
* then refuses the message and says that the thread cannot
|
|
208
|
-
*
|
|
209
|
-
* record it was first sent with. This happens once: a
|
|
210
|
-
* failure it is. When resuming fails,
|
|
211
|
-
* painted, with the failure as the error of the chat
|
|
233
|
+
* then refuses the message, or the upload of one of its images, and says that the thread cannot
|
|
234
|
+
* be continued. The thread is resumed, and the message is then sent again on the new thread, its
|
|
235
|
+
* images uploaded again, with the change record it was first sent with. This happens once: a
|
|
236
|
+
* refusal of the second attempt is the failure it is. When resuming fails, a refused message is
|
|
237
|
+
* left as any message that failed to send: painted, with the failure as the error of the chat; a
|
|
238
|
+
* refused upload leaves the message unsent. When the images of a refused message cannot be
|
|
239
|
+
* uploaded into the new thread, the message is given back through `onUnsent`.
|
|
240
|
+
*
|
|
241
|
+
* A chat that ends while the images upload, because another configuration was loaded or the
|
|
242
|
+
* thread is read again, sends nothing.
|
|
212
243
|
*
|
|
213
244
|
* Accepted: when the server refuses the compaction itself with a conflict, because another tab
|
|
214
245
|
* compacted the thread or a run is still running, the thread is read again (see `resume`) and
|
|
215
246
|
* the refused message is gone without a notice. It takes two tabs or a run racing the send, and
|
|
216
247
|
* the user writes the message again, as after any reload of a thread that failed.
|
|
217
248
|
*
|
|
249
|
+
* Accepted: images uploaded by an attempt that is not sent stay stored in that thread, which no
|
|
250
|
+
* message references.
|
|
251
|
+
*
|
|
218
252
|
* It never rejects: a message the client could not send is reported as the error of the chat.
|
|
219
253
|
*/
|
|
220
|
-
send: (content: string) => Promise<void>;
|
|
254
|
+
send: (content: string, images?: ReadonlyArray<Blob>, { onSent, onUnsent }?: AssistantSendOptions) => Promise<void>;
|
|
221
255
|
/**
|
|
222
256
|
* Makes the chat ready for the next message. A thread the server no longer lets this session
|
|
223
257
|
* continue, because the assistant's setup changed since it was started or the thread reached
|
|
@@ -231,6 +265,12 @@ export declare class AssistantSystem implements InitializableSystem {
|
|
|
231
265
|
* refuses with a conflict is not a failure: the thread is read again and `false` is returned.
|
|
232
266
|
*/
|
|
233
267
|
resume: () => Promise<boolean>;
|
|
268
|
+
/**
|
|
269
|
+
* An object URL of a screenshot of the conversation, by the id its tool result references it by.
|
|
270
|
+
* It is read from the server through the client of the current chat, once per image; a read that
|
|
271
|
+
* failed is forgotten, so it can be asked for again. Rejects without a chat or when the read fails.
|
|
272
|
+
*/
|
|
273
|
+
loadScreenshotUrl: (imageId: string) => Promise<string>;
|
|
234
274
|
/**
|
|
235
275
|
* Loads the thread before the oldest painted one and paints it above. Does nothing when there is
|
|
236
276
|
* none or one is being loaded. A load that fails is logged and can be asked for again.
|
|
@@ -265,6 +305,22 @@ export declare class AssistantSystem implements InitializableSystem {
|
|
|
265
305
|
* is no such message. A refused continuation of a reply is not one: its message is stored.
|
|
266
306
|
*/
|
|
267
307
|
private _findRefusedMessageIndex;
|
|
308
|
+
/** The content of a user message: its text, when it has any, and a reference to each of its images. */
|
|
309
|
+
private _messageContent;
|
|
310
|
+
/**
|
|
311
|
+
* Uploads the images of a message into the chat's thread, in their order, and resolves with their
|
|
312
|
+
* ids. Resolves with `'refused'` when the server refused an upload because the thread cannot be
|
|
313
|
+
* continued, and marks the chat so; then with `null` for any other failure, which is reported as
|
|
314
|
+
* the error of the chat. It never rejects.
|
|
315
|
+
*/
|
|
316
|
+
private _uploadImages;
|
|
317
|
+
/**
|
|
318
|
+
* Uploads the images of a message into the thread that was resumed for it. A message the chat
|
|
319
|
+
* refused shows nowhere meanwhile, so the chat stays resuming until the upload is over: nothing
|
|
320
|
+
* else is sent ahead of it.
|
|
321
|
+
*/
|
|
322
|
+
private _uploadSuccessorImages;
|
|
323
|
+
private _reportUploadFailure;
|
|
268
324
|
private _sendOn;
|
|
269
325
|
private _resume;
|
|
270
326
|
/**
|
|
@@ -300,6 +356,8 @@ export declare class AssistantSystem implements InitializableSystem {
|
|
|
300
356
|
* it is: whether it finishes its reply or is cut off is the caller's decision.
|
|
301
357
|
*/
|
|
302
358
|
private _retireChat;
|
|
359
|
+
/** Revokes the object URLs of the screenshots read for the configuration that was loaded, also those still being read. */
|
|
360
|
+
private _releaseScreenshotUrls;
|
|
303
361
|
/** Ends the current chat without cutting its reply off. */
|
|
304
362
|
private _endChat;
|
|
305
363
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{ChatClient as e,fetchServerSentEvents as t}from"@tanstack/ai-client";import{BehaviorSubject as i}from"rxjs";import{skip as s}from"rxjs/operators";import{isShallowEqual as a}from"@salsita-ai/common/utils";import{AssistantRequestError as r}from"#package/client";import{createBrowserDetailsClientTool as n}from"./browser-details.js";import{ChangeRecorder as o}from"./change-recorder.js";import{createApplyClientTool as l,createQueryClientTool as h,toToolResult as d}from"./graphql-tools.js";let c=Object.freeze({messages:Object.freeze([]),isLoading:!1,error:void 0,failedStatus:void 0,isContinuable:!0,isLoaded:!1,isResuming:!1,earlierThreads:Object.freeze([]),hasEarlierThread:!1,isLoadingEarlierThread:!1}),u=Object.freeze({open:!1,hasUnreadReply:!1,isInputFocused:!1}),_=Object.freeze({}),g=d({results:[],committed:!1,sideEffects:[],screenshots:new Map,message:"Nothing was run, because the user closed the configurator while this reply was being written. Do not call any more tools in this reply and end it now. The tools work again as soon as the user writes the next message."}),m=e=>{if(e.getError())return!0;let t=e.getMessages().at(-1)?.parts.at(-1);return t?.type!=="tool-call"&&t?.type!=="tool-result"};export class AssistantSystem{_context;_tools;_chat=new i(c);_panel=new i(u);_activation=null;_current=null;_finishing=new Set;_olderThreadId=null;_resuming=null;_refused=null;_firstAttempt=null;_chain={};_loadingThreadId=null;_recorder;_recording=null;_applyToolCallIds=new WeakMap;_undoTipToolCallId=new i(void 0);constructor(e){this._context=e;let{configuratorExtensionSelectors:t,domainContextSelectors:i,domainServicesSelectors:s,getAssistantSetup:a}=e;this._recorder=new o({maxEntities:30},{readers:{selectedEntityId:e=>i.getNavigationSystem().getActiveSelectionState(e),navigationState:e=>i.getNavigationSystem().getActiveNavigationState(e),viewState:e=>i.getNavigationSystem().getActiveViewState(e),toolState:e=>i.getNavigationSystem().getActiveToolState(e)},getExposedFields:()=>a().manifest?.fields??_,resolveLocalizable:e=>s.getResolveLocalizable()(e)});let r={getGraphQLSystem:()=>t.getGraphQLSystem(),getStoreSystem:()=>i.getStoreSystem(),getActiveMode:()=>i.getActiveMode(),getIsViewMode:()=>i.getIsViewMode(),clearChanges:()=>this._recorder.clear(this._committedState()),rememberCommit:(e,t)=>{this._applyToolCallIds.set(t,e),this._refreshUndoTip()}};this._tools=[n(),h(r),l(r)],i.getUndoSystem().tip$.subscribe(this._refreshUndoTip)}chat$=this._chat;panel$=this._panel;undoTipToolCallId$=this._undoTipToolCallId;getSessionManifest=()=>this._context.getAssistantSetup().manifest;initialize=()=>{let{committed:e}=this._context.domainContextSelectors.getStoreSystem().stateSlices;this._recording??=e.pipe(s(1)).subscribe(this._recorder.record),this._recorder.reset(e.value.state),this._endChat(),this._patchPanel(u),this._activation&&this._startClient()};activate=()=>{this._endChat();let e={};return this._activation=e,this._startClient(),()=>{this._activation===e&&(this._activation=null,this._endChat())}};send=async e=>{if(!this._chat.value.isContinuable&&!await this.resume())return;let t=this._current;if(!t)return;let i={changes:this._recorder.take(this._committedState())};this._firstAttempt=t;try{await this._sendOn(t,e,i);let s=this._findRefusedMessageIndex(t);if(-1===s)return;this._refused={chat:t,index:s}}finally{this._firstAttempt===t&&(this._firstAttempt=null)}if(!await this.resume())return;let s=this._current;s&&await this._sendOn(s,e,i)};resume=async()=>{let e=this._current;if(!e)return!1;if(this._chat.value.isContinuable)return!0;if(this._resuming)return this._resuming;let t=this._resume(e).finally(()=>{this._resuming===t&&(this._resuming=null)});return this._resuming=t,t};loadEarlierThread=async()=>{let e=this._current,t=this._olderThreadId;if(!e||null===t||this._loadingThreadId===t)return;let i=this._chain;this._loadingThreadId=t,this._chat.next({...this._chat.value,isLoadingEarlierThread:!0});try{let s=await e.authorizedClient.getAssistantEarlierThread(e.configurationId,t,50);if(this._chain!==i||this._olderThreadId!==t)return;this._olderThreadId=s.previousThreadId,this._chat.next({...this._chat.value,earlierThreads:[{threadId:t,messages:s.messages},...this._chat.value.earlierThreads],hasEarlierThread:null!==s.previousThreadId})}catch(e){this._context.domainServicesSelectors.getLogger().warn("Could not load the earlier assistant conversation",{error:e})}finally{this._chain===i&&this._loadingThreadId===t&&(this._loadingThreadId=null,this._chat.next({...this._chat.value,isLoadingEarlierThread:!1}))}};stop=async()=>{let e=this._current;if(!e)return;let t=e.client.getCurrentRunId();if(e.client.stop(),null!=t)try{let i=e.getConnection();await fetch(`${i.url}/runs/${encodeURIComponent(t)}/cancel`,{method:"POST",headers:await i.headers()})}catch(e){this._context.domainServicesSelectors.getLogger().warn("Could not cancel the assistant run on the server",{error:e})}};reloadThread=()=>{if(!this._activation)return;let e=this._retireChat();e?.client.stop(),e?.dispose(),this._recorder.reset(this._committedState()),this._startClient()};undoToolCalls=e=>{let t=this._context.domainContextSelectors.getUndoSystem(),i=()=>{let t=this._findTipToolCallId();return void 0!==t&&e.has(t)};for(;i();)t.undo()};setOpen=e=>{this._patchPanel(e?{open:e,hasUnreadReply:!1}:{open:e,isInputFocused:!1})};setInputFocused=e=>{this._patchPanel({isInputFocused:e})};_findRefusedMessageIndex=e=>{var t;let i,{failedStatus:s,isContinuable:a}=this._chat.value;return this._firstAttempt===e&&e.generation.active&&409===s&&!a?(i=(t=e.client.getMessages()).map(e=>e.role).lastIndexOf("user"),t.slice(i+1).every(e=>0===e.parts.length)?i:-1):-1};_sendOn=async(e,t,i)=>{let{client:s}=e;s.getIsLoading()||null===s.getResumeState()||s.stop();try{await s.sendMessage({content:t,metadata:i})}catch(i){let t=i instanceof Error?i:Error(String(i));e.generation.active&&this._chat.next({...this._chat.value,error:t}),this._context.domainServicesSelectors.getLogger().error("The assistant message could not be sent",{},t)}};_resume=async e=>{this._chat.next({...this._chat.value,isResuming:!0,error:void 0,failedStatus:void 0});try{let{previousThreadId:t}=await e.authorizedClient.compactAssistantThread(e.configurationId);if(!e.generation.active)return!1;let{messages:i,earlierThreads:s,hasEarlierThread:a}=this._chat.value,r=this._refused?.chat===e?i.slice(0,this._refused.index):i;return e.generation.active=!1,this._current=null,e.client.stop(),e.dispose(),this._chat.next({...c,earlierThreads:[...s,{threadId:t,messages:r}],hasEarlierThread:a,isLoadingEarlierThread:null!==this._loadingThreadId}),this._startClient(),!0}catch(i){let t=i instanceof Error?i:Error(String(i));if(t instanceof r&&409===t.status)return e.generation.active&&this.reloadThread(),!1;return e.generation.active&&this._chat.next({...this._chat.value,isResuming:!1,error:t,failedStatus:t instanceof r?t.status:void 0}),this._context.domainServicesSelectors.getLogger().error("The assistant thread could not be resumed",{},t),!1}};_findTipToolCallId=()=>{let e=this._context.domainContextSelectors.getUndoSystem(),t=e.tip$.value?.committedState;return void 0!==t&&e.canUndo()?this._applyToolCallIds.get(t):void 0};_refreshUndoTip=()=>{let e=this._findTipToolCallId();e!==this._undoTipToolCallId.value&&this._undoTipToolCallId.next(e)};_committedState=()=>this._context.domainContextSelectors.getStoreSystem().stateSlices.committed.value.state;_patchPanel=e=>{let t={...this._panel.value,...e};a(t,this._panel.value)||this._panel.next(t)};_takeOverThread=e=>{for(let t of this._finishing)t.configurationId===e&&(t.client.stop(),t.dispose())};_startClient=()=>{let i={active:!0},s=this._context.getConfigurationId();this._takeOverThread(s);let r=this._context.getAuthorizedClient(),n=()=>{if(i.active){let{manifest:e,error:t}=this._context.getAssistantSetup();if(t)throw t;if(!e)throw Error("The assistant is disabled for this session.")}return r.getAssistantChatConnection(s)},o=e=>{if(!i.active)return;let t={...this._chat.value,...e};a(t,this._chat.value)||this._chat.next(t)},l=async(e,t)=>{let s=await fetch(e,t).finally(()=>o({isLoaded:!0})),a=s.headers.get("x-assistant-thread-continuable");return null!=a&&s.ok&&i.active&&0===this._chat.value.earlierThreads.length&&(this._olderThreadId=s.headers.get("x-assistant-previous-thread")),o({failedStatus:s.ok?void 0:s.status,...null!=a&&{isContinuable:"false"!==a,hasEarlierThread:null!==this._olderThreadId}}),s},h=async()=>({headers:await n().headers(),fetchClient:l}),d=t(()=>n().url,h),c=t(()=>`${n().url}/runs`,h),u=this._tools.map(e=>({...e,execute:(t,s)=>{if(!i.active)return g;let{manifest:a,error:r}=this._context.getAssistantSetup();return r||!a?{error:r?.message??"The assistant is disabled for this session."}:e.execute?.(t,s)}})),_=new e({threadId:`assistant:${s}`,connection:{...d,joinRun:c.joinRun},persistence:!0,history:{pageSize:50},tools:u,onMessagesChange:e=>o({messages:e}),onLoadingChange:e=>{let t=i.active&&this._chat.value.isLoading;o({isLoading:e}),!e&&m(_)&&(i.active?t&&!this._panel.value.open&&this._patchPanel({hasUnreadReply:!0}):p())},onErrorChange:e=>{i.active&&e!==this._chat.value.error&&(!e||-1===this._findRefusedMessageIndex(v))&&(o({error:e}),e&&this._context.domainServicesSelectors.getLogger().error("The assistant request failed",{status:this._chat.value.failedStatus},e))}}),f=!1,p=()=>{f||(f=!0,this._finishing.delete(v),_.dispose())},v={client:_,configurationId:s,generation:i,authorizedClient:r,getConnection:n,dispose:p};this._current=v,_.attach()};_retireChat=()=>{let e=this._current;return this._current=null,e&&(e.generation.active=!1),this._chain={},this._olderThreadId=null,this._resuming=null,this._refused=null,this._loadingThreadId=null,this._chat.value!==c&&this._chat.next(c),e};_endChat=()=>{let e=this._retireChat();if(e){if(!e.client.getIsLoading()&&m(e.client))return void e.dispose();this._finishing.add(e)}}}
|
|
1
|
+
import{ChatClient as e,fetchServerSentEvents as t}from"@tanstack/ai-client";import{BehaviorSubject as i}from"rxjs";import{skip as s}from"rxjs/operators";import{isShallowEqual as a}from"@salsita-ai/common/utils";import{assistantImageReference as r}from"@salsita-ai/contracts/assistant";import{AssistantRequestError as n}from"#package/client";import{createBrowserDetailsClientTool as o}from"./browser-details.js";import{ChangeRecorder as l}from"./change-recorder.js";import{createApplyClientTool as h,createQueryClientTool as c,toToolResult as d}from"./graphql-tools.js";let u=Object.freeze({messages:Object.freeze([]),isLoading:!1,error:void 0,failedStatus:void 0,isContinuable:!0,isLoaded:!1,isResuming:!1,earlierThreads:Object.freeze([]),hasEarlierThread:!1,isLoadingEarlierThread:!1}),_=Object.freeze({open:!1,hasUnreadReply:!1,isInputFocused:!1}),g=Object.freeze({}),f=d({results:[],committed:!1,sideEffects:[],warnings:[],screenshots:new Map,message:"Nothing was run, because the user closed the configurator while this reply was being written. Do not call any more tools in this reply and end it now. The tools work again as soon as the user writes the next message."}),m=e=>{if(e.getError())return!0;let t=e.getMessages().at(-1)?.parts.at(-1);return t?.type!=="tool-call"&&t?.type!=="tool-result"};export class AssistantSystem{_context;_tools;_chat=new i(u);_panel=new i(_);_activation=null;_current=null;_finishing=new Set;_olderThreadId=null;_resuming=null;_refused=null;_firstAttempt=null;_chain={};_loadingThreadId=null;_recorder;_recording=null;_applyToolCallIds=new WeakMap;_undoTipToolCallId=new i(void 0);_screenshotUrls=new Map;constructor(e){this._context=e;let{configuratorExtensionSelectors:t,domainContextSelectors:i,domainServicesSelectors:s,getAssistantSetup:a}=e;this._recorder=new l({maxEntities:30},{readers:{selectedEntityId:e=>i.getNavigationSystem().getActiveSelectionState(e),navigationState:e=>i.getNavigationSystem().getActiveNavigationState(e),viewState:e=>i.getNavigationSystem().getActiveViewState(e),toolState:e=>i.getNavigationSystem().getActiveToolState(e)},getExposedFields:()=>a().manifest?.fields??g,resolveLocalizable:e=>s.getResolveLocalizable()(e)});let r={getGraphQLSystem:()=>t.getGraphQLSystem(),getStoreSystem:()=>i.getStoreSystem(),getActiveMode:()=>i.getActiveMode(),getIsViewMode:()=>i.getIsViewMode(),clearChanges:()=>this._recorder.clear(this._committedState()),rememberCommit:(e,t)=>{this._applyToolCallIds.set(t,e),this._refreshUndoTip()}};this._tools=[o(),c(r),h(r)],i.getUndoSystem().tip$.subscribe(this._refreshUndoTip)}chat$=this._chat;panel$=this._panel;undoTipToolCallId$=this._undoTipToolCallId;getSessionManifest=()=>this._context.getAssistantSetup().manifest;initialize=()=>{let{committed:e}=this._context.domainContextSelectors.getStoreSystem().stateSlices;this._recording??=e.pipe(s(1)).subscribe(this._recorder.record),this._recorder.reset(e.value.state),this._endChat(),this._patchPanel(_),this._releaseScreenshotUrls(),this._activation&&this._startClient()};activate=()=>{this._endChat();let e={};return this._activation=e,this._startClient(),()=>{this._activation===e&&(this._activation=null,this._endChat())}};send=async(e,t=[],{onSent:i,onUnsent:s}={})=>{if(!this._chat.value.isContinuable&&!await this.resume())return;let a=this._current;if(!a)return;let r={changes:this._recorder.take(this._committedState()),locale:this._context.domainServicesSelectors.getI18n().locale},n=()=>this._recorder.reset(this._committedState()),o=!1,l=(t,s)=>(o||(o=!0,i?.()),this._sendOn(t,this._messageContent(e,s),r));this._firstAttempt=a;try{let e=0===t.length?[]:await this._uploadImages(a,t);if(null===e||!a.generation.active)return void n();if("refused"!==e){await l(a,e);let t=this._findRefusedMessageIndex(a);if(-1===t)return;this._refused={chat:a,index:t}}}finally{this._firstAttempt===a&&(this._firstAttempt=null)}if(!await this.resume()){o||n();return}let h=this._current,c=h?await this._uploadSuccessorImages(h,t):null;if(!h||null===c||"refused"===c||!h.generation.active){h&&"refused"===c&&this._reportUploadFailure(h,this._chat.value.error),o&&s?.(),n();return}await l(h,c)};resume=async()=>{let e=this._current;if(!e)return!1;if(this._chat.value.isContinuable)return!0;if(this._resuming)return this._resuming;let t=this._resume(e).finally(()=>{this._resuming===t&&(this._resuming=null)});return this._resuming=t,t};loadScreenshotUrl=e=>{let t=this._screenshotUrls.get(e);if(t)return t;let i=this._current;if(!i)return Promise.reject(Error(`The screenshot ${e} cannot be read, because the assistant chat is not active. Open the assistant panel of the configuration first.`));let s=this._screenshotUrls,a=i.authorizedClient.getAssistantImage(i.configurationId,e).then(e=>URL.createObjectURL(e));return s.set(e,a),a.catch(()=>{s.get(e)===a&&s.delete(e)}),a};loadEarlierThread=async()=>{let e=this._current,t=this._olderThreadId;if(!e||null===t||this._loadingThreadId===t)return;let i=this._chain;this._loadingThreadId=t,this._chat.next({...this._chat.value,isLoadingEarlierThread:!0});try{let s=await e.authorizedClient.getAssistantEarlierThread(e.configurationId,t,50);if(this._chain!==i||this._olderThreadId!==t)return;this._olderThreadId=s.previousThreadId,this._chat.next({...this._chat.value,earlierThreads:[{threadId:t,messages:s.messages},...this._chat.value.earlierThreads],hasEarlierThread:null!==s.previousThreadId})}catch(e){this._context.domainServicesSelectors.getLogger().warn("Could not load the earlier assistant conversation",{error:e})}finally{this._chain===i&&this._loadingThreadId===t&&(this._loadingThreadId=null,this._chat.next({...this._chat.value,isLoadingEarlierThread:!1}))}};stop=async()=>{let e=this._current;if(!e)return;let t=e.client.getCurrentRunId();if(e.client.stop(),null!=t)try{let i=e.getConnection();await fetch(`${i.url}/runs/${encodeURIComponent(t)}/cancel`,{method:"POST",headers:await i.headers()})}catch(e){this._context.domainServicesSelectors.getLogger().warn("Could not cancel the assistant run on the server",{error:e})}};reloadThread=()=>{if(!this._activation)return;let e=this._retireChat();e?.client.stop(),e?.dispose(),this._recorder.reset(this._committedState()),this._startClient()};undoToolCalls=e=>{let t=this._context.domainContextSelectors.getUndoSystem(),i=()=>{let t=this._findTipToolCallId();return void 0!==t&&e.has(t)};for(;i();)t.undo()};setOpen=e=>{this._patchPanel(e?{open:e,hasUnreadReply:!1}:{open:e,isInputFocused:!1})};setInputFocused=e=>{this._patchPanel({isInputFocused:e})};_findRefusedMessageIndex=e=>{var t;let i,{failedStatus:s,isContinuable:a}=this._chat.value;return this._firstAttempt===e&&e.generation.active&&409===s&&!a?(i=(t=e.client.getMessages()).map(e=>e.role).lastIndexOf("user"),t.slice(i+1).every(e=>0===e.parts.length)?i:-1):-1};_messageContent=(e,t)=>0===t.length?e:[...e?[{type:"text",content:e}]:[],...t.map(e=>({type:"image",source:{type:"url",value:r(e)}}))];_uploadImages=async(e,t)=>{if(0===t.length)return[];e.generation.active&&this._chat.next({...this._chat.value,error:void 0,failedStatus:void 0});try{return(await Promise.all(t.map(t=>e.authorizedClient.uploadAssistantImage(e.configurationId,t)))).map(({imageId:e})=>e)}catch(i){let t=i instanceof Error?i:Error(String(i));if(t instanceof n&&t.threadNotContinuable)return e.generation.active&&this._chat.next({...this._chat.value,isContinuable:!1,error:t,failedStatus:t.status}),"refused";return this._reportUploadFailure(e,t),null}};_uploadSuccessorImages=async(e,t)=>{if(0===t.length)return[];this._chat.next({...this._chat.value,isResuming:!0});try{return await this._uploadImages(e,t)}finally{e.generation.active&&this._chat.next({...this._chat.value,isResuming:!1})}};_reportUploadFailure=(e,t)=>{e.generation.active&&this._chat.next({...this._chat.value,error:t,failedStatus:t instanceof n?t.status:void 0}),this._context.domainServicesSelectors.getLogger().error("The images of the assistant message could not be uploaded",{},t)};_sendOn=async(e,t,i)=>{let{client:s}=e;s.getIsLoading()||null===s.getResumeState()||s.stop();try{await s.sendMessage({content:t,metadata:i})}catch(i){let t=i instanceof Error?i:Error(String(i));e.generation.active&&this._chat.next({...this._chat.value,error:t}),this._context.domainServicesSelectors.getLogger().error("The assistant message could not be sent",{},t)}};_resume=async e=>{this._chat.next({...this._chat.value,isResuming:!0,error:void 0,failedStatus:void 0});try{let{previousThreadId:t}=await e.authorizedClient.compactAssistantThread(e.configurationId);if(!e.generation.active)return!1;let{messages:i,earlierThreads:s,hasEarlierThread:a}=this._chat.value,r=this._refused?.chat===e?i.slice(0,this._refused.index):i;return e.generation.active=!1,this._current=null,e.client.stop(),e.dispose(),this._chat.next({...u,earlierThreads:[...s,{threadId:t,messages:r}],hasEarlierThread:a,isLoadingEarlierThread:null!==this._loadingThreadId}),this._startClient(),!0}catch(i){let t=i instanceof Error?i:Error(String(i));if(t instanceof n&&409===t.status)return e.generation.active&&this.reloadThread(),!1;return e.generation.active&&this._chat.next({...this._chat.value,isResuming:!1,error:t,failedStatus:t instanceof n?t.status:void 0}),this._context.domainServicesSelectors.getLogger().error("The assistant thread could not be resumed",{},t),!1}};_findTipToolCallId=()=>{let e=this._context.domainContextSelectors.getUndoSystem(),t=e.tip$.value?.committedState;return void 0!==t&&e.canUndo()?this._applyToolCallIds.get(t):void 0};_refreshUndoTip=()=>{let e=this._findTipToolCallId();e!==this._undoTipToolCallId.value&&this._undoTipToolCallId.next(e)};_committedState=()=>this._context.domainContextSelectors.getStoreSystem().stateSlices.committed.value.state;_patchPanel=e=>{let t={...this._panel.value,...e};a(t,this._panel.value)||this._panel.next(t)};_takeOverThread=e=>{for(let t of this._finishing)t.configurationId===e&&(t.client.stop(),t.dispose())};_startClient=()=>{let i={active:!0},s=this._context.getConfigurationId();this._takeOverThread(s);let r=this._context.getAuthorizedClient(),n=()=>{if(i.active){let{manifest:e,error:t}=this._context.getAssistantSetup();if(t)throw t;if(!e)throw Error("The assistant is disabled for this session.")}return r.getAssistantChatConnection(s)},o=e=>{if(!i.active)return;let t={...this._chat.value,...e};a(t,this._chat.value)||this._chat.next(t)},l=async(e,t)=>{let s=await fetch(e,t).finally(()=>o({isLoaded:!0})),a=s.headers.get("x-assistant-thread-continuable");return null!=a&&s.ok&&i.active&&0===this._chat.value.earlierThreads.length&&(this._olderThreadId=s.headers.get("x-assistant-previous-thread")),o({failedStatus:s.ok?void 0:s.status,...null!=a&&{isContinuable:"false"!==a,hasEarlierThread:null!==this._olderThreadId}}),s},h=async()=>({headers:await n().headers(),fetchClient:l}),c=t(()=>n().url,h),d=t(()=>`${n().url}/runs`,h),u=this._tools.map(e=>({...e,execute:(t,s)=>{if(!i.active)return f;let{manifest:a,error:r}=this._context.getAssistantSetup();return r||!a?{error:r?.message??"The assistant is disabled for this session."}:e.execute?.(t,s)}})),_=new e({threadId:`assistant:${s}`,connection:{...c,joinRun:d.joinRun},persistence:!0,history:{pageSize:50},tools:u,onMessagesChange:e=>o({messages:e}),onLoadingChange:e=>{let t=i.active&&this._chat.value.isLoading;o({isLoading:e}),!e&&m(_)&&(i.active?t&&!this._panel.value.open&&this._patchPanel({hasUnreadReply:!0}):p())},onErrorChange:e=>{i.active&&e!==this._chat.value.error&&(!e||-1===this._findRefusedMessageIndex(v))&&(o({error:e}),e&&this._context.domainServicesSelectors.getLogger().error("The assistant request failed",{status:this._chat.value.failedStatus},e))}}),g=!1,p=()=>{g||(g=!0,this._finishing.delete(v),_.dispose())},v={client:_,configurationId:s,generation:i,authorizedClient:r,getConnection:n,dispose:p};this._current=v,_.attach()};_retireChat=()=>{let e=this._current;return this._current=null,e&&(e.generation.active=!1),this._chain={},this._olderThreadId=null,this._resuming=null,this._refused=null,this._loadingThreadId=null,this._chat.value!==u&&this._chat.next(u),e};_releaseScreenshotUrls=()=>{for(let e of this._screenshotUrls.values())e.then(URL.revokeObjectURL,()=>void 0);this._screenshotUrls=new Map};_endChat=()=>{let e=this._retireChat();if(e){if(!e.client.getIsLoading()&&m(e.client))return void e.dispose();this._finishing.add(e)}}}
|
package/dist/configurator/application-runtime/extensions/systems/assistant-system/graphql-tools.d.ts
CHANGED
|
@@ -7,7 +7,7 @@ import type { GraphQLExecution, GraphQLSystem } from '../graphql-system/graphql-
|
|
|
7
7
|
* mode current at that moment, never against ones captured when its reply began streaming.
|
|
8
8
|
*/
|
|
9
9
|
export interface AssistantToolDependencies {
|
|
10
|
-
readonly getGraphQLSystem: () => Pick<GraphQLSystem, 'prepare' | 'execute' | 'readSideEffects' | 'readScreenshots'>;
|
|
10
|
+
readonly getGraphQLSystem: () => Pick<GraphQLSystem, 'prepare' | 'execute' | 'readSideEffects' | 'readWarnings' | 'readScreenshots'>;
|
|
11
11
|
readonly getStoreSystem: () => {
|
|
12
12
|
readonly isInitialized: boolean;
|
|
13
13
|
readonly stateSlices: {
|
|
@@ -35,7 +35,8 @@ export interface AssistantToolDependencies {
|
|
|
35
35
|
/**
|
|
36
36
|
* A tool result as the chat client accepts it: content parts, the execution's JSON as a text part
|
|
37
37
|
* followed, per screenshot, by its label as a text part and its picture as an image part, so the
|
|
38
|
-
* model reads each picture under the label its `image` field returned
|
|
38
|
+
* model reads each picture under the label its `image` field returned; the image part references the picture the browser uploaded, which the server
|
|
39
|
+
* inlines only for the model. The client deep-clones a
|
|
39
40
|
* result and rejects anything that is not plain JSON, so the `GraphQLError` instances of a result
|
|
40
41
|
* are formatted through their `toJSON` and `undefined` members are dropped. The prepared state stays
|
|
41
42
|
* in the browser.
|
|
@@ -44,12 +45,16 @@ export declare const toToolResult: ({ preparedState, screenshots, ...execution }
|
|
|
44
45
|
/**
|
|
45
46
|
* Browser implementation of the assistant's `query` tool: prepares the operations from the
|
|
46
47
|
* committed state and drops their emissions, so mutations in the list show a hypothetical state and
|
|
47
|
-
* the configuration, the undo stack and the saved revision stay as they were. The side effects
|
|
48
|
-
* the dropped emissions are still reported, as what the changes would do.
|
|
48
|
+
* the configuration, the undo stack and the saved revision stay as they were. The side effects and
|
|
49
|
+
* the new warnings of the dropped emissions are still reported, as what the changes would do.
|
|
49
50
|
*/
|
|
50
51
|
export declare const createQueryClientTool: (dependencies: AssistantToolDependencies) => import("@tanstack/ai").ClientTool<{
|
|
51
52
|
type: string;
|
|
52
53
|
properties: {
|
|
54
|
+
title: {
|
|
55
|
+
type: string;
|
|
56
|
+
description: string;
|
|
57
|
+
};
|
|
53
58
|
operations: {
|
|
54
59
|
type: string;
|
|
55
60
|
minItems: number;
|
|
@@ -79,6 +84,10 @@ export declare const createQueryClientTool: (dependencies: AssistantToolDependen
|
|
|
79
84
|
inputSchema: {
|
|
80
85
|
type: string;
|
|
81
86
|
properties: {
|
|
87
|
+
title: {
|
|
88
|
+
type: string;
|
|
89
|
+
description: string;
|
|
90
|
+
};
|
|
82
91
|
operations: {
|
|
83
92
|
type: string;
|
|
84
93
|
minItems: number;
|
|
@@ -132,6 +141,10 @@ export declare const createQueryClientTool: (dependencies: AssistantToolDependen
|
|
|
132
141
|
export declare const createApplyClientTool: (dependencies: AssistantToolDependencies) => import("@tanstack/ai").ClientTool<{
|
|
133
142
|
type: string;
|
|
134
143
|
properties: {
|
|
144
|
+
title: {
|
|
145
|
+
type: string;
|
|
146
|
+
description: string;
|
|
147
|
+
};
|
|
135
148
|
operations: {
|
|
136
149
|
type: string;
|
|
137
150
|
minItems: number;
|
|
@@ -161,6 +174,10 @@ export declare const createApplyClientTool: (dependencies: AssistantToolDependen
|
|
|
161
174
|
inputSchema: {
|
|
162
175
|
type: string;
|
|
163
176
|
properties: {
|
|
177
|
+
title: {
|
|
178
|
+
type: string;
|
|
179
|
+
description: string;
|
|
180
|
+
};
|
|
164
181
|
operations: {
|
|
165
182
|
type: string;
|
|
166
183
|
minItems: number;
|
package/dist/configurator/application-runtime/extensions/systems/assistant-system/graphql-tools.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{AssistantGraphQLToolInput as e,applyTool as t,queryTool as
|
|
1
|
+
import{AssistantGraphQLToolInput as e,applyTool as t,assistantImageReference as o,queryTool as a}from"@salsita-ai/contracts/assistant";let i=e=>({results:[],committed:!1,message:e,sideEffects:[],screenshots:new Map,warnings:[]});export const toToolResult=({preparedState:e,screenshots:t,...a})=>[{type:"text",content:JSON.stringify(a)},...[...t].flatMap(([e,{imageId:t}])=>[{type:"text",content:e},{type:"image",source:{type:"url",value:o(t)}}])];let s=t=>{let o=e.safeParse(t);if(!o.success){let e=o.error.issues.map(e=>`${e.path.join(".")}: ${e.message}`).join("; ");return{ok:!1,refusal:i(`Nothing was run, because the tool input is not a list of operations (${e}). Send { "operations": [{ "query": "<one GraphQL operation>" }] } with at least one item.`)}}return{ok:!0,operations:o.data.operations.map(({query:e,variables:t,operationName:o})=>({document:e,variables:t??void 0,operationName:o??void 0}))}};export const createQueryClientTool=e=>a.client(async t=>{let o=s(t);if(!o.ok)return toToolResult(o.refusal);let a=e.getStoreSystem();if(!a.isInitialized)return toToolResult(i("Nothing was run, because the configuration is not loaded yet, so there is no state to query. Call the tool again once the configurator has finished loading."));let n=e.getGraphQLSystem(),r=a.stateSlices.committed.value.state,l=await n.prepare(r,o.operations);return toToolResult({results:l.map(({result:e})=>e),committed:!1,sideEffects:n.readSideEffects(l),screenshots:n.readScreenshots(l),warnings:n.readWarnings(r,l)})});export const createApplyClientTool=e=>t.client(async(t,o)=>{if("finalize"===e.getActiveMode())return toToolResult(i("Nothing was run, because changes cannot be applied in this session: the user may view this configuration but not change it. The query tool still works here, including mutations, to show what a change would do without keeping it."));if(e.getIsViewMode())return toToolResult(i("Nothing was run, because the configuration is read-only right now: the user may view it but not change it. The query tool still works here, including mutations, to show what a change would do without keeping it. Call apply again only once the configuration is editable."));let a=s(t);if(!a.ok)return toToolResult(a.refusal);let n=await e.getGraphQLSystem().execute(a.operations),r=o?.toolCallId;return void 0!==r&&void 0!==n.preparedState&&e.rememberCommit(r,n.preparedState),n.committed&&e.clearChanges(),toToolResult(n)});
|
package/dist/configurator/application-runtime/extensions/systems/graphql-system/entity-meta.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { type $DomainEntity, type AssistantManifest, type AssistantRecipeContext, type DomainEntity, type DomainEntityId, type DomainState, type
|
|
1
|
+
import { type $DomainEntity, type AssistantManifest, type AssistantRecipeContext, type DomainEntity, type DomainEntityId, type DomainState, type StateUpdate, type StateUpdateEmission, type StateValidationResult } from '#package/domain';
|
|
2
|
+
import { type ViolationEntry } from './violations.js';
|
|
2
3
|
type AnyDomainState = DomainState<DomainEntity<string>>;
|
|
3
4
|
type AnyStateUpdate = StateUpdate<DomainEntity<string>, DomainEntity<string>>;
|
|
4
5
|
/** An entity and the state it was read on, which everything under its `meta` field resolves against. */
|
|
@@ -27,76 +28,89 @@ export interface EntityMetaContext {
|
|
|
27
28
|
readonly takeScreenshot: (source: EntityMetaSource, view: string) => Promise<{
|
|
28
29
|
readonly image: string;
|
|
29
30
|
} | null>;
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
readonly
|
|
35
|
-
readonly message: string | null;
|
|
31
|
+
/**
|
|
32
|
+
* Validates a state: the one an entity was read on, for its warnings, or the one a dry-run ran on,
|
|
33
|
+
* whose warnings the dry-run's own are compared with.
|
|
34
|
+
*/
|
|
35
|
+
readonly validateState: (state: AnyDomainState) => StateValidationResult<DomainEntity<string>, string>;
|
|
36
36
|
}
|
|
37
37
|
/**
|
|
38
38
|
* The value of an entity's `meta` field: its built-ins, resolved lazily against the state the entity
|
|
39
|
-
* was read on. `childRecipes` and `replaceRecipes`
|
|
40
|
-
*
|
|
41
|
-
* `
|
|
39
|
+
* was read on. `childRecipes` and `replaceRecipes` hold one field per manifest recipe group of their
|
|
40
|
+
* kind, read only when selected, `null` when the group is not active on the entity there; each
|
|
41
|
+
* options edge lists the choices of its field there, or `null` when its component is not active;
|
|
42
|
+
* `screenshot` renders the entity there, and `warnings` lists the warnings and notices the entity holds there.
|
|
42
43
|
*/
|
|
43
44
|
export declare const createEntityMeta: (source: EntityMetaSource, context: EntityMetaContext) => {
|
|
44
45
|
childRecipes: () => {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
description: string | null;
|
|
48
|
-
recipes: {
|
|
49
|
-
key: string;
|
|
46
|
+
[k: string]: () => {
|
|
47
|
+
groupId: string;
|
|
50
48
|
name: string;
|
|
51
49
|
description: string | null;
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
50
|
+
recipes: ({ keys }: {
|
|
51
|
+
readonly keys?: readonly string[] | null;
|
|
52
|
+
}) => {
|
|
53
|
+
key: string;
|
|
54
|
+
name: string;
|
|
55
|
+
description: string | null;
|
|
56
|
+
imageUrl: string | null;
|
|
57
|
+
dryRun: () => {
|
|
58
|
+
ok: boolean;
|
|
59
|
+
root: null;
|
|
60
|
+
changedEntities: never[];
|
|
61
|
+
deletedEntityIds: never[];
|
|
62
|
+
sideEffects: never[];
|
|
63
|
+
warnings: never[];
|
|
64
|
+
errors: readonly ViolationEntry[];
|
|
65
|
+
} | {
|
|
66
|
+
ok: boolean;
|
|
67
|
+
root: unknown;
|
|
68
|
+
changedEntities: {}[];
|
|
69
|
+
deletedEntityIds: DomainEntityId<string>[];
|
|
70
|
+
sideEffects: readonly string[];
|
|
71
|
+
warnings: () => readonly import("./violations.js").AssistantWarning[];
|
|
72
|
+
errors: never[];
|
|
73
|
+
} | null;
|
|
74
|
+
}[];
|
|
75
|
+
} | null;
|
|
76
|
+
};
|
|
70
77
|
replaceRecipes: () => {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
description: string | null;
|
|
74
|
-
recipes: {
|
|
75
|
-
key: string;
|
|
78
|
+
[k: string]: () => {
|
|
79
|
+
groupId: string;
|
|
76
80
|
name: string;
|
|
77
81
|
description: string | null;
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
82
|
+
recipes: ({ keys }: {
|
|
83
|
+
readonly keys?: readonly string[] | null;
|
|
84
|
+
}) => {
|
|
85
|
+
key: string;
|
|
86
|
+
name: string;
|
|
87
|
+
description: string | null;
|
|
88
|
+
imageUrl: string | null;
|
|
89
|
+
dryRun: () => {
|
|
90
|
+
ok: boolean;
|
|
91
|
+
root: null;
|
|
92
|
+
changedEntities: never[];
|
|
93
|
+
deletedEntityIds: never[];
|
|
94
|
+
sideEffects: never[];
|
|
95
|
+
warnings: never[];
|
|
96
|
+
errors: readonly ViolationEntry[];
|
|
97
|
+
} | {
|
|
98
|
+
ok: boolean;
|
|
99
|
+
root: unknown;
|
|
100
|
+
changedEntities: {}[];
|
|
101
|
+
deletedEntityIds: DomainEntityId<string>[];
|
|
102
|
+
sideEffects: readonly string[];
|
|
103
|
+
warnings: () => readonly import("./violations.js").AssistantWarning[];
|
|
104
|
+
errors: never[];
|
|
105
|
+
} | null;
|
|
106
|
+
}[];
|
|
107
|
+
} | null;
|
|
108
|
+
};
|
|
96
109
|
screenshot: ({ view }: {
|
|
97
110
|
readonly view: string;
|
|
98
111
|
}) => Promise<{
|
|
99
112
|
readonly image: string;
|
|
100
113
|
} | null>;
|
|
114
|
+
warnings: () => readonly import("./violations.js").AssistantWarning[];
|
|
101
115
|
};
|
|
102
116
|
export {};
|
package/dist/configurator/application-runtime/extensions/systems/graphql-system/entity-meta.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{findAssistantFieldOptions as
|
|
1
|
+
import e from"lodash-es/isEqual.js";import{findAssistantFieldOptions as t,findAssistantRecipeGroups as i,modifyEntityUpdateTag as r,prepareAssistantRecipeUpdates as n,readAssistantFieldOptions as o,readAssistantRecipeGroup as a,systemUpdateFactory as s}from"#package/domain";import{readSideEffects as d}from"./side-effects.js";import{readEntityWarnings as l,readStateWarnings as c,readViolationEntries as u}from"./violations.js";let p=e=>({ok:!1,root:null,changedEntities:[],deletedEntityIds:[],sideEffects:[],warnings:[],errors:e}),m=(e,{state:t},{recipes:i,prepareStateEmission:r,find$Entity:n,validateState:o})=>{let{validity:a,state:s,updates:l}=r(e,t,"committed");if(a.valid){let e=new Map(t.entities.map(e=>[e.id,e])),r=new Set(s.entities.map(e=>e.id));return{ok:!0,root:n(s.rootEntityId,s),changedEntities:s.entities.filter(t=>e.get(t.id)!==t).flatMap(e=>n(e.id,s)??[]),deletedEntityIds:t.entities.map(e=>e.id).filter(e=>!r.has(e)),sideEffects:d(l,i.resolveLocalizable),warnings:()=>c(a,o(t),i.resolveLocalizable),errors:[]}}return p(u(a,i.resolveLocalizable))};export const createEntityMeta=(d,c)=>{let u=e=>()=>Object.fromEntries(i(c.manifest,e,d.entity.type).map(t=>[t.groupId,()=>{let i=a(e,t,d.entity.id,d.state,c.recipes);return i?((e,t,i)=>{let{group:r,label:o,description:a,recipes:s}=e,{resolveLocalizable:d}=i.recipes;return{groupId:r.groupId,name:void 0===o?r.instanceName:d(o),description:void 0===a?null:d(a),recipes:({keys:r})=>s.filter(e=>!r||r.includes(e.key)).map(r=>((e,t,i,r)=>{let{key:o,item:a}=e,{resolveLocalizable:s}=r.recipes;return{key:o,name:s(a.title),description:void 0===a.description?null:s(a.description),imageUrl:void 0===a.thumbnailUrl?null:s(a.thumbnailUrl),dryRun:()=>t.group.dryRuns?((e,t,i,r)=>{let{updates:o,error:a}=((e,t,{entity:i,state:r},{recipes:o})=>{try{return{updates:n(e,t,i.id,r,o),error:void 0}}catch(e){if("child"===t.target.kind)throw e;return{updates:void 0,error:e instanceof Error?e.message:String(e)}}})(e,t,i,r);return void 0===o?p([{type:"uncaught",entityId:null,message:a}]):m(o,i,r)})(e,t,i,r):null}})(r,e,t,i))}})(i,d,c):null}]));return{...Object.fromEntries(t(c.manifest,d.entity.type).map(t=>[t.edgeName,({values:i})=>o(t,d.entity.id,d.state,c.recipes)?.filter(t=>!i||i.some(i=>e(i,t.value))).map(e=>({...e,dryRun:()=>t.dryRuns?(({field:e},{value:t},i,n)=>{let{entity:o}=i,a=Object.entries(Object.entries(n.manifest.writableFields??{}).find(([e])=>e===o.type)?.[1]??{}).find(([t])=>t===e)?.[1];if(void 0===a)throw Error(`The options of "${e}" on "${o.id}" cannot be dry-run: the schema lists them, but the configurator has no writable field "${e}" on ${o.type}. This is a fault in the configurator, not in your request. Tell the user this is not available.`);let d=i.state.entities.find(e=>e.id===o.id);if(!d)throw Error(`The options of "${e}" on "${o.id}" cannot be dry-run: entity "${o.id}" does not exist. It may have been deleted by an earlier operation or field. Query the current entities and use an id they return.`);let l={[a]:t},c=n.validateEntity({...d,...l});return c.success?m([s.DomainEntityModification({entityId:o.id,stateDelta:l,updateTag:r})],i,n):p([{type:"uncaught",entityId:o.id,message:`Writing ${JSON.stringify(t)} to "${e}" would make "${o.id}" an invalid ${o.type}: ${c.errors.join("; ")}. The option comes from the configurator and cannot be corrected from here, so do not write it.`}])})(t,e,d,c):null}))??null])),childRecipes:u("child"),replaceRecipes:u("replace"),screenshot:({view:e})=>c.takeScreenshot(d,e),warnings:()=>l(d.entity.id,c.validateState(d.state),c.recipes.resolveLocalizable)}};
|
package/dist/configurator/application-runtime/extensions/systems/graphql-system/graphql-system.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { type ExecutionResult } from 'graphql';
|
|
2
2
|
import { type Localizable } from '@salsita-ai/common/utils';
|
|
3
3
|
import { type $DomainEntity, type AgentScreenshotComponent, type ComponentSnapshot, type DomainContextSelectors, type DomainEntity, type DomainServicesSelectors, type DomainState, type InitializationGeneration, type SessionAssistantSetup, type SpecSelectors, type StateUpdateEmission } from '#package/domain';
|
|
4
|
+
import { type AssistantWarning } from './violations.js';
|
|
4
5
|
/** One single-operation GraphQL document with its own variables, as executed by {@link GraphQLSystem}. */
|
|
5
6
|
export interface GraphQLOperation {
|
|
6
7
|
readonly document: string;
|
|
@@ -11,19 +12,25 @@ export interface GraphQLOperation {
|
|
|
11
12
|
export interface GraphQLScreenshot {
|
|
12
13
|
readonly entityId: string;
|
|
13
14
|
readonly view: string;
|
|
14
|
-
/** The picture
|
|
15
|
-
readonly
|
|
16
|
-
readonly mimeType: 'image/jpeg' | 'image/png';
|
|
15
|
+
/** The id the server stored the picture under, which the tool result references it by. */
|
|
16
|
+
readonly imageId: string;
|
|
17
17
|
}
|
|
18
18
|
export interface GraphQLSystemContext {
|
|
19
19
|
/** The assistant the initialized session runs: the operations are validated and executed against its schema. */
|
|
20
20
|
readonly getAssistantSetup: () => SessionAssistantSetup;
|
|
21
21
|
/**
|
|
22
22
|
* Renders the picture an `agentScreenshot` component of a state declares, behind every export
|
|
23
|
-
* already queued; `null` from an executor that renders no pictures.
|
|
24
|
-
* execution, and the only one that needs a canvas.
|
|
23
|
+
* already queued, as a JPEG or PNG blob; `null` from an executor that renders no pictures. One of
|
|
24
|
+
* the two async steps of an execution, and the only one that needs a canvas.
|
|
25
25
|
*/
|
|
26
26
|
readonly renderScreenshot: (component: ComponentSnapshot<AgentScreenshotComponent>, state: AnyDomainState) => Promise<Blob | null>;
|
|
27
|
+
/**
|
|
28
|
+
* Stores a rendered screenshot in the assistant thread on the server and resolves with the id the
|
|
29
|
+
* tool result references it by. The other async step of an execution, run right after each render.
|
|
30
|
+
*/
|
|
31
|
+
readonly uploadScreenshot: (image: Blob) => Promise<{
|
|
32
|
+
readonly imageId: string;
|
|
33
|
+
}>;
|
|
27
34
|
readonly specSelectors: SpecSelectors;
|
|
28
35
|
readonly domainContextSelectors: DomainContextSelectors;
|
|
29
36
|
readonly domainServicesSelectors: DomainServicesSelectors;
|
|
@@ -55,6 +62,12 @@ export interface GraphQLExecution {
|
|
|
55
62
|
readonly message?: string;
|
|
56
63
|
/** What the configurator did, or would do, beyond what the operations asked for, in applied order. */
|
|
57
64
|
readonly sideEffects: readonly string[];
|
|
65
|
+
/**
|
|
66
|
+
* The warnings and notices the prepared changes newly cause, whether or not they were committed:
|
|
67
|
+
* those of the prepared state that the state the operations started from did not have. Empty when
|
|
68
|
+
* nothing changed or an operation failed.
|
|
69
|
+
*/
|
|
70
|
+
readonly warnings: readonly AssistantWarning[];
|
|
58
71
|
/**
|
|
59
72
|
* The state the operations prepared, when it was committed or held for the user's approval; a
|
|
60
73
|
* held state is the one committed if the user approves. A caller can recognize its own change in
|
|
@@ -91,13 +104,15 @@ export declare class GraphQLSystem {
|
|
|
91
104
|
constructor(_context: GraphQLSystemContext);
|
|
92
105
|
private readonly _get$Entity;
|
|
93
106
|
private readonly _find$Entity;
|
|
107
|
+
private readonly _validateState;
|
|
108
|
+
private readonly _validateCached;
|
|
94
109
|
private readonly _recipeContext;
|
|
95
110
|
/** Root field resolvers, called by the executor with the field arguments and the operation context. */
|
|
96
111
|
private readonly _rootValue;
|
|
97
112
|
private readonly _resolveType;
|
|
98
113
|
private _generation;
|
|
99
114
|
/**
|
|
100
|
-
* The picture of an entity of a state from one `agentScreenshot` view, as
|
|
115
|
+
* The picture of an entity of a state from one `agentScreenshot` view, as a blob of the view's
|
|
101
116
|
* file format; `null` when the view is not attached to the entity there or nothing renders it.
|
|
102
117
|
*/
|
|
103
118
|
private readonly _renderScreenshot;
|
|
@@ -118,9 +133,9 @@ export declare class GraphQLSystem {
|
|
|
118
133
|
private readonly _runMutation;
|
|
119
134
|
/**
|
|
120
135
|
* Takes a screenshot once every one asked for before it in the execution has been taken, so they
|
|
121
|
-
* render and
|
|
122
|
-
* nothing else: the user kept changing the configuration,
|
|
123
|
-
*
|
|
136
|
+
* render in document order, and uploads it as soon as it has rendered. A failure nulls only its
|
|
137
|
+
* own field and fails nothing else: the user kept changing the configuration, rendering failed,
|
|
138
|
+
* or the server did not store the picture.
|
|
124
139
|
*/
|
|
125
140
|
private readonly _takeScreenshot;
|
|
126
141
|
private readonly _setup;
|
|
@@ -145,6 +160,12 @@ export declare class GraphQLSystem {
|
|
|
145
160
|
readSideEffects: (prepared: readonly PreparedOperation[]) => readonly string[];
|
|
146
161
|
/** The screenshots of prepared operations, by label, in the order they were taken. */
|
|
147
162
|
readScreenshots: (prepared: readonly PreparedOperation[]) => ReadonlyMap<string, GraphQLScreenshot>;
|
|
163
|
+
/**
|
|
164
|
+
* The warnings and notices prepared operations newly cause: those of the state their last emission
|
|
165
|
+
* left that `originalState`, the state they were prepared from, did not have. Empty when nothing
|
|
166
|
+
* changed or an operation failed, so the original state is validated only for a change.
|
|
167
|
+
*/
|
|
168
|
+
readWarnings: (originalState: AnyDomainState, prepared: readonly PreparedOperation[]) => readonly AssistantWarning[];
|
|
148
169
|
private readonly _prepareAndCommit;
|
|
149
170
|
/**
|
|
150
171
|
* Prepares the operations from the committed state and commits their changes as one emission,
|
package/dist/configurator/application-runtime/extensions/systems/graphql-system/graphql-system.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{GraphQLError as e,NoSchemaIntrospectionCustomRule as t,defaultFieldResolver as i,execute as n,getNamedType as r,parse as o,specifiedRules as s,validate as a,validateSchema as l}from"graphql";import{assertExistence as c,createSelector as h,isMessageDescriptor as d,isMultilingualString as u}from"@salsita-ai/common/utils";import{DomainEntityIdSchema as f,agentScreenshotComponent as m,createAssistantExecutionSchema as p,findAssistantMutation as g}from"#package/domain";import{ExportBusyError as y}from"../export-system/export-busy-error.js";import{closeUnclosedBraces as v}from"./close-unclosed-braces.js";import{createEntityMeta as S}from"./entity-meta.js";import{injectAssistantLenses as w}from"./inject-assistant-lenses.js";import{readSideEffects as _}from"./side-effects.js";let x={errors:[new e("The configurator does not provide this request. This is a fault in the configurator, not in your request. Tell the user this is not available.")]},$={errors:[new e("The configuration is not loaded yet, so there is no state to query. Run the query again once the configurator has finished loading.")]},b="Not taken: another configuration was loaded while this request ran. Query the current configuration before asking for screenshots again.",E="Not taken: the screenshots of this tool call have used up its image size budget. Ask for this screenshot in another call, and for fewer in one call.",T=async e=>{let t=new Uint8Array(await e.arrayBuffer()),i="";for(let e=0;e<t.length;e+=32768)i+=String.fromCharCode(...t.subarray(e,e+32768));return btoa(i)},C=new RegExp(f.pattern),M=[...s,t],k=e=>"object"==typeof e&&null!==e&&"type"in e&&"string"==typeof e.type&&"id"in e&&"string"==typeof e.id,j=(e,t)=>"object"==typeof e&&null!==e?Reflect.get(e,t):void 0,R=e=>e instanceof Error?e.message:String(e),A=e=>/[.!?]$/.test(e)?e:`${e}.`,N=e=>"object"==typeof e&&null!==e&&Object.getPrototypeOf(e)===Object.prototype,z=(e,t)=>{let i=N(e)?e._raw:void 0;if(k(i))return i;if(!Array.isArray(e)&&!N(e))return e;if(t.has(e))throw Error("The value contains itself.");let n=new Set([...t,e]);return Array.isArray(e)?e.map(e=>z(e,n)):Object.fromEntries(Object.entries(e).map(([e,t])=>[e,z(t,n)]))};export const localize=(e,t)=>Array.isArray(e)?e.map(e=>localize(e,t)):"string"==typeof e||d(e)||u(e)?t(e):e;let q=t=>new e(`The configurator cannot handle this request: ${A(t)} This is a fault in the configurator, not in your request. Tell the user this is not available.`),L="SCREENSHOT_NOT_TAKEN",F=(t,i)=>new e(t,{originalError:i,extensions:{code:L}}),O=e=>(e.errors??[]).some(e=>e.extensions.code!==L),V=t=>({errors:[new e(`Not run: operation ${t+1} failed, so the operations after it were skipped and no change of the list takes effect. Fix the failing operation and send the whole list again.`)]});export class GraphQLSystem{_context;_selectSchema=h([h.leaf(e=>e)],e=>{try{let t=p(e),i=l(t);return i.length>0?q(i.map(e=>e.message).join(" ")):t}catch(e){return q(R(e))}});_selectLenses=h([h.leaf(e=>e)],e=>o(e));_selectFieldResolver=h([h.leaf(e=>e)],t=>(n,o,s,a)=>{if(a.parentType===a.schema.getQueryType())return i(n,o,s,a);if(a.parentType===a.schema.getMutationType())return this._resolveMutation(a.fieldName,String(a.path.key),o,s);if(!k(n))return i(n,o,s,a);if("meta"===a.fieldName){let e;return S({entity:n,state:("object"==typeof(e=j(n,"_state"))&&null!==e&&"entities"in e&&"rootEntityId"in e?e:void 0)??s.state},{manifest:s.manifest,recipes:this._recipeContext(),prepareStateEmission:(e,t,i)=>this._context.domainContextSelectors.getStoreSystem().prepareStateEmission(e,t,i),find$Entity:(e,t)=>this._find$Entity(e,t),validateEntity:e=>this._context.domainContextSelectors.getDomain().validateEntity(e),takeScreenshot:(e,t)=>this._takeScreenshot(e,t,s)})}let{source:l,localized:c}=t[a.parentType.name]?.[a.fieldName]??{source:a.fieldName},h=((t,i)=>{try{return j(t,i)}catch(n){throw new e(`Expression "${i}" failed on ${k(t)?t.id:"an entity"}: ${A(R(n))} This is a fault in the configurator, not in your request. Tell the user this is not available.`,{originalError:n instanceof Error?n:void 0})}})(n,l);return c?localize(h,this._context.domainServicesSelectors.getResolveLocalizable()):l.startsWith("$")&&"JSON"===r(a.returnType).name?((t,i,n)=>{try{return z(n,new Set)}catch(n){throw new e(`Expression "${i}" returned a value that is not plain serializable data on ${k(t)?t.id:"an entity"}: ${A(R(n))} This is a fault in the configurator, not in your request. Tell the user this is not available.`,{originalError:n instanceof Error?n:void 0})}})(n,l,h):h});constructor(e){this._context=e}_get$Entity=(e,t)=>this._context.domainContextSelectors.getDomain().get$Entity(e,t);_find$Entity=(e,t)=>this._context.domainContextSelectors.getDomain().getEntity(e,t)?this._get$Entity(e,t):null;_recipeContext=()=>({componentReader:this._context.domainContextSelectors.getComponentReader(),recipeCooker:this._context.domainContextSelectors.getRecipeCookerSystem(),resolveLocalizable:this._context.domainServicesSelectors.getResolveLocalizable()});_rootValue={root:(e,{state:t})=>this._get$Entity(t.rootEntityId,t),entities:({ids:t},{state:i})=>{if(null==t)return i.entities.map(e=>this._get$Entity(e.id,i));var n=i.rootEntityId;let r=t.filter(e=>!C.test(e));if(r.length>0)throw new e(`${r.map(e=>`"${e}"`).join(", ")} ${1===r.length?"is not an entity id":"are not entity ids"}. Entity ids have the form "<Type>-<number>", e.g. "${n}". Use ids as returned by the "id" field.`);return t.map(e=>C.test(e)?this._find$Entity(e,i):null)},selectedEntity:(e,{state:t})=>this._find$Entity(this._context.domainContextSelectors.getNavigationSystem().getActiveSelectionState(t),t),navigation:(e,{state:t})=>{let i=this._context.domainContextSelectors.getNavigationSystem();return{navigationState:i.getActiveNavigationState(t),viewState:i.getActiveViewState(t),toolState:i.getActiveToolState(t)}}};_resolveType=e=>k(e)?e.type:void 0;_generation={active:!0};_renderScreenshot=async(e,t,i)=>{let n=this._context.domainContextSelectors.getComponentReader().readOneComponent({entityId:e,componentType:m,instanceName:t},i);if(!n)return null;let r=await this._context.renderScreenshot(n,i);return null===r?null:{data:await T(r),mimeType:"JPEG"===n.state.fileFormat?"image/jpeg":"image/png"}};initialize=()=>{this._generation.active=!1,this._generation={active:!0}};_resolveMutation=(t,i,n,r)=>{if(void 0!==r.failedMutationField)throw new e(`Not run: the earlier field "${r.failedMutationField}" of this operation failed, so "${i}" was skipped and no change of the operation takes effect. Fix the failing field and send the operation again.`);try{return this._runMutation(t,n,r)}catch(e){throw r.failedMutationField=i,e}};_runMutation=(t,i,n)=>{let r=g(t,n.manifest);if(!r)throw new e(`The schema declares the mutation "${t}", but the configurator has no implementation for it. This is a fault in the configurator, not in your request. Tell the user this is not available.`);let o=n.state,s=r.implementation(i,o,{manifest:n.manifest,action:this._context.domainContextSelectors.getActionSystem().createContext(o),resolveLocalizable:this._context.domainServicesSelectors.getResolveLocalizable()});if(s.updates.length>0){let i=this._context.domainContextSelectors.getStoreSystem().prepareStateEmission(s.updates,o,"committed");if(!i.validity.valid)throw new e(`The changes of "${t}" were not applied, because the resulting configuration is invalid: ${(e=>{if("uncaught"===e.severity)return`validating it threw: ${A(R(e.error))}`;let t=[...new Set(e.entityViolations.filter(({violation:t})=>t.severity===e.severity).map(({entityId:e})=>e))];return`it has ${e.severity} violations on ${t.join(", ")}.`})(i.validity)} Change the request so the configuration stays valid.`);n.emissions.push(i),n.state=i.state}return s.readResult({previousState:o,state:n.state})};_takeScreenshot=({entity:t,state:i},n,r)=>{let o=r.manifest.screenshots?.[t.type]?.find(e=>e.view===n);if(!o)return Promise.reject(new e(`The schema declares the screenshot view "${n}" on ${t.type}, but the configurator has no view of that name. This is a fault in the configurator, not in your request. Tell the user this is not available.`));let s=r.lastScreenshot.then(async()=>{if(!r.generation.active)throw F(b);if(r.screenshotBudget<=0)throw F(E);let e=await this._renderScreenshot(t.id,o.instanceName,i).catch(e=>{throw F(e instanceof y?"User made concurrent actions that prevented the screenshot from being taken, try again":`The screenshot of ${t.id} from "${n}" could not be taken: ${A(R(e))} Try again; if it fails again, tell the user the screenshot is not available.`,e instanceof Error?e:void 0)});if(!r.generation.active)throw F(b);if(null===e)return null;if(e.data.length>r.screenshotBudget)throw r.screenshotBudget=0,F(E);r.screenshotBudget-=e.data.length;let s=`${t.id}/${n}`,a=[...r.screenshots.values()].filter(e=>e.entityId===t.id&&e.view===n).length,l=0===a?s:`${s}#${a+1}`;return r.screenshots.set(l,{entityId:t.id,view:n,...e}),{image:l}});return r.lastScreenshot=s.catch(()=>void 0),s};_setup=()=>{let{manifest:t,error:i}=this._context.getAssistantSetup();if(i)return{ready:!1,result:{errors:[new e(i.message,{originalError:i})]}};if(!t)return{ready:!1,result:x};let n=this._selectSchema(t.sdl);return n instanceof e?{ready:!1,result:{errors:[n]}}:{ready:!0,assistant:t,schema:n,lenses:t.lenses?.definitions?this._selectLenses(t.lenses.definitions):void 0,fieldResolver:this._selectFieldResolver(t.fields)}};_run=(t,i,r,s)=>{let l;try{l=o(t)}catch(t){return{errors:[t instanceof e?t:new e(R(t))]}}let c=a(r.schema,l,M);return c.length>0?{errors:c}:n({schema:r.schema,document:l,rootValue:this._rootValue,contextValue:s,variableValues:i.variables,operationName:i.operationName,fieldResolver:r.fieldResolver,typeResolver:this._resolveType})};prepare=async(t,i,n=this._generation)=>{let r,o=this._setup();if(!o.ready)return i.map(()=>({result:o.result,emissions:[],screenshots:new Map}));let s={manifest:o.assistant,state:t,emissions:[],failedMutationField:void 0,screenshots:new Map,screenshotBudget:14e5,lastScreenshot:Promise.resolve(),generation:n},a=[];for(let[t,n]of i.entries())if(void 0===r){let i=s.emissions.length,l=s.screenshots.size;s.failedMutationField=void 0;let c=v(n.document),h=o.lenses?w(c,o.lenses):c,d=h instanceof e?{errors:[h]}:await this._run(h,n,o,s);await s.lastScreenshot,a.push({result:d,emissions:s.emissions.slice(i),screenshots:new Map([...s.screenshots].slice(l))}),O(d)&&(r=t)}else a.push({result:V(r),emissions:[],screenshots:new Map});return a};readSideEffects=e=>{let t=this._context.domainServicesSelectors.getResolveLocalizable();return e.flatMap(({emissions:e})=>e.flatMap(e=>_(e.updates,t)))};readScreenshots=e=>new Map(e.flatMap(({screenshots:e})=>[...e]));_prepareAndCommit=async(e,t)=>{let i,n,r,o=this._context.domainContextSelectors.getStoreSystem(),s=await this.prepare(o.stateSlices.committed.value.state,e,t),a=s.map(({result:e})=>e),l=this.readSideEffects(s),h=this.readScreenshots(s),d=s.flatMap(e=>e.emissions);if(!t.active)return{results:a,sideEffects:l,screenshots:h,outcome:"conflict"};if(a.some(O)||0===d.length)return{results:a,sideEffects:l,screenshots:h,outcome:"none"};let u=(i=c(d[0]),n=c(d[d.length-1]),r=d.some(e=>void 0!==e.transformationLog),{kind:"committed",previousState:i.previousState,state:n.state,updates:d.flatMap(e=>e.updates),validity:n.validity,transformationLog:r?d.flatMap(e=>e.transformationLog??[]):void 0});return{results:a,sideEffects:l,screenshots:h,outcome:o.commitPrepared(u),preparedState:u.state}};execute=async e=>{let t=this._generation;if(!this._context.domainContextSelectors.getStoreSystem().isInitialized)return{results:e.map(()=>$),committed:!1,sideEffects:[],screenshots:new Map};let i=await this._prepareAndCommit(e,t),{results:n,sideEffects:r,screenshots:o,outcome:s,preparedState:a}="conflict"===i.outcome&&t.active?await this._prepareAndCommit(e,t):i;return"committed"===s?{results:n,committed:!0,sideEffects:r,screenshots:o,preparedState:a}:"held"===s?{results:n,committed:!1,message:"The changes wait for the user's approval and are not applied yet. Do not send them again; the next `[changes]` block lists them once approved.",sideEffects:r,screenshots:o,preparedState:a}:"conflict"===s?{results:n,committed:!1,message:"The changes were not committed, because the configuration changed while they were being applied. The results describe a state that was discarded. Query the current configuration and send the operations again if they still make sense.",sideEffects:r,screenshots:o}:{results:n,committed:!1,sideEffects:r,screenshots:o}}}
|
|
1
|
+
import{GraphQLError as e,NoSchemaIntrospectionCustomRule as t,defaultFieldResolver as i,execute as n,getNamedType as o,parse as r,specifiedRules as a,validate as s,validateSchema as l}from"graphql";import{assertExistence as c,createSelector as h,isMessageDescriptor as d,isMultilingualString as u}from"@salsita-ai/common/utils";import{AGENT_SCREENSHOT_MAX_SIDE as m,DomainEntityIdSchema as f,agentScreenshotComponent as p,createAssistantExecutionSchema as g,findAssistantMutation as v}from"#package/domain";import{ExportBusyError as y}from"../export-system/export-busy-error.js";import{closeUnclosedBraces as S}from"./close-unclosed-braces.js";import{createEntityMeta as w}from"./entity-meta.js";import{injectAssistantLenses as _}from"./inject-assistant-lenses.js";import{readSideEffects as x}from"./side-effects.js";import{ViolationsError as $,readStateWarnings as b,readViolationEntries as E}from"./violations.js";let T={errors:[new e("The configurator does not provide this request. This is a fault in the configurator, not in your request. Tell the user this is not available.")]},C={errors:[new e("The configuration is not loaded yet, so there is no state to query. Run the query again once the configurator has finished loading.")]},M="Not taken: another configuration was loaded while this request ran. Query the current configuration before asking for screenshots again.",R=class ScreenshotTooLargeError extends Error{constructor(e,t){super(`The view is configured at ${e} \xd7 ${t} px, more than the ${m} \xd7 ${m} px a screenshot may have.`),this.name="ScreenshotTooLargeError"}},k=new RegExp(f.pattern),j=[...a,t],L=e=>"object"==typeof e&&null!==e&&"type"in e&&"string"==typeof e.type&&"id"in e&&"string"==typeof e.id,N=(e,t)=>"object"==typeof e&&null!==e?Reflect.get(e,t):void 0,A=e=>e instanceof Error?e.message:String(e),z=e=>/[.!?]$/.test(e)?e:`${e}.`,q=e=>"object"==typeof e&&null!==e&&Object.getPrototypeOf(e)===Object.prototype,O=(e,t)=>{let i=q(e)?e._raw:void 0;if(L(i))return i;if(!Array.isArray(e)&&!q(e))return e;if(t.has(e))throw Error("The value contains itself.");let n=new Set([...t,e]);return Array.isArray(e)?e.map(e=>O(e,n)):Object.fromEntries(Object.entries(e).map(([e,t])=>[e,O(t,n)]))};export const localize=(e,t)=>Array.isArray(e)?e.map(e=>localize(e,t)):"string"==typeof e||d(e)||u(e)?t(e):e;let F=t=>new e(`The configurator cannot handle this request: ${z(t)} This is a fault in the configurator, not in your request. Tell the user this is not available.`),I="SCREENSHOT_NOT_TAKEN",V=(t,i)=>new e(t,{originalError:i,extensions:{code:I}}),P=e=>(e.errors??[]).some(e=>e.extensions.code!==I),D=t=>({errors:[new e(`Not run: operation ${t+1} failed, so the operations after it were skipped and no change of the list takes effect. Fix the failing operation and send the whole list again.`)]});export class GraphQLSystem{_context;_selectSchema=h([h.leaf(e=>e)],e=>{try{let t=g(e),i=l(t);return i.length>0?F(i.map(e=>e.message).join(" ")):t}catch(e){return F(A(e))}});_selectLenses=h([h.leaf(e=>e)],e=>r(e));_selectFieldResolver=h([h.leaf(e=>e)],t=>(n,r,a,s)=>{if(s.parentType===s.schema.getQueryType())return i(n,r,a,s);if(s.parentType===s.schema.getMutationType())return this._resolveMutation(s.fieldName,String(s.path.key),r,a);if(!L(n))return i(n,r,a,s);if("meta"===s.fieldName){let e;return w({entity:n,state:("object"==typeof(e=N(n,"_state"))&&null!==e&&"entities"in e&&"rootEntityId"in e?e:void 0)??a.state},{manifest:a.manifest,recipes:this._recipeContext(),prepareStateEmission:(e,t,i)=>{let n=this._context.domainContextSelectors.getStoreSystem().prepareStateEmission(e,t,i);return a.validities.set(n.state,n.validity),n},find$Entity:(e,t)=>this._find$Entity(e,t),validateEntity:e=>this._context.domainContextSelectors.getDomain().validateEntity(e),takeScreenshot:(e,t)=>this._takeScreenshot(e,t,a),validateState:e=>this._validateCached(e,a)})}let{source:l,localized:c}=t[s.parentType.name]?.[s.fieldName]??{source:s.fieldName},h=((t,i)=>{try{return N(t,i)}catch(n){throw new e(`Expression "${i}" failed on ${L(t)?t.id:"an entity"}: ${z(A(n))} This is a fault in the configurator, not in your request. Tell the user this is not available.`,{originalError:n instanceof Error?n:void 0})}})(n,l);return c?localize(h,this._context.domainServicesSelectors.getResolveLocalizable()):l.startsWith("$")&&"JSON"===o(s.returnType).name?((t,i,n)=>{try{return O(n,new Set)}catch(n){throw new e(`Expression "${i}" returned a value that is not plain serializable data on ${L(t)?t.id:"an entity"}: ${z(A(n))} This is a fault in the configurator, not in your request. Tell the user this is not available.`,{originalError:n instanceof Error?n:void 0})}})(n,l,h):h});constructor(e){this._context=e}_get$Entity=(e,t)=>this._context.domainContextSelectors.getDomain().get$Entity(e,t);_find$Entity=(e,t)=>this._context.domainContextSelectors.getDomain().getEntity(e,t)?this._get$Entity(e,t):null;_validateState=e=>this._context.domainContextSelectors.getValidationProjections().validateState(e);_validateCached=(e,{validities:t})=>{let i=t.get(e);if(i)return i;let n=this._validateState(e);return t.set(e,n),n};_recipeContext=()=>({componentReader:this._context.domainContextSelectors.getComponentReader(),recipeCooker:this._context.domainContextSelectors.getRecipeCookerSystem(),resolveLocalizable:this._context.domainServicesSelectors.getResolveLocalizable()});_rootValue={warnings:(e,t)=>b(this._validateCached(t.state,t),void 0,this._context.domainServicesSelectors.getResolveLocalizable()),root:(e,{state:t})=>this._get$Entity(t.rootEntityId,t),entities:({ids:t},{state:i})=>{if(null==t)return i.entities.map(e=>this._get$Entity(e.id,i));var n=i.rootEntityId;let o=t.filter(e=>!k.test(e));if(o.length>0)throw new e(`${o.map(e=>`"${e}"`).join(", ")} ${1===o.length?"is not an entity id":"are not entity ids"}. Entity ids have the form "<Type>-<number>", e.g. "${n}". Use ids as returned by the "id" field.`);return t.map(e=>k.test(e)?this._find$Entity(e,i):null)},selectedEntity:(e,{state:t})=>this._find$Entity(this._context.domainContextSelectors.getNavigationSystem().getActiveSelectionState(t),t),navigation:(e,{state:t})=>{let i=this._context.domainContextSelectors.getNavigationSystem();return{navigationState:i.getActiveNavigationState(t),viewState:i.getActiveViewState(t),toolState:i.getActiveToolState(t)}}};_resolveType=e=>L(e)?e.type:void 0;_generation={active:!0};_renderScreenshot=async(e,t,i)=>{let n=this._context.domainContextSelectors.getComponentReader().readOneComponent({entityId:e,componentType:p,instanceName:t},i);if(!n)return null;let{width:o,height:r}=n.state;if(o>m||r>m)throw new R(o,r);let a=await this._context.renderScreenshot(n,i);return null===a?null:new Blob([a],{type:"JPEG"===n.state.fileFormat?"image/jpeg":"image/png"})};initialize=()=>{this._generation.active=!1,this._generation={active:!0}};_resolveMutation=(t,i,n,o)=>{if(void 0!==o.failedMutationField)throw new e(`Not run: the earlier field "${o.failedMutationField}" of this operation failed, so "${i}" was skipped and no change of the operation takes effect. Fix the failing field and send the operation again.`);try{return this._runMutation(t,n,o)}catch(e){throw o.failedMutationField=i,e}};_runMutation=(t,i,n)=>{let o=v(t,n.manifest);if(!o)throw new e(`The schema declares the mutation "${t}", but the configurator has no implementation for it. This is a fault in the configurator, not in your request. Tell the user this is not available.`);let r=n.state,a=o.implementation(i,r,{manifest:n.manifest,action:this._context.domainContextSelectors.getActionSystem().createContext(r),resolveLocalizable:this._context.domainServicesSelectors.getResolveLocalizable()});if(a.updates.length>0){let i=this._context.domainContextSelectors.getStoreSystem().prepareStateEmission(a.updates,r,"committed"),{validity:o}=i;if("uncaught"===o.severity)throw new e(`The changes of "${t}" were not applied, because the resulting configuration is invalid: validating it threw: ${z(A(o.error))} Change the request so the configuration stays valid.`,{originalError:o.error});if(!o.valid)throw new $(`The changes of "${t}" were not applied, because the resulting configuration has ${o.severity} violations.`,E(o,this._context.domainServicesSelectors.getResolveLocalizable()));n.emissions.push(i),n.validities.set(i.state,o),n.state=i.state}return a.readResult({previousState:r,state:n.state})};_takeScreenshot=({entity:t,state:i},n,o)=>{let r=o.manifest.screenshots?.[t.type]?.find(e=>e.view===n);if(!r)return Promise.reject(new e(`The schema declares the screenshot view "${n}" on ${t.type}, but the configurator has no view of that name. This is a fault in the configurator, not in your request. Tell the user this is not available.`));let a=o.lastScreenshot.then(async()=>{if(!o.generation.active)throw V(M);let e=await this._renderScreenshot(t.id,r.instanceName,i).catch(e=>{throw V(e instanceof y?"User made concurrent actions that prevented the screenshot from being taken, try again":e instanceof R?`The screenshot of ${t.id} from "${n}" cannot be taken: ${e.message} Tell the user the screenshot is not available.`:`The screenshot of ${t.id} from "${n}" could not be taken: ${z(A(e))} Try again; if it fails again, tell the user the screenshot is not available.`,e instanceof Error?e:void 0)});if(!o.generation.active)throw V(M);if(null===e)return null;let{imageId:a}=await this._context.uploadScreenshot(e).catch(e=>{throw V(`The screenshot of ${t.id} from "${n}" was taken but could not be stored: ${z(A(e))} Try again; if it fails again, tell the user the screenshot is not available.`,e instanceof Error?e:void 0)}),s=`${t.id}/${n}`,l=[...o.screenshots.values()].filter(e=>e.entityId===t.id&&e.view===n).length,c=0===l?s:`${s}#${l+1}`;return o.screenshots.set(c,{entityId:t.id,view:n,imageId:a}),{image:c}});return o.lastScreenshot=a.catch(()=>void 0),a};_setup=()=>{let{manifest:t,error:i}=this._context.getAssistantSetup();if(i)return{ready:!1,result:{errors:[new e(i.message,{originalError:i})]}};if(!t)return{ready:!1,result:T};let n=this._selectSchema(t.sdl);return n instanceof e?{ready:!1,result:{errors:[n]}}:{ready:!0,assistant:t,schema:n,lenses:t.lenses?.definitions?this._selectLenses(t.lenses.definitions):void 0,fieldResolver:this._selectFieldResolver(t.fields)}};_run=async(t,i,o,a)=>{var l;let c;try{c=r(t)}catch(t){return{errors:[t instanceof e?t:new e(A(t))]}}let h=s(o.schema,c,j);return h.length>0?{errors:h}:(l=await n({schema:o.schema,document:c,rootValue:this._rootValue,contextValue:a,variableValues:i.variables,operationName:i.operationName,fieldResolver:o.fieldResolver,typeResolver:this._resolveType}),l.errors?.some(e=>e.originalError instanceof $)?{...l,errors:l.errors.flatMap(t=>t.originalError instanceof $?t.originalError.entries.map(({type:i,entityId:n,message:o})=>new e(o??i,{nodes:t.nodes,source:t.source,positions:t.positions,path:t.path,extensions:{code:"VIOLATION",type:i,entityId:n}})):[t])}:l)};prepare=async(t,i,n=this._generation)=>{let o,r=this._setup();if(!r.ready)return i.map(()=>({result:r.result,emissions:[],screenshots:new Map}));let a={manifest:r.assistant,state:t,emissions:[],failedMutationField:void 0,screenshots:new Map,lastScreenshot:Promise.resolve(),generation:n,validities:new WeakMap},s=[];for(let[t,n]of i.entries())if(void 0===o){let i=a.emissions.length,l=a.screenshots.size;a.failedMutationField=void 0;let c=S(n.document),h=r.lenses?_(c,r.lenses):c,d=h instanceof e?{errors:[h]}:await this._run(h,n,r,a);await a.lastScreenshot,s.push({result:d,emissions:a.emissions.slice(i),screenshots:new Map([...a.screenshots].slice(l))}),P(d)&&(o=t)}else s.push({result:D(o),emissions:[],screenshots:new Map});return s};readSideEffects=e=>{let t=this._context.domainServicesSelectors.getResolveLocalizable();return e.flatMap(({emissions:e})=>e.flatMap(e=>x(e.updates,t)))};readScreenshots=e=>new Map(e.flatMap(({screenshots:e})=>[...e]));readWarnings=(e,t)=>{let i=t.flatMap(({emissions:e})=>e).at(-1);return void 0===i||t.some(({result:e})=>P(e))?[]:b(i.validity,this._validateState(e),this._context.domainServicesSelectors.getResolveLocalizable())};_prepareAndCommit=async(e,t)=>{let i,n,o,r=this._context.domainContextSelectors.getStoreSystem(),a=r.stateSlices.committed.value.state,s=await this.prepare(a,e,t),l=s.map(({result:e})=>e),h=this.readSideEffects(s),d=this.readScreenshots(s),u=s.flatMap(e=>e.emissions);if(!t.active)return{results:l,sideEffects:h,screenshots:d,warnings:[],outcome:"conflict"};if(l.some(P)||0===u.length)return{results:l,sideEffects:h,screenshots:d,warnings:[],outcome:"none"};let m=(i=c(u[0]),n=c(u[u.length-1]),o=u.some(e=>void 0!==e.transformationLog),{kind:"committed",previousState:i.previousState,state:n.state,updates:u.flatMap(e=>e.updates),validity:n.validity,transformationLog:o?u.flatMap(e=>e.transformationLog??[]):void 0});return{results:l,sideEffects:h,screenshots:d,warnings:this.readWarnings(a,s),outcome:r.commitPrepared(m),preparedState:m.state}};execute=async e=>{let t=this._generation;if(!this._context.domainContextSelectors.getStoreSystem().isInitialized)return{results:e.map(()=>C),committed:!1,sideEffects:[],warnings:[],screenshots:new Map};let i=await this._prepareAndCommit(e,t),{results:n,sideEffects:o,warnings:r,screenshots:a,outcome:s,preparedState:l}="conflict"===i.outcome&&t.active?await this._prepareAndCommit(e,t):i;return"committed"===s?{results:n,committed:!0,sideEffects:o,warnings:r,screenshots:a,preparedState:l}:"held"===s?{results:n,committed:!1,message:"The changes wait for the user's approval and are not applied yet. Do not send them again; the next `[changes]` block lists them once approved.",sideEffects:o,warnings:r,screenshots:a,preparedState:l}:"conflict"===s?{results:n,committed:!1,message:"The changes were not committed, because the configuration changed while they were being applied. The results describe a state that was discarded. Query the current configuration and send the operations again if they still make sense.",sideEffects:o,warnings:r,screenshots:a}:{results:n,committed:!1,sideEffects:o,warnings:r,screenshots:a}}}
|