@frontmcp/sdk 0.4.1 → 0.5.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/README.md +30 -18
- package/package.json +20 -5
- package/src/app/app.registry.d.ts +3 -2
- package/src/app/app.registry.js +3 -1
- package/src/app/app.registry.js.map +1 -1
- package/src/app/instances/app.local.instance.js +2 -2
- package/src/app/instances/app.local.instance.js.map +1 -1
- package/src/auth/auth.registry.d.ts +34 -2
- package/src/auth/auth.registry.js +162 -24
- package/src/auth/auth.registry.js.map +1 -1
- package/src/auth/auth.utils.js +8 -9
- package/src/auth/auth.utils.js.map +1 -1
- package/src/auth/authorization/authorization.class.d.ts +125 -0
- package/src/auth/authorization/authorization.class.js +224 -0
- package/src/auth/authorization/authorization.class.js.map +1 -0
- package/src/auth/authorization/authorization.types.d.ts +300 -0
- package/src/auth/authorization/authorization.types.js +79 -0
- package/src/auth/authorization/authorization.types.js.map +1 -0
- package/src/auth/authorization/index.d.ts +5 -0
- package/src/auth/authorization/index.js +19 -0
- package/src/auth/authorization/index.js.map +1 -0
- package/src/auth/authorization/orchestrated.authorization.d.ts +242 -0
- package/src/auth/authorization/orchestrated.authorization.js +306 -0
- package/src/auth/authorization/orchestrated.authorization.js.map +1 -0
- package/src/auth/authorization/public.authorization.d.ts +91 -0
- package/src/auth/authorization/public.authorization.js +132 -0
- package/src/auth/authorization/public.authorization.js.map +1 -0
- package/src/auth/authorization/transparent.authorization.d.ts +130 -0
- package/src/auth/authorization/transparent.authorization.js +147 -0
- package/src/auth/authorization/transparent.authorization.js.map +1 -0
- package/src/auth/consent/consent.types.d.ts +111 -0
- package/src/auth/consent/consent.types.js +119 -0
- package/src/auth/consent/consent.types.js.map +1 -0
- package/src/auth/consent/index.d.ts +1 -0
- package/src/auth/consent/index.js +13 -0
- package/src/auth/consent/index.js.map +1 -0
- package/src/auth/detection/auth-provider-detection.d.ts +84 -0
- package/src/auth/detection/auth-provider-detection.js +230 -0
- package/src/auth/detection/auth-provider-detection.js.map +1 -0
- package/src/auth/detection/index.d.ts +1 -0
- package/src/auth/detection/index.js +15 -0
- package/src/auth/detection/index.js.map +1 -0
- package/src/auth/flows/auth.verify.flow.d.ts +110 -0
- package/src/auth/flows/auth.verify.flow.js +379 -0
- package/src/auth/flows/auth.verify.flow.js.map +1 -0
- package/src/auth/flows/oauth.authorize.flow.d.ts +118 -164
- package/src/auth/flows/oauth.authorize.flow.js +701 -33
- package/src/auth/flows/oauth.authorize.flow.js.map +1 -1
- package/src/auth/flows/oauth.callback.flow.d.ts +117 -0
- package/src/auth/flows/oauth.callback.flow.js +357 -0
- package/src/auth/flows/oauth.callback.flow.js.map +1 -0
- package/src/auth/flows/oauth.register.flow.d.ts +32 -125
- package/src/auth/flows/oauth.token.flow.d.ts +52 -154
- package/src/auth/flows/oauth.token.flow.js +193 -55
- package/src/auth/flows/oauth.token.flow.js.map +1 -1
- package/src/auth/flows/session.verify.flow.d.ts +66 -321
- package/src/auth/flows/session.verify.flow.js +107 -18
- package/src/auth/flows/session.verify.flow.js.map +1 -1
- package/src/auth/flows/well-known.jwks.flow.d.ts +34 -205
- package/src/auth/flows/well-known.jwks.flow.js +15 -8
- package/src/auth/flows/well-known.jwks.flow.js.map +1 -1
- package/src/auth/flows/well-known.oauth-authorization-server.flow.d.ts +48 -223
- package/src/auth/flows/well-known.oauth-authorization-server.flow.js +2 -3
- package/src/auth/flows/well-known.oauth-authorization-server.flow.js.map +1 -1
- package/src/auth/flows/well-known.prm.flow.d.ts +19 -120
- package/src/auth/flows/well-known.prm.flow.js +3 -4
- package/src/auth/flows/well-known.prm.flow.js.map +1 -1
- package/src/auth/instances/instance.local-primary-auth.d.ts +91 -4
- package/src/auth/instances/instance.local-primary-auth.js +236 -6
- package/src/auth/instances/instance.local-primary-auth.js.map +1 -1
- package/src/auth/instances/instance.remote-primary-auth.d.ts +4 -3
- package/src/auth/instances/instance.remote-primary-auth.js +2 -2
- package/src/auth/instances/instance.remote-primary-auth.js.map +1 -1
- package/src/auth/session/authorization-vault.d.ts +611 -0
- package/src/auth/session/authorization-vault.js +817 -0
- package/src/auth/session/authorization-vault.js.map +1 -0
- package/src/auth/session/authorization.store.d.ts +301 -0
- package/src/auth/session/authorization.store.js +323 -0
- package/src/auth/session/authorization.store.js.map +1 -0
- package/src/auth/session/encrypted-authorization-vault.d.ts +181 -0
- package/src/auth/session/encrypted-authorization-vault.js +493 -0
- package/src/auth/session/encrypted-authorization-vault.js.map +1 -0
- package/src/auth/session/index.d.ts +4 -4
- package/src/auth/session/index.js +11 -7
- package/src/auth/session/index.js.map +1 -1
- package/src/auth/session/session.schema.d.ts +1 -1
- package/src/auth/session/session.service.d.ts +1 -1
- package/src/auth/session/transport-session.manager.d.ts +101 -0
- package/src/auth/session/transport-session.manager.js +300 -0
- package/src/auth/session/transport-session.manager.js.map +1 -0
- package/src/auth/session/transport-session.types.d.ts +457 -0
- package/src/auth/session/transport-session.types.js +110 -0
- package/src/auth/session/transport-session.types.js.map +1 -0
- package/src/auth/session/utils/session-id.utils.d.ts +14 -2
- package/src/auth/session/utils/session-id.utils.js +68 -19
- package/src/auth/session/utils/session-id.utils.js.map +1 -1
- package/src/auth/session/vault-encryption.d.ts +189 -0
- package/src/auth/session/vault-encryption.js +263 -0
- package/src/auth/session/vault-encryption.js.map +1 -0
- package/src/auth/ui/base-layout.d.ts +188 -0
- package/src/auth/ui/base-layout.js +292 -0
- package/src/auth/ui/base-layout.js.map +1 -0
- package/src/auth/ui/htmx-templates.d.ts +135 -0
- package/src/auth/ui/htmx-templates.js +433 -0
- package/src/auth/ui/htmx-templates.js.map +1 -0
- package/src/auth/ui/index.d.ts +11 -0
- package/src/auth/ui/index.js +35 -0
- package/src/auth/ui/index.js.map +1 -0
- package/src/auth/utils/audience.validator.d.ts +129 -0
- package/src/auth/utils/audience.validator.js +196 -0
- package/src/auth/utils/audience.validator.js.map +1 -0
- package/src/auth/utils/index.d.ts +2 -0
- package/src/auth/utils/index.js +7 -0
- package/src/auth/utils/index.js.map +1 -0
- package/src/auth/utils/www-authenticate.utils.d.ts +97 -0
- package/src/auth/utils/www-authenticate.utils.js +183 -0
- package/src/auth/utils/www-authenticate.utils.js.map +1 -0
- package/src/common/common.schema.d.ts +2 -16
- package/src/common/constants.d.ts +3 -0
- package/src/common/constants.js +6 -1
- package/src/common/constants.js.map +1 -1
- package/src/common/decorators/decorator-utils.d.ts +131 -0
- package/src/common/decorators/decorator-utils.js +195 -0
- package/src/common/decorators/decorator-utils.js.map +1 -0
- package/src/common/decorators/front-mcp.decorator.js +3 -2
- package/src/common/decorators/front-mcp.decorator.js.map +1 -1
- package/src/common/decorators/hook.decorator.d.ts +58 -2
- package/src/common/decorators/hook.decorator.js +127 -17
- package/src/common/decorators/hook.decorator.js.map +1 -1
- package/src/common/decorators/plugin.decorator.d.ts +1 -1
- package/src/common/decorators/plugin.decorator.js +11 -10
- package/src/common/decorators/plugin.decorator.js.map +1 -1
- package/src/common/decorators/resource.decorator.d.ts +32 -3
- package/src/common/decorators/resource.decorator.js +46 -4
- package/src/common/decorators/resource.decorator.js.map +1 -1
- package/src/common/decorators/tool.decorator.d.ts +54 -5
- package/src/common/decorators/tool.decorator.js.map +1 -1
- package/src/common/dynamic/dynamic.plugin.d.ts +22 -11
- package/src/common/dynamic/dynamic.plugin.js +7 -1
- package/src/common/dynamic/dynamic.plugin.js.map +1 -1
- package/src/common/entries/prompt.entry.d.ts +46 -2
- package/src/common/entries/prompt.entry.js +10 -0
- package/src/common/entries/prompt.entry.js.map +1 -1
- package/src/common/entries/resource.entry.d.ts +69 -6
- package/src/common/entries/resource.entry.js +27 -3
- package/src/common/entries/resource.entry.js.map +1 -1
- package/src/common/entries/scope.entry.d.ts +5 -1
- package/src/common/entries/scope.entry.js +3 -3
- package/src/common/entries/scope.entry.js.map +1 -1
- package/src/common/flow/flow.utils.d.ts +56 -0
- package/src/common/flow/flow.utils.js +96 -0
- package/src/common/flow/flow.utils.js.map +1 -0
- package/src/common/index.d.ts +2 -2
- package/src/common/index.js +2 -2
- package/src/common/index.js.map +1 -1
- package/src/common/interfaces/execution-context.interface.d.ts +59 -0
- package/src/common/interfaces/execution-context.interface.js +81 -0
- package/src/common/interfaces/execution-context.interface.js.map +1 -0
- package/src/common/interfaces/flow.interface.d.ts +1 -1
- package/src/common/interfaces/flow.interface.js.map +1 -1
- package/src/common/interfaces/index.d.ts +1 -0
- package/src/common/interfaces/index.js +1 -0
- package/src/common/interfaces/index.js.map +1 -1
- package/src/common/interfaces/internal/primary-auth-provider.interface.d.ts +17 -2
- package/src/common/interfaces/internal/primary-auth-provider.interface.js +52 -4
- package/src/common/interfaces/internal/primary-auth-provider.interface.js.map +1 -1
- package/src/common/interfaces/internal/registry.interface.d.ts +16 -2
- package/src/common/interfaces/internal/registry.interface.js.map +1 -1
- package/src/common/interfaces/plugin.interface.js.map +1 -1
- package/src/common/interfaces/prompt.interface.d.ts +53 -4
- package/src/common/interfaces/prompt.interface.js +78 -0
- package/src/common/interfaces/prompt.interface.js.map +1 -1
- package/src/common/interfaces/resource.interface.d.ts +47 -17
- package/src/common/interfaces/resource.interface.js +53 -0
- package/src/common/interfaces/resource.interface.js.map +1 -1
- package/src/common/interfaces/tool.interface.d.ts +39 -22
- package/src/common/interfaces/tool.interface.js +61 -34
- package/src/common/interfaces/tool.interface.js.map +1 -1
- package/src/common/metadata/adapter.metadata.d.ts +1 -9
- package/src/common/metadata/app.metadata.d.ts +425 -730
- package/src/common/metadata/auth-provider.metadata.d.ts +2 -12
- package/src/common/metadata/flow.metadata.d.ts +10 -25
- package/src/common/metadata/front-mcp.metadata.d.ts +602 -1023
- package/src/common/metadata/front-mcp.metadata.js +6 -4
- package/src/common/metadata/front-mcp.metadata.js.map +1 -1
- package/src/common/metadata/hook.metadata.d.ts +1 -1
- package/src/common/metadata/hook.metadata.js.map +1 -1
- package/src/common/metadata/index.d.ts +1 -0
- package/src/common/metadata/index.js +1 -0
- package/src/common/metadata/index.js.map +1 -1
- package/src/common/metadata/logger.metadata.d.ts +1 -9
- package/src/common/metadata/plugin.metadata.d.ts +8 -30
- package/src/common/metadata/prompt.metadata.d.ts +4 -161
- package/src/common/metadata/provider.metadata.d.ts +2 -12
- package/src/common/metadata/resource.metadata.d.ts +6 -98
- package/src/common/metadata/resource.metadata.js +15 -6
- package/src/common/metadata/resource.metadata.js.map +1 -1
- package/src/common/metadata/tool-ui.metadata.d.ts +10 -0
- package/src/common/metadata/tool-ui.metadata.js +12 -0
- package/src/common/metadata/tool-ui.metadata.js.map +1 -0
- package/src/common/metadata/tool.metadata.d.ts +78 -199
- package/src/common/metadata/tool.metadata.js +11 -14
- package/src/common/metadata/tool.metadata.js.map +1 -1
- package/src/common/providers/base-config.provider.d.ts +84 -0
- package/src/common/providers/base-config.provider.js +128 -0
- package/src/common/providers/base-config.provider.js.map +1 -0
- package/src/common/records/plugin.record.d.ts +5 -6
- package/src/common/records/plugin.record.js.map +1 -1
- package/src/common/records/prompt.record.js.map +1 -1
- package/src/common/records/resource.record.d.ts +17 -1
- package/src/common/records/resource.record.js +12 -6
- package/src/common/records/resource.record.js.map +1 -1
- package/src/common/records/tool.record.js.map +1 -1
- package/src/common/schemas/annotated-class.schema.d.ts +9 -9
- package/src/common/schemas/annotated-class.schema.js +92 -27
- package/src/common/schemas/annotated-class.schema.js.map +1 -1
- package/src/common/schemas/http-input.schema.d.ts +6 -30
- package/src/common/schemas/http-output.schema.d.ts +326 -1630
- package/src/common/schemas/http-output.schema.js +39 -1
- package/src/common/schemas/http-output.schema.js.map +1 -1
- package/src/common/tokens/front-mcp.tokens.js +4 -1
- package/src/common/tokens/front-mcp.tokens.js.map +1 -1
- package/src/common/tokens/resource.tokens.d.ts +2 -0
- package/src/common/tokens/resource.tokens.js +4 -1
- package/src/common/tokens/resource.tokens.js.map +1 -1
- package/src/common/tokens/tool.tokens.d.ts +2 -0
- package/src/common/tokens/tool.tokens.js +2 -0
- package/src/common/tokens/tool.tokens.js.map +1 -1
- package/src/common/types/auth/jwt.types.d.ts +5 -31
- package/src/common/types/auth/session.types.d.ts +97 -192
- package/src/common/types/auth/session.types.js +24 -11
- package/src/common/types/auth/session.types.js.map +1 -1
- package/src/common/types/options/auth.options.d.ts +1013 -490
- package/src/common/types/options/auth.options.js +554 -36
- package/src/common/types/options/auth.options.js.map +1 -1
- package/src/common/types/options/http.options.d.ts +1 -9
- package/src/common/types/options/logging.options.d.ts +7 -13
- package/src/common/types/options/logging.options.js +4 -0
- package/src/common/types/options/logging.options.js.map +1 -1
- package/src/common/types/options/server-info.options.d.ts +3 -31
- package/src/common/types/options/session.options.d.ts +90 -10
- package/src/common/types/options/session.options.js +26 -3
- package/src/common/types/options/session.options.js.map +1 -1
- package/src/common/utils/decide-request-intent.utils.d.ts +8 -46
- package/src/common/utils/decide-request-intent.utils.js +88 -23
- package/src/common/utils/decide-request-intent.utils.js.map +1 -1
- package/src/completion/flows/complete.flow.d.ts +74 -0
- package/src/completion/flows/complete.flow.js +199 -0
- package/src/completion/flows/complete.flow.js.map +1 -0
- package/src/errors/authorization-required.error.d.ts +189 -0
- package/src/errors/authorization-required.error.js +274 -0
- package/src/errors/authorization-required.error.js.map +1 -0
- package/src/errors/index.d.ts +2 -1
- package/src/errors/index.js +17 -1
- package/src/errors/index.js.map +1 -1
- package/src/errors/mcp.error.d.ts +101 -1
- package/src/errors/mcp.error.js +147 -2
- package/src/errors/mcp.error.js.map +1 -1
- package/src/flows/flow.instance.js +4 -3
- package/src/flows/flow.instance.js.map +1 -1
- package/src/flows/flow.registry.js.map +1 -1
- package/src/flows/flow.stages.js +14 -11
- package/src/flows/flow.stages.js.map +1 -1
- package/src/front-mcp/front-mcp.providers.d.ts +464 -102
- package/src/front-mcp/front-mcp.providers.js +3 -5
- package/src/front-mcp/front-mcp.providers.js.map +1 -1
- package/src/hooks/hook.instance.d.ts +1 -1
- package/src/hooks/hook.instance.js +5 -2
- package/src/hooks/hook.instance.js.map +1 -1
- package/src/hooks/hook.registry.js +7 -5
- package/src/hooks/hook.registry.js.map +1 -1
- package/src/index.d.ts +28 -9
- package/src/index.js +5 -1
- package/src/index.js.map +1 -1
- package/src/logger/instances/instance.logger.js +3 -2
- package/src/logger/instances/instance.logger.js.map +1 -1
- package/src/logger/logger.registry.js +7 -2
- package/src/logger/logger.registry.js.map +1 -1
- package/src/logging/flows/set-level.flow.d.ts +62 -0
- package/src/logging/flows/set-level.flow.js +108 -0
- package/src/logging/flows/set-level.flow.js.map +1 -0
- package/src/mcp-apps/csp.d.ts +111 -0
- package/src/mcp-apps/csp.js +267 -0
- package/src/mcp-apps/csp.js.map +1 -0
- package/src/mcp-apps/index.d.ts +23 -0
- package/src/mcp-apps/index.js +91 -0
- package/src/mcp-apps/index.js.map +1 -0
- package/src/mcp-apps/schemas.d.ts +403 -0
- package/src/mcp-apps/schemas.js +345 -0
- package/src/mcp-apps/schemas.js.map +1 -0
- package/src/mcp-apps/template.d.ts +94 -0
- package/src/mcp-apps/template.js +419 -0
- package/src/mcp-apps/template.js.map +1 -0
- package/src/mcp-apps/types.d.ts +323 -0
- package/src/mcp-apps/types.js +59 -0
- package/src/mcp-apps/types.js.map +1 -0
- package/src/notification/index.d.ts +1 -0
- package/src/notification/index.js +13 -0
- package/src/notification/index.js.map +1 -0
- package/src/notification/notification.service.d.ts +378 -0
- package/src/notification/notification.service.js +727 -0
- package/src/notification/notification.service.js.map +1 -0
- package/src/plugin/plugin.registry.js +12 -9
- package/src/plugin/plugin.registry.js.map +1 -1
- package/src/prompt/flows/get-prompt.flow.d.ts +153 -0
- package/src/prompt/flows/get-prompt.flow.js +214 -0
- package/src/prompt/flows/get-prompt.flow.js.map +1 -0
- package/src/prompt/flows/prompts-list.flow.d.ts +67 -0
- package/src/prompt/flows/prompts-list.flow.js +176 -0
- package/src/prompt/flows/prompts-list.flow.js.map +1 -0
- package/src/prompt/index.d.ts +7 -0
- package/src/prompt/index.js +17 -0
- package/src/prompt/index.js.map +1 -0
- package/src/prompt/prompt.events.d.ts +17 -0
- package/src/prompt/prompt.events.js +25 -0
- package/src/prompt/prompt.events.js.map +1 -0
- package/src/prompt/prompt.instance.d.ts +30 -0
- package/src/prompt/prompt.instance.js +120 -0
- package/src/prompt/prompt.instance.js.map +1 -0
- package/src/prompt/prompt.registry.d.ts +79 -12
- package/src/prompt/prompt.registry.js +360 -15
- package/src/prompt/prompt.registry.js.map +1 -1
- package/src/prompt/prompt.types.d.ts +26 -0
- package/src/prompt/prompt.types.js +11 -0
- package/src/prompt/prompt.types.js.map +1 -0
- package/src/prompt/prompt.utils.d.ts +26 -0
- package/src/prompt/prompt.utils.js +136 -0
- package/src/prompt/prompt.utils.js.map +1 -0
- package/src/provider/provider.registry.d.ts +12 -5
- package/src/provider/provider.registry.js +30 -138
- package/src/provider/provider.registry.js.map +1 -1
- package/src/regsitry/registry.base.d.ts +1 -1
- package/src/regsitry/registry.base.js.map +1 -1
- package/src/resource/flows/read-resource.flow.d.ts +91 -0
- package/src/resource/flows/read-resource.flow.js +270 -0
- package/src/resource/flows/read-resource.flow.js.map +1 -0
- package/src/resource/flows/resource-templates-list.flow.d.ts +64 -0
- package/src/resource/flows/resource-templates-list.flow.js +191 -0
- package/src/resource/flows/resource-templates-list.flow.js.map +1 -0
- package/src/resource/flows/resources-list.flow.d.ts +64 -0
- package/src/resource/flows/resources-list.flow.js +196 -0
- package/src/resource/flows/resources-list.flow.js.map +1 -0
- package/src/resource/flows/subscribe-resource.flow.d.ts +45 -0
- package/src/resource/flows/subscribe-resource.flow.js +123 -0
- package/src/resource/flows/subscribe-resource.flow.js.map +1 -0
- package/src/resource/flows/unsubscribe-resource.flow.d.ts +44 -0
- package/src/resource/flows/unsubscribe-resource.flow.js +107 -0
- package/src/resource/flows/unsubscribe-resource.flow.js.map +1 -0
- package/src/resource/index.d.ts +8 -0
- package/src/resource/index.js +20 -0
- package/src/resource/index.js.map +1 -0
- package/src/resource/resource.events.d.ts +24 -0
- package/src/resource/resource.events.js +17 -0
- package/src/resource/resource.events.js.map +1 -0
- package/src/resource/resource.instance.d.ts +35 -0
- package/src/resource/resource.instance.js +163 -0
- package/src/resource/resource.instance.js.map +1 -0
- package/src/resource/resource.registry.d.ts +106 -12
- package/src/resource/resource.registry.js +449 -13
- package/src/resource/resource.registry.js.map +1 -1
- package/src/resource/resource.types.d.ts +35 -0
- package/src/resource/resource.types.js +11 -0
- package/src/resource/resource.types.js.map +1 -0
- package/src/resource/resource.utils.d.ts +30 -0
- package/src/resource/resource.utils.js +151 -0
- package/src/resource/resource.utils.js.map +1 -0
- package/src/scope/flows/http.request.flow.d.ts +48 -330
- package/src/scope/flows/http.request.flow.js +306 -78
- package/src/scope/flows/http.request.flow.js.map +1 -1
- package/src/scope/scope.instance.d.ts +12 -0
- package/src/scope/scope.instance.js +145 -15
- package/src/scope/scope.instance.js.map +1 -1
- package/src/tool/flows/call-tool.flow.d.ts +64 -1110
- package/src/tool/flows/call-tool.flow.js +303 -15
- package/src/tool/flows/call-tool.flow.js.map +1 -1
- package/src/tool/flows/tools-list.flow.d.ts +32 -473
- package/src/tool/flows/tools-list.flow.js +121 -40
- package/src/tool/flows/tools-list.flow.js.map +1 -1
- package/src/tool/tool.events.d.ts +8 -1
- package/src/tool/tool.events.js.map +1 -1
- package/src/tool/tool.instance.d.ts +3 -1
- package/src/tool/tool.instance.js +17 -3
- package/src/tool/tool.instance.js.map +1 -1
- package/src/tool/tool.registry.d.ts +7 -1
- package/src/tool/tool.registry.js +26 -10
- package/src/tool/tool.registry.js.map +1 -1
- package/src/tool/tool.types.d.ts +4 -4
- package/src/tool/tool.types.js.map +1 -1
- package/src/tool/tool.utils.d.ts +3 -12
- package/src/tool/tool.utils.js +39 -193
- package/src/tool/tool.utils.js.map +1 -1
- package/src/tool/ui/index.d.ts +22 -0
- package/src/tool/ui/index.js +63 -0
- package/src/tool/ui/index.js.map +1 -0
- package/src/tool/ui/platform-adapters.d.ts +10 -0
- package/src/tool/ui/platform-adapters.js +18 -0
- package/src/tool/ui/platform-adapters.js.map +1 -0
- package/src/tool/ui/template-helpers.d.ts +46 -0
- package/src/tool/ui/template-helpers.js +112 -0
- package/src/tool/ui/template-helpers.js.map +1 -0
- package/src/tool/ui/ui-resource-template.d.ts +34 -0
- package/src/tool/ui/ui-resource-template.js +64 -0
- package/src/tool/ui/ui-resource-template.js.map +1 -0
- package/src/tool/ui/ui-resource.handler.d.ts +74 -0
- package/src/tool/ui/ui-resource.handler.js +129 -0
- package/src/tool/ui/ui-resource.handler.js.map +1 -0
- package/src/transport/adapters/transport.local.adapter.d.ts +2 -2
- package/src/transport/adapters/transport.local.adapter.js +28 -7
- package/src/transport/adapters/transport.local.adapter.js.map +1 -1
- package/src/transport/adapters/transport.sse.adapter.d.ts +2 -2
- package/src/transport/adapters/transport.sse.adapter.js +4 -3
- package/src/transport/adapters/transport.sse.adapter.js.map +1 -1
- package/src/transport/adapters/transport.streamable-http.adapter.d.ts +10 -3
- package/src/transport/adapters/transport.streamable-http.adapter.js +54 -8
- package/src/transport/adapters/transport.streamable-http.adapter.js.map +1 -1
- package/src/transport/flows/handle.sse.flow.d.ts +29 -63
- package/src/transport/flows/handle.sse.flow.js +78 -10
- package/src/transport/flows/handle.sse.flow.js.map +1 -1
- package/src/transport/flows/handle.stateless-http.flow.d.ts +29 -0
- package/src/transport/flows/handle.stateless-http.flow.js +102 -0
- package/src/transport/flows/handle.stateless-http.flow.js.map +1 -0
- package/src/transport/flows/handle.streamable-http.flow.d.ts +32 -64
- package/src/transport/flows/handle.streamable-http.flow.js +158 -26
- package/src/transport/flows/handle.streamable-http.flow.js.map +1 -1
- package/src/transport/legacy/legacy.sse.tranporter.d.ts +9 -0
- package/src/transport/legacy/legacy.sse.tranporter.js +17 -2
- package/src/transport/legacy/legacy.sse.tranporter.js.map +1 -1
- package/src/transport/mcp-handlers/call-tool-request.handler.js +27 -1
- package/src/transport/mcp-handlers/call-tool-request.handler.js.map +1 -1
- package/src/transport/mcp-handlers/complete-request.handler.d.ts +69 -0
- package/src/transport/mcp-handlers/complete-request.handler.js +11 -0
- package/src/transport/mcp-handlers/complete-request.handler.js.map +1 -0
- package/src/transport/mcp-handlers/get-prompt-request.handler.d.ts +87 -0
- package/src/transport/mcp-handlers/get-prompt-request.handler.js +11 -0
- package/src/transport/mcp-handlers/get-prompt-request.handler.js.map +1 -0
- package/src/transport/mcp-handlers/index.d.ts +517 -208
- package/src/transport/mcp-handlers/index.js +39 -2
- package/src/transport/mcp-handlers/index.js.map +1 -1
- package/src/transport/mcp-handlers/initialize-request.handler.d.ts +1 -1
- package/src/transport/mcp-handlers/initialize-request.handler.js +73 -7
- package/src/transport/mcp-handlers/initialize-request.handler.js.map +1 -1
- package/src/transport/mcp-handlers/list-prompts-request.handler.d.ts +54 -0
- package/src/transport/mcp-handlers/list-prompts-request.handler.js +11 -0
- package/src/transport/mcp-handlers/list-prompts-request.handler.js.map +1 -0
- package/src/transport/mcp-handlers/list-resource-templates-request.handler.d.ts +51 -0
- package/src/transport/mcp-handlers/list-resource-templates-request.handler.js +12 -0
- package/src/transport/mcp-handlers/list-resource-templates-request.handler.js.map +1 -0
- package/src/transport/mcp-handlers/list-resources-request.handler.d.ts +51 -0
- package/src/transport/mcp-handlers/list-resources-request.handler.js +12 -0
- package/src/transport/mcp-handlers/list-resources-request.handler.js.map +1 -0
- package/src/transport/mcp-handlers/list-tools-request.handler.d.ts +19 -146
- package/src/transport/mcp-handlers/logging-set-level-request.handler.d.ts +46 -0
- package/src/transport/mcp-handlers/logging-set-level-request.handler.js +34 -0
- package/src/transport/mcp-handlers/logging-set-level-request.handler.js.map +1 -0
- package/src/transport/mcp-handlers/mcp-handlers.types.d.ts +3 -7
- package/src/transport/mcp-handlers/mcp-handlers.types.js.map +1 -1
- package/src/transport/mcp-handlers/read-resource-request.handler.d.ts +46 -0
- package/src/transport/mcp-handlers/read-resource-request.handler.js +12 -0
- package/src/transport/mcp-handlers/read-resource-request.handler.js.map +1 -0
- package/src/transport/mcp-handlers/roots-list-changed-notification.handler.d.ts +11 -0
- package/src/transport/mcp-handlers/roots-list-changed-notification.handler.js +26 -0
- package/src/transport/mcp-handlers/roots-list-changed-notification.handler.js.map +1 -0
- package/src/transport/mcp-handlers/subscribe-request.handler.d.ts +37 -0
- package/src/transport/mcp-handlers/subscribe-request.handler.js +34 -0
- package/src/transport/mcp-handlers/subscribe-request.handler.js.map +1 -0
- package/src/transport/mcp-handlers/unsubscribe-request.handler.d.ts +37 -0
- package/src/transport/mcp-handlers/unsubscribe-request.handler.js +34 -0
- package/src/transport/mcp-handlers/unsubscribe-request.handler.js.map +1 -0
- package/src/transport/transport.local.js +7 -2
- package/src/transport/transport.local.js.map +1 -1
- package/src/transport/transport.registry.d.ts +30 -0
- package/src/transport/transport.registry.js +84 -1
- package/src/transport/transport.registry.js.map +1 -1
- package/src/transport/transport.types.d.ts +3 -3
- package/src/transport/transport.types.js.map +1 -1
- package/src/utils/content.utils.d.ts +48 -0
- package/src/utils/content.utils.js +194 -0
- package/src/utils/content.utils.js.map +1 -0
- package/src/utils/index.d.ts +8 -0
- package/src/utils/index.js +55 -0
- package/src/utils/index.js.map +1 -0
- package/src/utils/lineage.utils.d.ts +40 -0
- package/src/utils/lineage.utils.js +82 -0
- package/src/utils/lineage.utils.js.map +1 -0
- package/src/utils/naming.utils.d.ts +46 -0
- package/src/utils/naming.utils.js +136 -0
- package/src/utils/naming.utils.js.map +1 -0
- package/src/utils/types.utils.d.ts +2 -2
- package/src/utils/types.utils.js.map +1 -1
- package/src/utils/uri-template.utils.d.ts +57 -0
- package/src/utils/uri-template.utils.js +113 -0
- package/src/utils/uri-template.utils.js.map +1 -0
- package/src/utils/uri-validation.utils.d.ts +40 -0
- package/src/utils/uri-validation.utils.js +76 -0
- package/src/utils/uri-validation.utils.js.map +1 -0
- package/src/__test-utils__/fixtures/hook.fixtures.d.ts +0 -46
- package/src/__test-utils__/fixtures/hook.fixtures.js +0 -114
- package/src/__test-utils__/fixtures/hook.fixtures.js.map +0 -1
- package/src/__test-utils__/fixtures/index.d.ts +0 -7
- package/src/__test-utils__/fixtures/index.js +0 -11
- package/src/__test-utils__/fixtures/index.js.map +0 -1
- package/src/__test-utils__/fixtures/plugin.fixtures.d.ts +0 -46
- package/src/__test-utils__/fixtures/plugin.fixtures.js +0 -127
- package/src/__test-utils__/fixtures/plugin.fixtures.js.map +0 -1
- package/src/__test-utils__/fixtures/provider.fixtures.d.ts +0 -69
- package/src/__test-utils__/fixtures/provider.fixtures.js +0 -131
- package/src/__test-utils__/fixtures/provider.fixtures.js.map +0 -1
- package/src/__test-utils__/fixtures/scope.fixtures.d.ts +0 -14
- package/src/__test-utils__/fixtures/scope.fixtures.js +0 -59
- package/src/__test-utils__/fixtures/scope.fixtures.js.map +0 -1
- package/src/__test-utils__/fixtures/tool.fixtures.d.ts +0 -36
- package/src/__test-utils__/fixtures/tool.fixtures.js +0 -91
- package/src/__test-utils__/fixtures/tool.fixtures.js.map +0 -1
- package/src/__test-utils__/helpers/assertion.helpers.d.ts +0 -45
- package/src/__test-utils__/helpers/assertion.helpers.js +0 -153
- package/src/__test-utils__/helpers/assertion.helpers.js.map +0 -1
- package/src/__test-utils__/helpers/async.helpers.d.ts +0 -48
- package/src/__test-utils__/helpers/async.helpers.js +0 -112
- package/src/__test-utils__/helpers/async.helpers.js.map +0 -1
- package/src/__test-utils__/helpers/index.d.ts +0 -6
- package/src/__test-utils__/helpers/index.js +0 -10
- package/src/__test-utils__/helpers/index.js.map +0 -1
- package/src/__test-utils__/helpers/setup.helpers.d.ts +0 -54
- package/src/__test-utils__/helpers/setup.helpers.js +0 -106
- package/src/__test-utils__/helpers/setup.helpers.js.map +0 -1
- package/src/__test-utils__/index.d.ts +0 -9
- package/src/__test-utils__/index.js +0 -14
- package/src/__test-utils__/index.js.map +0 -1
- package/src/__test-utils__/mocks/flow-instance.mock.d.ts +0 -50
- package/src/__test-utils__/mocks/flow-instance.mock.js +0 -72
- package/src/__test-utils__/mocks/flow-instance.mock.js.map +0 -1
- package/src/__test-utils__/mocks/hook-registry.mock.d.ts +0 -25
- package/src/__test-utils__/mocks/hook-registry.mock.js +0 -65
- package/src/__test-utils__/mocks/hook-registry.mock.js.map +0 -1
- package/src/__test-utils__/mocks/index.d.ts +0 -8
- package/src/__test-utils__/mocks/index.js +0 -12
- package/src/__test-utils__/mocks/index.js.map +0 -1
- package/src/__test-utils__/mocks/plugin-registry.mock.d.ts +0 -43
- package/src/__test-utils__/mocks/plugin-registry.mock.js +0 -70
- package/src/__test-utils__/mocks/plugin-registry.mock.js.map +0 -1
- package/src/__test-utils__/mocks/provider-registry.mock.d.ts +0 -39
- package/src/__test-utils__/mocks/provider-registry.mock.js +0 -72
- package/src/__test-utils__/mocks/provider-registry.mock.js.map +0 -1
- package/src/__test-utils__/mocks/tool-registry.mock.d.ts +0 -43
- package/src/__test-utils__/mocks/tool-registry.mock.js +0 -79
- package/src/__test-utils__/mocks/tool-registry.mock.js.map +0 -1
- package/src/auth/path.utils.d.ts +0 -20
- package/src/auth/path.utils.js +0 -71
- package/src/auth/path.utils.js.map +0 -1
- package/src/common/decorators-old/async-with.decorator.d.ts +0 -10
- package/src/common/decorators-old/async-with.decorator.js +0 -24
- package/src/common/decorators-old/async-with.decorator.js.map +0 -1
- package/src/common/decorators-old/auth-hook.decorator.d.ts +0 -14
- package/src/common/decorators-old/auth-hook.decorator.js +0 -27
- package/src/common/decorators-old/auth-hook.decorator.js.map +0 -1
- package/src/common/decorators-old/session-hook.decorator.d.ts +0 -14
- package/src/common/decorators-old/session-hook.decorator.js +0 -27
- package/src/common/decorators-old/session-hook.decorator.js.map +0 -1
|
@@ -1,3 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP-specific error codes per JSON-RPC specification.
|
|
3
|
+
* These codes are used in the JSON-RPC error response format.
|
|
4
|
+
*/
|
|
5
|
+
export declare const MCP_ERROR_CODES: {
|
|
6
|
+
/** Resource not found (-32002) */
|
|
7
|
+
readonly RESOURCE_NOT_FOUND: -32002;
|
|
8
|
+
/** Invalid request (-32600) */
|
|
9
|
+
readonly INVALID_REQUEST: -32600;
|
|
10
|
+
/** Method not found (-32601) */
|
|
11
|
+
readonly METHOD_NOT_FOUND: -32601;
|
|
12
|
+
/** Invalid params (-32602) */
|
|
13
|
+
readonly INVALID_PARAMS: -32602;
|
|
14
|
+
/** Internal error (-32603) */
|
|
15
|
+
readonly INTERNAL_ERROR: -32603;
|
|
16
|
+
/** Parse error (-32700) */
|
|
17
|
+
readonly PARSE_ERROR: -32700;
|
|
18
|
+
};
|
|
19
|
+
export type McpErrorCode = (typeof MCP_ERROR_CODES)[keyof typeof MCP_ERROR_CODES];
|
|
1
20
|
/**
|
|
2
21
|
* Base class for all MCP-related errors
|
|
3
22
|
*/
|
|
@@ -68,11 +87,50 @@ export declare class InternalMcpError extends McpError {
|
|
|
68
87
|
getPublicMessage(): string;
|
|
69
88
|
}
|
|
70
89
|
/**
|
|
71
|
-
* Tool
|
|
90
|
+
* Tool not found error
|
|
72
91
|
*/
|
|
73
92
|
export declare class ToolNotFoundError extends PublicMcpError {
|
|
74
93
|
constructor(toolName: string);
|
|
75
94
|
}
|
|
95
|
+
/**
|
|
96
|
+
* Resource not found error
|
|
97
|
+
*/
|
|
98
|
+
export declare class ResourceNotFoundError extends PublicMcpError {
|
|
99
|
+
readonly uri: string;
|
|
100
|
+
readonly mcpErrorCode: -32002;
|
|
101
|
+
constructor(uri: string);
|
|
102
|
+
/**
|
|
103
|
+
* Convert to JSON-RPC error format per MCP specification.
|
|
104
|
+
*
|
|
105
|
+
* @example
|
|
106
|
+
* {
|
|
107
|
+
* "code": -32002,
|
|
108
|
+
* "message": "Resource not found: file:///missing.txt",
|
|
109
|
+
* "data": { "uri": "file:///missing.txt" }
|
|
110
|
+
* }
|
|
111
|
+
*/
|
|
112
|
+
toJsonRpcError(): {
|
|
113
|
+
code: number;
|
|
114
|
+
message: string;
|
|
115
|
+
data?: {
|
|
116
|
+
uri: string;
|
|
117
|
+
};
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Resource read error (internal)
|
|
122
|
+
*/
|
|
123
|
+
export declare class ResourceReadError extends InternalMcpError {
|
|
124
|
+
readonly originalError?: Error;
|
|
125
|
+
constructor(uri: string, originalError?: Error);
|
|
126
|
+
getInternalMessage(): string;
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Invalid resource URI error
|
|
130
|
+
*/
|
|
131
|
+
export declare class InvalidResourceUriError extends PublicMcpError {
|
|
132
|
+
constructor(uri: string, reason?: string);
|
|
133
|
+
}
|
|
76
134
|
/**
|
|
77
135
|
* Invalid input validation error
|
|
78
136
|
*/
|
|
@@ -130,6 +188,48 @@ export declare class GenericServerError extends InternalMcpError {
|
|
|
130
188
|
constructor(message: string, originalError?: Error);
|
|
131
189
|
getInternalMessage(): string;
|
|
132
190
|
}
|
|
191
|
+
/**
|
|
192
|
+
* Dependency not found error (internal) - thrown when a required dependency
|
|
193
|
+
* is not found in a registry during initialization.
|
|
194
|
+
*/
|
|
195
|
+
export declare class DependencyNotFoundError extends InternalMcpError {
|
|
196
|
+
constructor(registryName: string, dependencyName: string);
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Invalid hook flow error - thrown when a hook is registered with a flow
|
|
200
|
+
* that is not supported by the entry type (e.g., tool hook on resource class).
|
|
201
|
+
*/
|
|
202
|
+
export declare class InvalidHookFlowError extends InternalMcpError {
|
|
203
|
+
constructor(message: string);
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Auth configuration error - thrown when auth configuration is invalid
|
|
207
|
+
* (e.g., transparent mode on parent with multiple child providers).
|
|
208
|
+
*/
|
|
209
|
+
export declare class AuthConfigurationError extends PublicMcpError {
|
|
210
|
+
readonly errors: string[];
|
|
211
|
+
readonly suggestion?: string;
|
|
212
|
+
constructor(message: string, options?: {
|
|
213
|
+
errors?: string[];
|
|
214
|
+
suggestion?: string;
|
|
215
|
+
});
|
|
216
|
+
getPublicMessage(): string;
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Prompt not found error.
|
|
220
|
+
*/
|
|
221
|
+
export declare class PromptNotFoundError extends PublicMcpError {
|
|
222
|
+
constructor(promptName: string);
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Prompt execution error - wraps errors during prompt execution.
|
|
226
|
+
*/
|
|
227
|
+
export declare class PromptExecutionError extends InternalMcpError {
|
|
228
|
+
readonly promptName: string;
|
|
229
|
+
readonly originalError?: Error;
|
|
230
|
+
constructor(promptName: string, cause?: Error);
|
|
231
|
+
getInternalMessage(): string;
|
|
232
|
+
}
|
|
133
233
|
/**
|
|
134
234
|
* Check if the error is a public error that can be safely shown to users
|
|
135
235
|
*/
|
package/src/errors/mcp.error.js
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.GenericServerError = exports.UnauthorizedError = exports.QuotaExceededError = exports.RateLimitError = exports.ToolExecutionError = exports.InvalidMethodError = exports.InvalidOutputError = exports.InvalidInputError = exports.ToolNotFoundError = exports.InternalMcpError = exports.PublicMcpError = exports.McpError = void 0;
|
|
3
|
+
exports.PromptExecutionError = exports.PromptNotFoundError = exports.AuthConfigurationError = exports.InvalidHookFlowError = exports.DependencyNotFoundError = exports.GenericServerError = exports.UnauthorizedError = exports.QuotaExceededError = exports.RateLimitError = exports.ToolExecutionError = exports.InvalidMethodError = exports.InvalidOutputError = exports.InvalidInputError = exports.InvalidResourceUriError = exports.ResourceReadError = exports.ResourceNotFoundError = exports.ToolNotFoundError = exports.InternalMcpError = exports.PublicMcpError = exports.McpError = exports.MCP_ERROR_CODES = void 0;
|
|
4
4
|
exports.isPublicError = isPublicError;
|
|
5
5
|
exports.toMcpError = toMcpError;
|
|
6
6
|
exports.formatMcpErrorResponse = formatMcpErrorResponse;
|
|
7
7
|
// errors/mcp.error.ts
|
|
8
8
|
const crypto_1 = require("crypto");
|
|
9
|
+
/**
|
|
10
|
+
* MCP-specific error codes per JSON-RPC specification.
|
|
11
|
+
* These codes are used in the JSON-RPC error response format.
|
|
12
|
+
*/
|
|
13
|
+
exports.MCP_ERROR_CODES = {
|
|
14
|
+
/** Resource not found (-32002) */
|
|
15
|
+
RESOURCE_NOT_FOUND: -32002,
|
|
16
|
+
/** Invalid request (-32600) */
|
|
17
|
+
INVALID_REQUEST: -32600,
|
|
18
|
+
/** Method not found (-32601) */
|
|
19
|
+
METHOD_NOT_FOUND: -32601,
|
|
20
|
+
/** Invalid params (-32602) */
|
|
21
|
+
INVALID_PARAMS: -32602,
|
|
22
|
+
/** Internal error (-32603) */
|
|
23
|
+
INTERNAL_ERROR: -32603,
|
|
24
|
+
/** Parse error (-32700) */
|
|
25
|
+
PARSE_ERROR: -32700,
|
|
26
|
+
};
|
|
9
27
|
/**
|
|
10
28
|
* Base class for all MCP-related errors
|
|
11
29
|
*/
|
|
@@ -91,7 +109,7 @@ exports.InternalMcpError = InternalMcpError;
|
|
|
91
109
|
// Specific Error Classes
|
|
92
110
|
// ============================================================================
|
|
93
111
|
/**
|
|
94
|
-
* Tool
|
|
112
|
+
* Tool not found error
|
|
95
113
|
*/
|
|
96
114
|
class ToolNotFoundError extends PublicMcpError {
|
|
97
115
|
constructor(toolName) {
|
|
@@ -99,6 +117,61 @@ class ToolNotFoundError extends PublicMcpError {
|
|
|
99
117
|
}
|
|
100
118
|
}
|
|
101
119
|
exports.ToolNotFoundError = ToolNotFoundError;
|
|
120
|
+
/**
|
|
121
|
+
* Resource not found error
|
|
122
|
+
*/
|
|
123
|
+
class ResourceNotFoundError extends PublicMcpError {
|
|
124
|
+
uri;
|
|
125
|
+
mcpErrorCode = exports.MCP_ERROR_CODES.RESOURCE_NOT_FOUND;
|
|
126
|
+
constructor(uri) {
|
|
127
|
+
super(`Resource not found: ${uri}`, 'RESOURCE_NOT_FOUND', 404);
|
|
128
|
+
this.uri = uri;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Convert to JSON-RPC error format per MCP specification.
|
|
132
|
+
*
|
|
133
|
+
* @example
|
|
134
|
+
* {
|
|
135
|
+
* "code": -32002,
|
|
136
|
+
* "message": "Resource not found: file:///missing.txt",
|
|
137
|
+
* "data": { "uri": "file:///missing.txt" }
|
|
138
|
+
* }
|
|
139
|
+
*/
|
|
140
|
+
toJsonRpcError() {
|
|
141
|
+
return {
|
|
142
|
+
code: this.mcpErrorCode,
|
|
143
|
+
message: this.getPublicMessage(),
|
|
144
|
+
data: { uri: this.uri },
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
exports.ResourceNotFoundError = ResourceNotFoundError;
|
|
149
|
+
/**
|
|
150
|
+
* Resource read error (internal)
|
|
151
|
+
*/
|
|
152
|
+
class ResourceReadError extends InternalMcpError {
|
|
153
|
+
originalError;
|
|
154
|
+
constructor(uri, originalError) {
|
|
155
|
+
super(`Resource "${uri}" read failed: ${originalError?.message || 'Unknown error'}`, 'RESOURCE_READ_ERROR');
|
|
156
|
+
this.originalError = originalError;
|
|
157
|
+
}
|
|
158
|
+
getInternalMessage() {
|
|
159
|
+
if (this.originalError?.stack) {
|
|
160
|
+
return `${this.message}\n\nOriginal error:\n${this.originalError.stack}`;
|
|
161
|
+
}
|
|
162
|
+
return this.message;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
exports.ResourceReadError = ResourceReadError;
|
|
166
|
+
/**
|
|
167
|
+
* Invalid resource URI error
|
|
168
|
+
*/
|
|
169
|
+
class InvalidResourceUriError extends PublicMcpError {
|
|
170
|
+
constructor(uri, reason) {
|
|
171
|
+
super(`Invalid resource URI: ${uri}${reason ? ` (${reason})` : ''}`, 'INVALID_RESOURCE_URI', 400);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
exports.InvalidResourceUriError = InvalidResourceUriError;
|
|
102
175
|
/**
|
|
103
176
|
* Invalid input validation error
|
|
104
177
|
*/
|
|
@@ -212,6 +285,78 @@ class GenericServerError extends InternalMcpError {
|
|
|
212
285
|
}
|
|
213
286
|
}
|
|
214
287
|
exports.GenericServerError = GenericServerError;
|
|
288
|
+
/**
|
|
289
|
+
* Dependency not found error (internal) - thrown when a required dependency
|
|
290
|
+
* is not found in a registry during initialization.
|
|
291
|
+
*/
|
|
292
|
+
class DependencyNotFoundError extends InternalMcpError {
|
|
293
|
+
constructor(registryName, dependencyName) {
|
|
294
|
+
super(`Dependency "${dependencyName}" not found in ${registryName}`, 'DEPENDENCY_NOT_FOUND');
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
exports.DependencyNotFoundError = DependencyNotFoundError;
|
|
298
|
+
/**
|
|
299
|
+
* Invalid hook flow error - thrown when a hook is registered with a flow
|
|
300
|
+
* that is not supported by the entry type (e.g., tool hook on resource class).
|
|
301
|
+
*/
|
|
302
|
+
class InvalidHookFlowError extends InternalMcpError {
|
|
303
|
+
constructor(message) {
|
|
304
|
+
super(message, 'INVALID_HOOK_FLOW');
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
exports.InvalidHookFlowError = InvalidHookFlowError;
|
|
308
|
+
/**
|
|
309
|
+
* Auth configuration error - thrown when auth configuration is invalid
|
|
310
|
+
* (e.g., transparent mode on parent with multiple child providers).
|
|
311
|
+
*/
|
|
312
|
+
class AuthConfigurationError extends PublicMcpError {
|
|
313
|
+
errors;
|
|
314
|
+
suggestion;
|
|
315
|
+
constructor(message, options) {
|
|
316
|
+
super(message, 'AUTH_CONFIGURATION_ERROR', 500);
|
|
317
|
+
this.errors = options?.errors ?? [message];
|
|
318
|
+
this.suggestion = options?.suggestion;
|
|
319
|
+
}
|
|
320
|
+
getPublicMessage() {
|
|
321
|
+
let msg = this.message;
|
|
322
|
+
if (this.suggestion) {
|
|
323
|
+
msg += `\n\nTo fix this issue:\n${this.suggestion}`;
|
|
324
|
+
}
|
|
325
|
+
return msg;
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
exports.AuthConfigurationError = AuthConfigurationError;
|
|
329
|
+
// ============================================================================
|
|
330
|
+
// Prompt Errors
|
|
331
|
+
// ============================================================================
|
|
332
|
+
/**
|
|
333
|
+
* Prompt not found error.
|
|
334
|
+
*/
|
|
335
|
+
class PromptNotFoundError extends PublicMcpError {
|
|
336
|
+
constructor(promptName) {
|
|
337
|
+
super(`Prompt not found: ${promptName}`, 'PROMPT_NOT_FOUND', 404);
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
exports.PromptNotFoundError = PromptNotFoundError;
|
|
341
|
+
/**
|
|
342
|
+
* Prompt execution error - wraps errors during prompt execution.
|
|
343
|
+
*/
|
|
344
|
+
class PromptExecutionError extends InternalMcpError {
|
|
345
|
+
promptName;
|
|
346
|
+
originalError;
|
|
347
|
+
constructor(promptName, cause) {
|
|
348
|
+
super(cause ? `Prompt execution failed: ${cause.message}` : `Prompt execution failed: ${promptName}`, 'PROMPT_EXECUTION_FAILED');
|
|
349
|
+
this.promptName = promptName;
|
|
350
|
+
this.originalError = cause;
|
|
351
|
+
}
|
|
352
|
+
getInternalMessage() {
|
|
353
|
+
if (this.originalError?.stack) {
|
|
354
|
+
return `${this.message}\n\nOriginal error:\n${this.originalError.stack}`;
|
|
355
|
+
}
|
|
356
|
+
return this.message;
|
|
357
|
+
}
|
|
358
|
+
}
|
|
359
|
+
exports.PromptExecutionError = PromptExecutionError;
|
|
215
360
|
// ============================================================================
|
|
216
361
|
// Error Utilities
|
|
217
362
|
// ============================================================================
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.error.js","sourceRoot":"","sources":["../../../src/errors/mcp.error.ts"],"names":[],"mappings":";;;AAuQA,sCAEC;AAKD,gCAUC;AAKD,wDAGC;AAhSD,sBAAsB;AACtB,mCAAqC;AAErC;;GAEG;AACH,MAAsB,QAAS,SAAQ,KAAK;IAC1C;;OAEG;IACH,OAAO,CAAS;IAiBhB,YAAsB,OAAe,EAAE,OAAgB;QACrD,KAAK,CAAC,OAAO,CAAC,CAAC;QACf,IAAI,CAAC,IA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kB;AAClB,+EAA+E;AAE/E;;GAEG;AACH,SAAgB,aAAa,CAAC,KAAU;IACtC,OAAO,KAAK,YAAY,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC;AACrD,CAAC;AAED;;GAEG;AACH,SAAgB,UAAU,CAAC,KAAU;IACnC,IAAI,KAAK,YAAY,QAAQ,EAAE,CAAC;QAC9B,OAAO,KAAK,CAAC;IACf,CAAC;IAED,IAAI,KAAK,YAAY,KAAK,EAAE,CAAC;QAC3B,OAAO,IAAI,kBAAkB,CAAC,KAAK,CAAC,OAAO,EAAE,KAAK,CAAC,CAAC;IACtD,CAAC;IAED,OAAO,IAAI,kBAAkB,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC;AAC/C,CAAC;AAED;;GAEG;AACH,SAAgB,sBAAsB,CAAC,KAAU,EAAE,gBAAyB,OAAO,CAAC,GAAG,CAAC,UAAU,CAAC,KAAK,YAAY;IAClH,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;IACnC,OAAO,QAAQ,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["// errors/mcp.error.ts\nimport { randomBytes } from 'crypto';\n\n/**\n * Base class for all MCP-related errors\n */\nexport abstract class McpError extends Error {\n /**\n * Unique error ID for tracking in logs\n */\n errorId: string;\n\n /**\n * Whether this error should expose details to the client\n */\n abstract readonly isPublic: boolean;\n\n /**\n * HTTP status code equivalent (for reference)\n */\n abstract readonly statusCode: number;\n\n /**\n * Error code for categorization\n */\n abstract readonly code: string;\n\n protected constructor(message: string, errorId?: string) {\n super(message);\n this.name = this.constructor.name;\n this.errorId = errorId || this.generateErrorId();\n Error.captureStackTrace(this, this.constructor);\n }\n\n private generateErrorId(): string {\n return `err_${randomBytes(8).toString('hex')}`;\n }\n\n /**\n * Get the public-facing error message\n */\n abstract getPublicMessage(): string;\n\n /**\n * Get the internal error message (for logging)\n */\n getInternalMessage(): string {\n return this.message;\n }\n\n /**\n * Convert to MCP error response format\n */\n toMcpError(isDevelopment = false): {\n content: Array<{ type: 'text'; text: string }>;\n isError: true;\n _meta?: {\n errorId: string;\n code: string;\n timestamp: string;\n stack?: string;\n };\n } {\n const message = isDevelopment ? this.getInternalMessage() : this.getPublicMessage();\n\n return {\n content: [\n {\n type: 'text',\n text: message,\n },\n ],\n isError: true,\n _meta: {\n errorId: this.errorId,\n code: this.code,\n timestamp: new Date().toISOString(),\n ...(isDevelopment && { stack: this.stack }),\n },\n };\n }\n}\n\n/**\n * Public errors - safe to expose to clients\n * These include validation errors, not found errors, etc.\n */\nexport class PublicMcpError extends McpError {\n readonly isPublic = true;\n readonly statusCode: number;\n readonly code: string;\n\n constructor(message: string, code = 'PUBLIC_ERROR', statusCode = 400) {\n super(message);\n this.code = code;\n this.statusCode = statusCode;\n }\n\n getPublicMessage(): string {\n return this.message;\n }\n}\n\n/**\n * Internal errors - should not expose details to clients\n * These are server errors, unexpected failures, etc.\n */\nexport class InternalMcpError extends McpError {\n readonly isPublic = false;\n readonly statusCode = 500;\n readonly code: string;\n\n constructor(message: string, code = 'INTERNAL_ERROR') {\n super(message);\n this.code = code;\n }\n\n getPublicMessage(): string {\n return `Internal FrontMCP error. Please contact support with error ID: ${this.errorId}`;\n }\n}\n\n// ============================================================================\n// Specific Error Classes\n// ============================================================================\n\n/**\n * Tool didn't find an error\n */\nexport class ToolNotFoundError extends PublicMcpError {\n constructor(toolName: string) {\n super(`Tool \"${toolName}\" not found`, 'TOOL_NOT_FOUND', 404);\n }\n}\n\n/**\n * Invalid input validation error\n */\nexport class InvalidInputError extends PublicMcpError {\n readonly validationErrors?: any;\n\n constructor(message = 'Invalid input: validation failed', validationErrors?: any) {\n super(message, 'INVALID_INPUT', 400);\n this.validationErrors = validationErrors;\n }\n\n override getInternalMessage(): string {\n return this.message + (this.validationErrors ? `\\nDetails: ${JSON.stringify(this.validationErrors, null, 2)}` : '');\n }\n override getPublicMessage(): string {\n if (this.validationErrors) {\n return `${this.message}\\nDetails: ${JSON.stringify(this.validationErrors, null, 2)}`;\n }\n return this.message;\n }\n}\n\n/**\n * Invalid output validation error (internal - don't expose schema details)\n */\nexport class InvalidOutputError extends InternalMcpError {\n private readonly hasCustomErrorId: boolean;\n\n constructor(errorId?: string) {\n super('Tool output validation failed', 'INVALID_OUTPUT');\n this.hasCustomErrorId = !!errorId;\n if (errorId) {\n this.errorId = errorId;\n }\n }\n\n override getPublicMessage(): string {\n // If a custom errorId was provided (e.g., request ID), include it for correlation\n // Otherwise, use a simpler message since the auto-generated ID isn't meaningful to users\n if (this.hasCustomErrorId) {\n return `Output validation failed. Please contact support with error ID: ${this.errorId}`;\n }\n return 'Output validation failed. Please contact support.';\n }\n}\n\n/**\n * Invalid method error\n */\nexport class InvalidMethodError extends PublicMcpError {\n constructor(method: string, expected: string) {\n super(`Invalid method \"${method}\". Expected \"${expected}\"`, 'INVALID_METHOD', 400);\n }\n}\n\n/**\n * Tool execution error (internal)\n */\nexport class ToolExecutionError extends InternalMcpError {\n readonly originalError?: Error;\n\n constructor(toolName: string, originalError?: Error) {\n super(`Tool \"${toolName}\" execution failed: ${originalError?.message || 'Unknown error'}`, 'TOOL_EXECUTION_ERROR');\n this.originalError = originalError;\n }\n\n override getInternalMessage(): string {\n if (this.originalError?.stack) {\n return `${this.message}\\n\\nOriginal error:\\n${this.originalError.stack}`;\n }\n return this.message;\n }\n}\n\n/**\n * Rate limit error\n */\nexport class RateLimitError extends PublicMcpError {\n constructor(retryAfter?: number) {\n const message = retryAfter ? `Rate limit exceeded. Retry after ${retryAfter} seconds` : 'Rate limit exceeded';\n super(message, 'RATE_LIMIT_EXCEEDED', 429);\n }\n}\n\n/**\n * Quota exceeded error\n */\nexport class QuotaExceededError extends PublicMcpError {\n constructor(quotaType = 'usage') {\n super(`${quotaType} quota exceeded`, 'QUOTA_EXCEEDED', 429);\n }\n}\n\n/**\n * Unauthorized error\n */\nexport class UnauthorizedError extends PublicMcpError {\n constructor(message = 'Unauthorized') {\n super(message, 'UNAUTHORIZED', 401);\n }\n}\n\n/**\n * Generic server error wrapper\n */\nexport class GenericServerError extends InternalMcpError {\n readonly originalError?: Error;\n\n constructor(message: string, originalError?: Error) {\n super(message, 'SERVER_ERROR');\n this.originalError = originalError;\n }\n\n override getInternalMessage(): string {\n if (this.originalError?.stack) {\n return `${this.message}\\n\\nOriginal error:\\n${this.originalError.stack}`;\n }\n return this.message;\n }\n}\n\n// ============================================================================\n// Error Utilities\n// ============================================================================\n\n/**\n * Check if the error is a public error that can be safely shown to users\n */\nexport function isPublicError(error: any): error is PublicMcpError {\n return error instanceof McpError && error.isPublic;\n}\n\n/**\n * Convert any error to an MCP error\n */\nexport function toMcpError(error: any): McpError {\n if (error instanceof McpError) {\n return error;\n }\n\n if (error instanceof Error) {\n return new GenericServerError(error.message, error);\n }\n\n return new GenericServerError(String(error));\n}\n\n/**\n * Format error for MCP response\n */\nexport function formatMcpErrorResponse(error: any, isDevelopment: boolean = process.env['NODE_ENV'] !== 'production') {\n const mcpError = toMcpError(error);\n return mcpError.toMcpError(isDevelopment);\n}\n"]}
|
|
1
|
+
{"version":3,"file":"mcp.error.js","sourceRoot":"","sources":["../../../src/errors/mcp.error.ts"],"names":[],"mappings":";;;AA2aA,sCAEC;AAKD,gCAUC;AAKD,wDAGC;AApcD,sBAAsB;AACtB,mCAAqC;AAErC;;;GAGG;AACU,QAAA,eAAe,GAAG;IAC7B,kCAAkC;IAClC,kBAAkB,EAAE,CAAC,KAAK;IAC1B,+BAA+B;IAC/B,eAAe,EAAE,CAAC,KAAK;IACvB,gCAAgC;IAChC,gBAAgB,EAAE,CAAC,KAAK;IACxB,8BAA8B;IAC9B,cAAc,EAAE,CAAC,KAAK;IACtB,8BAA8B;IAC9B,cAAc,EAAE,CAAC,KAAK;IACtB,2BAA2B;IAC3B,WAAW,EAAE,CAAC,KAAK;CACX,CAAC;AAIX;;GAEG;AACH,MAAsB,QAAS,SAAQ,KAAK;IAC1C;;OAEG;IACH,OAAO,CAAS;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AAa,CAAC,CAAC;AAC5C,CAAC","sourcesContent":["// errors/mcp.error.ts\nimport { randomBytes } from 'crypto';\n\n/**\n * MCP-specific error codes per JSON-RPC specification.\n * These codes are used in the JSON-RPC error response format.\n */\nexport const MCP_ERROR_CODES = {\n /** Resource not found (-32002) */\n RESOURCE_NOT_FOUND: -32002,\n /** Invalid request (-32600) */\n INVALID_REQUEST: -32600,\n /** Method not found (-32601) */\n METHOD_NOT_FOUND: -32601,\n /** Invalid params (-32602) */\n INVALID_PARAMS: -32602,\n /** Internal error (-32603) */\n INTERNAL_ERROR: -32603,\n /** Parse error (-32700) */\n PARSE_ERROR: -32700,\n} as const;\n\nexport type McpErrorCode = (typeof MCP_ERROR_CODES)[keyof typeof MCP_ERROR_CODES];\n\n/**\n * Base class for all MCP-related errors\n */\nexport abstract class McpError extends Error {\n /**\n * Unique error ID for tracking in logs\n */\n errorId: string;\n\n /**\n * Whether this error should expose details to the client\n */\n abstract readonly isPublic: boolean;\n\n /**\n * HTTP status code equivalent (for reference)\n */\n abstract readonly statusCode: number;\n\n /**\n * Error code for categorization\n */\n abstract readonly code: string;\n\n protected constructor(message: string, errorId?: string) {\n super(message);\n this.name = this.constructor.name;\n this.errorId = errorId || this.generateErrorId();\n Error.captureStackTrace(this, this.constructor);\n }\n\n private generateErrorId(): string {\n return `err_${randomBytes(8).toString('hex')}`;\n }\n\n /**\n * Get the public-facing error message\n */\n abstract getPublicMessage(): string;\n\n /**\n * Get the internal error message (for logging)\n */\n getInternalMessage(): string {\n return this.message;\n }\n\n /**\n * Convert to MCP error response format\n */\n toMcpError(isDevelopment = false): {\n content: Array<{ type: 'text'; text: string }>;\n isError: true;\n _meta?: {\n errorId: string;\n code: string;\n timestamp: string;\n stack?: string;\n };\n } {\n const message = isDevelopment ? this.getInternalMessage() : this.getPublicMessage();\n\n return {\n content: [\n {\n type: 'text',\n text: message,\n },\n ],\n isError: true,\n _meta: {\n errorId: this.errorId,\n code: this.code,\n timestamp: new Date().toISOString(),\n ...(isDevelopment && { stack: this.stack }),\n },\n };\n }\n}\n\n/**\n * Public errors - safe to expose to clients\n * These include validation errors, not found errors, etc.\n */\nexport class PublicMcpError extends McpError {\n readonly isPublic = true;\n readonly statusCode: number;\n readonly code: string;\n\n constructor(message: string, code = 'PUBLIC_ERROR', statusCode = 400) {\n super(message);\n this.code = code;\n this.statusCode = statusCode;\n }\n\n getPublicMessage(): string {\n return this.message;\n }\n}\n\n/**\n * Internal errors - should not expose details to clients\n * These are server errors, unexpected failures, etc.\n */\nexport class InternalMcpError extends McpError {\n readonly isPublic = false;\n readonly statusCode = 500;\n readonly code: string;\n\n constructor(message: string, code = 'INTERNAL_ERROR') {\n super(message);\n this.code = code;\n }\n\n getPublicMessage(): string {\n return `Internal FrontMCP error. Please contact support with error ID: ${this.errorId}`;\n }\n}\n\n// ============================================================================\n// Specific Error Classes\n// ============================================================================\n\n/**\n * Tool not found error\n */\nexport class ToolNotFoundError extends PublicMcpError {\n constructor(toolName: string) {\n super(`Tool \"${toolName}\" not found`, 'TOOL_NOT_FOUND', 404);\n }\n}\n\n/**\n * Resource not found error\n */\nexport class ResourceNotFoundError extends PublicMcpError {\n readonly uri: string;\n readonly mcpErrorCode = MCP_ERROR_CODES.RESOURCE_NOT_FOUND;\n\n constructor(uri: string) {\n super(`Resource not found: ${uri}`, 'RESOURCE_NOT_FOUND', 404);\n this.uri = uri;\n }\n\n /**\n * Convert to JSON-RPC error format per MCP specification.\n *\n * @example\n * {\n * \"code\": -32002,\n * \"message\": \"Resource not found: file:///missing.txt\",\n * \"data\": { \"uri\": \"file:///missing.txt\" }\n * }\n */\n toJsonRpcError(): {\n code: number;\n message: string;\n data?: { uri: string };\n } {\n return {\n code: this.mcpErrorCode,\n message: this.getPublicMessage(),\n data: { uri: this.uri },\n };\n }\n}\n\n/**\n * Resource read error (internal)\n */\nexport class ResourceReadError extends InternalMcpError {\n readonly originalError?: Error;\n\n constructor(uri: string, originalError?: Error) {\n super(`Resource \"${uri}\" read failed: ${originalError?.message || 'Unknown error'}`, 'RESOURCE_READ_ERROR');\n this.originalError = originalError;\n }\n\n override getInternalMessage(): string {\n if (this.originalError?.stack) {\n return `${this.message}\\n\\nOriginal error:\\n${this.originalError.stack}`;\n }\n return this.message;\n }\n}\n\n/**\n * Invalid resource URI error\n */\nexport class InvalidResourceUriError extends PublicMcpError {\n constructor(uri: string, reason?: string) {\n super(`Invalid resource URI: ${uri}${reason ? ` (${reason})` : ''}`, 'INVALID_RESOURCE_URI', 400);\n }\n}\n\n/**\n * Invalid input validation error\n */\nexport class InvalidInputError extends PublicMcpError {\n readonly validationErrors?: any;\n\n constructor(message = 'Invalid input: validation failed', validationErrors?: any) {\n super(message, 'INVALID_INPUT', 400);\n this.validationErrors = validationErrors;\n }\n\n override getInternalMessage(): string {\n return this.message + (this.validationErrors ? `\\nDetails: ${JSON.stringify(this.validationErrors, null, 2)}` : '');\n }\n override getPublicMessage(): string {\n if (this.validationErrors) {\n return `${this.message}\\nDetails: ${JSON.stringify(this.validationErrors, null, 2)}`;\n }\n return this.message;\n }\n}\n\n/**\n * Invalid output validation error (internal - don't expose schema details)\n */\nexport class InvalidOutputError extends InternalMcpError {\n private readonly hasCustomErrorId: boolean;\n\n constructor(errorId?: string) {\n super('Tool output validation failed', 'INVALID_OUTPUT');\n this.hasCustomErrorId = !!errorId;\n if (errorId) {\n this.errorId = errorId;\n }\n }\n\n override getPublicMessage(): string {\n // If a custom errorId was provided (e.g., request ID), include it for correlation\n // Otherwise, use a simpler message since the auto-generated ID isn't meaningful to users\n if (this.hasCustomErrorId) {\n return `Output validation failed. Please contact support with error ID: ${this.errorId}`;\n }\n return 'Output validation failed. Please contact support.';\n }\n}\n\n/**\n * Invalid method error\n */\nexport class InvalidMethodError extends PublicMcpError {\n constructor(method: string, expected: string) {\n super(`Invalid method \"${method}\". Expected \"${expected}\"`, 'INVALID_METHOD', 400);\n }\n}\n\n/**\n * Tool execution error (internal)\n */\nexport class ToolExecutionError extends InternalMcpError {\n readonly originalError?: Error;\n\n constructor(toolName: string, originalError?: Error) {\n super(`Tool \"${toolName}\" execution failed: ${originalError?.message || 'Unknown error'}`, 'TOOL_EXECUTION_ERROR');\n this.originalError = originalError;\n }\n\n override getInternalMessage(): string {\n if (this.originalError?.stack) {\n return `${this.message}\\n\\nOriginal error:\\n${this.originalError.stack}`;\n }\n return this.message;\n }\n}\n\n/**\n * Rate limit error\n */\nexport class RateLimitError extends PublicMcpError {\n constructor(retryAfter?: number) {\n const message = retryAfter ? `Rate limit exceeded. Retry after ${retryAfter} seconds` : 'Rate limit exceeded';\n super(message, 'RATE_LIMIT_EXCEEDED', 429);\n }\n}\n\n/**\n * Quota exceeded error\n */\nexport class QuotaExceededError extends PublicMcpError {\n constructor(quotaType = 'usage') {\n super(`${quotaType} quota exceeded`, 'QUOTA_EXCEEDED', 429);\n }\n}\n\n/**\n * Unauthorized error\n */\nexport class UnauthorizedError extends PublicMcpError {\n constructor(message = 'Unauthorized') {\n super(message, 'UNAUTHORIZED', 401);\n }\n}\n\n/**\n * Generic server error wrapper\n */\nexport class GenericServerError extends InternalMcpError {\n readonly originalError?: Error;\n\n constructor(message: string, originalError?: Error) {\n super(message, 'SERVER_ERROR');\n this.originalError = originalError;\n }\n\n override getInternalMessage(): string {\n if (this.originalError?.stack) {\n return `${this.message}\\n\\nOriginal error:\\n${this.originalError.stack}`;\n }\n return this.message;\n }\n}\n\n/**\n * Dependency not found error (internal) - thrown when a required dependency\n * is not found in a registry during initialization.\n */\nexport class DependencyNotFoundError extends InternalMcpError {\n constructor(registryName: string, dependencyName: string) {\n super(`Dependency \"${dependencyName}\" not found in ${registryName}`, 'DEPENDENCY_NOT_FOUND');\n }\n}\n\n/**\n * Invalid hook flow error - thrown when a hook is registered with a flow\n * that is not supported by the entry type (e.g., tool hook on resource class).\n */\nexport class InvalidHookFlowError extends InternalMcpError {\n constructor(message: string) {\n super(message, 'INVALID_HOOK_FLOW');\n }\n}\n\n/**\n * Auth configuration error - thrown when auth configuration is invalid\n * (e.g., transparent mode on parent with multiple child providers).\n */\nexport class AuthConfigurationError extends PublicMcpError {\n readonly errors: string[];\n readonly suggestion?: string;\n\n constructor(message: string, options?: { errors?: string[]; suggestion?: string }) {\n super(message, 'AUTH_CONFIGURATION_ERROR', 500);\n this.errors = options?.errors ?? [message];\n this.suggestion = options?.suggestion;\n }\n\n override getPublicMessage(): string {\n let msg = this.message;\n if (this.suggestion) {\n msg += `\\n\\nTo fix this issue:\\n${this.suggestion}`;\n }\n return msg;\n }\n}\n\n// ============================================================================\n// Prompt Errors\n// ============================================================================\n\n/**\n * Prompt not found error.\n */\nexport class PromptNotFoundError extends PublicMcpError {\n constructor(promptName: string) {\n super(`Prompt not found: ${promptName}`, 'PROMPT_NOT_FOUND', 404);\n }\n}\n\n/**\n * Prompt execution error - wraps errors during prompt execution.\n */\nexport class PromptExecutionError extends InternalMcpError {\n readonly promptName: string;\n readonly originalError?: Error;\n\n constructor(promptName: string, cause?: Error) {\n super(\n cause ? `Prompt execution failed: ${cause.message}` : `Prompt execution failed: ${promptName}`,\n 'PROMPT_EXECUTION_FAILED',\n );\n this.promptName = promptName;\n this.originalError = cause;\n }\n\n override getInternalMessage(): string {\n if (this.originalError?.stack) {\n return `${this.message}\\n\\nOriginal error:\\n${this.originalError.stack}`;\n }\n return this.message;\n }\n}\n\n// ============================================================================\n// Error Utilities\n// ============================================================================\n\n/**\n * Check if the error is a public error that can be safely shown to users\n */\nexport function isPublicError(error: any): error is PublicMcpError {\n return error instanceof McpError && error.isPublic;\n}\n\n/**\n * Convert any error to an MCP error\n */\nexport function toMcpError(error: any): McpError {\n if (error instanceof McpError) {\n return error;\n }\n\n if (error instanceof Error) {\n return new GenericServerError(error.message, error);\n }\n\n return new GenericServerError(String(error));\n}\n\n/**\n * Format error for MCP response\n */\nexport function formatMcpErrorResponse(error: any, isDevelopment: boolean = process.env['NODE_ENV'] !== 'production') {\n const mcpError = toMcpError(error);\n return mcpError.toMcpError(isDevelopment);\n}\n"]}
|
|
@@ -67,8 +67,8 @@ class FlowInstance extends common_1.FlowEntry {
|
|
|
67
67
|
return (0, server_validation_1.writeHttpResponse)(response, e.output);
|
|
68
68
|
}
|
|
69
69
|
}
|
|
70
|
-
//
|
|
71
|
-
|
|
70
|
+
// Skip console.error due to Node.js 24 util.inspect bug with Zod validation errors
|
|
71
|
+
// The error will be returned to the client as a 500 response
|
|
72
72
|
return (0, server_validation_1.writeHttpResponse)(response, {
|
|
73
73
|
kind: 'text',
|
|
74
74
|
status: 500,
|
|
@@ -115,8 +115,9 @@ class FlowInstance extends common_1.FlowEntry {
|
|
|
115
115
|
metas.push(h.metadata);
|
|
116
116
|
}
|
|
117
117
|
catch (e) {
|
|
118
|
+
// Use safe logging to avoid Node.js 24 util.inspect bug with Zod errors
|
|
118
119
|
// eslint-disable-next-line no-console
|
|
119
|
-
console.warn('[flow] Ignoring injected hook that failed to materialize:', e);
|
|
120
|
+
console.warn('[flow] Ignoring injected hook that failed to materialize:', e instanceof Error ? e.message : 'Unknown error');
|
|
120
121
|
}
|
|
121
122
|
}
|
|
122
123
|
if (metas.length) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow.instance.js","sourceRoot":"","sources":["../../../src/flows/flow.instance.ts"],"names":[],"mappings":";AAAA,wCAAwC;AACxC,yBAAyB;;;AAEzB,4BAA0B;AAC1B,sCAiBmB;AAEnB,+CAAwG;AACxG,mEAAgE;AAYhE,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACrE,MAAM,IAAI,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;AAC5C,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,EAAE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AC;YAEzB,OAAO,SAAS,CAAC;QACnB,CAAC;QAAC,OAAO,CAAC,EAAE,CAAC;YACX,MAAM,CAAC,CAAC;QACV,CAAC;IACH,CAAC;CACF;AA9UD,oCA8UC","sourcesContent":["// noinspection ExceptionCaughtLocallyJS\n// flows/flow.instance.ts\n\nimport 'reflect-metadata';\nimport {\n FlowControl,\n FlowCtxOf,\n FlowEntry,\n FlowInputOf,\n FlowName,\n FlowOutputOf,\n FlowPlan,\n FlowRecord,\n FlowStagesOf,\n FlowType,\n HookEntry,\n HookMetadata,\n Reference,\n ServerRequest,\n Token,\n Type,\n} from '../common';\nimport ProviderRegistry from '../provider/provider.registry';\nimport { collectFlowHookMap, StageMap, cloneStageMap, mergeHookMetasIntoStageMap } from './flow.stages';\nimport { writeHttpResponse } from '../server/server.validation';\nimport { Scope } from '../scope';\nimport HookRegistry from '../hooks/hook.registry';\nimport { rpcError } from '../transport/transport.error';\n\ntype StageOutcome = 'ok' | 'respond' | 'next' | 'handled' | 'fail' | 'abort' | 'unknown_error';\n\ninterface StageResult {\n outcome: StageOutcome;\n control?: FlowControl | Error;\n}\n\nconst CAP = (s: string) => (s ? s[0].toUpperCase() + s.slice(1) : s);\nconst WILL = (s: string) => `will${CAP(s)}`;\nconst DID = (s: string) => `did${CAP(s)}`;\nconst AROUND = (s: string) => `around${CAP(s)}`;\n\nfunction parseTypedKey(k: string): { base: string; type?: 'will' | 'did' | 'around' } {\n const lc = k.toLowerCase();\n if (lc.startsWith('will') && k.length > 4) return { base: k.slice(4, 5).toLowerCase() + k.slice(5), type: 'will' };\n if (lc.startsWith('did') && k.length > 3) return { base: k.slice(3, 4).toLowerCase() + k.slice(4), type: 'did' };\n if (lc.startsWith('around') && k.length > 6)\n return { base: k.slice(6, 7).toLowerCase() + k.slice(7), type: 'around' };\n return { base: k };\n}\n\nexport class FlowInstance<Name extends FlowName> extends FlowEntry<Name> {\n readonly deps: Reference[];\n readonly globalProviders: ProviderRegistry;\n private plan: FlowPlan<never>;\n private FlowClass: FlowType;\n private stages: StageMap<FlowType>;\n private hooks: HookRegistry;\n\n constructor(scope: Scope, record: FlowRecord, deps: Set<Reference>, globalProviders: ProviderRegistry) {\n super(scope, record);\n this.deps = [...deps];\n this.globalProviders = globalProviders;\n this.FlowClass = this.record.provide;\n this.ready = this.initialize();\n this.plan = this.record.metadata.plan;\n this.hooks = scope.providers.getHooksRegistry();\n }\n\n protected async initialize() {\n const server = this.globalProviders.getActiveServer();\n\n this.stages = collectFlowHookMap(this.FlowClass);\n\n const { middleware } = this.metadata;\n if (middleware) {\n const path = typeof middleware.path === 'string' ? middleware.path : '';\n server.registerMiddleware(path, async (request, response, next) => {\n const canActivate = await this.canActivate(request);\n if (!canActivate) return next();\n\n try {\n const result = await this.run({ request, response, next } as any, new Map());\n if (result) return writeHttpResponse(response, result);\n } catch (e) {\n if (e instanceof FlowControl) {\n switch (e.type) {\n case 'abort':\n return writeHttpResponse(response, { kind: 'text', status: 500, body: 'Aborted' });\n case 'fail':\n return writeHttpResponse(response, { kind: 'text', status: 500, body: 'Internal Server Error' });\n case 'handled':\n return;\n case 'next':\n return next();\n case 'respond':\n return writeHttpResponse(response, e.output as any);\n }\n }\n // eslint-disable-next-line no-console\n console.error(e);\n return writeHttpResponse(response, {\n kind: 'text',\n status: 500,\n body: 'Internal Server Error',\n });\n }\n\n return next();\n });\n }\n\n return Promise.resolve();\n }\n\n async canActivate(request: ServerRequest): Promise<boolean> {\n if (this.method && request.method !== this.method) return false;\n\n const canActivate = this.metadata.middleware?.canActivate ?? [];\n if ((this.FlowClass as any)['canActivate']) {\n canActivate.push((this.FlowClass as any)['canActivate']);\n }\n if (canActivate.length === 0) return true;\n\n const results = await Promise.all(canActivate.map((m) => m(request, this.scope)));\n return results.every((r) => r);\n }\n\n async run(input: FlowInputOf<Name>, deps: Map<Token, Type>): Promise<FlowOutputOf<Name> | undefined> {\n const scope = this.globalProviders.getActiveScope();\n const { FlowClass, plan, name } = this;\n\n // Clone stages so we can merge injections safely per run.\n const baseStages = this.stages;\n let stages: StageMap<any> = cloneStageMap(baseStages);\n\n // Compute next order base after any class-defined entries.\n let orderBase = Math.max(0, ...Object.values(stages).flatMap((list) => list.map((e: any) => e._order ?? 0))) + 1;\n\n // Get tool owner ID if this is a tool call flow\n // The tool owner ID is set by the CallToolFlow.findTool stage\n const toolOwnerId = (input as any)?._toolOwnerId;\n\n const initialInjectedHooks =\n (this.hooks.getFlowHooksForOwner(name, toolOwnerId) as HookEntry<\n FlowInputOf<Name>,\n Name,\n FlowStagesOf<Name>,\n FlowCtxOf<Name>\n >[]) ?? [];\n\n let context: any;\n let contextReady = false;\n\n const materializeAndMerge = async (\n newHooks: HookEntry<FlowInputOf<Name>, Name, FlowStagesOf<Name>, FlowCtxOf<Name>>[],\n opts?: { orderStart?: number },\n ) => {\n if (!newHooks?.length || !contextReady) return;\n\n const metas: HookMetadata[] = [];\n for (const h of newHooks) {\n try {\n metas.push(h.metadata);\n } catch (e) {\n // eslint-disable-next-line no-console\n console.warn('[flow] Ignoring injected hook that failed to materialize:', e);\n }\n }\n\n if (metas.length) {\n const start = opts?.orderStart ?? orderBase;\n mergeHookMetasIntoStageMap(FlowClass, stages, metas, start);\n if (opts?.orderStart === undefined) orderBase += metas.length;\n }\n };\n\n const appendContextHooks = async (\n hooks: HookEntry<FlowInputOf<Name>, Name, FlowStagesOf<Name>, FlowCtxOf<Name>>[],\n ) => {\n await materializeAndMerge(hooks);\n };\n\n // Construct flow instance\n context = new FlowClass(this.metadata, input, scope, appendContextHooks, deps);\n\n // Now injections can materialize\n contextReady = true;\n\n // Initial registry hooks should not pre-empt stages; they just get registered\n await materializeAndMerge(initialInjectedHooks, { orderStart: -1_000_000 });\n\n // Refresh order base to be after everything currently present\n orderBase = Math.max(0, ...Object.values(stages).flatMap((list) => list.map((e: any) => e._order ?? 0))) + 1;\n\n let responded: FlowOutputOf<Name> | undefined;\n\n // Robust list runner (doesn't skip mid-run insertions)\n const runList = async (key: string, opts?: { ignoreRespond?: boolean }): Promise<StageResult> => {\n const getList = () => ((stages as any)[key] ?? []) as Array<{ method: (ctx: any) => Promise<void> }>;\n const seen = new Set<any>();\n\n while (true) {\n const list = getList();\n const item = list.find((e) => !seen.has(e));\n if (!item) break;\n seen.add(item);\n\n try {\n await item.method(context);\n } catch (e: any) {\n if (e instanceof FlowControl) {\n if (e.type === 'respond') {\n if (!opts?.ignoreRespond) {\n responded = e.output as FlowOutputOf<Name>;\n return { outcome: 'respond', control: e };\n }\n continue;\n }\n return { outcome: e.type, control: e };\n }\n return { outcome: 'unknown_error', control: e as Error };\n }\n }\n return { outcome: 'ok' };\n };\n\n // Run exactly one stage in order: will → around → stage → did (did runs once)\n const runOneStage = async (stageName: string, stopOnRespond: boolean): Promise<StageResult> => {\n // 1) willStage\n {\n const res = await runList(WILL(stageName));\n if (res.outcome === 'respond' && stopOnRespond) return res;\n if (res.outcome !== 'ok' && res.outcome !== 'respond') return res;\n }\n\n // 2) aroundStage (acts as pre-handlers unless you later add true wrapping)\n {\n const res = await runList(AROUND(stageName));\n if (res.outcome === 'respond' && stopOnRespond) return res;\n if (res.outcome !== 'ok' && res.outcome !== 'respond') return res;\n }\n\n // 3) stage\n let bodyOutcome: StageResult = { outcome: 'ok' };\n {\n const res = await runList(stageName, { ignoreRespond: false });\n bodyOutcome = res;\n if (res.outcome !== 'ok' && res.outcome !== 'respond') {\n // fail/abort/next/handled/unknown → do NOT run did\n return res;\n }\n }\n\n // 4) didStage (run once regardless of body respond)\n {\n const res = await runList(DID(stageName), { ignoreRespond: true });\n if (res.outcome !== 'ok' && res.outcome !== 'respond') return res;\n }\n\n if (bodyOutcome.outcome === 'respond') return bodyOutcome;\n return { outcome: 'ok' };\n };\n\n // IMPORTANT: ignore typed stage names in plan arrays.\n // Only base stage names in the plan drive execution; typed hooks run *with* their base.\n const runStageGroup = async (\n group: Array<string> | undefined,\n stopOnRespond: boolean,\n opts?: { ignoreRespond?: boolean },\n ): Promise<StageResult> => {\n if (!group || group.length === 0) return { outcome: 'ok' };\n\n const seenBase = new Set<string>();\n for (const rawKey of group) {\n const { base, type } = parseTypedKey(rawKey);\n if (type) {\n // Soft warning once per typed key occurrence (optional)\n // console.warn(`[flow] Ignoring typed stage \"${rawKey}\" in plan; hooks will run with base \"${base}\".`);\n continue; // Do not run typed keys as standalone stages\n }\n if (seenBase.has(base)) continue;\n seenBase.add(base);\n\n const res = await runOneStage(base, stopOnRespond);\n if (res.outcome === 'respond') {\n if (stopOnRespond) return res;\n // else keep going\n } else if (res.outcome !== 'ok') {\n return res;\n }\n }\n return { outcome: 'ok' };\n };\n\n const runErrorStage = async () => {\n await runStageGroup((plan as any).error, false, { ignoreRespond: true });\n };\n\n const runFinalizeStage = async () => {\n await runStageGroup((plan as any).finalize, false);\n };\n\n try {\n // ---------- PRE ----------\n {\n const pre = await runStageGroup((plan as any).pre, true);\n if (pre.outcome === 'respond') {\n const post = await runStageGroup((plan as any).post, false);\n if (post.outcome === 'unknown_error' || post.outcome === 'fail') {\n try {\n await runErrorStage();\n } finally {\n await runFinalizeStage();\n }\n if (post.outcome === 'fail') throw post.control!;\n throw post.control!;\n }\n if (post.outcome === 'abort' || post.outcome === 'next' || post.outcome === 'handled') {\n await runFinalizeStage();\n throw post.control as FlowControl;\n }\n await runFinalizeStage();\n return responded;\n }\n if (pre.outcome === 'unknown_error' || pre.outcome === 'fail') {\n try {\n await runErrorStage();\n } finally {\n await runFinalizeStage();\n }\n if (pre.outcome === 'fail') throw pre.control!;\n throw pre.control!;\n }\n if (pre.outcome === 'abort' || pre.outcome === 'next' || pre.outcome === 'handled') {\n await runFinalizeStage();\n throw pre.control as FlowControl;\n }\n }\n\n // ---------- EXECUTE ----------\n if (!responded) {\n const exec = await runStageGroup((plan as any).execute, true);\n if (exec.outcome === 'respond') {\n // continue to post + finalize\n } else if (exec.outcome === 'unknown_error' || exec.outcome === 'fail') {\n try {\n await runErrorStage();\n } finally {\n await runFinalizeStage();\n }\n if (exec.outcome === 'fail') throw exec.control!;\n throw exec.control!;\n } else if (exec.outcome === 'abort' || exec.outcome === 'next' || exec.outcome === 'handled') {\n await runFinalizeStage();\n throw exec.control as FlowControl;\n }\n }\n\n // ---------- POST ----------\n {\n const post = await runStageGroup((plan as any).post, false);\n if (post.outcome === 'unknown_error' || post.outcome === 'fail') {\n try {\n await runErrorStage();\n } finally {\n await runFinalizeStage();\n }\n if (post.outcome === 'fail') throw post.control!;\n throw post.control!;\n }\n if (post.outcome === 'abort' || post.outcome === 'next' || post.outcome === 'handled') {\n await runFinalizeStage();\n throw post.control as FlowControl;\n }\n }\n\n // ---------- FINALIZE ----------\n await runFinalizeStage();\n\n return responded;\n } catch (e) {\n throw e;\n }\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"flow.instance.js","sourceRoot":"","sources":["../../../src/flows/flow.instance.ts"],"names":[],"mappings":";AAAA,wCAAwC;AACxC,yBAAyB;;;AAEzB,4BAA0B;AAC1B,sCAiBmB;AAEnB,+CAAwG;AACxG,mEAAgE;AAYhE,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,WAAW,EAAE,GAAG,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACrE,MAAM,IAAI,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,OAAO,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;AAC5C,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;AAC1C,MAAM,MAAM,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;AAEhD,SAAS,aAAa,CAAC,CAAS;IAC9B,MAAM,EAAE,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;IAC3B,IAAI,EAAE,CAAC,UAAU,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{\n FlowControl,\n FlowCtxOf,\n FlowEntry,\n FlowInputOf,\n FlowName,\n FlowOutputOf,\n FlowPlan,\n FlowRecord,\n FlowStagesOf,\n FlowType,\n HookEntry,\n HookMetadata,\n Reference,\n ServerRequest,\n Token,\n Type,\n} from '../common';\nimport ProviderRegistry from '../provider/provider.registry';\nimport { collectFlowHookMap, StageMap, cloneStageMap, mergeHookMetasIntoStageMap } from './flow.stages';\nimport { writeHttpResponse } from '../server/server.validation';\nimport { Scope } from '../scope';\nimport HookRegistry from '../hooks/hook.registry';\nimport { rpcError } from '../transport/transport.error';\n\ntype StageOutcome = 'ok' | 'respond' | 'next' | 'handled' | 'fail' | 'abort' | 'unknown_error';\n\ninterface StageResult {\n outcome: StageOutcome;\n control?: FlowControl | Error;\n}\n\nconst CAP = (s: string) => (s ? s[0].toUpperCase() + s.slice(1) : s);\nconst WILL = (s: string) => `will${CAP(s)}`;\nconst DID = (s: string) => `did${CAP(s)}`;\nconst AROUND = (s: string) => `around${CAP(s)}`;\n\nfunction parseTypedKey(k: string): { base: string; type?: 'will' | 'did' | 'around' } {\n const lc = k.toLowerCase();\n if (lc.startsWith('will') && k.length > 4) return { base: k.slice(4, 5).toLowerCase() + k.slice(5), type: 'will' };\n if (lc.startsWith('did') && k.length > 3) return { base: k.slice(3, 4).toLowerCase() + k.slice(4), type: 'did' };\n if (lc.startsWith('around') && k.length > 6)\n return { base: k.slice(6, 7).toLowerCase() + k.slice(7), type: 'around' };\n return { base: k };\n}\n\nexport class FlowInstance<Name extends FlowName> extends FlowEntry<Name> {\n readonly deps: Reference[];\n readonly globalProviders: ProviderRegistry;\n private plan: FlowPlan<never>;\n private FlowClass: FlowType;\n private stages: StageMap<FlowType>;\n private hooks: HookRegistry;\n\n constructor(scope: Scope, record: FlowRecord, deps: Set<Reference>, globalProviders: ProviderRegistry) {\n super(scope, record);\n this.deps = [...deps];\n this.globalProviders = globalProviders;\n this.FlowClass = this.record.provide;\n this.ready = this.initialize();\n this.plan = this.record.metadata.plan;\n this.hooks = scope.providers.getHooksRegistry();\n }\n\n protected async initialize() {\n const server = this.globalProviders.getActiveServer();\n\n this.stages = collectFlowHookMap(this.FlowClass);\n\n const { middleware } = this.metadata;\n if (middleware) {\n const path = typeof middleware.path === 'string' ? middleware.path : '';\n server.registerMiddleware(path, async (request, response, next) => {\n const canActivate = await this.canActivate(request);\n if (!canActivate) return next();\n\n try {\n const result = await this.run({ request, response, next } as any, new Map());\n if (result) return writeHttpResponse(response, result);\n } catch (e) {\n if (e instanceof FlowControl) {\n switch (e.type) {\n case 'abort':\n return writeHttpResponse(response, { kind: 'text', status: 500, body: 'Aborted' });\n case 'fail':\n return writeHttpResponse(response, { kind: 'text', status: 500, body: 'Internal Server Error' });\n case 'handled':\n return;\n case 'next':\n return next();\n case 'respond':\n return writeHttpResponse(response, e.output as any);\n }\n }\n // Skip console.error due to Node.js 24 util.inspect bug with Zod validation errors\n // The error will be returned to the client as a 500 response\n return writeHttpResponse(response, {\n kind: 'text',\n status: 500,\n body: 'Internal Server Error',\n });\n }\n\n return next();\n });\n }\n\n return Promise.resolve();\n }\n\n async canActivate(request: ServerRequest): Promise<boolean> {\n if (this.method && request.method !== this.method) return false;\n\n const canActivate = this.metadata.middleware?.canActivate ?? [];\n if ((this.FlowClass as any)['canActivate']) {\n canActivate.push((this.FlowClass as any)['canActivate']);\n }\n if (canActivate.length === 0) return true;\n\n const results = await Promise.all(canActivate.map((m) => m(request, this.scope)));\n return results.every((r) => r);\n }\n\n async run(input: FlowInputOf<Name>, deps: Map<Token, Type>): Promise<FlowOutputOf<Name> | undefined> {\n const scope = this.globalProviders.getActiveScope();\n const { FlowClass, plan, name } = this;\n\n // Clone stages so we can merge injections safely per run.\n const baseStages = this.stages;\n let stages: StageMap<any> = cloneStageMap(baseStages);\n\n // Compute next order base after any class-defined entries.\n let orderBase = Math.max(0, ...Object.values(stages).flatMap((list) => list.map((e: any) => e._order ?? 0))) + 1;\n\n // Get tool owner ID if this is a tool call flow\n // The tool owner ID is set by the CallToolFlow.findTool stage\n const toolOwnerId = (input as any)?._toolOwnerId;\n\n const initialInjectedHooks =\n (this.hooks.getFlowHooksForOwner(name, toolOwnerId) as HookEntry<\n FlowInputOf<Name>,\n Name,\n FlowStagesOf<Name>,\n FlowCtxOf<Name>\n >[]) ?? [];\n\n let context: any;\n let contextReady = false;\n\n const materializeAndMerge = async (\n newHooks: HookEntry<FlowInputOf<Name>, Name, FlowStagesOf<Name>, FlowCtxOf<Name>>[],\n opts?: { orderStart?: number },\n ) => {\n if (!newHooks?.length || !contextReady) return;\n\n const metas: HookMetadata[] = [];\n for (const h of newHooks) {\n try {\n metas.push(h.metadata);\n } catch (e) {\n // Use safe logging to avoid Node.js 24 util.inspect bug with Zod errors\n // eslint-disable-next-line no-console\n console.warn(\n '[flow] Ignoring injected hook that failed to materialize:',\n e instanceof Error ? e.message : 'Unknown error',\n );\n }\n }\n\n if (metas.length) {\n const start = opts?.orderStart ?? orderBase;\n mergeHookMetasIntoStageMap(FlowClass, stages, metas, start);\n if (opts?.orderStart === undefined) orderBase += metas.length;\n }\n };\n\n const appendContextHooks = async (\n hooks: HookEntry<FlowInputOf<Name>, Name, FlowStagesOf<Name>, FlowCtxOf<Name>>[],\n ) => {\n await materializeAndMerge(hooks);\n };\n\n // Construct flow instance\n context = new FlowClass(this.metadata, input, scope, appendContextHooks, deps);\n\n // Now injections can materialize\n contextReady = true;\n\n // Initial registry hooks should not pre-empt stages; they just get registered\n await materializeAndMerge(initialInjectedHooks, { orderStart: -1_000_000 });\n\n // Refresh order base to be after everything currently present\n orderBase = Math.max(0, ...Object.values(stages).flatMap((list) => list.map((e: any) => e._order ?? 0))) + 1;\n\n let responded: FlowOutputOf<Name> | undefined;\n\n // Robust list runner (doesn't skip mid-run insertions)\n const runList = async (key: string, opts?: { ignoreRespond?: boolean }): Promise<StageResult> => {\n const getList = () => ((stages as any)[key] ?? []) as Array<{ method: (ctx: any) => Promise<void> }>;\n const seen = new Set<any>();\n\n while (true) {\n const list = getList();\n const item = list.find((e) => !seen.has(e));\n if (!item) break;\n seen.add(item);\n\n try {\n await item.method(context);\n } catch (e: any) {\n if (e instanceof FlowControl) {\n if (e.type === 'respond') {\n if (!opts?.ignoreRespond) {\n responded = e.output as FlowOutputOf<Name>;\n return { outcome: 'respond', control: e };\n }\n continue;\n }\n return { outcome: e.type, control: e };\n }\n return { outcome: 'unknown_error', control: e as Error };\n }\n }\n return { outcome: 'ok' };\n };\n\n // Run exactly one stage in order: will → around → stage → did (did runs once)\n const runOneStage = async (stageName: string, stopOnRespond: boolean): Promise<StageResult> => {\n // 1) willStage\n {\n const res = await runList(WILL(stageName));\n if (res.outcome === 'respond' && stopOnRespond) return res;\n if (res.outcome !== 'ok' && res.outcome !== 'respond') return res;\n }\n\n // 2) aroundStage (acts as pre-handlers unless you later add true wrapping)\n {\n const res = await runList(AROUND(stageName));\n if (res.outcome === 'respond' && stopOnRespond) return res;\n if (res.outcome !== 'ok' && res.outcome !== 'respond') return res;\n }\n\n // 3) stage\n let bodyOutcome: StageResult = { outcome: 'ok' };\n {\n const res = await runList(stageName, { ignoreRespond: false });\n bodyOutcome = res;\n if (res.outcome !== 'ok' && res.outcome !== 'respond') {\n // fail/abort/next/handled/unknown → do NOT run did\n return res;\n }\n }\n\n // 4) didStage (run once regardless of body respond)\n {\n const res = await runList(DID(stageName), { ignoreRespond: true });\n if (res.outcome !== 'ok' && res.outcome !== 'respond') return res;\n }\n\n if (bodyOutcome.outcome === 'respond') return bodyOutcome;\n return { outcome: 'ok' };\n };\n\n // IMPORTANT: ignore typed stage names in plan arrays.\n // Only base stage names in the plan drive execution; typed hooks run *with* their base.\n const runStageGroup = async (\n group: Array<string> | undefined,\n stopOnRespond: boolean,\n opts?: { ignoreRespond?: boolean },\n ): Promise<StageResult> => {\n if (!group || group.length === 0) return { outcome: 'ok' };\n\n const seenBase = new Set<string>();\n for (const rawKey of group) {\n const { base, type } = parseTypedKey(rawKey);\n if (type) {\n // Soft warning once per typed key occurrence (optional)\n // console.warn(`[flow] Ignoring typed stage \"${rawKey}\" in plan; hooks will run with base \"${base}\".`);\n continue; // Do not run typed keys as standalone stages\n }\n if (seenBase.has(base)) continue;\n seenBase.add(base);\n\n const res = await runOneStage(base, stopOnRespond);\n if (res.outcome === 'respond') {\n if (stopOnRespond) return res;\n // else keep going\n } else if (res.outcome !== 'ok') {\n return res;\n }\n }\n return { outcome: 'ok' };\n };\n\n const runErrorStage = async () => {\n await runStageGroup((plan as any).error, false, { ignoreRespond: true });\n };\n\n const runFinalizeStage = async () => {\n await runStageGroup((plan as any).finalize, false);\n };\n\n try {\n // ---------- PRE ----------\n {\n const pre = await runStageGroup((plan as any).pre, true);\n if (pre.outcome === 'respond') {\n const post = await runStageGroup((plan as any).post, false);\n if (post.outcome === 'unknown_error' || post.outcome === 'fail') {\n try {\n await runErrorStage();\n } finally {\n await runFinalizeStage();\n }\n if (post.outcome === 'fail') throw post.control!;\n throw post.control!;\n }\n if (post.outcome === 'abort' || post.outcome === 'next' || post.outcome === 'handled') {\n await runFinalizeStage();\n throw post.control as FlowControl;\n }\n await runFinalizeStage();\n return responded;\n }\n if (pre.outcome === 'unknown_error' || pre.outcome === 'fail') {\n try {\n await runErrorStage();\n } finally {\n await runFinalizeStage();\n }\n if (pre.outcome === 'fail') throw pre.control!;\n throw pre.control!;\n }\n if (pre.outcome === 'abort' || pre.outcome === 'next' || pre.outcome === 'handled') {\n await runFinalizeStage();\n throw pre.control as FlowControl;\n }\n }\n\n // ---------- EXECUTE ----------\n if (!responded) {\n const exec = await runStageGroup((plan as any).execute, true);\n if (exec.outcome === 'respond') {\n // continue to post + finalize\n } else if (exec.outcome === 'unknown_error' || exec.outcome === 'fail') {\n try {\n await runErrorStage();\n } finally {\n await runFinalizeStage();\n }\n if (exec.outcome === 'fail') throw exec.control!;\n throw exec.control!;\n } else if (exec.outcome === 'abort' || exec.outcome === 'next' || exec.outcome === 'handled') {\n await runFinalizeStage();\n throw exec.control as FlowControl;\n }\n }\n\n // ---------- POST ----------\n {\n const post = await runStageGroup((plan as any).post, false);\n if (post.outcome === 'unknown_error' || post.outcome === 'fail') {\n try {\n await runErrorStage();\n } finally {\n await runFinalizeStage();\n }\n if (post.outcome === 'fail') throw post.control!;\n throw post.control!;\n }\n if (post.outcome === 'abort' || post.outcome === 'next' || post.outcome === 'handled') {\n await runFinalizeStage();\n throw post.control as FlowControl;\n }\n }\n\n // ---------- FINALIZE ----------\n await runFinalizeStage();\n\n return responded;\n } catch (e) {\n throw e;\n }\n }\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"flow.registry.js","sourceRoot":"","sources":["../../../src/flows/flow.registry.ts"],"names":[],"mappings":";;AACA,0CAAuE;AACvE,sCAA+G;AAC/G,6CAA6C;AAC7C,sDAAiD;AACjD,mDAA+C;AAE/C,MAAqB,YAAa,SAAQ,2BAAgE;IACxG,YAAY,SAA2B,EAAE,IAAgB;QACvD,KAAK,CAAC,cAAc,EAAE,SAAS,EAAE,IAAI,CAAC,CAAC;IACzC,CAAC;IAEkB,QAAQ,CAAC,IAAgB;QAC1C,MAAM,MAAM,GAAG,IAAI,GAAG,EAAS,CAAC;QAChC,MAAM,IAAI,GAAG,IAAI,GAAG,EAAqB,CAAC;QAC1C,MAAM,KAAK,GAAG,IAAI,GAAG,EAAqB,CAAC;QAE3C,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,MAAM,GAAG,GAAG,IAAA,0BAAa,EAAC,GAAG,CAAC,CAAC;YAC/B,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;YAC5B,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACpB,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YACvB,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;QAChC,CAAC;QAED,OAAO,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,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AE,QAAQ,CAAC,CAAC;QAChD,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,KAAK,CAAC,aAAa,CAAC,QAAoB;QACtC,MAAM,QAAQ,GAAoB,EAAE,CAAC;QACrC,KAAK,MAAM,GAAG,IAAI,QAAQ,EAAE,CAAC;YAC3B,MAAM,GAAG,GAAG,IAAA,0BAAa,EAAC,GAAG,CAAC,CAAC;YAC/B,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;YAC5B,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;YACzB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC;YAC5B,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,GAAG,EAAE,CAAC,CAAC;YACnC,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC;QACnD,CAAC;QACD,MAAM,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IAC9B,CAAC;IAED,OAAO,CACL,IAAU,EACV,KAAwB,EACxB,IAAuB;QAEvB,MAAM,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,IAAI,EAAE,CAAC;YACV,MAAM,IAAI,KAAK,CAAC,QAAQ,IAAI,oBAAoB,CAAC,CAAC;QACpD,CAAC;QACD,OAAO,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,IAAI,IAAI,IAAI,GAAG,EAAE,CAA4C,CAAC;IACvF,CAAC;CACF;AAlFD,+BAkFC","sourcesContent":["import ProviderRegistry from '../provider/provider.registry';\nimport { RegistryAbstract, RegistryBuildMapResult } from '../regsitry';\nimport { FlowInputOf, FlowName, FlowOutputOf, FlowRecord, FlowType, ScopeEntry, Token, Type } from '../common';\nimport { normalizeFlow } from './flow.utils';\nimport { tokenName } from '../utils/token.utils';\nimport { FlowInstance } from './flow.instance';\n\nexport default class FlowRegistry extends RegistryAbstract<FlowInstance<FlowName>, FlowRecord, FlowType[]> {\n constructor(providers: ProviderRegistry, list: FlowType[]) {\n super('FlowRegistry', providers, list);\n }\n\n protected override buildMap(list: FlowType[]): RegistryBuildMapResult<FlowRecord> {\n const tokens = new Set<Token>();\n const defs = new Map<Token, FlowRecord>();\n const graph = new Map<Token, Set<Token>>();\n\n for (const raw of list) {\n const rec = normalizeFlow(raw);\n const provide = rec.provide;\n tokens.add(provide);\n defs.set(provide, rec);\n graph.set(provide, new Set());\n }\n\n return { tokens, defs, graph };\n }\n\n protected buildGraph() {\n for (const token of this.tokens) {\n const rec = this.defs.get(token)!;\n const deps = rec.metadata.dependsOn ?? [];\n\n for (const d of deps) {\n if (d == ScopeEntry) {\n this.graph.get(token)!.add(ScopeEntry);\n } else {\n if (!this.providers.get(d)) {\n throw new Error(`Flow ${tokenName(token)} depends on ${tokenName(d)}, which is not registered.`);\n }\n this.graph.get(token)!.add(d);\n }\n }\n }\n }\n\n /** Instantiate adapters, run fetch/transform, and populate registries. */\n protected async initialize(): Promise<void> {\n const readyArr: Promise<void>[] = [];\n for (const token of this.tokens) {\n const instance = this.initializeOne(token);\n readyArr.push(instance.ready);\n }\n await Promise.all(readyArr);\n }\n\n private initializeOne(token: Token) {\n const rec = this.defs.get(token)!;\n const deps = this.graph.get(token)!;\n\n const instance = new FlowInstance(this.providers.getActiveScope(), rec, deps, this.providers);\n this.instances.set(rec.metadata.name, instance);\n return instance;\n }\n\n async registryFlows(rawFlows: FlowType[]): Promise<void> {\n const readyArr: Promise<void>[] = [];\n for (const raw of rawFlows) {\n const rec = normalizeFlow(raw);\n const provide = rec.provide;\n this.tokens.add(provide);\n this.defs.set(provide, rec);\n this.graph.set(provide, new Set());\n readyArr.push(this.initializeOne(provide).ready);\n }\n await Promise.all(readyArr);\n }\n\n runFlow<Name extends FlowName>(\n name: Name,\n input: FlowInputOf<Name>,\n deps?: Map<Token, Type>,\n ): Promise<FlowOutputOf<Name> | undefined> {\n const flow = this.instances.get(name);\n if (!flow) {\n throw new Error(`Flow ${name} is not registered`);\n }\n return flow.run(input, deps ?? new Map()) as Promise<FlowOutputOf<Name> | undefined>;\n }\n}\n"]}
|
package/src/flows/flow.stages.js
CHANGED
|
@@ -6,6 +6,7 @@ exports.resolveStageKey = resolveStageKey;
|
|
|
6
6
|
exports.collectFlowHookMap = collectFlowHookMap;
|
|
7
7
|
exports.mergeHookMetasIntoStageMap = mergeHookMetasIntoStageMap;
|
|
8
8
|
const common_1 = require("../common");
|
|
9
|
+
const hook_decorator_1 = require("../common/decorators/hook.decorator");
|
|
9
10
|
const cap = (s) => (s ? s[0].toUpperCase() + s.slice(1) : s);
|
|
10
11
|
const CACHE = new WeakMap();
|
|
11
12
|
function sortStageMap(table) {
|
|
@@ -30,13 +31,19 @@ function resolveStageKey(type, stage) {
|
|
|
30
31
|
}
|
|
31
32
|
function collectFlowHookMap(FlowClass) {
|
|
32
33
|
const cached = CACHE.get(FlowClass);
|
|
33
|
-
if (cached)
|
|
34
|
+
if (cached) {
|
|
34
35
|
return cached;
|
|
35
|
-
|
|
36
|
+
}
|
|
37
|
+
// Get existing metadata (from legacy decorators)
|
|
38
|
+
const existingMetas = (Reflect.getMetadata(common_1.FrontMcpFlowHookTokens.hooks, FlowClass) ?? []);
|
|
39
|
+
// Resolve any pending TC39 decorator hooks
|
|
40
|
+
const tc39Metas = (0, hook_decorator_1.resolvePendingTC39HooksForClass)(FlowClass);
|
|
41
|
+
// Combine both sources
|
|
42
|
+
const metas = [...existingMetas, ...tc39Metas];
|
|
36
43
|
const sorted = metas
|
|
37
44
|
.map((m, i) => ({ m, i }))
|
|
38
45
|
.sort((a, b) => (a.m.priority ?? 0) - (b.m.priority ?? 0) || a.i - b.i)
|
|
39
|
-
.map(x => x.m);
|
|
46
|
+
.map((x) => x.m);
|
|
40
47
|
const table = {};
|
|
41
48
|
let order = 0;
|
|
42
49
|
for (const m of sorted) {
|
|
@@ -46,16 +53,13 @@ function collectFlowHookMap(FlowClass) {
|
|
|
46
53
|
_order: order++,
|
|
47
54
|
method: async (ctx) => {
|
|
48
55
|
const target = m.static ? FlowClass : ctx;
|
|
49
|
-
const impl = typeof m.method === 'function'
|
|
50
|
-
? m.method
|
|
51
|
-
: target?.[m.method];
|
|
56
|
+
const impl = typeof m.method === 'function' ? m.method : target?.[m.method];
|
|
52
57
|
if (typeof impl !== 'function')
|
|
53
58
|
return;
|
|
54
59
|
if (m.filter && !(await m.filter(ctx)))
|
|
55
60
|
return;
|
|
56
61
|
if (m.type === 'around') {
|
|
57
|
-
const next = async () => {
|
|
58
|
-
};
|
|
62
|
+
const next = async () => { };
|
|
59
63
|
return m.static ? impl.call(FlowClass, ctx, next) : impl.call(ctx, ctx, next);
|
|
60
64
|
}
|
|
61
65
|
else {
|
|
@@ -74,7 +78,7 @@ function mergeHookMetasIntoStageMap(FlowClass, table, metas, orderStart = 100_00
|
|
|
74
78
|
const sorted = metas
|
|
75
79
|
.map((m, i) => ({ m, i }))
|
|
76
80
|
.sort((a, b) => (a.m.priority ?? 0) - (b.m.priority ?? 0) || a.i - b.i)
|
|
77
|
-
.map(x => x.m);
|
|
81
|
+
.map((x) => x.m);
|
|
78
82
|
for (const m of sorted) {
|
|
79
83
|
const resolved = resolveStageKey(m.type, m.stage);
|
|
80
84
|
const entry = {
|
|
@@ -94,8 +98,7 @@ function mergeHookMetasIntoStageMap(FlowClass, table, metas, orderStart = 100_00
|
|
|
94
98
|
if (m.filter && !(await m.filter(ctx)))
|
|
95
99
|
return;
|
|
96
100
|
if (m.type === 'around') {
|
|
97
|
-
const next = async () => {
|
|
98
|
-
};
|
|
101
|
+
const next = async () => { };
|
|
99
102
|
return m.static ? impl.call(target, ctx, next) : impl.call(target, ctx, next);
|
|
100
103
|
}
|
|
101
104
|
else {
|