@falai/agent 1.2.7 → 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 +1196 -1015
- 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 +524 -134
- 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/providers/GeminiProvider.d.ts +3 -3
- package/dist/cjs/providers/GeminiProvider.d.ts.map +1 -1
- package/dist/cjs/providers/GeminiProvider.js +16 -14
- package/dist/cjs/providers/GeminiProvider.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 +1198 -1017
- 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 +524 -135
- 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/providers/GeminiProvider.d.ts +3 -3
- package/dist/providers/GeminiProvider.d.ts.map +1 -1
- package/dist/providers/GeminiProvider.js +16 -14
- package/dist/providers/GeminiProvider.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 +1458 -1241
- package/src/core/ResponsePipeline.ts +675 -173
- 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/providers/GeminiProvider.ts +17 -15
- 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
package/dist/core/ToolManager.js
CHANGED
|
@@ -33,8 +33,53 @@ export class ToolExecutionError extends Error {
|
|
|
33
33
|
export class ToolManager {
|
|
34
34
|
constructor(agent) {
|
|
35
35
|
this.agent = agent;
|
|
36
|
+
/**
|
|
37
|
+
* Per-turn transient tool layer populated from PreDirective.injectTools.
|
|
38
|
+
* Resolution order: transient → step → flow → agent.
|
|
39
|
+
* Drained at end of turn via try/finally guard.
|
|
40
|
+
*
|
|
41
|
+
* Tools are deduplicated by `id` with last-definition-wins when
|
|
42
|
+
* multiple pre-LLM emitters contribute tools in the same turn.
|
|
43
|
+
*/
|
|
44
|
+
this.transientTools = new Map();
|
|
36
45
|
this.toolRegistry = new Map();
|
|
37
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Set the transient tool layer for the current turn.
|
|
49
|
+
*
|
|
50
|
+
* Accepts the merged `injectTools` array from pre-LLM emitters
|
|
51
|
+
* (already concatenated in outer-to-inner order by the DirectiveBus).
|
|
52
|
+
* Deduplicates by tool `id` with last-definition-wins.
|
|
53
|
+
*
|
|
54
|
+
* Must be paired with `clearTransientTools()` in a try/finally guard
|
|
55
|
+
* so the layer is drained even on abnormal termination.
|
|
56
|
+
*/
|
|
57
|
+
setTransientTools(tools) {
|
|
58
|
+
this.transientTools.clear();
|
|
59
|
+
for (const tool of tools) {
|
|
60
|
+
this.transientTools.set(tool.id, tool);
|
|
61
|
+
}
|
|
62
|
+
if (this.transientTools.size > 0) {
|
|
63
|
+
logger.debug(`[ToolManager] Set transient tools for turn: ${Array.from(this.transientTools.keys()).join(', ')}`);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Clear the transient tool layer. Called at end of turn via try/finally
|
|
68
|
+
* guard so tools do not leak into subsequent turns.
|
|
69
|
+
*/
|
|
70
|
+
clearTransientTools() {
|
|
71
|
+
if (this.transientTools.size > 0) {
|
|
72
|
+
logger.debug(`[ToolManager] Cleared transient tools: ${Array.from(this.transientTools.keys()).join(', ')}`);
|
|
73
|
+
}
|
|
74
|
+
this.transientTools.clear();
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Check whether the transient layer currently has any tools.
|
|
78
|
+
* Useful for testing and debugging.
|
|
79
|
+
*/
|
|
80
|
+
hasTransientTools() {
|
|
81
|
+
return this.transientTools.size > 0;
|
|
82
|
+
}
|
|
38
83
|
/**
|
|
39
84
|
* Validate a tool definition for completeness and correctness
|
|
40
85
|
*/
|
|
@@ -53,10 +98,6 @@ export class ToolManager {
|
|
|
53
98
|
if (!definition.handler || typeof definition.handler !== 'function') {
|
|
54
99
|
errors.push('Tool handler is required and must be a function');
|
|
55
100
|
}
|
|
56
|
-
// Optional fields validation
|
|
57
|
-
if (definition.name !== undefined && (typeof definition.name !== 'string' || definition.name.trim() === '')) {
|
|
58
|
-
errors.push('Tool name must be a non-empty string if provided');
|
|
59
|
-
}
|
|
60
101
|
if (definition.description !== undefined && (typeof definition.description !== 'string' || definition.description.trim() === '')) {
|
|
61
102
|
errors.push('Tool description must be a non-empty string if provided');
|
|
62
103
|
}
|
|
@@ -82,7 +123,8 @@ export class ToolManager {
|
|
|
82
123
|
}
|
|
83
124
|
}
|
|
84
125
|
if (errors.length > 0) {
|
|
85
|
-
throw new ToolCreationError(`Tool definition validation failed: ${errors.join('; ')}
|
|
126
|
+
throw new ToolCreationError(`[ToolCreationError] Tool definition validation failed for "${definition.id || 'unknown'}": ${errors.join('; ')}. ` +
|
|
127
|
+
`Fix the tool definition to meet the required schema.`, definition.id || 'unknown');
|
|
86
128
|
}
|
|
87
129
|
}
|
|
88
130
|
/**
|
|
@@ -97,7 +139,8 @@ export class ToolManager {
|
|
|
97
139
|
errors.push('Data enrichment enricher must be a function');
|
|
98
140
|
}
|
|
99
141
|
if (errors.length > 0) {
|
|
100
|
-
throw new ToolCreationError(`Data enrichment
|
|
142
|
+
throw new ToolCreationError(`[ToolCreationError] Data enrichment config validation failed for "${config.id || 'unknown'}": ${errors.join('; ')}. ` +
|
|
143
|
+
`Fix the enrichment config to satisfy the required fields.`, config.id || 'unknown');
|
|
101
144
|
}
|
|
102
145
|
}
|
|
103
146
|
/**
|
|
@@ -112,7 +155,8 @@ export class ToolManager {
|
|
|
112
155
|
errors.push('Validation validator must be a function');
|
|
113
156
|
}
|
|
114
157
|
if (errors.length > 0) {
|
|
115
|
-
throw new ToolCreationError(`Validation
|
|
158
|
+
throw new ToolCreationError(`[ToolCreationError] Validation config validation failed for "${config.id || 'unknown'}": ${errors.join('; ')}. ` +
|
|
159
|
+
`Fix the validation config to satisfy the required fields.`, config.id || 'unknown');
|
|
116
160
|
}
|
|
117
161
|
}
|
|
118
162
|
/**
|
|
@@ -139,7 +183,8 @@ export class ToolManager {
|
|
|
139
183
|
errors.push('API call transform must be a function');
|
|
140
184
|
}
|
|
141
185
|
if (errors.length > 0) {
|
|
142
|
-
throw new ToolCreationError(`API call
|
|
186
|
+
throw new ToolCreationError(`[ToolCreationError] API call config validation failed for "${config.id || 'unknown'}": ${errors.join('; ')}. ` +
|
|
187
|
+
`Fix the API call config to satisfy the required fields.`, config.id || 'unknown');
|
|
143
188
|
}
|
|
144
189
|
}
|
|
145
190
|
/**
|
|
@@ -154,7 +199,8 @@ export class ToolManager {
|
|
|
154
199
|
errors.push('Computation compute function is required');
|
|
155
200
|
}
|
|
156
201
|
if (errors.length > 0) {
|
|
157
|
-
throw new ToolCreationError(`Computation
|
|
202
|
+
throw new ToolCreationError(`[ToolCreationError] Computation config validation failed for "${config.id || 'unknown'}": ${errors.join('; ')}. ` +
|
|
203
|
+
`Fix the computation config to satisfy the required fields.`, config.id || 'unknown');
|
|
158
204
|
}
|
|
159
205
|
}
|
|
160
206
|
/**
|
|
@@ -169,7 +215,8 @@ export class ToolManager {
|
|
|
169
215
|
return definition;
|
|
170
216
|
}
|
|
171
217
|
catch (error) {
|
|
172
|
-
throw new ToolCreationError(`Failed to create tool
|
|
218
|
+
throw new ToolCreationError(`[ToolCreationError] Failed to create tool "${definition.id}": ${error instanceof Error ? error.message : String(error)}. ` +
|
|
219
|
+
`Ensure the tool definition passes validation.`, definition.id, error instanceof Error ? error : undefined);
|
|
173
220
|
}
|
|
174
221
|
}
|
|
175
222
|
/**
|
|
@@ -179,22 +226,22 @@ export class ToolManager {
|
|
|
179
226
|
register(tool) {
|
|
180
227
|
try {
|
|
181
228
|
if (!tool) {
|
|
182
|
-
throw new ToolCreationError('Tool
|
|
229
|
+
throw new ToolCreationError('[ToolCreationError] Tool registration failed: no tool provided. Pass a valid tool object with id and handler.', 'unknown');
|
|
183
230
|
}
|
|
184
231
|
if (!('handler' in tool) || typeof tool.handler !== 'function') {
|
|
185
|
-
throw new ToolCreationError(
|
|
232
|
+
throw new ToolCreationError(`[ToolCreationError] Invalid tool for registration: tool "${tool?.id || 'unknown'}" must have a handler function. Add a handler property.`, tool?.id || 'unknown');
|
|
186
233
|
}
|
|
187
234
|
// Validate the tool
|
|
188
235
|
if (!tool.id || typeof tool.id !== 'string' || tool.id.trim() === '') {
|
|
189
|
-
throw new ToolCreationError('Tool ID is required and must be a non-empty string', tool.id || 'unknown');
|
|
236
|
+
throw new ToolCreationError('[ToolCreationError] Tool ID missing: tool ID is required and must be a non-empty string. Provide a unique string id.', tool.id || 'unknown');
|
|
190
237
|
}
|
|
191
238
|
// Check for ID conflicts and provide better error context
|
|
192
239
|
if (this.toolRegistry.has(tool.id)) {
|
|
193
240
|
const existingTool = this.toolRegistry.get(tool.id);
|
|
194
|
-
logger.warn(`[ToolManager] Overwriting existing registered tool: ${tool.id} (previous: ${existingTool?.
|
|
241
|
+
logger.warn(`[ToolManager] Overwriting existing registered tool: ${tool.id} (previous: ${existingTool?.id || 'unnamed'})`);
|
|
195
242
|
}
|
|
196
243
|
this.toolRegistry.set(tool.id, tool);
|
|
197
|
-
logger.debug(`[ToolManager] Registered tool: ${tool.id} (${tool.
|
|
244
|
+
logger.debug(`[ToolManager] Registered tool: ${tool.id} (${tool.id || 'unnamed'})`);
|
|
198
245
|
return tool;
|
|
199
246
|
}
|
|
200
247
|
catch (error) {
|
|
@@ -202,7 +249,8 @@ export class ToolManager {
|
|
|
202
249
|
throw error;
|
|
203
250
|
}
|
|
204
251
|
const toolId = tool?.id || 'unknown';
|
|
205
|
-
throw new ToolCreationError(`Failed to register tool
|
|
252
|
+
throw new ToolCreationError(`[ToolCreationError] Failed to register tool "${toolId}": ${error instanceof Error ? error.message : String(error)}. ` +
|
|
253
|
+
`Ensure the tool object is valid and has id + handler.`, toolId, error instanceof Error ? error : undefined);
|
|
206
254
|
}
|
|
207
255
|
}
|
|
208
256
|
/**
|
|
@@ -238,20 +286,20 @@ export class ToolManager {
|
|
|
238
286
|
/**
|
|
239
287
|
* Get tool by ID from a specific scope
|
|
240
288
|
*/
|
|
241
|
-
getFromScope(toolId, scope, step,
|
|
242
|
-
return this.find(toolId, scope, step,
|
|
289
|
+
getFromScope(toolId, scope, step, flow) {
|
|
290
|
+
return this.find(toolId, scope, step, flow);
|
|
243
291
|
}
|
|
244
292
|
/**
|
|
245
293
|
* Check if a tool exists in any scope
|
|
246
294
|
*/
|
|
247
|
-
exists(toolId, step,
|
|
248
|
-
return this.find(toolId, ToolScope.ALL, step,
|
|
295
|
+
exists(toolId, step, flow) {
|
|
296
|
+
return this.find(toolId, ToolScope.ALL, step, flow) !== undefined;
|
|
249
297
|
}
|
|
250
298
|
/**
|
|
251
299
|
* Get tool count by scope
|
|
252
300
|
*/
|
|
253
|
-
getToolCount(scope, step,
|
|
254
|
-
return this.getAvailable(scope, step,
|
|
301
|
+
getToolCount(scope, step, flow) {
|
|
302
|
+
return this.getAvailable(scope, step, flow).length;
|
|
255
303
|
}
|
|
256
304
|
/**
|
|
257
305
|
* Clear all registered tools
|
|
@@ -277,7 +325,8 @@ export class ToolManager {
|
|
|
277
325
|
addToAgent(tool) {
|
|
278
326
|
// Validate tool before adding
|
|
279
327
|
if (!tool || !tool.id || !tool.handler) {
|
|
280
|
-
throw new ToolCreationError(
|
|
328
|
+
throw new ToolCreationError(`[ToolCreationError] Invalid tool for addToAgent: tool must have id and handler properties. ` +
|
|
329
|
+
`Provide a complete tool object with { id, handler, ... }.`, tool?.id || 'unknown');
|
|
281
330
|
}
|
|
282
331
|
// Add to agent's tools array using the unified interface
|
|
283
332
|
if (this.agent) {
|
|
@@ -290,33 +339,41 @@ export class ToolManager {
|
|
|
290
339
|
return tool;
|
|
291
340
|
}
|
|
292
341
|
/**
|
|
293
|
-
* Add a tool to a specific
|
|
342
|
+
* Add a tool to a specific flow scope (creates and adds in one operation)
|
|
294
343
|
*/
|
|
295
|
-
|
|
296
|
-
// Add to
|
|
297
|
-
if (
|
|
298
|
-
|
|
344
|
+
addToFlow(flow, tool) {
|
|
345
|
+
// Add to flow's tools array using the existing createTool method
|
|
346
|
+
if (flow && typeof flow.createTool === 'function') {
|
|
347
|
+
flow.createTool(tool);
|
|
299
348
|
}
|
|
300
349
|
else {
|
|
301
|
-
logger.warn(`[ToolManager]
|
|
350
|
+
logger.warn(`[ToolManager] Flow does not support createTool method, tool not added to flow scope: ${tool.id}`);
|
|
302
351
|
}
|
|
303
|
-
logger.debug(`[ToolManager] Added tool to
|
|
352
|
+
logger.debug(`[ToolManager] Added tool to flow scope: ${tool.id}`);
|
|
304
353
|
return tool;
|
|
305
354
|
}
|
|
306
355
|
/**
|
|
307
356
|
* Find a tool by ID across different scopes with enhanced resolution logic
|
|
308
|
-
* Priority: step →
|
|
357
|
+
* Priority: transient → step → flow → agent → registry
|
|
309
358
|
* Supports both ID and name matching for better compatibility
|
|
310
359
|
*/
|
|
311
|
-
find(toolId, scope, step,
|
|
360
|
+
find(toolId, scope, step, flow) {
|
|
312
361
|
logger.debug(`[ToolManager] Finding tool: ${toolId} with scope: ${scope || 'ALL'}`);
|
|
313
|
-
// Check
|
|
362
|
+
// Check transient tools first (highest priority — per-turn injectTools)
|
|
363
|
+
if (!scope || scope === ToolScope.ALL) {
|
|
364
|
+
const transientTool = this.transientTools.get(toolId);
|
|
365
|
+
if (transientTool) {
|
|
366
|
+
logger.debug(`[ToolManager] Found tool in transient scope: ${toolId}`);
|
|
367
|
+
return transientTool;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
// Check step-level tools (if step provided and scope allows)
|
|
314
371
|
if (step && (!scope || scope === ToolScope.STEP || scope === ToolScope.ALL)) {
|
|
315
372
|
if (step.tools) {
|
|
316
373
|
for (const toolRef of step.tools) {
|
|
317
374
|
if (typeof toolRef !== 'string') {
|
|
318
375
|
// Inline tool object - check both id and name
|
|
319
|
-
if (toolRef.id === toolId
|
|
376
|
+
if (toolRef.id === toolId) {
|
|
320
377
|
logger.debug(`[ToolManager] Found tool in step scope: ${toolId}`);
|
|
321
378
|
return toolRef;
|
|
322
379
|
}
|
|
@@ -334,13 +391,13 @@ export class ToolManager {
|
|
|
334
391
|
}
|
|
335
392
|
}
|
|
336
393
|
}
|
|
337
|
-
// Check
|
|
338
|
-
if (
|
|
339
|
-
if (
|
|
340
|
-
const
|
|
341
|
-
if (
|
|
342
|
-
logger.debug(`[ToolManager] Found tool in
|
|
343
|
-
return
|
|
394
|
+
// Check flow-level tools (if route provided and scope allows)
|
|
395
|
+
if (flow && (!scope || scope === ToolScope.FLOW || scope === ToolScope.ALL)) {
|
|
396
|
+
if (flow.tools) {
|
|
397
|
+
const flowTool = flow.tools.find((t) => t.id === toolId);
|
|
398
|
+
if (flowTool) {
|
|
399
|
+
logger.debug(`[ToolManager] Found tool in flow scope: ${toolId}`);
|
|
400
|
+
return flowTool;
|
|
344
401
|
}
|
|
345
402
|
}
|
|
346
403
|
}
|
|
@@ -348,7 +405,7 @@ export class ToolManager {
|
|
|
348
405
|
if (!scope || scope === ToolScope.AGENT || scope === ToolScope.ALL) {
|
|
349
406
|
if (this.agent) {
|
|
350
407
|
const agentTools = this.agent.getTools();
|
|
351
|
-
const agentTool = agentTools.find((t) => t.id === toolId
|
|
408
|
+
const agentTool = agentTools.find((t) => t.id === toolId);
|
|
352
409
|
if (agentTool) {
|
|
353
410
|
logger.debug(`[ToolManager] Found tool in agent scope: ${toolId}`);
|
|
354
411
|
return agentTool;
|
|
@@ -364,7 +421,7 @@ export class ToolManager {
|
|
|
364
421
|
}
|
|
365
422
|
// Also check by name in registry
|
|
366
423
|
for (const [id, tool] of Array.from(this.toolRegistry.entries())) {
|
|
367
|
-
if (tool.
|
|
424
|
+
if (tool.id === toolId) {
|
|
368
425
|
logger.debug(`[ToolManager] Found tool in registry by name: ${toolId} (id: ${id})`);
|
|
369
426
|
return tool;
|
|
370
427
|
}
|
|
@@ -376,8 +433,9 @@ export class ToolManager {
|
|
|
376
433
|
/**
|
|
377
434
|
* Get available tools for current context with enhanced resolution and deduplication
|
|
378
435
|
* Returns tools in priority order with higher-priority scopes taking precedence
|
|
436
|
+
* Resolution order: transient → step → flow → agent → registry
|
|
379
437
|
*/
|
|
380
|
-
getAvailable(scope, step,
|
|
438
|
+
getAvailable(scope, step, flow) {
|
|
381
439
|
const toolMap = new Map();
|
|
382
440
|
const resolvedTools = [];
|
|
383
441
|
logger.debug(`[ToolManager] Getting available tools with scope: ${scope || 'ALL'}`);
|
|
@@ -399,15 +457,15 @@ export class ToolManager {
|
|
|
399
457
|
}
|
|
400
458
|
}
|
|
401
459
|
// Add route-level tools (override agent and registered tools with same ID)
|
|
402
|
-
if (
|
|
403
|
-
if (
|
|
404
|
-
for (const tool of
|
|
460
|
+
if (flow && (!scope || scope === ToolScope.FLOW || scope === ToolScope.ALL)) {
|
|
461
|
+
if (flow.tools) {
|
|
462
|
+
for (const tool of flow.tools) {
|
|
405
463
|
toolMap.set(tool.id, tool);
|
|
406
464
|
}
|
|
407
|
-
logger.debug(`[ToolManager] Added ${
|
|
465
|
+
logger.debug(`[ToolManager] Added ${flow.tools.length} flow.tools`);
|
|
408
466
|
}
|
|
409
467
|
}
|
|
410
|
-
// Add step-level tools (
|
|
468
|
+
// Add step-level tools (override flow/agent/registry with same ID)
|
|
411
469
|
if (step && (!scope || scope === ToolScope.STEP || scope === ToolScope.ALL)) {
|
|
412
470
|
if (step.tools) {
|
|
413
471
|
for (const toolRef of step.tools) {
|
|
@@ -424,21 +482,33 @@ export class ToolManager {
|
|
|
424
482
|
resolvedTools.push(registeredTool);
|
|
425
483
|
}
|
|
426
484
|
else {
|
|
427
|
-
logger.warn(`[
|
|
485
|
+
logger.warn(`[ToolExecutionError] Step references unknown tool: "${toolRef}" is not registered. Skipping. Register the tool or remove the reference.`);
|
|
428
486
|
}
|
|
429
487
|
}
|
|
430
488
|
}
|
|
431
489
|
logger.debug(`[ToolManager] Added ${step.tools.length} step tools (${resolvedTools.length} resolved)`);
|
|
432
490
|
}
|
|
433
491
|
}
|
|
492
|
+
// Add transient tools (highest priority — override everything with same ID)
|
|
493
|
+
if (!scope || scope === ToolScope.ALL) {
|
|
494
|
+
if (this.transientTools.size > 0) {
|
|
495
|
+
for (const [id, tool] of this.transientTools) {
|
|
496
|
+
toolMap.set(id, tool);
|
|
497
|
+
}
|
|
498
|
+
logger.debug(`[ToolManager] Added ${this.transientTools.size} transient tools`);
|
|
499
|
+
}
|
|
500
|
+
}
|
|
434
501
|
// Convert map to array, preserving priority order
|
|
435
502
|
const allTools = Array.from(toolMap.values());
|
|
436
|
-
// If we have step-specific tools, prioritize them
|
|
503
|
+
// If we have step-specific tools, prioritize them in the ordering
|
|
504
|
+
// (but transient tools that override step tools via same ID are already in the map)
|
|
437
505
|
if (resolvedTools.length > 0) {
|
|
438
506
|
// Add resolved step tools first, then other tools not already included
|
|
439
507
|
const stepToolIds = new Set(resolvedTools.map(t => t.id));
|
|
440
508
|
const otherTools = allTools.filter(t => !stepToolIds.has(t.id));
|
|
441
|
-
|
|
509
|
+
// For step tools, use the map version (which may be overridden by transient)
|
|
510
|
+
const finalStepTools = resolvedTools.map(t => toolMap.get(t.id) || t);
|
|
511
|
+
return [...finalStepTools, ...otherTools];
|
|
442
512
|
}
|
|
443
513
|
logger.debug(`[ToolManager] Returning ${allTools.length} available tools`);
|
|
444
514
|
return allTools;
|
|
@@ -462,7 +532,7 @@ export class ToolManager {
|
|
|
462
532
|
// Try primary tool with retries
|
|
463
533
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
464
534
|
try {
|
|
465
|
-
const tool = this.find(toolId, undefined, context?.step, context?.
|
|
535
|
+
const tool = this.find(toolId, undefined, context?.step, context?.flow);
|
|
466
536
|
if (!tool) {
|
|
467
537
|
// Tool not found - try fallback tools if available
|
|
468
538
|
if (fallbackTools.length > 0) {
|
|
@@ -574,7 +644,8 @@ export class ToolManager {
|
|
|
574
644
|
}
|
|
575
645
|
}
|
|
576
646
|
// All attempts and fallbacks failed
|
|
577
|
-
throw new ToolExecutionError(`Tool execution failed
|
|
647
|
+
throw new ToolExecutionError(`[ToolExecutionError] Tool "${toolId}" execution failed: all ${maxRetries + 1} attempts exhausted${fallbackTools.length > 0 ? ` and fallback tools [${fallbackTools.join(', ')}] also failed` : ''}. ` +
|
|
648
|
+
`Check the tool handler for errors or increase maxRetries. Last error: ${lastError?.message || 'Unknown'}.`, toolId, { args, context, attempts: maxRetries + 1, fallbackTools }, lastError);
|
|
578
649
|
}
|
|
579
650
|
/**
|
|
580
651
|
* Determine if an error is transient and should be retried
|
|
@@ -612,6 +683,7 @@ export class ToolManager {
|
|
|
612
683
|
};
|
|
613
684
|
}
|
|
614
685
|
// Build tool context with complete agent data
|
|
686
|
+
const collectedDirectives = [];
|
|
615
687
|
const toolContext = {
|
|
616
688
|
context,
|
|
617
689
|
updateContext,
|
|
@@ -628,16 +700,18 @@ export class ToolManager {
|
|
|
628
700
|
},
|
|
629
701
|
hasField: (key) => {
|
|
630
702
|
return data != null && key in data;
|
|
703
|
+
},
|
|
704
|
+
dispatch: (directive) => {
|
|
705
|
+
collectedDirectives.push(directive);
|
|
631
706
|
}
|
|
632
707
|
};
|
|
633
708
|
logger.debug(`[ToolManager] Executing tool: ${tool.id} with args:`, toolArguments);
|
|
634
|
-
//
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
const validation = await enhanced.validateInput(toolArguments, toolContext);
|
|
709
|
+
// Tool validation gate (Req 6.1, 6.7)
|
|
710
|
+
if (typeof tool.validateInput === 'function' && toolArguments) {
|
|
711
|
+
const validation = await tool.validateInput(toolArguments, toolContext);
|
|
638
712
|
if (!validation.valid) {
|
|
639
713
|
const executionTime = Date.now() - startTime;
|
|
640
|
-
logger.warn(`[
|
|
714
|
+
logger.warn(`[DataValidationError] Tool "${tool.id}" input validation failed: ${validation.error}. Fix the tool call arguments to match the expected schema.`);
|
|
641
715
|
return {
|
|
642
716
|
success: false,
|
|
643
717
|
error: `Validation failed: ${validation.error || 'Invalid input'}`,
|
|
@@ -645,12 +719,13 @@ export class ToolManager {
|
|
|
645
719
|
};
|
|
646
720
|
}
|
|
647
721
|
}
|
|
648
|
-
//
|
|
649
|
-
|
|
650
|
-
|
|
722
|
+
// Tool permission gate (Req 6.7, 6.8)
|
|
723
|
+
// When denied: do not invoke handler, do not process directives, do not apply state writes
|
|
724
|
+
if (typeof tool.checkPermissions === 'function' && toolArguments) {
|
|
725
|
+
const permission = await tool.checkPermissions(toolArguments, toolContext);
|
|
651
726
|
if (!permission.allowed) {
|
|
652
727
|
const executionTime = Date.now() - startTime;
|
|
653
|
-
logger.warn(`[
|
|
728
|
+
logger.warn(`[ToolExecutionError] Tool "${tool.id}" permission denied: ${permission.reason}. The tool's checkPermissions hook rejected this call.`);
|
|
654
729
|
return {
|
|
655
730
|
success: false,
|
|
656
731
|
error: `Permission denied: ${permission.reason || 'Not allowed'}`,
|
|
@@ -676,7 +751,7 @@ export class ToolManager {
|
|
|
676
751
|
logger.debug(`[ToolManager] Tool ${tool.id} completed in ${executionTime}ms`);
|
|
677
752
|
// Handle different result types
|
|
678
753
|
let toolResult;
|
|
679
|
-
if (result && typeof result === 'object' && ('data' in result || 'success' in result || 'error' in result)) {
|
|
754
|
+
if (result && typeof result === 'object' && ('data' in result || 'success' in result || 'error' in result || 'directive' in result)) {
|
|
680
755
|
// It's already a ToolResult-like object
|
|
681
756
|
toolResult = result;
|
|
682
757
|
}
|
|
@@ -687,6 +762,10 @@ export class ToolManager {
|
|
|
687
762
|
success: true
|
|
688
763
|
};
|
|
689
764
|
}
|
|
765
|
+
// Collect directive from ToolResult.directive (if present)
|
|
766
|
+
if (toolResult.directive) {
|
|
767
|
+
collectedDirectives.push(toolResult.directive);
|
|
768
|
+
}
|
|
690
769
|
// Apply data updates from tool result with validation
|
|
691
770
|
if (toolResult.dataUpdate) {
|
|
692
771
|
try {
|
|
@@ -694,7 +773,7 @@ export class ToolManager {
|
|
|
694
773
|
await updateData(toolResult.dataUpdate);
|
|
695
774
|
}
|
|
696
775
|
else {
|
|
697
|
-
logger.warn(`[
|
|
776
|
+
logger.warn(`[DataValidationError] Tool "${tool.id}" returned invalid dataUpdate: expected object, got ${typeof toolResult.dataUpdate}. Fix the tool handler to return a valid dataUpdate object.`);
|
|
698
777
|
}
|
|
699
778
|
}
|
|
700
779
|
catch (updateError) {
|
|
@@ -713,7 +792,7 @@ export class ToolManager {
|
|
|
713
792
|
await updateContext(toolResult.contextUpdate);
|
|
714
793
|
}
|
|
715
794
|
else {
|
|
716
|
-
logger.warn(`[
|
|
795
|
+
logger.warn(`[DataValidationError] Tool "${tool.id}" returned invalid contextUpdate: expected object, got ${typeof toolResult.contextUpdate}. Fix the tool handler to return a valid contextUpdate object.`);
|
|
717
796
|
}
|
|
718
797
|
}
|
|
719
798
|
catch (updateError) {
|
|
@@ -732,9 +811,10 @@ export class ToolManager {
|
|
|
732
811
|
contextUpdate: toolResult.contextUpdate,
|
|
733
812
|
dataUpdate: toolResult.dataUpdate,
|
|
734
813
|
error: toolResult.error,
|
|
814
|
+
directives: collectedDirectives.length > 0 ? collectedDirectives : undefined,
|
|
735
815
|
metadata: {
|
|
736
816
|
toolId: tool.id,
|
|
737
|
-
toolName: tool.
|
|
817
|
+
toolName: tool.id,
|
|
738
818
|
executionTime,
|
|
739
819
|
...(toolResult.meta || {})
|
|
740
820
|
}
|
|
@@ -789,7 +869,7 @@ export class ToolManager {
|
|
|
789
869
|
* Progress messages are yielded immediately.
|
|
790
870
|
*/
|
|
791
871
|
async *executeWithConcurrency(params) {
|
|
792
|
-
const { toolCalls, context, data, history, signal,
|
|
872
|
+
const { toolCalls, context, data, history, signal, flow, step } = params;
|
|
793
873
|
if (toolCalls.length === 0) {
|
|
794
874
|
return;
|
|
795
875
|
}
|
|
@@ -798,7 +878,7 @@ export class ToolManager {
|
|
|
798
878
|
context,
|
|
799
879
|
data: data || {},
|
|
800
880
|
history: history || [],
|
|
801
|
-
step: step ? { id: step.id,
|
|
881
|
+
step: step ? { id: step.id, flowId: flow?.id || '' } : undefined,
|
|
802
882
|
updateContext: (updates) => {
|
|
803
883
|
Object.assign(context, updates);
|
|
804
884
|
return Promise.resolve();
|
|
@@ -821,18 +901,23 @@ export class ToolManager {
|
|
|
821
901
|
hasField: (key) => {
|
|
822
902
|
return data != null && key in data;
|
|
823
903
|
},
|
|
904
|
+
dispatch: (_directive) => {
|
|
905
|
+
// Directives from concurrent execution are collected by the StreamingToolExecutor
|
|
906
|
+
// and surfaced via ToolExecutionUpdate. This is a no-op placeholder;
|
|
907
|
+
// full directive bus integration happens in ResponsePipeline (task 1.6).
|
|
908
|
+
},
|
|
824
909
|
};
|
|
825
910
|
const executor = new StreamingToolExecutor(toolContext, {
|
|
826
911
|
signal,
|
|
827
912
|
});
|
|
828
913
|
// Resolve and queue each tool call
|
|
829
914
|
for (const toolCall of toolCalls) {
|
|
830
|
-
const tool = this.find(toolCall.toolName, undefined, step,
|
|
915
|
+
const tool = this.find(toolCall.toolName, undefined, step, flow);
|
|
831
916
|
if (!tool) {
|
|
832
|
-
logger.warn(`[
|
|
917
|
+
logger.warn(`[ToolExecutionError] Tool not found for concurrent execution: "${toolCall.toolName}" is not registered in any scope. Skipping. Register the tool or check the tool name.`);
|
|
833
918
|
continue;
|
|
834
919
|
}
|
|
835
|
-
//
|
|
920
|
+
// Tool carries all metadata fields directly — no cast needed
|
|
836
921
|
executor.addTool(toolCall, tool);
|
|
837
922
|
}
|
|
838
923
|
// Yield all results in order
|
|
@@ -847,7 +932,6 @@ export class ToolManager {
|
|
|
847
932
|
this.validateDataEnrichmentConfig(config);
|
|
848
933
|
const tool = {
|
|
849
934
|
id: config.id,
|
|
850
|
-
name: config.name || `Data Enrichment: ${config.id}`,
|
|
851
935
|
description: config.description || `Enriches data fields: ${config.fields.join(', ')}`,
|
|
852
936
|
parameters: {
|
|
853
937
|
type: 'object',
|
|
@@ -886,7 +970,8 @@ export class ToolManager {
|
|
|
886
970
|
catch (error) {
|
|
887
971
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
888
972
|
logger.error(`[ToolManager] Data enrichment failed for ${config.id}: ${errorMessage}`);
|
|
889
|
-
throw new ToolExecutionError(`Data enrichment failed
|
|
973
|
+
throw new ToolExecutionError(`[ToolExecutionError] Data enrichment failed for tool "${config.id}": ${errorMessage}. ` +
|
|
974
|
+
`Check the enrichment handler and field references.`, config.id, { fields: config.fields }, error instanceof Error ? error : undefined);
|
|
890
975
|
}
|
|
891
976
|
}
|
|
892
977
|
};
|
|
@@ -901,7 +986,6 @@ export class ToolManager {
|
|
|
901
986
|
this.validateValidationConfig(config);
|
|
902
987
|
const tool = {
|
|
903
988
|
id: config.id,
|
|
904
|
-
name: config.name || `Validation: ${config.id}`,
|
|
905
989
|
description: config.description || `Validates data fields: ${config.fields.join(', ')}`,
|
|
906
990
|
parameters: {
|
|
907
991
|
type: 'object',
|
|
@@ -958,7 +1042,6 @@ export class ToolManager {
|
|
|
958
1042
|
this.validateApiCallConfig(config);
|
|
959
1043
|
const tool = {
|
|
960
1044
|
id: config.id,
|
|
961
|
-
name: config.name || `API Call: ${config.id}`,
|
|
962
1045
|
description: config.description || `Makes API call to external service`,
|
|
963
1046
|
parameters: {
|
|
964
1047
|
type: 'object',
|
|
@@ -1019,7 +1102,8 @@ export class ToolManager {
|
|
|
1019
1102
|
catch (error) {
|
|
1020
1103
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1021
1104
|
logger.error(`[ToolManager] API call failed for ${config.id}: ${errorMessage}`);
|
|
1022
|
-
throw new ToolExecutionError(`API call failed
|
|
1105
|
+
throw new ToolExecutionError(`[ToolExecutionError] API call failed for tool "${config.id}": ${errorMessage}. ` +
|
|
1106
|
+
`Check the endpoint URL, method, and network connectivity.`, config.id, { endpoint: config.endpoint, method: config.method, args }, error instanceof Error ? error : undefined);
|
|
1023
1107
|
}
|
|
1024
1108
|
}
|
|
1025
1109
|
};
|
|
@@ -1034,7 +1118,6 @@ export class ToolManager {
|
|
|
1034
1118
|
this.validateComputationConfig(config);
|
|
1035
1119
|
const tool = {
|
|
1036
1120
|
id: config.id,
|
|
1037
|
-
name: config.name || `Computation: ${config.id}`,
|
|
1038
1121
|
description: config.description || `Performs computation on inputs: ${config.inputs.join(', ')}`,
|
|
1039
1122
|
parameters: {
|
|
1040
1123
|
type: 'object',
|
|
@@ -1066,7 +1149,8 @@ export class ToolManager {
|
|
|
1066
1149
|
catch (error) {
|
|
1067
1150
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1068
1151
|
logger.error(`[ToolManager] Computation failed for ${config.id}: ${errorMessage}`);
|
|
1069
|
-
throw new ToolExecutionError(`Computation failed
|
|
1152
|
+
throw new ToolExecutionError(`[ToolExecutionError] Computation failed for tool "${config.id}": ${errorMessage}. ` +
|
|
1153
|
+
`Check the compute function and input field references.`, config.id, { inputs: config.inputs, args }, error instanceof Error ? error : undefined);
|
|
1070
1154
|
}
|
|
1071
1155
|
}
|
|
1072
1156
|
};
|
|
@@ -1075,8 +1159,8 @@ export class ToolManager {
|
|
|
1075
1159
|
/**
|
|
1076
1160
|
* Get detailed information about a tool for debugging
|
|
1077
1161
|
*/
|
|
1078
|
-
getToolInfo(toolId, scope, step,
|
|
1079
|
-
const tool = this.find(toolId, scope, step,
|
|
1162
|
+
getToolInfo(toolId, scope, step, flow) {
|
|
1163
|
+
const tool = this.find(toolId, scope, step, flow);
|
|
1080
1164
|
if (!tool) {
|
|
1081
1165
|
return { found: false };
|
|
1082
1166
|
}
|
|
@@ -1085,20 +1169,20 @@ export class ToolManager {
|
|
|
1085
1169
|
// Check step scope
|
|
1086
1170
|
if (step?.tools) {
|
|
1087
1171
|
const stepTool = step.tools.find((t) => (typeof t === 'string' && t === toolId) ||
|
|
1088
|
-
(typeof t === 'object' && (t.id === toolId
|
|
1172
|
+
(typeof t === 'object' && (t.id === toolId)));
|
|
1089
1173
|
if (stepTool)
|
|
1090
1174
|
foundScope = 'step';
|
|
1091
1175
|
}
|
|
1092
1176
|
// Check route scope
|
|
1093
|
-
if (foundScope === 'unknown' &&
|
|
1094
|
-
const
|
|
1095
|
-
if (
|
|
1096
|
-
foundScope = '
|
|
1177
|
+
if (foundScope === 'unknown' && flow?.tools) {
|
|
1178
|
+
const flowTool = flow.tools.find((t) => t.id === toolId);
|
|
1179
|
+
if (flowTool)
|
|
1180
|
+
foundScope = 'flow';
|
|
1097
1181
|
}
|
|
1098
1182
|
// Check agent scope
|
|
1099
1183
|
if (foundScope === 'unknown' && this.agent) {
|
|
1100
|
-
const agentTools = this.agent.
|
|
1101
|
-
const agentTool = agentTools.find((t) => t.id === toolId
|
|
1184
|
+
const agentTools = this.agent.tools;
|
|
1185
|
+
const agentTool = agentTools.find((t) => t.id === toolId);
|
|
1102
1186
|
if (agentTool)
|
|
1103
1187
|
foundScope = 'agent';
|
|
1104
1188
|
}
|
|
@@ -1112,7 +1196,6 @@ export class ToolManager {
|
|
|
1112
1196
|
scope: foundScope,
|
|
1113
1197
|
metadata: {
|
|
1114
1198
|
id: tool.id,
|
|
1115
|
-
name: tool.name,
|
|
1116
1199
|
hasDescription: !!tool.description,
|
|
1117
1200
|
hasParameters: !!tool.parameters,
|
|
1118
1201
|
handlerLength: tool.handler.length
|
|
@@ -1122,12 +1205,12 @@ export class ToolManager {
|
|
|
1122
1205
|
/**
|
|
1123
1206
|
* Validate that all tools in a list exist and are accessible
|
|
1124
1207
|
*/
|
|
1125
|
-
validateToolReferences(toolIds, step,
|
|
1208
|
+
validateToolReferences(toolIds, step, flow) {
|
|
1126
1209
|
const missing = [];
|
|
1127
1210
|
const found = [];
|
|
1128
1211
|
const details = [];
|
|
1129
1212
|
for (const toolId of toolIds) {
|
|
1130
|
-
const info = this.getToolInfo(toolId, ToolScope.ALL, step,
|
|
1213
|
+
const info = this.getToolInfo(toolId, ToolScope.ALL, step, flow);
|
|
1131
1214
|
if (info.found) {
|
|
1132
1215
|
found.push(toolId);
|
|
1133
1216
|
details.push({ id: toolId, found: true, scope: info.scope });
|