@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/src/core/ToolManager.ts
CHANGED
|
@@ -14,13 +14,13 @@ import type {
|
|
|
14
14
|
ToolContext,
|
|
15
15
|
ToolCallRequest,
|
|
16
16
|
ToolExecutionUpdate,
|
|
17
|
-
EnhancedTool,
|
|
18
17
|
Event,
|
|
19
18
|
} from "../types";
|
|
19
|
+
import type { Directive } from "../types/flow";
|
|
20
20
|
import { ToolScope } from "../types";
|
|
21
21
|
import { logger } from "../utils";
|
|
22
22
|
import { Agent } from "./Agent";
|
|
23
|
-
import {
|
|
23
|
+
import { Flow } from "./Flow";
|
|
24
24
|
import { Step } from "./Step";
|
|
25
25
|
import { StreamingToolExecutor } from "./StreamingToolExecutor";
|
|
26
26
|
|
|
@@ -61,10 +61,63 @@ export class ToolExecutionError extends Error {
|
|
|
61
61
|
export class ToolManager<TContext = unknown, TData = unknown> {
|
|
62
62
|
private toolRegistry: Map<string, Tool<TContext, TData>>;
|
|
63
63
|
|
|
64
|
+
/**
|
|
65
|
+
* Per-turn transient tool layer populated from PreDirective.injectTools.
|
|
66
|
+
* Resolution order: transient → step → flow → agent.
|
|
67
|
+
* Drained at end of turn via try/finally guard.
|
|
68
|
+
*
|
|
69
|
+
* Tools are deduplicated by `id` with last-definition-wins when
|
|
70
|
+
* multiple pre-LLM emitters contribute tools in the same turn.
|
|
71
|
+
*/
|
|
72
|
+
private transientTools: Map<string, Tool<TContext, TData>> = new Map();
|
|
73
|
+
|
|
64
74
|
constructor(private agent: Agent<TContext, TData>) {
|
|
65
75
|
this.toolRegistry = new Map();
|
|
66
76
|
}
|
|
67
77
|
|
|
78
|
+
/**
|
|
79
|
+
* Set the transient tool layer for the current turn.
|
|
80
|
+
*
|
|
81
|
+
* Accepts the merged `injectTools` array from pre-LLM emitters
|
|
82
|
+
* (already concatenated in outer-to-inner order by the DirectiveBus).
|
|
83
|
+
* Deduplicates by tool `id` with last-definition-wins.
|
|
84
|
+
*
|
|
85
|
+
* Must be paired with `clearTransientTools()` in a try/finally guard
|
|
86
|
+
* so the layer is drained even on abnormal termination.
|
|
87
|
+
*/
|
|
88
|
+
setTransientTools(tools: Tool<TContext, TData>[]): void {
|
|
89
|
+
this.transientTools.clear();
|
|
90
|
+
for (const tool of tools) {
|
|
91
|
+
this.transientTools.set(tool.id, tool);
|
|
92
|
+
}
|
|
93
|
+
if (this.transientTools.size > 0) {
|
|
94
|
+
logger.debug(
|
|
95
|
+
`[ToolManager] Set transient tools for turn: ${Array.from(this.transientTools.keys()).join(', ')}`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* Clear the transient tool layer. Called at end of turn via try/finally
|
|
102
|
+
* guard so tools do not leak into subsequent turns.
|
|
103
|
+
*/
|
|
104
|
+
clearTransientTools(): void {
|
|
105
|
+
if (this.transientTools.size > 0) {
|
|
106
|
+
logger.debug(
|
|
107
|
+
`[ToolManager] Cleared transient tools: ${Array.from(this.transientTools.keys()).join(', ')}`
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
this.transientTools.clear();
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Check whether the transient layer currently has any tools.
|
|
115
|
+
* Useful for testing and debugging.
|
|
116
|
+
*/
|
|
117
|
+
hasTransientTools(): boolean {
|
|
118
|
+
return this.transientTools.size > 0;
|
|
119
|
+
}
|
|
120
|
+
|
|
68
121
|
/**
|
|
69
122
|
* Validate a tool definition for completeness and correctness
|
|
70
123
|
*/
|
|
@@ -86,11 +139,6 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
86
139
|
errors.push('Tool handler is required and must be a function');
|
|
87
140
|
}
|
|
88
141
|
|
|
89
|
-
// Optional fields validation
|
|
90
|
-
if (definition.name !== undefined && (typeof definition.name !== 'string' || definition.name.trim() === '')) {
|
|
91
|
-
errors.push('Tool name must be a non-empty string if provided');
|
|
92
|
-
}
|
|
93
|
-
|
|
94
142
|
if (definition.description !== undefined && (typeof definition.description !== 'string' || definition.description.trim() === '')) {
|
|
95
143
|
errors.push('Tool description must be a non-empty string if provided');
|
|
96
144
|
}
|
|
@@ -117,7 +165,8 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
117
165
|
|
|
118
166
|
if (errors.length > 0) {
|
|
119
167
|
throw new ToolCreationError(
|
|
120
|
-
`Tool definition validation failed: ${errors.join('; ')}
|
|
168
|
+
`[ToolCreationError] Tool definition validation failed for "${definition.id || 'unknown'}": ${errors.join('; ')}. ` +
|
|
169
|
+
`Fix the tool definition to meet the required schema.`,
|
|
121
170
|
definition.id || 'unknown'
|
|
122
171
|
);
|
|
123
172
|
}
|
|
@@ -141,7 +190,8 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
141
190
|
|
|
142
191
|
if (errors.length > 0) {
|
|
143
192
|
throw new ToolCreationError(
|
|
144
|
-
`Data enrichment
|
|
193
|
+
`[ToolCreationError] Data enrichment config validation failed for "${config.id || 'unknown'}": ${errors.join('; ')}. ` +
|
|
194
|
+
`Fix the enrichment config to satisfy the required fields.`,
|
|
145
195
|
config.id || 'unknown'
|
|
146
196
|
);
|
|
147
197
|
}
|
|
@@ -165,7 +215,8 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
165
215
|
|
|
166
216
|
if (errors.length > 0) {
|
|
167
217
|
throw new ToolCreationError(
|
|
168
|
-
`Validation
|
|
218
|
+
`[ToolCreationError] Validation config validation failed for "${config.id || 'unknown'}": ${errors.join('; ')}. ` +
|
|
219
|
+
`Fix the validation config to satisfy the required fields.`,
|
|
169
220
|
config.id || 'unknown'
|
|
170
221
|
);
|
|
171
222
|
}
|
|
@@ -203,7 +254,8 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
203
254
|
|
|
204
255
|
if (errors.length > 0) {
|
|
205
256
|
throw new ToolCreationError(
|
|
206
|
-
`API call
|
|
257
|
+
`[ToolCreationError] API call config validation failed for "${config.id || 'unknown'}": ${errors.join('; ')}. ` +
|
|
258
|
+
`Fix the API call config to satisfy the required fields.`,
|
|
207
259
|
config.id || 'unknown'
|
|
208
260
|
);
|
|
209
261
|
}
|
|
@@ -227,7 +279,8 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
227
279
|
|
|
228
280
|
if (errors.length > 0) {
|
|
229
281
|
throw new ToolCreationError(
|
|
230
|
-
`Computation
|
|
282
|
+
`[ToolCreationError] Computation config validation failed for "${config.id || 'unknown'}": ${errors.join('; ')}. ` +
|
|
283
|
+
`Fix the computation config to satisfy the required fields.`,
|
|
231
284
|
config.id || 'unknown'
|
|
232
285
|
);
|
|
233
286
|
}
|
|
@@ -248,7 +301,8 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
248
301
|
return definition;
|
|
249
302
|
} catch (error) {
|
|
250
303
|
throw new ToolCreationError(
|
|
251
|
-
`Failed to create tool
|
|
304
|
+
`[ToolCreationError] Failed to create tool "${definition.id}": ${error instanceof Error ? error.message : String(error)}. ` +
|
|
305
|
+
`Ensure the tool definition passes validation.`,
|
|
252
306
|
definition.id,
|
|
253
307
|
error instanceof Error ? error : undefined
|
|
254
308
|
);
|
|
@@ -264,29 +318,35 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
264
318
|
): Tool<TContext, TData> {
|
|
265
319
|
try {
|
|
266
320
|
if (!tool) {
|
|
267
|
-
throw new ToolCreationError(
|
|
321
|
+
throw new ToolCreationError(
|
|
322
|
+
'[ToolCreationError] Tool registration failed: no tool provided. Pass a valid tool object with id and handler.',
|
|
323
|
+
'unknown'
|
|
324
|
+
);
|
|
268
325
|
}
|
|
269
326
|
|
|
270
327
|
if (!('handler' in tool) || typeof tool.handler !== 'function') {
|
|
271
328
|
throw new ToolCreationError(
|
|
272
|
-
|
|
329
|
+
`[ToolCreationError] Invalid tool for registration: tool "${tool?.id || 'unknown'}" must have a handler function. Add a handler property.`,
|
|
273
330
|
tool?.id || 'unknown'
|
|
274
331
|
);
|
|
275
332
|
}
|
|
276
333
|
|
|
277
334
|
// Validate the tool
|
|
278
335
|
if (!tool.id || typeof tool.id !== 'string' || tool.id.trim() === '') {
|
|
279
|
-
throw new ToolCreationError(
|
|
336
|
+
throw new ToolCreationError(
|
|
337
|
+
'[ToolCreationError] Tool ID missing: tool ID is required and must be a non-empty string. Provide a unique string id.',
|
|
338
|
+
tool.id || 'unknown'
|
|
339
|
+
);
|
|
280
340
|
}
|
|
281
341
|
|
|
282
342
|
// Check for ID conflicts and provide better error context
|
|
283
343
|
if (this.toolRegistry.has(tool.id)) {
|
|
284
344
|
const existingTool = this.toolRegistry.get(tool.id);
|
|
285
|
-
logger.warn(`[ToolManager] Overwriting existing registered tool: ${tool.id} (previous: ${existingTool?.
|
|
345
|
+
logger.warn(`[ToolManager] Overwriting existing registered tool: ${tool.id} (previous: ${existingTool?.id || 'unnamed'})`);
|
|
286
346
|
}
|
|
287
347
|
|
|
288
348
|
this.toolRegistry.set(tool.id, tool);
|
|
289
|
-
logger.debug(`[ToolManager] Registered tool: ${tool.id} (${tool.
|
|
349
|
+
logger.debug(`[ToolManager] Registered tool: ${tool.id} (${tool.id || 'unnamed'})`);
|
|
290
350
|
|
|
291
351
|
return tool;
|
|
292
352
|
} catch (error) {
|
|
@@ -296,7 +356,8 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
296
356
|
|
|
297
357
|
const toolId = tool?.id || 'unknown';
|
|
298
358
|
throw new ToolCreationError(
|
|
299
|
-
`Failed to register tool
|
|
359
|
+
`[ToolCreationError] Failed to register tool "${toolId}": ${error instanceof Error ? error.message : String(error)}. ` +
|
|
360
|
+
`Ensure the tool object is valid and has id + handler.`,
|
|
300
361
|
toolId,
|
|
301
362
|
error instanceof Error ? error : undefined
|
|
302
363
|
);
|
|
@@ -343,22 +404,22 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
343
404
|
/**
|
|
344
405
|
* Get tool by ID from a specific scope
|
|
345
406
|
*/
|
|
346
|
-
getFromScope(toolId: string, scope: ToolScope, step?: Step<TContext, TData>,
|
|
347
|
-
return this.find(toolId, scope, step,
|
|
407
|
+
getFromScope(toolId: string, scope: ToolScope, step?: Step<TContext, TData>, flow?: Flow<TContext, TData>): Tool<TContext, TData> | undefined {
|
|
408
|
+
return this.find(toolId, scope, step, flow);
|
|
348
409
|
}
|
|
349
410
|
|
|
350
411
|
/**
|
|
351
412
|
* Check if a tool exists in any scope
|
|
352
413
|
*/
|
|
353
|
-
exists(toolId: string, step?: Step<TContext, TData>,
|
|
354
|
-
return this.find(toolId, ToolScope.ALL, step,
|
|
414
|
+
exists(toolId: string, step?: Step<TContext, TData>, flow?: Flow<TContext, TData>): boolean {
|
|
415
|
+
return this.find(toolId, ToolScope.ALL, step, flow) !== undefined;
|
|
355
416
|
}
|
|
356
417
|
|
|
357
418
|
/**
|
|
358
419
|
* Get tool count by scope
|
|
359
420
|
*/
|
|
360
|
-
getToolCount(scope?: ToolScope, step?: Step<TContext, TData>,
|
|
361
|
-
return this.getAvailable(scope, step,
|
|
421
|
+
getToolCount(scope?: ToolScope, step?: Step<TContext, TData>, flow?: Flow<TContext, TData>): number {
|
|
422
|
+
return this.getAvailable(scope, step, flow).length;
|
|
362
423
|
}
|
|
363
424
|
|
|
364
425
|
/**
|
|
@@ -389,7 +450,11 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
389
450
|
): Tool<TContext, TData> {
|
|
390
451
|
// Validate tool before adding
|
|
391
452
|
if (!tool || !tool.id || !tool.handler) {
|
|
392
|
-
throw new ToolCreationError(
|
|
453
|
+
throw new ToolCreationError(
|
|
454
|
+
`[ToolCreationError] Invalid tool for addToAgent: tool must have id and handler properties. ` +
|
|
455
|
+
`Provide a complete tool object with { id, handler, ... }.`,
|
|
456
|
+
tool?.id || 'unknown'
|
|
457
|
+
);
|
|
393
458
|
}
|
|
394
459
|
|
|
395
460
|
// Add to agent's tools array using the unified interface
|
|
@@ -404,38 +469,47 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
404
469
|
}
|
|
405
470
|
|
|
406
471
|
/**
|
|
407
|
-
* Add a tool to a specific
|
|
472
|
+
* Add a tool to a specific flow scope (creates and adds in one operation)
|
|
408
473
|
*/
|
|
409
|
-
|
|
410
|
-
|
|
474
|
+
addToFlow(
|
|
475
|
+
flow: Flow<TContext, TData>,
|
|
411
476
|
tool: Tool<TContext, TData>
|
|
412
477
|
): Tool<TContext, TData> {
|
|
413
|
-
// Add to
|
|
414
|
-
if (
|
|
415
|
-
|
|
478
|
+
// Add to flow's tools array using the existing createTool method
|
|
479
|
+
if (flow && typeof flow.createTool === 'function') {
|
|
480
|
+
flow.createTool(tool);
|
|
416
481
|
} else {
|
|
417
|
-
logger.warn(`[ToolManager]
|
|
482
|
+
logger.warn(`[ToolManager] Flow does not support createTool method, tool not added to flow scope: ${tool.id}`);
|
|
418
483
|
}
|
|
419
484
|
|
|
420
|
-
logger.debug(`[ToolManager] Added tool to
|
|
485
|
+
logger.debug(`[ToolManager] Added tool to flow scope: ${tool.id}`);
|
|
421
486
|
return tool;
|
|
422
487
|
}
|
|
423
488
|
|
|
424
489
|
/**
|
|
425
490
|
* Find a tool by ID across different scopes with enhanced resolution logic
|
|
426
|
-
* Priority: step →
|
|
491
|
+
* Priority: transient → step → flow → agent → registry
|
|
427
492
|
* Supports both ID and name matching for better compatibility
|
|
428
493
|
*/
|
|
429
|
-
find(toolId: string, scope?: ToolScope, step?: Step<TContext, TData>,
|
|
494
|
+
find(toolId: string, scope?: ToolScope, step?: Step<TContext, TData>, flow?: Flow<TContext, TData>): Tool<TContext, TData> | undefined {
|
|
430
495
|
logger.debug(`[ToolManager] Finding tool: ${toolId} with scope: ${scope || 'ALL'}`);
|
|
431
496
|
|
|
432
|
-
// Check
|
|
497
|
+
// Check transient tools first (highest priority — per-turn injectTools)
|
|
498
|
+
if (!scope || scope === ToolScope.ALL) {
|
|
499
|
+
const transientTool = this.transientTools.get(toolId);
|
|
500
|
+
if (transientTool) {
|
|
501
|
+
logger.debug(`[ToolManager] Found tool in transient scope: ${toolId}`);
|
|
502
|
+
return transientTool;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
|
|
506
|
+
// Check step-level tools (if step provided and scope allows)
|
|
433
507
|
if (step && (!scope || scope === ToolScope.STEP || scope === ToolScope.ALL)) {
|
|
434
508
|
if (step.tools) {
|
|
435
509
|
for (const toolRef of step.tools) {
|
|
436
510
|
if (typeof toolRef !== 'string') {
|
|
437
511
|
// Inline tool object - check both id and name
|
|
438
|
-
if (toolRef.id === toolId
|
|
512
|
+
if (toolRef.id === toolId) {
|
|
439
513
|
logger.debug(`[ToolManager] Found tool in step scope: ${toolId}`);
|
|
440
514
|
return toolRef;
|
|
441
515
|
}
|
|
@@ -453,13 +527,13 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
453
527
|
}
|
|
454
528
|
}
|
|
455
529
|
|
|
456
|
-
// Check
|
|
457
|
-
if (
|
|
458
|
-
if (
|
|
459
|
-
const
|
|
460
|
-
if (
|
|
461
|
-
logger.debug(`[ToolManager] Found tool in
|
|
462
|
-
return
|
|
530
|
+
// Check flow-level tools (if route provided and scope allows)
|
|
531
|
+
if (flow && (!scope || scope === ToolScope.FLOW || scope === ToolScope.ALL)) {
|
|
532
|
+
if (flow.tools) {
|
|
533
|
+
const flowTool = flow.tools.find((t) => t.id === toolId);
|
|
534
|
+
if (flowTool) {
|
|
535
|
+
logger.debug(`[ToolManager] Found tool in flow scope: ${toolId}`);
|
|
536
|
+
return flowTool;
|
|
463
537
|
}
|
|
464
538
|
}
|
|
465
539
|
}
|
|
@@ -468,7 +542,7 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
468
542
|
if (!scope || scope === ToolScope.AGENT || scope === ToolScope.ALL) {
|
|
469
543
|
if (this.agent) {
|
|
470
544
|
const agentTools = this.agent.getTools();
|
|
471
|
-
const agentTool = agentTools.find((t) => t.id === toolId
|
|
545
|
+
const agentTool = agentTools.find((t) => t.id === toolId);
|
|
472
546
|
if (agentTool) {
|
|
473
547
|
logger.debug(`[ToolManager] Found tool in agent scope: ${toolId}`);
|
|
474
548
|
return agentTool;
|
|
@@ -486,7 +560,7 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
486
560
|
|
|
487
561
|
// Also check by name in registry
|
|
488
562
|
for (const [id, tool] of Array.from(this.toolRegistry.entries())) {
|
|
489
|
-
if (tool.
|
|
563
|
+
if (tool.id === toolId) {
|
|
490
564
|
logger.debug(`[ToolManager] Found tool in registry by name: ${toolId} (id: ${id})`);
|
|
491
565
|
return tool;
|
|
492
566
|
}
|
|
@@ -500,8 +574,9 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
500
574
|
/**
|
|
501
575
|
* Get available tools for current context with enhanced resolution and deduplication
|
|
502
576
|
* Returns tools in priority order with higher-priority scopes taking precedence
|
|
577
|
+
* Resolution order: transient → step → flow → agent → registry
|
|
503
578
|
*/
|
|
504
|
-
getAvailable(scope?: ToolScope, step?: Step<TContext, TData>,
|
|
579
|
+
getAvailable(scope?: ToolScope, step?: Step<TContext, TData>, flow?: Flow<TContext, TData>): Tool<TContext, TData>[] {
|
|
505
580
|
const toolMap = new Map<string, Tool<TContext, TData>>();
|
|
506
581
|
const resolvedTools: Tool<TContext, TData>[] = [];
|
|
507
582
|
|
|
@@ -527,16 +602,16 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
527
602
|
}
|
|
528
603
|
|
|
529
604
|
// Add route-level tools (override agent and registered tools with same ID)
|
|
530
|
-
if (
|
|
531
|
-
if (
|
|
532
|
-
for (const tool of
|
|
605
|
+
if (flow && (!scope || scope === ToolScope.FLOW || scope === ToolScope.ALL)) {
|
|
606
|
+
if (flow.tools) {
|
|
607
|
+
for (const tool of flow.tools) {
|
|
533
608
|
toolMap.set(tool.id, tool);
|
|
534
609
|
}
|
|
535
|
-
logger.debug(`[ToolManager] Added ${
|
|
610
|
+
logger.debug(`[ToolManager] Added ${flow.tools.length} flow.tools`);
|
|
536
611
|
}
|
|
537
612
|
}
|
|
538
613
|
|
|
539
|
-
// Add step-level tools (
|
|
614
|
+
// Add step-level tools (override flow/agent/registry with same ID)
|
|
540
615
|
if (step && (!scope || scope === ToolScope.STEP || scope === ToolScope.ALL)) {
|
|
541
616
|
if (step.tools) {
|
|
542
617
|
for (const toolRef of step.tools) {
|
|
@@ -551,7 +626,7 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
551
626
|
toolMap.set(registeredTool.id, registeredTool);
|
|
552
627
|
resolvedTools.push(registeredTool);
|
|
553
628
|
} else {
|
|
554
|
-
logger.warn(`[
|
|
629
|
+
logger.warn(`[ToolExecutionError] Step references unknown tool: "${toolRef}" is not registered. Skipping. Register the tool or remove the reference.`);
|
|
555
630
|
}
|
|
556
631
|
}
|
|
557
632
|
}
|
|
@@ -559,15 +634,28 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
559
634
|
}
|
|
560
635
|
}
|
|
561
636
|
|
|
637
|
+
// Add transient tools (highest priority — override everything with same ID)
|
|
638
|
+
if (!scope || scope === ToolScope.ALL) {
|
|
639
|
+
if (this.transientTools.size > 0) {
|
|
640
|
+
for (const [id, tool] of this.transientTools) {
|
|
641
|
+
toolMap.set(id, tool);
|
|
642
|
+
}
|
|
643
|
+
logger.debug(`[ToolManager] Added ${this.transientTools.size} transient tools`);
|
|
644
|
+
}
|
|
645
|
+
}
|
|
646
|
+
|
|
562
647
|
// Convert map to array, preserving priority order
|
|
563
648
|
const allTools = Array.from(toolMap.values());
|
|
564
649
|
|
|
565
|
-
// If we have step-specific tools, prioritize them
|
|
650
|
+
// If we have step-specific tools, prioritize them in the ordering
|
|
651
|
+
// (but transient tools that override step tools via same ID are already in the map)
|
|
566
652
|
if (resolvedTools.length > 0) {
|
|
567
653
|
// Add resolved step tools first, then other tools not already included
|
|
568
654
|
const stepToolIds = new Set(resolvedTools.map(t => t.id));
|
|
569
655
|
const otherTools = allTools.filter(t => !stepToolIds.has(t.id));
|
|
570
|
-
|
|
656
|
+
// For step tools, use the map version (which may be overridden by transient)
|
|
657
|
+
const finalStepTools = resolvedTools.map(t => toolMap.get(t.id) || t);
|
|
658
|
+
return [...finalStepTools, ...otherTools];
|
|
571
659
|
}
|
|
572
660
|
|
|
573
661
|
logger.debug(`[ToolManager] Returning ${allTools.length} available tools`);
|
|
@@ -583,7 +671,7 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
583
671
|
args?: Record<string, unknown>,
|
|
584
672
|
context?: {
|
|
585
673
|
step?: Step<TContext, TData>;
|
|
586
|
-
|
|
674
|
+
flow?: Flow<TContext, TData>;
|
|
587
675
|
context?: TContext;
|
|
588
676
|
data?: Partial<TData>;
|
|
589
677
|
history?: Event[];
|
|
@@ -609,7 +697,7 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
609
697
|
// Try primary tool with retries
|
|
610
698
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
611
699
|
try {
|
|
612
|
-
const tool = this.find(toolId, undefined, context?.step, context?.
|
|
700
|
+
const tool = this.find(toolId, undefined, context?.step, context?.flow);
|
|
613
701
|
if (!tool) {
|
|
614
702
|
// Tool not found - try fallback tools if available
|
|
615
703
|
if (fallbackTools.length > 0) {
|
|
@@ -730,7 +818,8 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
730
818
|
|
|
731
819
|
// All attempts and fallbacks failed
|
|
732
820
|
throw new ToolExecutionError(
|
|
733
|
-
`Tool execution failed
|
|
821
|
+
`[ToolExecutionError] Tool "${toolId}" execution failed: all ${maxRetries + 1} attempts exhausted${fallbackTools.length > 0 ? ` and fallback tools [${fallbackTools.join(', ')}] also failed` : ''}. ` +
|
|
822
|
+
`Check the tool handler for errors or increase maxRetries. Last error: ${lastError?.message || 'Unknown'}.`,
|
|
734
823
|
toolId,
|
|
735
824
|
{ args, context, attempts: maxRetries + 1, fallbackTools },
|
|
736
825
|
lastError
|
|
@@ -785,6 +874,8 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
785
874
|
}
|
|
786
875
|
|
|
787
876
|
// Build tool context with complete agent data
|
|
877
|
+
const collectedDirectives: Directive<TContext, TData>[] = [];
|
|
878
|
+
|
|
788
879
|
const toolContext: ToolContext<TContext, TData> = {
|
|
789
880
|
context,
|
|
790
881
|
updateContext,
|
|
@@ -801,18 +892,20 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
801
892
|
},
|
|
802
893
|
hasField: <K extends keyof TData>(key: K): boolean => {
|
|
803
894
|
return data != null && key in data;
|
|
895
|
+
},
|
|
896
|
+
dispatch: (directive: Directive<TContext, TData>): void => {
|
|
897
|
+
collectedDirectives.push(directive);
|
|
804
898
|
}
|
|
805
899
|
};
|
|
806
900
|
|
|
807
901
|
logger.debug(`[ToolManager] Executing tool: ${tool.id} with args:`, toolArguments);
|
|
808
902
|
|
|
809
|
-
//
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
const validation = await enhanced.validateInput(toolArguments, toolContext);
|
|
903
|
+
// Tool validation gate (Req 6.1, 6.7)
|
|
904
|
+
if (typeof tool.validateInput === 'function' && toolArguments) {
|
|
905
|
+
const validation = await tool.validateInput(toolArguments, toolContext);
|
|
813
906
|
if (!validation.valid) {
|
|
814
907
|
const executionTime = Date.now() - startTime;
|
|
815
|
-
logger.warn(`[
|
|
908
|
+
logger.warn(`[DataValidationError] Tool "${tool.id}" input validation failed: ${validation.error}. Fix the tool call arguments to match the expected schema.`);
|
|
816
909
|
return {
|
|
817
910
|
success: false,
|
|
818
911
|
error: `Validation failed: ${validation.error || 'Invalid input'}`,
|
|
@@ -821,12 +914,13 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
821
914
|
}
|
|
822
915
|
}
|
|
823
916
|
|
|
824
|
-
//
|
|
825
|
-
|
|
826
|
-
|
|
917
|
+
// Tool permission gate (Req 6.7, 6.8)
|
|
918
|
+
// When denied: do not invoke handler, do not process directives, do not apply state writes
|
|
919
|
+
if (typeof tool.checkPermissions === 'function' && toolArguments) {
|
|
920
|
+
const permission = await tool.checkPermissions(toolArguments, toolContext);
|
|
827
921
|
if (!permission.allowed) {
|
|
828
922
|
const executionTime = Date.now() - startTime;
|
|
829
|
-
logger.warn(`[
|
|
923
|
+
logger.warn(`[ToolExecutionError] Tool "${tool.id}" permission denied: ${permission.reason}. The tool's checkPermissions hook rejected this call.`);
|
|
830
924
|
return {
|
|
831
925
|
success: false,
|
|
832
926
|
error: `Permission denied: ${permission.reason || 'Not allowed'}`,
|
|
@@ -857,7 +951,7 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
857
951
|
// Handle different result types
|
|
858
952
|
let toolResult: ToolResult<unknown, TContext, TData>;
|
|
859
953
|
|
|
860
|
-
if (result && typeof result === 'object' && ('data' in result || 'success' in result || 'error' in result)) {
|
|
954
|
+
if (result && typeof result === 'object' && ('data' in result || 'success' in result || 'error' in result || 'directive' in result)) {
|
|
861
955
|
// It's already a ToolResult-like object
|
|
862
956
|
toolResult = result as ToolResult<unknown, TContext, TData>;
|
|
863
957
|
} else {
|
|
@@ -868,13 +962,18 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
868
962
|
};
|
|
869
963
|
}
|
|
870
964
|
|
|
965
|
+
// Collect directive from ToolResult.directive (if present)
|
|
966
|
+
if (toolResult.directive) {
|
|
967
|
+
collectedDirectives.push(toolResult.directive);
|
|
968
|
+
}
|
|
969
|
+
|
|
871
970
|
// Apply data updates from tool result with validation
|
|
872
971
|
if (toolResult.dataUpdate) {
|
|
873
972
|
try {
|
|
874
973
|
if (typeof toolResult.dataUpdate === 'object' && toolResult.dataUpdate !== null) {
|
|
875
974
|
await updateData(toolResult.dataUpdate);
|
|
876
975
|
} else {
|
|
877
|
-
logger.warn(`[
|
|
976
|
+
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.`);
|
|
878
977
|
}
|
|
879
978
|
} catch (updateError) {
|
|
880
979
|
logger.error(`[ToolManager] Failed to apply data update from tool ${tool.id}:`, updateError);
|
|
@@ -892,7 +991,7 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
892
991
|
if (typeof toolResult.contextUpdate === 'object' && toolResult.contextUpdate !== null) {
|
|
893
992
|
await updateContext(toolResult.contextUpdate);
|
|
894
993
|
} else {
|
|
895
|
-
logger.warn(`[
|
|
994
|
+
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.`);
|
|
896
995
|
}
|
|
897
996
|
} catch (updateError) {
|
|
898
997
|
logger.error(`[ToolManager] Failed to apply context update from tool ${tool.id}:`, updateError);
|
|
@@ -911,9 +1010,10 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
911
1010
|
contextUpdate: toolResult.contextUpdate,
|
|
912
1011
|
dataUpdate: toolResult.dataUpdate,
|
|
913
1012
|
error: toolResult.error,
|
|
1013
|
+
directives: collectedDirectives.length > 0 ? collectedDirectives : undefined,
|
|
914
1014
|
metadata: {
|
|
915
1015
|
toolId: tool.id,
|
|
916
|
-
toolName: tool.
|
|
1016
|
+
toolName: tool.id,
|
|
917
1017
|
executionTime,
|
|
918
1018
|
...(toolResult.meta || {})
|
|
919
1019
|
}
|
|
@@ -988,10 +1088,10 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
988
1088
|
data?: Partial<TData>;
|
|
989
1089
|
history?: Event[];
|
|
990
1090
|
signal?: AbortSignal;
|
|
991
|
-
|
|
1091
|
+
flow?: Flow<TContext, TData>;
|
|
992
1092
|
step?: Step<TContext, TData>;
|
|
993
1093
|
}): AsyncGenerator<ToolExecutionUpdate<TData>> {
|
|
994
|
-
const { toolCalls, context, data, history, signal,
|
|
1094
|
+
const { toolCalls, context, data, history, signal, flow, step } = params;
|
|
995
1095
|
|
|
996
1096
|
if (toolCalls.length === 0) {
|
|
997
1097
|
return;
|
|
@@ -1002,7 +1102,7 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
1002
1102
|
context,
|
|
1003
1103
|
data: data || {} as Partial<TData>,
|
|
1004
1104
|
history: history || [],
|
|
1005
|
-
step: step ? { id: step.id,
|
|
1105
|
+
step: step ? { id: step.id, flowId: flow?.id || '' } : undefined,
|
|
1006
1106
|
updateContext: (updates: Partial<TContext>): Promise<void> => {
|
|
1007
1107
|
Object.assign(context as Record<string, unknown>, updates);
|
|
1008
1108
|
return Promise.resolve();
|
|
@@ -1025,6 +1125,11 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
1025
1125
|
hasField: <K extends keyof TData>(key: K): boolean => {
|
|
1026
1126
|
return data != null && key in (data as Record<string, unknown>);
|
|
1027
1127
|
},
|
|
1128
|
+
dispatch: (_directive: Directive<TContext, TData>): void => {
|
|
1129
|
+
// Directives from concurrent execution are collected by the StreamingToolExecutor
|
|
1130
|
+
// and surfaced via ToolExecutionUpdate. This is a no-op placeholder;
|
|
1131
|
+
// full directive bus integration happens in ResponsePipeline (task 1.6).
|
|
1132
|
+
},
|
|
1028
1133
|
};
|
|
1029
1134
|
|
|
1030
1135
|
const executor = new StreamingToolExecutor<TContext, TData>(toolContext, {
|
|
@@ -1033,13 +1138,13 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
1033
1138
|
|
|
1034
1139
|
// Resolve and queue each tool call
|
|
1035
1140
|
for (const toolCall of toolCalls) {
|
|
1036
|
-
const tool = this.find(toolCall.toolName, undefined, step,
|
|
1141
|
+
const tool = this.find(toolCall.toolName, undefined, step, flow);
|
|
1037
1142
|
if (!tool) {
|
|
1038
|
-
logger.warn(`[
|
|
1143
|
+
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.`);
|
|
1039
1144
|
continue;
|
|
1040
1145
|
}
|
|
1041
|
-
//
|
|
1042
|
-
executor.addTool(toolCall, tool
|
|
1146
|
+
// Tool carries all metadata fields directly — no cast needed
|
|
1147
|
+
executor.addTool(toolCall, tool);
|
|
1043
1148
|
}
|
|
1044
1149
|
|
|
1045
1150
|
// Yield all results in order
|
|
@@ -1058,7 +1163,6 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
1058
1163
|
|
|
1059
1164
|
const tool: Tool<TContext, TData, void> = {
|
|
1060
1165
|
id: config.id,
|
|
1061
|
-
name: config.name || `Data Enrichment: ${config.id}`,
|
|
1062
1166
|
description: config.description || `Enriches data fields: ${config.fields.join(', ')}`,
|
|
1063
1167
|
parameters: {
|
|
1064
1168
|
type: 'object',
|
|
@@ -1101,7 +1205,8 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
1101
1205
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1102
1206
|
logger.error(`[ToolManager] Data enrichment failed for ${config.id}: ${errorMessage}`);
|
|
1103
1207
|
throw new ToolExecutionError(
|
|
1104
|
-
`Data enrichment failed: ${errorMessage}
|
|
1208
|
+
`[ToolExecutionError] Data enrichment failed for tool "${config.id}": ${errorMessage}. ` +
|
|
1209
|
+
`Check the enrichment handler and field references.`,
|
|
1105
1210
|
config.id,
|
|
1106
1211
|
{ fields: config.fields },
|
|
1107
1212
|
error instanceof Error ? error : undefined
|
|
@@ -1125,7 +1230,6 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
1125
1230
|
|
|
1126
1231
|
const tool: Tool<TContext, TData, ValidationResult> = {
|
|
1127
1232
|
id: config.id,
|
|
1128
|
-
name: config.name || `Validation: ${config.id}`,
|
|
1129
1233
|
description: config.description || `Validates data fields: ${config.fields.join(', ')}`,
|
|
1130
1234
|
parameters: {
|
|
1131
1235
|
type: 'object',
|
|
@@ -1189,7 +1293,6 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
1189
1293
|
|
|
1190
1294
|
const tool: Tool<TContext, TData, TResult> = {
|
|
1191
1295
|
id: config.id,
|
|
1192
|
-
name: config.name || `API Call: ${config.id}`,
|
|
1193
1296
|
description: config.description || `Makes API call to external service`,
|
|
1194
1297
|
parameters: {
|
|
1195
1298
|
type: 'object',
|
|
@@ -1258,7 +1361,8 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
1258
1361
|
logger.error(`[ToolManager] API call failed for ${config.id}: ${errorMessage}`);
|
|
1259
1362
|
|
|
1260
1363
|
throw new ToolExecutionError(
|
|
1261
|
-
`API call failed: ${errorMessage}
|
|
1364
|
+
`[ToolExecutionError] API call failed for tool "${config.id}": ${errorMessage}. ` +
|
|
1365
|
+
`Check the endpoint URL, method, and network connectivity.`,
|
|
1262
1366
|
config.id,
|
|
1263
1367
|
{ endpoint: config.endpoint, method: config.method, args },
|
|
1264
1368
|
error instanceof Error ? error : undefined
|
|
@@ -1282,7 +1386,6 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
1282
1386
|
|
|
1283
1387
|
const tool: Tool<TContext, TData, TResult> = {
|
|
1284
1388
|
id: config.id,
|
|
1285
|
-
name: config.name || `Computation: ${config.id}`,
|
|
1286
1389
|
description: config.description || `Performs computation on inputs: ${config.inputs.join(', ')}`,
|
|
1287
1390
|
parameters: {
|
|
1288
1391
|
type: 'object',
|
|
@@ -1317,7 +1420,8 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
1317
1420
|
logger.error(`[ToolManager] Computation failed for ${config.id}: ${errorMessage}`);
|
|
1318
1421
|
|
|
1319
1422
|
throw new ToolExecutionError(
|
|
1320
|
-
`Computation failed: ${errorMessage}
|
|
1423
|
+
`[ToolExecutionError] Computation failed for tool "${config.id}": ${errorMessage}. ` +
|
|
1424
|
+
`Check the compute function and input field references.`,
|
|
1321
1425
|
config.id,
|
|
1322
1426
|
{ inputs: config.inputs, args },
|
|
1323
1427
|
error instanceof Error ? error : undefined
|
|
@@ -1332,13 +1436,13 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
1332
1436
|
/**
|
|
1333
1437
|
* Get detailed information about a tool for debugging
|
|
1334
1438
|
*/
|
|
1335
|
-
getToolInfo(toolId: string, scope?: ToolScope, step?: Step<TContext, TData>,
|
|
1439
|
+
getToolInfo(toolId: string, scope?: ToolScope, step?: Step<TContext, TData>, flow?: Flow<TContext, TData>): {
|
|
1336
1440
|
found: boolean;
|
|
1337
1441
|
tool?: Tool<TContext, TData>;
|
|
1338
1442
|
scope?: string;
|
|
1339
1443
|
metadata?: Record<string, unknown>;
|
|
1340
1444
|
} {
|
|
1341
|
-
const tool = this.find(toolId, scope, step,
|
|
1445
|
+
const tool = this.find(toolId, scope, step, flow);
|
|
1342
1446
|
|
|
1343
1447
|
if (!tool) {
|
|
1344
1448
|
return { found: false };
|
|
@@ -1351,21 +1455,21 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
1351
1455
|
if (step?.tools) {
|
|
1352
1456
|
const stepTool = step.tools.find((t) =>
|
|
1353
1457
|
(typeof t === 'string' && t === toolId) ||
|
|
1354
|
-
(typeof t === 'object' && (t.id === toolId
|
|
1458
|
+
(typeof t === 'object' && (t.id === toolId))
|
|
1355
1459
|
);
|
|
1356
1460
|
if (stepTool) foundScope = 'step';
|
|
1357
1461
|
}
|
|
1358
1462
|
|
|
1359
1463
|
// Check route scope
|
|
1360
|
-
if (foundScope === 'unknown' &&
|
|
1361
|
-
const
|
|
1362
|
-
if (
|
|
1464
|
+
if (foundScope === 'unknown' && flow?.tools) {
|
|
1465
|
+
const flowTool = flow.tools.find((t) => t.id === toolId);
|
|
1466
|
+
if (flowTool) foundScope = 'flow';
|
|
1363
1467
|
}
|
|
1364
1468
|
|
|
1365
1469
|
// Check agent scope
|
|
1366
1470
|
if (foundScope === 'unknown' && this.agent) {
|
|
1367
|
-
const agentTools = this.agent.
|
|
1368
|
-
const agentTool = agentTools.find((t) => t.id === toolId
|
|
1471
|
+
const agentTools = this.agent.tools;
|
|
1472
|
+
const agentTool = agentTools.find((t) => t.id === toolId);
|
|
1369
1473
|
if (agentTool) foundScope = 'agent';
|
|
1370
1474
|
}
|
|
1371
1475
|
|
|
@@ -1380,7 +1484,6 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
1380
1484
|
scope: foundScope,
|
|
1381
1485
|
metadata: {
|
|
1382
1486
|
id: tool.id,
|
|
1383
|
-
name: tool.name,
|
|
1384
1487
|
hasDescription: !!tool.description,
|
|
1385
1488
|
hasParameters: !!tool.parameters,
|
|
1386
1489
|
handlerLength: tool.handler.length
|
|
@@ -1391,7 +1494,7 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
1391
1494
|
/**
|
|
1392
1495
|
* Validate that all tools in a list exist and are accessible
|
|
1393
1496
|
*/
|
|
1394
|
-
validateToolReferences(toolIds: string[], step?: Step<TContext, TData>,
|
|
1497
|
+
validateToolReferences(toolIds: string[], step?: Step<TContext, TData>, flow?: Flow<TContext, TData>): {
|
|
1395
1498
|
valid: boolean;
|
|
1396
1499
|
missing: string[];
|
|
1397
1500
|
found: string[];
|
|
@@ -1402,7 +1505,7 @@ export class ToolManager<TContext = unknown, TData = unknown> {
|
|
|
1402
1505
|
const details: Array<{ id: string; found: boolean; scope?: string; }> = [];
|
|
1403
1506
|
|
|
1404
1507
|
for (const toolId of toolIds) {
|
|
1405
|
-
const info = this.getToolInfo(toolId, ToolScope.ALL, step,
|
|
1508
|
+
const info = this.getToolInfo(toolId, ToolScope.ALL, step, flow);
|
|
1406
1509
|
|
|
1407
1510
|
if (info.found) {
|
|
1408
1511
|
found.push(toolId);
|