@vurb/core 3.2.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 +677 -0
- package/dist/cli/args.d.ts +26 -0
- package/dist/cli/args.d.ts.map +1 -0
- package/dist/cli/args.js +117 -0
- package/dist/cli/args.js.map +1 -0
- package/dist/cli/commands/create.d.ts +11 -0
- package/dist/cli/commands/create.d.ts.map +1 -0
- package/dist/cli/commands/create.js +121 -0
- package/dist/cli/commands/create.js.map +1 -0
- package/dist/cli/commands/deploy.d.ts +3 -0
- package/dist/cli/commands/deploy.d.ts.map +1 -0
- package/dist/cli/commands/deploy.js +268 -0
- package/dist/cli/commands/deploy.js.map +1 -0
- package/dist/cli/commands/dev.d.ts +9 -0
- package/dist/cli/commands/dev.d.ts.map +1 -0
- package/dist/cli/commands/dev.js +58 -0
- package/dist/cli/commands/dev.js.map +1 -0
- package/dist/cli/commands/lock.d.ts +5 -0
- package/dist/cli/commands/lock.d.ts.map +1 -0
- package/dist/cli/commands/lock.js +94 -0
- package/dist/cli/commands/lock.js.map +1 -0
- package/dist/cli/commands/remote.d.ts +3 -0
- package/dist/cli/commands/remote.d.ts.map +1 -0
- package/dist/cli/commands/remote.js +37 -0
- package/dist/cli/commands/remote.js.map +1 -0
- package/dist/cli/constants.d.ts +18 -0
- package/dist/cli/constants.d.ts.map +1 -0
- package/dist/cli/constants.js +95 -0
- package/dist/cli/constants.js.map +1 -0
- package/dist/cli/progress.d.ts +34 -0
- package/dist/cli/progress.d.ts.map +1 -0
- package/dist/cli/progress.js +102 -0
- package/dist/cli/progress.js.map +1 -0
- package/dist/cli/rc.d.ts +11 -0
- package/dist/cli/rc.d.ts.map +1 -0
- package/dist/cli/rc.js +75 -0
- package/dist/cli/rc.js.map +1 -0
- package/dist/cli/registry.d.ts +25 -0
- package/dist/cli/registry.d.ts.map +1 -0
- package/dist/cli/registry.js +86 -0
- package/dist/cli/registry.js.map +1 -0
- package/dist/cli/scaffold.d.ts +10 -0
- package/dist/cli/scaffold.d.ts.map +1 -0
- package/dist/cli/scaffold.js +105 -0
- package/dist/cli/scaffold.js.map +1 -0
- package/dist/cli/templates/config.d.ts +14 -0
- package/dist/cli/templates/config.d.ts.map +1 -0
- package/dist/cli/templates/config.js +133 -0
- package/dist/cli/templates/config.js.map +1 -0
- package/dist/cli/templates/constants.d.ts +9 -0
- package/dist/cli/templates/constants.d.ts.map +1 -0
- package/dist/cli/templates/constants.js +9 -0
- package/dist/cli/templates/constants.js.map +1 -0
- package/dist/cli/templates/core.d.ts +14 -0
- package/dist/cli/templates/core.d.ts.map +1 -0
- package/dist/cli/templates/core.js +186 -0
- package/dist/cli/templates/core.js.map +1 -0
- package/dist/cli/templates/cursor.d.ts +8 -0
- package/dist/cli/templates/cursor.d.ts.map +1 -0
- package/dist/cli/templates/cursor.js +13 -0
- package/dist/cli/templates/cursor.js.map +1 -0
- package/dist/cli/templates/index.d.ts +17 -0
- package/dist/cli/templates/index.d.ts.map +1 -0
- package/dist/cli/templates/index.js +27 -0
- package/dist/cli/templates/index.js.map +1 -0
- package/dist/cli/templates/middleware.d.ts +7 -0
- package/dist/cli/templates/middleware.d.ts.map +1 -0
- package/dist/cli/templates/middleware.js +34 -0
- package/dist/cli/templates/middleware.js.map +1 -0
- package/dist/cli/templates/presenter.d.ts +7 -0
- package/dist/cli/templates/presenter.d.ts.map +1 -0
- package/dist/cli/templates/presenter.js +46 -0
- package/dist/cli/templates/presenter.js.map +1 -0
- package/dist/cli/templates/prompt.d.ts +7 -0
- package/dist/cli/templates/prompt.d.ts.map +1 -0
- package/dist/cli/templates/prompt.js +42 -0
- package/dist/cli/templates/prompt.js.map +1 -0
- package/dist/cli/templates/readme.d.ts +8 -0
- package/dist/cli/templates/readme.d.ts.map +1 -0
- package/dist/cli/templates/readme.js +173 -0
- package/dist/cli/templates/readme.js.map +1 -0
- package/dist/cli/templates/testing.d.ts +11 -0
- package/dist/cli/templates/testing.d.ts.map +1 -0
- package/dist/cli/templates/testing.js +101 -0
- package/dist/cli/templates/testing.js.map +1 -0
- package/dist/cli/templates/tools.d.ts +13 -0
- package/dist/cli/templates/tools.d.ts.map +1 -0
- package/dist/cli/templates/tools.js +63 -0
- package/dist/cli/templates/tools.js.map +1 -0
- package/dist/cli/templates/vectors/database.d.ts +9 -0
- package/dist/cli/templates/vectors/database.d.ts.map +1 -0
- package/dist/cli/templates/vectors/database.js +82 -0
- package/dist/cli/templates/vectors/database.js.map +1 -0
- package/dist/cli/templates/vectors/index.d.ts +9 -0
- package/dist/cli/templates/vectors/index.d.ts.map +1 -0
- package/dist/cli/templates/vectors/index.js +9 -0
- package/dist/cli/templates/vectors/index.js.map +1 -0
- package/dist/cli/templates/vectors/oauth.d.ts +10 -0
- package/dist/cli/templates/vectors/oauth.d.ts.map +1 -0
- package/dist/cli/templates/vectors/oauth.js +76 -0
- package/dist/cli/templates/vectors/oauth.js.map +1 -0
- package/dist/cli/templates/vectors/openapi.d.ts +10 -0
- package/dist/cli/templates/vectors/openapi.d.ts.map +1 -0
- package/dist/cli/templates/vectors/openapi.js +106 -0
- package/dist/cli/templates/vectors/openapi.js.map +1 -0
- package/dist/cli/templates/vectors/workflow.d.ts +7 -0
- package/dist/cli/templates/vectors/workflow.d.ts.map +1 -0
- package/dist/cli/templates/vectors/workflow.js +49 -0
- package/dist/cli/templates/vectors/workflow.js.map +1 -0
- package/dist/cli/types.d.ts +36 -0
- package/dist/cli/types.d.ts.map +1 -0
- package/dist/cli/types.js +10 -0
- package/dist/cli/types.js.map +1 -0
- package/dist/cli/utils.d.ts +27 -0
- package/dist/cli/utils.d.ts.map +1 -0
- package/dist/cli/utils.js +73 -0
- package/dist/cli/utils.js.map +1 -0
- package/dist/cli/vurb.d.ts +15 -0
- package/dist/cli/vurb.d.ts.map +1 -0
- package/dist/cli/vurb.js +87 -0
- package/dist/cli/vurb.js.map +1 -0
- package/dist/client/InferRouter.d.ts +92 -0
- package/dist/client/InferRouter.d.ts.map +1 -0
- package/dist/client/InferRouter.js +31 -0
- package/dist/client/InferRouter.js.map +1 -0
- package/dist/client/VurbClient.d.ts +282 -0
- package/dist/client/VurbClient.d.ts.map +1 -0
- package/dist/client/VurbClient.js +287 -0
- package/dist/client/VurbClient.js.map +1 -0
- package/dist/client/createTypedRegistry.d.ts +25 -0
- package/dist/client/createTypedRegistry.d.ts.map +1 -0
- package/dist/client/createTypedRegistry.js +74 -0
- package/dist/client/createTypedRegistry.js.map +1 -0
- package/dist/client/index.d.ts +6 -0
- package/dist/client/index.d.ts.map +1 -0
- package/dist/client/index.js +4 -0
- package/dist/client/index.js.map +1 -0
- package/dist/converters/ConverterBase.d.ts +68 -0
- package/dist/converters/ConverterBase.d.ts.map +1 -0
- package/dist/converters/ConverterBase.js +62 -0
- package/dist/converters/ConverterBase.js.map +1 -0
- package/dist/converters/GroupConverter.d.ts +33 -0
- package/dist/converters/GroupConverter.d.ts.map +1 -0
- package/dist/converters/GroupConverter.js +26 -0
- package/dist/converters/GroupConverter.js.map +1 -0
- package/dist/converters/PromptConverter.d.ts +33 -0
- package/dist/converters/PromptConverter.d.ts.map +1 -0
- package/dist/converters/PromptConverter.js +26 -0
- package/dist/converters/PromptConverter.js.map +1 -0
- package/dist/converters/ResourceConverter.d.ts +35 -0
- package/dist/converters/ResourceConverter.d.ts.map +1 -0
- package/dist/converters/ResourceConverter.js +28 -0
- package/dist/converters/ResourceConverter.js.map +1 -0
- package/dist/converters/ToolAnnotationsConverter.d.ts +33 -0
- package/dist/converters/ToolAnnotationsConverter.d.ts.map +1 -0
- package/dist/converters/ToolAnnotationsConverter.js +26 -0
- package/dist/converters/ToolAnnotationsConverter.js.map +1 -0
- package/dist/converters/ToolConverter.d.ts +35 -0
- package/dist/converters/ToolConverter.d.ts.map +1 -0
- package/dist/converters/ToolConverter.js +28 -0
- package/dist/converters/ToolConverter.js.map +1 -0
- package/dist/converters/index.d.ts +7 -0
- package/dist/converters/index.d.ts.map +1 -0
- package/dist/converters/index.js +7 -0
- package/dist/converters/index.js.map +1 -0
- package/dist/core/StandardSchema.d.ts +178 -0
- package/dist/core/StandardSchema.d.ts.map +1 -0
- package/dist/core/StandardSchema.js +174 -0
- package/dist/core/StandardSchema.js.map +1 -0
- package/dist/core/builder/ActionGroupBuilder.d.ts +208 -0
- package/dist/core/builder/ActionGroupBuilder.d.ts.map +1 -0
- package/dist/core/builder/ActionGroupBuilder.js +193 -0
- package/dist/core/builder/ActionGroupBuilder.js.map +1 -0
- package/dist/core/builder/ErrorBuilder.d.ts +59 -0
- package/dist/core/builder/ErrorBuilder.d.ts.map +1 -0
- package/dist/core/builder/ErrorBuilder.js +99 -0
- package/dist/core/builder/ErrorBuilder.js.map +1 -0
- package/dist/core/builder/FluentRouter.d.ts +96 -0
- package/dist/core/builder/FluentRouter.d.ts.map +1 -0
- package/dist/core/builder/FluentRouter.js +116 -0
- package/dist/core/builder/FluentRouter.js.map +1 -0
- package/dist/core/builder/FluentSchemaHelpers.d.ts +237 -0
- package/dist/core/builder/FluentSchemaHelpers.d.ts.map +1 -0
- package/dist/core/builder/FluentSchemaHelpers.js +227 -0
- package/dist/core/builder/FluentSchemaHelpers.js.map +1 -0
- package/dist/core/builder/FluentToolBuilder.d.ts +419 -0
- package/dist/core/builder/FluentToolBuilder.d.ts.map +1 -0
- package/dist/core/builder/FluentToolBuilder.js +643 -0
- package/dist/core/builder/FluentToolBuilder.js.map +1 -0
- package/dist/core/builder/GroupedToolBuilder.d.ts +832 -0
- package/dist/core/builder/GroupedToolBuilder.d.ts.map +1 -0
- package/dist/core/builder/GroupedToolBuilder.js +1306 -0
- package/dist/core/builder/GroupedToolBuilder.js.map +1 -0
- package/dist/core/builder/ParamDescriptors.d.ts +142 -0
- package/dist/core/builder/ParamDescriptors.d.ts.map +1 -0
- package/dist/core/builder/ParamDescriptors.js +164 -0
- package/dist/core/builder/ParamDescriptors.js.map +1 -0
- package/dist/core/builder/ToolDefinitionCompiler.d.ts +37 -0
- package/dist/core/builder/ToolDefinitionCompiler.d.ts.map +1 -0
- package/dist/core/builder/ToolDefinitionCompiler.js +72 -0
- package/dist/core/builder/ToolDefinitionCompiler.js.map +1 -0
- package/dist/core/builder/defineTool.d.ts +180 -0
- package/dist/core/builder/defineTool.d.ts.map +1 -0
- package/dist/core/builder/defineTool.js +164 -0
- package/dist/core/builder/defineTool.js.map +1 -0
- package/dist/core/builder/index.d.ts +13 -0
- package/dist/core/builder/index.d.ts.map +1 -0
- package/dist/core/builder/index.js +13 -0
- package/dist/core/builder/index.js.map +1 -0
- package/dist/core/createGroup.d.ts +140 -0
- package/dist/core/createGroup.d.ts.map +1 -0
- package/dist/core/createGroup.js +144 -0
- package/dist/core/createGroup.js.map +1 -0
- package/dist/core/execution/ConcurrencyGuard.d.ts +103 -0
- package/dist/core/execution/ConcurrencyGuard.d.ts.map +1 -0
- package/dist/core/execution/ConcurrencyGuard.js +147 -0
- package/dist/core/execution/ConcurrencyGuard.js.map +1 -0
- package/dist/core/execution/EgressGuard.d.ts +72 -0
- package/dist/core/execution/EgressGuard.d.ts.map +1 -0
- package/dist/core/execution/EgressGuard.js +163 -0
- package/dist/core/execution/EgressGuard.js.map +1 -0
- package/dist/core/execution/ExecutionPipeline.d.ts +67 -0
- package/dist/core/execution/ExecutionPipeline.d.ts.map +1 -0
- package/dist/core/execution/ExecutionPipeline.js +176 -0
- package/dist/core/execution/ExecutionPipeline.js.map +1 -0
- package/dist/core/execution/MiddlewareCompiler.d.ts +35 -0
- package/dist/core/execution/MiddlewareCompiler.d.ts.map +1 -0
- package/dist/core/execution/MiddlewareCompiler.js +111 -0
- package/dist/core/execution/MiddlewareCompiler.js.map +1 -0
- package/dist/core/execution/MutationSerializer.d.ts +78 -0
- package/dist/core/execution/MutationSerializer.d.ts.map +1 -0
- package/dist/core/execution/MutationSerializer.js +106 -0
- package/dist/core/execution/MutationSerializer.js.map +1 -0
- package/dist/core/execution/PipelineHooks.d.ts +46 -0
- package/dist/core/execution/PipelineHooks.d.ts.map +1 -0
- package/dist/core/execution/PipelineHooks.js +66 -0
- package/dist/core/execution/PipelineHooks.js.map +1 -0
- package/dist/core/execution/ProgressHelper.d.ts +67 -0
- package/dist/core/execution/ProgressHelper.d.ts.map +1 -0
- package/dist/core/execution/ProgressHelper.js +59 -0
- package/dist/core/execution/ProgressHelper.js.map +1 -0
- package/dist/core/execution/ValidationErrorFormatter.d.ts +34 -0
- package/dist/core/execution/ValidationErrorFormatter.d.ts.map +1 -0
- package/dist/core/execution/ValidationErrorFormatter.js +193 -0
- package/dist/core/execution/ValidationErrorFormatter.js.map +1 -0
- package/dist/core/execution/index.d.ts +9 -0
- package/dist/core/execution/index.d.ts.map +1 -0
- package/dist/core/execution/index.js +9 -0
- package/dist/core/execution/index.js.map +1 -0
- package/dist/core/index.d.ts +34 -0
- package/dist/core/index.d.ts.map +1 -0
- package/dist/core/index.js +29 -0
- package/dist/core/index.js.map +1 -0
- package/dist/core/initVurb.d.ts +295 -0
- package/dist/core/initVurb.d.ts.map +1 -0
- package/dist/core/initVurb.js +171 -0
- package/dist/core/initVurb.js.map +1 -0
- package/dist/core/middleware/ContextDerivation.d.ts +124 -0
- package/dist/core/middleware/ContextDerivation.d.ts.map +1 -0
- package/dist/core/middleware/ContextDerivation.js +117 -0
- package/dist/core/middleware/ContextDerivation.js.map +1 -0
- package/dist/core/middleware/index.d.ts +4 -0
- package/dist/core/middleware/index.d.ts.map +1 -0
- package/dist/core/middleware/index.js +3 -0
- package/dist/core/middleware/index.js.map +1 -0
- package/dist/core/registry/ToolFilterEngine.d.ts +27 -0
- package/dist/core/registry/ToolFilterEngine.d.ts.map +1 -0
- package/dist/core/registry/ToolFilterEngine.js +45 -0
- package/dist/core/registry/ToolFilterEngine.js.map +1 -0
- package/dist/core/registry/ToolRegistry.d.ts +259 -0
- package/dist/core/registry/ToolRegistry.d.ts.map +1 -0
- package/dist/core/registry/ToolRegistry.js +343 -0
- package/dist/core/registry/ToolRegistry.js.map +1 -0
- package/dist/core/registry/index.d.ts +4 -0
- package/dist/core/registry/index.d.ts.map +1 -0
- package/dist/core/registry/index.js +3 -0
- package/dist/core/registry/index.js.map +1 -0
- package/dist/core/response.d.ts +289 -0
- package/dist/core/response.d.ts.map +1 -0
- package/dist/core/response.js +286 -0
- package/dist/core/response.js.map +1 -0
- package/dist/core/result.d.ts +93 -0
- package/dist/core/result.d.ts.map +1 -0
- package/dist/core/result.js +66 -0
- package/dist/core/result.js.map +1 -0
- package/dist/core/schema/AnnotationAggregator.d.ts +11 -0
- package/dist/core/schema/AnnotationAggregator.d.ts.map +1 -0
- package/dist/core/schema/AnnotationAggregator.js +40 -0
- package/dist/core/schema/AnnotationAggregator.js.map +1 -0
- package/dist/core/schema/DescriptionGenerator.d.ts +12 -0
- package/dist/core/schema/DescriptionGenerator.d.ts.map +1 -0
- package/dist/core/schema/DescriptionGenerator.js +81 -0
- package/dist/core/schema/DescriptionGenerator.js.map +1 -0
- package/dist/core/schema/SchemaGenerator.d.ts +15 -0
- package/dist/core/schema/SchemaGenerator.d.ts.map +1 -0
- package/dist/core/schema/SchemaGenerator.js +192 -0
- package/dist/core/schema/SchemaGenerator.js.map +1 -0
- package/dist/core/schema/SchemaUtils.d.ts +26 -0
- package/dist/core/schema/SchemaUtils.d.ts.map +1 -0
- package/dist/core/schema/SchemaUtils.js +85 -0
- package/dist/core/schema/SchemaUtils.js.map +1 -0
- package/dist/core/schema/ToonDescriptionGenerator.d.ts +3 -0
- package/dist/core/schema/ToonDescriptionGenerator.d.ts.map +1 -0
- package/dist/core/schema/ToonDescriptionGenerator.js +65 -0
- package/dist/core/schema/ToonDescriptionGenerator.js.map +1 -0
- package/dist/core/schema/index.d.ts +7 -0
- package/dist/core/schema/index.d.ts.map +1 -0
- package/dist/core/schema/index.js +7 -0
- package/dist/core/schema/index.js.map +1 -0
- package/dist/core/serialization/JsonSerializer.d.ts +71 -0
- package/dist/core/serialization/JsonSerializer.d.ts.map +1 -0
- package/dist/core/serialization/JsonSerializer.js +192 -0
- package/dist/core/serialization/JsonSerializer.js.map +1 -0
- package/dist/core/serialization/index.d.ts +7 -0
- package/dist/core/serialization/index.d.ts.map +1 -0
- package/dist/core/serialization/index.js +7 -0
- package/dist/core/serialization/index.js.map +1 -0
- package/dist/core/types.d.ts +303 -0
- package/dist/core/types.d.ts.map +1 -0
- package/dist/core/types.js +17 -0
- package/dist/core/types.js.map +1 -0
- package/dist/domain/Annotations.d.ts +42 -0
- package/dist/domain/Annotations.d.ts.map +1 -0
- package/dist/domain/Annotations.js +16 -0
- package/dist/domain/Annotations.js.map +1 -0
- package/dist/domain/BaseModel.d.ts +50 -0
- package/dist/domain/BaseModel.d.ts.map +1 -0
- package/dist/domain/BaseModel.js +41 -0
- package/dist/domain/BaseModel.js.map +1 -0
- package/dist/domain/Group.d.ts +99 -0
- package/dist/domain/Group.d.ts.map +1 -0
- package/dist/domain/Group.js +172 -0
- package/dist/domain/Group.js.map +1 -0
- package/dist/domain/GroupItem.d.ts +46 -0
- package/dist/domain/GroupItem.d.ts.map +1 -0
- package/dist/domain/GroupItem.js +58 -0
- package/dist/domain/GroupItem.js.map +1 -0
- package/dist/domain/Icon.d.ts +41 -0
- package/dist/domain/Icon.d.ts.map +1 -0
- package/dist/domain/Icon.js +15 -0
- package/dist/domain/Icon.js.map +1 -0
- package/dist/domain/Prompt.d.ts +49 -0
- package/dist/domain/Prompt.d.ts.map +1 -0
- package/dist/domain/Prompt.js +59 -0
- package/dist/domain/Prompt.js.map +1 -0
- package/dist/domain/PromptArgument.d.ts +23 -0
- package/dist/domain/PromptArgument.d.ts.map +1 -0
- package/dist/domain/PromptArgument.js +27 -0
- package/dist/domain/PromptArgument.js.map +1 -0
- package/dist/domain/Resource.d.ts +37 -0
- package/dist/domain/Resource.d.ts.map +1 -0
- package/dist/domain/Resource.js +39 -0
- package/dist/domain/Resource.js.map +1 -0
- package/dist/domain/Role.d.ts +23 -0
- package/dist/domain/Role.d.ts.map +1 -0
- package/dist/domain/Role.js +24 -0
- package/dist/domain/Role.js.map +1 -0
- package/dist/domain/Tool.d.ts +39 -0
- package/dist/domain/Tool.d.ts.map +1 -0
- package/dist/domain/Tool.js +41 -0
- package/dist/domain/Tool.js.map +1 -0
- package/dist/domain/ToolAnnotations.d.ts +48 -0
- package/dist/domain/ToolAnnotations.d.ts.map +1 -0
- package/dist/domain/ToolAnnotations.js +15 -0
- package/dist/domain/ToolAnnotations.js.map +1 -0
- package/dist/domain/index.d.ts +16 -0
- package/dist/domain/index.d.ts.map +1 -0
- package/dist/domain/index.js +13 -0
- package/dist/domain/index.js.map +1 -0
- package/dist/domain/utils.d.ts +6 -0
- package/dist/domain/utils.d.ts.map +1 -0
- package/dist/domain/utils.js +12 -0
- package/dist/domain/utils.js.map +1 -0
- package/dist/edge-stub.d.ts +73 -0
- package/dist/edge-stub.d.ts.map +1 -0
- package/dist/edge-stub.js +83 -0
- package/dist/edge-stub.js.map +1 -0
- package/dist/exposition/ExpositionCompiler.d.ts +66 -0
- package/dist/exposition/ExpositionCompiler.d.ts.map +1 -0
- package/dist/exposition/ExpositionCompiler.js +279 -0
- package/dist/exposition/ExpositionCompiler.js.map +1 -0
- package/dist/exposition/index.d.ts +4 -0
- package/dist/exposition/index.d.ts.map +1 -0
- package/dist/exposition/index.js +2 -0
- package/dist/exposition/index.js.map +1 -0
- package/dist/exposition/types.d.ts +58 -0
- package/dist/exposition/types.d.ts.map +1 -0
- package/dist/exposition/types.js +11 -0
- package/dist/exposition/types.js.map +1 -0
- package/dist/fsm/StateMachineGate.d.ts +294 -0
- package/dist/fsm/StateMachineGate.d.ts.map +1 -0
- package/dist/fsm/StateMachineGate.js +400 -0
- package/dist/fsm/StateMachineGate.js.map +1 -0
- package/dist/index.d.ts +148 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +112 -0
- package/dist/index.js.map +1 -0
- package/dist/introspection/BehaviorDigest.d.ts +112 -0
- package/dist/introspection/BehaviorDigest.d.ts.map +1 -0
- package/dist/introspection/BehaviorDigest.js +149 -0
- package/dist/introspection/BehaviorDigest.js.map +1 -0
- package/dist/introspection/CapabilityLockfile.d.ts +261 -0
- package/dist/introspection/CapabilityLockfile.d.ts.map +1 -0
- package/dist/introspection/CapabilityLockfile.js +395 -0
- package/dist/introspection/CapabilityLockfile.js.map +1 -0
- package/dist/introspection/ContractAwareSelfHealing.d.ts +90 -0
- package/dist/introspection/ContractAwareSelfHealing.d.ts.map +1 -0
- package/dist/introspection/ContractAwareSelfHealing.js +132 -0
- package/dist/introspection/ContractAwareSelfHealing.js.map +1 -0
- package/dist/introspection/ContractDiff.d.ts +91 -0
- package/dist/introspection/ContractDiff.d.ts.map +1 -0
- package/dist/introspection/ContractDiff.js +466 -0
- package/dist/introspection/ContractDiff.js.map +1 -0
- package/dist/introspection/CryptoAttestation.d.ts +143 -0
- package/dist/introspection/CryptoAttestation.d.ts.map +1 -0
- package/dist/introspection/CryptoAttestation.js +192 -0
- package/dist/introspection/CryptoAttestation.js.map +1 -0
- package/dist/introspection/EntitlementScanner.d.ts +177 -0
- package/dist/introspection/EntitlementScanner.d.ts.map +1 -0
- package/dist/introspection/EntitlementScanner.js +459 -0
- package/dist/introspection/EntitlementScanner.js.map +1 -0
- package/dist/introspection/GovernanceObserver.d.ts +88 -0
- package/dist/introspection/GovernanceObserver.d.ts.map +1 -0
- package/dist/introspection/GovernanceObserver.js +136 -0
- package/dist/introspection/GovernanceObserver.js.map +1 -0
- package/dist/introspection/IntrospectionResource.d.ts +20 -0
- package/dist/introspection/IntrospectionResource.d.ts.map +1 -0
- package/dist/introspection/IntrospectionResource.js +112 -0
- package/dist/introspection/IntrospectionResource.js.map +1 -0
- package/dist/introspection/ManifestCompiler.d.ts +33 -0
- package/dist/introspection/ManifestCompiler.d.ts.map +1 -0
- package/dist/introspection/ManifestCompiler.js +88 -0
- package/dist/introspection/ManifestCompiler.js.map +1 -0
- package/dist/introspection/SemanticProbe.d.ts +207 -0
- package/dist/introspection/SemanticProbe.d.ts.map +1 -0
- package/dist/introspection/SemanticProbe.js +274 -0
- package/dist/introspection/SemanticProbe.js.map +1 -0
- package/dist/introspection/TokenEconomics.d.ts +210 -0
- package/dist/introspection/TokenEconomics.d.ts.map +1 -0
- package/dist/introspection/TokenEconomics.js +292 -0
- package/dist/introspection/TokenEconomics.js.map +1 -0
- package/dist/introspection/ToolContract.d.ts +161 -0
- package/dist/introspection/ToolContract.d.ts.map +1 -0
- package/dist/introspection/ToolContract.js +218 -0
- package/dist/introspection/ToolContract.js.map +1 -0
- package/dist/introspection/canonicalize.d.ts +35 -0
- package/dist/introspection/canonicalize.d.ts.map +1 -0
- package/dist/introspection/canonicalize.js +72 -0
- package/dist/introspection/canonicalize.js.map +1 -0
- package/dist/introspection/index.d.ts +26 -0
- package/dist/introspection/index.d.ts.map +1 -0
- package/dist/introspection/index.js +24 -0
- package/dist/introspection/index.js.map +1 -0
- package/dist/introspection/types.d.ts +120 -0
- package/dist/introspection/types.d.ts.map +1 -0
- package/dist/introspection/types.js +13 -0
- package/dist/introspection/types.js.map +1 -0
- package/dist/observability/DebugObserver.d.ts +185 -0
- package/dist/observability/DebugObserver.d.ts.map +1 -0
- package/dist/observability/DebugObserver.js +102 -0
- package/dist/observability/DebugObserver.js.map +1 -0
- package/dist/observability/TelemetryBus.d.ts +88 -0
- package/dist/observability/TelemetryBus.d.ts.map +1 -0
- package/dist/observability/TelemetryBus.js +463 -0
- package/dist/observability/TelemetryBus.js.map +1 -0
- package/dist/observability/TelemetryEvent.d.ts +177 -0
- package/dist/observability/TelemetryEvent.d.ts.map +1 -0
- package/dist/observability/TelemetryEvent.js +2 -0
- package/dist/observability/TelemetryEvent.js.map +1 -0
- package/dist/observability/Tracing.d.ts +155 -0
- package/dist/observability/Tracing.d.ts.map +1 -0
- package/dist/observability/Tracing.js +67 -0
- package/dist/observability/Tracing.js.map +1 -0
- package/dist/observability/index.d.ts +13 -0
- package/dist/observability/index.d.ts.map +1 -0
- package/dist/observability/index.js +12 -0
- package/dist/observability/index.js.map +1 -0
- package/dist/presenter/PostProcessor.d.ts +52 -0
- package/dist/presenter/PostProcessor.d.ts.map +1 -0
- package/dist/presenter/PostProcessor.js +148 -0
- package/dist/presenter/PostProcessor.js.map +1 -0
- package/dist/presenter/Presenter.d.ts +575 -0
- package/dist/presenter/Presenter.d.ts.map +1 -0
- package/dist/presenter/Presenter.js +768 -0
- package/dist/presenter/Presenter.js.map +1 -0
- package/dist/presenter/PresenterValidationError.d.ts +42 -0
- package/dist/presenter/PresenterValidationError.d.ts.map +1 -0
- package/dist/presenter/PresenterValidationError.js +55 -0
- package/dist/presenter/PresenterValidationError.js.map +1 -0
- package/dist/presenter/RedactEngine.d.ts +110 -0
- package/dist/presenter/RedactEngine.d.ts.map +1 -0
- package/dist/presenter/RedactEngine.js +128 -0
- package/dist/presenter/RedactEngine.js.map +1 -0
- package/dist/presenter/ResponseBuilder.d.ts +262 -0
- package/dist/presenter/ResponseBuilder.d.ts.map +1 -0
- package/dist/presenter/ResponseBuilder.js +374 -0
- package/dist/presenter/ResponseBuilder.js.map +1 -0
- package/dist/presenter/SelectUtils.d.ts +78 -0
- package/dist/presenter/SelectUtils.d.ts.map +1 -0
- package/dist/presenter/SelectUtils.js +141 -0
- package/dist/presenter/SelectUtils.js.map +1 -0
- package/dist/presenter/ZodDescriptionExtractor.d.ts +54 -0
- package/dist/presenter/ZodDescriptionExtractor.d.ts.map +1 -0
- package/dist/presenter/ZodDescriptionExtractor.js +131 -0
- package/dist/presenter/ZodDescriptionExtractor.js.map +1 -0
- package/dist/presenter/definePresenter.d.ts +193 -0
- package/dist/presenter/definePresenter.d.ts.map +1 -0
- package/dist/presenter/definePresenter.js +99 -0
- package/dist/presenter/definePresenter.js.map +1 -0
- package/dist/presenter/index.d.ts +21 -0
- package/dist/presenter/index.d.ts.map +1 -0
- package/dist/presenter/index.js +28 -0
- package/dist/presenter/index.js.map +1 -0
- package/dist/presenter/suggest.d.ts +39 -0
- package/dist/presenter/suggest.d.ts.map +1 -0
- package/dist/presenter/suggest.js +41 -0
- package/dist/presenter/suggest.js.map +1 -0
- package/dist/presenter/typeHelpers.d.ts +147 -0
- package/dist/presenter/typeHelpers.d.ts.map +1 -0
- package/dist/presenter/typeHelpers.js +152 -0
- package/dist/presenter/typeHelpers.js.map +1 -0
- package/dist/presenter/ui.d.ts +205 -0
- package/dist/presenter/ui.d.ts.map +1 -0
- package/dist/presenter/ui.js +222 -0
- package/dist/presenter/ui.js.map +1 -0
- package/dist/prompt/CursorCodec.d.ts +43 -0
- package/dist/prompt/CursorCodec.d.ts.map +1 -0
- package/dist/prompt/CursorCodec.js +171 -0
- package/dist/prompt/CursorCodec.js.map +1 -0
- package/dist/prompt/FluentPromptBuilder.d.ts +155 -0
- package/dist/prompt/FluentPromptBuilder.d.ts.map +1 -0
- package/dist/prompt/FluentPromptBuilder.js +195 -0
- package/dist/prompt/FluentPromptBuilder.js.map +1 -0
- package/dist/prompt/HydrationSandbox.d.ts +55 -0
- package/dist/prompt/HydrationSandbox.d.ts.map +1 -0
- package/dist/prompt/HydrationSandbox.js +122 -0
- package/dist/prompt/HydrationSandbox.js.map +1 -0
- package/dist/prompt/PromptExecutionPipeline.d.ts +61 -0
- package/dist/prompt/PromptExecutionPipeline.d.ts.map +1 -0
- package/dist/prompt/PromptExecutionPipeline.js +177 -0
- package/dist/prompt/PromptExecutionPipeline.js.map +1 -0
- package/dist/prompt/PromptMessage.d.ts +133 -0
- package/dist/prompt/PromptMessage.d.ts.map +1 -0
- package/dist/prompt/PromptMessage.js +182 -0
- package/dist/prompt/PromptMessage.js.map +1 -0
- package/dist/prompt/PromptRegistry.d.ts +236 -0
- package/dist/prompt/PromptRegistry.d.ts.map +1 -0
- package/dist/prompt/PromptRegistry.js +399 -0
- package/dist/prompt/PromptRegistry.js.map +1 -0
- package/dist/prompt/definePrompt.d.ts +111 -0
- package/dist/prompt/definePrompt.d.ts.map +1 -0
- package/dist/prompt/definePrompt.js +130 -0
- package/dist/prompt/definePrompt.js.map +1 -0
- package/dist/prompt/index.d.ts +12 -0
- package/dist/prompt/index.d.ts.map +1 -0
- package/dist/prompt/index.js +13 -0
- package/dist/prompt/index.js.map +1 -0
- package/dist/prompt/types.d.ts +425 -0
- package/dist/prompt/types.d.ts.map +1 -0
- package/dist/prompt/types.js +19 -0
- package/dist/prompt/types.js.map +1 -0
- package/dist/sandbox/SandboxEngine.d.ts +225 -0
- package/dist/sandbox/SandboxEngine.d.ts.map +1 -0
- package/dist/sandbox/SandboxEngine.js +437 -0
- package/dist/sandbox/SandboxEngine.js.map +1 -0
- package/dist/sandbox/SandboxGuard.d.ts +47 -0
- package/dist/sandbox/SandboxGuard.d.ts.map +1 -0
- package/dist/sandbox/SandboxGuard.js +127 -0
- package/dist/sandbox/SandboxGuard.js.map +1 -0
- package/dist/sandbox/index.d.ts +23 -0
- package/dist/sandbox/index.d.ts.map +1 -0
- package/dist/sandbox/index.js +26 -0
- package/dist/sandbox/index.js.map +1 -0
- package/dist/server/DevServer.d.ts +120 -0
- package/dist/server/DevServer.d.ts.map +1 -0
- package/dist/server/DevServer.js +252 -0
- package/dist/server/DevServer.js.map +1 -0
- package/dist/server/ServerAttachment.d.ts +354 -0
- package/dist/server/ServerAttachment.d.ts.map +1 -0
- package/dist/server/ServerAttachment.js +709 -0
- package/dist/server/ServerAttachment.js.map +1 -0
- package/dist/server/ServerResolver.d.ts +24 -0
- package/dist/server/ServerResolver.d.ts.map +1 -0
- package/dist/server/ServerResolver.js +50 -0
- package/dist/server/ServerResolver.js.map +1 -0
- package/dist/server/autoDiscover.d.ts +75 -0
- package/dist/server/autoDiscover.d.ts.map +1 -0
- package/dist/server/autoDiscover.js +164 -0
- package/dist/server/autoDiscover.js.map +1 -0
- package/dist/server/index.d.ts +12 -0
- package/dist/server/index.d.ts.map +1 -0
- package/dist/server/index.js +11 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/startServer.d.ts +81 -0
- package/dist/server/startServer.d.ts.map +1 -0
- package/dist/server/startServer.js +143 -0
- package/dist/server/startServer.js.map +1 -0
- package/dist/state-sync/CausalEngine.d.ts +28 -0
- package/dist/state-sync/CausalEngine.d.ts.map +1 -0
- package/dist/state-sync/CausalEngine.js +17 -0
- package/dist/state-sync/CausalEngine.js.map +1 -0
- package/dist/state-sync/DescriptionDecorator.d.ts +31 -0
- package/dist/state-sync/DescriptionDecorator.d.ts.map +1 -0
- package/dist/state-sync/DescriptionDecorator.js +38 -0
- package/dist/state-sync/DescriptionDecorator.js.map +1 -0
- package/dist/state-sync/GlobMatcher.d.ts +29 -0
- package/dist/state-sync/GlobMatcher.d.ts.map +1 -0
- package/dist/state-sync/GlobMatcher.js +79 -0
- package/dist/state-sync/GlobMatcher.js.map +1 -0
- package/dist/state-sync/PolicyEngine.d.ts +75 -0
- package/dist/state-sync/PolicyEngine.d.ts.map +1 -0
- package/dist/state-sync/PolicyEngine.js +107 -0
- package/dist/state-sync/PolicyEngine.js.map +1 -0
- package/dist/state-sync/PolicyValidator.d.ts +67 -0
- package/dist/state-sync/PolicyValidator.d.ts.map +1 -0
- package/dist/state-sync/PolicyValidator.js +122 -0
- package/dist/state-sync/PolicyValidator.js.map +1 -0
- package/dist/state-sync/ResponseDecorator.d.ts +33 -0
- package/dist/state-sync/ResponseDecorator.d.ts.map +1 -0
- package/dist/state-sync/ResponseDecorator.js +20 -0
- package/dist/state-sync/ResponseDecorator.js.map +1 -0
- package/dist/state-sync/StateSyncBuilder.d.ts +77 -0
- package/dist/state-sync/StateSyncBuilder.d.ts.map +1 -0
- package/dist/state-sync/StateSyncBuilder.js +129 -0
- package/dist/state-sync/StateSyncBuilder.js.map +1 -0
- package/dist/state-sync/StateSyncLayer.d.ts +107 -0
- package/dist/state-sync/StateSyncLayer.d.ts.map +1 -0
- package/dist/state-sync/StateSyncLayer.js +158 -0
- package/dist/state-sync/StateSyncLayer.js.map +1 -0
- package/dist/state-sync/index.d.ts +27 -0
- package/dist/state-sync/index.d.ts.map +1 -0
- package/dist/state-sync/index.js +27 -0
- package/dist/state-sync/index.js.map +1 -0
- package/dist/state-sync/types.d.ts +174 -0
- package/dist/state-sync/types.d.ts.map +1 -0
- package/dist/state-sync/types.js +17 -0
- package/dist/state-sync/types.js.map +1 -0
- package/dist/testing/MvaMetaSymbol.d.ts +45 -0
- package/dist/testing/MvaMetaSymbol.d.ts.map +1 -0
- package/dist/testing/MvaMetaSymbol.js +34 -0
- package/dist/testing/MvaMetaSymbol.js.map +1 -0
- package/package.json +153 -0
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StateMachineGate — Temporal Anti-Hallucination Engine
|
|
3
|
+
*
|
|
4
|
+
* Zero-hallucination tool ordering via finite state machines.
|
|
5
|
+
* Tools bound to FSM states are **physically removed** from
|
|
6
|
+
* `tools/list` when the current state doesn't match — the LLM
|
|
7
|
+
* cannot call what doesn't exist in its reality.
|
|
8
|
+
*
|
|
9
|
+
* Powered by XState v5 (optional peer dependency, lazy-loaded).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const gate = new StateMachineGate({
|
|
14
|
+
* id: 'checkout',
|
|
15
|
+
* initial: 'empty',
|
|
16
|
+
* states: {
|
|
17
|
+
* empty: { on: { ADD_ITEM: 'has_items' } },
|
|
18
|
+
* has_items: { on: { CHECKOUT: 'payment', CLEAR: 'empty' } },
|
|
19
|
+
* payment: { on: { PAY: 'confirmed', CANCEL: 'has_items' } },
|
|
20
|
+
* confirmed: { on: { RESET: 'empty' } },
|
|
21
|
+
* },
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* gate.bindTool('cart_add_item', ['empty', 'has_items'], 'ADD_ITEM');
|
|
25
|
+
* gate.bindTool('cart_checkout', ['has_items'], 'CHECKOUT');
|
|
26
|
+
* gate.bindTool('cart_pay', ['payment'], 'PAY');
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* ## Architecture
|
|
30
|
+
*
|
|
31
|
+
* ```
|
|
32
|
+
* ┌──────────────────────────────────────────────────────┐
|
|
33
|
+
* │ Boot: StateMachineGate(config) │
|
|
34
|
+
* │ │
|
|
35
|
+
* │ XState createMachine() → createActor() → .start() │
|
|
36
|
+
* │ │ │
|
|
37
|
+
* │ ▼ │
|
|
38
|
+
* │ tools/list request │
|
|
39
|
+
* │ │ │
|
|
40
|
+
* │ ▼ │
|
|
41
|
+
* │ gate.getVisibleTools(allTools) │
|
|
42
|
+
* │ → filter by current FSM state │
|
|
43
|
+
* │ → return only allowed tools │
|
|
44
|
+
* │ │ │
|
|
45
|
+
* │ ▼ │
|
|
46
|
+
* │ tools/call succeeds │
|
|
47
|
+
* │ → gate.transition(event) │
|
|
48
|
+
* │ → FSM advances → list_changed notification │
|
|
49
|
+
* └──────────────────────────────────────────────────────┘
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @module
|
|
53
|
+
*/
|
|
54
|
+
/**
|
|
55
|
+
* Configuration for a finite state machine definition.
|
|
56
|
+
*
|
|
57
|
+
* Uses the same shape as XState v5 `createMachine()` config,
|
|
58
|
+
* but only the subset needed for tool gating.
|
|
59
|
+
*/
|
|
60
|
+
export interface FsmConfig {
|
|
61
|
+
/** Unique identifier for this state machine */
|
|
62
|
+
id?: string;
|
|
63
|
+
/** Initial state when a new session starts */
|
|
64
|
+
initial: string;
|
|
65
|
+
/** State definitions with event transitions */
|
|
66
|
+
states: Record<string, {
|
|
67
|
+
/** Events that trigger transitions: `{ EVENT_NAME: 'target_state' }` */
|
|
68
|
+
on?: Record<string, string>;
|
|
69
|
+
/** Set to `'final'` to mark a terminal state */
|
|
70
|
+
type?: 'final';
|
|
71
|
+
}>;
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* External state store for serverless/edge deployments.
|
|
75
|
+
*
|
|
76
|
+
* When MCP runs over Streamable HTTP (Vercel, Cloudflare Workers),
|
|
77
|
+
* there is no persistent process — FSM state must be externalized.
|
|
78
|
+
* The `sessionId` comes from the `Mcp-Session-Id` header.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* const fsmStore: FsmStateStore = {
|
|
83
|
+
* load: async (sessionId) => {
|
|
84
|
+
* const data = await redis.get(`fsm:${sessionId}`);
|
|
85
|
+
* return data ? JSON.parse(data) : undefined;
|
|
86
|
+
* },
|
|
87
|
+
* save: async (sessionId, snapshot) => {
|
|
88
|
+
* await redis.set(`fsm:${sessionId}`, JSON.stringify(snapshot), { EX: 3600 });
|
|
89
|
+
* },
|
|
90
|
+
* };
|
|
91
|
+
* ```
|
|
92
|
+
*/
|
|
93
|
+
export interface FsmStateStore {
|
|
94
|
+
/** Load persisted FSM state for a session. Returns `undefined` for new sessions. */
|
|
95
|
+
load(sessionId: string): Promise<FsmSnapshot | undefined>;
|
|
96
|
+
/** Save FSM state after a transition. */
|
|
97
|
+
save(sessionId: string, snapshot: FsmSnapshot): Promise<void>;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Serializable FSM state snapshot for persistence.
|
|
101
|
+
*/
|
|
102
|
+
export interface FsmSnapshot {
|
|
103
|
+
/** Current FSM state value */
|
|
104
|
+
state: string;
|
|
105
|
+
/** Timestamp of last transition */
|
|
106
|
+
updatedAt: number;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Result of a state transition attempt.
|
|
110
|
+
*/
|
|
111
|
+
export interface TransitionResult {
|
|
112
|
+
/** Whether the FSM state actually changed */
|
|
113
|
+
changed: boolean;
|
|
114
|
+
/** The FSM state before the transition */
|
|
115
|
+
previousState: string;
|
|
116
|
+
/** The FSM state after the transition */
|
|
117
|
+
currentState: string;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Reset the XState module cache so that `loadXState()` will
|
|
121
|
+
* re-attempt the dynamic import on next call.
|
|
122
|
+
*
|
|
123
|
+
* Intended for test environments where `xstate` availability
|
|
124
|
+
* may change between test suites via dynamic mocking.
|
|
125
|
+
*
|
|
126
|
+
* @public
|
|
127
|
+
*/
|
|
128
|
+
export declare function resetXStateCache(): void;
|
|
129
|
+
/**
|
|
130
|
+
* Pre-load `xstate` at boot time (optional optimization).
|
|
131
|
+
*
|
|
132
|
+
* Call during server startup to avoid the first-use dynamic import latency.
|
|
133
|
+
* Returns `true` if xstate is available, `false` otherwise.
|
|
134
|
+
*
|
|
135
|
+
* @example
|
|
136
|
+
* ```typescript
|
|
137
|
+
* import { initFsmEngine } from 'vurb';
|
|
138
|
+
* const available = await initFsmEngine();
|
|
139
|
+
* if (!available) console.warn('xstate not installed — FSM gating disabled');
|
|
140
|
+
* ```
|
|
141
|
+
*/
|
|
142
|
+
export declare function initFsmEngine(): Promise<boolean>;
|
|
143
|
+
/**
|
|
144
|
+
* Temporal Anti-Hallucination Engine.
|
|
145
|
+
*
|
|
146
|
+
* Wraps an XState v5 finite state machine and controls which MCP tools
|
|
147
|
+
* are visible to the LLM based on the current workflow state.
|
|
148
|
+
*
|
|
149
|
+
* **Hard constraint**: Tools not bound to the current state are removed
|
|
150
|
+
* from `tools/list` entirely — the LLM physically cannot call them.
|
|
151
|
+
*
|
|
152
|
+
* **Soft constraint**: `suggestActions` (HATEOAS) continues to recommend
|
|
153
|
+
* the best next action within the visible set. Zero conflict.
|
|
154
|
+
*/
|
|
155
|
+
export declare class StateMachineGate {
|
|
156
|
+
private readonly _config;
|
|
157
|
+
private readonly _bindings;
|
|
158
|
+
private readonly _transitionCallbacks;
|
|
159
|
+
private _actor;
|
|
160
|
+
private _currentState;
|
|
161
|
+
private _initialized;
|
|
162
|
+
/**
|
|
163
|
+
* @param config - FSM definition (states, transitions, initial state)
|
|
164
|
+
*/
|
|
165
|
+
constructor(config: FsmConfig);
|
|
166
|
+
/**
|
|
167
|
+
* Initialize the XState actor (lazy-loaded).
|
|
168
|
+
*
|
|
169
|
+
* Called automatically on first use. Can be called explicitly
|
|
170
|
+
* at boot time for eager initialization.
|
|
171
|
+
*
|
|
172
|
+
* @returns `true` if XState is available and the actor started
|
|
173
|
+
*/
|
|
174
|
+
init(): Promise<boolean>;
|
|
175
|
+
/**
|
|
176
|
+
* Bind a tool to specific FSM states.
|
|
177
|
+
*
|
|
178
|
+
* The tool will only appear in `tools/list` when the FSM
|
|
179
|
+
* is in one of the specified states.
|
|
180
|
+
*
|
|
181
|
+
* @param toolName - MCP tool name (flat: `cart_add_item`, grouped: `cart`)
|
|
182
|
+
* @param allowedStates - FSM states where this tool is visible
|
|
183
|
+
* @param transitionEvent - Event to send on successful execution (optional)
|
|
184
|
+
* @returns `this` for chaining
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* gate.bindTool('cart_add_item', ['empty', 'has_items'], 'ADD_ITEM');
|
|
189
|
+
* gate.bindTool('cart_checkout', ['has_items'], 'CHECKOUT');
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
bindTool(toolName: string, allowedStates: string[], transitionEvent?: string): StateMachineGate;
|
|
193
|
+
/**
|
|
194
|
+
* Get the current FSM state.
|
|
195
|
+
*/
|
|
196
|
+
get currentState(): string;
|
|
197
|
+
/**
|
|
198
|
+
* Check if a specific tool is allowed in the current FSM state.
|
|
199
|
+
*
|
|
200
|
+
* Tools **not** registered via `bindTool()` are always visible
|
|
201
|
+
* (ungated — they don't participate in FSM gating).
|
|
202
|
+
*
|
|
203
|
+
* @param toolName - MCP tool name to check
|
|
204
|
+
* @returns `true` if the tool should appear in `tools/list`
|
|
205
|
+
*/
|
|
206
|
+
isToolAllowed(toolName: string): boolean;
|
|
207
|
+
/**
|
|
208
|
+
* Filter a list of tool names by the current FSM state.
|
|
209
|
+
*
|
|
210
|
+
* @param toolNames - All registered tool names
|
|
211
|
+
* @returns Only the tools allowed in the current state
|
|
212
|
+
*/
|
|
213
|
+
getVisibleToolNames(toolNames: string[]): string[];
|
|
214
|
+
/**
|
|
215
|
+
* Get the transition event for a tool (if any).
|
|
216
|
+
*
|
|
217
|
+
* @param toolName - MCP tool name
|
|
218
|
+
* @returns The event string, or `undefined` if no transition is bound
|
|
219
|
+
*/
|
|
220
|
+
getTransitionEvent(toolName: string): string | undefined;
|
|
221
|
+
/**
|
|
222
|
+
* Check if any tools are bound to this FSM gate.
|
|
223
|
+
*
|
|
224
|
+
* @returns `true` if at least one tool is state-gated
|
|
225
|
+
*/
|
|
226
|
+
get hasBindings(): boolean;
|
|
227
|
+
/**
|
|
228
|
+
* Send an event to the FSM, potentially triggering a state transition.
|
|
229
|
+
*
|
|
230
|
+
* @param eventType - The event to send (e.g. `'ADD_ITEM'`, `'CHECKOUT'`)
|
|
231
|
+
* @returns Result indicating whether the state changed
|
|
232
|
+
*/
|
|
233
|
+
transition(eventType: string): Promise<TransitionResult>;
|
|
234
|
+
/**
|
|
235
|
+
* Manual state transition fallback when XState is not installed.
|
|
236
|
+
*
|
|
237
|
+
* Reads the FSM config directly to determine the next state.
|
|
238
|
+
* This provides basic FSM gating even without `xstate` installed,
|
|
239
|
+
* though without XState's guards, actions, and advanced features.
|
|
240
|
+
*
|
|
241
|
+
* @internal
|
|
242
|
+
*/
|
|
243
|
+
private _transitionManual;
|
|
244
|
+
/**
|
|
245
|
+
* Register a callback that fires when the FSM state changes.
|
|
246
|
+
*
|
|
247
|
+
* Used by `ServerAttachment` to emit `notifications/tools/list_changed`
|
|
248
|
+
* when a state transition makes tools appear or disappear.
|
|
249
|
+
*
|
|
250
|
+
* @param callback - Function to call on state change
|
|
251
|
+
* @returns Unsubscribe function
|
|
252
|
+
*/
|
|
253
|
+
onTransition(callback: () => void): () => void;
|
|
254
|
+
/**
|
|
255
|
+
* Create a serializable snapshot of the current FSM state.
|
|
256
|
+
*
|
|
257
|
+
* Used with `FsmStateStore` for serverless deployments where
|
|
258
|
+
* FSM state must survive across request boundaries.
|
|
259
|
+
*
|
|
260
|
+
* @returns Serializable snapshot
|
|
261
|
+
*/
|
|
262
|
+
snapshot(): FsmSnapshot;
|
|
263
|
+
/**
|
|
264
|
+
* Restore FSM state from a persisted snapshot.
|
|
265
|
+
*
|
|
266
|
+
* Resets the XState actor (if running) so the next `transition()`
|
|
267
|
+
* re-initializes the machine starting from the restored state.
|
|
268
|
+
* This ensures restore → transition works correctly in
|
|
269
|
+
* serverless/edge deployments (Vercel, Cloudflare Workers).
|
|
270
|
+
*
|
|
271
|
+
* @param snap - Previously saved snapshot
|
|
272
|
+
*/
|
|
273
|
+
restore(snap: FsmSnapshot): void;
|
|
274
|
+
/**
|
|
275
|
+
* Create a lightweight clone of this gate with the same config
|
|
276
|
+
* and bindings but independent mutable state.
|
|
277
|
+
*
|
|
278
|
+
* Used in serverless/edge deployments where concurrent requests
|
|
279
|
+
* must not share `_currentState`. Each request gets its own clone,
|
|
280
|
+
* restores session state into it, transitions, and saves — without
|
|
281
|
+
* interfering with other concurrent requests.
|
|
282
|
+
*
|
|
283
|
+
* The clone starts **uninitialized** (no XState actor) so the first
|
|
284
|
+
* `transition()` call will create a fresh actor from the cloned state.
|
|
285
|
+
*
|
|
286
|
+
* @returns A new `StateMachineGate` with identical config and bindings
|
|
287
|
+
*/
|
|
288
|
+
clone(): StateMachineGate;
|
|
289
|
+
/**
|
|
290
|
+
* Stop the XState actor and release resources.
|
|
291
|
+
*/
|
|
292
|
+
dispose(): void;
|
|
293
|
+
}
|
|
294
|
+
//# sourceMappingURL=StateMachineGate.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"StateMachineGate.d.ts","sourceRoot":"","sources":["../../src/fsm/StateMachineGate.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoDG;AAIH;;;;;GAKG;AACH,MAAM,WAAW,SAAS;IACtB,+CAA+C;IAC/C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,8CAA8C;IAC9C,OAAO,EAAE,MAAM,CAAC;IAChB,+CAA+C;IAC/C,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE;QACnB,wEAAwE;QACxE,EAAE,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC5B,gDAAgD;QAChD,IAAI,CAAC,EAAE,OAAO,CAAC;KAClB,CAAC,CAAC;CACN;AAcD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,WAAW,aAAa;IAC1B,oFAAoF;IACpF,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,GAAG,SAAS,CAAC,CAAC;IAC1D,yCAAyC;IACzC,IAAI,CAAC,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACjE;AAED;;GAEG;AACH,MAAM,WAAW,WAAW;IACxB,8BAA8B;IAC9B,KAAK,EAAE,MAAM,CAAC;IACd,mCAAmC;IACnC,SAAS,EAAE,MAAM,CAAC;CACrB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B,6CAA6C;IAC7C,OAAO,EAAE,OAAO,CAAC;IACjB,0CAA0C;IAC1C,aAAa,EAAE,MAAM,CAAC;IACtB,yCAAyC;IACzC,YAAY,EAAE,MAAM,CAAC;CACxB;AA6BD;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,IAAI,IAAI,CAGvC;AAED;;;;;;;;;;;;GAYG;AACH,wBAAsB,aAAa,IAAI,OAAO,CAAC,OAAO,CAAC,CAEtD;AAID;;;;;;;;;;;GAWG;AACH,qBAAa,gBAAgB;IACzB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAY;IACpC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAqC;IAC/D,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAyB;IAC9D,OAAO,CAAC,MAAM,CAAuC;IACrD,OAAO,CAAC,aAAa,CAAS;IAC9B,OAAO,CAAC,YAAY,CAAS;IAE7B;;OAEG;gBACS,MAAM,EAAE,SAAS;IAO7B;;;;;;;OAOG;IACG,IAAI,IAAI,OAAO,CAAC,OAAO,CAAC;IAwC9B;;;;;;;;;;;;;;;;OAgBG;IACH,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,gBAAgB;IAW/F;;OAEG;IACH,IAAI,YAAY,IAAI,MAAM,CAEzB;IAED;;;;;;;;OAQG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAMxC;;;;;OAKG;IACH,mBAAmB,CAAC,SAAS,EAAE,MAAM,EAAE,GAAG,MAAM,EAAE;IAIlD;;;;;OAKG;IACH,kBAAkB,CAAC,QAAQ,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAIxD;;;;OAIG;IACH,IAAI,WAAW,IAAI,OAAO,CAEzB;IAID;;;;;OAKG;IACG,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAuB9D;;;;;;;;OAQG;IACH,OAAO,CAAC,iBAAiB;IAkBzB;;;;;;;;OAQG;IACH,YAAY,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAU9C;;;;;;;OAOG;IACH,QAAQ,IAAI,WAAW;IAOvB;;;;;;;;;OASG;IACH,OAAO,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI;IAiBhC;;;;;;;;;;;;;OAaG;IACH,KAAK,IAAI,gBAAgB;IAczB;;OAEG;IACH,OAAO,IAAI,IAAI;CAOlB"}
|
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* StateMachineGate — Temporal Anti-Hallucination Engine
|
|
3
|
+
*
|
|
4
|
+
* Zero-hallucination tool ordering via finite state machines.
|
|
5
|
+
* Tools bound to FSM states are **physically removed** from
|
|
6
|
+
* `tools/list` when the current state doesn't match — the LLM
|
|
7
|
+
* cannot call what doesn't exist in its reality.
|
|
8
|
+
*
|
|
9
|
+
* Powered by XState v5 (optional peer dependency, lazy-loaded).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* const gate = new StateMachineGate({
|
|
14
|
+
* id: 'checkout',
|
|
15
|
+
* initial: 'empty',
|
|
16
|
+
* states: {
|
|
17
|
+
* empty: { on: { ADD_ITEM: 'has_items' } },
|
|
18
|
+
* has_items: { on: { CHECKOUT: 'payment', CLEAR: 'empty' } },
|
|
19
|
+
* payment: { on: { PAY: 'confirmed', CANCEL: 'has_items' } },
|
|
20
|
+
* confirmed: { on: { RESET: 'empty' } },
|
|
21
|
+
* },
|
|
22
|
+
* });
|
|
23
|
+
*
|
|
24
|
+
* gate.bindTool('cart_add_item', ['empty', 'has_items'], 'ADD_ITEM');
|
|
25
|
+
* gate.bindTool('cart_checkout', ['has_items'], 'CHECKOUT');
|
|
26
|
+
* gate.bindTool('cart_pay', ['payment'], 'PAY');
|
|
27
|
+
* ```
|
|
28
|
+
*
|
|
29
|
+
* ## Architecture
|
|
30
|
+
*
|
|
31
|
+
* ```
|
|
32
|
+
* ┌──────────────────────────────────────────────────────┐
|
|
33
|
+
* │ Boot: StateMachineGate(config) │
|
|
34
|
+
* │ │
|
|
35
|
+
* │ XState createMachine() → createActor() → .start() │
|
|
36
|
+
* │ │ │
|
|
37
|
+
* │ ▼ │
|
|
38
|
+
* │ tools/list request │
|
|
39
|
+
* │ │ │
|
|
40
|
+
* │ ▼ │
|
|
41
|
+
* │ gate.getVisibleTools(allTools) │
|
|
42
|
+
* │ → filter by current FSM state │
|
|
43
|
+
* │ → return only allowed tools │
|
|
44
|
+
* │ │ │
|
|
45
|
+
* │ ▼ │
|
|
46
|
+
* │ tools/call succeeds │
|
|
47
|
+
* │ → gate.transition(event) │
|
|
48
|
+
* │ → FSM advances → list_changed notification │
|
|
49
|
+
* └──────────────────────────────────────────────────────┘
|
|
50
|
+
* ```
|
|
51
|
+
*
|
|
52
|
+
* @module
|
|
53
|
+
*/
|
|
54
|
+
// ── Lazy XState Loading ──────────────────────────────────
|
|
55
|
+
/** Cached XState module reference */
|
|
56
|
+
let xstateModule = null;
|
|
57
|
+
/** Whether we already attempted to load XState */
|
|
58
|
+
let xstateLoadAttempted = false;
|
|
59
|
+
/**
|
|
60
|
+
* Lazily load the `xstate` module.
|
|
61
|
+
*
|
|
62
|
+
* Returns `null` if `xstate` is not installed — the framework
|
|
63
|
+
* degrades gracefully (all tools remain visible, no gating).
|
|
64
|
+
*
|
|
65
|
+
* @internal
|
|
66
|
+
*/
|
|
67
|
+
async function loadXState() {
|
|
68
|
+
if (xstateLoadAttempted)
|
|
69
|
+
return xstateModule;
|
|
70
|
+
xstateLoadAttempted = true;
|
|
71
|
+
try {
|
|
72
|
+
xstateModule = await import('xstate');
|
|
73
|
+
return xstateModule;
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return null;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Reset the XState module cache so that `loadXState()` will
|
|
81
|
+
* re-attempt the dynamic import on next call.
|
|
82
|
+
*
|
|
83
|
+
* Intended for test environments where `xstate` availability
|
|
84
|
+
* may change between test suites via dynamic mocking.
|
|
85
|
+
*
|
|
86
|
+
* @public
|
|
87
|
+
*/
|
|
88
|
+
export function resetXStateCache() {
|
|
89
|
+
xstateLoadAttempted = false;
|
|
90
|
+
xstateModule = null;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Pre-load `xstate` at boot time (optional optimization).
|
|
94
|
+
*
|
|
95
|
+
* Call during server startup to avoid the first-use dynamic import latency.
|
|
96
|
+
* Returns `true` if xstate is available, `false` otherwise.
|
|
97
|
+
*
|
|
98
|
+
* @example
|
|
99
|
+
* ```typescript
|
|
100
|
+
* import { initFsmEngine } from 'vurb';
|
|
101
|
+
* const available = await initFsmEngine();
|
|
102
|
+
* if (!available) console.warn('xstate not installed — FSM gating disabled');
|
|
103
|
+
* ```
|
|
104
|
+
*/
|
|
105
|
+
export async function initFsmEngine() {
|
|
106
|
+
return (await loadXState()) !== null;
|
|
107
|
+
}
|
|
108
|
+
// ── StateMachineGate ─────────────────────────────────────
|
|
109
|
+
/**
|
|
110
|
+
* Temporal Anti-Hallucination Engine.
|
|
111
|
+
*
|
|
112
|
+
* Wraps an XState v5 finite state machine and controls which MCP tools
|
|
113
|
+
* are visible to the LLM based on the current workflow state.
|
|
114
|
+
*
|
|
115
|
+
* **Hard constraint**: Tools not bound to the current state are removed
|
|
116
|
+
* from `tools/list` entirely — the LLM physically cannot call them.
|
|
117
|
+
*
|
|
118
|
+
* **Soft constraint**: `suggestActions` (HATEOAS) continues to recommend
|
|
119
|
+
* the best next action within the visible set. Zero conflict.
|
|
120
|
+
*/
|
|
121
|
+
export class StateMachineGate {
|
|
122
|
+
_config;
|
|
123
|
+
_bindings = new Map();
|
|
124
|
+
_transitionCallbacks = [];
|
|
125
|
+
_actor = null;
|
|
126
|
+
_currentState;
|
|
127
|
+
_initialized = false;
|
|
128
|
+
/**
|
|
129
|
+
* @param config - FSM definition (states, transitions, initial state)
|
|
130
|
+
*/
|
|
131
|
+
constructor(config) {
|
|
132
|
+
this._config = config;
|
|
133
|
+
this._currentState = config.initial;
|
|
134
|
+
}
|
|
135
|
+
// ── Initialization ───────────────────────────────────
|
|
136
|
+
/**
|
|
137
|
+
* Initialize the XState actor (lazy-loaded).
|
|
138
|
+
*
|
|
139
|
+
* Called automatically on first use. Can be called explicitly
|
|
140
|
+
* at boot time for eager initialization.
|
|
141
|
+
*
|
|
142
|
+
* @returns `true` if XState is available and the actor started
|
|
143
|
+
*/
|
|
144
|
+
async init() {
|
|
145
|
+
if (this._initialized)
|
|
146
|
+
return this._actor !== null;
|
|
147
|
+
const xstate = await loadXState();
|
|
148
|
+
if (!xstate) {
|
|
149
|
+
this._initialized = true;
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
// Use _currentState as initial — it may have been set by restore()
|
|
154
|
+
// before init() was called (serverless/edge: restore → transition → init)
|
|
155
|
+
const machineConfig = this._currentState !== this._config.initial
|
|
156
|
+
? { ...this._config, initial: this._currentState }
|
|
157
|
+
: this._config;
|
|
158
|
+
const machine = xstate.createMachine(machineConfig);
|
|
159
|
+
this._actor = xstate.createActor(machine);
|
|
160
|
+
this._actor.subscribe((snapshot) => {
|
|
161
|
+
const newState = typeof snapshot.value === 'string'
|
|
162
|
+
? snapshot.value
|
|
163
|
+
: Object.keys(snapshot.value)[0] ?? this._config.initial;
|
|
164
|
+
if (newState !== this._currentState) {
|
|
165
|
+
this._currentState = newState;
|
|
166
|
+
for (const cb of this._transitionCallbacks) {
|
|
167
|
+
cb();
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
this._actor.start();
|
|
172
|
+
this._initialized = true;
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
catch {
|
|
176
|
+
this._initialized = true;
|
|
177
|
+
return false;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
// ── Tool Binding ─────────────────────────────────────
|
|
181
|
+
/**
|
|
182
|
+
* Bind a tool to specific FSM states.
|
|
183
|
+
*
|
|
184
|
+
* The tool will only appear in `tools/list` when the FSM
|
|
185
|
+
* is in one of the specified states.
|
|
186
|
+
*
|
|
187
|
+
* @param toolName - MCP tool name (flat: `cart_add_item`, grouped: `cart`)
|
|
188
|
+
* @param allowedStates - FSM states where this tool is visible
|
|
189
|
+
* @param transitionEvent - Event to send on successful execution (optional)
|
|
190
|
+
* @returns `this` for chaining
|
|
191
|
+
*
|
|
192
|
+
* @example
|
|
193
|
+
* ```typescript
|
|
194
|
+
* gate.bindTool('cart_add_item', ['empty', 'has_items'], 'ADD_ITEM');
|
|
195
|
+
* gate.bindTool('cart_checkout', ['has_items'], 'CHECKOUT');
|
|
196
|
+
* ```
|
|
197
|
+
*/
|
|
198
|
+
bindTool(toolName, allowedStates, transitionEvent) {
|
|
199
|
+
const binding = {
|
|
200
|
+
allowedStates: new Set(allowedStates),
|
|
201
|
+
};
|
|
202
|
+
if (transitionEvent !== undefined)
|
|
203
|
+
binding.transitionEvent = transitionEvent;
|
|
204
|
+
this._bindings.set(toolName, binding);
|
|
205
|
+
return this;
|
|
206
|
+
}
|
|
207
|
+
// ── State Queries ────────────────────────────────────
|
|
208
|
+
/**
|
|
209
|
+
* Get the current FSM state.
|
|
210
|
+
*/
|
|
211
|
+
get currentState() {
|
|
212
|
+
return this._currentState;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Check if a specific tool is allowed in the current FSM state.
|
|
216
|
+
*
|
|
217
|
+
* Tools **not** registered via `bindTool()` are always visible
|
|
218
|
+
* (ungated — they don't participate in FSM gating).
|
|
219
|
+
*
|
|
220
|
+
* @param toolName - MCP tool name to check
|
|
221
|
+
* @returns `true` if the tool should appear in `tools/list`
|
|
222
|
+
*/
|
|
223
|
+
isToolAllowed(toolName) {
|
|
224
|
+
const binding = this._bindings.get(toolName);
|
|
225
|
+
if (!binding)
|
|
226
|
+
return true; // Ungated tools are always visible
|
|
227
|
+
return binding.allowedStates.has(this._currentState);
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Filter a list of tool names by the current FSM state.
|
|
231
|
+
*
|
|
232
|
+
* @param toolNames - All registered tool names
|
|
233
|
+
* @returns Only the tools allowed in the current state
|
|
234
|
+
*/
|
|
235
|
+
getVisibleToolNames(toolNames) {
|
|
236
|
+
return toolNames.filter(name => this.isToolAllowed(name));
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Get the transition event for a tool (if any).
|
|
240
|
+
*
|
|
241
|
+
* @param toolName - MCP tool name
|
|
242
|
+
* @returns The event string, or `undefined` if no transition is bound
|
|
243
|
+
*/
|
|
244
|
+
getTransitionEvent(toolName) {
|
|
245
|
+
return this._bindings.get(toolName)?.transitionEvent;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Check if any tools are bound to this FSM gate.
|
|
249
|
+
*
|
|
250
|
+
* @returns `true` if at least one tool is state-gated
|
|
251
|
+
*/
|
|
252
|
+
get hasBindings() {
|
|
253
|
+
return this._bindings.size > 0;
|
|
254
|
+
}
|
|
255
|
+
// ── State Transitions ────────────────────────────────
|
|
256
|
+
/**
|
|
257
|
+
* Send an event to the FSM, potentially triggering a state transition.
|
|
258
|
+
*
|
|
259
|
+
* @param eventType - The event to send (e.g. `'ADD_ITEM'`, `'CHECKOUT'`)
|
|
260
|
+
* @returns Result indicating whether the state changed
|
|
261
|
+
*/
|
|
262
|
+
async transition(eventType) {
|
|
263
|
+
const previousState = this._currentState;
|
|
264
|
+
// Ensure initialized
|
|
265
|
+
if (!this._initialized) {
|
|
266
|
+
await this.init();
|
|
267
|
+
}
|
|
268
|
+
if (this._actor) {
|
|
269
|
+
// XState actor handles the transition
|
|
270
|
+
this._actor.send({ type: eventType });
|
|
271
|
+
}
|
|
272
|
+
else {
|
|
273
|
+
// Fallback: manual transition without XState
|
|
274
|
+
this._transitionManual(eventType);
|
|
275
|
+
}
|
|
276
|
+
return {
|
|
277
|
+
changed: this._currentState !== previousState,
|
|
278
|
+
previousState,
|
|
279
|
+
currentState: this._currentState,
|
|
280
|
+
};
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* Manual state transition fallback when XState is not installed.
|
|
284
|
+
*
|
|
285
|
+
* Reads the FSM config directly to determine the next state.
|
|
286
|
+
* This provides basic FSM gating even without `xstate` installed,
|
|
287
|
+
* though without XState's guards, actions, and advanced features.
|
|
288
|
+
*
|
|
289
|
+
* @internal
|
|
290
|
+
*/
|
|
291
|
+
_transitionManual(eventType) {
|
|
292
|
+
const stateConfig = this._config.states[this._currentState];
|
|
293
|
+
if (!stateConfig?.on)
|
|
294
|
+
return;
|
|
295
|
+
const target = stateConfig.on[eventType];
|
|
296
|
+
if (target && this._config.states[target]) {
|
|
297
|
+
const previousState = this._currentState;
|
|
298
|
+
this._currentState = target;
|
|
299
|
+
if (previousState !== this._currentState) {
|
|
300
|
+
for (const cb of this._transitionCallbacks) {
|
|
301
|
+
cb();
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
// ── Transition Callbacks ─────────────────────────────
|
|
307
|
+
/**
|
|
308
|
+
* Register a callback that fires when the FSM state changes.
|
|
309
|
+
*
|
|
310
|
+
* Used by `ServerAttachment` to emit `notifications/tools/list_changed`
|
|
311
|
+
* when a state transition makes tools appear or disappear.
|
|
312
|
+
*
|
|
313
|
+
* @param callback - Function to call on state change
|
|
314
|
+
* @returns Unsubscribe function
|
|
315
|
+
*/
|
|
316
|
+
onTransition(callback) {
|
|
317
|
+
this._transitionCallbacks.push(callback);
|
|
318
|
+
return () => {
|
|
319
|
+
const idx = this._transitionCallbacks.indexOf(callback);
|
|
320
|
+
if (idx >= 0)
|
|
321
|
+
this._transitionCallbacks.splice(idx, 1);
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
// ── Persistence (Serverless/Edge) ────────────────────
|
|
325
|
+
/**
|
|
326
|
+
* Create a serializable snapshot of the current FSM state.
|
|
327
|
+
*
|
|
328
|
+
* Used with `FsmStateStore` for serverless deployments where
|
|
329
|
+
* FSM state must survive across request boundaries.
|
|
330
|
+
*
|
|
331
|
+
* @returns Serializable snapshot
|
|
332
|
+
*/
|
|
333
|
+
snapshot() {
|
|
334
|
+
return {
|
|
335
|
+
state: this._currentState,
|
|
336
|
+
updatedAt: Date.now(),
|
|
337
|
+
};
|
|
338
|
+
}
|
|
339
|
+
/**
|
|
340
|
+
* Restore FSM state from a persisted snapshot.
|
|
341
|
+
*
|
|
342
|
+
* Resets the XState actor (if running) so the next `transition()`
|
|
343
|
+
* re-initializes the machine starting from the restored state.
|
|
344
|
+
* This ensures restore → transition works correctly in
|
|
345
|
+
* serverless/edge deployments (Vercel, Cloudflare Workers).
|
|
346
|
+
*
|
|
347
|
+
* @param snap - Previously saved snapshot
|
|
348
|
+
*/
|
|
349
|
+
restore(snap) {
|
|
350
|
+
if (this._config.states[snap.state]) {
|
|
351
|
+
this._currentState = snap.state;
|
|
352
|
+
// If the actor is already running, stop it and mark as
|
|
353
|
+
// uninitialized so the next transition() call will re-create
|
|
354
|
+
// the machine starting from the restored state.
|
|
355
|
+
if (this._actor) {
|
|
356
|
+
this._actor.stop();
|
|
357
|
+
this._actor = null;
|
|
358
|
+
this._initialized = false;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
// ── Clone (Serverless Isolation) ─────────────────────
|
|
363
|
+
/**
|
|
364
|
+
* Create a lightweight clone of this gate with the same config
|
|
365
|
+
* and bindings but independent mutable state.
|
|
366
|
+
*
|
|
367
|
+
* Used in serverless/edge deployments where concurrent requests
|
|
368
|
+
* must not share `_currentState`. Each request gets its own clone,
|
|
369
|
+
* restores session state into it, transitions, and saves — without
|
|
370
|
+
* interfering with other concurrent requests.
|
|
371
|
+
*
|
|
372
|
+
* The clone starts **uninitialized** (no XState actor) so the first
|
|
373
|
+
* `transition()` call will create a fresh actor from the cloned state.
|
|
374
|
+
*
|
|
375
|
+
* @returns A new `StateMachineGate` with identical config and bindings
|
|
376
|
+
*/
|
|
377
|
+
clone() {
|
|
378
|
+
const copy = new StateMachineGate(this._config);
|
|
379
|
+
for (const [toolName, binding] of this._bindings) {
|
|
380
|
+
copy._bindings.set(toolName, {
|
|
381
|
+
allowedStates: new Set(binding.allowedStates),
|
|
382
|
+
...(binding.transitionEvent !== undefined ? { transitionEvent: binding.transitionEvent } : {}),
|
|
383
|
+
});
|
|
384
|
+
}
|
|
385
|
+
copy._currentState = this._currentState;
|
|
386
|
+
return copy;
|
|
387
|
+
}
|
|
388
|
+
// ── Cleanup ──────────────────────────────────────────
|
|
389
|
+
/**
|
|
390
|
+
* Stop the XState actor and release resources.
|
|
391
|
+
*/
|
|
392
|
+
dispose() {
|
|
393
|
+
if (this._actor) {
|
|
394
|
+
this._actor.stop();
|
|
395
|
+
this._actor = null;
|
|
396
|
+
}
|
|
397
|
+
this._transitionCallbacks.length = 0;
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
//# sourceMappingURL=StateMachineGate.js.map
|