@falai/agent 1.2.8 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +40 -886
- package/dist/adapters/MemoryAdapter.js +2 -2
- package/dist/adapters/MemoryAdapter.js.map +1 -1
- package/dist/adapters/MongoAdapter.js +2 -2
- package/dist/adapters/MongoAdapter.js.map +1 -1
- package/dist/adapters/OpenSearchAdapter.d.ts.map +1 -1
- package/dist/adapters/OpenSearchAdapter.js +9 -7
- package/dist/adapters/OpenSearchAdapter.js.map +1 -1
- package/dist/adapters/PostgreSQLAdapter.d.ts +14 -0
- package/dist/adapters/PostgreSQLAdapter.d.ts.map +1 -1
- package/dist/adapters/PostgreSQLAdapter.js +25 -9
- package/dist/adapters/PostgreSQLAdapter.js.map +1 -1
- package/dist/adapters/PrismaAdapter.js +5 -5
- package/dist/adapters/PrismaAdapter.js.map +1 -1
- package/dist/adapters/RedisAdapter.js +2 -2
- package/dist/adapters/RedisAdapter.js.map +1 -1
- package/dist/adapters/SQLiteAdapter.d.ts +17 -0
- package/dist/adapters/SQLiteAdapter.d.ts.map +1 -1
- package/dist/adapters/SQLiteAdapter.js +30 -11
- package/dist/adapters/SQLiteAdapter.js.map +1 -1
- package/dist/cjs/adapters/MemoryAdapter.js +2 -2
- package/dist/cjs/adapters/MemoryAdapter.js.map +1 -1
- package/dist/cjs/adapters/MongoAdapter.js +2 -2
- package/dist/cjs/adapters/MongoAdapter.js.map +1 -1
- package/dist/cjs/adapters/OpenSearchAdapter.d.ts.map +1 -1
- package/dist/cjs/adapters/OpenSearchAdapter.js +9 -7
- package/dist/cjs/adapters/OpenSearchAdapter.js.map +1 -1
- package/dist/cjs/adapters/PostgreSQLAdapter.d.ts +14 -0
- package/dist/cjs/adapters/PostgreSQLAdapter.d.ts.map +1 -1
- package/dist/cjs/adapters/PostgreSQLAdapter.js +25 -9
- package/dist/cjs/adapters/PostgreSQLAdapter.js.map +1 -1
- package/dist/cjs/adapters/PrismaAdapter.js +5 -5
- package/dist/cjs/adapters/PrismaAdapter.js.map +1 -1
- package/dist/cjs/adapters/RedisAdapter.js +2 -2
- package/dist/cjs/adapters/RedisAdapter.js.map +1 -1
- package/dist/cjs/adapters/SQLiteAdapter.d.ts +17 -0
- package/dist/cjs/adapters/SQLiteAdapter.d.ts.map +1 -1
- package/dist/cjs/adapters/SQLiteAdapter.js +30 -11
- package/dist/cjs/adapters/SQLiteAdapter.js.map +1 -1
- package/dist/cjs/constants/index.d.ts +0 -9
- package/dist/cjs/constants/index.d.ts.map +1 -1
- package/dist/cjs/constants/index.js +2 -11
- package/dist/cjs/constants/index.js.map +1 -1
- package/dist/cjs/core/Agent.d.ts +119 -153
- package/dist/cjs/core/Agent.d.ts.map +1 -1
- package/dist/cjs/core/Agent.js +471 -324
- package/dist/cjs/core/Agent.js.map +1 -1
- package/dist/cjs/core/AutoChainExecutor.d.ts +107 -0
- package/dist/cjs/core/AutoChainExecutor.d.ts.map +1 -0
- package/dist/cjs/core/AutoChainExecutor.js +297 -0
- package/dist/cjs/core/AutoChainExecutor.js.map +1 -0
- package/dist/cjs/core/BranchEvaluator.d.ts +54 -0
- package/dist/cjs/core/BranchEvaluator.d.ts.map +1 -0
- package/dist/cjs/core/BranchEvaluator.js +130 -0
- package/dist/cjs/core/BranchEvaluator.js.map +1 -0
- package/dist/cjs/core/DirectiveBus.d.ts +88 -0
- package/dist/cjs/core/DirectiveBus.d.ts.map +1 -0
- package/dist/cjs/core/DirectiveBus.js +196 -0
- package/dist/cjs/core/DirectiveBus.js.map +1 -0
- package/dist/cjs/core/DirectiveChainTracker.d.ts +49 -0
- package/dist/cjs/core/DirectiveChainTracker.d.ts.map +1 -0
- package/dist/cjs/core/DirectiveChainTracker.js +121 -0
- package/dist/cjs/core/DirectiveChainTracker.js.map +1 -0
- package/dist/cjs/core/Flow.d.ts +186 -0
- package/dist/cjs/core/Flow.d.ts.map +1 -0
- package/dist/cjs/core/Flow.js +550 -0
- package/dist/cjs/core/Flow.js.map +1 -0
- package/dist/cjs/core/FlowRouter.d.ts +182 -0
- package/dist/cjs/core/FlowRouter.d.ts.map +1 -0
- package/dist/cjs/core/{RoutingEngine.js → FlowRouter.js} +323 -306
- package/dist/cjs/core/FlowRouter.js.map +1 -0
- package/dist/cjs/core/PersistenceManager.d.ts +2 -2
- package/dist/cjs/core/PersistenceManager.d.ts.map +1 -1
- package/dist/cjs/core/PersistenceManager.js +7 -7
- package/dist/cjs/core/PersistenceManager.js.map +1 -1
- package/dist/cjs/core/PromptComposer.d.ts +21 -8
- package/dist/cjs/core/PromptComposer.d.ts.map +1 -1
- package/dist/cjs/core/PromptComposer.js +182 -105
- package/dist/cjs/core/PromptComposer.js.map +1 -1
- package/dist/cjs/core/PromptSectionCache.d.ts +1 -1
- package/dist/cjs/core/PromptSectionCache.js +1 -1
- package/dist/cjs/core/ResponseEngine.d.ts +18 -8
- package/dist/cjs/core/ResponseEngine.d.ts.map +1 -1
- package/dist/cjs/core/ResponseEngine.js +38 -36
- package/dist/cjs/core/ResponseEngine.js.map +1 -1
- package/dist/cjs/core/ResponseModal.d.ts +73 -56
- package/dist/cjs/core/ResponseModal.d.ts.map +1 -1
- package/dist/cjs/core/ResponseModal.js +1191 -1014
- package/dist/cjs/core/ResponseModal.js.map +1 -1
- package/dist/cjs/core/ResponsePipeline.d.ts +124 -26
- package/dist/cjs/core/ResponsePipeline.d.ts.map +1 -1
- package/dist/cjs/core/ResponsePipeline.js +509 -136
- package/dist/cjs/core/ResponsePipeline.js.map +1 -1
- package/dist/cjs/core/SignalEvaluator.d.ts +86 -0
- package/dist/cjs/core/SignalEvaluator.d.ts.map +1 -0
- package/dist/cjs/core/SignalEvaluator.js +333 -0
- package/dist/cjs/core/SignalEvaluator.js.map +1 -0
- package/dist/cjs/core/SignalProcessor.d.ts +152 -0
- package/dist/cjs/core/SignalProcessor.d.ts.map +1 -0
- package/dist/cjs/core/SignalProcessor.js +562 -0
- package/dist/cjs/core/SignalProcessor.js.map +1 -0
- package/dist/cjs/core/Step.d.ts +43 -32
- package/dist/cjs/core/Step.d.ts.map +1 -1
- package/dist/cjs/core/Step.js +221 -126
- package/dist/cjs/core/Step.js.map +1 -1
- package/dist/cjs/core/StreamingToolExecutor.d.ts +2 -2
- package/dist/cjs/core/StreamingToolExecutor.d.ts.map +1 -1
- package/dist/cjs/core/StreamingToolExecutor.js.map +1 -1
- package/dist/cjs/core/ToolManager.d.ts +44 -13
- package/dist/cjs/core/ToolManager.d.ts.map +1 -1
- package/dist/cjs/core/ToolManager.js +174 -91
- package/dist/cjs/core/ToolManager.js.map +1 -1
- package/dist/cjs/core/createAgent.d.ts +35 -0
- package/dist/cjs/core/createAgent.d.ts.map +1 -0
- package/dist/cjs/core/createAgent.js +39 -0
- package/dist/cjs/core/createAgent.js.map +1 -0
- package/dist/cjs/core/flow-namespace.d.ts +49 -0
- package/dist/cjs/core/flow-namespace.d.ts.map +1 -0
- package/dist/cjs/core/flow-namespace.js +171 -0
- package/dist/cjs/core/flow-namespace.js.map +1 -0
- package/dist/cjs/index.d.ts +11 -14
- package/dist/cjs/index.d.ts.map +1 -1
- package/dist/cjs/index.js +18 -22
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/providers/AnthropicProvider.d.ts +1 -1
- package/dist/cjs/providers/AnthropicProvider.js +1 -1
- package/dist/cjs/providers/GeminiProvider.d.ts +1 -1
- package/dist/cjs/providers/GeminiProvider.d.ts.map +1 -1
- package/dist/cjs/providers/GeminiProvider.js +1 -1
- package/dist/cjs/providers/GeminiProvider.js.map +1 -1
- package/dist/cjs/providers/OpenAIProvider.d.ts +1 -1
- package/dist/cjs/providers/OpenAIProvider.d.ts.map +1 -1
- package/dist/cjs/providers/OpenAIProvider.js +1 -1
- package/dist/cjs/providers/OpenAIProvider.js.map +1 -1
- package/dist/cjs/types/agent.d.ts +183 -54
- package/dist/cjs/types/agent.d.ts.map +1 -1
- package/dist/cjs/types/agent.js +0 -6
- package/dist/cjs/types/agent.js.map +1 -1
- package/dist/cjs/types/ai.d.ts +3 -3
- package/dist/cjs/types/ai.d.ts.map +1 -1
- package/dist/cjs/types/errors.d.ts +15 -0
- package/dist/cjs/types/errors.d.ts.map +1 -0
- package/dist/cjs/types/errors.js +22 -0
- package/dist/cjs/types/errors.js.map +1 -0
- package/dist/cjs/types/flow.d.ts +513 -0
- package/dist/cjs/types/flow.d.ts.map +1 -0
- package/dist/cjs/types/{route.js → flow.js} +2 -2
- package/dist/cjs/types/flow.js.map +1 -0
- package/dist/cjs/types/index.d.ts +7 -6
- package/dist/cjs/types/index.d.ts.map +1 -1
- package/dist/cjs/types/index.js +6 -2
- package/dist/cjs/types/index.js.map +1 -1
- package/dist/cjs/types/persistence.d.ts +11 -7
- package/dist/cjs/types/persistence.d.ts.map +1 -1
- package/dist/cjs/types/routing.d.ts +1 -1
- package/dist/cjs/types/routing.d.ts.map +1 -1
- package/dist/cjs/types/session.d.ts +24 -23
- package/dist/cjs/types/session.d.ts.map +1 -1
- package/dist/cjs/types/signals.d.ts +248 -0
- package/dist/cjs/types/signals.d.ts.map +1 -0
- package/dist/cjs/types/signals.js +11 -0
- package/dist/cjs/types/signals.js.map +1 -0
- package/dist/cjs/types/template.d.ts +2 -8
- package/dist/cjs/types/template.d.ts.map +1 -1
- package/dist/cjs/types/tool.d.ts +36 -29
- package/dist/cjs/types/tool.d.ts.map +1 -1
- package/dist/cjs/types/tool.js +1 -1
- package/dist/cjs/types/tool.js.map +1 -1
- package/dist/cjs/utils/condition.d.ts +7 -1
- package/dist/cjs/utils/condition.d.ts.map +1 -1
- package/dist/cjs/utils/condition.js.map +1 -1
- package/dist/cjs/utils/id.d.ts +13 -5
- package/dist/cjs/utils/id.d.ts.map +1 -1
- package/dist/cjs/utils/id.js +24 -10
- package/dist/cjs/utils/id.js.map +1 -1
- package/dist/cjs/utils/index.d.ts +2 -2
- package/dist/cjs/utils/index.d.ts.map +1 -1
- package/dist/cjs/utils/index.js +7 -3
- package/dist/cjs/utils/index.js.map +1 -1
- package/dist/cjs/utils/session.d.ts +44 -5
- package/dist/cjs/utils/session.d.ts.map +1 -1
- package/dist/cjs/utils/session.js +197 -38
- package/dist/cjs/utils/session.js.map +1 -1
- package/dist/constants/index.d.ts +0 -9
- package/dist/constants/index.d.ts.map +1 -1
- package/dist/constants/index.js +3 -9
- package/dist/constants/index.js.map +1 -1
- package/dist/core/Agent.d.ts +119 -153
- package/dist/core/Agent.d.ts.map +1 -1
- package/dist/core/Agent.js +472 -325
- package/dist/core/Agent.js.map +1 -1
- package/dist/core/AutoChainExecutor.d.ts +107 -0
- package/dist/core/AutoChainExecutor.d.ts.map +1 -0
- package/dist/core/AutoChainExecutor.js +293 -0
- package/dist/core/AutoChainExecutor.js.map +1 -0
- package/dist/core/BranchEvaluator.d.ts +54 -0
- package/dist/core/BranchEvaluator.d.ts.map +1 -0
- package/dist/core/BranchEvaluator.js +126 -0
- package/dist/core/BranchEvaluator.js.map +1 -0
- package/dist/core/DirectiveBus.d.ts +88 -0
- package/dist/core/DirectiveBus.d.ts.map +1 -0
- package/dist/core/DirectiveBus.js +192 -0
- package/dist/core/DirectiveBus.js.map +1 -0
- package/dist/core/DirectiveChainTracker.d.ts +49 -0
- package/dist/core/DirectiveChainTracker.d.ts.map +1 -0
- package/dist/core/DirectiveChainTracker.js +117 -0
- package/dist/core/DirectiveChainTracker.js.map +1 -0
- package/dist/core/Flow.d.ts +186 -0
- package/dist/core/Flow.d.ts.map +1 -0
- package/dist/core/Flow.js +546 -0
- package/dist/core/Flow.js.map +1 -0
- package/dist/core/FlowRouter.d.ts +182 -0
- package/dist/core/FlowRouter.d.ts.map +1 -0
- package/dist/core/{RoutingEngine.js → FlowRouter.js} +322 -305
- package/dist/core/FlowRouter.js.map +1 -0
- package/dist/core/PersistenceManager.d.ts +2 -2
- package/dist/core/PersistenceManager.d.ts.map +1 -1
- package/dist/core/PersistenceManager.js +7 -7
- package/dist/core/PersistenceManager.js.map +1 -1
- package/dist/core/PromptComposer.d.ts +21 -8
- package/dist/core/PromptComposer.d.ts.map +1 -1
- package/dist/core/PromptComposer.js +183 -106
- package/dist/core/PromptComposer.js.map +1 -1
- package/dist/core/PromptSectionCache.d.ts +1 -1
- package/dist/core/PromptSectionCache.js +1 -1
- package/dist/core/ResponseEngine.d.ts +18 -8
- package/dist/core/ResponseEngine.d.ts.map +1 -1
- package/dist/core/ResponseEngine.js +38 -36
- package/dist/core/ResponseEngine.js.map +1 -1
- package/dist/core/ResponseModal.d.ts +73 -56
- package/dist/core/ResponseModal.d.ts.map +1 -1
- package/dist/core/ResponseModal.js +1193 -1016
- package/dist/core/ResponseModal.js.map +1 -1
- package/dist/core/ResponsePipeline.d.ts +124 -26
- package/dist/core/ResponsePipeline.d.ts.map +1 -1
- package/dist/core/ResponsePipeline.js +509 -137
- package/dist/core/ResponsePipeline.js.map +1 -1
- package/dist/core/SignalEvaluator.d.ts +86 -0
- package/dist/core/SignalEvaluator.d.ts.map +1 -0
- package/dist/core/SignalEvaluator.js +326 -0
- package/dist/core/SignalEvaluator.js.map +1 -0
- package/dist/core/SignalProcessor.d.ts +152 -0
- package/dist/core/SignalProcessor.d.ts.map +1 -0
- package/dist/core/SignalProcessor.js +555 -0
- package/dist/core/SignalProcessor.js.map +1 -0
- package/dist/core/Step.d.ts +43 -32
- package/dist/core/Step.d.ts.map +1 -1
- package/dist/core/Step.js +220 -126
- package/dist/core/Step.js.map +1 -1
- package/dist/core/StreamingToolExecutor.d.ts +2 -2
- package/dist/core/StreamingToolExecutor.d.ts.map +1 -1
- package/dist/core/StreamingToolExecutor.js.map +1 -1
- package/dist/core/ToolManager.d.ts +44 -13
- package/dist/core/ToolManager.d.ts.map +1 -1
- package/dist/core/ToolManager.js +174 -91
- package/dist/core/ToolManager.js.map +1 -1
- package/dist/core/createAgent.d.ts +35 -0
- package/dist/core/createAgent.d.ts.map +1 -0
- package/dist/core/createAgent.js +36 -0
- package/dist/core/createAgent.js.map +1 -0
- package/dist/core/flow-namespace.d.ts +49 -0
- package/dist/core/flow-namespace.d.ts.map +1 -0
- package/dist/core/flow-namespace.js +168 -0
- package/dist/core/flow-namespace.js.map +1 -0
- package/dist/index.d.ts +11 -14
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -12
- package/dist/index.js.map +1 -1
- package/dist/providers/AnthropicProvider.d.ts +1 -1
- package/dist/providers/AnthropicProvider.js +1 -1
- package/dist/providers/GeminiProvider.d.ts +1 -1
- package/dist/providers/GeminiProvider.d.ts.map +1 -1
- package/dist/providers/GeminiProvider.js +1 -1
- package/dist/providers/GeminiProvider.js.map +1 -1
- package/dist/providers/OpenAIProvider.d.ts +1 -1
- package/dist/providers/OpenAIProvider.d.ts.map +1 -1
- package/dist/providers/OpenAIProvider.js +1 -1
- package/dist/providers/OpenAIProvider.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 +22 -200
- 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 +14 -0
- package/docs/migration/route-to-flow.md +561 -0
- package/docs/migration/v1-to-v2.md +909 -0
- package/docs/reference/adapters.md +481 -0
- package/docs/reference/branches.md +241 -0
- package/docs/reference/create-agent.md +186 -0
- package/docs/reference/directive.md +243 -0
- package/docs/reference/errors.md +122 -0
- package/docs/reference/flow.md +238 -0
- package/docs/reference/instruction.md +177 -0
- package/docs/reference/pre-directive.md +131 -0
- package/docs/reference/providers.md +227 -0
- package/docs/reference/signals.md +356 -0
- package/docs/reference/step.md +339 -0
- package/docs/reference/tool.md +269 -0
- package/docs/start/01-install.md +81 -0
- package/docs/start/02-first-agent.md +196 -0
- package/docs/start/03-collect-data.md +222 -0
- package/docs/start/04-add-tools.md +276 -0
- package/docs/start/05-go-to-production.md +216 -0
- package/examples/01-quickstart.ts +20 -0
- package/examples/02-data-extraction.ts +90 -0
- package/examples/03-tools.ts +136 -0
- package/examples/04-instructions.ts +100 -0
- package/examples/05-branching.ts +140 -0
- package/examples/06-flow-control.ts +103 -0
- package/examples/07-streaming.ts +69 -0
- package/examples/08-persistence.ts +98 -0
- package/examples/09-signals.ts +144 -0
- package/examples/tsconfig.json +30 -0
- package/package.json +2 -1
- package/src/adapters/MemoryAdapter.ts +3 -3
- package/src/adapters/MongoAdapter.ts +3 -3
- package/src/adapters/OpenSearchAdapter.ts +10 -8
- package/src/adapters/PostgreSQLAdapter.ts +26 -10
- package/src/adapters/PrismaAdapter.ts +6 -6
- package/src/adapters/RedisAdapter.ts +3 -3
- package/src/adapters/SQLiteAdapter.ts +31 -12
- package/src/constants/index.ts +2 -10
- package/src/core/Agent.ts +585 -374
- package/src/core/AutoChainExecutor.ts +440 -0
- package/src/core/BranchEvaluator.ts +167 -0
- package/src/core/DirectiveBus.ts +248 -0
- package/src/core/DirectiveChainTracker.ts +144 -0
- package/src/core/Flow.ts +666 -0
- package/src/core/{RoutingEngine.ts → FlowRouter.ts} +385 -365
- package/src/core/PersistenceManager.ts +8 -8
- package/src/core/PromptComposer.ts +209 -140
- package/src/core/PromptSectionCache.ts +1 -1
- package/src/core/ResponseEngine.ts +61 -46
- package/src/core/ResponseModal.ts +1453 -1240
- package/src/core/ResponsePipeline.ts +655 -175
- package/src/core/SignalEvaluator.ts +420 -0
- package/src/core/SignalProcessor.ts +723 -0
- package/src/core/Step.ts +279 -176
- package/src/core/StreamingToolExecutor.ts +4 -4
- package/src/core/ToolManager.ts +200 -97
- package/src/core/createAgent.ts +40 -0
- package/src/core/flow-namespace.ts +219 -0
- package/src/index.ts +42 -36
- package/src/providers/AnthropicProvider.ts +2 -2
- package/src/providers/GeminiProvider.ts +2 -2
- package/src/providers/OpenAIProvider.ts +2 -2
- 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
|
@@ -38,8 +38,53 @@ exports.ToolExecutionError = ToolExecutionError;
|
|
|
38
38
|
class ToolManager {
|
|
39
39
|
constructor(agent) {
|
|
40
40
|
this.agent = agent;
|
|
41
|
+
/**
|
|
42
|
+
* Per-turn transient tool layer populated from PreDirective.injectTools.
|
|
43
|
+
* Resolution order: transient → step → flow → agent.
|
|
44
|
+
* Drained at end of turn via try/finally guard.
|
|
45
|
+
*
|
|
46
|
+
* Tools are deduplicated by `id` with last-definition-wins when
|
|
47
|
+
* multiple pre-LLM emitters contribute tools in the same turn.
|
|
48
|
+
*/
|
|
49
|
+
this.transientTools = new Map();
|
|
41
50
|
this.toolRegistry = new Map();
|
|
42
51
|
}
|
|
52
|
+
/**
|
|
53
|
+
* Set the transient tool layer for the current turn.
|
|
54
|
+
*
|
|
55
|
+
* Accepts the merged `injectTools` array from pre-LLM emitters
|
|
56
|
+
* (already concatenated in outer-to-inner order by the DirectiveBus).
|
|
57
|
+
* Deduplicates by tool `id` with last-definition-wins.
|
|
58
|
+
*
|
|
59
|
+
* Must be paired with `clearTransientTools()` in a try/finally guard
|
|
60
|
+
* so the layer is drained even on abnormal termination.
|
|
61
|
+
*/
|
|
62
|
+
setTransientTools(tools) {
|
|
63
|
+
this.transientTools.clear();
|
|
64
|
+
for (const tool of tools) {
|
|
65
|
+
this.transientTools.set(tool.id, tool);
|
|
66
|
+
}
|
|
67
|
+
if (this.transientTools.size > 0) {
|
|
68
|
+
utils_1.logger.debug(`[ToolManager] Set transient tools for turn: ${Array.from(this.transientTools.keys()).join(', ')}`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Clear the transient tool layer. Called at end of turn via try/finally
|
|
73
|
+
* guard so tools do not leak into subsequent turns.
|
|
74
|
+
*/
|
|
75
|
+
clearTransientTools() {
|
|
76
|
+
if (this.transientTools.size > 0) {
|
|
77
|
+
utils_1.logger.debug(`[ToolManager] Cleared transient tools: ${Array.from(this.transientTools.keys()).join(', ')}`);
|
|
78
|
+
}
|
|
79
|
+
this.transientTools.clear();
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Check whether the transient layer currently has any tools.
|
|
83
|
+
* Useful for testing and debugging.
|
|
84
|
+
*/
|
|
85
|
+
hasTransientTools() {
|
|
86
|
+
return this.transientTools.size > 0;
|
|
87
|
+
}
|
|
43
88
|
/**
|
|
44
89
|
* Validate a tool definition for completeness and correctness
|
|
45
90
|
*/
|
|
@@ -58,10 +103,6 @@ class ToolManager {
|
|
|
58
103
|
if (!definition.handler || typeof definition.handler !== 'function') {
|
|
59
104
|
errors.push('Tool handler is required and must be a function');
|
|
60
105
|
}
|
|
61
|
-
// Optional fields validation
|
|
62
|
-
if (definition.name !== undefined && (typeof definition.name !== 'string' || definition.name.trim() === '')) {
|
|
63
|
-
errors.push('Tool name must be a non-empty string if provided');
|
|
64
|
-
}
|
|
65
106
|
if (definition.description !== undefined && (typeof definition.description !== 'string' || definition.description.trim() === '')) {
|
|
66
107
|
errors.push('Tool description must be a non-empty string if provided');
|
|
67
108
|
}
|
|
@@ -87,7 +128,8 @@ class ToolManager {
|
|
|
87
128
|
}
|
|
88
129
|
}
|
|
89
130
|
if (errors.length > 0) {
|
|
90
|
-
throw new ToolCreationError(`Tool definition validation failed: ${errors.join('; ')}
|
|
131
|
+
throw new ToolCreationError(`[ToolCreationError] Tool definition validation failed for "${definition.id || 'unknown'}": ${errors.join('; ')}. ` +
|
|
132
|
+
`Fix the tool definition to meet the required schema.`, definition.id || 'unknown');
|
|
91
133
|
}
|
|
92
134
|
}
|
|
93
135
|
/**
|
|
@@ -102,7 +144,8 @@ class ToolManager {
|
|
|
102
144
|
errors.push('Data enrichment enricher must be a function');
|
|
103
145
|
}
|
|
104
146
|
if (errors.length > 0) {
|
|
105
|
-
throw new ToolCreationError(`Data enrichment
|
|
147
|
+
throw new ToolCreationError(`[ToolCreationError] Data enrichment config validation failed for "${config.id || 'unknown'}": ${errors.join('; ')}. ` +
|
|
148
|
+
`Fix the enrichment config to satisfy the required fields.`, config.id || 'unknown');
|
|
106
149
|
}
|
|
107
150
|
}
|
|
108
151
|
/**
|
|
@@ -117,7 +160,8 @@ class ToolManager {
|
|
|
117
160
|
errors.push('Validation validator must be a function');
|
|
118
161
|
}
|
|
119
162
|
if (errors.length > 0) {
|
|
120
|
-
throw new ToolCreationError(`Validation
|
|
163
|
+
throw new ToolCreationError(`[ToolCreationError] Validation config validation failed for "${config.id || 'unknown'}": ${errors.join('; ')}. ` +
|
|
164
|
+
`Fix the validation config to satisfy the required fields.`, config.id || 'unknown');
|
|
121
165
|
}
|
|
122
166
|
}
|
|
123
167
|
/**
|
|
@@ -144,7 +188,8 @@ class ToolManager {
|
|
|
144
188
|
errors.push('API call transform must be a function');
|
|
145
189
|
}
|
|
146
190
|
if (errors.length > 0) {
|
|
147
|
-
throw new ToolCreationError(`API call
|
|
191
|
+
throw new ToolCreationError(`[ToolCreationError] API call config validation failed for "${config.id || 'unknown'}": ${errors.join('; ')}. ` +
|
|
192
|
+
`Fix the API call config to satisfy the required fields.`, config.id || 'unknown');
|
|
148
193
|
}
|
|
149
194
|
}
|
|
150
195
|
/**
|
|
@@ -159,7 +204,8 @@ class ToolManager {
|
|
|
159
204
|
errors.push('Computation compute function is required');
|
|
160
205
|
}
|
|
161
206
|
if (errors.length > 0) {
|
|
162
|
-
throw new ToolCreationError(`Computation
|
|
207
|
+
throw new ToolCreationError(`[ToolCreationError] Computation config validation failed for "${config.id || 'unknown'}": ${errors.join('; ')}. ` +
|
|
208
|
+
`Fix the computation config to satisfy the required fields.`, config.id || 'unknown');
|
|
163
209
|
}
|
|
164
210
|
}
|
|
165
211
|
/**
|
|
@@ -174,7 +220,8 @@ class ToolManager {
|
|
|
174
220
|
return definition;
|
|
175
221
|
}
|
|
176
222
|
catch (error) {
|
|
177
|
-
throw new ToolCreationError(`Failed to create tool
|
|
223
|
+
throw new ToolCreationError(`[ToolCreationError] Failed to create tool "${definition.id}": ${error instanceof Error ? error.message : String(error)}. ` +
|
|
224
|
+
`Ensure the tool definition passes validation.`, definition.id, error instanceof Error ? error : undefined);
|
|
178
225
|
}
|
|
179
226
|
}
|
|
180
227
|
/**
|
|
@@ -184,22 +231,22 @@ class ToolManager {
|
|
|
184
231
|
register(tool) {
|
|
185
232
|
try {
|
|
186
233
|
if (!tool) {
|
|
187
|
-
throw new ToolCreationError('Tool
|
|
234
|
+
throw new ToolCreationError('[ToolCreationError] Tool registration failed: no tool provided. Pass a valid tool object with id and handler.', 'unknown');
|
|
188
235
|
}
|
|
189
236
|
if (!('handler' in tool) || typeof tool.handler !== 'function') {
|
|
190
|
-
throw new ToolCreationError(
|
|
237
|
+
throw new ToolCreationError(`[ToolCreationError] Invalid tool for registration: tool "${tool?.id || 'unknown'}" must have a handler function. Add a handler property.`, tool?.id || 'unknown');
|
|
191
238
|
}
|
|
192
239
|
// Validate the tool
|
|
193
240
|
if (!tool.id || typeof tool.id !== 'string' || tool.id.trim() === '') {
|
|
194
|
-
throw new ToolCreationError('Tool ID is required and must be a non-empty string', tool.id || 'unknown');
|
|
241
|
+
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');
|
|
195
242
|
}
|
|
196
243
|
// Check for ID conflicts and provide better error context
|
|
197
244
|
if (this.toolRegistry.has(tool.id)) {
|
|
198
245
|
const existingTool = this.toolRegistry.get(tool.id);
|
|
199
|
-
utils_1.logger.warn(`[ToolManager] Overwriting existing registered tool: ${tool.id} (previous: ${existingTool?.
|
|
246
|
+
utils_1.logger.warn(`[ToolManager] Overwriting existing registered tool: ${tool.id} (previous: ${existingTool?.id || 'unnamed'})`);
|
|
200
247
|
}
|
|
201
248
|
this.toolRegistry.set(tool.id, tool);
|
|
202
|
-
utils_1.logger.debug(`[ToolManager] Registered tool: ${tool.id} (${tool.
|
|
249
|
+
utils_1.logger.debug(`[ToolManager] Registered tool: ${tool.id} (${tool.id || 'unnamed'})`);
|
|
203
250
|
return tool;
|
|
204
251
|
}
|
|
205
252
|
catch (error) {
|
|
@@ -207,7 +254,8 @@ class ToolManager {
|
|
|
207
254
|
throw error;
|
|
208
255
|
}
|
|
209
256
|
const toolId = tool?.id || 'unknown';
|
|
210
|
-
throw new ToolCreationError(`Failed to register tool
|
|
257
|
+
throw new ToolCreationError(`[ToolCreationError] Failed to register tool "${toolId}": ${error instanceof Error ? error.message : String(error)}. ` +
|
|
258
|
+
`Ensure the tool object is valid and has id + handler.`, toolId, error instanceof Error ? error : undefined);
|
|
211
259
|
}
|
|
212
260
|
}
|
|
213
261
|
/**
|
|
@@ -243,20 +291,20 @@ class ToolManager {
|
|
|
243
291
|
/**
|
|
244
292
|
* Get tool by ID from a specific scope
|
|
245
293
|
*/
|
|
246
|
-
getFromScope(toolId, scope, step,
|
|
247
|
-
return this.find(toolId, scope, step,
|
|
294
|
+
getFromScope(toolId, scope, step, flow) {
|
|
295
|
+
return this.find(toolId, scope, step, flow);
|
|
248
296
|
}
|
|
249
297
|
/**
|
|
250
298
|
* Check if a tool exists in any scope
|
|
251
299
|
*/
|
|
252
|
-
exists(toolId, step,
|
|
253
|
-
return this.find(toolId, types_1.ToolScope.ALL, step,
|
|
300
|
+
exists(toolId, step, flow) {
|
|
301
|
+
return this.find(toolId, types_1.ToolScope.ALL, step, flow) !== undefined;
|
|
254
302
|
}
|
|
255
303
|
/**
|
|
256
304
|
* Get tool count by scope
|
|
257
305
|
*/
|
|
258
|
-
getToolCount(scope, step,
|
|
259
|
-
return this.getAvailable(scope, step,
|
|
306
|
+
getToolCount(scope, step, flow) {
|
|
307
|
+
return this.getAvailable(scope, step, flow).length;
|
|
260
308
|
}
|
|
261
309
|
/**
|
|
262
310
|
* Clear all registered tools
|
|
@@ -282,7 +330,8 @@ class ToolManager {
|
|
|
282
330
|
addToAgent(tool) {
|
|
283
331
|
// Validate tool before adding
|
|
284
332
|
if (!tool || !tool.id || !tool.handler) {
|
|
285
|
-
throw new ToolCreationError(
|
|
333
|
+
throw new ToolCreationError(`[ToolCreationError] Invalid tool for addToAgent: tool must have id and handler properties. ` +
|
|
334
|
+
`Provide a complete tool object with { id, handler, ... }.`, tool?.id || 'unknown');
|
|
286
335
|
}
|
|
287
336
|
// Add to agent's tools array using the unified interface
|
|
288
337
|
if (this.agent) {
|
|
@@ -295,33 +344,41 @@ class ToolManager {
|
|
|
295
344
|
return tool;
|
|
296
345
|
}
|
|
297
346
|
/**
|
|
298
|
-
* Add a tool to a specific
|
|
347
|
+
* Add a tool to a specific flow scope (creates and adds in one operation)
|
|
299
348
|
*/
|
|
300
|
-
|
|
301
|
-
// Add to
|
|
302
|
-
if (
|
|
303
|
-
|
|
349
|
+
addToFlow(flow, tool) {
|
|
350
|
+
// Add to flow's tools array using the existing createTool method
|
|
351
|
+
if (flow && typeof flow.createTool === 'function') {
|
|
352
|
+
flow.createTool(tool);
|
|
304
353
|
}
|
|
305
354
|
else {
|
|
306
|
-
utils_1.logger.warn(`[ToolManager]
|
|
355
|
+
utils_1.logger.warn(`[ToolManager] Flow does not support createTool method, tool not added to flow scope: ${tool.id}`);
|
|
307
356
|
}
|
|
308
|
-
utils_1.logger.debug(`[ToolManager] Added tool to
|
|
357
|
+
utils_1.logger.debug(`[ToolManager] Added tool to flow scope: ${tool.id}`);
|
|
309
358
|
return tool;
|
|
310
359
|
}
|
|
311
360
|
/**
|
|
312
361
|
* Find a tool by ID across different scopes with enhanced resolution logic
|
|
313
|
-
* Priority: step →
|
|
362
|
+
* Priority: transient → step → flow → agent → registry
|
|
314
363
|
* Supports both ID and name matching for better compatibility
|
|
315
364
|
*/
|
|
316
|
-
find(toolId, scope, step,
|
|
365
|
+
find(toolId, scope, step, flow) {
|
|
317
366
|
utils_1.logger.debug(`[ToolManager] Finding tool: ${toolId} with scope: ${scope || 'ALL'}`);
|
|
318
|
-
// Check
|
|
367
|
+
// Check transient tools first (highest priority — per-turn injectTools)
|
|
368
|
+
if (!scope || scope === types_1.ToolScope.ALL) {
|
|
369
|
+
const transientTool = this.transientTools.get(toolId);
|
|
370
|
+
if (transientTool) {
|
|
371
|
+
utils_1.logger.debug(`[ToolManager] Found tool in transient scope: ${toolId}`);
|
|
372
|
+
return transientTool;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
// Check step-level tools (if step provided and scope allows)
|
|
319
376
|
if (step && (!scope || scope === types_1.ToolScope.STEP || scope === types_1.ToolScope.ALL)) {
|
|
320
377
|
if (step.tools) {
|
|
321
378
|
for (const toolRef of step.tools) {
|
|
322
379
|
if (typeof toolRef !== 'string') {
|
|
323
380
|
// Inline tool object - check both id and name
|
|
324
|
-
if (toolRef.id === toolId
|
|
381
|
+
if (toolRef.id === toolId) {
|
|
325
382
|
utils_1.logger.debug(`[ToolManager] Found tool in step scope: ${toolId}`);
|
|
326
383
|
return toolRef;
|
|
327
384
|
}
|
|
@@ -339,13 +396,13 @@ class ToolManager {
|
|
|
339
396
|
}
|
|
340
397
|
}
|
|
341
398
|
}
|
|
342
|
-
// Check
|
|
343
|
-
if (
|
|
344
|
-
if (
|
|
345
|
-
const
|
|
346
|
-
if (
|
|
347
|
-
utils_1.logger.debug(`[ToolManager] Found tool in
|
|
348
|
-
return
|
|
399
|
+
// Check flow-level tools (if route provided and scope allows)
|
|
400
|
+
if (flow && (!scope || scope === types_1.ToolScope.FLOW || scope === types_1.ToolScope.ALL)) {
|
|
401
|
+
if (flow.tools) {
|
|
402
|
+
const flowTool = flow.tools.find((t) => t.id === toolId);
|
|
403
|
+
if (flowTool) {
|
|
404
|
+
utils_1.logger.debug(`[ToolManager] Found tool in flow scope: ${toolId}`);
|
|
405
|
+
return flowTool;
|
|
349
406
|
}
|
|
350
407
|
}
|
|
351
408
|
}
|
|
@@ -353,7 +410,7 @@ class ToolManager {
|
|
|
353
410
|
if (!scope || scope === types_1.ToolScope.AGENT || scope === types_1.ToolScope.ALL) {
|
|
354
411
|
if (this.agent) {
|
|
355
412
|
const agentTools = this.agent.getTools();
|
|
356
|
-
const agentTool = agentTools.find((t) => t.id === toolId
|
|
413
|
+
const agentTool = agentTools.find((t) => t.id === toolId);
|
|
357
414
|
if (agentTool) {
|
|
358
415
|
utils_1.logger.debug(`[ToolManager] Found tool in agent scope: ${toolId}`);
|
|
359
416
|
return agentTool;
|
|
@@ -369,7 +426,7 @@ class ToolManager {
|
|
|
369
426
|
}
|
|
370
427
|
// Also check by name in registry
|
|
371
428
|
for (const [id, tool] of Array.from(this.toolRegistry.entries())) {
|
|
372
|
-
if (tool.
|
|
429
|
+
if (tool.id === toolId) {
|
|
373
430
|
utils_1.logger.debug(`[ToolManager] Found tool in registry by name: ${toolId} (id: ${id})`);
|
|
374
431
|
return tool;
|
|
375
432
|
}
|
|
@@ -381,8 +438,9 @@ class ToolManager {
|
|
|
381
438
|
/**
|
|
382
439
|
* Get available tools for current context with enhanced resolution and deduplication
|
|
383
440
|
* Returns tools in priority order with higher-priority scopes taking precedence
|
|
441
|
+
* Resolution order: transient → step → flow → agent → registry
|
|
384
442
|
*/
|
|
385
|
-
getAvailable(scope, step,
|
|
443
|
+
getAvailable(scope, step, flow) {
|
|
386
444
|
const toolMap = new Map();
|
|
387
445
|
const resolvedTools = [];
|
|
388
446
|
utils_1.logger.debug(`[ToolManager] Getting available tools with scope: ${scope || 'ALL'}`);
|
|
@@ -404,15 +462,15 @@ class ToolManager {
|
|
|
404
462
|
}
|
|
405
463
|
}
|
|
406
464
|
// Add route-level tools (override agent and registered tools with same ID)
|
|
407
|
-
if (
|
|
408
|
-
if (
|
|
409
|
-
for (const tool of
|
|
465
|
+
if (flow && (!scope || scope === types_1.ToolScope.FLOW || scope === types_1.ToolScope.ALL)) {
|
|
466
|
+
if (flow.tools) {
|
|
467
|
+
for (const tool of flow.tools) {
|
|
410
468
|
toolMap.set(tool.id, tool);
|
|
411
469
|
}
|
|
412
|
-
utils_1.logger.debug(`[ToolManager] Added ${
|
|
470
|
+
utils_1.logger.debug(`[ToolManager] Added ${flow.tools.length} flow.tools`);
|
|
413
471
|
}
|
|
414
472
|
}
|
|
415
|
-
// Add step-level tools (
|
|
473
|
+
// Add step-level tools (override flow/agent/registry with same ID)
|
|
416
474
|
if (step && (!scope || scope === types_1.ToolScope.STEP || scope === types_1.ToolScope.ALL)) {
|
|
417
475
|
if (step.tools) {
|
|
418
476
|
for (const toolRef of step.tools) {
|
|
@@ -429,21 +487,33 @@ class ToolManager {
|
|
|
429
487
|
resolvedTools.push(registeredTool);
|
|
430
488
|
}
|
|
431
489
|
else {
|
|
432
|
-
utils_1.logger.warn(`[
|
|
490
|
+
utils_1.logger.warn(`[ToolExecutionError] Step references unknown tool: "${toolRef}" is not registered. Skipping. Register the tool or remove the reference.`);
|
|
433
491
|
}
|
|
434
492
|
}
|
|
435
493
|
}
|
|
436
494
|
utils_1.logger.debug(`[ToolManager] Added ${step.tools.length} step tools (${resolvedTools.length} resolved)`);
|
|
437
495
|
}
|
|
438
496
|
}
|
|
497
|
+
// Add transient tools (highest priority — override everything with same ID)
|
|
498
|
+
if (!scope || scope === types_1.ToolScope.ALL) {
|
|
499
|
+
if (this.transientTools.size > 0) {
|
|
500
|
+
for (const [id, tool] of this.transientTools) {
|
|
501
|
+
toolMap.set(id, tool);
|
|
502
|
+
}
|
|
503
|
+
utils_1.logger.debug(`[ToolManager] Added ${this.transientTools.size} transient tools`);
|
|
504
|
+
}
|
|
505
|
+
}
|
|
439
506
|
// Convert map to array, preserving priority order
|
|
440
507
|
const allTools = Array.from(toolMap.values());
|
|
441
|
-
// If we have step-specific tools, prioritize them
|
|
508
|
+
// If we have step-specific tools, prioritize them in the ordering
|
|
509
|
+
// (but transient tools that override step tools via same ID are already in the map)
|
|
442
510
|
if (resolvedTools.length > 0) {
|
|
443
511
|
// Add resolved step tools first, then other tools not already included
|
|
444
512
|
const stepToolIds = new Set(resolvedTools.map(t => t.id));
|
|
445
513
|
const otherTools = allTools.filter(t => !stepToolIds.has(t.id));
|
|
446
|
-
|
|
514
|
+
// For step tools, use the map version (which may be overridden by transient)
|
|
515
|
+
const finalStepTools = resolvedTools.map(t => toolMap.get(t.id) || t);
|
|
516
|
+
return [...finalStepTools, ...otherTools];
|
|
447
517
|
}
|
|
448
518
|
utils_1.logger.debug(`[ToolManager] Returning ${allTools.length} available tools`);
|
|
449
519
|
return allTools;
|
|
@@ -467,7 +537,7 @@ class ToolManager {
|
|
|
467
537
|
// Try primary tool with retries
|
|
468
538
|
for (let attempt = 0; attempt <= maxRetries; attempt++) {
|
|
469
539
|
try {
|
|
470
|
-
const tool = this.find(toolId, undefined, context?.step, context?.
|
|
540
|
+
const tool = this.find(toolId, undefined, context?.step, context?.flow);
|
|
471
541
|
if (!tool) {
|
|
472
542
|
// Tool not found - try fallback tools if available
|
|
473
543
|
if (fallbackTools.length > 0) {
|
|
@@ -579,7 +649,8 @@ class ToolManager {
|
|
|
579
649
|
}
|
|
580
650
|
}
|
|
581
651
|
// All attempts and fallbacks failed
|
|
582
|
-
throw new ToolExecutionError(`Tool execution failed
|
|
652
|
+
throw new ToolExecutionError(`[ToolExecutionError] Tool "${toolId}" execution failed: all ${maxRetries + 1} attempts exhausted${fallbackTools.length > 0 ? ` and fallback tools [${fallbackTools.join(', ')}] also failed` : ''}. ` +
|
|
653
|
+
`Check the tool handler for errors or increase maxRetries. Last error: ${lastError?.message || 'Unknown'}.`, toolId, { args, context, attempts: maxRetries + 1, fallbackTools }, lastError);
|
|
583
654
|
}
|
|
584
655
|
/**
|
|
585
656
|
* Determine if an error is transient and should be retried
|
|
@@ -617,6 +688,7 @@ class ToolManager {
|
|
|
617
688
|
};
|
|
618
689
|
}
|
|
619
690
|
// Build tool context with complete agent data
|
|
691
|
+
const collectedDirectives = [];
|
|
620
692
|
const toolContext = {
|
|
621
693
|
context,
|
|
622
694
|
updateContext,
|
|
@@ -633,16 +705,18 @@ class ToolManager {
|
|
|
633
705
|
},
|
|
634
706
|
hasField: (key) => {
|
|
635
707
|
return data != null && key in data;
|
|
708
|
+
},
|
|
709
|
+
dispatch: (directive) => {
|
|
710
|
+
collectedDirectives.push(directive);
|
|
636
711
|
}
|
|
637
712
|
};
|
|
638
713
|
utils_1.logger.debug(`[ToolManager] Executing tool: ${tool.id} with args:`, toolArguments);
|
|
639
|
-
//
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
const validation = await enhanced.validateInput(toolArguments, toolContext);
|
|
714
|
+
// Tool validation gate (Req 6.1, 6.7)
|
|
715
|
+
if (typeof tool.validateInput === 'function' && toolArguments) {
|
|
716
|
+
const validation = await tool.validateInput(toolArguments, toolContext);
|
|
643
717
|
if (!validation.valid) {
|
|
644
718
|
const executionTime = Date.now() - startTime;
|
|
645
|
-
utils_1.logger.warn(`[
|
|
719
|
+
utils_1.logger.warn(`[DataValidationError] Tool "${tool.id}" input validation failed: ${validation.error}. Fix the tool call arguments to match the expected schema.`);
|
|
646
720
|
return {
|
|
647
721
|
success: false,
|
|
648
722
|
error: `Validation failed: ${validation.error || 'Invalid input'}`,
|
|
@@ -650,12 +724,13 @@ class ToolManager {
|
|
|
650
724
|
};
|
|
651
725
|
}
|
|
652
726
|
}
|
|
653
|
-
//
|
|
654
|
-
|
|
655
|
-
|
|
727
|
+
// Tool permission gate (Req 6.7, 6.8)
|
|
728
|
+
// When denied: do not invoke handler, do not process directives, do not apply state writes
|
|
729
|
+
if (typeof tool.checkPermissions === 'function' && toolArguments) {
|
|
730
|
+
const permission = await tool.checkPermissions(toolArguments, toolContext);
|
|
656
731
|
if (!permission.allowed) {
|
|
657
732
|
const executionTime = Date.now() - startTime;
|
|
658
|
-
utils_1.logger.warn(`[
|
|
733
|
+
utils_1.logger.warn(`[ToolExecutionError] Tool "${tool.id}" permission denied: ${permission.reason}. The tool's checkPermissions hook rejected this call.`);
|
|
659
734
|
return {
|
|
660
735
|
success: false,
|
|
661
736
|
error: `Permission denied: ${permission.reason || 'Not allowed'}`,
|
|
@@ -681,7 +756,7 @@ class ToolManager {
|
|
|
681
756
|
utils_1.logger.debug(`[ToolManager] Tool ${tool.id} completed in ${executionTime}ms`);
|
|
682
757
|
// Handle different result types
|
|
683
758
|
let toolResult;
|
|
684
|
-
if (result && typeof result === 'object' && ('data' in result || 'success' in result || 'error' in result)) {
|
|
759
|
+
if (result && typeof result === 'object' && ('data' in result || 'success' in result || 'error' in result || 'directive' in result)) {
|
|
685
760
|
// It's already a ToolResult-like object
|
|
686
761
|
toolResult = result;
|
|
687
762
|
}
|
|
@@ -692,6 +767,10 @@ class ToolManager {
|
|
|
692
767
|
success: true
|
|
693
768
|
};
|
|
694
769
|
}
|
|
770
|
+
// Collect directive from ToolResult.directive (if present)
|
|
771
|
+
if (toolResult.directive) {
|
|
772
|
+
collectedDirectives.push(toolResult.directive);
|
|
773
|
+
}
|
|
695
774
|
// Apply data updates from tool result with validation
|
|
696
775
|
if (toolResult.dataUpdate) {
|
|
697
776
|
try {
|
|
@@ -699,7 +778,7 @@ class ToolManager {
|
|
|
699
778
|
await updateData(toolResult.dataUpdate);
|
|
700
779
|
}
|
|
701
780
|
else {
|
|
702
|
-
utils_1.logger.warn(`[
|
|
781
|
+
utils_1.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.`);
|
|
703
782
|
}
|
|
704
783
|
}
|
|
705
784
|
catch (updateError) {
|
|
@@ -718,7 +797,7 @@ class ToolManager {
|
|
|
718
797
|
await updateContext(toolResult.contextUpdate);
|
|
719
798
|
}
|
|
720
799
|
else {
|
|
721
|
-
utils_1.logger.warn(`[
|
|
800
|
+
utils_1.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.`);
|
|
722
801
|
}
|
|
723
802
|
}
|
|
724
803
|
catch (updateError) {
|
|
@@ -737,9 +816,10 @@ class ToolManager {
|
|
|
737
816
|
contextUpdate: toolResult.contextUpdate,
|
|
738
817
|
dataUpdate: toolResult.dataUpdate,
|
|
739
818
|
error: toolResult.error,
|
|
819
|
+
directives: collectedDirectives.length > 0 ? collectedDirectives : undefined,
|
|
740
820
|
metadata: {
|
|
741
821
|
toolId: tool.id,
|
|
742
|
-
toolName: tool.
|
|
822
|
+
toolName: tool.id,
|
|
743
823
|
executionTime,
|
|
744
824
|
...(toolResult.meta || {})
|
|
745
825
|
}
|
|
@@ -794,7 +874,7 @@ class ToolManager {
|
|
|
794
874
|
* Progress messages are yielded immediately.
|
|
795
875
|
*/
|
|
796
876
|
async *executeWithConcurrency(params) {
|
|
797
|
-
const { toolCalls, context, data, history, signal,
|
|
877
|
+
const { toolCalls, context, data, history, signal, flow, step } = params;
|
|
798
878
|
if (toolCalls.length === 0) {
|
|
799
879
|
return;
|
|
800
880
|
}
|
|
@@ -803,7 +883,7 @@ class ToolManager {
|
|
|
803
883
|
context,
|
|
804
884
|
data: data || {},
|
|
805
885
|
history: history || [],
|
|
806
|
-
step: step ? { id: step.id,
|
|
886
|
+
step: step ? { id: step.id, flowId: flow?.id || '' } : undefined,
|
|
807
887
|
updateContext: (updates) => {
|
|
808
888
|
Object.assign(context, updates);
|
|
809
889
|
return Promise.resolve();
|
|
@@ -826,18 +906,23 @@ class ToolManager {
|
|
|
826
906
|
hasField: (key) => {
|
|
827
907
|
return data != null && key in data;
|
|
828
908
|
},
|
|
909
|
+
dispatch: (_directive) => {
|
|
910
|
+
// Directives from concurrent execution are collected by the StreamingToolExecutor
|
|
911
|
+
// and surfaced via ToolExecutionUpdate. This is a no-op placeholder;
|
|
912
|
+
// full directive bus integration happens in ResponsePipeline (task 1.6).
|
|
913
|
+
},
|
|
829
914
|
};
|
|
830
915
|
const executor = new StreamingToolExecutor_1.StreamingToolExecutor(toolContext, {
|
|
831
916
|
signal,
|
|
832
917
|
});
|
|
833
918
|
// Resolve and queue each tool call
|
|
834
919
|
for (const toolCall of toolCalls) {
|
|
835
|
-
const tool = this.find(toolCall.toolName, undefined, step,
|
|
920
|
+
const tool = this.find(toolCall.toolName, undefined, step, flow);
|
|
836
921
|
if (!tool) {
|
|
837
|
-
utils_1.logger.warn(`[
|
|
922
|
+
utils_1.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.`);
|
|
838
923
|
continue;
|
|
839
924
|
}
|
|
840
|
-
//
|
|
925
|
+
// Tool carries all metadata fields directly — no cast needed
|
|
841
926
|
executor.addTool(toolCall, tool);
|
|
842
927
|
}
|
|
843
928
|
// Yield all results in order
|
|
@@ -852,7 +937,6 @@ class ToolManager {
|
|
|
852
937
|
this.validateDataEnrichmentConfig(config);
|
|
853
938
|
const tool = {
|
|
854
939
|
id: config.id,
|
|
855
|
-
name: config.name || `Data Enrichment: ${config.id}`,
|
|
856
940
|
description: config.description || `Enriches data fields: ${config.fields.join(', ')}`,
|
|
857
941
|
parameters: {
|
|
858
942
|
type: 'object',
|
|
@@ -891,7 +975,8 @@ class ToolManager {
|
|
|
891
975
|
catch (error) {
|
|
892
976
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
893
977
|
utils_1.logger.error(`[ToolManager] Data enrichment failed for ${config.id}: ${errorMessage}`);
|
|
894
|
-
throw new ToolExecutionError(`Data enrichment failed
|
|
978
|
+
throw new ToolExecutionError(`[ToolExecutionError] Data enrichment failed for tool "${config.id}": ${errorMessage}. ` +
|
|
979
|
+
`Check the enrichment handler and field references.`, config.id, { fields: config.fields }, error instanceof Error ? error : undefined);
|
|
895
980
|
}
|
|
896
981
|
}
|
|
897
982
|
};
|
|
@@ -906,7 +991,6 @@ class ToolManager {
|
|
|
906
991
|
this.validateValidationConfig(config);
|
|
907
992
|
const tool = {
|
|
908
993
|
id: config.id,
|
|
909
|
-
name: config.name || `Validation: ${config.id}`,
|
|
910
994
|
description: config.description || `Validates data fields: ${config.fields.join(', ')}`,
|
|
911
995
|
parameters: {
|
|
912
996
|
type: 'object',
|
|
@@ -963,7 +1047,6 @@ class ToolManager {
|
|
|
963
1047
|
this.validateApiCallConfig(config);
|
|
964
1048
|
const tool = {
|
|
965
1049
|
id: config.id,
|
|
966
|
-
name: config.name || `API Call: ${config.id}`,
|
|
967
1050
|
description: config.description || `Makes API call to external service`,
|
|
968
1051
|
parameters: {
|
|
969
1052
|
type: 'object',
|
|
@@ -1024,7 +1107,8 @@ class ToolManager {
|
|
|
1024
1107
|
catch (error) {
|
|
1025
1108
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1026
1109
|
utils_1.logger.error(`[ToolManager] API call failed for ${config.id}: ${errorMessage}`);
|
|
1027
|
-
throw new ToolExecutionError(`API call failed
|
|
1110
|
+
throw new ToolExecutionError(`[ToolExecutionError] API call failed for tool "${config.id}": ${errorMessage}. ` +
|
|
1111
|
+
`Check the endpoint URL, method, and network connectivity.`, config.id, { endpoint: config.endpoint, method: config.method, args }, error instanceof Error ? error : undefined);
|
|
1028
1112
|
}
|
|
1029
1113
|
}
|
|
1030
1114
|
};
|
|
@@ -1039,7 +1123,6 @@ class ToolManager {
|
|
|
1039
1123
|
this.validateComputationConfig(config);
|
|
1040
1124
|
const tool = {
|
|
1041
1125
|
id: config.id,
|
|
1042
|
-
name: config.name || `Computation: ${config.id}`,
|
|
1043
1126
|
description: config.description || `Performs computation on inputs: ${config.inputs.join(', ')}`,
|
|
1044
1127
|
parameters: {
|
|
1045
1128
|
type: 'object',
|
|
@@ -1071,7 +1154,8 @@ class ToolManager {
|
|
|
1071
1154
|
catch (error) {
|
|
1072
1155
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
1073
1156
|
utils_1.logger.error(`[ToolManager] Computation failed for ${config.id}: ${errorMessage}`);
|
|
1074
|
-
throw new ToolExecutionError(`Computation failed
|
|
1157
|
+
throw new ToolExecutionError(`[ToolExecutionError] Computation failed for tool "${config.id}": ${errorMessage}. ` +
|
|
1158
|
+
`Check the compute function and input field references.`, config.id, { inputs: config.inputs, args }, error instanceof Error ? error : undefined);
|
|
1075
1159
|
}
|
|
1076
1160
|
}
|
|
1077
1161
|
};
|
|
@@ -1080,8 +1164,8 @@ class ToolManager {
|
|
|
1080
1164
|
/**
|
|
1081
1165
|
* Get detailed information about a tool for debugging
|
|
1082
1166
|
*/
|
|
1083
|
-
getToolInfo(toolId, scope, step,
|
|
1084
|
-
const tool = this.find(toolId, scope, step,
|
|
1167
|
+
getToolInfo(toolId, scope, step, flow) {
|
|
1168
|
+
const tool = this.find(toolId, scope, step, flow);
|
|
1085
1169
|
if (!tool) {
|
|
1086
1170
|
return { found: false };
|
|
1087
1171
|
}
|
|
@@ -1090,20 +1174,20 @@ class ToolManager {
|
|
|
1090
1174
|
// Check step scope
|
|
1091
1175
|
if (step?.tools) {
|
|
1092
1176
|
const stepTool = step.tools.find((t) => (typeof t === 'string' && t === toolId) ||
|
|
1093
|
-
(typeof t === 'object' && (t.id === toolId
|
|
1177
|
+
(typeof t === 'object' && (t.id === toolId)));
|
|
1094
1178
|
if (stepTool)
|
|
1095
1179
|
foundScope = 'step';
|
|
1096
1180
|
}
|
|
1097
1181
|
// Check route scope
|
|
1098
|
-
if (foundScope === 'unknown' &&
|
|
1099
|
-
const
|
|
1100
|
-
if (
|
|
1101
|
-
foundScope = '
|
|
1182
|
+
if (foundScope === 'unknown' && flow?.tools) {
|
|
1183
|
+
const flowTool = flow.tools.find((t) => t.id === toolId);
|
|
1184
|
+
if (flowTool)
|
|
1185
|
+
foundScope = 'flow';
|
|
1102
1186
|
}
|
|
1103
1187
|
// Check agent scope
|
|
1104
1188
|
if (foundScope === 'unknown' && this.agent) {
|
|
1105
|
-
const agentTools = this.agent.
|
|
1106
|
-
const agentTool = agentTools.find((t) => t.id === toolId
|
|
1189
|
+
const agentTools = this.agent.tools;
|
|
1190
|
+
const agentTool = agentTools.find((t) => t.id === toolId);
|
|
1107
1191
|
if (agentTool)
|
|
1108
1192
|
foundScope = 'agent';
|
|
1109
1193
|
}
|
|
@@ -1117,7 +1201,6 @@ class ToolManager {
|
|
|
1117
1201
|
scope: foundScope,
|
|
1118
1202
|
metadata: {
|
|
1119
1203
|
id: tool.id,
|
|
1120
|
-
name: tool.name,
|
|
1121
1204
|
hasDescription: !!tool.description,
|
|
1122
1205
|
hasParameters: !!tool.parameters,
|
|
1123
1206
|
handlerLength: tool.handler.length
|
|
@@ -1127,12 +1210,12 @@ class ToolManager {
|
|
|
1127
1210
|
/**
|
|
1128
1211
|
* Validate that all tools in a list exist and are accessible
|
|
1129
1212
|
*/
|
|
1130
|
-
validateToolReferences(toolIds, step,
|
|
1213
|
+
validateToolReferences(toolIds, step, flow) {
|
|
1131
1214
|
const missing = [];
|
|
1132
1215
|
const found = [];
|
|
1133
1216
|
const details = [];
|
|
1134
1217
|
for (const toolId of toolIds) {
|
|
1135
|
-
const info = this.getToolInfo(toolId, types_1.ToolScope.ALL, step,
|
|
1218
|
+
const info = this.getToolInfo(toolId, types_1.ToolScope.ALL, step, flow);
|
|
1136
1219
|
if (info.found) {
|
|
1137
1220
|
found.push(toolId);
|
|
1138
1221
|
details.push({ id: toolId, found: true, scope: info.scope });
|