@ai-agent-forge/agent-forge 0.86.6 → 0.87.0
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/CHANGELOG.md +19 -1
- package/README.md +8 -9
- package/dist/artifacts/artifact-store.d.ts.map +1 -1
- package/dist/artifacts/artifact-store.js +9 -5
- package/dist/artifacts/artifact-store.js.map +1 -1
- package/dist/bundle/.build-manifest.json +410 -371
- package/dist/bundle/chunks/{chunk-A7GUOX2H.js → chunk-6ZKDNZHA.js} +5 -1
- package/dist/bundle/chunks/chunk-BFC2BDVJ.js +13 -0
- package/dist/bundle/chunks/chunk-MOHOLL3F.js +1456 -0
- package/dist/bundle/chunks/image-resize-worker.js +12 -1
- package/dist/bundle/chunks/{virtual-modules-3IZ4MYSQ.js → virtual-modules-KZ5DRH7Q.js} +1 -1
- package/dist/bundle/cli.js +1 -1
- package/dist/bundle/client.js +1 -1
- package/dist/bundle/index.js +2 -2
- package/dist/bundle/rpc-entry.js +1 -1
- package/dist/cli/args.d.ts.map +1 -1
- package/dist/cli/args.js +231 -185
- package/dist/cli/args.js.map +1 -1
- package/dist/cli/auth-check.d.ts.map +1 -1
- package/dist/cli/auth-check.js +3 -2
- package/dist/cli/auth-check.js.map +1 -1
- package/dist/cli/auth-command.d.ts.map +1 -1
- package/dist/cli/auth-command.js +15 -9
- package/dist/cli/auth-command.js.map +1 -1
- package/dist/cli/credential-print.d.ts.map +1 -1
- package/dist/cli/credential-print.js +14 -7
- package/dist/cli/credential-print.js.map +1 -1
- package/dist/cli/experimental/command.d.ts.map +1 -1
- package/dist/cli/experimental/command.js +6 -5
- package/dist/cli/experimental/command.js.map +1 -1
- package/dist/cli/list-models.d.ts.map +1 -1
- package/dist/cli/list-models.js +9 -8
- package/dist/cli/list-models.js.map +1 -1
- package/dist/cli/plugin-manager-controller.d.ts.map +1 -1
- package/dist/cli/plugin-manager-controller.js +2 -1
- package/dist/cli/plugin-manager-controller.js.map +1 -1
- package/dist/cli/serve.d.ts.map +1 -1
- package/dist/cli/serve.js +8 -5
- package/dist/cli/serve.js.map +1 -1
- package/dist/client/remote-session.d.ts.map +1 -1
- package/dist/client/remote-session.js +16 -9
- package/dist/client/remote-session.js.map +1 -1
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js +2 -1
- package/dist/config.js.map +1 -1
- package/dist/core/agent-capability-contract.d.ts +0 -7
- package/dist/core/agent-capability-contract.d.ts.map +1 -1
- package/dist/core/agent-capability-contract.js +72 -68
- package/dist/core/agent-capability-contract.js.map +1 -1
- package/dist/core/agent-session-bash.d.ts.map +1 -1
- package/dist/core/agent-session-bash.js +5 -4
- package/dist/core/agent-session-bash.js.map +1 -1
- package/dist/core/agent-session-compaction.d.ts.map +1 -1
- package/dist/core/agent-session-compaction.js +28 -22
- package/dist/core/agent-session-compaction.js.map +1 -1
- package/dist/core/agent-session-context.d.ts.map +1 -1
- package/dist/core/agent-session-context.js +18 -13
- package/dist/core/agent-session-context.js.map +1 -1
- package/dist/core/agent-session-model.d.ts.map +1 -1
- package/dist/core/agent-session-model.js +2 -1
- package/dist/core/agent-session-model.js.map +1 -1
- package/dist/core/agent-session-retry.d.ts.map +1 -1
- package/dist/core/agent-session-retry.js +3 -2
- package/dist/core/agent-session-retry.js.map +1 -1
- package/dist/core/agent-session-runtime.d.ts.map +1 -1
- package/dist/core/agent-session-runtime.js +7 -6
- package/dist/core/agent-session-runtime.js.map +1 -1
- package/dist/core/agent-session-services.d.ts +1 -1
- package/dist/core/agent-session-services.d.ts.map +1 -1
- package/dist/core/agent-session-services.js.map +1 -1
- package/dist/core/agent-session-tools.d.ts.map +1 -1
- package/dist/core/agent-session-tools.js +3 -2
- package/dist/core/agent-session-tools.js.map +1 -1
- package/dist/core/agent-session.d.ts +40 -2
- package/dist/core/agent-session.d.ts.map +1 -1
- package/dist/core/agent-session.js +142 -34
- package/dist/core/agent-session.js.map +1 -1
- package/dist/core/auth-guidance.d.ts.map +1 -1
- package/dist/core/auth-guidance.js +11 -5
- package/dist/core/auth-guidance.js.map +1 -1
- package/dist/core/auth-storage.d.ts.map +1 -1
- package/dist/core/auth-storage.js +9 -6
- package/dist/core/auth-storage.js.map +1 -1
- package/dist/core/compaction/compaction.d.ts.map +1 -1
- package/dist/core/compaction/compaction.js +2 -1
- package/dist/core/compaction/compaction.js.map +1 -1
- package/dist/core/embedded-sdk.d.ts.map +1 -1
- package/dist/core/embedded-sdk.js +10 -6
- package/dist/core/embedded-sdk.js.map +1 -1
- package/dist/core/export-html/index.d.ts.map +1 -1
- package/dist/core/export-html/index.js +9 -4
- package/dist/core/export-html/index.js.map +1 -1
- package/dist/core/extensions/agent-composition.d.ts.map +1 -1
- package/dist/core/extensions/agent-composition.js +26 -19
- package/dist/core/extensions/agent-composition.js.map +1 -1
- package/dist/core/extensions/bootstrap-agent-loop.d.ts.map +1 -1
- package/dist/core/extensions/bootstrap-agent-loop.js +3 -2
- package/dist/core/extensions/bootstrap-agent-loop.js.map +1 -1
- package/dist/core/extensions/bootstrap-lifecycle.d.ts.map +1 -1
- package/dist/core/extensions/bootstrap-lifecycle.js +20 -17
- package/dist/core/extensions/bootstrap-lifecycle.js.map +1 -1
- package/dist/core/extensions/bootstrap-overflow-policy.d.ts.map +1 -1
- package/dist/core/extensions/bootstrap-overflow-policy.js +2 -1
- package/dist/core/extensions/bootstrap-overflow-policy.js.map +1 -1
- package/dist/core/extensions/bootstrap-retry-policy.d.ts.map +1 -1
- package/dist/core/extensions/bootstrap-retry-policy.js +2 -1
- package/dist/core/extensions/bootstrap-retry-policy.js.map +1 -1
- package/dist/core/extensions/bootstrap-skills.d.ts.map +1 -1
- package/dist/core/extensions/bootstrap-skills.js +7 -6
- package/dist/core/extensions/bootstrap-skills.js.map +1 -1
- package/dist/core/extensions/bootstrap-tools.d.ts.map +1 -1
- package/dist/core/extensions/bootstrap-tools.js +2 -1
- package/dist/core/extensions/bootstrap-tools.js.map +1 -1
- package/dist/core/extensions/capability-plugin.d.ts.map +1 -1
- package/dist/core/extensions/capability-plugin.js +37 -13
- package/dist/core/extensions/capability-plugin.js.map +1 -1
- package/dist/core/extensions/capability-runtime-events.d.ts.map +1 -1
- package/dist/core/extensions/capability-runtime-events.js +17 -13
- package/dist/core/extensions/capability-runtime-events.js.map +1 -1
- package/dist/core/extensions/capability-runtime-guards.d.ts.map +1 -1
- package/dist/core/extensions/capability-runtime-guards.js +16 -15
- package/dist/core/extensions/capability-runtime-guards.js.map +1 -1
- package/dist/core/extensions/capability-runtime-manifest.d.ts.map +1 -1
- package/dist/core/extensions/capability-runtime-manifest.js +52 -30
- package/dist/core/extensions/capability-runtime-manifest.js.map +1 -1
- package/dist/core/extensions/capability-runtime-validation.d.ts.map +1 -1
- package/dist/core/extensions/capability-runtime-validation.js +66 -65
- package/dist/core/extensions/capability-runtime-validation.js.map +1 -1
- package/dist/core/extensions/capability-runtime.d.ts.map +1 -1
- package/dist/core/extensions/capability-runtime.js +147 -127
- package/dist/core/extensions/capability-runtime.js.map +1 -1
- package/dist/core/extensions/compaction-memory-failure-mode.d.ts.map +1 -1
- package/dist/core/extensions/compaction-memory-failure-mode.js +3 -2
- package/dist/core/extensions/compaction-memory-failure-mode.js.map +1 -1
- package/dist/core/extensions/context-strategy-binding.d.ts.map +1 -1
- package/dist/core/extensions/context-strategy-binding.js +7 -4
- package/dist/core/extensions/context-strategy-binding.js.map +1 -1
- package/dist/core/extensions/lifecycle-catalog.d.ts.map +1 -1
- package/dist/core/extensions/lifecycle-catalog.js +290 -279
- package/dist/core/extensions/lifecycle-catalog.js.map +1 -1
- package/dist/core/extensions/lifecycle-delivery-queue.d.ts.map +1 -1
- package/dist/core/extensions/lifecycle-delivery-queue.js +3 -2
- package/dist/core/extensions/lifecycle-delivery-queue.js.map +1 -1
- package/dist/core/facade/coding-agent-facade.d.ts +6 -0
- package/dist/core/facade/coding-agent-facade.d.ts.map +1 -1
- package/dist/core/facade/coding-agent-facade.js +2 -0
- package/dist/core/facade/coding-agent-facade.js.map +1 -1
- package/dist/core/http-dispatcher.d.ts.map +1 -1
- package/dist/core/http-dispatcher.js +2 -1
- package/dist/core/http-dispatcher.js.map +1 -1
- package/dist/core/i18n/index.d.ts +14 -0
- package/dist/core/i18n/index.d.ts.map +1 -0
- package/dist/core/i18n/index.js +67 -0
- package/dist/core/i18n/index.js.map +1 -0
- package/dist/core/i18n/locales/en/example.d.ts +7 -0
- package/dist/core/i18n/locales/en/example.d.ts.map +1 -0
- package/dist/core/i18n/locales/en/example.js +7 -0
- package/dist/core/i18n/locales/en/example.js.map +1 -0
- package/dist/core/i18n/locales/zh-cn/cli.d.ts +8 -0
- package/dist/core/i18n/locales/zh-cn/cli.d.ts.map +1 -0
- package/dist/core/i18n/locales/zh-cn/cli.js +227 -0
- package/dist/core/i18n/locales/zh-cn/cli.js.map +1 -0
- package/dist/core/i18n/locales/zh-cn/common.d.ts +6 -0
- package/dist/core/i18n/locales/zh-cn/common.d.ts.map +1 -0
- package/dist/core/i18n/locales/zh-cn/common.js +6 -0
- package/dist/core/i18n/locales/zh-cn/common.js.map +1 -0
- package/dist/core/i18n/locales/zh-cn/core-contract-core.d.ts +13 -0
- package/dist/core/i18n/locales/zh-cn/core-contract-core.d.ts.map +1 -0
- package/dist/core/i18n/locales/zh-cn/core-contract-core.js +173 -0
- package/dist/core/i18n/locales/zh-cn/core-contract-core.js.map +1 -0
- package/dist/core/i18n/locales/zh-cn/core-contract-extensions.d.ts +12 -0
- package/dist/core/i18n/locales/zh-cn/core-contract-extensions.d.ts.map +1 -0
- package/dist/core/i18n/locales/zh-cn/core-contract-extensions.js +582 -0
- package/dist/core/i18n/locales/zh-cn/core-contract-extensions.js.map +1 -0
- package/dist/core/i18n/locales/zh-cn/core-contract-final.d.ts +9 -0
- package/dist/core/i18n/locales/zh-cn/core-contract-final.d.ts.map +1 -0
- package/dist/core/i18n/locales/zh-cn/core-contract-final.js +55 -0
- package/dist/core/i18n/locales/zh-cn/core-contract-final.js.map +1 -0
- package/dist/core/i18n/locales/zh-cn/core-contract-plugins.d.ts +11 -0
- package/dist/core/i18n/locales/zh-cn/core-contract-plugins.d.ts.map +1 -0
- package/dist/core/i18n/locales/zh-cn/core-contract-plugins.js +455 -0
- package/dist/core/i18n/locales/zh-cn/core-contract-plugins.js.map +1 -0
- package/dist/core/i18n/locales/zh-cn/core-errors.d.ts +9 -0
- package/dist/core/i18n/locales/zh-cn/core-errors.d.ts.map +1 -0
- package/dist/core/i18n/locales/zh-cn/core-errors.js +191 -0
- package/dist/core/i18n/locales/zh-cn/core-errors.js.map +1 -0
- package/dist/core/i18n/locales/zh-cn/example.d.ts +7 -0
- package/dist/core/i18n/locales/zh-cn/example.d.ts.map +1 -0
- package/dist/core/i18n/locales/zh-cn/example.js +10 -0
- package/dist/core/i18n/locales/zh-cn/example.js.map +1 -0
- package/dist/core/i18n/locales/zh-cn/index.d.ts +2 -0
- package/dist/core/i18n/locales/zh-cn/index.d.ts.map +1 -0
- package/dist/core/i18n/locales/zh-cn/index.js +41 -0
- package/dist/core/i18n/locales/zh-cn/index.js.map +1 -0
- package/dist/core/i18n/locales/zh-cn/interactive-mode.d.ts +10 -0
- package/dist/core/i18n/locales/zh-cn/interactive-mode.d.ts.map +1 -0
- package/dist/core/i18n/locales/zh-cn/interactive-mode.js +265 -0
- package/dist/core/i18n/locales/zh-cn/interactive-mode.js.map +1 -0
- package/dist/core/i18n/locales/zh-cn/keybindings.d.ts +11 -0
- package/dist/core/i18n/locales/zh-cn/keybindings.d.ts.map +1 -0
- package/dist/core/i18n/locales/zh-cn/keybindings.js +67 -0
- package/dist/core/i18n/locales/zh-cn/keybindings.js.map +1 -0
- package/dist/core/i18n/locales/zh-cn/slash-commands.d.ts +7 -0
- package/dist/core/i18n/locales/zh-cn/slash-commands.d.ts.map +1 -0
- package/dist/core/i18n/locales/zh-cn/slash-commands.js +39 -0
- package/dist/core/i18n/locales/zh-cn/slash-commands.js.map +1 -0
- package/dist/core/i18n/locales/zh-cn/tui-builtin.d.ts +10 -0
- package/dist/core/i18n/locales/zh-cn/tui-builtin.d.ts.map +1 -0
- package/dist/core/i18n/locales/zh-cn/tui-builtin.js +15 -0
- package/dist/core/i18n/locales/zh-cn/tui-builtin.js.map +1 -0
- package/dist/core/i18n/locales/zh-cn/tui-components-misc.d.ts +13 -0
- package/dist/core/i18n/locales/zh-cn/tui-components-misc.d.ts.map +1 -0
- package/dist/core/i18n/locales/zh-cn/tui-components-misc.js +102 -0
- package/dist/core/i18n/locales/zh-cn/tui-components-misc.js.map +1 -0
- package/dist/core/i18n/locales/zh-cn/tui-components-selectors.d.ts +12 -0
- package/dist/core/i18n/locales/zh-cn/tui-components-selectors.d.ts.map +1 -0
- package/dist/core/i18n/locales/zh-cn/tui-components-selectors.js +288 -0
- package/dist/core/i18n/locales/zh-cn/tui-components-selectors.js.map +1 -0
- package/dist/core/i18n/locales/zh-cn/tui-interactive-misc.d.ts +9 -0
- package/dist/core/i18n/locales/zh-cn/tui-interactive-misc.d.ts.map +1 -0
- package/dist/core/i18n/locales/zh-cn/tui-interactive-misc.js +79 -0
- package/dist/core/i18n/locales/zh-cn/tui-interactive-misc.js.map +1 -0
- package/dist/core/i18n/locales/zh-cn/tui-self-owned.d.ts +8 -0
- package/dist/core/i18n/locales/zh-cn/tui-self-owned.d.ts.map +1 -0
- package/dist/core/i18n/locales/zh-cn/tui-self-owned.js +72 -0
- package/dist/core/i18n/locales/zh-cn/tui-self-owned.js.map +1 -0
- package/dist/core/keybindings.d.ts +15 -0
- package/dist/core/keybindings.d.ts.map +1 -1
- package/dist/core/keybindings.js +18 -0
- package/dist/core/keybindings.js.map +1 -1
- package/dist/core/logger.d.ts.map +1 -1
- package/dist/core/logger.js +5 -1
- package/dist/core/logger.js.map +1 -1
- package/dist/core/model-registry.d.ts.map +1 -1
- package/dist/core/model-registry.js +2 -1
- package/dist/core/model-registry.js.map +1 -1
- package/dist/core/model-runtime.d.ts.map +1 -1
- package/dist/core/model-runtime.js +8 -4
- package/dist/core/model-runtime.js.map +1 -1
- package/dist/core/package-install-host.d.ts.map +1 -1
- package/dist/core/package-install-host.js +4 -3
- package/dist/core/package-install-host.js.map +1 -1
- package/dist/core/package-manager.d.ts.map +1 -1
- package/dist/core/package-manager.js +15 -10
- package/dist/core/package-manager.js.map +1 -1
- package/dist/core/package-resource-collection.d.ts.map +1 -1
- package/dist/core/package-resource-collection.js +2 -1
- package/dist/core/package-resource-collection.js.map +1 -1
- package/dist/core/package-source.d.ts.map +1 -1
- package/dist/core/package-source.js +3 -2
- package/dist/core/package-source.js.map +1 -1
- package/dist/core/provider-composer.d.ts.map +1 -1
- package/dist/core/provider-composer.js +22 -13
- package/dist/core/provider-composer.js.map +1 -1
- package/dist/core/remote-catalog-provider.d.ts.map +1 -1
- package/dist/core/remote-catalog-provider.js +6 -2
- package/dist/core/remote-catalog-provider.js.map +1 -1
- package/dist/core/resolve-config-value.d.ts.map +1 -1
- package/dist/core/resolve-config-value.js +15 -5
- package/dist/core/resolve-config-value.js.map +1 -1
- package/dist/core/sdk.d.ts +19 -5
- package/dist/core/sdk.d.ts.map +1 -1
- package/dist/core/sdk.js +74 -54
- package/dist/core/sdk.js.map +1 -1
- package/dist/core/session-cwd.d.ts.map +1 -1
- package/dist/core/session-cwd.js +5 -2
- package/dist/core/session-cwd.js.map +1 -1
- package/dist/core/session-export.d.ts.map +1 -1
- package/dist/core/session-export.js +2 -1
- package/dist/core/session-export.js.map +1 -1
- package/dist/core/session-manager.d.ts.map +1 -1
- package/dist/core/session-manager.js +39 -29
- package/dist/core/session-manager.js.map +1 -1
- package/dist/core/session-storage.d.ts.map +1 -1
- package/dist/core/session-storage.js +3 -3
- package/dist/core/session-storage.js.map +1 -1
- package/dist/core/settings-manager.d.ts +11 -0
- package/dist/core/settings-manager.d.ts.map +1 -1
- package/dist/core/settings-manager.js +27 -5
- package/dist/core/settings-manager.js.map +1 -1
- package/dist/core/slash-commands.d.ts.map +1 -1
- package/dist/core/slash-commands.js +53 -32
- package/dist/core/slash-commands.js.map +1 -1
- package/dist/core/system-prompt.d.ts.map +1 -1
- package/dist/core/system-prompt.js +25 -2
- package/dist/core/system-prompt.js.map +1 -1
- package/dist/core/tools/bash.d.ts.map +1 -1
- package/dist/core/tools/bash.js +11 -7
- package/dist/core/tools/bash.js.map +1 -1
- package/dist/core/tools/edit-diff.d.ts.map +1 -1
- package/dist/core/tools/edit-diff.js +9 -4
- package/dist/core/tools/edit-diff.js.map +1 -1
- package/dist/core/tools/edit.d.ts.map +1 -1
- package/dist/core/tools/edit.js +4 -3
- package/dist/core/tools/edit.js.map +1 -1
- package/dist/core/tools/index.d.ts.map +1 -1
- package/dist/core/tools/index.js +3 -2
- package/dist/core/tools/index.js.map +1 -1
- package/dist/core/tools/output-accumulator.d.ts.map +1 -1
- package/dist/core/tools/output-accumulator.js +2 -1
- package/dist/core/tools/output-accumulator.js.map +1 -1
- package/dist/core/tools/read.d.ts.map +1 -1
- package/dist/core/tools/read.js +6 -2
- package/dist/core/tools/read.js.map +1 -1
- package/dist/core/tools/write.d.ts.map +1 -1
- package/dist/core/tools/write.js +2 -1
- package/dist/core/tools/write.js.map +1 -1
- package/dist/durable/durable-service.d.ts.map +1 -1
- package/dist/durable/durable-service.js +25 -18
- package/dist/durable/durable-service.js.map +1 -1
- package/dist/host/checkpoint-commit.d.ts.map +1 -1
- package/dist/host/checkpoint-commit.js +2 -1
- package/dist/host/checkpoint-commit.js.map +1 -1
- package/dist/host/manual-compaction.d.ts.map +1 -1
- package/dist/host/manual-compaction.js +2 -1
- package/dist/host/manual-compaction.js.map +1 -1
- package/dist/host/output-projection.d.ts +0 -13
- package/dist/host/output-projection.d.ts.map +1 -1
- package/dist/host/output-projection.js +16 -2
- package/dist/host/output-projection.js.map +1 -1
- package/dist/host/summary-retry.d.ts.map +1 -1
- package/dist/host/summary-retry.js +3 -2
- package/dist/host/summary-retry.js.map +1 -1
- package/dist/main.d.ts.map +1 -1
- package/dist/main.js +94 -58
- package/dist/main.js.map +1 -1
- package/dist/modes/interactive/components/agents-view.d.ts.map +1 -1
- package/dist/modes/interactive/components/agents-view.js +18 -15
- package/dist/modes/interactive/components/agents-view.js.map +1 -1
- package/dist/modes/interactive/components/assistant-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/assistant-message.js +6 -5
- package/dist/modes/interactive/components/assistant-message.js.map +1 -1
- package/dist/modes/interactive/components/bash-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/bash-execution.js +12 -7
- package/dist/modes/interactive/components/bash-execution.js.map +1 -1
- package/dist/modes/interactive/components/bordered-loader.d.ts.map +1 -1
- package/dist/modes/interactive/components/bordered-loader.js +2 -1
- package/dist/modes/interactive/components/bordered-loader.js.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/branch-summary-message.js +6 -5
- package/dist/modes/interactive/components/branch-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/compaction-summary-message.js +9 -5
- package/dist/modes/interactive/components/compaction-summary-message.js.map +1 -1
- package/dist/modes/interactive/components/config-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/config-selector.js +18 -15
- package/dist/modes/interactive/components/config-selector.js.map +1 -1
- package/dist/modes/interactive/components/custom-entry.d.ts.map +1 -1
- package/dist/modes/interactive/components/custom-entry.js +2 -1
- package/dist/modes/interactive/components/custom-entry.js.map +1 -1
- package/dist/modes/interactive/components/dialog-editor.d.ts.map +1 -1
- package/dist/modes/interactive/components/dialog-editor.js +5 -4
- package/dist/modes/interactive/components/dialog-editor.js.map +1 -1
- package/dist/modes/interactive/components/dialog-input.d.ts.map +1 -1
- package/dist/modes/interactive/components/dialog-input.js +2 -1
- package/dist/modes/interactive/components/dialog-input.js.map +1 -1
- package/dist/modes/interactive/components/dialog-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/dialog-selector.js +4 -3
- package/dist/modes/interactive/components/dialog-selector.js.map +1 -1
- package/dist/modes/interactive/components/first-time-setup.d.ts.map +1 -1
- package/dist/modes/interactive/components/first-time-setup.js +11 -10
- package/dist/modes/interactive/components/first-time-setup.js.map +1 -1
- package/dist/modes/interactive/components/footer.d.ts.map +1 -1
- package/dist/modes/interactive/components/footer.js +7 -4
- package/dist/modes/interactive/components/footer.js.map +1 -1
- package/dist/modes/interactive/components/index.d.ts +1 -0
- package/dist/modes/interactive/components/index.d.ts.map +1 -1
- package/dist/modes/interactive/components/index.js +1 -0
- package/dist/modes/interactive/components/index.js.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.d.ts.map +1 -1
- package/dist/modes/interactive/components/keybinding-hints.js +3 -2
- package/dist/modes/interactive/components/keybinding-hints.js.map +1 -1
- package/dist/modes/interactive/components/login-dialog.d.ts.map +1 -1
- package/dist/modes/interactive/components/login-dialog.js +12 -11
- package/dist/modes/interactive/components/login-dialog.js.map +1 -1
- package/dist/modes/interactive/components/mermaid.d.ts.map +1 -1
- package/dist/modes/interactive/components/mermaid.js +6 -2
- package/dist/modes/interactive/components/mermaid.js.map +1 -1
- package/dist/modes/interactive/components/model-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/model-selector.js +28 -16
- package/dist/modes/interactive/components/model-selector.js.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/oauth-selector.js +10 -9
- package/dist/modes/interactive/components/oauth-selector.js.map +1 -1
- package/dist/modes/interactive/components/plugin-manager-entry.d.ts.map +1 -1
- package/dist/modes/interactive/components/plugin-manager-entry.js +22 -13
- package/dist/modes/interactive/components/plugin-manager-entry.js.map +1 -1
- package/dist/modes/interactive/components/plugin-selection-entry.d.ts.map +1 -1
- package/dist/modes/interactive/components/plugin-selection-entry.js +27 -12
- package/dist/modes/interactive/components/plugin-selection-entry.js.map +1 -1
- package/dist/modes/interactive/components/queue-manager-selector.d.ts +60 -0
- package/dist/modes/interactive/components/queue-manager-selector.d.ts.map +1 -0
- package/dist/modes/interactive/components/queue-manager-selector.js +166 -0
- package/dist/modes/interactive/components/queue-manager-selector.js.map +1 -0
- package/dist/modes/interactive/components/scoped-models-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/scoped-models-selector.js +16 -14
- package/dist/modes/interactive/components/scoped-models-selector.js.map +1 -1
- package/dist/modes/interactive/components/session-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/session-selector.js +43 -31
- package/dist/modes/interactive/components/session-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-selector.d.ts +2 -0
- package/dist/modes/interactive/components/settings-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-selector.js +113 -96
- package/dist/modes/interactive/components/settings-selector.js.map +1 -1
- package/dist/modes/interactive/components/settings-submenu.d.ts.map +1 -1
- package/dist/modes/interactive/components/settings-submenu.js +5 -4
- package/dist/modes/interactive/components/settings-submenu.js.map +1 -1
- package/dist/modes/interactive/components/show-images-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/show-images-selector.js +3 -2
- package/dist/modes/interactive/components/show-images-selector.js.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.d.ts.map +1 -1
- package/dist/modes/interactive/components/skill-invocation-message.js +4 -3
- package/dist/modes/interactive/components/skill-invocation-message.js.map +1 -1
- package/dist/modes/interactive/components/status-indicator.d.ts.map +1 -1
- package/dist/modes/interactive/components/status-indicator.js +14 -5
- package/dist/modes/interactive/components/status-indicator.js.map +1 -1
- package/dist/modes/interactive/components/theme-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/theme-selector.js +2 -1
- package/dist/modes/interactive/components/theme-selector.js.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/thinking-selector.js +11 -4
- package/dist/modes/interactive/components/thinking-selector.js.map +1 -1
- package/dist/modes/interactive/components/tool-execution.d.ts.map +1 -1
- package/dist/modes/interactive/components/tool-execution.js +8 -3
- package/dist/modes/interactive/components/tool-execution.js.map +1 -1
- package/dist/modes/interactive/components/tree-list.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-list.js +7 -6
- package/dist/modes/interactive/components/tree-list.js.map +1 -1
- package/dist/modes/interactive/components/tree-render.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-render.js +28 -23
- package/dist/modes/interactive/components/tree-render.js.map +1 -1
- package/dist/modes/interactive/components/tree-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/tree-selector.js +9 -7
- package/dist/modes/interactive/components/tree-selector.js.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.d.ts.map +1 -1
- package/dist/modes/interactive/components/user-message-selector.js +5 -4
- package/dist/modes/interactive/components/user-message-selector.js.map +1 -1
- package/dist/modes/interactive/components/workflow-view.d.ts.map +1 -1
- package/dist/modes/interactive/components/workflow-view.js +36 -21
- package/dist/modes/interactive/components/workflow-view.js.map +1 -1
- package/dist/modes/interactive/external-editor.d.ts.map +1 -1
- package/dist/modes/interactive/external-editor.js +2 -1
- package/dist/modes/interactive/external-editor.js.map +1 -1
- package/dist/modes/interactive/interactive-auth.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-auth.js +71 -40
- package/dist/modes/interactive/interactive-auth.js.map +1 -1
- package/dist/modes/interactive/interactive-commands.d.ts +1 -0
- package/dist/modes/interactive/interactive-commands.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-commands.js +3 -0
- package/dist/modes/interactive/interactive-commands.js.map +1 -1
- package/dist/modes/interactive/interactive-dialog-ui.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-dialog-ui.js +5 -5
- package/dist/modes/interactive/interactive-dialog-ui.js.map +1 -1
- package/dist/modes/interactive/interactive-format.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-format.js +34 -18
- package/dist/modes/interactive/interactive-format.js.map +1 -1
- package/dist/modes/interactive/interactive-helpers.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-helpers.js +7 -2
- package/dist/modes/interactive/interactive-helpers.js.map +1 -1
- package/dist/modes/interactive/interactive-mode.d.ts +4 -1
- package/dist/modes/interactive/interactive-mode.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-mode.js +327 -243
- package/dist/modes/interactive/interactive-mode.js.map +1 -1
- package/dist/modes/interactive/interactive-selectors.d.ts +9 -0
- package/dist/modes/interactive/interactive-selectors.d.ts.map +1 -1
- package/dist/modes/interactive/interactive-selectors.js +79 -25
- package/dist/modes/interactive/interactive-selectors.js.map +1 -1
- package/dist/modes/interactive/theme/theme-controller.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme-controller.js +5 -1
- package/dist/modes/interactive/theme/theme-controller.js.map +1 -1
- package/dist/modes/interactive/theme/theme.d.ts.map +1 -1
- package/dist/modes/interactive/theme/theme.js +26 -23
- package/dist/modes/interactive/theme/theme.js.map +1 -1
- package/dist/modes/json-event.d.ts.map +1 -1
- package/dist/modes/json-event.js +3 -2
- package/dist/modes/json-event.js.map +1 -1
- package/dist/modes/print-mode.d.ts.map +1 -1
- package/dist/modes/print-mode.js +3 -2
- package/dist/modes/print-mode.js.map +1 -1
- package/dist/modes/rpc/rpc-client.d.ts.map +1 -1
- package/dist/modes/rpc/rpc-client.js +3 -2
- package/dist/modes/rpc/rpc-client.js.map +1 -1
- package/dist/package-manager-cli.d.ts.map +1 -1
- package/dist/package-manager-cli.js +28 -13
- package/dist/package-manager-cli.js.map +1 -1
- package/dist/plugins/ecosystem/catalog.d.ts.map +1 -1
- package/dist/plugins/ecosystem/catalog.js +3 -2
- package/dist/plugins/ecosystem/catalog.js.map +1 -1
- package/dist/plugins/ecosystem/cli.d.ts.map +1 -1
- package/dist/plugins/ecosystem/cli.js +2 -1
- package/dist/plugins/ecosystem/cli.js.map +1 -1
- package/dist/plugins/ecosystem/default-plugin-market.d.ts.map +1 -1
- package/dist/plugins/ecosystem/default-plugin-market.js +3 -2
- package/dist/plugins/ecosystem/default-plugin-market.js.map +1 -1
- package/dist/plugins/ecosystem/distribution.d.ts.map +1 -1
- package/dist/plugins/ecosystem/distribution.js +2 -1
- package/dist/plugins/ecosystem/distribution.js.map +1 -1
- package/dist/plugins/ecosystem/installer.d.ts.map +1 -1
- package/dist/plugins/ecosystem/installer.js +3 -2
- package/dist/plugins/ecosystem/installer.js.map +1 -1
- package/dist/plugins/ecosystem/node-disk-registry-source.d.ts.map +1 -1
- package/dist/plugins/ecosystem/node-disk-registry-source.js +20 -17
- package/dist/plugins/ecosystem/node-disk-registry-source.js.map +1 -1
- package/dist/plugins/ecosystem/node-distribution-host.d.ts.map +1 -1
- package/dist/plugins/ecosystem/node-distribution-host.js +35 -34
- package/dist/plugins/ecosystem/node-distribution-host.js.map +1 -1
- package/dist/plugins/ecosystem/node-npm-registry-source.d.ts.map +1 -1
- package/dist/plugins/ecosystem/node-npm-registry-source.js +35 -34
- package/dist/plugins/ecosystem/node-npm-registry-source.js.map +1 -1
- package/dist/plugins/ecosystem/node-package-install-host.d.ts.map +1 -1
- package/dist/plugins/ecosystem/node-package-install-host.js +9 -8
- package/dist/plugins/ecosystem/node-package-install-host.js.map +1 -1
- package/dist/plugins/ecosystem/node-package-install-persistence.d.ts.map +1 -1
- package/dist/plugins/ecosystem/node-package-install-persistence.js +4 -3
- package/dist/plugins/ecosystem/node-package-install-persistence.js.map +1 -1
- package/dist/plugins/ecosystem/node-plugin-bootstrap.d.ts.map +1 -1
- package/dist/plugins/ecosystem/node-plugin-bootstrap.js +21 -5
- package/dist/plugins/ecosystem/node-plugin-bootstrap.js.map +1 -1
- package/dist/plugins/ecosystem/node-plugin-trust-root.d.ts.map +1 -1
- package/dist/plugins/ecosystem/node-plugin-trust-root.js +10 -9
- package/dist/plugins/ecosystem/node-plugin-trust-root.js.map +1 -1
- package/dist/plugins/ecosystem/node-registry-source.d.ts.map +1 -1
- package/dist/plugins/ecosystem/node-registry-source.js +31 -30
- package/dist/plugins/ecosystem/node-registry-source.js.map +1 -1
- package/dist/plugins/ecosystem/node-release-package-source.d.ts.map +1 -1
- package/dist/plugins/ecosystem/node-release-package-source.js +30 -29
- package/dist/plugins/ecosystem/node-release-package-source.js.map +1 -1
- package/dist/plugins/ecosystem/node-tar-writer.d.ts.map +1 -1
- package/dist/plugins/ecosystem/node-tar-writer.js +11 -10
- package/dist/plugins/ecosystem/node-tar-writer.js.map +1 -1
- package/dist/plugins/ecosystem/node-url-package-source.d.ts.map +1 -1
- package/dist/plugins/ecosystem/node-url-package-source.js +21 -20
- package/dist/plugins/ecosystem/node-url-package-source.js.map +1 -1
- package/dist/plugins/ecosystem/plugin-acquisition.d.ts.map +1 -1
- package/dist/plugins/ecosystem/plugin-acquisition.js +3 -2
- package/dist/plugins/ecosystem/plugin-acquisition.js.map +1 -1
- package/dist/plugins/ecosystem/registry-cli-adapter.d.ts.map +1 -1
- package/dist/plugins/ecosystem/registry-cli-adapter.js +2 -1
- package/dist/plugins/ecosystem/registry-cli-adapter.js.map +1 -1
- package/dist/plugins/ecosystem/registry.d.ts.map +1 -1
- package/dist/plugins/ecosystem/registry.js +35 -32
- package/dist/plugins/ecosystem/registry.js.map +1 -1
- package/dist/plugins/ecosystem/resolver.d.ts.map +1 -1
- package/dist/plugins/ecosystem/resolver.js +3 -2
- package/dist/plugins/ecosystem/resolver.js.map +1 -1
- package/dist/plugins/ecosystem/selection-store.d.ts.map +1 -1
- package/dist/plugins/ecosystem/selection-store.js +11 -10
- package/dist/plugins/ecosystem/selection-store.js.map +1 -1
- package/dist/plugins/ecosystem/selection.d.ts.map +1 -1
- package/dist/plugins/ecosystem/selection.js +8 -7
- package/dist/plugins/ecosystem/selection.js.map +1 -1
- package/dist/plugins/ecosystem/state.d.ts.map +1 -1
- package/dist/plugins/ecosystem/state.js +24 -23
- package/dist/plugins/ecosystem/state.js.map +1 -1
- package/dist/plugins/ecosystem/updates.d.ts.map +1 -1
- package/dist/plugins/ecosystem/updates.js +5 -4
- package/dist/plugins/ecosystem/updates.js.map +1 -1
- package/dist/plugins/mcp-http.d.ts +0 -17
- package/dist/plugins/mcp-http.d.ts.map +1 -1
- package/dist/plugins/mcp-http.js +30 -7
- package/dist/plugins/mcp-http.js.map +1 -1
- package/dist/plugins/plugin-supervisor.d.ts.map +1 -1
- package/dist/plugins/plugin-supervisor.js +19 -1
- package/dist/plugins/plugin-supervisor.js.map +1 -1
- package/dist/profile/first-roles.d.ts.map +1 -1
- package/dist/profile/first-roles.js +10 -1
- package/dist/profile/first-roles.js.map +1 -1
- package/dist/profile/goal-plugin.d.ts.map +1 -1
- package/dist/profile/goal-plugin.js +24 -5
- package/dist/profile/goal-plugin.js.map +1 -1
- package/dist/profile/identity.d.ts.map +1 -1
- package/dist/profile/identity.js +7 -6
- package/dist/profile/identity.js.map +1 -1
- package/dist/profile/lock.d.ts.map +1 -1
- package/dist/profile/lock.js +15 -1
- package/dist/profile/lock.js.map +1 -1
- package/dist/profile/plan-plugin.d.ts.map +1 -1
- package/dist/profile/plan-plugin.js +26 -13
- package/dist/profile/plan-plugin.js.map +1 -1
- package/dist/profile/plugin-profiles.d.ts.map +1 -1
- package/dist/profile/plugin-profiles.js +2 -1
- package/dist/profile/plugin-profiles.js.map +1 -1
- package/dist/profile/policy-manifest.d.ts.map +1 -1
- package/dist/profile/policy-manifest.js +5 -4
- package/dist/profile/policy-manifest.js.map +1 -1
- package/dist/profile/profile-registry.d.ts +0 -12
- package/dist/profile/profile-registry.d.ts.map +1 -1
- package/dist/profile/profile-registry.js +14 -1
- package/dist/profile/profile-registry.js.map +1 -1
- package/dist/profile/role-catalog.d.ts +0 -1
- package/dist/profile/role-catalog.d.ts.map +1 -1
- package/dist/profile/role-catalog.js +17 -15
- package/dist/profile/role-catalog.js.map +1 -1
- package/dist/profile/role-orchestrator.d.ts.map +1 -1
- package/dist/profile/role-orchestrator.js +8 -7
- package/dist/profile/role-orchestrator.js.map +1 -1
- package/dist/profile/role-runner.d.ts.map +1 -1
- package/dist/profile/role-runner.js +3 -2
- package/dist/profile/role-runner.js.map +1 -1
- package/dist/profile/root-facade.d.ts.map +1 -1
- package/dist/profile/root-facade.js +2 -1
- package/dist/profile/root-facade.js.map +1 -1
- package/dist/profile/skill-discovery-wiring.d.ts.map +1 -1
- package/dist/profile/skill-discovery-wiring.js +7 -2
- package/dist/profile/skill-discovery-wiring.js.map +1 -1
- package/dist/profile/state-store.d.ts.map +1 -1
- package/dist/profile/state-store.js +13 -9
- package/dist/profile/state-store.js.map +1 -1
- package/dist/profile/todo-plugin.d.ts.map +1 -1
- package/dist/profile/todo-plugin.js +9 -4
- package/dist/profile/todo-plugin.js.map +1 -1
- package/dist/profiles/builtin-suites.d.ts +13 -6
- package/dist/profiles/builtin-suites.d.ts.map +1 -1
- package/dist/profiles/builtin-suites.js +15 -6
- package/dist/profiles/builtin-suites.js.map +1 -1
- package/dist/profiles/suite-loader.d.ts +25 -1
- package/dist/profiles/suite-loader.d.ts.map +1 -1
- package/dist/profiles/suite-loader.js +34 -9
- package/dist/profiles/suite-loader.js.map +1 -1
- package/dist/remote/server-entry.d.ts.map +1 -1
- package/dist/remote/server-entry.js +3 -2
- package/dist/remote/server-entry.js.map +1 -1
- package/dist/remote/session-source.d.ts.map +1 -1
- package/dist/remote/session-source.js +8 -4
- package/dist/remote/session-source.js.map +1 -1
- package/dist/share/session-share.d.ts.map +1 -1
- package/dist/share/session-share.js +14 -2
- package/dist/share/session-share.js.map +1 -1
- package/dist/testing/plugin-testkit.d.ts.map +1 -1
- package/dist/testing/plugin-testkit.js +4 -3
- package/dist/testing/plugin-testkit.js.map +1 -1
- package/dist/testing/runtime-delivery-queue.d.ts.map +1 -1
- package/dist/testing/runtime-delivery-queue.js +2 -1
- package/dist/testing/runtime-delivery-queue.js.map +1 -1
- package/dist/testing/session-plugin-testkit.d.ts.map +1 -1
- package/dist/testing/session-plugin-testkit.js +10 -7
- package/dist/testing/session-plugin-testkit.js.map +1 -1
- package/dist/utils/ansi.d.ts.map +1 -1
- package/dist/utils/ansi.js +2 -1
- package/dist/utils/ansi.js.map +1 -1
- package/dist/utils/clipboard.d.ts.map +1 -1
- package/dist/utils/clipboard.js +7 -6
- package/dist/utils/clipboard.js.map +1 -1
- package/dist/utils/image-resize-worker.d.ts.map +1 -1
- package/dist/utils/image-resize-worker.js +3 -2
- package/dist/utils/image-resize-worker.js.map +1 -1
- package/dist/utils/shell.d.ts.map +1 -1
- package/dist/utils/shell.js +9 -8
- package/dist/utils/shell.js.map +1 -1
- package/dist/utils/tools-manager.d.ts.map +1 -1
- package/dist/utils/tools-manager.js +23 -13
- package/dist/utils/tools-manager.js.map +1 -1
- package/dist/utils/version-check.d.ts.map +1 -1
- package/dist/utils/version-check.js +5 -1
- package/dist/utils/version-check.js.map +1 -1
- package/docs/keybindings.md +3 -0
- package/docs/quickstart.md +1 -1
- package/docs/settings.md +1 -0
- package/docs/terminal-setup.md +2 -3
- package/docs/usage.md +6 -5
- package/examples/extensions/with-deps/package-lock.json +2 -2
- package/examples/extensions/with-deps/package.json +1 -1
- package/examples/extensions/with-deps/plugin.json +1 -1
- package/package.json +1 -1
- package/dist/bundle/chunks/chunk-EALJ5DDX.js +0 -1452
|
@@ -3,6 +3,7 @@ import { readFile } from "node:fs/promises";
|
|
|
3
3
|
import { createRequire } from "node:module";
|
|
4
4
|
import * as path from "node:path";
|
|
5
5
|
import { parseCapabilityPluginManifest, } from "@agent-forge/plugin-sdk";
|
|
6
|
+
import { t } from "../i18n/index.js";
|
|
6
7
|
import { PLUGIN_DISPOSE_EVENT_ID, PLUGIN_DISPOSE_EVENT_VERSION, PLUGIN_READY_EVENT_ID, PLUGIN_READY_EVENT_VERSION, } from "./lifecycle-catalog.js";
|
|
7
8
|
export { parseCapabilityPluginManifest } from "@agent-forge/plugin-sdk";
|
|
8
9
|
const activePlugins = new WeakMap();
|
|
@@ -107,7 +108,7 @@ function normalizePluginInstance(value, manifest) {
|
|
|
107
108
|
if (value === undefined)
|
|
108
109
|
return undefined;
|
|
109
110
|
if (!isPluginInstance(value)) {
|
|
110
|
-
throw new Error(
|
|
111
|
+
throw new Error(t("Capability plugin factory must return void or an instance with dispose(): {id}", { id: manifest.id }));
|
|
111
112
|
}
|
|
112
113
|
return value;
|
|
113
114
|
}
|
|
@@ -115,7 +116,9 @@ function normalizePluginSyncInstance(value, manifest) {
|
|
|
115
116
|
if (value === undefined)
|
|
116
117
|
return undefined;
|
|
117
118
|
if (!isPluginInstance(value)) {
|
|
118
|
-
throw new Error(
|
|
119
|
+
throw new Error(t("Synchronous capability plugin factory must return void or an instance with dispose(): {id}", {
|
|
120
|
+
id: manifest.id,
|
|
121
|
+
}));
|
|
119
122
|
}
|
|
120
123
|
return value;
|
|
121
124
|
}
|
|
@@ -191,20 +194,29 @@ export function discoverCapabilityPluginManifests(pluginDirectories) {
|
|
|
191
194
|
catch (linkError) {
|
|
192
195
|
if (isMissingPathError(linkError))
|
|
193
196
|
return;
|
|
194
|
-
throw new Error(
|
|
197
|
+
throw new Error(t("Failed to inspect capability plugin directory {directory}: {reason}", {
|
|
198
|
+
directory: resolvedDirectory,
|
|
199
|
+
reason: linkError instanceof Error ? linkError.message : String(linkError),
|
|
200
|
+
}));
|
|
195
201
|
}
|
|
196
202
|
}
|
|
197
|
-
throw new Error(
|
|
203
|
+
throw new Error(t("Failed to inspect capability plugin directory {directory}: {reason}", {
|
|
204
|
+
directory: resolvedDirectory,
|
|
205
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
206
|
+
}));
|
|
198
207
|
}
|
|
199
208
|
if (!stats.isDirectory()) {
|
|
200
|
-
throw new Error(
|
|
209
|
+
throw new Error(t("Capability plugin path must be a directory: {directory}", { directory: resolvedDirectory }));
|
|
201
210
|
}
|
|
202
211
|
let canonicalDirectory;
|
|
203
212
|
try {
|
|
204
213
|
canonicalDirectory = realpathSync(resolvedDirectory);
|
|
205
214
|
}
|
|
206
215
|
catch (error) {
|
|
207
|
-
throw new Error(
|
|
216
|
+
throw new Error(t("Failed to resolve capability plugin directory {directory}: {reason}", {
|
|
217
|
+
directory: resolvedDirectory,
|
|
218
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
219
|
+
}));
|
|
208
220
|
}
|
|
209
221
|
if (seenDirectories.has(canonicalDirectory))
|
|
210
222
|
return;
|
|
@@ -214,7 +226,10 @@ export function discoverCapabilityPluginManifests(pluginDirectories) {
|
|
|
214
226
|
entries = readdirSync(resolvedDirectory, { withFileTypes: true, encoding: "utf8" });
|
|
215
227
|
}
|
|
216
228
|
catch (error) {
|
|
217
|
-
throw new Error(
|
|
229
|
+
throw new Error(t("Failed to read capability plugin directory {directory}: {reason}", {
|
|
230
|
+
directory: resolvedDirectory,
|
|
231
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
232
|
+
}));
|
|
218
233
|
}
|
|
219
234
|
for (const entry of entries.sort((left, right) => compareNames(left.name, right.name))) {
|
|
220
235
|
if (entry.name === "node_modules" || entry.name.startsWith("."))
|
|
@@ -231,7 +246,10 @@ export function discoverCapabilityPluginManifests(pluginDirectories) {
|
|
|
231
246
|
canonicalManifest = realpathSync(entryPath);
|
|
232
247
|
}
|
|
233
248
|
catch (error) {
|
|
234
|
-
throw new Error(
|
|
249
|
+
throw new Error(t("Failed to resolve capability plugin manifest {path}: {reason}", {
|
|
250
|
+
path: entryPath,
|
|
251
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
252
|
+
}));
|
|
235
253
|
}
|
|
236
254
|
if (seenManifests.has(canonicalManifest))
|
|
237
255
|
continue;
|
|
@@ -250,7 +268,7 @@ export function discoverCapabilityPluginManifests(pluginDirectories) {
|
|
|
250
268
|
export async function loadCapabilityPlugin(runtime, manifest, factory) {
|
|
251
269
|
const active = activePlugins.get(runtime) ?? new Map();
|
|
252
270
|
if (active.has(manifest.id))
|
|
253
|
-
throw new Error(
|
|
271
|
+
throw new Error(t("Capability plugin is already loaded: {id}", { id: manifest.id }));
|
|
254
272
|
const ownerToken = Symbol(manifest.id);
|
|
255
273
|
active.set(manifest.id, ownerToken);
|
|
256
274
|
activePlugins.set(runtime, active);
|
|
@@ -324,7 +342,7 @@ export async function loadCapabilityPlugin(runtime, manifest, factory) {
|
|
|
324
342
|
export function loadCapabilityPluginSync(runtime, manifest, factory) {
|
|
325
343
|
const active = activePlugins.get(runtime) ?? new Map();
|
|
326
344
|
if (active.has(manifest.id))
|
|
327
|
-
throw new Error(
|
|
345
|
+
throw new Error(t("Capability plugin is already loaded: {id}", { id: manifest.id }));
|
|
328
346
|
const ownerToken = Symbol(manifest.id);
|
|
329
347
|
active.set(manifest.id, ownerToken);
|
|
330
348
|
activePlugins.set(runtime, active);
|
|
@@ -442,7 +460,10 @@ export async function loadCapabilityPluginFromManifest(runtime, manifestPath, op
|
|
|
442
460
|
raw = JSON.parse(await readFile(manifestPath, "utf8"));
|
|
443
461
|
}
|
|
444
462
|
catch (error) {
|
|
445
|
-
throw new Error(
|
|
463
|
+
throw new Error(t("Failed to read capability plugin manifest {path}: {reason}", {
|
|
464
|
+
path: manifestPath,
|
|
465
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
466
|
+
}));
|
|
446
467
|
}
|
|
447
468
|
const parsed = parseCapabilityPluginManifest(raw, manifestPath);
|
|
448
469
|
// hostDependencyPaths (安装店重依赖可见性): 宿主已解析的重依赖入口绝对路径
|
|
@@ -481,10 +502,13 @@ export async function loadCapabilityPluginFromManifest(runtime, manifestPath, op
|
|
|
481
502
|
factory = await jiti.import(entryPath, { default: true });
|
|
482
503
|
}
|
|
483
504
|
catch (error) {
|
|
484
|
-
throw new Error(
|
|
505
|
+
throw new Error(t("Failed to import capability plugin entry {path}: {reason}", {
|
|
506
|
+
path: entryPath,
|
|
507
|
+
reason: error instanceof Error ? error.message : String(error),
|
|
508
|
+
}));
|
|
485
509
|
}
|
|
486
510
|
if (typeof factory !== "function") {
|
|
487
|
-
throw new Error(
|
|
511
|
+
throw new Error(t("Capability plugin entry must default-export a factory function: {entryPath}", { entryPath }));
|
|
488
512
|
}
|
|
489
513
|
return loadCapabilityPlugin(runtime, manifest, factory);
|
|
490
514
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability-plugin.js","sourceRoot":"","sources":["../../../src/core/extensions/capability-plugin.ts"],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EAAE,OAAkC,CAAC,CAAC;AAAA,CACnF","sourcesContent":["import type { Dirent } from \"node:fs\";\nimport { lstatSync, readdirSync, realpathSync, statSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { createRequire } from \"node:module\";\nimport * as path from \"node:path\";\nimport {\n\ttype CapabilityPluginFactory,\n\ttype CapabilityPluginInstance,\n\ttype CapabilityPluginSyncFactory,\n\ttype CapabilityPluginSyncInstance,\n\tparseCapabilityPluginManifest,\n} from \"@agent-forge/plugin-sdk\";\n// Type-only: the runtime dependency stays deferred until the first plugin\n// load (getCreateJiti below).\nimport type { createJiti } from \"jiti/static\";\nimport type { CapabilityRuntime } from \"./capability-runtime.ts\";\nimport {\n\tPLUGIN_DISPOSE_EVENT_ID,\n\tPLUGIN_DISPOSE_EVENT_VERSION,\n\tPLUGIN_READY_EVENT_ID,\n\tPLUGIN_READY_EVENT_VERSION,\n\ttype PluginDisposeEventDataV1,\n} from \"./lifecycle-catalog.ts\";\nimport type { CapabilityAPI, PluginConfig, PluginManifest } from \"./public-api.ts\";\n\n// Authoring-surface symbols moved to @agent-forge/plugin-sdk (D-075 S2);\n// re-exported here so existing host imports keep resolving.\nexport type {\n\tCapabilityPluginFactory,\n\tCapabilityPluginFactoryResult,\n\tCapabilityPluginInstance,\n\tCapabilityPluginSyncFactory,\n\tCapabilityPluginSyncInstance,\n} from \"@agent-forge/plugin-sdk\";\nexport { parseCapabilityPluginManifest } from \"@agent-forge/plugin-sdk\";\n\nexport interface CapabilityPluginHandle {\n\treadonly manifest: PluginManifest;\n\treadonly api: CapabilityAPI;\n\t/** Resolves once the plugin.ready lifecycle delivery has settled. */\n\treadonly ready: Promise<void>;\n\tdispose(): Promise<void>;\n}\n\nconst activePlugins = new WeakMap<CapabilityRuntime, Map<string, symbol>>();\n\n// Upstream pi 40c256ccc parity: importing this module sits on every startup\n// path, so the jiti transform pipeline (Babel included) and the bundled\n// virtual modules stay deferred until the first plugin actually loads. The\n// dynamic imports below are deliberate lazy-load points; the thin\n// jiti-static-loader entry keeps jiti/static statically reachable for the\n// Bun and Node bundlers that must embed it.\nlet createJitiPromise: Promise<typeof createJiti> | undefined;\n\nfunction getCreateJiti(): Promise<typeof createJiti> {\n\tcreateJitiPromise ??= import(\"./jiti-static-loader.ts\").then((module) => module.createJiti);\n\treturn createJitiPromise;\n}\n\nlet virtualModulesPromise: Promise<Record<string, unknown>> | undefined;\n\nfunction getVirtualModules(): Promise<Record<string, unknown>> {\n\tvirtualModulesPromise ??= import(\"./virtual-modules.ts\").then((module) => module.VIRTUAL_MODULES);\n\treturn virtualModulesPromise;\n}\n\n// Host-resolved heavy-dependency aliases (D-075 S4 fourth batch, installed-\n// code-loading): the memory plugin package carries its vector stack pinned in\n// its own package.json, but an npm-installed tarball ships no node_modules —\n// the same void the SDK/protocol virtual modules below fill. Unlike those,\n// lancedb/transformers are NATIVE/lazy packages the host must not bundle or\n// import here: they stay host dependencies, and each specifier is resolved\n// ONCE (module-level cache, successes only) to the host's own entry file\n// path and handed to jiti as an alias. The alias reliably intercepts only\n// STATIC imports on the entry chain of files jiti transforms — lazy\n// `await import()` calls inside an installed ESM dist bypass the transform\n// pipeline and hit the native resolver, so those lazy paths are supplied by\n// the hostDependencyPaths absolute-path channel instead (hostDependencyPaths-\n// Config below plus the plugin-side host-module-import). Resolution failures\n// are tolerated on both channels: the alias table is a best-effort supply\n// path, and heavy-dependency failures must surface at the plugin's point of\n// use, where the memory plugin reports structured failures with an action\n// list.\nconst hostHeavyDependencyAliases: ReadonlySet<string> = new Set([\n\t\"@lancedb/lancedb\",\n\t\"@huggingface/transformers\",\n\t// memory 的 onnxruntime 预检(nativeBinaryCheck)在插件内直接 resolve 该传递\n\t// 依赖;安装店副本无 node_modules,必须与 transformers 同走宿主 alias 通道。\n\t\"onnxruntime-node\",\n]);\n\nconst resolvedHeavyDependencyAliases: Map<string, string> = new Map();\n\n/**\n * Explicit injection object for {@link buildHostDependencyAliases}. Both fields\n * are required on purpose: with optional positional parameters a test could\n * inject only `resolve` and silently write its fake results into the\n * module-level production cache (`resolvedHeavyDependencyAliases`), hijacking\n * every later real plugin load in the same vitest worker. Making the object\n * mandatory means a test cannot supply a resolver without also supplying the\n * cache it pollutes.\n */\nexport interface HostDependencyAliasResolution {\n\treadonly resolve: (specifier: string) => string;\n\treadonly cache: Map<string, string>;\n}\n\nconst defaultHostDependencyAliasResolution: HostDependencyAliasResolution = {\n\tresolve: (specifier) => createRequire(import.meta.url).resolve(specifier),\n\tcache: resolvedHeavyDependencyAliases,\n};\n\n/**\n * Tolerant heavy-dependency resolution shared by the jiti alias channel and\n * the hostDependencyPaths config channel: each specifier is resolved against\n * the host installation (successes cached module-level), and a specifier that\n * fails to resolve is simply absent from the result. The alias table is a\n * best-effort supply path — heavy-dependency failures must surface at the\n * plugin's point of use, where the memory plugin reports structured failures\n * with an action list. Exported for deterministic tests; production callers\n * pass {@link defaultHostDependencyAliasResolution} explicitly.\n */\nexport function buildHostDependencyAliases(\n\tspecifiers: ReadonlySet<string> | readonly string[],\n\tresolution: HostDependencyAliasResolution,\n): Record<string, string> {\n\tconst aliases: Record<string, string> = {};\n\tfor (const specifier of specifiers) {\n\t\tconst cached = resolution.cache.get(specifier);\n\t\tif (cached !== undefined) {\n\t\t\taliases[specifier] = cached;\n\t\t\tcontinue;\n\t\t}\n\t\ttry {\n\t\t\tconst resolved = resolution.resolve(specifier);\n\t\t\tresolution.cache.set(specifier, resolved);\n\t\t\taliases[specifier] = resolved;\n\t\t} catch {\n\t\t\t// Tolerant by contract: absent entry = plugin-side fallback.\n\t\t}\n\t}\n\treturn aliases;\n}\n\n/**\n * Host-resolved heavy-dependency entry paths (specifier → absolute path) for\n * the config channel that feeds the lazy `await import()` paths the jiti\n * alias channel cannot reach (installed ESM dists bypass the transform\n * pipeline). Tolerant like the alias table: a specifier the host installation\n * cannot resolve is simply absent, and plugin code falls back to its own\n * resolution (or reports the structured failure). camelCase keys keep the\n * JSON config channel idiomatic for plugin consumers.\n */\nfunction hostDependencyPathsConfig(): Record<string, string> {\n\tconst paths: Record<string, string> = {};\n\tfor (const [specifier, entryPath] of Object.entries(\n\t\tbuildHostDependencyAliases(hostHeavyDependencyAliases, defaultHostDependencyAliasResolution),\n\t)) {\n\t\tpaths[camelCaseDependencyKey(specifier)] = entryPath;\n\t}\n\treturn paths;\n}\n\nfunction camelCaseDependencyKey(specifier: string): string {\n\tconst scoped = specifier.replace(/^@[^/]+\\//, \"\");\n\treturn scoped.replace(/[-.](.)/g, (_, character: string) => character.toUpperCase());\n}\n\nfunction isPluginInstance(value: unknown): value is CapabilityPluginInstance {\n\treturn typeof value === \"object\" && value !== null && typeof (value as { dispose?: unknown }).dispose === \"function\";\n}\n\nfunction normalizePluginInstance(value: unknown, manifest: PluginManifest): CapabilityPluginInstance | undefined {\n\tif (value === undefined) return undefined;\n\tif (!isPluginInstance(value)) {\n\t\tthrow new Error(`Capability plugin factory must return void or an instance with dispose(): ${manifest.id}`);\n\t}\n\treturn value;\n}\n\nfunction normalizePluginSyncInstance(\n\tvalue: unknown,\n\tmanifest: PluginManifest,\n): CapabilityPluginSyncInstance | undefined {\n\tif (value === undefined) return undefined;\n\tif (!isPluginInstance(value)) {\n\t\tthrow new Error(\n\t\t\t`Synchronous capability plugin factory must return void or an instance with dispose(): ${manifest.id}`,\n\t\t);\n\t}\n\treturn value as CapabilityPluginSyncInstance;\n}\n\nfunction throwCleanupErrors(errors: unknown[], manifestId: string): void {\n\tif (errors.length === 0) return;\n\tif (errors.length === 1) throw errors[0];\n\tthrow new AggregateError(errors, `Capability plugin cleanup failed: ${manifestId}`);\n}\n\nasync function dispatchPluginDisposeEvent(\n\truntime: CapabilityRuntime,\n\tmanifest: PluginManifest,\n\tstatus: PluginDisposeEventDataV1[\"status\"],\n): Promise<void> {\n\tif (!runtime.hasLifecycleEvent(PLUGIN_DISPOSE_EVENT_ID, PLUGIN_DISPOSE_EVENT_VERSION)) return;\n\tawait runtime.dispatchLifecycle({\n\t\ttype: PLUGIN_DISPOSE_EVENT_ID,\n\t\tversion: PLUGIN_DISPOSE_EVENT_VERSION,\n\t\tphase: \"committed\",\n\t\tdata: {\n\t\t\tversion: 1,\n\t\t\tpluginId: manifest.id,\n\t\t\tpluginVersion: manifest.version,\n\t\t\tstatus,\n\t\t},\n\t\tsource: \"capability-plugin\",\n\t});\n}\n\nasync function dispatchPluginReadyEvent(runtime: CapabilityRuntime, manifest: PluginManifest): Promise<void> {\n\tif (!runtime.hasLifecycleEvent(PLUGIN_READY_EVENT_ID, PLUGIN_READY_EVENT_VERSION)) return;\n\tawait runtime.dispatchLifecycle({\n\t\ttype: PLUGIN_READY_EVENT_ID,\n\t\tversion: PLUGIN_READY_EVENT_VERSION,\n\t\tphase: \"committed\",\n\t\tdata: {\n\t\t\tversion: 1,\n\t\t\tpluginId: manifest.id,\n\t\t\tpluginVersion: manifest.version,\n\t\t},\n\t\tsource: \"capability-plugin\",\n\t});\n}\n\nfunction isMissingPathError(error: unknown): boolean {\n\treturn typeof error === \"object\" && error !== null && \"code\" in error && error.code === \"ENOENT\";\n}\n\nfunction compareNames(left: string, right: string): number {\n\treturn left < right ? -1 : left > right ? 1 : 0;\n}\n\n/**\n * Find installed capability manifests below the given plugin directories.\n *\n * Directories are visited in caller order; entries in each directory use a\n * stable lexical order. Missing roots are normal for a first-run host.\n * Existing unreadable or malformed filesystem paths fail explicitly rather\n * than silently changing the loaded plugin set. Dependency and hidden\n * directories are never traversed.\n */\nexport function discoverCapabilityPluginManifests(pluginDirectories: readonly string[]): string[] {\n\tconst manifests: string[] = [];\n\tconst seenDirectories = new Set<string>();\n\tconst seenManifests = new Set<string>();\n\n\tconst visit = (directory: string, optional: boolean): void => {\n\t\tconst resolvedDirectory = path.resolve(directory);\n\t\tlet stats: ReturnType<typeof statSync>;\n\t\ttry {\n\t\t\tstats = statSync(resolvedDirectory);\n\t\t} catch (error) {\n\t\t\tif (optional && isMissingPathError(error)) {\n\t\t\t\ttry {\n\t\t\t\t\tif (!lstatSync(resolvedDirectory).isSymbolicLink()) return;\n\t\t\t\t} catch (linkError) {\n\t\t\t\t\tif (isMissingPathError(linkError)) return;\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\t`Failed to inspect capability plugin directory ${resolvedDirectory}: ${\n\t\t\t\t\t\t\tlinkError instanceof Error ? linkError.message : String(linkError)\n\t\t\t\t\t\t}`,\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to inspect capability plugin directory ${resolvedDirectory}: ${\n\t\t\t\t\terror instanceof Error ? error.message : String(error)\n\t\t\t\t}`,\n\t\t\t);\n\t\t}\n\t\tif (!stats.isDirectory()) {\n\t\t\tthrow new Error(`Capability plugin path must be a directory: ${resolvedDirectory}`);\n\t\t}\n\n\t\tlet canonicalDirectory: string;\n\t\ttry {\n\t\t\tcanonicalDirectory = realpathSync(resolvedDirectory);\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to resolve capability plugin directory ${resolvedDirectory}: ${\n\t\t\t\t\terror instanceof Error ? error.message : String(error)\n\t\t\t\t}`,\n\t\t\t);\n\t\t}\n\t\tif (seenDirectories.has(canonicalDirectory)) return;\n\t\tseenDirectories.add(canonicalDirectory);\n\n\t\tlet entries: Dirent<string>[];\n\t\ttry {\n\t\t\tentries = readdirSync(resolvedDirectory, { withFileTypes: true, encoding: \"utf8\" });\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to read capability plugin directory ${resolvedDirectory}: ${\n\t\t\t\t\terror instanceof Error ? error.message : String(error)\n\t\t\t\t}`,\n\t\t\t);\n\t\t}\n\n\t\tfor (const entry of entries.sort((left, right) => compareNames(left.name, right.name))) {\n\t\t\tif (entry.name === \"node_modules\" || entry.name.startsWith(\".\")) continue;\n\t\t\tconst entryPath = path.join(resolvedDirectory, entry.name);\n\t\t\tif (entry.isDirectory()) {\n\t\t\t\tvisit(entryPath, false);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!entry.isFile() || entry.name !== \"plugin.json\") continue;\n\n\t\t\tlet canonicalManifest: string;\n\t\t\ttry {\n\t\t\t\tcanonicalManifest = realpathSync(entryPath);\n\t\t\t} catch (error) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Failed to resolve capability plugin manifest ${entryPath}: ${\n\t\t\t\t\t\terror instanceof Error ? error.message : String(error)\n\t\t\t\t\t}`,\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (seenManifests.has(canonicalManifest)) continue;\n\t\t\tseenManifests.add(canonicalManifest);\n\t\t\tmanifests.push(canonicalManifest);\n\t\t}\n\t};\n\n\tfor (const pluginDirectory of pluginDirectories) visit(pluginDirectory, true);\n\treturn manifests;\n}\n\n/**\n * Load a capability plugin through the public facade only.\n * Filesystem discovery and package installation stay outside this mechanism.\n */\nexport async function loadCapabilityPlugin(\n\truntime: CapabilityRuntime,\n\tmanifest: PluginManifest,\n\tfactory: CapabilityPluginFactory,\n): Promise<CapabilityPluginHandle> {\n\tconst active = activePlugins.get(runtime) ?? new Map<string, symbol>();\n\tif (active.has(manifest.id)) throw new Error(`Capability plugin is already loaded: ${manifest.id}`);\n\tconst ownerToken = Symbol(manifest.id);\n\tactive.set(manifest.id, ownerToken);\n\tactivePlugins.set(runtime, active);\n\tlet api: CapabilityAPI | undefined;\n\tlet instance: CapabilityPluginInstance | undefined;\n\tconst cleanup = async (notifyDispose: boolean): Promise<void> => {\n\t\tconst errors: unknown[] = [];\n\t\tif (api) runtime.revokeAPI(api);\n\t\ttry {\n\t\t\tawait runtime.disposePlugin(manifest.id);\n\t\t} catch (error) {\n\t\t\terrors.push(error);\n\t\t}\n\t\ttry {\n\t\t\tawait instance?.dispose();\n\t\t} catch (error) {\n\t\t\terrors.push(error);\n\t\t}\n\t\tif (notifyDispose) {\n\t\t\ttry {\n\t\t\t\tawait dispatchPluginDisposeEvent(runtime, manifest, errors.length === 0 ? \"disposed\" : \"failed\");\n\t\t\t} catch (error) {\n\t\t\t\terrors.push(error);\n\t\t\t}\n\t\t}\n\t\tthrowCleanupErrors(errors, manifest.id);\n\t};\n\ttry {\n\t\tapi = runtime.createAPI(manifest);\n\t\tinstance = normalizePluginInstance(await factory(api), manifest);\n\t\tawait dispatchPluginReadyEvent(runtime, manifest);\n\t\tconst pluginApi = api;\n\t\tlet disposePromise: Promise<void> | undefined;\n\t\treturn {\n\t\t\tmanifest,\n\t\t\tapi: pluginApi,\n\t\t\tready: Promise.resolve(),\n\t\t\tdispose: async () => {\n\t\t\t\tdisposePromise ??= (async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait cleanup(true);\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tif (active.get(manifest.id) === ownerToken) active.delete(manifest.id);\n\t\t\t\t\t}\n\t\t\t\t})();\n\t\t\t\treturn disposePromise;\n\t\t\t},\n\t\t};\n\t} catch (error) {\n\t\ttry {\n\t\t\tawait cleanup(false);\n\t\t} catch (cleanupError) {\n\t\t\tthrow new AggregateError([error, cleanupError], `Capability plugin startup cleanup failed: ${manifest.id}`);\n\t\t} finally {\n\t\t\tif (active.get(manifest.id) === ownerToken) active.delete(manifest.id);\n\t\t}\n\t\tthrow error;\n\t}\n}\n\n/** Load a synchronous embedded plugin during host construction. */\nexport function loadCapabilityPluginSync(\n\truntime: CapabilityRuntime,\n\tmanifest: PluginManifest,\n\tfactory: CapabilityPluginSyncFactory,\n): CapabilityPluginHandle {\n\tconst active = activePlugins.get(runtime) ?? new Map<string, symbol>();\n\tif (active.has(manifest.id)) throw new Error(`Capability plugin is already loaded: ${manifest.id}`);\n\tconst ownerToken = Symbol(manifest.id);\n\tactive.set(manifest.id, ownerToken);\n\tactivePlugins.set(runtime, active);\n\tlet api: CapabilityAPI | undefined;\n\tlet instance: CapabilityPluginSyncInstance | undefined;\n\tconst cleanupRegistrationsSync = (): unknown[] => {\n\t\tconst errors: unknown[] = [];\n\t\tif (api) runtime.revokeAPI(api);\n\t\ttry {\n\t\t\truntime.disposePluginSync(manifest.id);\n\t\t} catch (error) {\n\t\t\terrors.push(error);\n\t\t}\n\t\treturn errors;\n\t};\n\tconst cleanupSync = async (): Promise<void> => {\n\t\tconst errors = cleanupRegistrationsSync();\n\t\tlet result: unknown;\n\t\ttry {\n\t\t\tresult = instance?.dispose();\n\t\t} catch (error) {\n\t\t\terrors.push(error);\n\t\t}\n\t\tif (result && typeof (result as PromiseLike<void>).then === \"function\") {\n\t\t\tconst contractError = new Error(\n\t\t\t\t`Synchronous capability plugin disposer must not return a Promise: ${manifest.id}`,\n\t\t\t);\n\t\t\ttry {\n\t\t\t\tawait result;\n\t\t\t} catch (error) {\n\t\t\t\terrors.push(error);\n\t\t\t}\n\t\t\terrors.push(contractError);\n\t\t}\n\t\ttry {\n\t\t\tawait dispatchPluginDisposeEvent(runtime, manifest, errors.length === 0 ? \"disposed\" : \"failed\");\n\t\t} catch (error) {\n\t\t\terrors.push(error);\n\t\t}\n\t\tthrowCleanupErrors(errors, manifest.id);\n\t};\n\ttry {\n\t\tapi = runtime.createAPI(manifest);\n\t\tinstance = normalizePluginSyncInstance(factory(api), manifest);\n\t} catch (error) {\n\t\ttry {\n\t\t\tthrowCleanupErrors(cleanupRegistrationsSync(), manifest.id);\n\t\t} catch (cleanupError) {\n\t\t\tthrow new AggregateError([error, cleanupError], `Capability plugin startup cleanup failed: ${manifest.id}`);\n\t\t} finally {\n\t\t\tif (active.get(manifest.id) === ownerToken) active.delete(manifest.id);\n\t\t}\n\t\tthrow error;\n\t}\n\tconst ready = dispatchPluginReadyEvent(runtime, manifest);\n\t// The embedded constructor API is synchronous; retain a handled promise so\n\t// hosts may explicitly await lifecycle delivery without risking an unhandled rejection.\n\tvoid ready.catch(() => undefined);\n\tlet disposePromise: Promise<void> | undefined;\n\treturn {\n\t\tmanifest,\n\t\tapi: api!,\n\t\tready,\n\t\tdispose: async () => {\n\t\t\tdisposePromise ??= (async () => {\n\t\t\t\tlet readyError: unknown;\n\t\t\t\ttry {\n\t\t\t\t\tawait ready;\n\t\t\t\t} catch (error) {\n\t\t\t\t\treadyError = error;\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tawait cleanupSync();\n\t\t\t\t\tif (readyError !== undefined) throw readyError;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (readyError !== undefined && error !== readyError) {\n\t\t\t\t\t\tthrow new AggregateError([readyError, error], `Capability plugin cleanup failed: ${manifest.id}`);\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t} finally {\n\t\t\t\t\tif (active.get(manifest.id) === ownerToken) active.delete(manifest.id);\n\t\t\t\t}\n\t\t\t})();\n\t\t\treturn disposePromise;\n\t\t},\n\t};\n}\n\n/**\n * Load a plugin from its JSON manifest. This is intentionally separate from\n * legacy extension discovery until both systems share the same public facade.\n *\n * `options.configOverride` (D-075 S4 third batch) merges host-declared values\n * over the manifest's own `config` defaults before the plugin API is built —\n * a public channel (first-party and third-party plugins alike) for hosts that\n * vouch for facts the manifest cannot know, e.g. the CLI declaring its own\n * process entry trustworthy so the subagent-delegate package auto-pools. It\n * stays below any plugin-side config channel: the agent-dir config file the\n * plugin entry reads merges over whatever the host injected here.\n */\nexport async function loadCapabilityPluginFromManifest(\n\truntime: CapabilityRuntime,\n\tmanifestPath: string,\n\toptions?: { readonly configOverride?: PluginConfig },\n): Promise<CapabilityPluginHandle> {\n\tlet raw: unknown;\n\ttry {\n\t\traw = JSON.parse(await readFile(manifestPath, \"utf8\"));\n\t} catch (error) {\n\t\tthrow new Error(\n\t\t\t`Failed to read capability plugin manifest ${manifestPath}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t);\n\t}\n\tconst parsed = parseCapabilityPluginManifest(raw, manifestPath);\n\t// hostDependencyPaths (安装店重依赖可见性): 宿主已解析的重依赖入口绝对路径\n\t// 并进 manifest config——安装店副本无 node_modules, 插件内 createRequire 自\n\t// 解析不可达 (memory 的 onnxruntime native 预检实证); 与 jiti alias 通道互补\n\t// (alias 拦截 import, 本通道喂插件内的路径式消费)。公共同道: 第一方与第三方\n\t// 插件同样可读。仍低于插件侧 config 文件通道 (agent-dir 配置合并在其上)。\n\tconst hostDependencyOverride = { hostDependencyPaths: hostDependencyPathsConfig() };\n\tconst callerOverride = options?.configOverride;\n\tconst manifest =\n\t\tcallerOverride === undefined || Object.keys(callerOverride).length === 0\n\t\t\t? { ...parsed, config: { ...parsed.config, ...hostDependencyOverride } }\n\t\t\t: { ...parsed, config: { ...parsed.config, ...hostDependencyOverride, ...callerOverride } };\n\tconst entryPath = path.resolve(path.dirname(manifestPath), manifest.entry);\n\t// Host-resolved authoring dependencies (D-075 §4.1): installed plugin\n\t// packages live in the install store, which carries no node_modules (npm\n\t// tarballs never include dependencies), so their bare imports of the SDK\n\t// and the pinned typebox dependency resolve against the host's own copies\n\t// through jiti virtual modules (./virtual-modules.ts, lazy). Works\n\t// identically in the bundle and Bun binaries where no source-tree\n\t// node_modules exists at all. D-075 S4 third batch: the protocol package\n\t// joins — the subagent-delegate package's runtime imports\n\t// (`@agent-forge/protocol`) resolve the same way. S4 fourth batch: the\n\t// memory package's native vector stack (`@lancedb/lancedb`,\n\t// `@huggingface/transformers`) resolves through the jiti alias channel\n\t// instead — those stay real host node_modules entries, so plugins load the\n\t// host's native builds rather than a virtual copy.\n\tconst [createJitiImpl, virtualModules] = await Promise.all([getCreateJiti(), getVirtualModules()]);\n\tconst jiti = createJitiImpl(import.meta.url, {\n\t\tmoduleCache: false,\n\t\ttsconfigPaths: true,\n\t\talias: buildHostDependencyAliases(hostHeavyDependencyAliases, defaultHostDependencyAliasResolution),\n\t\tvirtualModules,\n\t});\n\tlet factory: unknown;\n\ttry {\n\t\tfactory = await jiti.import(entryPath, { default: true });\n\t} catch (error) {\n\t\tthrow new Error(\n\t\t\t`Failed to import capability plugin entry ${entryPath}: ${error instanceof Error ? error.message : String(error)}`,\n\t\t);\n\t}\n\tif (typeof factory !== \"function\") {\n\t\tthrow new Error(`Capability plugin entry must default-export a factory function: ${entryPath}`);\n\t}\n\treturn loadCapabilityPlugin(runtime, manifest, factory as CapabilityPluginFactory);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"capability-plugin.js","sourceRoot":"","sources":["../../../src/core/extensions/capability-plugin.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,KAAK,IAAI,MAAM,WAAW,CAAC;AAClC,OAAO,EAKN,6BAA6B,GAC7B,MAAM,yBAAyB,CAAC;AAIjC,OAAO,EAAE,CAAC,EAAE,MAAM,kBAAkB,CAAC;AAErC,OAAO,EACN,uBAAuB,EACvB,4BAA4B,EAC5B,qBAAqB,EACrB,0BAA0B,GAE1B,MAAM,wBAAwB,CAAC;AAYhC,OAAO,EAAE,6BAA6B,EAAE,MAAM,yBAAyB,CAAC;AAUxE,MAAM,aAAa,GAAG,IAAI,OAAO,EAA0C,CAAC;AAE5E,4EAA4E;AAC5E,wEAAwE;AACxE,2EAA2E;AAC3E,kEAAkE;AAClE,0EAA0E;AAC1E,4CAA4C;AAC5C,IAAI,iBAAyD,CAAC;AAE9D,SAAS,aAAa,GAA+B;IACpD,iBAAiB,KAAK,MAAM,CAAC,yBAAyB,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC;IAC5F,OAAO,iBAAiB,CAAC;AAAA,CACzB;AAED,IAAI,qBAAmE,CAAC;AAExE,SAAS,iBAAiB,GAAqC;IAC9D,qBAAqB,KAAK,MAAM,CAAC,sBAAsB,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,eAAe,CAAC,CAAC;IAClG,OAAO,qBAAqB,CAAC;AAAA,CAC7B;AAED,4EAA4E;A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C,CAAC;IACnG,MAAM,IAAI,GAAG,cAAc,CAAC,OAAO,IAAI,CAAC,GAAG,EAAE;QAC5C,WAAW,EAAE,KAAK;QAClB,aAAa,EAAE,IAAI;QACnB,KAAK,EAAE,0BAA0B,CAAC,0BAA0B,EAAE,oCAAoC,CAAC;QACnG,cAAc;KACd,CAAC,CAAC;IACH,IAAI,OAAgB,CAAC;IACrB,IAAI,CAAC;QACJ,OAAO,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,SAAS,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;IAC3D,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QAChB,MAAM,IAAI,KAAK,CACd,CAAC,CAAC,2DAA2D,EAAE;YAC9D,IAAI,EAAE,SAAS;YACf,MAAM,EAAE,KAAK,YAAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC;SAC9D,CAAC,CACF,CAAC;IACH,CAAC;IACD,IAAI,OAAO,OAAO,KAAK,UAAU,EAAE,CAAC;QACnC,MAAM,IAAI,KAAK,CAAC,CAAC,CAAC,6EAA6E,EAAE,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC;IAClH,CAAC;IACD,OAAO,oBAAoB,CAAC,OAAO,EAAE,QAAQ,EAAE,OAAkC,CAAC,CAAC;AAAA,CACnF","sourcesContent":["import type { Dirent } from \"node:fs\";\nimport { lstatSync, readdirSync, realpathSync, statSync } from \"node:fs\";\nimport { readFile } from \"node:fs/promises\";\nimport { createRequire } from \"node:module\";\nimport * as path from \"node:path\";\nimport {\n\ttype CapabilityPluginFactory,\n\ttype CapabilityPluginInstance,\n\ttype CapabilityPluginSyncFactory,\n\ttype CapabilityPluginSyncInstance,\n\tparseCapabilityPluginManifest,\n} from \"@agent-forge/plugin-sdk\";\n// Type-only: the runtime dependency stays deferred until the first plugin\n// load (getCreateJiti below).\nimport type { createJiti } from \"jiti/static\";\nimport { t } from \"../i18n/index.ts\";\nimport type { CapabilityRuntime } from \"./capability-runtime.ts\";\nimport {\n\tPLUGIN_DISPOSE_EVENT_ID,\n\tPLUGIN_DISPOSE_EVENT_VERSION,\n\tPLUGIN_READY_EVENT_ID,\n\tPLUGIN_READY_EVENT_VERSION,\n\ttype PluginDisposeEventDataV1,\n} from \"./lifecycle-catalog.ts\";\nimport type { CapabilityAPI, PluginConfig, PluginManifest } from \"./public-api.ts\";\n\n// Authoring-surface symbols moved to @agent-forge/plugin-sdk (D-075 S2);\n// re-exported here so existing host imports keep resolving.\nexport type {\n\tCapabilityPluginFactory,\n\tCapabilityPluginFactoryResult,\n\tCapabilityPluginInstance,\n\tCapabilityPluginSyncFactory,\n\tCapabilityPluginSyncInstance,\n} from \"@agent-forge/plugin-sdk\";\nexport { parseCapabilityPluginManifest } from \"@agent-forge/plugin-sdk\";\n\nexport interface CapabilityPluginHandle {\n\treadonly manifest: PluginManifest;\n\treadonly api: CapabilityAPI;\n\t/** Resolves once the plugin.ready lifecycle delivery has settled. */\n\treadonly ready: Promise<void>;\n\tdispose(): Promise<void>;\n}\n\nconst activePlugins = new WeakMap<CapabilityRuntime, Map<string, symbol>>();\n\n// Upstream pi 40c256ccc parity: importing this module sits on every startup\n// path, so the jiti transform pipeline (Babel included) and the bundled\n// virtual modules stay deferred until the first plugin actually loads. The\n// dynamic imports below are deliberate lazy-load points; the thin\n// jiti-static-loader entry keeps jiti/static statically reachable for the\n// Bun and Node bundlers that must embed it.\nlet createJitiPromise: Promise<typeof createJiti> | undefined;\n\nfunction getCreateJiti(): Promise<typeof createJiti> {\n\tcreateJitiPromise ??= import(\"./jiti-static-loader.ts\").then((module) => module.createJiti);\n\treturn createJitiPromise;\n}\n\nlet virtualModulesPromise: Promise<Record<string, unknown>> | undefined;\n\nfunction getVirtualModules(): Promise<Record<string, unknown>> {\n\tvirtualModulesPromise ??= import(\"./virtual-modules.ts\").then((module) => module.VIRTUAL_MODULES);\n\treturn virtualModulesPromise;\n}\n\n// Host-resolved heavy-dependency aliases (D-075 S4 fourth batch, installed-\n// code-loading): the memory plugin package carries its vector stack pinned in\n// its own package.json, but an npm-installed tarball ships no node_modules —\n// the same void the SDK/protocol virtual modules below fill. Unlike those,\n// lancedb/transformers are NATIVE/lazy packages the host must not bundle or\n// import here: they stay host dependencies, and each specifier is resolved\n// ONCE (module-level cache, successes only) to the host's own entry file\n// path and handed to jiti as an alias. The alias reliably intercepts only\n// STATIC imports on the entry chain of files jiti transforms — lazy\n// `await import()` calls inside an installed ESM dist bypass the transform\n// pipeline and hit the native resolver, so those lazy paths are supplied by\n// the hostDependencyPaths absolute-path channel instead (hostDependencyPaths-\n// Config below plus the plugin-side host-module-import). Resolution failures\n// are tolerated on both channels: the alias table is a best-effort supply\n// path, and heavy-dependency failures must surface at the plugin's point of\n// use, where the memory plugin reports structured failures with an action\n// list.\nconst hostHeavyDependencyAliases: ReadonlySet<string> = new Set([\n\t\"@lancedb/lancedb\",\n\t\"@huggingface/transformers\",\n\t// memory 的 onnxruntime 预检(nativeBinaryCheck)在插件内直接 resolve 该传递\n\t// 依赖;安装店副本无 node_modules,必须与 transformers 同走宿主 alias 通道。\n\t\"onnxruntime-node\",\n]);\n\nconst resolvedHeavyDependencyAliases: Map<string, string> = new Map();\n\n/**\n * Explicit injection object for {@link buildHostDependencyAliases}. Both fields\n * are required on purpose: with optional positional parameters a test could\n * inject only `resolve` and silently write its fake results into the\n * module-level production cache (`resolvedHeavyDependencyAliases`), hijacking\n * every later real plugin load in the same vitest worker. Making the object\n * mandatory means a test cannot supply a resolver without also supplying the\n * cache it pollutes.\n */\nexport interface HostDependencyAliasResolution {\n\treadonly resolve: (specifier: string) => string;\n\treadonly cache: Map<string, string>;\n}\n\nconst defaultHostDependencyAliasResolution: HostDependencyAliasResolution = {\n\tresolve: (specifier) => createRequire(import.meta.url).resolve(specifier),\n\tcache: resolvedHeavyDependencyAliases,\n};\n\n/**\n * Tolerant heavy-dependency resolution shared by the jiti alias channel and\n * the hostDependencyPaths config channel: each specifier is resolved against\n * the host installation (successes cached module-level), and a specifier that\n * fails to resolve is simply absent from the result. The alias table is a\n * best-effort supply path — heavy-dependency failures must surface at the\n * plugin's point of use, where the memory plugin reports structured failures\n * with an action list. Exported for deterministic tests; production callers\n * pass {@link defaultHostDependencyAliasResolution} explicitly.\n */\nexport function buildHostDependencyAliases(\n\tspecifiers: ReadonlySet<string> | readonly string[],\n\tresolution: HostDependencyAliasResolution,\n): Record<string, string> {\n\tconst aliases: Record<string, string> = {};\n\tfor (const specifier of specifiers) {\n\t\tconst cached = resolution.cache.get(specifier);\n\t\tif (cached !== undefined) {\n\t\t\taliases[specifier] = cached;\n\t\t\tcontinue;\n\t\t}\n\t\ttry {\n\t\t\tconst resolved = resolution.resolve(specifier);\n\t\t\tresolution.cache.set(specifier, resolved);\n\t\t\taliases[specifier] = resolved;\n\t\t} catch {\n\t\t\t// Tolerant by contract: absent entry = plugin-side fallback.\n\t\t}\n\t}\n\treturn aliases;\n}\n\n/**\n * Host-resolved heavy-dependency entry paths (specifier → absolute path) for\n * the config channel that feeds the lazy `await import()` paths the jiti\n * alias channel cannot reach (installed ESM dists bypass the transform\n * pipeline). Tolerant like the alias table: a specifier the host installation\n * cannot resolve is simply absent, and plugin code falls back to its own\n * resolution (or reports the structured failure). camelCase keys keep the\n * JSON config channel idiomatic for plugin consumers.\n */\nfunction hostDependencyPathsConfig(): Record<string, string> {\n\tconst paths: Record<string, string> = {};\n\tfor (const [specifier, entryPath] of Object.entries(\n\t\tbuildHostDependencyAliases(hostHeavyDependencyAliases, defaultHostDependencyAliasResolution),\n\t)) {\n\t\tpaths[camelCaseDependencyKey(specifier)] = entryPath;\n\t}\n\treturn paths;\n}\n\nfunction camelCaseDependencyKey(specifier: string): string {\n\tconst scoped = specifier.replace(/^@[^/]+\\//, \"\");\n\treturn scoped.replace(/[-.](.)/g, (_, character: string) => character.toUpperCase());\n}\n\nfunction isPluginInstance(value: unknown): value is CapabilityPluginInstance {\n\treturn typeof value === \"object\" && value !== null && typeof (value as { dispose?: unknown }).dispose === \"function\";\n}\n\nfunction normalizePluginInstance(value: unknown, manifest: PluginManifest): CapabilityPluginInstance | undefined {\n\tif (value === undefined) return undefined;\n\tif (!isPluginInstance(value)) {\n\t\tthrow new Error(\n\t\t\tt(\"Capability plugin factory must return void or an instance with dispose(): {id}\", { id: manifest.id }),\n\t\t);\n\t}\n\treturn value;\n}\n\nfunction normalizePluginSyncInstance(\n\tvalue: unknown,\n\tmanifest: PluginManifest,\n): CapabilityPluginSyncInstance | undefined {\n\tif (value === undefined) return undefined;\n\tif (!isPluginInstance(value)) {\n\t\tthrow new Error(\n\t\t\tt(\"Synchronous capability plugin factory must return void or an instance with dispose(): {id}\", {\n\t\t\t\tid: manifest.id,\n\t\t\t}),\n\t\t);\n\t}\n\treturn value as CapabilityPluginSyncInstance;\n}\n\nfunction throwCleanupErrors(errors: unknown[], manifestId: string): void {\n\tif (errors.length === 0) return;\n\tif (errors.length === 1) throw errors[0];\n\tthrow new AggregateError(errors, `Capability plugin cleanup failed: ${manifestId}`);\n}\n\nasync function dispatchPluginDisposeEvent(\n\truntime: CapabilityRuntime,\n\tmanifest: PluginManifest,\n\tstatus: PluginDisposeEventDataV1[\"status\"],\n): Promise<void> {\n\tif (!runtime.hasLifecycleEvent(PLUGIN_DISPOSE_EVENT_ID, PLUGIN_DISPOSE_EVENT_VERSION)) return;\n\tawait runtime.dispatchLifecycle({\n\t\ttype: PLUGIN_DISPOSE_EVENT_ID,\n\t\tversion: PLUGIN_DISPOSE_EVENT_VERSION,\n\t\tphase: \"committed\",\n\t\tdata: {\n\t\t\tversion: 1,\n\t\t\tpluginId: manifest.id,\n\t\t\tpluginVersion: manifest.version,\n\t\t\tstatus,\n\t\t},\n\t\tsource: \"capability-plugin\",\n\t});\n}\n\nasync function dispatchPluginReadyEvent(runtime: CapabilityRuntime, manifest: PluginManifest): Promise<void> {\n\tif (!runtime.hasLifecycleEvent(PLUGIN_READY_EVENT_ID, PLUGIN_READY_EVENT_VERSION)) return;\n\tawait runtime.dispatchLifecycle({\n\t\ttype: PLUGIN_READY_EVENT_ID,\n\t\tversion: PLUGIN_READY_EVENT_VERSION,\n\t\tphase: \"committed\",\n\t\tdata: {\n\t\t\tversion: 1,\n\t\t\tpluginId: manifest.id,\n\t\t\tpluginVersion: manifest.version,\n\t\t},\n\t\tsource: \"capability-plugin\",\n\t});\n}\n\nfunction isMissingPathError(error: unknown): boolean {\n\treturn typeof error === \"object\" && error !== null && \"code\" in error && error.code === \"ENOENT\";\n}\n\nfunction compareNames(left: string, right: string): number {\n\treturn left < right ? -1 : left > right ? 1 : 0;\n}\n\n/**\n * Find installed capability manifests below the given plugin directories.\n *\n * Directories are visited in caller order; entries in each directory use a\n * stable lexical order. Missing roots are normal for a first-run host.\n * Existing unreadable or malformed filesystem paths fail explicitly rather\n * than silently changing the loaded plugin set. Dependency and hidden\n * directories are never traversed.\n */\nexport function discoverCapabilityPluginManifests(pluginDirectories: readonly string[]): string[] {\n\tconst manifests: string[] = [];\n\tconst seenDirectories = new Set<string>();\n\tconst seenManifests = new Set<string>();\n\n\tconst visit = (directory: string, optional: boolean): void => {\n\t\tconst resolvedDirectory = path.resolve(directory);\n\t\tlet stats: ReturnType<typeof statSync>;\n\t\ttry {\n\t\t\tstats = statSync(resolvedDirectory);\n\t\t} catch (error) {\n\t\t\tif (optional && isMissingPathError(error)) {\n\t\t\t\ttry {\n\t\t\t\t\tif (!lstatSync(resolvedDirectory).isSymbolicLink()) return;\n\t\t\t\t} catch (linkError) {\n\t\t\t\t\tif (isMissingPathError(linkError)) return;\n\t\t\t\t\tthrow new Error(\n\t\t\t\t\t\tt(\"Failed to inspect capability plugin directory {directory}: {reason}\", {\n\t\t\t\t\t\t\tdirectory: resolvedDirectory,\n\t\t\t\t\t\t\treason: linkError instanceof Error ? linkError.message : String(linkError),\n\t\t\t\t\t\t}),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t\tthrow new Error(\n\t\t\t\tt(\"Failed to inspect capability plugin directory {directory}: {reason}\", {\n\t\t\t\t\tdirectory: resolvedDirectory,\n\t\t\t\t\treason: error instanceof Error ? error.message : String(error),\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\tif (!stats.isDirectory()) {\n\t\t\tthrow new Error(\n\t\t\t\tt(\"Capability plugin path must be a directory: {directory}\", { directory: resolvedDirectory }),\n\t\t\t);\n\t\t}\n\n\t\tlet canonicalDirectory: string;\n\t\ttry {\n\t\t\tcanonicalDirectory = realpathSync(resolvedDirectory);\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\tt(\"Failed to resolve capability plugin directory {directory}: {reason}\", {\n\t\t\t\t\tdirectory: resolvedDirectory,\n\t\t\t\t\treason: error instanceof Error ? error.message : String(error),\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\tif (seenDirectories.has(canonicalDirectory)) return;\n\t\tseenDirectories.add(canonicalDirectory);\n\n\t\tlet entries: Dirent<string>[];\n\t\ttry {\n\t\t\tentries = readdirSync(resolvedDirectory, { withFileTypes: true, encoding: \"utf8\" });\n\t\t} catch (error) {\n\t\t\tthrow new Error(\n\t\t\t\tt(\"Failed to read capability plugin directory {directory}: {reason}\", {\n\t\t\t\t\tdirectory: resolvedDirectory,\n\t\t\t\t\treason: error instanceof Error ? error.message : String(error),\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\n\t\tfor (const entry of entries.sort((left, right) => compareNames(left.name, right.name))) {\n\t\t\tif (entry.name === \"node_modules\" || entry.name.startsWith(\".\")) continue;\n\t\t\tconst entryPath = path.join(resolvedDirectory, entry.name);\n\t\t\tif (entry.isDirectory()) {\n\t\t\t\tvisit(entryPath, false);\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (!entry.isFile() || entry.name !== \"plugin.json\") continue;\n\n\t\t\tlet canonicalManifest: string;\n\t\t\ttry {\n\t\t\t\tcanonicalManifest = realpathSync(entryPath);\n\t\t\t} catch (error) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\tt(\"Failed to resolve capability plugin manifest {path}: {reason}\", {\n\t\t\t\t\t\tpath: entryPath,\n\t\t\t\t\t\treason: error instanceof Error ? error.message : String(error),\n\t\t\t\t\t}),\n\t\t\t\t);\n\t\t\t}\n\t\t\tif (seenManifests.has(canonicalManifest)) continue;\n\t\t\tseenManifests.add(canonicalManifest);\n\t\t\tmanifests.push(canonicalManifest);\n\t\t}\n\t};\n\n\tfor (const pluginDirectory of pluginDirectories) visit(pluginDirectory, true);\n\treturn manifests;\n}\n\n/**\n * Load a capability plugin through the public facade only.\n * Filesystem discovery and package installation stay outside this mechanism.\n */\nexport async function loadCapabilityPlugin(\n\truntime: CapabilityRuntime,\n\tmanifest: PluginManifest,\n\tfactory: CapabilityPluginFactory,\n): Promise<CapabilityPluginHandle> {\n\tconst active = activePlugins.get(runtime) ?? new Map<string, symbol>();\n\tif (active.has(manifest.id)) throw new Error(t(\"Capability plugin is already loaded: {id}\", { id: manifest.id }));\n\tconst ownerToken = Symbol(manifest.id);\n\tactive.set(manifest.id, ownerToken);\n\tactivePlugins.set(runtime, active);\n\tlet api: CapabilityAPI | undefined;\n\tlet instance: CapabilityPluginInstance | undefined;\n\tconst cleanup = async (notifyDispose: boolean): Promise<void> => {\n\t\tconst errors: unknown[] = [];\n\t\tif (api) runtime.revokeAPI(api);\n\t\ttry {\n\t\t\tawait runtime.disposePlugin(manifest.id);\n\t\t} catch (error) {\n\t\t\terrors.push(error);\n\t\t}\n\t\ttry {\n\t\t\tawait instance?.dispose();\n\t\t} catch (error) {\n\t\t\terrors.push(error);\n\t\t}\n\t\tif (notifyDispose) {\n\t\t\ttry {\n\t\t\t\tawait dispatchPluginDisposeEvent(runtime, manifest, errors.length === 0 ? \"disposed\" : \"failed\");\n\t\t\t} catch (error) {\n\t\t\t\terrors.push(error);\n\t\t\t}\n\t\t}\n\t\tthrowCleanupErrors(errors, manifest.id);\n\t};\n\ttry {\n\t\tapi = runtime.createAPI(manifest);\n\t\tinstance = normalizePluginInstance(await factory(api), manifest);\n\t\tawait dispatchPluginReadyEvent(runtime, manifest);\n\t\tconst pluginApi = api;\n\t\tlet disposePromise: Promise<void> | undefined;\n\t\treturn {\n\t\t\tmanifest,\n\t\t\tapi: pluginApi,\n\t\t\tready: Promise.resolve(),\n\t\t\tdispose: async () => {\n\t\t\t\tdisposePromise ??= (async () => {\n\t\t\t\t\ttry {\n\t\t\t\t\t\tawait cleanup(true);\n\t\t\t\t\t} finally {\n\t\t\t\t\t\tif (active.get(manifest.id) === ownerToken) active.delete(manifest.id);\n\t\t\t\t\t}\n\t\t\t\t})();\n\t\t\t\treturn disposePromise;\n\t\t\t},\n\t\t};\n\t} catch (error) {\n\t\ttry {\n\t\t\tawait cleanup(false);\n\t\t} catch (cleanupError) {\n\t\t\tthrow new AggregateError([error, cleanupError], `Capability plugin startup cleanup failed: ${manifest.id}`);\n\t\t} finally {\n\t\t\tif (active.get(manifest.id) === ownerToken) active.delete(manifest.id);\n\t\t}\n\t\tthrow error;\n\t}\n}\n\n/** Load a synchronous embedded plugin during host construction. */\nexport function loadCapabilityPluginSync(\n\truntime: CapabilityRuntime,\n\tmanifest: PluginManifest,\n\tfactory: CapabilityPluginSyncFactory,\n): CapabilityPluginHandle {\n\tconst active = activePlugins.get(runtime) ?? new Map<string, symbol>();\n\tif (active.has(manifest.id)) throw new Error(t(\"Capability plugin is already loaded: {id}\", { id: manifest.id }));\n\tconst ownerToken = Symbol(manifest.id);\n\tactive.set(manifest.id, ownerToken);\n\tactivePlugins.set(runtime, active);\n\tlet api: CapabilityAPI | undefined;\n\tlet instance: CapabilityPluginSyncInstance | undefined;\n\tconst cleanupRegistrationsSync = (): unknown[] => {\n\t\tconst errors: unknown[] = [];\n\t\tif (api) runtime.revokeAPI(api);\n\t\ttry {\n\t\t\truntime.disposePluginSync(manifest.id);\n\t\t} catch (error) {\n\t\t\terrors.push(error);\n\t\t}\n\t\treturn errors;\n\t};\n\tconst cleanupSync = async (): Promise<void> => {\n\t\tconst errors = cleanupRegistrationsSync();\n\t\tlet result: unknown;\n\t\ttry {\n\t\t\tresult = instance?.dispose();\n\t\t} catch (error) {\n\t\t\terrors.push(error);\n\t\t}\n\t\tif (result && typeof (result as PromiseLike<void>).then === \"function\") {\n\t\t\tconst contractError = new Error(\n\t\t\t\t`Synchronous capability plugin disposer must not return a Promise: ${manifest.id}`,\n\t\t\t);\n\t\t\ttry {\n\t\t\t\tawait result;\n\t\t\t} catch (error) {\n\t\t\t\terrors.push(error);\n\t\t\t}\n\t\t\terrors.push(contractError);\n\t\t}\n\t\ttry {\n\t\t\tawait dispatchPluginDisposeEvent(runtime, manifest, errors.length === 0 ? \"disposed\" : \"failed\");\n\t\t} catch (error) {\n\t\t\terrors.push(error);\n\t\t}\n\t\tthrowCleanupErrors(errors, manifest.id);\n\t};\n\ttry {\n\t\tapi = runtime.createAPI(manifest);\n\t\tinstance = normalizePluginSyncInstance(factory(api), manifest);\n\t} catch (error) {\n\t\ttry {\n\t\t\tthrowCleanupErrors(cleanupRegistrationsSync(), manifest.id);\n\t\t} catch (cleanupError) {\n\t\t\tthrow new AggregateError([error, cleanupError], `Capability plugin startup cleanup failed: ${manifest.id}`);\n\t\t} finally {\n\t\t\tif (active.get(manifest.id) === ownerToken) active.delete(manifest.id);\n\t\t}\n\t\tthrow error;\n\t}\n\tconst ready = dispatchPluginReadyEvent(runtime, manifest);\n\t// The embedded constructor API is synchronous; retain a handled promise so\n\t// hosts may explicitly await lifecycle delivery without risking an unhandled rejection.\n\tvoid ready.catch(() => undefined);\n\tlet disposePromise: Promise<void> | undefined;\n\treturn {\n\t\tmanifest,\n\t\tapi: api!,\n\t\tready,\n\t\tdispose: async () => {\n\t\t\tdisposePromise ??= (async () => {\n\t\t\t\tlet readyError: unknown;\n\t\t\t\ttry {\n\t\t\t\t\tawait ready;\n\t\t\t\t} catch (error) {\n\t\t\t\t\treadyError = error;\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tawait cleanupSync();\n\t\t\t\t\tif (readyError !== undefined) throw readyError;\n\t\t\t\t} catch (error) {\n\t\t\t\t\tif (readyError !== undefined && error !== readyError) {\n\t\t\t\t\t\tthrow new AggregateError([readyError, error], `Capability plugin cleanup failed: ${manifest.id}`);\n\t\t\t\t\t}\n\t\t\t\t\tthrow error;\n\t\t\t\t} finally {\n\t\t\t\t\tif (active.get(manifest.id) === ownerToken) active.delete(manifest.id);\n\t\t\t\t}\n\t\t\t})();\n\t\t\treturn disposePromise;\n\t\t},\n\t};\n}\n\n/**\n * Load a plugin from its JSON manifest. This is intentionally separate from\n * legacy extension discovery until both systems share the same public facade.\n *\n * `options.configOverride` (D-075 S4 third batch) merges host-declared values\n * over the manifest's own `config` defaults before the plugin API is built —\n * a public channel (first-party and third-party plugins alike) for hosts that\n * vouch for facts the manifest cannot know, e.g. the CLI declaring its own\n * process entry trustworthy so the subagent-delegate package auto-pools. It\n * stays below any plugin-side config channel: the agent-dir config file the\n * plugin entry reads merges over whatever the host injected here.\n */\nexport async function loadCapabilityPluginFromManifest(\n\truntime: CapabilityRuntime,\n\tmanifestPath: string,\n\toptions?: { readonly configOverride?: PluginConfig },\n): Promise<CapabilityPluginHandle> {\n\tlet raw: unknown;\n\ttry {\n\t\traw = JSON.parse(await readFile(manifestPath, \"utf8\"));\n\t} catch (error) {\n\t\tthrow new Error(\n\t\t\tt(\"Failed to read capability plugin manifest {path}: {reason}\", {\n\t\t\t\tpath: manifestPath,\n\t\t\t\treason: error instanceof Error ? error.message : String(error),\n\t\t\t}),\n\t\t);\n\t}\n\tconst parsed = parseCapabilityPluginManifest(raw, manifestPath);\n\t// hostDependencyPaths (安装店重依赖可见性): 宿主已解析的重依赖入口绝对路径\n\t// 并进 manifest config——安装店副本无 node_modules, 插件内 createRequire 自\n\t// 解析不可达 (memory 的 onnxruntime native 预检实证); 与 jiti alias 通道互补\n\t// (alias 拦截 import, 本通道喂插件内的路径式消费)。公共同道: 第一方与第三方\n\t// 插件同样可读。仍低于插件侧 config 文件通道 (agent-dir 配置合并在其上)。\n\tconst hostDependencyOverride = { hostDependencyPaths: hostDependencyPathsConfig() };\n\tconst callerOverride = options?.configOverride;\n\tconst manifest =\n\t\tcallerOverride === undefined || Object.keys(callerOverride).length === 0\n\t\t\t? { ...parsed, config: { ...parsed.config, ...hostDependencyOverride } }\n\t\t\t: { ...parsed, config: { ...parsed.config, ...hostDependencyOverride, ...callerOverride } };\n\tconst entryPath = path.resolve(path.dirname(manifestPath), manifest.entry);\n\t// Host-resolved authoring dependencies (D-075 §4.1): installed plugin\n\t// packages live in the install store, which carries no node_modules (npm\n\t// tarballs never include dependencies), so their bare imports of the SDK\n\t// and the pinned typebox dependency resolve against the host's own copies\n\t// through jiti virtual modules (./virtual-modules.ts, lazy). Works\n\t// identically in the bundle and Bun binaries where no source-tree\n\t// node_modules exists at all. D-075 S4 third batch: the protocol package\n\t// joins — the subagent-delegate package's runtime imports\n\t// (`@agent-forge/protocol`) resolve the same way. S4 fourth batch: the\n\t// memory package's native vector stack (`@lancedb/lancedb`,\n\t// `@huggingface/transformers`) resolves through the jiti alias channel\n\t// instead — those stay real host node_modules entries, so plugins load the\n\t// host's native builds rather than a virtual copy.\n\tconst [createJitiImpl, virtualModules] = await Promise.all([getCreateJiti(), getVirtualModules()]);\n\tconst jiti = createJitiImpl(import.meta.url, {\n\t\tmoduleCache: false,\n\t\ttsconfigPaths: true,\n\t\talias: buildHostDependencyAliases(hostHeavyDependencyAliases, defaultHostDependencyAliasResolution),\n\t\tvirtualModules,\n\t});\n\tlet factory: unknown;\n\ttry {\n\t\tfactory = await jiti.import(entryPath, { default: true });\n\t} catch (error) {\n\t\tthrow new Error(\n\t\t\tt(\"Failed to import capability plugin entry {path}: {reason}\", {\n\t\t\t\tpath: entryPath,\n\t\t\t\treason: error instanceof Error ? error.message : String(error),\n\t\t\t}),\n\t\t);\n\t}\n\tif (typeof factory !== \"function\") {\n\t\tthrow new Error(t(\"Capability plugin entry must default-export a factory function: {entryPath}\", { entryPath }));\n\t}\n\treturn loadCapabilityPlugin(runtime, manifest, factory as CapabilityPluginFactory);\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capability-runtime-events.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/capability-runtime-events.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EACX,wBAAwB,EACxB,sBAAsB,EACtB,uBAAuB,EACvB,0BAA0B,EAE1B,MAAM,+BAA+B,CAAC;AAWvC,OAAO,EAGN,KAAK,wBAAwB,EAC7B,KAAK,uBAAuB,EAO5B,KAAK,iBAAiB,EACtB,MAAM,iBAAiB,CAAC;AAIzB,MAAM,WAAW,gBAAgB;IAChC,iBAAiB,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,wBAAwB,CAAC,KAAK,CAAC,KAAK,OAAO,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC,CAAC;IAChH,kBAAkB,EAAE,CACnB,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,EACrB,MAAM,EAAE,uBAAuB,EAC/B,WAAW,EAAE,SAAS,MAAM,EAAE,KAC1B,IAAI,CAAC;IACV,oBAAoB,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,MAAM,EAAE,KAAK,IAAI,CAAC;IAC3G,mBAAmB,EAAE,CACpB,WAAW,EAAE,MAAM,EACnB,aAAa,EAAE,MAAM,EACrB,WAAW,EAAE,SAAS,MAAM,EAAE,EAC9B,QAAQ,EAAE,iBAAiB,EAC3B,IAAI,EAAE,MAAM,KACR,OAAO,CAAC;IACb,qBAAqB,EAAE,CAAC,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,WAAW,EAAE,SAAS,MAAM,EAAE,KAAK,IAAI,CAAC;IAC5G,oBAAoB,EAAE,CACrB,KAAK,EAAE,OAAO,GAAG,QAAQ,GAAG,KAAK,EACjC,WAAW,EAAE,MAAM,EACnB,cAAc,EAAE,MAAM,EACtB,UAAU,EAAE,0BAA0B,EACtC,WAAW,EAAE,SAAS,MAAM,EAAE,EAC9B,MAAM,CAAC,EAAE,uBAAuB,KAC5B,IAAI,CAAC;CACV;AAED;;;;GAIG;AACH,wBAAgB,sBAAsB,CAAC,IAAI,EAAE;IAC5C,KAAK,EAAE,sBAAsB,CAAC;IAC9B,KAAK,EAAE,MAAM,MAAM,CAAC;IACpB,eAAe,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;IAC9E,mBAAmB,CAAC,EAAE,wBAAwB,CAAC,qBAAqB,CAAC,CAAC;CACtE,GAAG,gBAAgB,CA4anB","sourcesContent":["import { isPluginConfigValue } from \"./capability-runtime-manifest.ts\";\nimport { cancellationError } from \"./capability-runtime-operation.ts\";\nimport { detachedSnapshot, lifecycleErrorSnapshot } from \"./capability-runtime-snapshot.ts\";\nimport {\n\tcreateRevokedCapabilityError,\n\tinvokeRegisteredCapabilityWithSignal,\n\tisRevokedCapabilityError,\n} from \"./capability-runtime-store.ts\";\nimport type {\n\tCapabilityRuntimeOptions,\n\tCapabilityRuntimeState,\n\tOperationTerminalStatus,\n\tRegisteredPluginCapability,\n\tStoredLifecycleDefinition,\n} from \"./capability-runtime-types.ts\";\nimport { lifecycleEventKey, lifecyclePhases } from \"./capability-runtime-validation.ts\";\nimport {\n\tCAPABILITY_CALL_EVENT_ID,\n\tCAPABILITY_CALL_EVENT_VERSION,\n\tOPERATION_CANCEL_EVENT_ID,\n\tOPERATION_END_EVENT_ID,\n\tOPERATION_START_EVENT_ID,\n\tOPERATION_STEP_EVENT_ID,\n} from \"./lifecycle-catalog.ts\";\nimport { LifecycleDeliveryQueueOverflowError } from \"./lifecycle-delivery-queue.ts\";\nimport {\n\ttype LifecycleDeliveryFailure,\n\ttype LifecycleDeliveryReport,\n\ttype LifecycleDispatchRequest,\n\ttype LifecycleDispatchResult,\n\ttype LifecycleEvent,\n\tLifecycleExecuteError,\n\ttype LifecycleExecuteHandler,\n\ttype LifecycleObserveHandler,\n\tLifecycleTransformError,\n\ttype LifecycleTransformHandler,\n\ttype OperationProgress,\n} from \"./public-api.ts\";\n\nconst MAX_RUNTIME_INSPECTOR_LIFECYCLE_REPORTS = 64;\n\nexport interface LifecycleRuntime {\n\tdispatchLifecycle: <TData>(request: LifecycleDispatchRequest<TData>) => Promise<LifecycleDispatchResult<TData>>;\n\treportOperationEnd: (\n\t\toperationId: string,\n\t\toperationKind: string,\n\t\tstatus: OperationTerminalStatus,\n\t\townerTokens: readonly symbol[],\n\t) => void;\n\treportOperationStart: (operationId: string, operationKind: string, ownerTokens: readonly symbol[]) => void;\n\treportOperationStep: (\n\t\toperationId: string,\n\t\toperationKind: string,\n\t\townerTokens: readonly symbol[],\n\t\tprogress: OperationProgress,\n\t\tstep: number,\n\t) => boolean;\n\treportOperationCancel: (operationId: string, operationKind: string, ownerTokens: readonly symbol[]) => void;\n\treportCapabilityCall: (\n\t\tevent: \"start\" | \"cancel\" | \"end\",\n\t\toperationId: string,\n\t\tcallerPluginId: string,\n\t\tcapability: RegisteredPluginCapability,\n\t\townerTokens: readonly symbol[],\n\t\tstatus?: OperationTerminalStatus,\n\t) => void;\n}\n\n/**\n * Create the lifecycle dispatch and operation-fact machinery for one runtime.\n * All mutable state is shared through {@link CapabilityRuntimeState}; the\n * returned functions close over the same state object as the runtime entry.\n */\nexport function createLifecycleRuntime(deps: {\n\tstate: CapabilityRuntimeState;\n\tclock: () => number;\n\tcreateRuntimeId: (kind: string, sequence: number, fallback: string) => string;\n\tonLifecycleDispatch?: CapabilityRuntimeOptions[\"onLifecycleDispatch\"];\n}): LifecycleRuntime {\n\tconst { state, clock, createRuntimeId, onLifecycleDispatch } = deps;\n\tconst lifecycleReport = (\n\t\tevent: LifecycleEvent,\n\t\tstatus: LifecycleDeliveryReport[\"status\"],\n\t\tattempted: number,\n\t\tsucceeded: number,\n\t\tfailures: readonly LifecycleDeliveryFailure[],\n\t\tqueued = 0,\n\t): LifecycleDeliveryReport =>\n\t\tObject.freeze({\n\t\t\teventId: event.id,\n\t\t\ttype: event.type,\n\t\t\tversion: event.version,\n\t\t\tphase: event.phase,\n\t\t\tstatus,\n\t\t\tattempted,\n\t\t\tsucceeded,\n\t\t\t...(queued === 0 ? {} : { queued }),\n\t\t\tfailed: failures.length,\n\t\t\tfailures: Object.freeze([...failures]),\n\t\t});\n\tconst recordLifecycleReport = (report: LifecycleDeliveryReport): void => {\n\t\tconst snapshot = detachedSnapshot({\n\t\t\teventId: report.eventId,\n\t\t\ttype: report.type,\n\t\t\tversion: report.version,\n\t\t\tphase: report.phase,\n\t\t\tstatus: report.status,\n\t\t\tattempted: report.attempted,\n\t\t\tsucceeded: report.succeeded,\n\t\t\t...(report.queued === undefined ? {} : { queued: report.queued }),\n\t\t\tfailed: report.failed,\n\t\t\tcompletedAt: clock(),\n\t\t\tfailures: report.failures.map((failure) => ({\n\t\t\t\tpluginId: failure.pluginId,\n\t\t\t\tregistrationId: failure.registrationId,\n\t\t\t\tkind: failure.kind,\n\t\t\t\terror: lifecycleErrorSnapshot(failure.error),\n\t\t\t})),\n\t\t});\n\t\tstate.lifecycleReports.push(snapshot);\n\t\tif (state.lifecycleReports.length > MAX_RUNTIME_INSPECTOR_LIFECYCLE_REPORTS) state.lifecycleReports.shift();\n\t};\n\tconst assertLifecycleDefinitionActive = (stored: StoredLifecycleDefinition): void => {\n\t\tif (!state.activeOwnerTokens.has(stored.ownerToken)) {\n\t\t\tthrow createRevokedCapabilityError(stored.owner);\n\t\t}\n\t};\n\n\tconst dispatchLifecycleImpl = async <TData>(\n\t\trequest: LifecycleDispatchRequest<TData>,\n\t): Promise<LifecycleDispatchResult<TData>> => {\n\t\tif (!request || typeof request !== \"object\") throw new Error(\"Lifecycle dispatch request is required\");\n\t\tif (request.signal?.aborted) throw cancellationError(request.signal.reason);\n\t\tif (typeof request.type !== \"string\" || !request.type.trim()) {\n\t\t\tthrow new Error(\"Lifecycle dispatch requires a non-empty type\");\n\t\t}\n\t\tif (!Number.isSafeInteger(request.version) || request.version < 1) {\n\t\t\tthrow new Error(\"Lifecycle dispatch version must be a positive safe integer\");\n\t\t}\n\t\tif (!lifecyclePhases.has(request.phase)) throw new Error(`Lifecycle dispatch phase is invalid: ${request.phase}`);\n\t\tconst stored = state.lifecycleDefinitions.get(lifecycleEventKey(request.type, request.version));\n\t\tif (!stored || !state.activeOwnerTokens.has(stored.ownerToken)) {\n\t\t\tthrow new Error(`Lifecycle event is not defined: ${request.type}@${request.version}`);\n\t\t}\n\t\tif (!(stored.definition.allowedPhases ?? [stored.definition.phase]).includes(request.phase)) {\n\t\t\tthrow new Error(\n\t\t\t\t`Lifecycle dispatch phase does not match event definition: ${request.type}@${request.version}`,\n\t\t\t);\n\t\t}\n\t\tassertLifecycleDefinitionActive(stored);\n\t\tconst sequence = ++state.eventSequence;\n\t\tconst deliveryId = createRuntimeId(\"lifecycle-delivery\", sequence, `lifecycle-delivery:${sequence}`);\n\t\tconst operationId = request.operationId;\n\t\tconst correlationId = request.correlationId ?? operationId;\n\t\tif (operationId !== undefined && (typeof operationId !== \"string\" || !operationId.trim()))\n\t\t\tthrow new Error(\"Lifecycle operationId must be non-empty\");\n\t\tif (correlationId !== undefined && (typeof correlationId !== \"string\" || !correlationId.trim())) {\n\t\t\tthrow new Error(\"Lifecycle correlationId must be non-empty\");\n\t\t}\n\t\tif (\n\t\t\trequest.causationId !== undefined &&\n\t\t\t(typeof request.causationId !== \"string\" || !request.causationId.trim())\n\t\t) {\n\t\t\tthrow new Error(\"Lifecycle causationId must be non-empty\");\n\t\t}\n\t\tconst source = request.source ?? \"host\";\n\t\tif (typeof source !== \"string\" || !source.trim()) throw new Error(\"Lifecycle source must be non-empty\");\n\n\t\tconst validated = stored.definition.validate(detachedSnapshot(request.data));\n\t\tassertLifecycleDefinitionActive(stored);\n\t\tlet data = detachedSnapshot(validated) as TData;\n\t\tconst makeEvent = (): LifecycleEvent<TData> =>\n\t\t\tdetachedSnapshot({\n\t\t\t\tid: createRuntimeId(\"lifecycle-event\", sequence, `lifecycle-event:${sequence}`),\n\t\t\t\tdeliveryId,\n\t\t\t\ttype: request.type,\n\t\t\t\tversion: request.version,\n\t\t\t\tphase: request.phase,\n\t\t\t\tsource,\n\t\t\t\ttimestamp: clock(),\n\t\t\t\t...(operationId === undefined ? {} : { operationId }),\n\t\t\t\t...(correlationId === undefined ? {} : { correlationId }),\n\t\t\t\t...(request.causationId === undefined ? {} : { causationId: request.causationId }),\n\t\t\t\tdata,\n\t\t\t});\n\t\tlet event = makeEvent();\n\t\tconst registrations = Array.from(\n\t\t\tstate.lifecycleRegistrations.get(lifecycleEventKey(request.type, request.version))?.values() ?? [],\n\t\t).sort((left, right) => left.sequence - right.sequence);\n\t\tconst transforms = registrations.filter((registration) => registration.kind === \"transform\");\n\t\tfor (let index = 0; index < transforms.length; index++) {\n\t\t\tconst registration = transforms[index];\n\t\t\ttry {\n\t\t\t\tassertLifecycleDefinitionActive(stored);\n\t\t\t\tconst registered = {\n\t\t\t\t\towner: registration.owner,\n\t\t\t\t\townerToken: registration.ownerToken,\n\t\t\t\t\tvalue: registration.handler,\n\t\t\t\t};\n\t\t\t\tconst result = await invokeRegisteredCapabilityWithSignal(state, registered, request.signal, (handler) =>\n\t\t\t\t\t(handler as LifecycleTransformHandler<TData>)(detachedSnapshot(event), request.signal),\n\t\t\t\t);\n\t\t\t\tassertLifecycleDefinitionActive(stored);\n\t\t\t\tdata = detachedSnapshot(stored.definition.validate(detachedSnapshot(result))) as TData;\n\t\t\t\tassertLifecycleDefinitionActive(stored);\n\t\t\t\tevent = makeEvent();\n\t\t\t\tassertLifecycleDefinitionActive(stored);\n\t\t\t} catch (error) {\n\t\t\t\tconst failure: LifecycleDeliveryFailure = {\n\t\t\t\t\tpluginId: registration.owner,\n\t\t\t\t\tregistrationId: registration.id,\n\t\t\t\t\tkind: registration.kind,\n\t\t\t\t\terror,\n\t\t\t\t};\n\t\t\t\tconst report = lifecycleReport(event, \"transform-failed\", index + 1, index, [failure]);\n\t\t\t\trecordLifecycleReport(report);\n\t\t\t\tthrow new LifecycleTransformError(error, report);\n\t\t\t}\n\t\t}\n\t\tconst executes = registrations.filter(\n\t\t\t(registration) => request.phase === \"committed\" && registration.kind === \"execute\",\n\t\t);\n\t\tconst executeResults: unknown[] = [];\n\t\tfor (let index = 0; index < executes.length; index++) {\n\t\t\tconst registration = executes[index];\n\t\t\ttry {\n\t\t\t\tassertLifecycleDefinitionActive(stored);\n\t\t\t\tconst registered = {\n\t\t\t\t\towner: registration.owner,\n\t\t\t\t\townerToken: registration.ownerToken,\n\t\t\t\t\tvalue: registration.handler,\n\t\t\t\t};\n\t\t\t\tconst result = await invokeRegisteredCapabilityWithSignal(state, registered, request.signal, (handler) =>\n\t\t\t\t\t(handler as LifecycleExecuteHandler<TData>)(detachedSnapshot(event), request.signal),\n\t\t\t\t);\n\t\t\t\tassertLifecycleDefinitionActive(stored);\n\t\t\t\texecuteResults.push(detachedSnapshot(result));\n\t\t\t\tassertLifecycleDefinitionActive(stored);\n\t\t\t} catch (error) {\n\t\t\t\tconst failure: LifecycleDeliveryFailure = {\n\t\t\t\t\tpluginId: registration.owner,\n\t\t\t\t\tregistrationId: registration.id,\n\t\t\t\t\tkind: registration.kind,\n\t\t\t\t\terror,\n\t\t\t\t};\n\t\t\t\tconst report = lifecycleReport(event, \"execute-failed\", index + 1, index, [failure]);\n\t\t\t\trecordLifecycleReport(report);\n\t\t\t\tthrow new LifecycleExecuteError(error, report);\n\t\t\t}\n\t\t}\n\n\t\tconst deliveries = registrations.filter(\n\t\t\t(registration) =>\n\t\t\t\tregistration.kind === \"observe\" || (request.phase === \"committed\" && registration.kind === \"after-commit\"),\n\t\t);\n\t\tassertLifecycleDefinitionActive(stored);\n\t\tconst results = await Promise.allSettled(\n\t\t\tdeliveries\n\t\t\t\t.filter((registration) => registration.queue === undefined)\n\t\t\t\t.map((registration) => {\n\t\t\t\t\tconst registered = {\n\t\t\t\t\t\towner: registration.owner,\n\t\t\t\t\t\townerToken: registration.ownerToken,\n\t\t\t\t\t\tvalue: registration.handler,\n\t\t\t\t\t};\n\t\t\t\t\treturn invokeRegisteredCapabilityWithSignal(state, registered, request.signal, (handler) =>\n\t\t\t\t\t\t(handler as LifecycleObserveHandler<TData>)(detachedSnapshot(event), request.signal),\n\t\t\t\t\t);\n\t\t\t\t}),\n\t\t);\n\t\tif (request.signal?.aborted) throw cancellationError(request.signal.reason);\n\t\tconst failures: LifecycleDeliveryFailure[] = [];\n\t\tlet succeeded = 0;\n\t\tconst inlineDeliveries = deliveries.filter((registration) => registration.queue === undefined);\n\t\tfor (let index = 0; index < results.length; index++) {\n\t\t\tconst result = results[index];\n\t\t\tif (result.status === \"fulfilled\") {\n\t\t\t\tsucceeded++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (isRevokedCapabilityError(result.reason)) continue;\n\t\t\tconst registration = inlineDeliveries[index];\n\t\t\tfailures.push({\n\t\t\t\tpluginId: registration.owner,\n\t\t\t\tregistrationId: registration.id,\n\t\t\t\tkind: registration.kind,\n\t\t\t\terror: result.reason,\n\t\t\t});\n\t\t}\n\t\tlet queued = 0;\n\t\tfor (const registration of deliveries) {\n\t\t\tconst queue = registration.queue;\n\t\t\tif (!queue) continue;\n\t\t\ttry {\n\t\t\t\tconst acceptedBefore = queue.snapshot().accepted;\n\t\t\t\tconst delivery = queue.enqueue({ event: detachedSnapshot(event), signal: request.signal });\n\t\t\t\tconst queueSnapshot = queue.snapshot();\n\t\t\t\tif (queueSnapshot.accepted > acceptedBefore) queued += 1;\n\t\t\t\tif (queueSnapshot.status === \"overflowed\") {\n\t\t\t\t\tfailures.push({\n\t\t\t\t\t\tpluginId: registration.owner,\n\t\t\t\t\t\tregistrationId: registration.id,\n\t\t\t\t\t\tkind: registration.kind,\n\t\t\t\t\t\terror: new LifecycleDeliveryQueueOverflowError(\n\t\t\t\t\t\t\tevent.type === \"model.stream\"\n\t\t\t\t\t\t\t\t? \"model_stream_backpressure_overflow\"\n\t\t\t\t\t\t\t\t: \"lifecycle_delivery_backpressure_overflow\",\n\t\t\t\t\t\t\tqueueSnapshot.maxPendingEvents,\n\t\t\t\t\t\t\tqueueSnapshot.maxPendingBytes,\n\t\t\t\t\t\t\tqueueSnapshot.pendingEvents,\n\t\t\t\t\t\t\tqueueSnapshot.pendingBytes,\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tvoid delivery.then(\n\t\t\t\t\t() => recordLifecycleReport(lifecycleReport(event, \"delivered\", 1, 1, [])),\n\t\t\t\t\t(error) => {\n\t\t\t\t\t\tif (isRevokedCapabilityError(error)) return;\n\t\t\t\t\t\tif (error instanceof LifecycleDeliveryQueueOverflowError) return;\n\t\t\t\t\t\tconst failure: LifecycleDeliveryFailure = {\n\t\t\t\t\t\t\tpluginId: registration.owner,\n\t\t\t\t\t\t\tregistrationId: registration.id,\n\t\t\t\t\t\t\tkind: registration.kind,\n\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t};\n\t\t\t\t\t\trecordLifecycleReport(lifecycleReport(event, \"delivered\", 1, 0, [failure]));\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\tfailures.push({\n\t\t\t\t\tpluginId: registration.owner,\n\t\t\t\t\tregistrationId: registration.id,\n\t\t\t\t\tkind: registration.kind,\n\t\t\t\t\terror,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tassertLifecycleDefinitionActive(stored);\n\t\tconst report = lifecycleReport(\n\t\t\tevent,\n\t\t\tqueued > 0 ? \"queued\" : \"delivered\",\n\t\t\tdeliveries.length,\n\t\t\tsucceeded,\n\t\t\tfailures,\n\t\t\tqueued,\n\t\t);\n\t\trecordLifecycleReport(report);\n\t\tassertLifecycleDefinitionActive(stored);\n\t\treturn Object.freeze({ event, data: event.data, executeResults: Object.freeze(executeResults), report });\n\t};\n\tconst dispatchLifecycle = <TData>(\n\t\trequest: LifecycleDispatchRequest<TData>,\n\t): Promise<LifecycleDispatchResult<TData>> => {\n\t\tconst settled = dispatchLifecycleImpl(request);\n\t\ttry {\n\t\t\tonLifecycleDispatch?.(\n\t\t\t\trequest as LifecycleDispatchRequest<unknown>,\n\t\t\t\tsettled as Promise<LifecycleDispatchResult<unknown>>,\n\t\t\t);\n\t\t} catch {\n\t\t\t// Test observers must never alter lifecycle delivery or operation results.\n\t\t}\n\t\treturn settled;\n\t};\n\tconst reportOperationFact = (\n\t\teventId: string,\n\t\toperationId: string,\n\t\toperationKind: string,\n\t\tstatus: OperationTerminalStatus,\n\t\townerTokens: readonly symbol[],\n\t): void => {\n\t\tif (ownerTokens.some((ownerToken) => !state.activeOwnerTokens.has(ownerToken))) return;\n\t\tconst data = {\n\t\t\tversion: 1 as const,\n\t\t\toperationId,\n\t\t\toperationKind,\n\t\t\tstatus,\n\t\t\t...(status === \"failed\" ? { errorMessage: \"operation failed\" } : {}),\n\t\t\t...(status === \"cancelled\" ? { reason: \"cancelled\" } : {}),\n\t\t};\n\t\tvoid dispatchLifecycle({\n\t\t\ttype: eventId,\n\t\t\tversion: 1,\n\t\t\tphase: \"committed\",\n\t\t\tsource: \"host\",\n\t\t\toperationId,\n\t\t\tcorrelationId: operationId,\n\t\t\tdata,\n\t\t}).catch(() => {});\n\t};\n\tconst reportOperationEnd = (\n\t\toperationId: string,\n\t\toperationKind: string,\n\t\tstatus: OperationTerminalStatus,\n\t\townerTokens: readonly symbol[],\n\t): void => {\n\t\treportOperationFact(OPERATION_END_EVENT_ID, operationId, operationKind, status, ownerTokens);\n\t};\n\t// operation.start fires when execution begins; operation.cancel fires at the\n\t// cancellation request, before the terminal operation.end fact. Both stay\n\t// within CapabilityAPI-registered operations and never carry input, results,\n\t// or caller cancellation reasons.\n\tconst reportOperationStart = (operationId: string, operationKind: string, ownerTokens: readonly symbol[]): void => {\n\t\tif (ownerTokens.some((ownerToken) => !state.activeOwnerTokens.has(ownerToken))) return;\n\t\tvoid dispatchLifecycle({\n\t\t\ttype: OPERATION_START_EVENT_ID,\n\t\t\tversion: 1,\n\t\t\tphase: \"committed\",\n\t\t\tsource: \"host\",\n\t\t\toperationId,\n\t\t\tcorrelationId: operationId,\n\t\t\tdata: { version: 1, operationId, operationKind },\n\t\t}).catch(() => {});\n\t};\n\tconst reportOperationStep = (\n\t\toperationId: string,\n\t\toperationKind: string,\n\t\townerTokens: readonly symbol[],\n\t\tprogress: OperationProgress,\n\t\tstep: number,\n\t): boolean => {\n\t\tif (\n\t\t\townerTokens.some((ownerToken) => !state.activeOwnerTokens.has(ownerToken)) ||\n\t\t\tstate.statuses.get(operationId) !== \"running\"\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\t\tif (!progress || typeof progress !== \"object\" || Array.isArray(progress)) {\n\t\t\tthrow new Error(\"Operation progress must be an object\");\n\t\t}\n\t\tif (progress.message !== undefined && (typeof progress.message !== \"string\" || !progress.message.trim())) {\n\t\t\tthrow new Error(\"Operation progress message must be a non-empty string\");\n\t\t}\n\t\tif (progress.data !== undefined && !isPluginConfigValue(progress.data)) {\n\t\t\tthrow new Error(\"Operation progress data must be serializable\");\n\t\t}\n\t\tvoid dispatchLifecycle({\n\t\t\ttype: OPERATION_STEP_EVENT_ID,\n\t\t\tversion: 1,\n\t\t\tphase: \"committed\",\n\t\t\tsource: \"host\",\n\t\t\toperationId,\n\t\t\tcorrelationId: operationId,\n\t\t\tdata: {\n\t\t\t\tversion: 1,\n\t\t\t\toperationId,\n\t\t\t\toperationKind,\n\t\t\t\tstep,\n\t\t\t\t...(progress.message === undefined ? {} : { message: progress.message }),\n\t\t\t\t...(progress.data === undefined ? {} : { data: detachedSnapshot(progress.data) }),\n\t\t\t},\n\t\t}).catch(() => {});\n\t\treturn true;\n\t};\n\tconst reportOperationCancel = (operationId: string, operationKind: string, ownerTokens: readonly symbol[]): void => {\n\t\tif (ownerTokens.some((ownerToken) => !state.activeOwnerTokens.has(ownerToken))) return;\n\t\tvoid dispatchLifecycle({\n\t\t\ttype: OPERATION_CANCEL_EVENT_ID,\n\t\t\tversion: 1,\n\t\t\tphase: \"committed\",\n\t\t\tsource: \"host\",\n\t\t\toperationId,\n\t\t\tcorrelationId: operationId,\n\t\t\tdata: { version: 1, operationId, operationKind },\n\t\t}).catch(() => {});\n\t};\n\tconst reportCapabilityCall = (\n\t\tevent: \"start\" | \"cancel\" | \"end\",\n\t\toperationId: string,\n\t\tcallerPluginId: string,\n\t\tcapability: RegisteredPluginCapability,\n\t\townerTokens: readonly symbol[],\n\t\tstatus?: OperationTerminalStatus,\n\t): void => {\n\t\tif (ownerTokens.some((ownerToken) => !state.activeOwnerTokens.has(ownerToken))) return;\n\t\tconst data = {\n\t\t\tversion: 1 as const,\n\t\t\tevent,\n\t\t\toperationId,\n\t\t\tcallerPluginId,\n\t\t\tcapabilityId: capability.declaration.id,\n\t\t\tcapabilityVersion: capability.declaration.version,\n\t\t\tcapabilityKind: capability.declaration.kind,\n\t\t\tproviderPluginId: capability.owner,\n\t\t\t...(status === undefined ? {} : { status }),\n\t\t};\n\t\tvoid dispatchLifecycle({\n\t\t\ttype: CAPABILITY_CALL_EVENT_ID,\n\t\t\tversion: CAPABILITY_CALL_EVENT_VERSION,\n\t\t\tphase: \"committed\",\n\t\t\tsource: \"host\",\n\t\t\toperationId,\n\t\t\tcorrelationId: operationId,\n\t\t\tdata,\n\t\t}).catch(() => {});\n\t};\n\n\treturn {\n\t\tdispatchLifecycle,\n\t\treportOperationEnd,\n\t\treportOperationStart,\n\t\treportOperationStep,\n\t\treportOperationCancel,\n\t\treportCapabilityCall,\n\t};\n}\n"]}
|
|
1
|
+
{"version":3,"file":"capability-runtime-events.d.ts","sourceRoot":"","sources":["../../../src/core/extensions/capability-runtime-events.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EACX,wBAAwB,EACxB,sBAAsB,EACtB,uBAAuB,EACvB,0BAA0B,EAE1B,MAAM,+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CAAC,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,KAAK,MAAM,CAAC;IAC9E,mBAAmB,CAAC,EAAE,wBAAwB,CAAC,qBAAqB,CAAC,CAAC;CACtE,GAAG,gBAAgB,CAkbnB","sourcesContent":["import { t } from \"../i18n/index.ts\";\nimport { isPluginConfigValue } from \"./capability-runtime-manifest.ts\";\nimport { cancellationError } from \"./capability-runtime-operation.ts\";\nimport { detachedSnapshot, lifecycleErrorSnapshot } from \"./capability-runtime-snapshot.ts\";\nimport {\n\tcreateRevokedCapabilityError,\n\tinvokeRegisteredCapabilityWithSignal,\n\tisRevokedCapabilityError,\n} from \"./capability-runtime-store.ts\";\nimport type {\n\tCapabilityRuntimeOptions,\n\tCapabilityRuntimeState,\n\tOperationTerminalStatus,\n\tRegisteredPluginCapability,\n\tStoredLifecycleDefinition,\n} from \"./capability-runtime-types.ts\";\nimport { lifecycleEventKey, lifecyclePhases } from \"./capability-runtime-validation.ts\";\nimport {\n\tCAPABILITY_CALL_EVENT_ID,\n\tCAPABILITY_CALL_EVENT_VERSION,\n\tOPERATION_CANCEL_EVENT_ID,\n\tOPERATION_END_EVENT_ID,\n\tOPERATION_START_EVENT_ID,\n\tOPERATION_STEP_EVENT_ID,\n} from \"./lifecycle-catalog.ts\";\nimport { LifecycleDeliveryQueueOverflowError } from \"./lifecycle-delivery-queue.ts\";\nimport {\n\ttype LifecycleDeliveryFailure,\n\ttype LifecycleDeliveryReport,\n\ttype LifecycleDispatchRequest,\n\ttype LifecycleDispatchResult,\n\ttype LifecycleEvent,\n\tLifecycleExecuteError,\n\ttype LifecycleExecuteHandler,\n\ttype LifecycleObserveHandler,\n\tLifecycleTransformError,\n\ttype LifecycleTransformHandler,\n\ttype OperationProgress,\n} from \"./public-api.ts\";\n\nconst MAX_RUNTIME_INSPECTOR_LIFECYCLE_REPORTS = 64;\n\nexport interface LifecycleRuntime {\n\tdispatchLifecycle: <TData>(request: LifecycleDispatchRequest<TData>) => Promise<LifecycleDispatchResult<TData>>;\n\treportOperationEnd: (\n\t\toperationId: string,\n\t\toperationKind: string,\n\t\tstatus: OperationTerminalStatus,\n\t\townerTokens: readonly symbol[],\n\t) => void;\n\treportOperationStart: (operationId: string, operationKind: string, ownerTokens: readonly symbol[]) => void;\n\treportOperationStep: (\n\t\toperationId: string,\n\t\toperationKind: string,\n\t\townerTokens: readonly symbol[],\n\t\tprogress: OperationProgress,\n\t\tstep: number,\n\t) => boolean;\n\treportOperationCancel: (operationId: string, operationKind: string, ownerTokens: readonly symbol[]) => void;\n\treportCapabilityCall: (\n\t\tevent: \"start\" | \"cancel\" | \"end\",\n\t\toperationId: string,\n\t\tcallerPluginId: string,\n\t\tcapability: RegisteredPluginCapability,\n\t\townerTokens: readonly symbol[],\n\t\tstatus?: OperationTerminalStatus,\n\t) => void;\n}\n\n/**\n * Create the lifecycle dispatch and operation-fact machinery for one runtime.\n * All mutable state is shared through {@link CapabilityRuntimeState}; the\n * returned functions close over the same state object as the runtime entry.\n */\nexport function createLifecycleRuntime(deps: {\n\tstate: CapabilityRuntimeState;\n\tclock: () => number;\n\tcreateRuntimeId: (kind: string, sequence: number, fallback: string) => string;\n\tonLifecycleDispatch?: CapabilityRuntimeOptions[\"onLifecycleDispatch\"];\n}): LifecycleRuntime {\n\tconst { state, clock, createRuntimeId, onLifecycleDispatch } = deps;\n\tconst lifecycleReport = (\n\t\tevent: LifecycleEvent,\n\t\tstatus: LifecycleDeliveryReport[\"status\"],\n\t\tattempted: number,\n\t\tsucceeded: number,\n\t\tfailures: readonly LifecycleDeliveryFailure[],\n\t\tqueued = 0,\n\t): LifecycleDeliveryReport =>\n\t\tObject.freeze({\n\t\t\teventId: event.id,\n\t\t\ttype: event.type,\n\t\t\tversion: event.version,\n\t\t\tphase: event.phase,\n\t\t\tstatus,\n\t\t\tattempted,\n\t\t\tsucceeded,\n\t\t\t...(queued === 0 ? {} : { queued }),\n\t\t\tfailed: failures.length,\n\t\t\tfailures: Object.freeze([...failures]),\n\t\t});\n\tconst recordLifecycleReport = (report: LifecycleDeliveryReport): void => {\n\t\tconst snapshot = detachedSnapshot({\n\t\t\teventId: report.eventId,\n\t\t\ttype: report.type,\n\t\t\tversion: report.version,\n\t\t\tphase: report.phase,\n\t\t\tstatus: report.status,\n\t\t\tattempted: report.attempted,\n\t\t\tsucceeded: report.succeeded,\n\t\t\t...(report.queued === undefined ? {} : { queued: report.queued }),\n\t\t\tfailed: report.failed,\n\t\t\tcompletedAt: clock(),\n\t\t\tfailures: report.failures.map((failure) => ({\n\t\t\t\tpluginId: failure.pluginId,\n\t\t\t\tregistrationId: failure.registrationId,\n\t\t\t\tkind: failure.kind,\n\t\t\t\terror: lifecycleErrorSnapshot(failure.error),\n\t\t\t})),\n\t\t});\n\t\tstate.lifecycleReports.push(snapshot);\n\t\tif (state.lifecycleReports.length > MAX_RUNTIME_INSPECTOR_LIFECYCLE_REPORTS) state.lifecycleReports.shift();\n\t};\n\tconst assertLifecycleDefinitionActive = (stored: StoredLifecycleDefinition): void => {\n\t\tif (!state.activeOwnerTokens.has(stored.ownerToken)) {\n\t\t\tthrow createRevokedCapabilityError(stored.owner);\n\t\t}\n\t};\n\n\tconst dispatchLifecycleImpl = async <TData>(\n\t\trequest: LifecycleDispatchRequest<TData>,\n\t): Promise<LifecycleDispatchResult<TData>> => {\n\t\tif (!request || typeof request !== \"object\") throw new Error(t(\"Lifecycle dispatch request is required\"));\n\t\tif (request.signal?.aborted) throw cancellationError(request.signal.reason);\n\t\tif (typeof request.type !== \"string\" || !request.type.trim()) {\n\t\t\tthrow new Error(t(\"Lifecycle dispatch requires a non-empty type\"));\n\t\t}\n\t\tif (!Number.isSafeInteger(request.version) || request.version < 1) {\n\t\t\tthrow new Error(t(\"Lifecycle dispatch version must be a positive safe integer\"));\n\t\t}\n\t\tif (!lifecyclePhases.has(request.phase))\n\t\t\tthrow new Error(t(\"Lifecycle dispatch phase is invalid: {phase}\", { phase: request.phase }));\n\t\tconst stored = state.lifecycleDefinitions.get(lifecycleEventKey(request.type, request.version));\n\t\tif (!stored || !state.activeOwnerTokens.has(stored.ownerToken)) {\n\t\t\tthrow new Error(\n\t\t\t\tt(\"Lifecycle event is not defined: {type}@{version}\", { type: request.type, version: request.version }),\n\t\t\t);\n\t\t}\n\t\tif (!(stored.definition.allowedPhases ?? [stored.definition.phase]).includes(request.phase)) {\n\t\t\tthrow new Error(\n\t\t\t\tt(\"Lifecycle dispatch phase does not match event definition: {type}@{version}\", {\n\t\t\t\t\ttype: request.type,\n\t\t\t\t\tversion: request.version,\n\t\t\t\t}),\n\t\t\t);\n\t\t}\n\t\tassertLifecycleDefinitionActive(stored);\n\t\tconst sequence = ++state.eventSequence;\n\t\tconst deliveryId = createRuntimeId(\"lifecycle-delivery\", sequence, `lifecycle-delivery:${sequence}`);\n\t\tconst operationId = request.operationId;\n\t\tconst correlationId = request.correlationId ?? operationId;\n\t\tif (operationId !== undefined && (typeof operationId !== \"string\" || !operationId.trim()))\n\t\t\tthrow new Error(t(\"Lifecycle operationId must be non-empty\"));\n\t\tif (correlationId !== undefined && (typeof correlationId !== \"string\" || !correlationId.trim())) {\n\t\t\tthrow new Error(t(\"Lifecycle correlationId must be non-empty\"));\n\t\t}\n\t\tif (\n\t\t\trequest.causationId !== undefined &&\n\t\t\t(typeof request.causationId !== \"string\" || !request.causationId.trim())\n\t\t) {\n\t\t\tthrow new Error(t(\"Lifecycle causationId must be non-empty\"));\n\t\t}\n\t\tconst source = request.source ?? \"host\";\n\t\tif (typeof source !== \"string\" || !source.trim()) throw new Error(t(\"Lifecycle source must be non-empty\"));\n\n\t\tconst validated = stored.definition.validate(detachedSnapshot(request.data));\n\t\tassertLifecycleDefinitionActive(stored);\n\t\tlet data = detachedSnapshot(validated) as TData;\n\t\tconst makeEvent = (): LifecycleEvent<TData> =>\n\t\t\tdetachedSnapshot({\n\t\t\t\tid: createRuntimeId(\"lifecycle-event\", sequence, `lifecycle-event:${sequence}`),\n\t\t\t\tdeliveryId,\n\t\t\t\ttype: request.type,\n\t\t\t\tversion: request.version,\n\t\t\t\tphase: request.phase,\n\t\t\t\tsource,\n\t\t\t\ttimestamp: clock(),\n\t\t\t\t...(operationId === undefined ? {} : { operationId }),\n\t\t\t\t...(correlationId === undefined ? {} : { correlationId }),\n\t\t\t\t...(request.causationId === undefined ? {} : { causationId: request.causationId }),\n\t\t\t\tdata,\n\t\t\t});\n\t\tlet event = makeEvent();\n\t\tconst registrations = Array.from(\n\t\t\tstate.lifecycleRegistrations.get(lifecycleEventKey(request.type, request.version))?.values() ?? [],\n\t\t).sort((left, right) => left.sequence - right.sequence);\n\t\tconst transforms = registrations.filter((registration) => registration.kind === \"transform\");\n\t\tfor (let index = 0; index < transforms.length; index++) {\n\t\t\tconst registration = transforms[index];\n\t\t\ttry {\n\t\t\t\tassertLifecycleDefinitionActive(stored);\n\t\t\t\tconst registered = {\n\t\t\t\t\towner: registration.owner,\n\t\t\t\t\townerToken: registration.ownerToken,\n\t\t\t\t\tvalue: registration.handler,\n\t\t\t\t};\n\t\t\t\tconst result = await invokeRegisteredCapabilityWithSignal(state, registered, request.signal, (handler) =>\n\t\t\t\t\t(handler as LifecycleTransformHandler<TData>)(detachedSnapshot(event), request.signal),\n\t\t\t\t);\n\t\t\t\tassertLifecycleDefinitionActive(stored);\n\t\t\t\tdata = detachedSnapshot(stored.definition.validate(detachedSnapshot(result))) as TData;\n\t\t\t\tassertLifecycleDefinitionActive(stored);\n\t\t\t\tevent = makeEvent();\n\t\t\t\tassertLifecycleDefinitionActive(stored);\n\t\t\t} catch (error) {\n\t\t\t\tconst failure: LifecycleDeliveryFailure = {\n\t\t\t\t\tpluginId: registration.owner,\n\t\t\t\t\tregistrationId: registration.id,\n\t\t\t\t\tkind: registration.kind,\n\t\t\t\t\terror,\n\t\t\t\t};\n\t\t\t\tconst report = lifecycleReport(event, \"transform-failed\", index + 1, index, [failure]);\n\t\t\t\trecordLifecycleReport(report);\n\t\t\t\tthrow new LifecycleTransformError(error, report);\n\t\t\t}\n\t\t}\n\t\tconst executes = registrations.filter(\n\t\t\t(registration) => request.phase === \"committed\" && registration.kind === \"execute\",\n\t\t);\n\t\tconst executeResults: unknown[] = [];\n\t\tfor (let index = 0; index < executes.length; index++) {\n\t\t\tconst registration = executes[index];\n\t\t\ttry {\n\t\t\t\tassertLifecycleDefinitionActive(stored);\n\t\t\t\tconst registered = {\n\t\t\t\t\towner: registration.owner,\n\t\t\t\t\townerToken: registration.ownerToken,\n\t\t\t\t\tvalue: registration.handler,\n\t\t\t\t};\n\t\t\t\tconst result = await invokeRegisteredCapabilityWithSignal(state, registered, request.signal, (handler) =>\n\t\t\t\t\t(handler as LifecycleExecuteHandler<TData>)(detachedSnapshot(event), request.signal),\n\t\t\t\t);\n\t\t\t\tassertLifecycleDefinitionActive(stored);\n\t\t\t\texecuteResults.push(detachedSnapshot(result));\n\t\t\t\tassertLifecycleDefinitionActive(stored);\n\t\t\t} catch (error) {\n\t\t\t\tconst failure: LifecycleDeliveryFailure = {\n\t\t\t\t\tpluginId: registration.owner,\n\t\t\t\t\tregistrationId: registration.id,\n\t\t\t\t\tkind: registration.kind,\n\t\t\t\t\terror,\n\t\t\t\t};\n\t\t\t\tconst report = lifecycleReport(event, \"execute-failed\", index + 1, index, [failure]);\n\t\t\t\trecordLifecycleReport(report);\n\t\t\t\tthrow new LifecycleExecuteError(error, report);\n\t\t\t}\n\t\t}\n\n\t\tconst deliveries = registrations.filter(\n\t\t\t(registration) =>\n\t\t\t\tregistration.kind === \"observe\" || (request.phase === \"committed\" && registration.kind === \"after-commit\"),\n\t\t);\n\t\tassertLifecycleDefinitionActive(stored);\n\t\tconst results = await Promise.allSettled(\n\t\t\tdeliveries\n\t\t\t\t.filter((registration) => registration.queue === undefined)\n\t\t\t\t.map((registration) => {\n\t\t\t\t\tconst registered = {\n\t\t\t\t\t\towner: registration.owner,\n\t\t\t\t\t\townerToken: registration.ownerToken,\n\t\t\t\t\t\tvalue: registration.handler,\n\t\t\t\t\t};\n\t\t\t\t\treturn invokeRegisteredCapabilityWithSignal(state, registered, request.signal, (handler) =>\n\t\t\t\t\t\t(handler as LifecycleObserveHandler<TData>)(detachedSnapshot(event), request.signal),\n\t\t\t\t\t);\n\t\t\t\t}),\n\t\t);\n\t\tif (request.signal?.aborted) throw cancellationError(request.signal.reason);\n\t\tconst failures: LifecycleDeliveryFailure[] = [];\n\t\tlet succeeded = 0;\n\t\tconst inlineDeliveries = deliveries.filter((registration) => registration.queue === undefined);\n\t\tfor (let index = 0; index < results.length; index++) {\n\t\t\tconst result = results[index];\n\t\t\tif (result.status === \"fulfilled\") {\n\t\t\t\tsucceeded++;\n\t\t\t\tcontinue;\n\t\t\t}\n\t\t\tif (isRevokedCapabilityError(result.reason)) continue;\n\t\t\tconst registration = inlineDeliveries[index];\n\t\t\tfailures.push({\n\t\t\t\tpluginId: registration.owner,\n\t\t\t\tregistrationId: registration.id,\n\t\t\t\tkind: registration.kind,\n\t\t\t\terror: result.reason,\n\t\t\t});\n\t\t}\n\t\tlet queued = 0;\n\t\tfor (const registration of deliveries) {\n\t\t\tconst queue = registration.queue;\n\t\t\tif (!queue) continue;\n\t\t\ttry {\n\t\t\t\tconst acceptedBefore = queue.snapshot().accepted;\n\t\t\t\tconst delivery = queue.enqueue({ event: detachedSnapshot(event), signal: request.signal });\n\t\t\t\tconst queueSnapshot = queue.snapshot();\n\t\t\t\tif (queueSnapshot.accepted > acceptedBefore) queued += 1;\n\t\t\t\tif (queueSnapshot.status === \"overflowed\") {\n\t\t\t\t\tfailures.push({\n\t\t\t\t\t\tpluginId: registration.owner,\n\t\t\t\t\t\tregistrationId: registration.id,\n\t\t\t\t\t\tkind: registration.kind,\n\t\t\t\t\t\terror: new LifecycleDeliveryQueueOverflowError(\n\t\t\t\t\t\t\tevent.type === \"model.stream\"\n\t\t\t\t\t\t\t\t? \"model_stream_backpressure_overflow\"\n\t\t\t\t\t\t\t\t: \"lifecycle_delivery_backpressure_overflow\",\n\t\t\t\t\t\t\tqueueSnapshot.maxPendingEvents,\n\t\t\t\t\t\t\tqueueSnapshot.maxPendingBytes,\n\t\t\t\t\t\t\tqueueSnapshot.pendingEvents,\n\t\t\t\t\t\t\tqueueSnapshot.pendingBytes,\n\t\t\t\t\t\t\t0,\n\t\t\t\t\t\t),\n\t\t\t\t\t});\n\t\t\t\t}\n\t\t\t\tvoid delivery.then(\n\t\t\t\t\t() => recordLifecycleReport(lifecycleReport(event, \"delivered\", 1, 1, [])),\n\t\t\t\t\t(error) => {\n\t\t\t\t\t\tif (isRevokedCapabilityError(error)) return;\n\t\t\t\t\t\tif (error instanceof LifecycleDeliveryQueueOverflowError) return;\n\t\t\t\t\t\tconst failure: LifecycleDeliveryFailure = {\n\t\t\t\t\t\t\tpluginId: registration.owner,\n\t\t\t\t\t\t\tregistrationId: registration.id,\n\t\t\t\t\t\t\tkind: registration.kind,\n\t\t\t\t\t\t\terror,\n\t\t\t\t\t\t};\n\t\t\t\t\t\trecordLifecycleReport(lifecycleReport(event, \"delivered\", 1, 0, [failure]));\n\t\t\t\t\t},\n\t\t\t\t);\n\t\t\t} catch (error) {\n\t\t\t\tfailures.push({\n\t\t\t\t\tpluginId: registration.owner,\n\t\t\t\t\tregistrationId: registration.id,\n\t\t\t\t\tkind: registration.kind,\n\t\t\t\t\terror,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\t\tassertLifecycleDefinitionActive(stored);\n\t\tconst report = lifecycleReport(\n\t\t\tevent,\n\t\t\tqueued > 0 ? \"queued\" : \"delivered\",\n\t\t\tdeliveries.length,\n\t\t\tsucceeded,\n\t\t\tfailures,\n\t\t\tqueued,\n\t\t);\n\t\trecordLifecycleReport(report);\n\t\tassertLifecycleDefinitionActive(stored);\n\t\treturn Object.freeze({ event, data: event.data, executeResults: Object.freeze(executeResults), report });\n\t};\n\tconst dispatchLifecycle = <TData>(\n\t\trequest: LifecycleDispatchRequest<TData>,\n\t): Promise<LifecycleDispatchResult<TData>> => {\n\t\tconst settled = dispatchLifecycleImpl(request);\n\t\ttry {\n\t\t\tonLifecycleDispatch?.(\n\t\t\t\trequest as LifecycleDispatchRequest<unknown>,\n\t\t\t\tsettled as Promise<LifecycleDispatchResult<unknown>>,\n\t\t\t);\n\t\t} catch {\n\t\t\t// Test observers must never alter lifecycle delivery or operation results.\n\t\t}\n\t\treturn settled;\n\t};\n\tconst reportOperationFact = (\n\t\teventId: string,\n\t\toperationId: string,\n\t\toperationKind: string,\n\t\tstatus: OperationTerminalStatus,\n\t\townerTokens: readonly symbol[],\n\t): void => {\n\t\tif (ownerTokens.some((ownerToken) => !state.activeOwnerTokens.has(ownerToken))) return;\n\t\tconst data = {\n\t\t\tversion: 1 as const,\n\t\t\toperationId,\n\t\t\toperationKind,\n\t\t\tstatus,\n\t\t\t...(status === \"failed\" ? { errorMessage: \"operation failed\" } : {}),\n\t\t\t...(status === \"cancelled\" ? { reason: \"cancelled\" } : {}),\n\t\t};\n\t\tvoid dispatchLifecycle({\n\t\t\ttype: eventId,\n\t\t\tversion: 1,\n\t\t\tphase: \"committed\",\n\t\t\tsource: \"host\",\n\t\t\toperationId,\n\t\t\tcorrelationId: operationId,\n\t\t\tdata,\n\t\t}).catch(() => {});\n\t};\n\tconst reportOperationEnd = (\n\t\toperationId: string,\n\t\toperationKind: string,\n\t\tstatus: OperationTerminalStatus,\n\t\townerTokens: readonly symbol[],\n\t): void => {\n\t\treportOperationFact(OPERATION_END_EVENT_ID, operationId, operationKind, status, ownerTokens);\n\t};\n\t// operation.start fires when execution begins; operation.cancel fires at the\n\t// cancellation request, before the terminal operation.end fact. Both stay\n\t// within CapabilityAPI-registered operations and never carry input, results,\n\t// or caller cancellation reasons.\n\tconst reportOperationStart = (operationId: string, operationKind: string, ownerTokens: readonly symbol[]): void => {\n\t\tif (ownerTokens.some((ownerToken) => !state.activeOwnerTokens.has(ownerToken))) return;\n\t\tvoid dispatchLifecycle({\n\t\t\ttype: OPERATION_START_EVENT_ID,\n\t\t\tversion: 1,\n\t\t\tphase: \"committed\",\n\t\t\tsource: \"host\",\n\t\t\toperationId,\n\t\t\tcorrelationId: operationId,\n\t\t\tdata: { version: 1, operationId, operationKind },\n\t\t}).catch(() => {});\n\t};\n\tconst reportOperationStep = (\n\t\toperationId: string,\n\t\toperationKind: string,\n\t\townerTokens: readonly symbol[],\n\t\tprogress: OperationProgress,\n\t\tstep: number,\n\t): boolean => {\n\t\tif (\n\t\t\townerTokens.some((ownerToken) => !state.activeOwnerTokens.has(ownerToken)) ||\n\t\t\tstate.statuses.get(operationId) !== \"running\"\n\t\t) {\n\t\t\treturn false;\n\t\t}\n\t\tif (!progress || typeof progress !== \"object\" || Array.isArray(progress)) {\n\t\t\tthrow new Error(t(\"Operation progress must be an object\"));\n\t\t}\n\t\tif (progress.message !== undefined && (typeof progress.message !== \"string\" || !progress.message.trim())) {\n\t\t\tthrow new Error(t(\"Operation progress message must be a non-empty string\"));\n\t\t}\n\t\tif (progress.data !== undefined && !isPluginConfigValue(progress.data)) {\n\t\t\tthrow new Error(t(\"Operation progress data must be serializable\"));\n\t\t}\n\t\tvoid dispatchLifecycle({\n\t\t\ttype: OPERATION_STEP_EVENT_ID,\n\t\t\tversion: 1,\n\t\t\tphase: \"committed\",\n\t\t\tsource: \"host\",\n\t\t\toperationId,\n\t\t\tcorrelationId: operationId,\n\t\t\tdata: {\n\t\t\t\tversion: 1,\n\t\t\t\toperationId,\n\t\t\t\toperationKind,\n\t\t\t\tstep,\n\t\t\t\t...(progress.message === undefined ? {} : { message: progress.message }),\n\t\t\t\t...(progress.data === undefined ? {} : { data: detachedSnapshot(progress.data) }),\n\t\t\t},\n\t\t}).catch(() => {});\n\t\treturn true;\n\t};\n\tconst reportOperationCancel = (operationId: string, operationKind: string, ownerTokens: readonly symbol[]): void => {\n\t\tif (ownerTokens.some((ownerToken) => !state.activeOwnerTokens.has(ownerToken))) return;\n\t\tvoid dispatchLifecycle({\n\t\t\ttype: OPERATION_CANCEL_EVENT_ID,\n\t\t\tversion: 1,\n\t\t\tphase: \"committed\",\n\t\t\tsource: \"host\",\n\t\t\toperationId,\n\t\t\tcorrelationId: operationId,\n\t\t\tdata: { version: 1, operationId, operationKind },\n\t\t}).catch(() => {});\n\t};\n\tconst reportCapabilityCall = (\n\t\tevent: \"start\" | \"cancel\" | \"end\",\n\t\toperationId: string,\n\t\tcallerPluginId: string,\n\t\tcapability: RegisteredPluginCapability,\n\t\townerTokens: readonly symbol[],\n\t\tstatus?: OperationTerminalStatus,\n\t): void => {\n\t\tif (ownerTokens.some((ownerToken) => !state.activeOwnerTokens.has(ownerToken))) return;\n\t\tconst data = {\n\t\t\tversion: 1 as const,\n\t\t\tevent,\n\t\t\toperationId,\n\t\t\tcallerPluginId,\n\t\t\tcapabilityId: capability.declaration.id,\n\t\t\tcapabilityVersion: capability.declaration.version,\n\t\t\tcapabilityKind: capability.declaration.kind,\n\t\t\tproviderPluginId: capability.owner,\n\t\t\t...(status === undefined ? {} : { status }),\n\t\t};\n\t\tvoid dispatchLifecycle({\n\t\t\ttype: CAPABILITY_CALL_EVENT_ID,\n\t\t\tversion: CAPABILITY_CALL_EVENT_VERSION,\n\t\t\tphase: \"committed\",\n\t\t\tsource: \"host\",\n\t\t\toperationId,\n\t\t\tcorrelationId: operationId,\n\t\t\tdata,\n\t\t}).catch(() => {});\n\t};\n\n\treturn {\n\t\tdispatchLifecycle,\n\t\treportOperationEnd,\n\t\treportOperationStart,\n\t\treportOperationStep,\n\t\treportOperationCancel,\n\t\treportCapabilityCall,\n\t};\n}\n"]}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { t } from "../i18n/index.js";
|
|
1
2
|
import { isPluginConfigValue } from "./capability-runtime-manifest.js";
|
|
2
3
|
import { cancellationError } from "./capability-runtime-operation.js";
|
|
3
4
|
import { detachedSnapshot, lifecycleErrorSnapshot } from "./capability-runtime-snapshot.js";
|
|
@@ -56,23 +57,26 @@ export function createLifecycleRuntime(deps) {
|
|
|
56
57
|
};
|
|
57
58
|
const dispatchLifecycleImpl = async (request) => {
|
|
58
59
|
if (!request || typeof request !== "object")
|
|
59
|
-
throw new Error("Lifecycle dispatch request is required");
|
|
60
|
+
throw new Error(t("Lifecycle dispatch request is required"));
|
|
60
61
|
if (request.signal?.aborted)
|
|
61
62
|
throw cancellationError(request.signal.reason);
|
|
62
63
|
if (typeof request.type !== "string" || !request.type.trim()) {
|
|
63
|
-
throw new Error("Lifecycle dispatch requires a non-empty type");
|
|
64
|
+
throw new Error(t("Lifecycle dispatch requires a non-empty type"));
|
|
64
65
|
}
|
|
65
66
|
if (!Number.isSafeInteger(request.version) || request.version < 1) {
|
|
66
|
-
throw new Error("Lifecycle dispatch version must be a positive safe integer");
|
|
67
|
+
throw new Error(t("Lifecycle dispatch version must be a positive safe integer"));
|
|
67
68
|
}
|
|
68
69
|
if (!lifecyclePhases.has(request.phase))
|
|
69
|
-
throw new Error(
|
|
70
|
+
throw new Error(t("Lifecycle dispatch phase is invalid: {phase}", { phase: request.phase }));
|
|
70
71
|
const stored = state.lifecycleDefinitions.get(lifecycleEventKey(request.type, request.version));
|
|
71
72
|
if (!stored || !state.activeOwnerTokens.has(stored.ownerToken)) {
|
|
72
|
-
throw new Error(
|
|
73
|
+
throw new Error(t("Lifecycle event is not defined: {type}@{version}", { type: request.type, version: request.version }));
|
|
73
74
|
}
|
|
74
75
|
if (!(stored.definition.allowedPhases ?? [stored.definition.phase]).includes(request.phase)) {
|
|
75
|
-
throw new Error(
|
|
76
|
+
throw new Error(t("Lifecycle dispatch phase does not match event definition: {type}@{version}", {
|
|
77
|
+
type: request.type,
|
|
78
|
+
version: request.version,
|
|
79
|
+
}));
|
|
76
80
|
}
|
|
77
81
|
assertLifecycleDefinitionActive(stored);
|
|
78
82
|
const sequence = ++state.eventSequence;
|
|
@@ -80,17 +84,17 @@ export function createLifecycleRuntime(deps) {
|
|
|
80
84
|
const operationId = request.operationId;
|
|
81
85
|
const correlationId = request.correlationId ?? operationId;
|
|
82
86
|
if (operationId !== undefined && (typeof operationId !== "string" || !operationId.trim()))
|
|
83
|
-
throw new Error("Lifecycle operationId must be non-empty");
|
|
87
|
+
throw new Error(t("Lifecycle operationId must be non-empty"));
|
|
84
88
|
if (correlationId !== undefined && (typeof correlationId !== "string" || !correlationId.trim())) {
|
|
85
|
-
throw new Error("Lifecycle correlationId must be non-empty");
|
|
89
|
+
throw new Error(t("Lifecycle correlationId must be non-empty"));
|
|
86
90
|
}
|
|
87
91
|
if (request.causationId !== undefined &&
|
|
88
92
|
(typeof request.causationId !== "string" || !request.causationId.trim())) {
|
|
89
|
-
throw new Error("Lifecycle causationId must be non-empty");
|
|
93
|
+
throw new Error(t("Lifecycle causationId must be non-empty"));
|
|
90
94
|
}
|
|
91
95
|
const source = request.source ?? "host";
|
|
92
96
|
if (typeof source !== "string" || !source.trim())
|
|
93
|
-
throw new Error("Lifecycle source must be non-empty");
|
|
97
|
+
throw new Error(t("Lifecycle source must be non-empty"));
|
|
94
98
|
const validated = stored.definition.validate(detachedSnapshot(request.data));
|
|
95
99
|
assertLifecycleDefinitionActive(stored);
|
|
96
100
|
let data = detachedSnapshot(validated);
|
|
@@ -306,13 +310,13 @@ export function createLifecycleRuntime(deps) {
|
|
|
306
310
|
return false;
|
|
307
311
|
}
|
|
308
312
|
if (!progress || typeof progress !== "object" || Array.isArray(progress)) {
|
|
309
|
-
throw new Error("Operation progress must be an object");
|
|
313
|
+
throw new Error(t("Operation progress must be an object"));
|
|
310
314
|
}
|
|
311
315
|
if (progress.message !== undefined && (typeof progress.message !== "string" || !progress.message.trim())) {
|
|
312
|
-
throw new Error("Operation progress message must be a non-empty string");
|
|
316
|
+
throw new Error(t("Operation progress message must be a non-empty string"));
|
|
313
317
|
}
|
|
314
318
|
if (progress.data !== undefined && !isPluginConfigValue(progress.data)) {
|
|
315
|
-
throw new Error("Operation progress data must be serializable");
|
|
319
|
+
throw new Error(t("Operation progress data must be serializable"));
|
|
316
320
|
}
|
|
317
321
|
void dispatchLifecycle({
|
|
318
322
|
type: OPERATION_STEP_EVENT_ID,
|