@exaudeus/workrail 0.8.6 → 0.10.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 +1117 -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/ids/with-healthy-session-lock.d.ts +7 -0
- package/dist/v2/durable-core/ids/with-healthy-session-lock.js +2 -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 +332 -0
- package/dist/v2/durable-core/schemas/session/index.d.ts +3 -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/durable-core/schemas/session/session-health.d.ts +25 -0
- package/dist/v2/durable-core/schemas/session/session-health.js +2 -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 +23 -0
- package/dist/v2/infra/local/session-store/index.js +473 -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 +49 -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 +4 -0
- package/dist/v2/projections/session-health.js +12 -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/dist/v2/usecases/execution-session-gate.d.ts +53 -0
- package/dist/v2/usecases/execution-session-gate.js +167 -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,47 +1,49 @@
|
|
|
1
|
+
import type { ConditionContext } from '../../utils/condition-evaluator';
|
|
2
|
+
import type { Workflow, WorkflowSummary } from '../../types/workflow';
|
|
3
|
+
import { ValidationEngine } from './validation-engine';
|
|
4
|
+
import { WorkflowCompiler } from './workflow-compiler';
|
|
5
|
+
import { WorkflowInterpreter, NextStep } from './workflow-interpreter';
|
|
6
|
+
import type { ExecutionState } from '../../domain/execution/state';
|
|
7
|
+
import type { WorkflowEvent } from '../../domain/execution/event';
|
|
8
|
+
import type { DomainError } from '../../domain/execution/error';
|
|
9
|
+
import type { Result } from 'neverthrow';
|
|
1
10
|
export interface WorkflowService {
|
|
2
|
-
listWorkflowSummaries(): Promise<
|
|
3
|
-
getWorkflowById(id: string): Promise<
|
|
4
|
-
getNextStep(workflowId: string,
|
|
5
|
-
|
|
6
|
-
|
|
11
|
+
listWorkflowSummaries(): Promise<readonly WorkflowSummary[]>;
|
|
12
|
+
getWorkflowById(id: string): Promise<Workflow | null>;
|
|
13
|
+
getNextStep(workflowId: string, state: ExecutionState, event?: WorkflowEvent, context?: ConditionContext): Promise<Result<{
|
|
14
|
+
state: ExecutionState;
|
|
15
|
+
next: NextStep | null;
|
|
7
16
|
isComplete: boolean;
|
|
8
|
-
|
|
9
|
-
}>;
|
|
17
|
+
}, DomainError>>;
|
|
10
18
|
validateStepOutput(workflowId: string, stepId: string, output: string): Promise<{
|
|
11
19
|
valid: boolean;
|
|
12
|
-
issues: string[];
|
|
13
|
-
suggestions: string[];
|
|
20
|
+
issues: readonly string[];
|
|
21
|
+
suggestions: readonly string[];
|
|
14
22
|
}>;
|
|
15
23
|
}
|
|
16
|
-
import { Workflow, WorkflowSummary, WorkflowStep, WorkflowGuidance } from '../../types/mcp-types';
|
|
17
|
-
import { IWorkflowStorage } from '../../types/storage';
|
|
18
|
-
import { ConditionContext } from '../../utils/condition-evaluator';
|
|
19
|
-
import { ValidationEngine } from './validation-engine';
|
|
20
|
-
import { EnhancedContext } from '../../types/workflow-types';
|
|
21
|
-
import { ILoopContextOptimizer } from '../../types/loop-context-optimizer';
|
|
22
24
|
export declare class DefaultWorkflowService implements WorkflowService {
|
|
23
25
|
private readonly storage;
|
|
24
26
|
private readonly validationEngine;
|
|
25
|
-
private readonly
|
|
26
|
-
private
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
private readonly compiler;
|
|
28
|
+
private readonly interpreter;
|
|
29
|
+
private readonly logger;
|
|
30
|
+
private readonly compiledCache;
|
|
31
|
+
private readonly COMPILED_CACHE_MAX;
|
|
32
|
+
constructor(storage: import('../../types/storage').IWorkflowReader, validationEngine: ValidationEngine, compiler: WorkflowCompiler, interpreter: WorkflowInterpreter);
|
|
33
|
+
listWorkflowSummaries(): Promise<readonly WorkflowSummary[]>;
|
|
29
34
|
getWorkflowById(id: string): Promise<Workflow | null>;
|
|
30
|
-
getNextStep(workflowId: string,
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
getNextStep(workflowId: string, state: ExecutionState, event?: WorkflowEvent, context?: ConditionContext): Promise<Result<{
|
|
36
|
+
state: ExecutionState;
|
|
37
|
+
next: NextStep | null;
|
|
33
38
|
isComplete: boolean;
|
|
34
|
-
|
|
35
|
-
}>;
|
|
36
|
-
private buildStepPrompt;
|
|
37
|
-
private collectConditionVars;
|
|
38
|
-
private collectEqualsValues;
|
|
39
|
-
private findLoopStepById;
|
|
39
|
+
}, DomainError>>;
|
|
40
40
|
validateStepOutput(workflowId: string, stepId: string, output: string): Promise<{
|
|
41
41
|
valid: boolean;
|
|
42
|
-
issues: string[];
|
|
43
|
-
suggestions: string[];
|
|
42
|
+
issues: readonly string[];
|
|
43
|
+
suggestions: readonly string[];
|
|
44
44
|
}>;
|
|
45
|
-
|
|
45
|
+
private getOrCompile;
|
|
46
|
+
__debugCompiledCacheSize(): number;
|
|
47
|
+
__debugPrimeCompiledWorkflow(id: string): void;
|
|
48
|
+
private evictCompiledCacheIfNeeded;
|
|
46
49
|
}
|
|
47
|
-
export declare const defaultWorkflowService: WorkflowService;
|
|
@@ -1,21 +1,35 @@
|
|
|
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
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const condition_evaluator_1 = require("../../utils/condition-evaluator");
|
|
15
|
+
exports.DefaultWorkflowService = void 0;
|
|
16
|
+
const tsyringe_1 = require("tsyringe");
|
|
17
|
+
const tokens_js_1 = require("../../di/tokens.js");
|
|
7
18
|
const validation_engine_1 = require("./validation-engine");
|
|
8
|
-
const
|
|
9
|
-
const
|
|
10
|
-
const
|
|
11
|
-
const
|
|
12
|
-
const
|
|
13
|
-
class DefaultWorkflowService {
|
|
14
|
-
constructor(storage
|
|
19
|
+
const workflow_compiler_1 = require("./workflow-compiler");
|
|
20
|
+
const workflow_interpreter_1 = require("./workflow-interpreter");
|
|
21
|
+
const error_1 = require("../../domain/execution/error");
|
|
22
|
+
const neverthrow_1 = require("neverthrow");
|
|
23
|
+
const logger_1 = require("../../utils/logger");
|
|
24
|
+
let DefaultWorkflowService = class DefaultWorkflowService {
|
|
25
|
+
constructor(storage, validationEngine, compiler, interpreter) {
|
|
15
26
|
this.storage = storage;
|
|
16
27
|
this.validationEngine = validationEngine;
|
|
17
|
-
this.
|
|
18
|
-
this.
|
|
28
|
+
this.compiler = compiler;
|
|
29
|
+
this.interpreter = interpreter;
|
|
30
|
+
this.logger = (0, logger_1.createLogger)('WorkflowService');
|
|
31
|
+
this.compiledCache = new Map();
|
|
32
|
+
this.COMPILED_CACHE_MAX = 1000;
|
|
19
33
|
}
|
|
20
34
|
async listWorkflowSummaries() {
|
|
21
35
|
return this.storage.listWorkflowSummaries();
|
|
@@ -23,428 +37,82 @@ class DefaultWorkflowService {
|
|
|
23
37
|
async getWorkflowById(id) {
|
|
24
38
|
return this.storage.getWorkflowById(id);
|
|
25
39
|
}
|
|
26
|
-
async getNextStep(workflowId,
|
|
27
|
-
const sizeCheck = (0, context_size_1.checkContextSize)(context);
|
|
28
|
-
if (sizeCheck.isError) {
|
|
29
|
-
throw new Error(`Context size (${Math.round(sizeCheck.sizeBytes / 1024)}KB) exceeds maximum allowed size (256KB)`);
|
|
30
|
-
}
|
|
31
|
-
const checkedContext = sizeCheck.context;
|
|
40
|
+
async getNextStep(workflowId, state, event, context = {}) {
|
|
32
41
|
const workflow = await this.storage.getWorkflowById(workflowId);
|
|
33
|
-
if (!workflow)
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
const
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
bodyStepToLoop.set(loopStep.body, loopStep);
|
|
50
|
-
}
|
|
51
|
-
else if (Array.isArray(loopStep.body)) {
|
|
52
|
-
loopStep.body.forEach(bodyStep => {
|
|
53
|
-
loopBodySteps.add(bodyStep.id);
|
|
54
|
-
bodyStepToLoop.set(bodyStep.id, loopStep);
|
|
55
|
-
});
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
if (!enhancedContext._currentLoop) {
|
|
60
|
-
const completedLoopBodySteps = completed.filter(stepId => loopBodySteps.has(stepId));
|
|
61
|
-
if (completedLoopBodySteps.length > 0) {
|
|
62
|
-
const loopStep = bodyStepToLoop.get(completedLoopBodySteps[0]);
|
|
63
|
-
if (loopStep && !completed.includes(loopStep.id)) {
|
|
64
|
-
enhancedContext._currentLoop = {
|
|
65
|
-
loopId: loopStep.id,
|
|
66
|
-
loopStep: loopStep
|
|
67
|
-
};
|
|
68
|
-
if (!enhancedContext._loopState || !enhancedContext._loopState[loopStep.id]) {
|
|
69
|
-
const resolvedBody = this.loopStepResolver.resolveLoopBody(workflow, loopStep.body, loopStep.id);
|
|
70
|
-
let completedIterations = 0;
|
|
71
|
-
if (Array.isArray(resolvedBody)) {
|
|
72
|
-
const hasConditionalSteps = resolvedBody.some(step => step.runCondition);
|
|
73
|
-
if (hasConditionalSteps) {
|
|
74
|
-
completedIterations = completedLoopBodySteps.length;
|
|
75
|
-
}
|
|
76
|
-
else {
|
|
77
|
-
completedIterations = 0;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
else {
|
|
81
|
-
completedIterations = completedLoopBodySteps.length;
|
|
82
|
-
}
|
|
83
|
-
if (!enhancedContext._loopState) {
|
|
84
|
-
enhancedContext._loopState = {};
|
|
85
|
-
}
|
|
86
|
-
enhancedContext._loopState[loopStep.id] = {
|
|
87
|
-
iteration: completedIterations,
|
|
88
|
-
started: Date.now(),
|
|
89
|
-
warnings: []
|
|
90
|
-
};
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (enhancedContext._currentLoop) {
|
|
96
|
-
const { loopId, loopStep } = enhancedContext._currentLoop;
|
|
97
|
-
const loopContext = new loop_execution_context_1.LoopExecutionContext(loopId, loopStep.loop, enhancedContext._loopState?.[loopId]);
|
|
98
|
-
const bodyStep = this.loopStepResolver.resolveLoopBody(workflow, loopStep.body, loopStep.id);
|
|
99
|
-
let bodyIsCompleted;
|
|
100
|
-
if (Array.isArray(bodyStep)) {
|
|
101
|
-
const loopEnhancedContext = loopContext.injectVariables(enhancedContext, false);
|
|
102
|
-
const eligibleSteps = bodyStep.filter(step => {
|
|
103
|
-
if (!step.runCondition) {
|
|
104
|
-
return true;
|
|
105
|
-
}
|
|
106
|
-
return (0, condition_evaluator_1.evaluateCondition)(step.runCondition, loopEnhancedContext);
|
|
107
|
-
});
|
|
108
|
-
bodyIsCompleted = eligibleSteps.length === 0 || eligibleSteps.every(step => completed.includes(step.id));
|
|
109
|
-
}
|
|
110
|
-
else {
|
|
111
|
-
bodyIsCompleted = completed.includes(bodyStep.id);
|
|
112
|
-
}
|
|
113
|
-
if (bodyIsCompleted) {
|
|
114
|
-
loopContext.incrementIteration();
|
|
115
|
-
if (!enhancedContext._loopState) {
|
|
116
|
-
enhancedContext._loopState = {};
|
|
117
|
-
}
|
|
118
|
-
enhancedContext._loopState[loopId] = loopContext.getCurrentState();
|
|
119
|
-
if (Array.isArray(bodyStep)) {
|
|
120
|
-
bodyStep.forEach(step => {
|
|
121
|
-
const index = completed.indexOf(step.id);
|
|
122
|
-
if (index > -1) {
|
|
123
|
-
completed.splice(index, 1);
|
|
124
|
-
}
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
else {
|
|
128
|
-
const index = completed.indexOf(bodyStep.id);
|
|
129
|
-
if (index > -1) {
|
|
130
|
-
completed.splice(index, 1);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
if (!loopContext.shouldContinue(context)) {
|
|
134
|
-
completed.push(loopId);
|
|
135
|
-
delete enhancedContext._currentLoop;
|
|
136
|
-
const nextStep = await this.getNextStep(workflow.id, completed, enhancedContext);
|
|
137
|
-
return nextStep;
|
|
138
|
-
}
|
|
139
|
-
}
|
|
140
|
-
if (loopContext.shouldContinue(context)) {
|
|
141
|
-
if (!Array.isArray(bodyStep)) {
|
|
142
|
-
const isFirst = loopContext.isFirstIteration();
|
|
143
|
-
if (isFirst && loopContext.isEmpty(context)) {
|
|
144
|
-
const skipContext = context_optimizer_1.ContextOptimizer.createEnhancedContext(context, completed);
|
|
145
|
-
delete skipContext._currentLoop;
|
|
146
|
-
const nextStep = await this.getNextStep(workflow.id, completed, skipContext);
|
|
147
|
-
return nextStep;
|
|
148
|
-
}
|
|
149
|
-
const useMinimal = !isFirst && !!this.loopContextOptimizer;
|
|
150
|
-
const loopEnhancedContext = loopContext.injectVariables(context, useMinimal);
|
|
151
|
-
const optimizedContext = useMinimal && this.loopContextOptimizer
|
|
152
|
-
? this.loopContextOptimizer.stripLoopMetadata(loopEnhancedContext)
|
|
153
|
-
: loopEnhancedContext;
|
|
154
|
-
const loopSizeCheck = (0, context_size_1.checkContextSize)(optimizedContext);
|
|
155
|
-
if (loopSizeCheck.isError) {
|
|
156
|
-
throw new Error(`Context size (${Math.round(loopSizeCheck.sizeBytes / 1024)}KB) exceeds maximum allowed size (256KB) during loop execution`);
|
|
157
|
-
}
|
|
158
|
-
return {
|
|
159
|
-
step: bodyStep,
|
|
160
|
-
guidance: {
|
|
161
|
-
prompt: this.buildStepPrompt(bodyStep, loopContext, useMinimal)
|
|
162
|
-
},
|
|
163
|
-
isComplete: false,
|
|
164
|
-
context: loopSizeCheck.context
|
|
165
|
-
};
|
|
166
|
-
}
|
|
167
|
-
else {
|
|
168
|
-
const isFirst = loopContext.isFirstIteration();
|
|
169
|
-
if (isFirst && loopContext.isEmpty(context)) {
|
|
170
|
-
const skipContext = context_optimizer_1.ContextOptimizer.createEnhancedContext(context, completed);
|
|
171
|
-
delete skipContext._currentLoop;
|
|
172
|
-
const nextStep = await this.getNextStep(workflow.id, completed, skipContext);
|
|
173
|
-
return nextStep;
|
|
174
|
-
}
|
|
175
|
-
const useMinimal = !isFirst && !!this.loopContextOptimizer;
|
|
176
|
-
const loopEnhancedContext = loopContext.injectVariables(context, useMinimal);
|
|
177
|
-
const uncompletedBodyStep = bodyStep.find(step => {
|
|
178
|
-
if (completed.includes(step.id)) {
|
|
179
|
-
return false;
|
|
180
|
-
}
|
|
181
|
-
if (step.runCondition) {
|
|
182
|
-
return (0, condition_evaluator_1.evaluateCondition)(step.runCondition, loopEnhancedContext);
|
|
183
|
-
}
|
|
184
|
-
return true;
|
|
185
|
-
});
|
|
186
|
-
if (uncompletedBodyStep) {
|
|
187
|
-
const optimizedContext = useMinimal && this.loopContextOptimizer
|
|
188
|
-
? this.loopContextOptimizer.stripLoopMetadata(loopEnhancedContext)
|
|
189
|
-
: loopEnhancedContext;
|
|
190
|
-
const loopSizeCheck = (0, context_size_1.checkContextSize)(optimizedContext);
|
|
191
|
-
if (loopSizeCheck.isError) {
|
|
192
|
-
throw new Error(`Context size (${Math.round(loopSizeCheck.sizeBytes / 1024)}KB) exceeds maximum allowed size (256KB) during loop execution`);
|
|
193
|
-
}
|
|
194
|
-
return {
|
|
195
|
-
step: uncompletedBodyStep,
|
|
196
|
-
guidance: {
|
|
197
|
-
prompt: this.buildStepPrompt(uncompletedBodyStep, loopContext, useMinimal)
|
|
198
|
-
},
|
|
199
|
-
isComplete: false,
|
|
200
|
-
context: loopSizeCheck.context
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
else {
|
|
204
|
-
loopContext.incrementIteration();
|
|
205
|
-
if (!enhancedContext._loopState) {
|
|
206
|
-
enhancedContext._loopState = {};
|
|
207
|
-
}
|
|
208
|
-
enhancedContext._loopState[loopId] = loopContext.getCurrentState();
|
|
209
|
-
bodyStep.forEach(step => {
|
|
210
|
-
const index = completed.indexOf(step.id);
|
|
211
|
-
if (index > -1) {
|
|
212
|
-
completed.splice(index, 1);
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
return this.getNextStep(workflowId, completed, enhancedContext);
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
}
|
|
219
|
-
else {
|
|
220
|
-
completed.push(loopId);
|
|
221
|
-
delete enhancedContext._currentLoop;
|
|
222
|
-
}
|
|
223
|
-
}
|
|
224
|
-
const nextStep = workflow.steps.find((step) => {
|
|
225
|
-
if (completed.includes(step.id)) {
|
|
226
|
-
return false;
|
|
227
|
-
}
|
|
228
|
-
if (loopBodySteps.has(step.id)) {
|
|
229
|
-
if (!enhancedContext._currentLoop) {
|
|
230
|
-
return false;
|
|
231
|
-
}
|
|
232
|
-
const currentLoopBody = enhancedContext._currentLoop.loopStep.body;
|
|
233
|
-
if (typeof currentLoopBody === 'string') {
|
|
234
|
-
return currentLoopBody === step.id;
|
|
235
|
-
}
|
|
236
|
-
else if (Array.isArray(currentLoopBody)) {
|
|
237
|
-
return currentLoopBody.some(bodyStep => bodyStep.id === step.id);
|
|
238
|
-
}
|
|
239
|
-
return false;
|
|
240
|
-
}
|
|
241
|
-
if (step.runCondition) {
|
|
242
|
-
return (0, condition_evaluator_1.evaluateCondition)(step.runCondition, context);
|
|
243
|
-
}
|
|
244
|
-
return true;
|
|
245
|
-
}) || null;
|
|
246
|
-
if (nextStep && (0, workflow_types_1.isLoopStep)(nextStep)) {
|
|
247
|
-
const loopStep = nextStep;
|
|
248
|
-
const loopContext = new loop_execution_context_1.LoopExecutionContext(nextStep.id, loopStep.loop, enhancedContext._loopState?.[nextStep.id]);
|
|
249
|
-
if (loopStep.loop.type === 'forEach') {
|
|
250
|
-
loopContext.initializeForEach(context);
|
|
251
|
-
}
|
|
252
|
-
if (!loopContext.shouldContinue(context)) {
|
|
253
|
-
completed.push(nextStep.id);
|
|
254
|
-
const loopStateData = loopContext.getCurrentState();
|
|
255
|
-
let skipContext = context_optimizer_1.ContextOptimizer.mergeLoopState(context, nextStep.id, loopStateData);
|
|
256
|
-
if (loopStateData.warnings && loopStateData.warnings.length > 0) {
|
|
257
|
-
skipContext = context_optimizer_1.ContextOptimizer.addWarnings(skipContext, 'loops', nextStep.id, loopStateData.warnings);
|
|
258
|
-
}
|
|
259
|
-
return this.getNextStep(workflowId, completed, skipContext);
|
|
260
|
-
}
|
|
261
|
-
let newContext = context_optimizer_1.ContextOptimizer.createEnhancedContext(context, {
|
|
262
|
-
_currentLoop: {
|
|
263
|
-
loopId: nextStep.id,
|
|
264
|
-
loopStep: loopStep
|
|
265
|
-
}
|
|
266
|
-
});
|
|
267
|
-
newContext = context_optimizer_1.ContextOptimizer.mergeLoopState(newContext, nextStep.id, loopContext.getCurrentState());
|
|
268
|
-
const loopStartSizeCheck = (0, context_size_1.checkContextSize)(newContext);
|
|
269
|
-
if (loopStartSizeCheck.isError) {
|
|
270
|
-
throw new Error(`Context size (${Math.round(loopStartSizeCheck.sizeBytes / 1024)}KB) exceeds maximum allowed size (256KB) when starting loop`);
|
|
271
|
-
}
|
|
272
|
-
return this.getNextStep(workflowId, completedSteps, loopStartSizeCheck.context);
|
|
273
|
-
}
|
|
274
|
-
if (!nextStep) {
|
|
275
|
-
const remainingConditionalSteps = workflow.steps.filter((step) => {
|
|
276
|
-
if (completed.includes(step.id))
|
|
277
|
-
return false;
|
|
278
|
-
if (loopBodySteps.has(step.id))
|
|
279
|
-
return false;
|
|
280
|
-
return !!step.runCondition;
|
|
281
|
-
});
|
|
282
|
-
if (remainingConditionalSteps.length > 0) {
|
|
283
|
-
const requiredVars = new Set();
|
|
284
|
-
const allowedValues = {};
|
|
285
|
-
for (const step of remainingConditionalSteps) {
|
|
286
|
-
const condition = step.runCondition;
|
|
287
|
-
this.collectConditionVars(condition, requiredVars);
|
|
288
|
-
this.collectEqualsValues(condition, allowedValues);
|
|
289
|
-
}
|
|
290
|
-
const issues = [];
|
|
291
|
-
for (const variableName of requiredVars) {
|
|
292
|
-
const currentValue = enhancedContext[variableName];
|
|
293
|
-
const allowed = allowedValues[variableName]
|
|
294
|
-
? Array.from(allowedValues[variableName])
|
|
295
|
-
: [];
|
|
296
|
-
if (currentValue === undefined || currentValue === null || currentValue === '') {
|
|
297
|
-
if (allowed.length > 0) {
|
|
298
|
-
issues.push(`Set '${variableName}' to one of: ${allowed.map(v => `'${v}'`).join(', ')}`);
|
|
299
|
-
}
|
|
300
|
-
else {
|
|
301
|
-
issues.push(`Provide a value for '${variableName}'`);
|
|
302
|
-
}
|
|
303
|
-
}
|
|
304
|
-
else if (allowed.length > 0) {
|
|
305
|
-
const matchesExactly = allowed.some(v => v === String(currentValue));
|
|
306
|
-
const matchesCaseInsensitive = allowed.some(v => v.toLowerCase() === String(currentValue).toLowerCase());
|
|
307
|
-
if (!matchesExactly) {
|
|
308
|
-
if (matchesCaseInsensitive) {
|
|
309
|
-
issues.push(`Normalize casing for '${variableName}': use one of ${allowed.map(v => `'${v}'`).join(', ')} (current '${currentValue}')`);
|
|
310
|
-
}
|
|
311
|
-
else {
|
|
312
|
-
issues.push(`Adjust '${variableName}' to one of: ${allowed.map(v => `'${v}'`).join(', ')} (current '${currentValue}')`);
|
|
313
|
-
}
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
}
|
|
317
|
-
if (issues.length > 0) {
|
|
318
|
-
return {
|
|
319
|
-
step: null,
|
|
320
|
-
guidance: {
|
|
321
|
-
prompt: `No eligible step due to unmet conditions. Please update context:\n- ${issues.join('\n- ')}`
|
|
322
|
-
},
|
|
323
|
-
isComplete: false,
|
|
324
|
-
context: enhancedContext
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
}
|
|
329
|
-
const isComplete = !nextStep;
|
|
330
|
-
let finalPrompt = 'Workflow complete.';
|
|
331
|
-
if (nextStep) {
|
|
332
|
-
finalPrompt = this.buildStepPrompt(nextStep);
|
|
333
|
-
}
|
|
334
|
-
return {
|
|
335
|
-
step: nextStep,
|
|
336
|
-
guidance: {
|
|
337
|
-
prompt: finalPrompt
|
|
338
|
-
},
|
|
339
|
-
isComplete,
|
|
340
|
-
context: enhancedContext
|
|
341
|
-
};
|
|
342
|
-
}
|
|
343
|
-
buildStepPrompt(step, loopContext, useMinimal = false) {
|
|
344
|
-
let stepGuidance = '';
|
|
345
|
-
if (step.guidance && step.guidance.length > 0) {
|
|
346
|
-
const guidanceHeader = '## Step Guidance';
|
|
347
|
-
const guidanceList = step.guidance.map((g) => `- ${g}`).join('\n');
|
|
348
|
-
stepGuidance = `${guidanceHeader}\n${guidanceList}\n\n`;
|
|
349
|
-
}
|
|
350
|
-
let finalPrompt = `${stepGuidance}${step.prompt}`;
|
|
351
|
-
if (step.agentRole) {
|
|
352
|
-
finalPrompt = `## Agent Role Instructions\n${step.agentRole}\n\n${finalPrompt}`;
|
|
353
|
-
}
|
|
354
|
-
if (loopContext) {
|
|
355
|
-
const state = loopContext.getCurrentState();
|
|
356
|
-
if (useMinimal && this.loopContextOptimizer) {
|
|
357
|
-
finalPrompt += `\n\n## Loop Context\n- Iteration: ${state.iteration + 1}`;
|
|
358
|
-
if (!loopContext.isFirstIteration()) {
|
|
359
|
-
finalPrompt += '\n\n_Note: Refer to the phase overview provided in the first iteration for overall context._';
|
|
360
|
-
}
|
|
361
|
-
}
|
|
362
|
-
else {
|
|
363
|
-
finalPrompt += `\n\n## Loop Context\n- Iteration: ${state.iteration + 1}`;
|
|
364
|
-
if (state.items) {
|
|
365
|
-
finalPrompt += `\n- Total Items: ${state.items.length}`;
|
|
366
|
-
finalPrompt += `\n- Current Index: ${state.index}`;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
}
|
|
370
|
-
return finalPrompt;
|
|
371
|
-
}
|
|
372
|
-
collectConditionVars(condition, sink) {
|
|
373
|
-
if (!condition || typeof condition !== 'object')
|
|
374
|
-
return;
|
|
375
|
-
if (typeof condition.var === 'string' && condition.var.length > 0) {
|
|
376
|
-
sink.add(condition.var);
|
|
377
|
-
}
|
|
378
|
-
if (Array.isArray(condition.and)) {
|
|
379
|
-
for (const sub of condition.and)
|
|
380
|
-
this.collectConditionVars(sub, sink);
|
|
381
|
-
}
|
|
382
|
-
if (Array.isArray(condition.or)) {
|
|
383
|
-
for (const sub of condition.or)
|
|
384
|
-
this.collectConditionVars(sub, sink);
|
|
385
|
-
}
|
|
386
|
-
if (condition.not)
|
|
387
|
-
this.collectConditionVars(condition.not, sink);
|
|
388
|
-
}
|
|
389
|
-
collectEqualsValues(condition, sink) {
|
|
390
|
-
if (!condition || typeof condition !== 'object')
|
|
391
|
-
return;
|
|
392
|
-
if (typeof condition.var === 'string' && Object.prototype.hasOwnProperty.call(condition, 'equals')) {
|
|
393
|
-
const variableName = condition.var;
|
|
394
|
-
const value = condition.equals;
|
|
395
|
-
if (value !== undefined && value !== null) {
|
|
396
|
-
if (!sink[variableName])
|
|
397
|
-
sink[variableName] = new Set();
|
|
398
|
-
sink[variableName].add(String(value));
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
if (Array.isArray(condition.and)) {
|
|
402
|
-
for (const sub of condition.and)
|
|
403
|
-
this.collectEqualsValues(sub, sink);
|
|
404
|
-
}
|
|
405
|
-
if (Array.isArray(condition.or)) {
|
|
406
|
-
for (const sub of condition.or)
|
|
407
|
-
this.collectEqualsValues(sub, sink);
|
|
408
|
-
}
|
|
409
|
-
if (condition.not)
|
|
410
|
-
this.collectEqualsValues(condition.not, sink);
|
|
411
|
-
}
|
|
412
|
-
findLoopStepById(workflow, stepId) {
|
|
413
|
-
const step = workflow.steps.find(s => s.id === stepId);
|
|
414
|
-
return step && (0, workflow_types_1.isLoopStep)(step) ? step : null;
|
|
42
|
+
if (!workflow)
|
|
43
|
+
return (0, neverthrow_1.err)(error_1.Err.workflowNotFound(workflowId));
|
|
44
|
+
const compiled = this.getOrCompile(workflowId, workflow);
|
|
45
|
+
if (compiled.isErr())
|
|
46
|
+
return (0, neverthrow_1.err)(compiled.error);
|
|
47
|
+
const advancedState = event ? this.interpreter.applyEvent(state, event) : (0, neverthrow_1.ok)(state);
|
|
48
|
+
if (advancedState.isErr())
|
|
49
|
+
return (0, neverthrow_1.err)(advancedState.error);
|
|
50
|
+
const next = this.interpreter.next(compiled.value, advancedState.value, context);
|
|
51
|
+
if (next.isErr())
|
|
52
|
+
return (0, neverthrow_1.err)(next.error);
|
|
53
|
+
return (0, neverthrow_1.ok)({
|
|
54
|
+
state: next.value.state,
|
|
55
|
+
next: next.value.next,
|
|
56
|
+
isComplete: next.value.isComplete,
|
|
57
|
+
});
|
|
415
58
|
}
|
|
416
59
|
async validateStepOutput(workflowId, stepId, output) {
|
|
417
60
|
const workflow = await this.storage.getWorkflowById(workflowId);
|
|
418
61
|
if (!workflow) {
|
|
419
|
-
|
|
62
|
+
return { valid: false, issues: [`Workflow '${workflowId}' not found`], suggestions: [] };
|
|
420
63
|
}
|
|
421
|
-
const step = workflow.steps.find((s) => s.id === stepId);
|
|
64
|
+
const step = workflow.definition.steps.find((s) => s.id === stepId);
|
|
422
65
|
if (!step) {
|
|
423
|
-
|
|
66
|
+
return { valid: false, issues: [`Step '${stepId}' not found in workflow '${workflowId}'`], suggestions: [] };
|
|
424
67
|
}
|
|
425
|
-
const criteria = step.validationCriteria
|
|
68
|
+
const criteria = step.validationCriteria;
|
|
69
|
+
if (!criteria)
|
|
70
|
+
return { valid: true, issues: [], suggestions: [] };
|
|
426
71
|
return this.validationEngine.validate(output, criteria);
|
|
427
72
|
}
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
if (
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
73
|
+
getOrCompile(workflowId, workflow) {
|
|
74
|
+
const cached = this.compiledCache.get(workflowId);
|
|
75
|
+
if (cached)
|
|
76
|
+
return (0, neverthrow_1.ok)(cached);
|
|
77
|
+
const validation = this.validationEngine.validateWorkflow(workflow);
|
|
78
|
+
if (!validation.valid) {
|
|
79
|
+
return (0, neverthrow_1.err)(error_1.Err.invalidState(`Invalid workflow structure: ${validation.issues.join('; ')}`));
|
|
80
|
+
}
|
|
81
|
+
const compiled = this.compiler.compile(workflow);
|
|
82
|
+
if (compiled.isErr())
|
|
83
|
+
return (0, neverthrow_1.err)(compiled.error);
|
|
84
|
+
this.compiledCache.set(workflowId, compiled.value);
|
|
85
|
+
this.evictCompiledCacheIfNeeded();
|
|
86
|
+
return (0, neverthrow_1.ok)(compiled.value);
|
|
87
|
+
}
|
|
88
|
+
__debugCompiledCacheSize() {
|
|
89
|
+
return this.compiledCache.size;
|
|
90
|
+
}
|
|
91
|
+
__debugPrimeCompiledWorkflow(id) {
|
|
92
|
+
if (this.compiledCache.has(id))
|
|
93
|
+
return;
|
|
94
|
+
this.compiledCache.set(id, {});
|
|
95
|
+
this.evictCompiledCacheIfNeeded();
|
|
96
|
+
}
|
|
97
|
+
evictCompiledCacheIfNeeded() {
|
|
98
|
+
if (this.compiledCache.size <= this.COMPILED_CACHE_MAX)
|
|
99
|
+
return;
|
|
100
|
+
while (this.compiledCache.size > this.COMPILED_CACHE_MAX) {
|
|
101
|
+
const oldestKey = this.compiledCache.keys().next().value;
|
|
102
|
+
if (!oldestKey)
|
|
103
|
+
return;
|
|
104
|
+
this.compiledCache.delete(oldestKey);
|
|
445
105
|
}
|
|
446
|
-
return sizeCheck.context;
|
|
447
106
|
}
|
|
448
|
-
}
|
|
107
|
+
};
|
|
449
108
|
exports.DefaultWorkflowService = DefaultWorkflowService;
|
|
450
|
-
exports.
|
|
109
|
+
exports.DefaultWorkflowService = DefaultWorkflowService = __decorate([
|
|
110
|
+
(0, tsyringe_1.singleton)(),
|
|
111
|
+
__param(0, (0, tsyringe_1.inject)(tokens_js_1.DI.Storage.Primary)),
|
|
112
|
+
__param(1, (0, tsyringe_1.inject)(validation_engine_1.ValidationEngine)),
|
|
113
|
+
__param(2, (0, tsyringe_1.inject)(workflow_compiler_1.WorkflowCompiler)),
|
|
114
|
+
__param(3, (0, tsyringe_1.inject)(workflow_interpreter_1.WorkflowInterpreter)),
|
|
115
|
+
__metadata("design:paramtypes", [Object, validation_engine_1.ValidationEngine,
|
|
116
|
+
workflow_compiler_1.WorkflowCompiler,
|
|
117
|
+
workflow_interpreter_1.WorkflowInterpreter])
|
|
118
|
+
], DefaultWorkflowService);
|
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import { WorkflowService } from '../services/workflow-service';
|
|
2
|
-
import { WorkflowStep, WorkflowGuidance } from '../../types/mcp-types';
|
|
3
2
|
import { ConditionContext } from '../../utils/condition-evaluator';
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
3
|
+
import type { ExecutionState } from '../../domain/execution/state';
|
|
4
|
+
import type { WorkflowEvent } from '../../domain/execution/event';
|
|
5
|
+
export declare function createGetNextStep(service: WorkflowService): (workflowId: string, state: ExecutionState, event?: WorkflowEvent, context?: ConditionContext) => Promise<import("neverthrow").Result<{
|
|
6
|
+
state: ExecutionState;
|
|
7
|
+
next: import("../services/workflow-interpreter").NextStep | null;
|
|
7
8
|
isComplete: boolean;
|
|
8
|
-
}
|
|
9
|
-
export declare function getNextStep(service: WorkflowService, workflowId: string, completedSteps: string[], context?: ConditionContext): Promise<{
|
|
10
|
-
step: WorkflowStep | null;
|
|
11
|
-
guidance: WorkflowGuidance;
|
|
12
|
-
isComplete: boolean;
|
|
13
|
-
}>;
|
|
9
|
+
}, import("../../domain/execution/error").DomainError>>;
|