@falai/agent 1.2.8 → 2.0.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 +40 -886
- package/dist/adapters/MemoryAdapter.js +2 -2
- package/dist/adapters/MemoryAdapter.js.map +1 -1
- package/dist/adapters/MongoAdapter.js +2 -2
- package/dist/adapters/MongoAdapter.js.map +1 -1
- package/dist/adapters/OpenSearchAdapter.d.ts.map +1 -1
- package/dist/adapters/OpenSearchAdapter.js +9 -7
- package/dist/adapters/OpenSearchAdapter.js.map +1 -1
- package/dist/adapters/PostgreSQLAdapter.d.ts +14 -0
- package/dist/adapters/PostgreSQLAdapter.d.ts.map +1 -1
- package/dist/adapters/PostgreSQLAdapter.js +25 -9
- package/dist/adapters/PostgreSQLAdapter.js.map +1 -1
- package/dist/adapters/PrismaAdapter.js +5 -5
- package/dist/adapters/PrismaAdapter.js.map +1 -1
- package/dist/adapters/RedisAdapter.js +2 -2
- package/dist/adapters/RedisAdapter.js.map +1 -1
- package/dist/adapters/SQLiteAdapter.d.ts +17 -0
- package/dist/adapters/SQLiteAdapter.d.ts.map +1 -1
- package/dist/adapters/SQLiteAdapter.js +30 -11
- package/dist/adapters/SQLiteAdapter.js.map +1 -1
- package/dist/cjs/adapters/MemoryAdapter.js +2 -2
- package/dist/cjs/adapters/MemoryAdapter.js.map +1 -1
- package/dist/cjs/adapters/MongoAdapter.js +2 -2
- package/dist/cjs/adapters/MongoAdapter.js.map +1 -1
- package/dist/cjs/adapters/OpenSearchAdapter.d.ts.map +1 -1
- package/dist/cjs/adapters/OpenSearchAdapter.js +9 -7
- package/dist/cjs/adapters/OpenSearchAdapter.js.map +1 -1
- package/dist/cjs/adapters/PostgreSQLAdapter.d.ts +14 -0
- package/dist/cjs/adapters/PostgreSQLAdapter.d.ts.map +1 -1
- package/dist/cjs/adapters/PostgreSQLAdapter.js +25 -9
- package/dist/cjs/adapters/PostgreSQLAdapter.js.map +1 -1
- package/dist/cjs/adapters/PrismaAdapter.js +5 -5
- package/dist/cjs/adapters/PrismaAdapter.js.map +1 -1
- package/dist/cjs/adapters/RedisAdapter.js +2 -2
- package/dist/cjs/adapters/RedisAdapter.js.map +1 -1
- package/dist/cjs/adapters/SQLiteAdapter.d.ts +17 -0
- package/dist/cjs/adapters/SQLiteAdapter.d.ts.map +1 -1
- package/dist/cjs/adapters/SQLiteAdapter.js +30 -11
- package/dist/cjs/adapters/SQLiteAdapter.js.map +1 -1
- package/dist/cjs/constants/index.d.ts +0 -9
- package/dist/cjs/constants/index.d.ts.map +1 -1
- package/dist/cjs/constants/index.js +2 -11
- package/dist/cjs/constants/index.js.map +1 -1
- package/dist/cjs/core/Agent.d.ts +119 -153
- package/dist/cjs/core/Agent.d.ts.map +1 -1
- package/dist/cjs/core/Agent.js +471 -324
- package/dist/cjs/core/Agent.js.map +1 -1
- package/dist/cjs/core/AutoChainExecutor.d.ts +107 -0
- package/dist/cjs/core/AutoChainExecutor.d.ts.map +1 -0
- package/dist/cjs/core/AutoChainExecutor.js +297 -0
- package/dist/cjs/core/AutoChainExecutor.js.map +1 -0
- package/dist/cjs/core/BranchEvaluator.d.ts +54 -0
- package/dist/cjs/core/BranchEvaluator.d.ts.map +1 -0
- package/dist/cjs/core/BranchEvaluator.js +130 -0
- package/dist/cjs/core/BranchEvaluator.js.map +1 -0
- package/dist/cjs/core/DirectiveBus.d.ts +88 -0
- package/dist/cjs/core/DirectiveBus.d.ts.map +1 -0
- package/dist/cjs/core/DirectiveBus.js +196 -0
- package/dist/cjs/core/DirectiveBus.js.map +1 -0
- package/dist/cjs/core/DirectiveChainTracker.d.ts +49 -0
- package/dist/cjs/core/DirectiveChainTracker.d.ts.map +1 -0
- package/dist/cjs/core/DirectiveChainTracker.js +121 -0
- package/dist/cjs/core/DirectiveChainTracker.js.map +1 -0
- package/dist/cjs/core/Flow.d.ts +186 -0
- package/dist/cjs/core/Flow.d.ts.map +1 -0
- package/dist/cjs/core/Flow.js +550 -0
- package/dist/cjs/core/Flow.js.map +1 -0
- package/dist/cjs/core/FlowRouter.d.ts +182 -0
- package/dist/cjs/core/FlowRouter.d.ts.map +1 -0
- package/dist/cjs/core/{RoutingEngine.js → FlowRouter.js} +323 -306
- package/dist/cjs/core/FlowRouter.js.map +1 -0
- package/dist/cjs/core/PersistenceManager.d.ts +2 -2
- package/dist/cjs/core/PersistenceManager.d.ts.map +1 -1
- package/dist/cjs/core/PersistenceManager.js +7 -7
- package/dist/cjs/core/PersistenceManager.js.map +1 -1
- package/dist/cjs/core/PromptComposer.d.ts +21 -8
- package/dist/cjs/core/PromptComposer.d.ts.map +1 -1
- package/dist/cjs/core/PromptComposer.js +182 -105
- package/dist/cjs/core/PromptComposer.js.map +1 -1
- package/dist/cjs/core/PromptSectionCache.d.ts +1 -1
- package/dist/cjs/core/PromptSectionCache.js +1 -1
- package/dist/cjs/core/ResponseEngine.d.ts +18 -8
- package/dist/cjs/core/ResponseEngine.d.ts.map +1 -1
- package/dist/cjs/core/ResponseEngine.js +38 -36
- package/dist/cjs/core/ResponseEngine.js.map +1 -1
- package/dist/cjs/core/ResponseModal.d.ts +73 -56
- package/dist/cjs/core/ResponseModal.d.ts.map +1 -1
- package/dist/cjs/core/ResponseModal.js +1191 -1014
- package/dist/cjs/core/ResponseModal.js.map +1 -1
- package/dist/cjs/core/ResponsePipeline.d.ts +124 -26
- package/dist/cjs/core/ResponsePipeline.d.ts.map +1 -1
- package/dist/cjs/core/ResponsePipeline.js +509 -136
- package/dist/cjs/core/ResponsePipeline.js.map +1 -1
- package/dist/cjs/core/SignalEvaluator.d.ts +86 -0
- package/dist/cjs/core/SignalEvaluator.d.ts.map +1 -0
- package/dist/cjs/core/SignalEvaluator.js +333 -0
- package/dist/cjs/core/SignalEvaluator.js.map +1 -0
- package/dist/cjs/core/SignalProcessor.d.ts +152 -0
- package/dist/cjs/core/SignalProcessor.d.ts.map +1 -0
- package/dist/cjs/core/SignalProcessor.js +562 -0
- package/dist/cjs/core/SignalProcessor.js.map +1 -0
- package/dist/cjs/core/Step.d.ts +43 -32
- package/dist/cjs/core/Step.d.ts.map +1 -1
- package/dist/cjs/core/Step.js +221 -126
- package/dist/cjs/core/Step.js.map +1 -1
- package/dist/cjs/core/StreamingToolExecutor.d.ts +2 -2
- package/dist/cjs/core/StreamingToolExecutor.d.ts.map +1 -1
- package/dist/cjs/core/StreamingToolExecutor.js.map +1 -1
- package/dist/cjs/core/ToolManager.d.ts +44 -13
- package/dist/cjs/core/ToolManager.d.ts.map +1 -1
- package/dist/cjs/core/ToolManager.js +174 -91
- package/dist/cjs/core/ToolManager.js.map +1 -1
- package/dist/cjs/core/createAgent.d.ts +35 -0
- package/dist/cjs/core/createAgent.d.ts.map +1 -0
- package/dist/cjs/core/createAgent.js +39 -0
- package/dist/cjs/core/createAgent.js.map +1 -0
- package/dist/cjs/core/flow-namespace.d.ts +49 -0
- package/dist/cjs/core/flow-namespace.d.ts.map +1 -0
- package/dist/cjs/core/flow-namespace.js +171 -0
- package/dist/cjs/core/flow-namespace.js.map +1 -0
- package/dist/cjs/index.d.ts +11 -14
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +18 -22
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/types/agent.d.ts +183 -54
- package/dist/cjs/types/agent.d.ts.map +1 -1
- package/dist/cjs/types/agent.js +0 -6
- package/dist/cjs/types/agent.js.map +1 -1
- package/dist/cjs/types/ai.d.ts +3 -3
- package/dist/cjs/types/ai.d.ts.map +1 -1
- package/dist/cjs/types/errors.d.ts +15 -0
- package/dist/cjs/types/errors.d.ts.map +1 -0
- package/dist/cjs/types/errors.js +22 -0
- package/dist/cjs/types/errors.js.map +1 -0
- package/dist/cjs/types/flow.d.ts +513 -0
- package/dist/cjs/types/flow.d.ts.map +1 -0
- package/dist/cjs/types/{route.js → flow.js} +2 -2
- package/dist/cjs/types/flow.js.map +1 -0
- package/dist/cjs/types/index.d.ts +7 -6
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/index.js +6 -2
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/persistence.d.ts +11 -7
- package/dist/cjs/types/persistence.d.ts.map +1 -1
- package/dist/cjs/types/routing.d.ts +1 -1
- package/dist/cjs/types/routing.d.ts.map +1 -1
- package/dist/cjs/types/session.d.ts +24 -23
- package/dist/cjs/types/session.d.ts.map +1 -1
- package/dist/cjs/types/signals.d.ts +248 -0
- package/dist/cjs/types/signals.d.ts.map +1 -0
- package/dist/cjs/types/signals.js +11 -0
- package/dist/cjs/types/signals.js.map +1 -0
- package/dist/cjs/types/template.d.ts +2 -8
- package/dist/cjs/types/template.d.ts.map +1 -1
- package/dist/cjs/types/tool.d.ts +36 -29
- package/dist/cjs/types/tool.d.ts.map +1 -1
- package/dist/cjs/types/tool.js +1 -1
- package/dist/cjs/types/tool.js.map +1 -1
- package/dist/cjs/utils/condition.d.ts +7 -1
- package/dist/cjs/utils/condition.d.ts.map +1 -1
- package/dist/cjs/utils/condition.js.map +1 -1
- package/dist/cjs/utils/id.d.ts +13 -5
- package/dist/cjs/utils/id.d.ts.map +1 -1
- package/dist/cjs/utils/id.js +24 -10
- package/dist/cjs/utils/id.js.map +1 -1
- package/dist/cjs/utils/index.d.ts +2 -2
- package/dist/cjs/utils/index.d.ts.map +1 -1
- package/dist/cjs/utils/index.js +7 -3
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/session.d.ts +44 -5
- package/dist/cjs/utils/session.d.ts.map +1 -1
- package/dist/cjs/utils/session.js +197 -38
- package/dist/cjs/utils/session.js.map +1 -1
- package/dist/constants/index.d.ts +0 -9
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/constants/index.js +3 -9
- package/dist/constants/index.js.map +1 -1
- package/dist/core/Agent.d.ts +119 -153
- package/dist/core/Agent.d.ts.map +1 -1
- package/dist/core/Agent.js +472 -325
- package/dist/core/Agent.js.map +1 -1
- package/dist/core/AutoChainExecutor.d.ts +107 -0
- package/dist/core/AutoChainExecutor.d.ts.map +1 -0
- package/dist/core/AutoChainExecutor.js +293 -0
- package/dist/core/AutoChainExecutor.js.map +1 -0
- package/dist/core/BranchEvaluator.d.ts +54 -0
- package/dist/core/BranchEvaluator.d.ts.map +1 -0
- package/dist/core/BranchEvaluator.js +126 -0
- package/dist/core/BranchEvaluator.js.map +1 -0
- package/dist/core/DirectiveBus.d.ts +88 -0
- package/dist/core/DirectiveBus.d.ts.map +1 -0
- package/dist/core/DirectiveBus.js +192 -0
- package/dist/core/DirectiveBus.js.map +1 -0
- package/dist/core/DirectiveChainTracker.d.ts +49 -0
- package/dist/core/DirectiveChainTracker.d.ts.map +1 -0
- package/dist/core/DirectiveChainTracker.js +117 -0
- package/dist/core/DirectiveChainTracker.js.map +1 -0
- package/dist/core/Flow.d.ts +186 -0
- package/dist/core/Flow.d.ts.map +1 -0
- package/dist/core/Flow.js +546 -0
- package/dist/core/Flow.js.map +1 -0
- package/dist/core/FlowRouter.d.ts +182 -0
- package/dist/core/FlowRouter.d.ts.map +1 -0
- package/dist/core/{RoutingEngine.js → FlowRouter.js} +322 -305
- package/dist/core/FlowRouter.js.map +1 -0
- package/dist/core/PersistenceManager.d.ts +2 -2
- package/dist/core/PersistenceManager.d.ts.map +1 -1
- package/dist/core/PersistenceManager.js +7 -7
- package/dist/core/PersistenceManager.js.map +1 -1
- package/dist/core/PromptComposer.d.ts +21 -8
- package/dist/core/PromptComposer.d.ts.map +1 -1
- package/dist/core/PromptComposer.js +183 -106
- package/dist/core/PromptComposer.js.map +1 -1
- package/dist/core/PromptSectionCache.d.ts +1 -1
- package/dist/core/PromptSectionCache.js +1 -1
- package/dist/core/ResponseEngine.d.ts +18 -8
- package/dist/core/ResponseEngine.d.ts.map +1 -1
- package/dist/core/ResponseEngine.js +38 -36
- package/dist/core/ResponseEngine.js.map +1 -1
- package/dist/core/ResponseModal.d.ts +73 -56
- package/dist/core/ResponseModal.d.ts.map +1 -1
- package/dist/core/ResponseModal.js +1193 -1016
- package/dist/core/ResponseModal.js.map +1 -1
- package/dist/core/ResponsePipeline.d.ts +124 -26
- package/dist/core/ResponsePipeline.d.ts.map +1 -1
- package/dist/core/ResponsePipeline.js +509 -137
- package/dist/core/ResponsePipeline.js.map +1 -1
- package/dist/core/SignalEvaluator.d.ts +86 -0
- package/dist/core/SignalEvaluator.d.ts.map +1 -0
- package/dist/core/SignalEvaluator.js +326 -0
- package/dist/core/SignalEvaluator.js.map +1 -0
- package/dist/core/SignalProcessor.d.ts +152 -0
- package/dist/core/SignalProcessor.d.ts.map +1 -0
- package/dist/core/SignalProcessor.js +555 -0
- package/dist/core/SignalProcessor.js.map +1 -0
- package/dist/core/Step.d.ts +43 -32
- package/dist/core/Step.d.ts.map +1 -1
- package/dist/core/Step.js +220 -126
- package/dist/core/Step.js.map +1 -1
- package/dist/core/StreamingToolExecutor.d.ts +2 -2
- package/dist/core/StreamingToolExecutor.d.ts.map +1 -1
- package/dist/core/StreamingToolExecutor.js.map +1 -1
- package/dist/core/ToolManager.d.ts +44 -13
- package/dist/core/ToolManager.d.ts.map +1 -1
- package/dist/core/ToolManager.js +174 -91
- package/dist/core/ToolManager.js.map +1 -1
- package/dist/core/createAgent.d.ts +35 -0
- package/dist/core/createAgent.d.ts.map +1 -0
- package/dist/core/createAgent.js +36 -0
- package/dist/core/createAgent.js.map +1 -0
- package/dist/core/flow-namespace.d.ts +49 -0
- package/dist/core/flow-namespace.d.ts.map +1 -0
- package/dist/core/flow-namespace.js +168 -0
- package/dist/core/flow-namespace.js.map +1 -0
- package/dist/index.d.ts +11 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -12
- package/dist/index.js.map +1 -1
- package/dist/types/agent.d.ts +183 -54
- package/dist/types/agent.d.ts.map +1 -1
- package/dist/types/agent.js +0 -6
- package/dist/types/agent.js.map +1 -1
- package/dist/types/ai.d.ts +3 -3
- package/dist/types/ai.d.ts.map +1 -1
- package/dist/types/errors.d.ts +15 -0
- package/dist/types/errors.d.ts.map +1 -0
- package/dist/types/errors.js +18 -0
- package/dist/types/errors.js.map +1 -0
- package/dist/types/flow.d.ts +513 -0
- package/dist/types/flow.d.ts.map +1 -0
- package/dist/types/flow.js +5 -0
- package/dist/types/flow.js.map +1 -0
- package/dist/types/index.d.ts +7 -6
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +4 -1
- package/dist/types/index.js.map +1 -1
- package/dist/types/persistence.d.ts +11 -7
- package/dist/types/persistence.d.ts.map +1 -1
- package/dist/types/routing.d.ts +1 -1
- package/dist/types/routing.d.ts.map +1 -1
- package/dist/types/session.d.ts +24 -23
- package/dist/types/session.d.ts.map +1 -1
- package/dist/types/signals.d.ts +248 -0
- package/dist/types/signals.d.ts.map +1 -0
- package/dist/types/signals.js +10 -0
- package/dist/types/signals.js.map +1 -0
- package/dist/types/template.d.ts +2 -8
- package/dist/types/template.d.ts.map +1 -1
- package/dist/types/tool.d.ts +36 -29
- package/dist/types/tool.d.ts.map +1 -1
- package/dist/types/tool.js +1 -1
- package/dist/types/tool.js.map +1 -1
- package/dist/utils/condition.d.ts +7 -1
- package/dist/utils/condition.d.ts.map +1 -1
- package/dist/utils/condition.js.map +1 -1
- package/dist/utils/id.d.ts +13 -5
- package/dist/utils/id.d.ts.map +1 -1
- package/dist/utils/id.js +22 -9
- package/dist/utils/id.js.map +1 -1
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -2
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/session.d.ts +44 -5
- package/dist/utils/session.d.ts.map +1 -1
- package/dist/utils/session.js +193 -37
- package/dist/utils/session.js.map +1 -1
- package/docs/README.md +15 -202
- package/docs/concepts/architecture.md +281 -0
- package/docs/concepts/directives.md +400 -0
- package/docs/concepts/pipeline.md +399 -0
- package/docs/guides/branching.md +263 -0
- package/docs/guides/compaction.md +163 -0
- package/docs/guides/conditions.md +167 -0
- package/docs/guides/error-handling.md +176 -0
- package/docs/guides/flow-control.md +409 -0
- package/docs/guides/instructions.md +210 -0
- package/docs/guides/persistence.md +182 -0
- package/docs/guides/streaming.md +137 -0
- package/docs/migration/README.md +15 -0
- package/docs/migration/route-to-flow.md +560 -0
- package/docs/migration/v1-to-v2.md +909 -0
- package/docs/reference/adapters.md +481 -0
- package/docs/reference/branches.md +241 -0
- package/docs/reference/create-agent.md +186 -0
- package/docs/reference/directive.md +243 -0
- package/docs/reference/errors.md +122 -0
- package/docs/reference/flow.md +238 -0
- package/docs/reference/instruction.md +177 -0
- package/docs/reference/pre-directive.md +131 -0
- package/docs/reference/providers.md +227 -0
- package/docs/reference/signals.md +356 -0
- package/docs/reference/step.md +339 -0
- package/docs/reference/tool.md +269 -0
- package/docs/start/01-install.md +81 -0
- package/docs/start/02-first-agent.md +196 -0
- package/docs/start/03-collect-data.md +222 -0
- package/docs/start/04-add-tools.md +276 -0
- package/docs/start/05-go-to-production.md +216 -0
- package/examples/01-quickstart.ts +20 -0
- package/examples/02-data-extraction.ts +90 -0
- package/examples/03-tools.ts +136 -0
- package/examples/04-instructions.ts +100 -0
- package/examples/05-branching.ts +140 -0
- package/examples/06-flow-control.ts +103 -0
- package/examples/07-streaming.ts +69 -0
- package/examples/08-persistence.ts +98 -0
- package/examples/09-signals.ts +144 -0
- package/examples/tsconfig.json +30 -0
- package/package.json +2 -1
- package/src/adapters/MemoryAdapter.ts +3 -3
- package/src/adapters/MongoAdapter.ts +3 -3
- package/src/adapters/OpenSearchAdapter.ts +10 -8
- package/src/adapters/PostgreSQLAdapter.ts +26 -10
- package/src/adapters/PrismaAdapter.ts +6 -6
- package/src/adapters/RedisAdapter.ts +3 -3
- package/src/adapters/SQLiteAdapter.ts +31 -12
- package/src/constants/index.ts +2 -10
- package/src/core/Agent.ts +585 -374
- package/src/core/AutoChainExecutor.ts +440 -0
- package/src/core/BranchEvaluator.ts +167 -0
- package/src/core/DirectiveBus.ts +248 -0
- package/src/core/DirectiveChainTracker.ts +144 -0
- package/src/core/Flow.ts +666 -0
- package/src/core/{RoutingEngine.ts → FlowRouter.ts} +385 -365
- package/src/core/PersistenceManager.ts +8 -8
- package/src/core/PromptComposer.ts +209 -140
- package/src/core/PromptSectionCache.ts +1 -1
- package/src/core/ResponseEngine.ts +61 -46
- package/src/core/ResponseModal.ts +1453 -1240
- package/src/core/ResponsePipeline.ts +655 -175
- package/src/core/SignalEvaluator.ts +420 -0
- package/src/core/SignalProcessor.ts +723 -0
- package/src/core/Step.ts +279 -176
- package/src/core/StreamingToolExecutor.ts +4 -4
- package/src/core/ToolManager.ts +200 -97
- package/src/core/createAgent.ts +40 -0
- package/src/core/flow-namespace.ts +219 -0
- package/src/index.ts +42 -36
- package/src/types/agent.ts +182 -53
- package/src/types/ai.ts +3 -3
- package/src/types/errors.ts +18 -0
- package/src/types/flow.ts +590 -0
- package/src/types/index.ts +43 -16
- package/src/types/persistence.ts +12 -8
- package/src/types/routing.ts +1 -1
- package/src/types/session.ts +26 -23
- package/src/types/signals.ts +321 -0
- package/src/types/template.ts +3 -11
- package/src/types/tool.ts +50 -42
- package/src/utils/condition.ts +13 -4
- package/src/utils/id.ts +27 -9
- package/src/utils/index.ts +6 -2
- package/src/utils/session.ts +238 -42
- package/dist/cjs/core/BatchExecutor.d.ts +0 -359
- package/dist/cjs/core/BatchExecutor.d.ts.map +0 -1
- package/dist/cjs/core/BatchExecutor.js +0 -861
- package/dist/cjs/core/BatchExecutor.js.map +0 -1
- package/dist/cjs/core/BatchPromptBuilder.d.ts +0 -89
- package/dist/cjs/core/BatchPromptBuilder.d.ts.map +0 -1
- package/dist/cjs/core/BatchPromptBuilder.js +0 -223
- package/dist/cjs/core/BatchPromptBuilder.js.map +0 -1
- package/dist/cjs/core/Route.d.ts +0 -180
- package/dist/cjs/core/Route.d.ts.map +0 -1
- package/dist/cjs/core/Route.js +0 -542
- package/dist/cjs/core/Route.js.map +0 -1
- package/dist/cjs/core/RoutingEngine.d.ts +0 -185
- package/dist/cjs/core/RoutingEngine.d.ts.map +0 -1
- package/dist/cjs/core/RoutingEngine.js.map +0 -1
- package/dist/cjs/types/route.d.ts +0 -336
- package/dist/cjs/types/route.d.ts.map +0 -1
- package/dist/cjs/types/route.js.map +0 -1
- package/dist/core/BatchExecutor.d.ts +0 -359
- package/dist/core/BatchExecutor.d.ts.map +0 -1
- package/dist/core/BatchExecutor.js +0 -856
- package/dist/core/BatchExecutor.js.map +0 -1
- package/dist/core/BatchPromptBuilder.d.ts +0 -89
- package/dist/core/BatchPromptBuilder.d.ts.map +0 -1
- package/dist/core/BatchPromptBuilder.js +0 -219
- package/dist/core/BatchPromptBuilder.js.map +0 -1
- package/dist/core/Route.d.ts +0 -180
- package/dist/core/Route.d.ts.map +0 -1
- package/dist/core/Route.js +0 -538
- package/dist/core/Route.js.map +0 -1
- package/dist/core/RoutingEngine.d.ts +0 -185
- package/dist/core/RoutingEngine.d.ts.map +0 -1
- package/dist/core/RoutingEngine.js.map +0 -1
- package/dist/types/route.d.ts +0 -336
- package/dist/types/route.d.ts.map +0 -1
- package/dist/types/route.js +0 -5
- package/dist/types/route.js.map +0 -1
- package/docs/CONTRIBUTING.md +0 -521
- package/docs/api/README.md +0 -3299
- package/docs/api/overview.md +0 -1410
- package/docs/architecture/data-extraction-flow.md +0 -360
- package/docs/architecture/multi-step-execution.md +0 -277
- package/docs/core/agent/README.md +0 -938
- package/docs/core/agent/context-management.md +0 -796
- package/docs/core/agent/rules-and-prohibitions.md +0 -113
- package/docs/core/agent/session-management.md +0 -693
- package/docs/core/ai-integration/prompt-composition.md +0 -355
- package/docs/core/ai-integration/providers.md +0 -515
- package/docs/core/ai-integration/response-processing.md +0 -433
- package/docs/core/conversation-flows/data-collection.md +0 -772
- package/docs/core/conversation-flows/route-dsl.md +0 -509
- package/docs/core/conversation-flows/routes.md +0 -249
- package/docs/core/conversation-flows/step-transitions.md +0 -731
- package/docs/core/conversation-flows/steps.md +0 -268
- package/docs/core/error-handling.md +0 -830
- package/docs/core/persistence/adapters.md +0 -255
- package/docs/core/persistence/session-storage.md +0 -656
- package/docs/core/routing/intelligent-routing.md +0 -470
- package/docs/core/tools/enhanced-tool.md +0 -186
- package/docs/core/tools/streaming-execution.md +0 -161
- package/docs/core/tools/tool-definition.md +0 -970
- package/docs/core/tools/tool-scoping.md +0 -819
- package/docs/guides/advanced-patterns/publishing.md +0 -186
- package/docs/guides/context-compaction.md +0 -96
- package/docs/guides/error-handling-patterns.md +0 -578
- package/docs/guides/getting-started/README.md +0 -795
- package/docs/guides/migration/README.md +0 -101
- package/docs/guides/migration/flexible-routing-conditions.md +0 -375
- package/docs/guides/migration/multi-step-execution.md +0 -393
- package/docs/guides/migration/response-modal-refactor.md +0 -518
- package/docs/guides/prompt-optimization.md +0 -164
- package/examples/advanced-patterns/context-compaction.ts +0 -223
- package/examples/advanced-patterns/knowledge-based-agent.ts +0 -735
- package/examples/advanced-patterns/persistent-onboarding.ts +0 -728
- package/examples/advanced-patterns/route-lifecycle-hooks.ts +0 -556
- package/examples/advanced-patterns/streaming-responses.ts +0 -656
- package/examples/ai-providers/anthropic-integration.ts +0 -388
- package/examples/ai-providers/openai-integration.ts +0 -228
- package/examples/condition-patterns/function-only-conditions.ts +0 -365
- package/examples/condition-patterns/mixed-array-conditions.ts +0 -477
- package/examples/condition-patterns/route-skipif-patterns.ts +0 -468
- package/examples/condition-patterns/step-skipif-patterns.ts +0 -0
- package/examples/condition-patterns/string-only-conditions.ts +0 -296
- package/examples/conversation-flows/completion-transitions.ts +0 -318
- package/examples/core-concepts/basic-agent.ts +0 -503
- package/examples/core-concepts/modern-streaming-api.ts +0 -309
- package/examples/core-concepts/schema-driven-extraction.ts +0 -332
- package/examples/core-concepts/session-management.ts +0 -494
- package/examples/integrations/database-integration.ts +0 -631
- package/examples/integrations/healthcare-integration.ts +0 -595
- package/examples/integrations/search-integration.ts +0 -530
- package/examples/integrations/server-session-management.ts +0 -307
- package/examples/persistence/custom-adapter.ts +0 -526
- package/examples/persistence/database-persistence.ts +0 -583
- package/examples/persistence/memory-sessions.ts +0 -495
- package/examples/persistence/prisma-schema.example.prisma +0 -74
- package/examples/persistence/redis-persistence.ts +0 -488
- package/examples/tools/basic-tools.ts +0 -765
- package/examples/tools/data-enrichment-tools.ts +0 -593
- package/examples/tools/enhanced-tool-metadata.ts +0 -268
- package/examples/tools/streaming-tool-execution.ts +0 -283
- package/src/core/BatchExecutor.ts +0 -1187
- package/src/core/BatchPromptBuilder.ts +0 -299
- package/src/core/Route.ts +0 -678
- package/src/types/route.ts +0 -392
|
@@ -1,861 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* BatchExecutor - Core component for multi-step execution
|
|
4
|
-
*
|
|
5
|
-
* Responsible for determining which Steps can execute together in a single batch
|
|
6
|
-
* and orchestrating their execution with a single LLM call.
|
|
7
|
-
*/
|
|
8
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
9
|
-
exports.BatchExecutor = void 0;
|
|
10
|
-
exports.needsInput = needsInput;
|
|
11
|
-
const constants_1 = require("../constants");
|
|
12
|
-
const utils_1 = require("../utils");
|
|
13
|
-
/**
|
|
14
|
-
* Determine if a Step needs user input to proceed
|
|
15
|
-
*
|
|
16
|
-
* IMPORTANT: sessionData MUST already include pre-extracted fields.
|
|
17
|
-
* This function is called AFTER pre-extraction has been merged into session data.
|
|
18
|
-
*
|
|
19
|
-
* A Step needs input when:
|
|
20
|
-
* 1. It has `requires` fields and at least one is missing from session data (after pre-extraction)
|
|
21
|
-
* 2. It has non-empty `collect` fields and none of those fields have data (after pre-extraction)
|
|
22
|
-
*
|
|
23
|
-
* @param step - The Step to evaluate (can be Step instance or StepOptions)
|
|
24
|
-
* @param sessionDataAfterPreExtraction - Session data with pre-extracted fields already merged
|
|
25
|
-
* @returns true if the step needs user input, false otherwise
|
|
26
|
-
*
|
|
27
|
-
* @example
|
|
28
|
-
* ```typescript
|
|
29
|
-
* // Step with requires - needs input if any required field is missing
|
|
30
|
-
* const step = { requires: ['name', 'email'], collect: [] };
|
|
31
|
-
* needsInput(step, { name: 'John' }); // true - email is missing
|
|
32
|
-
* needsInput(step, { name: 'John', email: 'john@example.com' }); // false - all present
|
|
33
|
-
*
|
|
34
|
-
* // Step with collect - needs input if no collect fields have data
|
|
35
|
-
* const step2 = { collect: ['preference', 'feedback'] };
|
|
36
|
-
* needsInput(step2, {}); // true - no collect fields have data
|
|
37
|
-
* needsInput(step2, { preference: 'A' }); // false - at least one has data
|
|
38
|
-
* ```
|
|
39
|
-
*
|
|
40
|
-
* **Validates: Requirements 1.2, 1.3**
|
|
41
|
-
*/
|
|
42
|
-
function needsInput(step, sessionDataAfterPreExtraction) {
|
|
43
|
-
// Check requires - all must be present (after pre-extraction)
|
|
44
|
-
// Requirement 1.2: A Step Needs_Input WHEN it has `requires` fields that are not present
|
|
45
|
-
// in session data after Pre_Extraction
|
|
46
|
-
if (step.requires && step.requires.length > 0) {
|
|
47
|
-
const missingRequired = step.requires.some(field => {
|
|
48
|
-
const key = String(field);
|
|
49
|
-
return sessionDataAfterPreExtraction[key] === undefined;
|
|
50
|
-
});
|
|
51
|
-
if (missingRequired)
|
|
52
|
-
return true;
|
|
53
|
-
}
|
|
54
|
-
// Check collect - needs input if collecting and no data exists (after pre-extraction)
|
|
55
|
-
// Requirement 1.3: A Step Needs_Input WHEN it has `collect` fields (non-empty array) and
|
|
56
|
-
// no data for those fields exists in session data
|
|
57
|
-
if (step.collect && step.collect.length > 0) {
|
|
58
|
-
const hasAnyCollectData = step.collect.some(field => {
|
|
59
|
-
const key = String(field);
|
|
60
|
-
return sessionDataAfterPreExtraction[key] !== undefined;
|
|
61
|
-
});
|
|
62
|
-
if (!hasAnyCollectData)
|
|
63
|
-
return true;
|
|
64
|
-
}
|
|
65
|
-
return false;
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
* BatchExecutor class - orchestrates multi-step execution
|
|
69
|
-
*
|
|
70
|
-
* Determines which Steps can execute together in a single batch based on:
|
|
71
|
-
* - skipIf conditions (skip steps that evaluate to true)
|
|
72
|
-
* - needsInput detection (stop when a step needs user input)
|
|
73
|
-
* - END_ROUTE detection (stop when reaching end of route)
|
|
74
|
-
*
|
|
75
|
-
* Supports event emission for debugging and observability:
|
|
76
|
-
* - batch_start: Emitted when batch determination begins
|
|
77
|
-
* - step_included: Emitted when a step is included in the batch
|
|
78
|
-
* - step_skipped: Emitted when a step is skipped (due to skipIf)
|
|
79
|
-
* - batch_stop: Emitted when batch determination stops
|
|
80
|
-
* - batch_complete: Emitted when batch execution completes
|
|
81
|
-
*
|
|
82
|
-
* **Validates: Requirements 1.1, 1.4, 1.5, 7.1, 7.2, 7.3, 11.1, 11.2, 11.3**
|
|
83
|
-
*/
|
|
84
|
-
class BatchExecutor {
|
|
85
|
-
constructor() {
|
|
86
|
-
/** Event listeners for batch execution events */
|
|
87
|
-
this.eventListeners = [];
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Add an event listener for batch execution events
|
|
91
|
-
*
|
|
92
|
-
* @param listener - Callback function to receive events
|
|
93
|
-
* @returns Function to remove the listener
|
|
94
|
-
*
|
|
95
|
-
* **Validates: Requirements 11.3**
|
|
96
|
-
*/
|
|
97
|
-
addEventListener(listener) {
|
|
98
|
-
this.eventListeners.push(listener);
|
|
99
|
-
return () => {
|
|
100
|
-
const index = this.eventListeners.indexOf(listener);
|
|
101
|
-
if (index !== -1) {
|
|
102
|
-
this.eventListeners.splice(index, 1);
|
|
103
|
-
}
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* Remove an event listener
|
|
108
|
-
*
|
|
109
|
-
* @param listener - The listener to remove
|
|
110
|
-
*/
|
|
111
|
-
removeEventListener(listener) {
|
|
112
|
-
const index = this.eventListeners.indexOf(listener);
|
|
113
|
-
if (index !== -1) {
|
|
114
|
-
this.eventListeners.splice(index, 1);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Emit a batch execution event to all listeners
|
|
119
|
-
*
|
|
120
|
-
* @param event - The event to emit
|
|
121
|
-
* @private
|
|
122
|
-
*/
|
|
123
|
-
emitEvent(event) {
|
|
124
|
-
for (const listener of this.eventListeners) {
|
|
125
|
-
try {
|
|
126
|
-
listener(event);
|
|
127
|
-
}
|
|
128
|
-
catch (error) {
|
|
129
|
-
// Log but don't fail on listener errors
|
|
130
|
-
utils_1.logger.warn(`[BatchExecutor] Event listener error:`, error);
|
|
131
|
-
}
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
/**
|
|
135
|
-
* Create and emit a batch execution event
|
|
136
|
-
*
|
|
137
|
-
* @param type - Event type
|
|
138
|
-
* @param details - Event details
|
|
139
|
-
* @private
|
|
140
|
-
*/
|
|
141
|
-
emitBatchEvent(type, details) {
|
|
142
|
-
const event = {
|
|
143
|
-
type,
|
|
144
|
-
timestamp: new Date(),
|
|
145
|
-
details,
|
|
146
|
-
};
|
|
147
|
-
this.emitEvent(event);
|
|
148
|
-
// Also log the event when debug mode is enabled
|
|
149
|
-
utils_1.logger.debug(`[BatchExecutor] Event: ${type}`, details);
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Determine which Steps can execute in the current batch
|
|
153
|
-
* starting from the given Step position.
|
|
154
|
-
*
|
|
155
|
-
* Algorithm:
|
|
156
|
-
* 1. Start from currentStep (or initialStep if undefined)
|
|
157
|
-
* 2. For each step:
|
|
158
|
-
* a. Check if it's END_ROUTE - stop with 'end_route'
|
|
159
|
-
* b. Evaluate skipIf condition
|
|
160
|
-
* c. If skipIf is true - skip step, continue to next
|
|
161
|
-
* d. If skipIf throws error - treat as non-skippable (Requirement 7.3)
|
|
162
|
-
* e. Evaluate needsInput
|
|
163
|
-
* f. If needsInput is false - include in batch, continue to next
|
|
164
|
-
* g. If needsInput is true - stop with 'needs_input'
|
|
165
|
-
* 3. If all steps processed - stop with 'route_complete'
|
|
166
|
-
*
|
|
167
|
-
* @param params - Parameters for batch determination
|
|
168
|
-
* @returns BatchResult with steps to execute and stopping reason
|
|
169
|
-
*
|
|
170
|
-
* **Validates: Requirements 1.1, 1.4, 1.5, 7.1, 7.2, 7.3**
|
|
171
|
-
*/
|
|
172
|
-
async determineBatch(params) {
|
|
173
|
-
const { route, currentStep, sessionData, context, maxSteps = 1 } = params;
|
|
174
|
-
const startTime = Date.now();
|
|
175
|
-
const batchSteps = [];
|
|
176
|
-
let stoppedReason = 'route_complete';
|
|
177
|
-
let stoppedAtStep;
|
|
178
|
-
// Get all steps in the route for traversal
|
|
179
|
-
const allSteps = route.getAllSteps();
|
|
180
|
-
// Find starting position
|
|
181
|
-
let startIndex = 0;
|
|
182
|
-
if (currentStep) {
|
|
183
|
-
const currentIndex = allSteps.findIndex(s => s.id === currentStep.id);
|
|
184
|
-
if (currentIndex !== -1) {
|
|
185
|
-
startIndex = currentIndex;
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
// Log batch determination start (Requirement 11.1)
|
|
189
|
-
utils_1.logger.debug(`[BatchExecutor] Starting batch determination from step index ${startIndex}, total steps: ${allSteps.length}`);
|
|
190
|
-
// Emit batch_start event (Requirement 11.3)
|
|
191
|
-
this.emitBatchEvent('batch_start', {
|
|
192
|
-
stepId: currentStep?.id,
|
|
193
|
-
reason: `Starting batch determination from ${currentStep?.id || 'initial step'}`,
|
|
194
|
-
batchSize: 0,
|
|
195
|
-
});
|
|
196
|
-
// Create template context for condition evaluation
|
|
197
|
-
const templateContext = (0, utils_1.createTemplateContext)({
|
|
198
|
-
context,
|
|
199
|
-
data: sessionData,
|
|
200
|
-
session: (0, utils_1.createSession)({ data: sessionData }),
|
|
201
|
-
});
|
|
202
|
-
// Walk through steps starting from current position
|
|
203
|
-
for (let i = startIndex; i < allSteps.length; i++) {
|
|
204
|
-
const step = allSteps[i];
|
|
205
|
-
const stepOptions = step.toOptions();
|
|
206
|
-
// Check for END_ROUTE (Requirement 2.2)
|
|
207
|
-
if (step.id === constants_1.END_ROUTE_ID) {
|
|
208
|
-
stoppedReason = 'end_route';
|
|
209
|
-
stoppedAtStep = stepOptions;
|
|
210
|
-
// Log stopping reason (Requirement 11.2)
|
|
211
|
-
utils_1.logger.debug(`[BatchExecutor] Reached END_ROUTE, stopping batch`);
|
|
212
|
-
// Emit batch_stop event (Requirement 11.3)
|
|
213
|
-
this.emitBatchEvent('batch_stop', {
|
|
214
|
-
stepId: step.id,
|
|
215
|
-
reason: 'Reached END_ROUTE',
|
|
216
|
-
stoppedReason: 'end_route',
|
|
217
|
-
batchSize: batchSteps.length,
|
|
218
|
-
});
|
|
219
|
-
break;
|
|
220
|
-
}
|
|
221
|
-
// Evaluate skipIf condition (Requirements 7.1, 7.2, 7.3)
|
|
222
|
-
let shouldSkip = false;
|
|
223
|
-
if (step.skipIf) {
|
|
224
|
-
try {
|
|
225
|
-
const skipResult = await step.evaluateSkipIf(templateContext);
|
|
226
|
-
shouldSkip = skipResult.shouldSkip;
|
|
227
|
-
// Log skipIf evaluation (Requirement 11.1)
|
|
228
|
-
utils_1.logger.debug(`[BatchExecutor] Step ${step.id} skipIf evaluated to: ${shouldSkip}`);
|
|
229
|
-
}
|
|
230
|
-
catch (error) {
|
|
231
|
-
// Requirement 7.3: If skipIf evaluation throws an error, treat as non-skippable
|
|
232
|
-
utils_1.logger.warn(`[BatchExecutor] skipIf evaluation error for step ${step.id}, treating as non-skippable:`, error);
|
|
233
|
-
shouldSkip = false;
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
// If skipIf is true, skip this step and continue (Requirement 7.2)
|
|
237
|
-
if (shouldSkip) {
|
|
238
|
-
// Log step skip (Requirement 11.1)
|
|
239
|
-
utils_1.logger.debug(`[BatchExecutor] Skipping step ${step.id} due to skipIf condition`);
|
|
240
|
-
// Emit step_skipped event (Requirement 11.3)
|
|
241
|
-
this.emitBatchEvent('step_skipped', {
|
|
242
|
-
stepId: step.id,
|
|
243
|
-
reason: 'skipIf condition evaluated to true',
|
|
244
|
-
});
|
|
245
|
-
continue;
|
|
246
|
-
}
|
|
247
|
-
// Evaluate needsInput (Requirements 1.2, 1.3)
|
|
248
|
-
const stepNeedsInput = needsInput(step, sessionData);
|
|
249
|
-
if (stepNeedsInput) {
|
|
250
|
-
// Requirement 1.5: Stop when a step needs input
|
|
251
|
-
stoppedReason = 'needs_input';
|
|
252
|
-
stoppedAtStep = stepOptions;
|
|
253
|
-
// Log stopping reason with details (Requirement 11.1, 11.2)
|
|
254
|
-
const missingRequires = step.requires?.filter(field => sessionData[String(field)] === undefined) || [];
|
|
255
|
-
const collectFields = step.collect || [];
|
|
256
|
-
// Warn about missing required fields from previous steps
|
|
257
|
-
if (missingRequires.length > 0) {
|
|
258
|
-
const warning = `[Agent] Step "${step.description || step.id}" requires data [${missingRequires.join(', ')}] that was not collected by previous steps. ` +
|
|
259
|
-
`Ensure earlier steps collect these fields before this step can proceed.`;
|
|
260
|
-
utils_1.logger.warn(warning);
|
|
261
|
-
// Also log to console for developer visibility (but silence in test suites to prevent fast-check spam)
|
|
262
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
263
|
-
console.warn(warning);
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
utils_1.logger.debug(`[BatchExecutor] Step ${step.id} needs input, stopping batch. Missing requires: [${missingRequires.join(', ')}], Collect fields: [${collectFields.join(', ')}]`);
|
|
267
|
-
// Emit batch_stop event (Requirement 11.3)
|
|
268
|
-
this.emitBatchEvent('batch_stop', {
|
|
269
|
-
stepId: step.id,
|
|
270
|
-
reason: `Step needs input - missing requires: [${missingRequires.join(', ')}], collect fields: [${collectFields.join(', ')}]`,
|
|
271
|
-
stoppedReason: 'needs_input',
|
|
272
|
-
batchSize: batchSteps.length,
|
|
273
|
-
});
|
|
274
|
-
break;
|
|
275
|
-
}
|
|
276
|
-
// Requirement 1.4: Step doesn't need input, include in batch
|
|
277
|
-
batchSteps.push(stepOptions);
|
|
278
|
-
// Log step inclusion with reason (Requirement 11.1)
|
|
279
|
-
utils_1.logger.debug(`[BatchExecutor] Including step ${step.id} in batch (all requirements satisfied)`);
|
|
280
|
-
// Emit step_included event (Requirement 11.3)
|
|
281
|
-
this.emitBatchEvent('step_included', {
|
|
282
|
-
stepId: step.id,
|
|
283
|
-
reason: 'All requirements satisfied, no input needed',
|
|
284
|
-
batchSize: batchSteps.length,
|
|
285
|
-
});
|
|
286
|
-
// Check if we've reached the max steps limit
|
|
287
|
-
if (batchSteps.length >= maxSteps) {
|
|
288
|
-
stoppedReason = 'max_steps_reached';
|
|
289
|
-
utils_1.logger.debug(`[BatchExecutor] Reached maxStepsPerBatch limit (${maxSteps}), stopping batch`);
|
|
290
|
-
this.emitBatchEvent('batch_stop', {
|
|
291
|
-
stepId: step.id,
|
|
292
|
-
reason: `Reached maxStepsPerBatch limit (${maxSteps})`,
|
|
293
|
-
stoppedReason: 'max_steps_reached',
|
|
294
|
-
batchSize: batchSteps.length,
|
|
295
|
-
});
|
|
296
|
-
break;
|
|
297
|
-
}
|
|
298
|
-
// Move to next step in the sequence
|
|
299
|
-
const transitions = step.getTransitions();
|
|
300
|
-
if (transitions.length === 0) {
|
|
301
|
-
// No more transitions, route is complete
|
|
302
|
-
stoppedReason = 'route_complete';
|
|
303
|
-
// Log stopping reason (Requirement 11.2)
|
|
304
|
-
utils_1.logger.debug(`[BatchExecutor] No more transitions from step ${step.id}, route complete`);
|
|
305
|
-
// Emit batch_stop event (Requirement 11.3)
|
|
306
|
-
this.emitBatchEvent('batch_stop', {
|
|
307
|
-
stepId: step.id,
|
|
308
|
-
reason: 'No more transitions, route complete',
|
|
309
|
-
stoppedReason: 'route_complete',
|
|
310
|
-
batchSize: batchSteps.length,
|
|
311
|
-
});
|
|
312
|
-
break;
|
|
313
|
-
}
|
|
314
|
-
// For linear routes, follow the first transition
|
|
315
|
-
// For branching routes, we'd need more complex logic
|
|
316
|
-
const nextStep = transitions[0];
|
|
317
|
-
if (nextStep) {
|
|
318
|
-
// Update the loop to continue from the next step
|
|
319
|
-
const nextIndex = allSteps.findIndex(s => s.id === nextStep.id);
|
|
320
|
-
if (nextIndex !== -1 && nextIndex > i) {
|
|
321
|
-
// Continue from next step (will be incremented by loop)
|
|
322
|
-
i = nextIndex - 1;
|
|
323
|
-
}
|
|
324
|
-
else if (nextStep.id === constants_1.END_ROUTE_ID) {
|
|
325
|
-
// Next step is END_ROUTE
|
|
326
|
-
stoppedReason = 'end_route';
|
|
327
|
-
stoppedAtStep = nextStep.toOptions();
|
|
328
|
-
// Log stopping reason (Requirement 11.2)
|
|
329
|
-
utils_1.logger.debug(`[BatchExecutor] Next step is END_ROUTE, stopping batch`);
|
|
330
|
-
// Emit batch_stop event (Requirement 11.3)
|
|
331
|
-
this.emitBatchEvent('batch_stop', {
|
|
332
|
-
stepId: nextStep.id,
|
|
333
|
-
reason: 'Next step is END_ROUTE',
|
|
334
|
-
stoppedReason: 'end_route',
|
|
335
|
-
batchSize: batchSteps.length,
|
|
336
|
-
});
|
|
337
|
-
break;
|
|
338
|
-
}
|
|
339
|
-
}
|
|
340
|
-
}
|
|
341
|
-
// Log batch determination complete with timing (Requirement 11.1, 11.2)
|
|
342
|
-
const determinationTime = Date.now() - startTime;
|
|
343
|
-
utils_1.logger.debug(`[BatchExecutor] Batch determination complete. Steps: ${batchSteps.length}, Stopped reason: ${stoppedReason}, Time: ${determinationTime}ms`);
|
|
344
|
-
return {
|
|
345
|
-
steps: batchSteps,
|
|
346
|
-
stoppedReason,
|
|
347
|
-
stoppedAtStep,
|
|
348
|
-
};
|
|
349
|
-
}
|
|
350
|
-
/**
|
|
351
|
-
* Execute prepare hooks for all steps in the batch
|
|
352
|
-
*
|
|
353
|
-
* Executes all prepare hooks in Step order before the LLM call.
|
|
354
|
-
* If any prepare hook fails, execution stops immediately and returns an error.
|
|
355
|
-
*
|
|
356
|
-
* @param params - Parameters for hook execution
|
|
357
|
-
* @returns Result indicating success or failure with error details
|
|
358
|
-
*
|
|
359
|
-
* **Validates: Requirements 5.1, 5.3, 5.4**
|
|
360
|
-
*/
|
|
361
|
-
async executePrepareHooks(params) {
|
|
362
|
-
const { steps, context, data, executeHook } = params;
|
|
363
|
-
const executedSteps = [];
|
|
364
|
-
utils_1.logger.debug(`[BatchExecutor] Executing prepare hooks for ${steps.length} steps`);
|
|
365
|
-
for (const step of steps) {
|
|
366
|
-
if (step.prepare) {
|
|
367
|
-
utils_1.logger.debug(`[BatchExecutor] Executing prepare hook for step: ${step.id}`);
|
|
368
|
-
try {
|
|
369
|
-
await executeHook(step.prepare, context, data, step);
|
|
370
|
-
executedSteps.push(step.id || 'unknown');
|
|
371
|
-
utils_1.logger.debug(`[BatchExecutor] Prepare hook completed for step: ${step.id}`);
|
|
372
|
-
}
|
|
373
|
-
catch (error) {
|
|
374
|
-
// Requirement 5.4: Stop on prepare hook failure
|
|
375
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
376
|
-
utils_1.logger.error(`[BatchExecutor] Prepare hook failed for step ${step.id}: ${errorMessage}`);
|
|
377
|
-
return {
|
|
378
|
-
success: false,
|
|
379
|
-
executedSteps,
|
|
380
|
-
error: {
|
|
381
|
-
type: 'prepare_hook',
|
|
382
|
-
message: errorMessage,
|
|
383
|
-
stepId: step.id,
|
|
384
|
-
details: error,
|
|
385
|
-
},
|
|
386
|
-
};
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
}
|
|
390
|
-
utils_1.logger.debug(`[BatchExecutor] All prepare hooks completed successfully`);
|
|
391
|
-
return {
|
|
392
|
-
success: true,
|
|
393
|
-
executedSteps,
|
|
394
|
-
};
|
|
395
|
-
}
|
|
396
|
-
/**
|
|
397
|
-
* Execute finalize hooks for all steps in the batch
|
|
398
|
-
*
|
|
399
|
-
* Executes all finalize hooks in Step order after the LLM response.
|
|
400
|
-
* If a finalize hook fails, the error is logged but execution continues
|
|
401
|
-
* with remaining hooks.
|
|
402
|
-
*
|
|
403
|
-
* @param params - Parameters for hook execution
|
|
404
|
-
* @returns Result with any errors that occurred (always succeeds)
|
|
405
|
-
*
|
|
406
|
-
* **Validates: Requirements 5.2, 5.3, 5.5**
|
|
407
|
-
*/
|
|
408
|
-
async executeFinalizeHooks(params) {
|
|
409
|
-
const { steps, context, data, executeHook } = params;
|
|
410
|
-
const executedSteps = [];
|
|
411
|
-
const errors = [];
|
|
412
|
-
utils_1.logger.debug(`[BatchExecutor] Executing finalize hooks for ${steps.length} steps`);
|
|
413
|
-
for (const step of steps) {
|
|
414
|
-
if (step.finalize) {
|
|
415
|
-
utils_1.logger.debug(`[BatchExecutor] Executing finalize hook for step: ${step.id}`);
|
|
416
|
-
try {
|
|
417
|
-
await executeHook(step.finalize, context, data, step);
|
|
418
|
-
executedSteps.push(step.id || 'unknown');
|
|
419
|
-
utils_1.logger.debug(`[BatchExecutor] Finalize hook completed for step: ${step.id}`);
|
|
420
|
-
}
|
|
421
|
-
catch (error) {
|
|
422
|
-
// Requirement 5.5: Log error and continue with remaining hooks
|
|
423
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
424
|
-
utils_1.logger.error(`[BatchExecutor] Finalize hook failed for step ${step.id}: ${errorMessage}`);
|
|
425
|
-
errors.push({
|
|
426
|
-
stepId: step.id || 'unknown',
|
|
427
|
-
error: {
|
|
428
|
-
type: 'finalize_hook',
|
|
429
|
-
message: errorMessage,
|
|
430
|
-
stepId: step.id,
|
|
431
|
-
details: error,
|
|
432
|
-
},
|
|
433
|
-
});
|
|
434
|
-
// Continue to next step despite error
|
|
435
|
-
}
|
|
436
|
-
}
|
|
437
|
-
}
|
|
438
|
-
if (errors.length > 0) {
|
|
439
|
-
utils_1.logger.warn(`[BatchExecutor] ${errors.length} finalize hook(s) failed, but execution continued`);
|
|
440
|
-
}
|
|
441
|
-
else {
|
|
442
|
-
utils_1.logger.debug(`[BatchExecutor] All finalize hooks completed successfully`);
|
|
443
|
-
}
|
|
444
|
-
// Always return success for finalize hooks (errors are logged but don't stop execution)
|
|
445
|
-
return {
|
|
446
|
-
success: true,
|
|
447
|
-
executedSteps,
|
|
448
|
-
errors: errors.length > 0 ? errors : undefined,
|
|
449
|
-
};
|
|
450
|
-
}
|
|
451
|
-
/**
|
|
452
|
-
* Execute all hooks for a batch of steps
|
|
453
|
-
*
|
|
454
|
-
* This is a convenience method that executes prepare hooks, then allows
|
|
455
|
-
* the caller to perform the LLM call, and finally executes finalize hooks.
|
|
456
|
-
*
|
|
457
|
-
* @param params - Parameters for hook execution
|
|
458
|
-
* @returns Object with methods to execute prepare and finalize phases
|
|
459
|
-
*
|
|
460
|
-
* **Validates: Requirements 5.1, 5.2, 5.3, 5.4, 5.5**
|
|
461
|
-
*/
|
|
462
|
-
createHookExecutor(params) {
|
|
463
|
-
return {
|
|
464
|
-
executePrepare: () => this.executePrepareHooks(params),
|
|
465
|
-
executeFinalize: () => this.executeFinalizeHooks(params),
|
|
466
|
-
};
|
|
467
|
-
}
|
|
468
|
-
/**
|
|
469
|
-
* Execute a batch of steps with comprehensive error handling
|
|
470
|
-
*
|
|
471
|
-
* This method orchestrates the complete batch execution flow:
|
|
472
|
-
* 1. Execute prepare hooks (stop on failure)
|
|
473
|
-
* 2. Make LLM call (preserve session state on failure)
|
|
474
|
-
* 3. Collect and validate data (include errors in response)
|
|
475
|
-
* 4. Execute finalize hooks (continue on failure, log errors)
|
|
476
|
-
*
|
|
477
|
-
* Error handling behavior:
|
|
478
|
-
* - LLM call failures: Return error response with last successful session state
|
|
479
|
-
* - Validation failures: Include validation errors in response, preserve partial data
|
|
480
|
-
* - Prepare hook failures: Stop execution, return error with appropriate stoppedReason
|
|
481
|
-
* - Finalize hook failures: Log errors, continue execution (non-fatal)
|
|
482
|
-
*
|
|
483
|
-
* @param params - Parameters for batch execution
|
|
484
|
-
* @returns BatchExecutionResult with message, session, executed steps, and any errors
|
|
485
|
-
*
|
|
486
|
-
* **Validates: Requirements 9.1, 9.2, 9.3, 2.4**
|
|
487
|
-
*/
|
|
488
|
-
async executeBatch(params) {
|
|
489
|
-
const { batch, session: initialSession, context, executeHook, generateMessage, schema, routeId, } = params;
|
|
490
|
-
// Track timing for each phase (Requirement 11.1)
|
|
491
|
-
const timing = {
|
|
492
|
-
totalMs: 0,
|
|
493
|
-
};
|
|
494
|
-
const batchStartTime = Date.now();
|
|
495
|
-
// Track the last successful session state for error recovery
|
|
496
|
-
let lastSuccessfulSession = initialSession;
|
|
497
|
-
let currentSession = initialSession;
|
|
498
|
-
// Track executed steps for the response
|
|
499
|
-
const executedSteps = [];
|
|
500
|
-
// Log batch execution start with details (Requirement 11.1)
|
|
501
|
-
utils_1.logger.debug(`[BatchExecutor] Starting batch execution with ${batch.steps.length} steps, route: ${routeId || 'unknown'}`);
|
|
502
|
-
// If batch is empty, return early with appropriate reason
|
|
503
|
-
if (batch.steps.length === 0) {
|
|
504
|
-
utils_1.logger.debug(`[BatchExecutor] Empty batch, returning with stopped reason: ${batch.stoppedReason}`);
|
|
505
|
-
// Emit batch_complete event for empty batch (Requirement 11.3)
|
|
506
|
-
timing.totalMs = Date.now() - batchStartTime;
|
|
507
|
-
this.emitBatchEvent('batch_complete', {
|
|
508
|
-
batchSize: 0,
|
|
509
|
-
stoppedReason: batch.stoppedReason,
|
|
510
|
-
reason: 'Empty batch',
|
|
511
|
-
timing,
|
|
512
|
-
});
|
|
513
|
-
return {
|
|
514
|
-
message: '',
|
|
515
|
-
session: currentSession,
|
|
516
|
-
executedSteps: [],
|
|
517
|
-
stoppedReason: batch.stoppedReason,
|
|
518
|
-
collectedData: {},
|
|
519
|
-
};
|
|
520
|
-
}
|
|
521
|
-
// PHASE 1: Execute prepare hooks (Requirement 5.4 - stop on failure)
|
|
522
|
-
const prepareStartTime = Date.now();
|
|
523
|
-
utils_1.logger.debug(`[BatchExecutor] Phase 1: Executing prepare hooks`);
|
|
524
|
-
const prepareResult = await this.executePrepareHooks({
|
|
525
|
-
steps: batch.steps,
|
|
526
|
-
context,
|
|
527
|
-
data: currentSession.data,
|
|
528
|
-
executeHook,
|
|
529
|
-
});
|
|
530
|
-
timing.prepareHooksMs = Date.now() - prepareStartTime;
|
|
531
|
-
utils_1.logger.debug(`[BatchExecutor] Prepare hooks completed in ${timing.prepareHooksMs}ms`);
|
|
532
|
-
if (!prepareResult.success) {
|
|
533
|
-
// Requirement 9.3: Preserve partial progress on errors
|
|
534
|
-
// Requirement 2.4: Stop and include error information
|
|
535
|
-
utils_1.logger.error(`[BatchExecutor] Prepare hook failed:`, prepareResult.error);
|
|
536
|
-
// Emit batch_complete event with error (Requirement 11.3)
|
|
537
|
-
timing.totalMs = Date.now() - batchStartTime;
|
|
538
|
-
this.emitBatchEvent('batch_complete', {
|
|
539
|
-
batchSize: batch.steps.length,
|
|
540
|
-
stoppedReason: 'prepare_error',
|
|
541
|
-
reason: `Prepare hook failed: ${prepareResult.error?.message}`,
|
|
542
|
-
timing,
|
|
543
|
-
});
|
|
544
|
-
return {
|
|
545
|
-
message: '',
|
|
546
|
-
session: lastSuccessfulSession, // Return last successful state
|
|
547
|
-
executedSteps: prepareResult.executedSteps.map(stepId => ({
|
|
548
|
-
id: stepId,
|
|
549
|
-
routeId: routeId || 'unknown',
|
|
550
|
-
})),
|
|
551
|
-
stoppedReason: 'prepare_error',
|
|
552
|
-
error: prepareResult.error,
|
|
553
|
-
};
|
|
554
|
-
}
|
|
555
|
-
// Update last successful session after prepare hooks complete
|
|
556
|
-
lastSuccessfulSession = currentSession;
|
|
557
|
-
// PHASE 2: Make LLM call (Requirement 9.1 - preserve session state on failure)
|
|
558
|
-
const llmStartTime = Date.now();
|
|
559
|
-
utils_1.logger.debug(`[BatchExecutor] Phase 2: Making LLM call`);
|
|
560
|
-
let llmResponse;
|
|
561
|
-
let message;
|
|
562
|
-
try {
|
|
563
|
-
const result = await generateMessage();
|
|
564
|
-
llmResponse = result.structured || {};
|
|
565
|
-
message = result.message || '';
|
|
566
|
-
timing.llmCallMs = Date.now() - llmStartTime;
|
|
567
|
-
utils_1.logger.debug(`[BatchExecutor] LLM call successful in ${timing.llmCallMs}ms`);
|
|
568
|
-
}
|
|
569
|
-
catch (error) {
|
|
570
|
-
// Requirement 9.1: Return error response with last successful session state
|
|
571
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
572
|
-
timing.llmCallMs = Date.now() - llmStartTime;
|
|
573
|
-
utils_1.logger.error(`[BatchExecutor] LLM call failed after ${timing.llmCallMs}ms:`, errorMessage);
|
|
574
|
-
// Emit batch_complete event with error (Requirement 11.3)
|
|
575
|
-
timing.totalMs = Date.now() - batchStartTime;
|
|
576
|
-
this.emitBatchEvent('batch_complete', {
|
|
577
|
-
batchSize: batch.steps.length,
|
|
578
|
-
stoppedReason: 'llm_error',
|
|
579
|
-
reason: `LLM call failed: ${errorMessage}`,
|
|
580
|
-
timing,
|
|
581
|
-
});
|
|
582
|
-
return {
|
|
583
|
-
message: '',
|
|
584
|
-
session: lastSuccessfulSession, // Preserve session state
|
|
585
|
-
executedSteps: [], // No steps were fully executed
|
|
586
|
-
stoppedReason: 'llm_error',
|
|
587
|
-
error: {
|
|
588
|
-
type: 'llm_call',
|
|
589
|
-
message: errorMessage,
|
|
590
|
-
details: error,
|
|
591
|
-
},
|
|
592
|
-
};
|
|
593
|
-
}
|
|
594
|
-
// Update last successful session after LLM call
|
|
595
|
-
lastSuccessfulSession = currentSession;
|
|
596
|
-
// PHASE 3: Collect and validate data (Requirement 9.2 - include validation errors)
|
|
597
|
-
const collectStartTime = Date.now();
|
|
598
|
-
utils_1.logger.debug(`[BatchExecutor] Phase 3: Collecting and validating data`);
|
|
599
|
-
const collectResult = this.collectBatchData({
|
|
600
|
-
steps: batch.steps,
|
|
601
|
-
llmResponse,
|
|
602
|
-
session: currentSession,
|
|
603
|
-
schema,
|
|
604
|
-
});
|
|
605
|
-
timing.dataCollectionMs = Date.now() - collectStartTime;
|
|
606
|
-
utils_1.logger.debug(`[BatchExecutor] Data collection completed in ${timing.dataCollectionMs}ms`);
|
|
607
|
-
// Update session with collected data (even if validation failed)
|
|
608
|
-
currentSession = collectResult.session;
|
|
609
|
-
// Track collected data for response
|
|
610
|
-
const collectedData = collectResult.collectedData;
|
|
611
|
-
// Check for validation errors
|
|
612
|
-
let validationError;
|
|
613
|
-
if (!collectResult.success && collectResult.validationErrors && collectResult.validationErrors.length > 0) {
|
|
614
|
-
// Requirement 9.2: Include validation errors in response
|
|
615
|
-
utils_1.logger.warn(`[BatchExecutor] Data validation failed:`, collectResult.validationErrors);
|
|
616
|
-
validationError = {
|
|
617
|
-
type: 'data_validation',
|
|
618
|
-
message: `Validation failed for ${collectResult.validationErrors.length} field(s): ${collectResult.validationErrors.map(e => e.field).join(', ')}`,
|
|
619
|
-
details: collectResult.validationErrors,
|
|
620
|
-
};
|
|
621
|
-
// Note: We continue execution despite validation errors
|
|
622
|
-
// The error is included in the response for the caller to handle
|
|
623
|
-
}
|
|
624
|
-
// Update last successful session after data collection
|
|
625
|
-
// (even with validation errors, we preserve the collected data)
|
|
626
|
-
lastSuccessfulSession = currentSession;
|
|
627
|
-
// Build executed steps list
|
|
628
|
-
for (const step of batch.steps) {
|
|
629
|
-
if (step.id) {
|
|
630
|
-
executedSteps.push({
|
|
631
|
-
id: step.id,
|
|
632
|
-
routeId: routeId || 'unknown',
|
|
633
|
-
});
|
|
634
|
-
}
|
|
635
|
-
}
|
|
636
|
-
// PHASE 4: Execute finalize hooks (Requirement 5.5 - continue on failure)
|
|
637
|
-
const finalizeStartTime = Date.now();
|
|
638
|
-
utils_1.logger.debug(`[BatchExecutor] Phase 4: Executing finalize hooks`);
|
|
639
|
-
const finalizeResult = await this.executeFinalizeHooks({
|
|
640
|
-
steps: batch.steps,
|
|
641
|
-
context,
|
|
642
|
-
data: currentSession.data,
|
|
643
|
-
executeHook,
|
|
644
|
-
});
|
|
645
|
-
timing.finalizeHooksMs = Date.now() - finalizeStartTime;
|
|
646
|
-
utils_1.logger.debug(`[BatchExecutor] Finalize hooks completed in ${timing.finalizeHooksMs}ms`);
|
|
647
|
-
// Log finalize errors but don't fail the batch
|
|
648
|
-
let finalizeError;
|
|
649
|
-
if (finalizeResult.errors && finalizeResult.errors.length > 0) {
|
|
650
|
-
utils_1.logger.warn(`[BatchExecutor] Some finalize hooks failed:`, finalizeResult.errors);
|
|
651
|
-
// Create a summary error for finalize failures
|
|
652
|
-
finalizeError = {
|
|
653
|
-
type: 'finalize_hook',
|
|
654
|
-
message: `${finalizeResult.errors.length} finalize hook(s) failed`,
|
|
655
|
-
details: finalizeResult.errors,
|
|
656
|
-
};
|
|
657
|
-
}
|
|
658
|
-
// Determine the final stopped reason
|
|
659
|
-
// Priority: validation_error > finalize_error > batch.stoppedReason
|
|
660
|
-
let finalStoppedReason = batch.stoppedReason;
|
|
661
|
-
let finalError;
|
|
662
|
-
if (validationError) {
|
|
663
|
-
finalStoppedReason = 'validation_error';
|
|
664
|
-
finalError = validationError;
|
|
665
|
-
}
|
|
666
|
-
else if (finalizeError) {
|
|
667
|
-
// Finalize errors are non-fatal, so we keep the original stopped reason
|
|
668
|
-
// but include the error in the response
|
|
669
|
-
finalError = finalizeError;
|
|
670
|
-
}
|
|
671
|
-
// Calculate total time and log completion (Requirement 11.1, 11.2)
|
|
672
|
-
timing.totalMs = Date.now() - batchStartTime;
|
|
673
|
-
utils_1.logger.debug(`[BatchExecutor] Batch execution complete. Stopped reason: ${finalStoppedReason}, Executed steps: ${executedSteps.length}, Total time: ${timing.totalMs}ms`);
|
|
674
|
-
// Emit batch_complete event (Requirement 11.3)
|
|
675
|
-
this.emitBatchEvent('batch_complete', {
|
|
676
|
-
batchSize: executedSteps.length,
|
|
677
|
-
stoppedReason: finalStoppedReason,
|
|
678
|
-
reason: `Batch completed with ${executedSteps.length} steps`,
|
|
679
|
-
timing,
|
|
680
|
-
});
|
|
681
|
-
return {
|
|
682
|
-
message,
|
|
683
|
-
session: currentSession,
|
|
684
|
-
executedSteps,
|
|
685
|
-
stoppedReason: finalStoppedReason,
|
|
686
|
-
collectedData,
|
|
687
|
-
error: finalError,
|
|
688
|
-
};
|
|
689
|
-
}
|
|
690
|
-
/**
|
|
691
|
-
* Collect data from LLM response for all steps in the batch
|
|
692
|
-
*
|
|
693
|
-
* This method:
|
|
694
|
-
* 1. Gathers all collect fields from all steps in the batch
|
|
695
|
-
* 2. Extracts those fields from the LLM response
|
|
696
|
-
* 3. Validates extracted data against the agent schema (if provided)
|
|
697
|
-
* 4. Updates session data with all collected values
|
|
698
|
-
*
|
|
699
|
-
* @param params - Parameters for data collection
|
|
700
|
-
* @returns Result with collected data, updated session, and any validation errors
|
|
701
|
-
*
|
|
702
|
-
* **Validates: Requirements 6.1, 6.2, 6.3**
|
|
703
|
-
*/
|
|
704
|
-
collectBatchData(params) {
|
|
705
|
-
const { steps, llmResponse, session, schema } = params;
|
|
706
|
-
utils_1.logger.debug(`[BatchExecutor] Collecting batch data from ${steps.length} steps`);
|
|
707
|
-
// Requirement 6.1: Gather all collect fields from all steps in the batch
|
|
708
|
-
const allCollectFields = new Set();
|
|
709
|
-
for (const step of steps) {
|
|
710
|
-
if (step.collect && step.collect.length > 0) {
|
|
711
|
-
for (const field of step.collect) {
|
|
712
|
-
allCollectFields.add(String(field));
|
|
713
|
-
}
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
utils_1.logger.debug(`[BatchExecutor] Collect fields to extract: ${Array.from(allCollectFields).join(', ')}`);
|
|
717
|
-
// If no fields to collect, return early with unchanged session
|
|
718
|
-
if (allCollectFields.size === 0) {
|
|
719
|
-
utils_1.logger.debug(`[BatchExecutor] No collect fields defined, skipping data collection`);
|
|
720
|
-
return {
|
|
721
|
-
success: true,
|
|
722
|
-
collectedData: {},
|
|
723
|
-
session,
|
|
724
|
-
fieldsCollected: [],
|
|
725
|
-
};
|
|
726
|
-
}
|
|
727
|
-
// Extract data from LLM response for all collect fields
|
|
728
|
-
const collectedData = {};
|
|
729
|
-
const fieldsCollected = [];
|
|
730
|
-
const fieldsMissing = [];
|
|
731
|
-
for (const field of allCollectFields) {
|
|
732
|
-
// Check if the field exists in the LLM response
|
|
733
|
-
if (field in llmResponse && llmResponse[field] !== undefined) {
|
|
734
|
-
collectedData[field] = llmResponse[field];
|
|
735
|
-
fieldsCollected.push(field);
|
|
736
|
-
utils_1.logger.debug(`[BatchExecutor] Collected field '${field}': ${JSON.stringify(llmResponse[field])}`);
|
|
737
|
-
}
|
|
738
|
-
else {
|
|
739
|
-
fieldsMissing.push(field);
|
|
740
|
-
utils_1.logger.debug(`[BatchExecutor] Field '${field}' not found in LLM response`);
|
|
741
|
-
}
|
|
742
|
-
}
|
|
743
|
-
// Requirement 6.2: Validate collected data against the agent schema
|
|
744
|
-
const validationErrors = [];
|
|
745
|
-
if (schema && Object.keys(collectedData).length > 0) {
|
|
746
|
-
utils_1.logger.debug(`[BatchExecutor] Validating collected data against schema`);
|
|
747
|
-
const validationResult = this.validateAgainstSchema(collectedData, schema);
|
|
748
|
-
if (!validationResult.valid) {
|
|
749
|
-
validationErrors.push(...validationResult.errors);
|
|
750
|
-
utils_1.logger.warn(`[BatchExecutor] Schema validation found ${validationErrors.length} error(s)`);
|
|
751
|
-
}
|
|
752
|
-
}
|
|
753
|
-
// Requirement 6.3: Update session data with all collected values
|
|
754
|
-
// Only merge valid data (data that passed validation or had no schema to validate against)
|
|
755
|
-
let updatedSession = session;
|
|
756
|
-
if (Object.keys(collectedData).length > 0) {
|
|
757
|
-
// Filter out fields with validation errors if we want strict validation
|
|
758
|
-
// For now, we include all collected data and report errors separately
|
|
759
|
-
updatedSession = (0, utils_1.mergeCollected)(session, collectedData);
|
|
760
|
-
utils_1.logger.debug(`[BatchExecutor] Updated session with collected data`);
|
|
761
|
-
}
|
|
762
|
-
const success = validationErrors.length === 0;
|
|
763
|
-
utils_1.logger.debug(`[BatchExecutor] Data collection complete. Success: ${success}, Fields collected: ${fieldsCollected.length}, Fields missing: ${fieldsMissing.length}`);
|
|
764
|
-
return {
|
|
765
|
-
success,
|
|
766
|
-
collectedData,
|
|
767
|
-
session: updatedSession,
|
|
768
|
-
fieldsCollected,
|
|
769
|
-
fieldsMissing: fieldsMissing.length > 0 ? fieldsMissing : undefined,
|
|
770
|
-
validationErrors: validationErrors.length > 0 ? validationErrors : undefined,
|
|
771
|
-
};
|
|
772
|
-
}
|
|
773
|
-
/**
|
|
774
|
-
* Validate data against a JSON schema
|
|
775
|
-
*
|
|
776
|
-
* Performs basic validation of collected data against the agent schema.
|
|
777
|
-
* Checks:
|
|
778
|
-
* - Fields exist in schema properties
|
|
779
|
-
* - Required fields are present (as warnings)
|
|
780
|
-
* - Basic type validation
|
|
781
|
-
*
|
|
782
|
-
* @param data - Data to validate
|
|
783
|
-
* @param schema - JSON schema to validate against
|
|
784
|
-
* @returns Validation result with errors
|
|
785
|
-
* @private
|
|
786
|
-
*/
|
|
787
|
-
validateAgainstSchema(data, schema) {
|
|
788
|
-
const errors = [];
|
|
789
|
-
// Check if provided fields exist in schema
|
|
790
|
-
if (schema.properties) {
|
|
791
|
-
for (const [key, value] of Object.entries(data)) {
|
|
792
|
-
if (!(key in schema.properties)) {
|
|
793
|
-
errors.push({
|
|
794
|
-
field: key,
|
|
795
|
-
value,
|
|
796
|
-
message: `Field '${key}' is not defined in schema`,
|
|
797
|
-
schemaPath: `properties.${key}`,
|
|
798
|
-
});
|
|
799
|
-
}
|
|
800
|
-
else {
|
|
801
|
-
// Basic type validation
|
|
802
|
-
const fieldSchema = schema.properties[key];
|
|
803
|
-
const typeError = this.validateFieldType(key, value, fieldSchema);
|
|
804
|
-
if (typeError) {
|
|
805
|
-
errors.push(typeError);
|
|
806
|
-
}
|
|
807
|
-
}
|
|
808
|
-
}
|
|
809
|
-
}
|
|
810
|
-
return {
|
|
811
|
-
valid: errors.length === 0,
|
|
812
|
-
errors,
|
|
813
|
-
};
|
|
814
|
-
}
|
|
815
|
-
/**
|
|
816
|
-
* Validate a single field's type against its schema
|
|
817
|
-
* @private
|
|
818
|
-
*/
|
|
819
|
-
validateFieldType(field, value, fieldSchema) {
|
|
820
|
-
if (value === null || value === undefined) {
|
|
821
|
-
// Null/undefined values are handled separately (required field check)
|
|
822
|
-
return null;
|
|
823
|
-
}
|
|
824
|
-
const expectedType = fieldSchema.type;
|
|
825
|
-
if (!expectedType) {
|
|
826
|
-
// No type specified, consider valid
|
|
827
|
-
return null;
|
|
828
|
-
}
|
|
829
|
-
const actualType = Array.isArray(value) ? 'array' : typeof value;
|
|
830
|
-
// Handle array of types
|
|
831
|
-
const allowedTypes = Array.isArray(expectedType) ? expectedType : [expectedType];
|
|
832
|
-
// Map JavaScript types to JSON Schema types
|
|
833
|
-
const typeMapping = {
|
|
834
|
-
'string': 'string',
|
|
835
|
-
'number': 'number',
|
|
836
|
-
'boolean': 'boolean',
|
|
837
|
-
'object': 'object',
|
|
838
|
-
'array': 'array',
|
|
839
|
-
};
|
|
840
|
-
const mappedActualType = typeMapping[actualType] || actualType;
|
|
841
|
-
// Check if actual type matches any allowed type
|
|
842
|
-
// Also handle 'integer' as a valid number type
|
|
843
|
-
const isValidType = allowedTypes.some(t => {
|
|
844
|
-
if (t === 'integer') {
|
|
845
|
-
return typeof value === 'number' && Number.isInteger(value);
|
|
846
|
-
}
|
|
847
|
-
return t === mappedActualType;
|
|
848
|
-
});
|
|
849
|
-
if (!isValidType) {
|
|
850
|
-
return {
|
|
851
|
-
field,
|
|
852
|
-
value,
|
|
853
|
-
message: `Field '${field}' has type '${actualType}' but expected '${allowedTypes.join(' | ')}'`,
|
|
854
|
-
schemaPath: `properties.${field}.type`,
|
|
855
|
-
};
|
|
856
|
-
}
|
|
857
|
-
return null;
|
|
858
|
-
}
|
|
859
|
-
}
|
|
860
|
-
exports.BatchExecutor = BatchExecutor;
|
|
861
|
-
//# sourceMappingURL=BatchExecutor.js.map
|