@exaudeus/workrail 0.8.6 → 0.9.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 +157 -403
- package/dist/application/services/enhanced-loop-validator.d.ts +2 -2
- package/dist/application/services/enhanced-loop-validator.js +12 -2
- package/dist/application/services/validation-engine.d.ts +8 -29
- package/dist/application/services/validation-engine.js +38 -21
- package/dist/application/services/workflow-compiler.d.ts +18 -0
- package/dist/application/services/workflow-compiler.js +79 -0
- package/dist/application/services/workflow-interpreter.d.ts +31 -0
- package/dist/application/services/workflow-interpreter.js +280 -0
- package/dist/application/services/workflow-service.d.ts +34 -32
- package/dist/application/services/workflow-service.js +93 -425
- package/dist/application/use-cases/get-next-step.d.ts +6 -10
- package/dist/application/use-cases/get-next-step.js +2 -6
- package/dist/application/use-cases/get-workflow.d.ts +8 -6
- package/dist/application/use-cases/get-workflow.js +42 -33
- package/dist/application/use-cases/list-workflows.d.ts +3 -3
- package/dist/application/use-cases/validate-step-output.d.ts +4 -4
- package/dist/application/use-cases/validate-workflow-file.d.ts +46 -0
- package/dist/application/use-cases/validate-workflow-file.js +57 -0
- package/dist/cli/commands/cleanup.d.ts +8 -0
- package/dist/cli/commands/cleanup.js +20 -0
- package/dist/cli/commands/index.d.ts +7 -0
- package/dist/cli/commands/index.js +21 -0
- package/dist/cli/commands/init.d.ts +11 -0
- package/dist/cli/commands/init.js +49 -0
- package/dist/cli/commands/list.d.ts +9 -0
- package/dist/cli/commands/list.js +34 -0
- package/dist/cli/commands/migrate.d.ts +78 -0
- package/dist/cli/commands/migrate.js +248 -0
- package/dist/cli/commands/sources.d.ts +21 -0
- package/dist/cli/commands/sources.js +87 -0
- package/dist/cli/commands/start.d.ts +8 -0
- package/dist/cli/commands/start.js +16 -0
- package/dist/cli/commands/validate.d.ts +6 -0
- package/dist/cli/commands/validate.js +55 -0
- package/dist/cli/interpret-result.d.ts +4 -0
- package/dist/cli/interpret-result.js +24 -0
- package/dist/cli/output-formatter.d.ts +10 -0
- package/dist/cli/output-formatter.js +97 -0
- package/dist/cli/types/cli-result.d.ts +23 -0
- package/dist/cli/types/cli-result.js +30 -0
- package/dist/cli/types/exit-code.d.ts +13 -0
- package/dist/cli/types/exit-code.js +23 -0
- package/dist/cli/types/index.d.ts +4 -0
- package/dist/cli/types/index.js +11 -0
- package/dist/cli.js +84 -278
- package/dist/config/app-config.d.ts +40 -0
- package/dist/config/app-config.js +58 -0
- package/dist/config/feature-flags.d.ts +10 -2
- package/dist/config/feature-flags.js +74 -12
- package/dist/core/error-handler.d.ts +18 -27
- package/dist/core/error-handler.js +24 -218
- package/dist/di/container.d.ts +12 -0
- package/dist/di/container.js +244 -0
- package/dist/di/tokens.d.ts +40 -0
- package/dist/di/tokens.js +42 -0
- package/dist/domain/execution/error.d.ts +32 -0
- package/dist/domain/execution/error.js +24 -0
- package/dist/domain/execution/event.d.ts +7 -0
- package/dist/domain/execution/event.js +11 -0
- package/dist/domain/execution/ids.d.ts +9 -0
- package/dist/domain/execution/ids.js +9 -0
- package/dist/domain/execution/result.d.ts +3 -0
- package/dist/domain/execution/result.js +10 -0
- package/dist/domain/execution/state.d.ts +57 -0
- package/dist/domain/execution/state.js +28 -0
- package/dist/errors/app-error.d.ts +23 -0
- package/dist/errors/factories.d.ts +6 -0
- package/dist/errors/factories.js +21 -0
- package/dist/errors/formatter.d.ts +2 -0
- package/dist/errors/formatter.js +32 -0
- package/dist/errors/index.d.ts +3 -0
- package/dist/errors/index.js +7 -0
- package/dist/index.d.ts +6 -1
- package/dist/index.js +10 -25
- package/dist/infrastructure/index.d.ts +0 -1
- package/dist/infrastructure/index.js +0 -1
- package/dist/infrastructure/session/DashboardHeartbeat.d.ts +8 -0
- package/dist/infrastructure/session/DashboardHeartbeat.js +39 -0
- package/dist/infrastructure/session/DashboardLockRelease.d.ts +2 -0
- package/dist/infrastructure/session/DashboardLockRelease.js +29 -0
- package/dist/infrastructure/session/HttpServer.d.ts +25 -6
- package/dist/infrastructure/session/HttpServer.js +245 -90
- package/dist/infrastructure/session/SessionDataNormalizer.js +12 -2
- package/dist/infrastructure/session/SessionDataValidator.js +12 -2
- package/dist/infrastructure/session/SessionManager.d.ts +5 -3
- package/dist/infrastructure/session/SessionManager.js +52 -6
- package/dist/infrastructure/storage/caching-workflow-storage.d.ts +30 -6
- package/dist/infrastructure/storage/caching-workflow-storage.js +105 -23
- package/dist/infrastructure/storage/enhanced-multi-source-workflow-storage.d.ts +13 -9
- package/dist/infrastructure/storage/enhanced-multi-source-workflow-storage.js +45 -39
- package/dist/infrastructure/storage/file-workflow-storage.d.ts +10 -8
- package/dist/infrastructure/storage/file-workflow-storage.js +48 -56
- package/dist/infrastructure/storage/git-workflow-storage.d.ts +7 -22
- package/dist/infrastructure/storage/git-workflow-storage.js +48 -103
- package/dist/infrastructure/storage/in-memory-storage.d.ts +10 -6
- package/dist/infrastructure/storage/in-memory-storage.js +18 -13
- package/dist/infrastructure/storage/plugin-workflow-storage.d.ts +6 -18
- package/dist/infrastructure/storage/plugin-workflow-storage.js +29 -51
- package/dist/infrastructure/storage/remote-workflow-storage.d.ts +8 -17
- package/dist/infrastructure/storage/remote-workflow-storage.js +33 -156
- package/dist/infrastructure/storage/schema-validating-workflow-storage.d.ts +21 -13
- package/dist/infrastructure/storage/schema-validating-workflow-storage.js +86 -24
- package/dist/infrastructure/storage/storage.d.ts +7 -5
- package/dist/infrastructure/storage/storage.js +7 -6
- package/dist/manifest.json +1093 -0
- package/dist/mcp/error-mapper.d.ts +9 -0
- package/dist/mcp/error-mapper.js +66 -0
- package/dist/mcp/handlers/session.d.ts +34 -0
- package/dist/mcp/handlers/session.js +135 -0
- package/dist/mcp/handlers/v2-workflow.d.ts +4 -0
- package/dist/mcp/handlers/v2-workflow.js +112 -0
- package/dist/mcp/handlers/workflow.d.ts +45 -0
- package/dist/mcp/handlers/workflow.js +167 -0
- package/dist/mcp/index.d.ts +16 -0
- package/dist/mcp/index.js +51 -0
- package/dist/mcp/output-schemas.d.ts +317 -0
- package/dist/mcp/output-schemas.js +91 -0
- package/dist/mcp/server.d.ts +3 -0
- package/dist/mcp/server.js +258 -0
- package/dist/mcp/tool-description-provider.d.ts +16 -0
- package/dist/mcp/tool-description-provider.js +43 -0
- package/dist/mcp/tool-descriptions.d.ts +2 -0
- package/dist/mcp/tool-descriptions.js +109 -0
- package/dist/mcp/tool-factory.d.ts +23 -0
- package/dist/mcp/tool-factory.js +14 -0
- package/dist/mcp/tools.d.ts +156 -0
- package/dist/mcp/tools.js +196 -0
- package/dist/mcp/types/tool-description-types.d.ts +8 -0
- package/dist/mcp/types/tool-description-types.js +24 -0
- package/dist/mcp/types.d.ts +25 -0
- package/dist/mcp/types.js +15 -0
- package/dist/mcp/v2/tool-registry.d.ts +11 -0
- package/dist/mcp/v2/tool-registry.js +26 -0
- package/dist/mcp/v2/tools.d.ts +20 -0
- package/dist/mcp/v2/tools.js +17 -0
- package/dist/mcp/validation/bounded-json.d.ts +3 -0
- package/dist/mcp/validation/bounded-json.js +22 -0
- package/dist/mcp/validation/workflow-next-prevalidate.d.ts +9 -0
- package/dist/mcp/validation/workflow-next-prevalidate.js +83 -0
- package/dist/mcp/zod-to-json-schema.d.ts +17 -0
- package/dist/mcp/zod-to-json-schema.js +134 -0
- package/dist/mcp-server.d.ts +1 -1
- package/dist/mcp-server.js +6 -424
- package/dist/runtime/adapters/in-memory-shutdown-events.d.ts +6 -0
- package/dist/runtime/adapters/in-memory-shutdown-events.js +20 -0
- package/dist/runtime/adapters/node-process-signals.d.ts +4 -0
- package/dist/runtime/adapters/node-process-signals.js +11 -0
- package/dist/runtime/adapters/node-process-terminator.d.ts +4 -0
- package/dist/runtime/adapters/node-process-terminator.js +17 -0
- package/dist/runtime/adapters/noop-process-signals.d.ts +4 -0
- package/dist/runtime/adapters/noop-process-signals.js +8 -0
- package/dist/runtime/adapters/throwing-process-terminator.d.ts +4 -0
- package/dist/runtime/adapters/throwing-process-terminator.js +9 -0
- package/dist/runtime/assert-never.d.ts +1 -0
- package/dist/runtime/assert-never.js +6 -0
- package/dist/runtime/brand.d.ts +5 -0
- package/dist/runtime/ports/process-signals.d.ts +4 -0
- package/dist/runtime/ports/process-signals.js +2 -0
- package/dist/runtime/ports/process-terminator.d.ts +8 -0
- package/dist/runtime/ports/process-terminator.js +2 -0
- package/dist/runtime/ports/shutdown-events.d.ts +11 -0
- package/dist/runtime/ports/shutdown-events.js +2 -0
- package/dist/runtime/process-lifecycle-policy.d.ts +5 -0
- package/dist/runtime/process-lifecycle-policy.js +2 -0
- package/dist/runtime/result.d.ts +17 -0
- package/dist/runtime/result.js +31 -0
- package/dist/runtime/runtime-mode.d.ts +9 -0
- package/dist/runtime/runtime-mode.js +2 -0
- package/dist/types/storage.d.ts +16 -5
- package/dist/types/storage.js +8 -0
- package/dist/types/validation.d.ts +27 -0
- package/dist/types/validation.js +10 -0
- package/dist/types/workflow-definition.d.ts +63 -0
- package/dist/types/workflow-definition.js +33 -0
- package/dist/types/workflow-source.d.ts +51 -0
- package/dist/types/workflow-source.js +128 -0
- package/dist/types/workflow.d.ts +28 -0
- package/dist/types/workflow.js +96 -0
- package/dist/utils/workflow-init.d.ts +1 -0
- package/dist/utils/workflow-init.js +38 -0
- package/dist/v2/durable-core/canonical/hashing.d.ts +11 -0
- package/dist/v2/durable-core/canonical/hashing.js +13 -0
- package/dist/v2/durable-core/canonical/jcs.d.ts +11 -0
- package/dist/v2/durable-core/canonical/jcs.js +65 -0
- package/dist/v2/durable-core/canonical/json-types.d.ts +6 -0
- package/dist/v2/durable-core/canonical/json-types.js +2 -0
- package/dist/v2/durable-core/canonical/json-zod.d.ts +2 -0
- package/dist/v2/durable-core/canonical/json-zod.js +7 -0
- package/dist/v2/durable-core/canonical/jsonl.d.ts +4 -0
- package/dist/v2/durable-core/canonical/jsonl.js +13 -0
- package/dist/v2/durable-core/ids/index.d.ts +23 -0
- package/dist/v2/durable-core/ids/index.js +46 -0
- package/dist/v2/durable-core/schemas/compiled-workflow/index.d.ts +47 -0
- package/dist/v2/durable-core/schemas/compiled-workflow/index.js +17 -0
- package/dist/v2/durable-core/schemas/session/events.d.ts +1812 -0
- package/dist/v2/durable-core/schemas/session/events.js +328 -0
- package/dist/v2/durable-core/schemas/session/index.d.ts +2 -0
- package/dist/v2/durable-core/schemas/session/index.js +8 -0
- package/dist/v2/durable-core/schemas/session/manifest.d.ts +57 -0
- package/dist/v2/durable-core/schemas/session/manifest.js +30 -0
- package/dist/v2/infra/local/crypto/index.d.ts +5 -0
- package/dist/v2/infra/local/crypto/index.js +12 -0
- package/dist/v2/infra/local/data-dir/index.d.ts +13 -0
- package/dist/v2/infra/local/data-dir/index.js +69 -0
- package/dist/v2/infra/local/fs/index.d.ts +26 -0
- package/dist/v2/infra/local/fs/index.js +156 -0
- package/dist/v2/infra/local/pinned-workflow-store/index.d.ts +11 -0
- package/dist/v2/infra/local/pinned-workflow-store/index.js +85 -0
- package/dist/v2/infra/local/session-lock/index.d.ts +12 -0
- package/dist/v2/infra/local/session-lock/index.js +44 -0
- package/dist/v2/infra/local/session-store/index.d.ts +22 -0
- package/dist/v2/infra/local/session-store/index.js +358 -0
- package/dist/v2/infra/local/sha256/index.d.ts +5 -0
- package/dist/v2/infra/local/sha256/index.js +12 -0
- package/dist/v2/ports/data-dir.port.d.ts +9 -0
- package/dist/v2/ports/data-dir.port.js +2 -0
- package/dist/v2/ports/fs.port.d.ts +41 -0
- package/dist/v2/ports/fs.port.js +2 -0
- package/dist/v2/ports/pinned-workflow-store.port.d.ts +11 -0
- package/dist/v2/ports/pinned-workflow-store.port.js +2 -0
- package/dist/v2/ports/session-event-log-store.port.d.ts +37 -0
- package/dist/v2/ports/session-event-log-store.port.js +2 -0
- package/dist/v2/ports/session-lock.port.d.ts +23 -0
- package/dist/v2/ports/session-lock.port.js +2 -0
- package/dist/v2/ports/sha256.port.d.ts +4 -0
- package/dist/v2/ports/sha256.port.js +2 -0
- package/dist/v2/projections/advance-outcomes.d.ts +23 -0
- package/dist/v2/projections/advance-outcomes.js +23 -0
- package/dist/v2/projections/capabilities.d.ts +27 -0
- package/dist/v2/projections/capabilities.js +33 -0
- package/dist/v2/projections/gaps.d.ts +29 -0
- package/dist/v2/projections/gaps.js +49 -0
- package/dist/v2/projections/node-outputs.d.ts +34 -0
- package/dist/v2/projections/node-outputs.js +73 -0
- package/dist/v2/projections/preferences.d.ts +28 -0
- package/dist/v2/projections/preferences.js +50 -0
- package/dist/v2/projections/run-dag.d.ts +42 -0
- package/dist/v2/projections/run-dag.js +186 -0
- package/dist/v2/projections/run-status-signals.d.ts +26 -0
- package/dist/v2/projections/run-status-signals.js +49 -0
- package/dist/v2/projections/session-health.d.ts +18 -0
- package/dist/v2/projections/session-health.js +15 -0
- package/dist/v2/read-only/v1-to-v2-shim.d.ts +3 -0
- package/dist/v2/read-only/v1-to-v2-shim.js +38 -0
- package/package.json +35 -10
- package/spec/mcp-api-v1.0.md +5 -5
- package/web/assets/services/data-normalizer.js +17 -2
- package/web/assets/services/pattern-recognizer.js +3 -1
- package/web/assets/services/session-data.js +13 -8
- package/web/assets/utils/formatters.js +34 -23
- package/workflows/CHANGELOG-bug-investigation.md +4 -4
- package/workflows/coding-task-workflow-agentic.json +262 -0
- package/workflows/design-thinking-workflow-autonomous.agentic.json +215 -0
- package/workflows/design-thinking-workflow.json +198 -0
- package/workflows/mr-review-workflow.agentic.json +538 -0
- package/workflows/routines/context-gathering.json +0 -4
- package/dist/application/app.d.ts +0 -29
- package/dist/application/app.d.ts.map +0 -1
- package/dist/application/app.js +0 -114
- package/dist/application/app.js.map +0 -1
- package/dist/application/decorators/simple-output-decorator.d.ts +0 -8
- package/dist/application/decorators/simple-output-decorator.js +0 -89
- package/dist/application/services/classification-engine.d.ts +0 -33
- package/dist/application/services/classification-engine.js +0 -258
- package/dist/application/services/compression-service.d.ts +0 -20
- package/dist/application/services/compression-service.js +0 -312
- package/dist/application/services/context-management-service.d.ts +0 -38
- package/dist/application/services/context-management-service.js +0 -301
- package/dist/application/services/context-optimizer.d.ts +0 -11
- package/dist/application/services/context-optimizer.js +0 -62
- package/dist/application/services/context-persistence-service.d.ts +0 -45
- package/dist/application/services/context-persistence-service.js +0 -273
- package/dist/application/services/documentation-service.d.ts +0 -20
- package/dist/application/services/documentation-service.js +0 -155
- package/dist/application/services/enhanced-error-service.d.ts.map +0 -1
- package/dist/application/services/enhanced-error-service.js.map +0 -1
- package/dist/application/services/loop-context-optimizer.d.ts +0 -8
- package/dist/application/services/loop-context-optimizer.js +0 -114
- package/dist/application/services/loop-execution-context.d.ts +0 -23
- package/dist/application/services/loop-execution-context.js +0 -188
- package/dist/application/services/loop-step-resolver.d.ts +0 -11
- package/dist/application/services/loop-step-resolver.js +0 -70
- package/dist/application/services/validation-engine.d.ts.map +0 -1
- package/dist/application/services/validation-engine.js.map +0 -1
- package/dist/application/services/workflow-service.d.ts.map +0 -1
- package/dist/application/services/workflow-service.js.map +0 -1
- package/dist/application/use-cases/get-next-step.d.ts.map +0 -1
- package/dist/application/use-cases/get-next-step.js.map +0 -1
- package/dist/application/use-cases/get-workflow-docs.d.ts +0 -4
- package/dist/application/use-cases/get-workflow-docs.js +0 -12
- package/dist/application/use-cases/get-workflow.d.ts.map +0 -1
- package/dist/application/use-cases/get-workflow.js.map +0 -1
- package/dist/application/use-cases/get-workrail-help.d.ts +0 -4
- package/dist/application/use-cases/get-workrail-help.js +0 -12
- package/dist/application/use-cases/list-workflows.d.ts.map +0 -1
- package/dist/application/use-cases/list-workflows.js.map +0 -1
- package/dist/application/use-cases/validate-step-output.d.ts.map +0 -1
- package/dist/application/use-cases/validate-step-output.js.map +0 -1
- package/dist/application/use-cases/validate-workflow-json.d.ts.map +0 -1
- package/dist/application/use-cases/validate-workflow-json.js.map +0 -1
- package/dist/application/validation.d.ts.map +0 -1
- package/dist/application/validation.js.map +0 -1
- package/dist/cli/migrate-workflow.d.ts +0 -22
- package/dist/cli/migrate-workflow.js +0 -196
- package/dist/cli.d.ts.map +0 -1
- package/dist/cli.js.map +0 -1
- package/dist/container.d.ts +0 -15
- package/dist/container.d.ts.map +0 -1
- package/dist/container.js +0 -25
- package/dist/container.js.map +0 -1
- package/dist/core/error-handler.d.ts.map +0 -1
- package/dist/core/error-handler.js.map +0 -1
- package/dist/domain/index.d.ts +0 -2
- package/dist/domain/index.d.ts.map +0 -1
- package/dist/domain/index.js +0 -18
- package/dist/domain/index.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/infrastructure/index.d.ts.map +0 -1
- package/dist/infrastructure/index.js.map +0 -1
- package/dist/infrastructure/rpc/handler.d.ts +0 -17
- package/dist/infrastructure/rpc/handler.d.ts.map +0 -1
- package/dist/infrastructure/rpc/handler.js +0 -78
- package/dist/infrastructure/rpc/handler.js.map +0 -1
- package/dist/infrastructure/rpc/index.d.ts +0 -1
- package/dist/infrastructure/rpc/index.d.ts.map +0 -1
- package/dist/infrastructure/rpc/index.js +0 -17
- package/dist/infrastructure/rpc/index.js.map +0 -1
- package/dist/infrastructure/rpc/server.d.ts +0 -3
- package/dist/infrastructure/rpc/server.d.ts.map +0 -1
- package/dist/infrastructure/rpc/server.js +0 -37
- package/dist/infrastructure/rpc/server.js.map +0 -1
- package/dist/infrastructure/storage/caching-workflow-storage.d.ts.map +0 -1
- package/dist/infrastructure/storage/caching-workflow-storage.js.map +0 -1
- package/dist/infrastructure/storage/context-storage.d.ts +0 -150
- package/dist/infrastructure/storage/context-storage.js +0 -40
- package/dist/infrastructure/storage/file-workflow-storage.d.ts.map +0 -1
- package/dist/infrastructure/storage/file-workflow-storage.js.map +0 -1
- package/dist/infrastructure/storage/filesystem-blob-storage.d.ts +0 -27
- package/dist/infrastructure/storage/filesystem-blob-storage.js +0 -363
- package/dist/infrastructure/storage/git-workflow-storage.d.ts.map +0 -1
- package/dist/infrastructure/storage/git-workflow-storage.js.map +0 -1
- package/dist/infrastructure/storage/hybrid-context-storage.d.ts +0 -29
- package/dist/infrastructure/storage/hybrid-context-storage.js +0 -400
- package/dist/infrastructure/storage/in-memory-storage.d.ts.map +0 -1
- package/dist/infrastructure/storage/in-memory-storage.js.map +0 -1
- package/dist/infrastructure/storage/index.d.ts.map +0 -1
- package/dist/infrastructure/storage/index.js.map +0 -1
- package/dist/infrastructure/storage/migrations/001_initial_schema.sql +0 -38
- package/dist/infrastructure/storage/migrations/002_context_concurrency_enhancements.sql +0 -234
- package/dist/infrastructure/storage/migrations/003_classification_overrides.sql +0 -20
- package/dist/infrastructure/storage/multi-directory-workflow-storage.d.ts +0 -32
- package/dist/infrastructure/storage/multi-directory-workflow-storage.d.ts.map +0 -1
- package/dist/infrastructure/storage/multi-directory-workflow-storage.js +0 -184
- package/dist/infrastructure/storage/multi-directory-workflow-storage.js.map +0 -1
- package/dist/infrastructure/storage/plugin-workflow-storage.d.ts.map +0 -1
- package/dist/infrastructure/storage/plugin-workflow-storage.js.map +0 -1
- package/dist/infrastructure/storage/remote-workflow-storage.d.ts.map +0 -1
- package/dist/infrastructure/storage/remote-workflow-storage.js.map +0 -1
- package/dist/infrastructure/storage/schema-validating-workflow-storage.d.ts.map +0 -1
- package/dist/infrastructure/storage/schema-validating-workflow-storage.js.map +0 -1
- package/dist/infrastructure/storage/sqlite-metadata-storage.d.ts +0 -35
- package/dist/infrastructure/storage/sqlite-metadata-storage.js +0 -410
- package/dist/infrastructure/storage/sqlite-migrator.d.ts +0 -46
- package/dist/infrastructure/storage/sqlite-migrator.js +0 -293
- package/dist/infrastructure/storage/storage.d.ts.map +0 -1
- package/dist/infrastructure/storage/storage.js.map +0 -1
- package/dist/mcp-server.d.ts.map +0 -1
- package/dist/mcp-server.js.map +0 -1
- package/dist/tools/mcp_initialize.d.ts +0 -2
- package/dist/tools/mcp_initialize.d.ts.map +0 -1
- package/dist/tools/mcp_initialize.js +0 -45
- package/dist/tools/mcp_initialize.js.map +0 -1
- package/dist/tools/mcp_shutdown.d.ts +0 -2
- package/dist/tools/mcp_shutdown.d.ts.map +0 -1
- package/dist/tools/mcp_shutdown.js +0 -10
- package/dist/tools/mcp_shutdown.js.map +0 -1
- package/dist/tools/mcp_tools_list.d.ts +0 -2
- package/dist/tools/mcp_tools_list.d.ts.map +0 -1
- package/dist/tools/mcp_tools_list.js +0 -60
- package/dist/tools/mcp_tools_list.js.map +0 -1
- package/dist/tools/session-tools.d.ts +0 -5
- package/dist/tools/session-tools.js +0 -270
- package/dist/types/context-types.d.ts +0 -236
- package/dist/types/context-types.js +0 -10
- package/dist/types/documentation-types.d.ts +0 -37
- package/dist/types/loop-context-optimizer.d.ts +0 -7
- package/dist/types/mcp-types.d.ts +0 -273
- package/dist/types/mcp-types.d.ts.map +0 -1
- package/dist/types/mcp-types.js +0 -19
- package/dist/types/mcp-types.js.map +0 -1
- package/dist/types/server.d.ts.map +0 -1
- package/dist/types/server.js.map +0 -1
- package/dist/types/storage.d.ts.map +0 -1
- package/dist/types/storage.js.map +0 -1
- package/dist/types/workflow-types.d.ts +0 -336
- package/dist/types/workflow-types.d.ts.map +0 -1
- package/dist/types/workflow-types.js +0 -20
- package/dist/types/workflow-types.js.map +0 -1
- package/dist/utils/condition-evaluator.d.ts.map +0 -1
- package/dist/utils/condition-evaluator.js.map +0 -1
- package/dist/utils/config.d.ts +0 -149
- package/dist/utils/config.d.ts.map +0 -1
- package/dist/utils/config.js +0 -251
- package/dist/utils/config.js.map +0 -1
- package/dist/utils/storage-security.d.ts.map +0 -1
- package/dist/utils/storage-security.js.map +0 -1
- package/dist/validation/request-validator.d.ts +0 -8
- package/dist/validation/request-validator.d.ts.map +0 -1
- package/dist/validation/request-validator.js +0 -32
- package/dist/validation/request-validator.js.map +0 -1
- package/dist/validation/response-validator.d.ts +0 -8
- package/dist/validation/response-validator.d.ts.map +0 -1
- package/dist/validation/response-validator.js +0 -110
- package/dist/validation/response-validator.js.map +0 -1
- package/dist/validation/schemas.d.ts +0 -1
- package/dist/validation/schemas.d.ts.map +0 -1
- package/dist/validation/schemas.js +0 -53
- package/dist/validation/schemas.js.map +0 -1
- /package/dist/{types/documentation-types.js → errors/app-error.js} +0 -0
- /package/dist/{types/loop-context-optimizer.js → runtime/brand.js} +0 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import type { LoopStepDefinition } from '../../types/workflow-definition';
|
|
2
2
|
export interface EnhancedValidationResult {
|
|
3
3
|
warnings: string[];
|
|
4
4
|
suggestions: string[];
|
|
@@ -10,7 +10,7 @@ export declare class EnhancedLoopValidator {
|
|
|
10
10
|
private readonly TEMPLATE_VAR_PATTERN;
|
|
11
11
|
private readonly TERNARY_PATTERN;
|
|
12
12
|
private readonly NESTED_TERNARY_PATTERN;
|
|
13
|
-
validateLoopStep(step:
|
|
13
|
+
validateLoopStep(step: LoopStepDefinition): EnhancedValidationResult;
|
|
14
14
|
private getLoopBodySteps;
|
|
15
15
|
private validateConditionalLogic;
|
|
16
16
|
private validatePromptLength;
|
|
@@ -1,7 +1,14 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
2
8
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
9
|
exports.EnhancedLoopValidator = void 0;
|
|
4
|
-
|
|
10
|
+
const tsyringe_1 = require("tsyringe");
|
|
11
|
+
let EnhancedLoopValidator = class EnhancedLoopValidator {
|
|
5
12
|
constructor() {
|
|
6
13
|
this.PROMPT_WARNING_THRESHOLD = 1500;
|
|
7
14
|
this.PROMPT_ERROR_THRESHOLD = 2000;
|
|
@@ -133,5 +140,8 @@ class EnhancedLoopValidator {
|
|
|
133
140
|
suggestions.push(`Consider if you really need ${step.loop.maxIterations} iterations, or implement pagination/chunking instead.`);
|
|
134
141
|
}
|
|
135
142
|
}
|
|
136
|
-
}
|
|
143
|
+
};
|
|
137
144
|
exports.EnhancedLoopValidator = EnhancedLoopValidator;
|
|
145
|
+
exports.EnhancedLoopValidator = EnhancedLoopValidator = __decorate([
|
|
146
|
+
(0, tsyringe_1.singleton)()
|
|
147
|
+
], EnhancedLoopValidator);
|
|
@@ -1,34 +1,13 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
value?: string;
|
|
7
|
-
pattern?: string;
|
|
8
|
-
flags?: string;
|
|
9
|
-
min?: number;
|
|
10
|
-
max?: number;
|
|
11
|
-
schema?: Record<string, any>;
|
|
12
|
-
condition?: Condition;
|
|
13
|
-
}
|
|
14
|
-
export interface ValidationComposition {
|
|
15
|
-
and?: ValidationCriteria[];
|
|
16
|
-
or?: ValidationCriteria[];
|
|
17
|
-
not?: ValidationCriteria;
|
|
18
|
-
}
|
|
19
|
-
export type ValidationCriteria = ValidationRule | ValidationComposition;
|
|
20
|
-
export interface ValidationResult {
|
|
21
|
-
valid: boolean;
|
|
22
|
-
issues: string[];
|
|
23
|
-
suggestions: string[];
|
|
24
|
-
warnings?: string[];
|
|
25
|
-
info?: string[];
|
|
26
|
-
}
|
|
1
|
+
import { ConditionContext } from '../../utils/condition-evaluator';
|
|
2
|
+
import type { LoopStepDefinition } from '../../types/workflow-definition';
|
|
3
|
+
import type { Workflow } from '../../types/workflow';
|
|
4
|
+
import { ValidationCriteria, ValidationResult } from '../../types/validation';
|
|
5
|
+
import { EnhancedLoopValidator } from './enhanced-loop-validator';
|
|
27
6
|
export declare class ValidationEngine {
|
|
28
7
|
private ajv;
|
|
29
8
|
private schemaCache;
|
|
30
9
|
private enhancedLoopValidator;
|
|
31
|
-
constructor();
|
|
10
|
+
constructor(enhancedLoopValidator: EnhancedLoopValidator);
|
|
32
11
|
private compileSchema;
|
|
33
12
|
private evaluateCriteria;
|
|
34
13
|
private evaluateRuleArray;
|
|
@@ -36,9 +15,9 @@ export declare class ValidationEngine {
|
|
|
36
15
|
private evaluateSingleCriteria;
|
|
37
16
|
private isValidationRule;
|
|
38
17
|
private isValidationComposition;
|
|
39
|
-
validate(output: string, criteria:
|
|
18
|
+
validate(output: string, criteria: ValidationCriteria, context?: ConditionContext): Promise<ValidationResult>;
|
|
40
19
|
private evaluateRule;
|
|
41
|
-
validateLoopStep(step:
|
|
20
|
+
validateLoopStep(step: LoopStepDefinition, workflow: Workflow): ValidationResult;
|
|
42
21
|
validateWorkflow(workflow: Workflow): ValidationResult;
|
|
43
22
|
private isValidVariableName;
|
|
44
23
|
private validateStepFunctionCalls;
|
|
@@ -1,19 +1,32 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
var __param = (this && this.__param) || function (paramIndex, decorator) {
|
|
12
|
+
return function (target, key) { decorator(target, key, paramIndex); }
|
|
13
|
+
};
|
|
2
14
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
15
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
16
|
};
|
|
5
17
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
18
|
exports.ValidationEngine = void 0;
|
|
19
|
+
const tsyringe_1 = require("tsyringe");
|
|
7
20
|
const error_handler_1 = require("../../core/error-handler");
|
|
8
21
|
const condition_evaluator_1 = require("../../utils/condition-evaluator");
|
|
9
22
|
const ajv_1 = __importDefault(require("ajv"));
|
|
10
|
-
const
|
|
23
|
+
const workflow_definition_1 = require("../../types/workflow-definition");
|
|
11
24
|
const enhanced_loop_validator_1 = require("./enhanced-loop-validator");
|
|
12
|
-
class ValidationEngine {
|
|
13
|
-
constructor() {
|
|
25
|
+
let ValidationEngine = class ValidationEngine {
|
|
26
|
+
constructor(enhancedLoopValidator) {
|
|
14
27
|
this.schemaCache = new Map();
|
|
15
28
|
this.ajv = new ajv_1.default({ allErrors: true });
|
|
16
|
-
this.enhancedLoopValidator =
|
|
29
|
+
this.enhancedLoopValidator = enhancedLoopValidator;
|
|
17
30
|
}
|
|
18
31
|
compileSchema(schema) {
|
|
19
32
|
const schemaKey = JSON.stringify(schema);
|
|
@@ -257,12 +270,12 @@ class ValidationEngine {
|
|
|
257
270
|
}
|
|
258
271
|
else {
|
|
259
272
|
if (typeof step.body === 'string') {
|
|
260
|
-
const bodyStep = workflow.steps.find(s => s.id === step.body);
|
|
273
|
+
const bodyStep = workflow.definition.steps.find(s => s.id === step.body);
|
|
261
274
|
if (!bodyStep) {
|
|
262
275
|
issues.push(`Loop body references non-existent step '${step.body}'`);
|
|
263
276
|
suggestions.push(`Create a step with ID '${step.body}' or update the body reference`);
|
|
264
277
|
}
|
|
265
|
-
else if ((0,
|
|
278
|
+
else if ((0, workflow_definition_1.isLoopStepDefinition)(bodyStep)) {
|
|
266
279
|
issues.push(`Nested loops are not currently supported. Step '${step.body}' is a loop`);
|
|
267
280
|
suggestions.push('Refactor to avoid nested loops or use sequential loops');
|
|
268
281
|
}
|
|
@@ -293,11 +306,11 @@ class ValidationEngine {
|
|
|
293
306
|
issues.push(`Inline step '${inlineStep.id || 'unknown'}' must have a prompt`);
|
|
294
307
|
suggestions.push('Add a prompt to all inline steps');
|
|
295
308
|
}
|
|
296
|
-
if ((0,
|
|
309
|
+
if ((0, workflow_definition_1.isLoopStepDefinition)(inlineStep)) {
|
|
297
310
|
issues.push(`Nested loops are not currently supported. Inline step '${inlineStep.id}' is a loop`);
|
|
298
311
|
suggestions.push('Refactor to avoid nested loops');
|
|
299
312
|
}
|
|
300
|
-
const callValidation = this.validateStepFunctionCalls(inlineStep, workflow.functionDefinitions || [], step.functionDefinitions || []);
|
|
313
|
+
const callValidation = this.validateStepFunctionCalls(inlineStep, workflow.definition.functionDefinitions || [], step.functionDefinitions || []);
|
|
301
314
|
if (!callValidation.valid) {
|
|
302
315
|
issues.push(...callValidation.issues.map(i => `Step '${inlineStep.id}': ${i}`));
|
|
303
316
|
if (callValidation.suggestions)
|
|
@@ -335,15 +348,15 @@ class ValidationEngine {
|
|
|
335
348
|
const warnings = [];
|
|
336
349
|
const info = [];
|
|
337
350
|
const stepIds = new Set();
|
|
338
|
-
for (const step of workflow.steps) {
|
|
351
|
+
for (const step of workflow.definition.steps) {
|
|
339
352
|
if (stepIds.has(step.id)) {
|
|
340
353
|
issues.push(`Duplicate step ID '${step.id}'`);
|
|
341
354
|
suggestions.push('Ensure all step IDs are unique');
|
|
342
355
|
}
|
|
343
356
|
stepIds.add(step.id);
|
|
344
357
|
}
|
|
345
|
-
for (const step of workflow.steps) {
|
|
346
|
-
if ((0,
|
|
358
|
+
for (const step of workflow.definition.steps) {
|
|
359
|
+
if ((0, workflow_definition_1.isLoopStepDefinition)(step)) {
|
|
347
360
|
const loopResult = this.validateLoopStep(step, workflow);
|
|
348
361
|
issues.push(...loopResult.issues.map(issue => `Step '${step.id}': ${issue}`));
|
|
349
362
|
suggestions.push(...loopResult.suggestions);
|
|
@@ -364,7 +377,7 @@ class ValidationEngine {
|
|
|
364
377
|
if (!step.prompt) {
|
|
365
378
|
issues.push(`Step '${step.id}' missing required prompt`);
|
|
366
379
|
}
|
|
367
|
-
const callValidation = this.validateStepFunctionCalls(step, workflow.functionDefinitions || []);
|
|
380
|
+
const callValidation = this.validateStepFunctionCalls(step, workflow.definition.functionDefinitions || []);
|
|
368
381
|
if (!callValidation.valid) {
|
|
369
382
|
issues.push(...callValidation.issues.map(i => `Step '${step.id}': ${i}`));
|
|
370
383
|
if (callValidation.suggestions)
|
|
@@ -373,21 +386,20 @@ class ValidationEngine {
|
|
|
373
386
|
}
|
|
374
387
|
}
|
|
375
388
|
const loopBodySteps = new Set();
|
|
376
|
-
for (const step of workflow.steps) {
|
|
377
|
-
if ((0,
|
|
389
|
+
for (const step of workflow.definition.steps) {
|
|
390
|
+
if ((0, workflow_definition_1.isLoopStepDefinition)(step)) {
|
|
378
391
|
if (typeof step.body === 'string') {
|
|
379
392
|
loopBodySteps.add(step.body);
|
|
380
393
|
}
|
|
381
394
|
else if (Array.isArray(step.body)) {
|
|
382
|
-
step.body
|
|
383
|
-
if (
|
|
384
|
-
loopBodySteps.add(id);
|
|
385
|
-
|
|
386
|
-
});
|
|
395
|
+
for (const inlineStep of step.body) {
|
|
396
|
+
if (inlineStep?.id)
|
|
397
|
+
loopBodySteps.add(inlineStep.id);
|
|
398
|
+
}
|
|
387
399
|
}
|
|
388
400
|
}
|
|
389
401
|
}
|
|
390
|
-
for (const step of workflow.steps) {
|
|
402
|
+
for (const step of workflow.definition.steps) {
|
|
391
403
|
if (loopBodySteps.has(step.id) && step.runCondition) {
|
|
392
404
|
issues.push(`Step '${step.id}' is a loop body but has runCondition - this may cause conflicts`);
|
|
393
405
|
suggestions.push('Remove runCondition from loop body steps as they are controlled by the loop');
|
|
@@ -458,5 +470,10 @@ class ValidationEngine {
|
|
|
458
470
|
default: return true;
|
|
459
471
|
}
|
|
460
472
|
}
|
|
461
|
-
}
|
|
473
|
+
};
|
|
462
474
|
exports.ValidationEngine = ValidationEngine;
|
|
475
|
+
exports.ValidationEngine = ValidationEngine = __decorate([
|
|
476
|
+
(0, tsyringe_1.singleton)(),
|
|
477
|
+
__param(0, (0, tsyringe_1.inject)(enhanced_loop_validator_1.EnhancedLoopValidator)),
|
|
478
|
+
__metadata("design:paramtypes", [enhanced_loop_validator_1.EnhancedLoopValidator])
|
|
479
|
+
], ValidationEngine);
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { Workflow, WorkflowStepDefinition, LoopStepDefinition } from '../../types/workflow';
|
|
2
|
+
import type { Result } from 'neverthrow';
|
|
3
|
+
import { type DomainError } from '../../domain/execution/error';
|
|
4
|
+
export interface CompiledLoop {
|
|
5
|
+
readonly loop: LoopStepDefinition;
|
|
6
|
+
readonly bodySteps: readonly WorkflowStepDefinition[];
|
|
7
|
+
}
|
|
8
|
+
export interface CompiledWorkflow {
|
|
9
|
+
readonly workflow: Workflow;
|
|
10
|
+
readonly steps: readonly (WorkflowStepDefinition | LoopStepDefinition)[];
|
|
11
|
+
readonly stepById: ReadonlyMap<string, WorkflowStepDefinition | LoopStepDefinition>;
|
|
12
|
+
readonly compiledLoops: ReadonlyMap<string, CompiledLoop>;
|
|
13
|
+
readonly loopBodyStepIds: ReadonlySet<string>;
|
|
14
|
+
}
|
|
15
|
+
export declare class WorkflowCompiler {
|
|
16
|
+
compile(workflow: Workflow): Result<CompiledWorkflow, DomainError>;
|
|
17
|
+
private resolveLoopBody;
|
|
18
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.WorkflowCompiler = void 0;
|
|
10
|
+
const tsyringe_1 = require("tsyringe");
|
|
11
|
+
const workflow_1 = require("../../types/workflow");
|
|
12
|
+
const neverthrow_1 = require("neverthrow");
|
|
13
|
+
const error_1 = require("../../domain/execution/error");
|
|
14
|
+
let WorkflowCompiler = class WorkflowCompiler {
|
|
15
|
+
compile(workflow) {
|
|
16
|
+
const steps = workflow.definition.steps;
|
|
17
|
+
const stepById = new Map();
|
|
18
|
+
for (const step of steps) {
|
|
19
|
+
if (stepById.has(step.id)) {
|
|
20
|
+
return (0, neverthrow_1.err)(error_1.Err.invalidState(`Duplicate step id '${step.id}' in workflow '${workflow.definition.id}'`));
|
|
21
|
+
}
|
|
22
|
+
stepById.set(step.id, step);
|
|
23
|
+
}
|
|
24
|
+
const compiledLoops = new Map();
|
|
25
|
+
const loopBodyStepIds = new Set();
|
|
26
|
+
for (const step of steps) {
|
|
27
|
+
if (!(0, workflow_1.isLoopStepDefinition)(step))
|
|
28
|
+
continue;
|
|
29
|
+
const loop = step;
|
|
30
|
+
const bodyResolved = this.resolveLoopBody(loop, stepById, workflow);
|
|
31
|
+
if (bodyResolved.isErr())
|
|
32
|
+
return (0, neverthrow_1.err)(bodyResolved.error);
|
|
33
|
+
for (const bodyStep of bodyResolved.value) {
|
|
34
|
+
loopBodyStepIds.add(bodyStep.id);
|
|
35
|
+
}
|
|
36
|
+
compiledLoops.set(loop.id, {
|
|
37
|
+
loop,
|
|
38
|
+
bodySteps: bodyResolved.value,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
return (0, neverthrow_1.ok)({
|
|
42
|
+
workflow,
|
|
43
|
+
steps,
|
|
44
|
+
stepById,
|
|
45
|
+
compiledLoops,
|
|
46
|
+
loopBodyStepIds,
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
resolveLoopBody(loop, stepById, workflow) {
|
|
50
|
+
if (Array.isArray(loop.body)) {
|
|
51
|
+
for (const s of loop.body) {
|
|
52
|
+
if ((0, workflow_1.isLoopStepDefinition)(s)) {
|
|
53
|
+
return (0, neverthrow_1.err)(error_1.Err.invalidLoop(loop.id, `Nested loops are not supported (inline step '${s.id}' is a loop)`));
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
for (const s of loop.body) {
|
|
57
|
+
const existing = stepById.get(s.id);
|
|
58
|
+
if (existing) {
|
|
59
|
+
return (0, neverthrow_1.err)(error_1.Err.invalidState(`Inline loop body step id '${s.id}' collides with existing step id in workflow '${workflow.definition.id}'`));
|
|
60
|
+
}
|
|
61
|
+
stepById.set(s.id, s);
|
|
62
|
+
}
|
|
63
|
+
return (0, neverthrow_1.ok)(loop.body);
|
|
64
|
+
}
|
|
65
|
+
const bodyRef = loop.body;
|
|
66
|
+
const referenced = stepById.get(bodyRef);
|
|
67
|
+
if (!referenced) {
|
|
68
|
+
return (0, neverthrow_1.err)(error_1.Err.invalidLoop(loop.id, `Loop body references missing step '${bodyRef}'`));
|
|
69
|
+
}
|
|
70
|
+
if ((0, workflow_1.isLoopStepDefinition)(referenced)) {
|
|
71
|
+
return (0, neverthrow_1.err)(error_1.Err.invalidLoop(loop.id, `Nested loops are not supported (referenced step '${referenced.id}' is a loop)`));
|
|
72
|
+
}
|
|
73
|
+
return (0, neverthrow_1.ok)([referenced]);
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
exports.WorkflowCompiler = WorkflowCompiler;
|
|
77
|
+
exports.WorkflowCompiler = WorkflowCompiler = __decorate([
|
|
78
|
+
(0, tsyringe_1.singleton)()
|
|
79
|
+
], WorkflowCompiler);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { WorkflowStepDefinition } from '../../types/workflow';
|
|
2
|
+
import { CompiledWorkflow } from './workflow-compiler';
|
|
3
|
+
import type { Result } from 'neverthrow';
|
|
4
|
+
import { type DomainError } from '../../domain/execution/error';
|
|
5
|
+
import { ExecutionState } from '../../domain/execution/state';
|
|
6
|
+
import { WorkflowEvent } from '../../domain/execution/event';
|
|
7
|
+
import { StepInstanceId } from '../../domain/execution/ids';
|
|
8
|
+
export interface NextStep {
|
|
9
|
+
readonly step: WorkflowStepDefinition;
|
|
10
|
+
readonly stepInstanceId: StepInstanceId;
|
|
11
|
+
readonly guidance: {
|
|
12
|
+
readonly prompt: string;
|
|
13
|
+
readonly requiresConfirmation?: boolean;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export interface InterpreterOutput {
|
|
17
|
+
readonly state: ExecutionState;
|
|
18
|
+
readonly next: NextStep | null;
|
|
19
|
+
readonly isComplete: boolean;
|
|
20
|
+
}
|
|
21
|
+
export declare class WorkflowInterpreter {
|
|
22
|
+
applyEvent(state: ExecutionState, event: WorkflowEvent): Result<ExecutionState, DomainError>;
|
|
23
|
+
next(compiled: CompiledWorkflow, state: ExecutionState, context?: Record<string, unknown>): Result<InterpreterOutput, DomainError>;
|
|
24
|
+
private ensureRunning;
|
|
25
|
+
private nextTopLevel;
|
|
26
|
+
private nextInCurrentLoop;
|
|
27
|
+
private shouldContinueLoop;
|
|
28
|
+
private projectLoopContext;
|
|
29
|
+
private lookupStepInstance;
|
|
30
|
+
private materializeStep;
|
|
31
|
+
}
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
+
exports.WorkflowInterpreter = void 0;
|
|
10
|
+
const tsyringe_1 = require("tsyringe");
|
|
11
|
+
const condition_evaluator_1 = require("../../utils/condition-evaluator");
|
|
12
|
+
const workflow_1 = require("../../types/workflow");
|
|
13
|
+
const neverthrow_1 = require("neverthrow");
|
|
14
|
+
const error_1 = require("../../domain/execution/error");
|
|
15
|
+
const ids_1 = require("../../domain/execution/ids");
|
|
16
|
+
let WorkflowInterpreter = class WorkflowInterpreter {
|
|
17
|
+
applyEvent(state, event) {
|
|
18
|
+
if (state.kind === 'complete')
|
|
19
|
+
return (0, neverthrow_1.ok)(state);
|
|
20
|
+
const running = this.ensureRunning(state);
|
|
21
|
+
if (running.isErr())
|
|
22
|
+
return (0, neverthrow_1.err)(running.error);
|
|
23
|
+
const s = running.value;
|
|
24
|
+
if (!s.pendingStep) {
|
|
25
|
+
return (0, neverthrow_1.err)(error_1.Err.invalidState('No pending step to complete'));
|
|
26
|
+
}
|
|
27
|
+
switch (event.kind) {
|
|
28
|
+
case 'step_completed': {
|
|
29
|
+
const expectedKey = (0, ids_1.toStepInstanceKey)(s.pendingStep);
|
|
30
|
+
const actualKey = (0, ids_1.toStepInstanceKey)(event.stepInstanceId);
|
|
31
|
+
if (expectedKey !== actualKey) {
|
|
32
|
+
return (0, neverthrow_1.err)(error_1.Err.invalidState(`StepCompleted does not match pendingStep (expected '${expectedKey}', got '${actualKey}')`));
|
|
33
|
+
}
|
|
34
|
+
return (0, neverthrow_1.ok)({
|
|
35
|
+
kind: 'running',
|
|
36
|
+
completed: [...s.completed, expectedKey],
|
|
37
|
+
loopStack: s.loopStack,
|
|
38
|
+
pendingStep: undefined,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
default: {
|
|
42
|
+
return (0, neverthrow_1.err)(error_1.Err.invalidState('Unsupported event'));
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
next(compiled, state, context = {}) {
|
|
47
|
+
if (state.kind === 'complete') {
|
|
48
|
+
return (0, neverthrow_1.ok)({ state, next: null, isComplete: true });
|
|
49
|
+
}
|
|
50
|
+
const runningRes = this.ensureRunning(state);
|
|
51
|
+
if (runningRes.isErr())
|
|
52
|
+
return (0, neverthrow_1.err)(runningRes.error);
|
|
53
|
+
let running = runningRes.value;
|
|
54
|
+
if (running.pendingStep) {
|
|
55
|
+
const step = this.lookupStepInstance(compiled, running.pendingStep);
|
|
56
|
+
if (step.isErr())
|
|
57
|
+
return (0, neverthrow_1.err)(step.error);
|
|
58
|
+
return (0, neverthrow_1.ok)({
|
|
59
|
+
state: running,
|
|
60
|
+
next: step.value,
|
|
61
|
+
isComplete: false,
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
for (let guard = 0; guard < 10000; guard++) {
|
|
65
|
+
if (running.loopStack.length > 0) {
|
|
66
|
+
const inLoop = this.nextInCurrentLoop(compiled, running, context);
|
|
67
|
+
if (inLoop.isErr())
|
|
68
|
+
return (0, neverthrow_1.err)(inLoop.error);
|
|
69
|
+
const result = inLoop.value;
|
|
70
|
+
running = result.state;
|
|
71
|
+
if (result.next) {
|
|
72
|
+
return (0, neverthrow_1.ok)({ state: running, next: result.next, isComplete: false });
|
|
73
|
+
}
|
|
74
|
+
if (running.loopStack.length > 0) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
const top = this.nextTopLevel(compiled, running, context);
|
|
79
|
+
if (top.isErr())
|
|
80
|
+
return (0, neverthrow_1.err)(top.error);
|
|
81
|
+
const out = top.value;
|
|
82
|
+
running = out.state;
|
|
83
|
+
if (out.next) {
|
|
84
|
+
return (0, neverthrow_1.ok)({ state: running, next: out.next, isComplete: false });
|
|
85
|
+
}
|
|
86
|
+
if (running.loopStack.length > 0) {
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
return (0, neverthrow_1.ok)({ state: { kind: 'complete' }, next: null, isComplete: true });
|
|
90
|
+
}
|
|
91
|
+
return (0, neverthrow_1.err)(error_1.Err.invalidState('Interpreter exceeded guard iterations (possible infinite loop)'));
|
|
92
|
+
}
|
|
93
|
+
ensureRunning(state) {
|
|
94
|
+
if (state.kind === 'init') {
|
|
95
|
+
return (0, neverthrow_1.ok)({ kind: 'running', completed: [], loopStack: [], pendingStep: undefined });
|
|
96
|
+
}
|
|
97
|
+
if (state.kind !== 'running') {
|
|
98
|
+
return (0, neverthrow_1.err)(error_1.Err.invalidState(`Unsupported state kind '${state.kind}'`));
|
|
99
|
+
}
|
|
100
|
+
return (0, neverthrow_1.ok)(state);
|
|
101
|
+
}
|
|
102
|
+
nextTopLevel(compiled, state, context) {
|
|
103
|
+
for (const step of compiled.steps) {
|
|
104
|
+
if (compiled.loopBodyStepIds.has(step.id))
|
|
105
|
+
continue;
|
|
106
|
+
if (state.completed.includes(step.id))
|
|
107
|
+
continue;
|
|
108
|
+
if (step.runCondition && !(0, condition_evaluator_1.evaluateCondition)(step.runCondition, context)) {
|
|
109
|
+
continue;
|
|
110
|
+
}
|
|
111
|
+
if ((0, workflow_1.isLoopStepDefinition)(step)) {
|
|
112
|
+
const entered = { loopId: step.id, iteration: 0, bodyIndex: 0 };
|
|
113
|
+
return (0, neverthrow_1.ok)({
|
|
114
|
+
state: { ...state, loopStack: [...state.loopStack, entered] },
|
|
115
|
+
next: null,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
const instance = { stepId: step.id, loopPath: [] };
|
|
119
|
+
const next = this.materializeStep(compiled, instance, context);
|
|
120
|
+
if (next.isErr())
|
|
121
|
+
return (0, neverthrow_1.err)(next.error);
|
|
122
|
+
return (0, neverthrow_1.ok)({
|
|
123
|
+
state: { ...state, pendingStep: instance },
|
|
124
|
+
next: next.value,
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
return (0, neverthrow_1.ok)({ state, next: null });
|
|
128
|
+
}
|
|
129
|
+
nextInCurrentLoop(compiled, state, context) {
|
|
130
|
+
const frame = state.loopStack[state.loopStack.length - 1];
|
|
131
|
+
const loopCompiled = compiled.compiledLoops.get(frame.loopId);
|
|
132
|
+
if (!loopCompiled) {
|
|
133
|
+
return (0, neverthrow_1.err)(error_1.Err.invalidLoop(frame.loopId, 'Loop not found in compiled metadata'));
|
|
134
|
+
}
|
|
135
|
+
const shouldContinue = this.shouldContinueLoop(loopCompiled.loop, frame, context);
|
|
136
|
+
if (shouldContinue.isErr())
|
|
137
|
+
return (0, neverthrow_1.err)(shouldContinue.error);
|
|
138
|
+
if (!shouldContinue.value) {
|
|
139
|
+
const popped = state.loopStack.slice(0, -1);
|
|
140
|
+
return (0, neverthrow_1.ok)({
|
|
141
|
+
state: {
|
|
142
|
+
...state,
|
|
143
|
+
loopStack: popped,
|
|
144
|
+
completed: [...state.completed, frame.loopId],
|
|
145
|
+
},
|
|
146
|
+
next: null,
|
|
147
|
+
});
|
|
148
|
+
}
|
|
149
|
+
const body = loopCompiled.bodySteps;
|
|
150
|
+
for (let i = frame.bodyIndex; i < body.length; i++) {
|
|
151
|
+
const bodyStep = body[i];
|
|
152
|
+
const instance = {
|
|
153
|
+
stepId: bodyStep.id,
|
|
154
|
+
loopPath: [...state.loopStack.map((f) => ({ loopId: f.loopId, iteration: f.iteration }))],
|
|
155
|
+
};
|
|
156
|
+
const key = (0, ids_1.toStepInstanceKey)(instance);
|
|
157
|
+
if (state.completed.includes(key))
|
|
158
|
+
continue;
|
|
159
|
+
const projectedContext = this.projectLoopContext(loopCompiled.loop, frame, context);
|
|
160
|
+
if (bodyStep.runCondition && !(0, condition_evaluator_1.evaluateCondition)(bodyStep.runCondition, projectedContext)) {
|
|
161
|
+
continue;
|
|
162
|
+
}
|
|
163
|
+
const next = this.materializeStep(compiled, instance, projectedContext);
|
|
164
|
+
if (next.isErr())
|
|
165
|
+
return (0, neverthrow_1.err)(next.error);
|
|
166
|
+
const updatedTop = { ...frame, bodyIndex: i };
|
|
167
|
+
const updatedStack = [...state.loopStack.slice(0, -1), updatedTop];
|
|
168
|
+
return (0, neverthrow_1.ok)({
|
|
169
|
+
state: { ...state, loopStack: updatedStack, pendingStep: instance },
|
|
170
|
+
next: next.value,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
if (frame.iteration + 1 > loopCompiled.loop.loop.maxIterations) {
|
|
174
|
+
return (0, neverthrow_1.err)(error_1.Err.maxIterationsExceeded(frame.loopId, loopCompiled.loop.loop.maxIterations));
|
|
175
|
+
}
|
|
176
|
+
const advanced = { ...frame, iteration: frame.iteration + 1, bodyIndex: 0 };
|
|
177
|
+
const updatedStack = [...state.loopStack.slice(0, -1), advanced];
|
|
178
|
+
return (0, neverthrow_1.ok)({ state: { ...state, loopStack: updatedStack }, next: null });
|
|
179
|
+
}
|
|
180
|
+
shouldContinueLoop(loop, frame, context) {
|
|
181
|
+
if (frame.iteration >= loop.loop.maxIterations) {
|
|
182
|
+
return (0, neverthrow_1.ok)(false);
|
|
183
|
+
}
|
|
184
|
+
switch (loop.loop.type) {
|
|
185
|
+
case 'for': {
|
|
186
|
+
const count = loop.loop.count;
|
|
187
|
+
if (typeof count === 'number') {
|
|
188
|
+
return (0, neverthrow_1.ok)(frame.iteration < count);
|
|
189
|
+
}
|
|
190
|
+
if (typeof count === 'string') {
|
|
191
|
+
const raw = context[count];
|
|
192
|
+
if (typeof raw !== 'number') {
|
|
193
|
+
return (0, neverthrow_1.err)(error_1.Err.missingContext(`for loop '${loop.id}' requires numeric context['${count}']`));
|
|
194
|
+
}
|
|
195
|
+
return (0, neverthrow_1.ok)(frame.iteration < raw);
|
|
196
|
+
}
|
|
197
|
+
return (0, neverthrow_1.err)(error_1.Err.invalidLoop(loop.id, `for loop '${loop.id}' missing count`));
|
|
198
|
+
}
|
|
199
|
+
case 'forEach': {
|
|
200
|
+
const itemsVar = loop.loop.items;
|
|
201
|
+
if (!itemsVar)
|
|
202
|
+
return (0, neverthrow_1.err)(error_1.Err.invalidLoop(loop.id, `forEach loop '${loop.id}' missing items`));
|
|
203
|
+
const raw = context[itemsVar];
|
|
204
|
+
if (!Array.isArray(raw)) {
|
|
205
|
+
return (0, neverthrow_1.err)(error_1.Err.missingContext(`forEach loop '${loop.id}' requires array context['${itemsVar}']`));
|
|
206
|
+
}
|
|
207
|
+
return (0, neverthrow_1.ok)(frame.iteration < raw.length);
|
|
208
|
+
}
|
|
209
|
+
case 'while': {
|
|
210
|
+
if (!loop.loop.condition)
|
|
211
|
+
return (0, neverthrow_1.err)(error_1.Err.invalidLoop(loop.id, `while loop '${loop.id}' missing condition`));
|
|
212
|
+
return (0, neverthrow_1.ok)((0, condition_evaluator_1.evaluateCondition)(loop.loop.condition, this.projectLoopContext(loop, frame, context)));
|
|
213
|
+
}
|
|
214
|
+
case 'until': {
|
|
215
|
+
if (!loop.loop.condition)
|
|
216
|
+
return (0, neverthrow_1.err)(error_1.Err.invalidLoop(loop.id, `until loop '${loop.id}' missing condition`));
|
|
217
|
+
return (0, neverthrow_1.ok)(!(0, condition_evaluator_1.evaluateCondition)(loop.loop.condition, this.projectLoopContext(loop, frame, context)));
|
|
218
|
+
}
|
|
219
|
+
default:
|
|
220
|
+
return (0, neverthrow_1.err)(error_1.Err.invalidLoop(loop.id, `Unknown loop type '${loop.loop.type}'`));
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
projectLoopContext(loop, frame, base) {
|
|
224
|
+
const out = { ...base };
|
|
225
|
+
const iterationVar = loop.loop.iterationVar || 'currentIteration';
|
|
226
|
+
out[iterationVar] = frame.iteration + 1;
|
|
227
|
+
if (loop.loop.type === 'forEach') {
|
|
228
|
+
const itemsVar = loop.loop.items;
|
|
229
|
+
const raw = base[itemsVar];
|
|
230
|
+
if (Array.isArray(raw)) {
|
|
231
|
+
const index = frame.iteration;
|
|
232
|
+
const itemVar = loop.loop.itemVar || 'currentItem';
|
|
233
|
+
const indexVar = loop.loop.indexVar || 'currentIndex';
|
|
234
|
+
out[itemVar] = raw[index];
|
|
235
|
+
out[indexVar] = index;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return out;
|
|
239
|
+
}
|
|
240
|
+
lookupStepInstance(compiled, id) {
|
|
241
|
+
const step = compiled.stepById.get(id.stepId);
|
|
242
|
+
if (!step)
|
|
243
|
+
return (0, neverthrow_1.err)(error_1.Err.invalidState(`Unknown stepId '${id.stepId}'`));
|
|
244
|
+
if ((0, workflow_1.isLoopStepDefinition)(step))
|
|
245
|
+
return (0, neverthrow_1.err)(error_1.Err.invalidState(`pendingStep cannot be a loop step ('${id.stepId}')`));
|
|
246
|
+
return this.materializeStep(compiled, id, {});
|
|
247
|
+
}
|
|
248
|
+
materializeStep(compiled, instance, context) {
|
|
249
|
+
const step = compiled.stepById.get(instance.stepId);
|
|
250
|
+
if (!step)
|
|
251
|
+
return (0, neverthrow_1.err)(error_1.Err.invalidState(`Unknown stepId '${instance.stepId}'`));
|
|
252
|
+
if ((0, workflow_1.isLoopStepDefinition)(step)) {
|
|
253
|
+
return (0, neverthrow_1.err)(error_1.Err.invalidState(`Cannot execute loop step '${step.id}' directly`));
|
|
254
|
+
}
|
|
255
|
+
const promptParts = [];
|
|
256
|
+
if (step.agentRole) {
|
|
257
|
+
promptParts.push(`## Agent Role Instructions\n${step.agentRole}\n`);
|
|
258
|
+
}
|
|
259
|
+
if (step.guidance && step.guidance.length > 0) {
|
|
260
|
+
promptParts.push(`## Step Guidance\n${step.guidance.map((g) => `- ${g}`).join('\n')}\n`);
|
|
261
|
+
}
|
|
262
|
+
promptParts.push(step.prompt);
|
|
263
|
+
if (instance.loopPath.length > 0) {
|
|
264
|
+
const current = instance.loopPath[instance.loopPath.length - 1];
|
|
265
|
+
promptParts.push(`\n\n## Loop Context\n- Loop: ${current.loopId}\n- Iteration: ${current.iteration + 1}`);
|
|
266
|
+
}
|
|
267
|
+
return (0, neverthrow_1.ok)({
|
|
268
|
+
step,
|
|
269
|
+
stepInstanceId: instance,
|
|
270
|
+
guidance: {
|
|
271
|
+
prompt: promptParts.join('\n'),
|
|
272
|
+
requiresConfirmation: !!step.requireConfirmation,
|
|
273
|
+
},
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
};
|
|
277
|
+
exports.WorkflowInterpreter = WorkflowInterpreter;
|
|
278
|
+
exports.WorkflowInterpreter = WorkflowInterpreter = __decorate([
|
|
279
|
+
(0, tsyringe_1.singleton)()
|
|
280
|
+
], WorkflowInterpreter);
|