@falai/agent 2.6.1 → 3.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.
Files changed (611) hide show
  1. package/README.md +2 -2
  2. package/dist/adapters/MemoryAdapter.d.ts +1 -1
  3. package/dist/adapters/MemoryAdapter.d.ts.map +1 -1
  4. package/dist/adapters/MemoryAdapter.js +32 -36
  5. package/dist/adapters/MemoryAdapter.js.map +1 -1
  6. package/dist/adapters/MongoAdapter.d.ts +1 -1
  7. package/dist/adapters/MongoAdapter.d.ts.map +1 -1
  8. package/dist/adapters/MongoAdapter.js +2 -2
  9. package/dist/adapters/MongoAdapter.js.map +1 -1
  10. package/dist/adapters/OpenSearchAdapter.d.ts +1 -1
  11. package/dist/adapters/OpenSearchAdapter.d.ts.map +1 -1
  12. package/dist/adapters/OpenSearchAdapter.js +3 -3
  13. package/dist/adapters/OpenSearchAdapter.js.map +1 -1
  14. package/dist/adapters/PostgreSQLAdapter.d.ts +1 -1
  15. package/dist/adapters/PostgreSQLAdapter.d.ts.map +1 -1
  16. package/dist/adapters/PostgreSQLAdapter.js +18 -13
  17. package/dist/adapters/PostgreSQLAdapter.js.map +1 -1
  18. package/dist/adapters/PrismaAdapter.d.ts +1 -1
  19. package/dist/adapters/PrismaAdapter.d.ts.map +1 -1
  20. package/dist/adapters/PrismaAdapter.js +3 -3
  21. package/dist/adapters/PrismaAdapter.js.map +1 -1
  22. package/dist/adapters/RedisAdapter.d.ts +2 -1
  23. package/dist/adapters/RedisAdapter.d.ts.map +1 -1
  24. package/dist/adapters/RedisAdapter.js +77 -27
  25. package/dist/adapters/RedisAdapter.js.map +1 -1
  26. package/dist/adapters/SQLiteAdapter.d.ts +1 -1
  27. package/dist/adapters/SQLiteAdapter.d.ts.map +1 -1
  28. package/dist/adapters/SQLiteAdapter.js +9 -31
  29. package/dist/adapters/SQLiteAdapter.js.map +1 -1
  30. package/dist/adapters/index.d.ts +13 -13
  31. package/dist/adapters/index.d.ts.map +1 -1
  32. package/dist/adapters/index.js +7 -7
  33. package/dist/adapters/index.js.map +1 -1
  34. package/dist/adapters/sessionRow.d.ts +22 -0
  35. package/dist/adapters/sessionRow.d.ts.map +1 -0
  36. package/dist/adapters/sessionRow.js +48 -0
  37. package/dist/adapters/sessionRow.js.map +1 -0
  38. package/dist/cjs/adapters/MemoryAdapter.d.ts +1 -1
  39. package/dist/cjs/adapters/MemoryAdapter.d.ts.map +1 -1
  40. package/dist/cjs/adapters/MemoryAdapter.js +39 -43
  41. package/dist/cjs/adapters/MemoryAdapter.js.map +1 -1
  42. package/dist/cjs/adapters/MongoAdapter.d.ts +1 -1
  43. package/dist/cjs/adapters/MongoAdapter.d.ts.map +1 -1
  44. package/dist/cjs/adapters/MongoAdapter.js +4 -4
  45. package/dist/cjs/adapters/MongoAdapter.js.map +1 -1
  46. package/dist/cjs/adapters/OpenSearchAdapter.d.ts +1 -1
  47. package/dist/cjs/adapters/OpenSearchAdapter.d.ts.map +1 -1
  48. package/dist/cjs/adapters/OpenSearchAdapter.js +6 -6
  49. package/dist/cjs/adapters/OpenSearchAdapter.js.map +1 -1
  50. package/dist/cjs/adapters/PostgreSQLAdapter.d.ts +1 -1
  51. package/dist/cjs/adapters/PostgreSQLAdapter.d.ts.map +1 -1
  52. package/dist/cjs/adapters/PostgreSQLAdapter.js +20 -15
  53. package/dist/cjs/adapters/PostgreSQLAdapter.js.map +1 -1
  54. package/dist/cjs/adapters/PrismaAdapter.d.ts +1 -1
  55. package/dist/cjs/adapters/PrismaAdapter.d.ts.map +1 -1
  56. package/dist/cjs/adapters/PrismaAdapter.js +7 -7
  57. package/dist/cjs/adapters/PrismaAdapter.js.map +1 -1
  58. package/dist/cjs/adapters/RedisAdapter.d.ts +2 -1
  59. package/dist/cjs/adapters/RedisAdapter.d.ts.map +1 -1
  60. package/dist/cjs/adapters/RedisAdapter.js +81 -31
  61. package/dist/cjs/adapters/RedisAdapter.js.map +1 -1
  62. package/dist/cjs/adapters/SQLiteAdapter.d.ts +1 -1
  63. package/dist/cjs/adapters/SQLiteAdapter.d.ts.map +1 -1
  64. package/dist/cjs/adapters/SQLiteAdapter.js +11 -33
  65. package/dist/cjs/adapters/SQLiteAdapter.js.map +1 -1
  66. package/dist/cjs/adapters/index.d.ts +13 -13
  67. package/dist/cjs/adapters/index.d.ts.map +1 -1
  68. package/dist/cjs/adapters/index.js +14 -14
  69. package/dist/cjs/adapters/index.js.map +1 -1
  70. package/dist/cjs/adapters/sessionRow.d.ts +22 -0
  71. package/dist/cjs/adapters/sessionRow.d.ts.map +1 -0
  72. package/dist/cjs/adapters/sessionRow.js +52 -0
  73. package/dist/cjs/adapters/sessionRow.js.map +1 -0
  74. package/dist/cjs/core/Agent.d.ts +19 -11
  75. package/dist/cjs/core/Agent.d.ts.map +1 -1
  76. package/dist/cjs/core/Agent.js +102 -64
  77. package/dist/cjs/core/Agent.js.map +1 -1
  78. package/dist/cjs/core/AutoChainExecutor.d.ts +12 -22
  79. package/dist/cjs/core/AutoChainExecutor.d.ts.map +1 -1
  80. package/dist/cjs/core/AutoChainExecutor.js +46 -49
  81. package/dist/cjs/core/AutoChainExecutor.js.map +1 -1
  82. package/dist/cjs/core/BranchEvaluator.d.ts +4 -4
  83. package/dist/cjs/core/BranchEvaluator.d.ts.map +1 -1
  84. package/dist/cjs/core/BranchEvaluator.js +6 -6
  85. package/dist/cjs/core/BranchEvaluator.js.map +1 -1
  86. package/dist/cjs/core/CompactionEngine.d.ts +16 -3
  87. package/dist/cjs/core/CompactionEngine.d.ts.map +1 -1
  88. package/dist/cjs/core/CompactionEngine.js +30 -6
  89. package/dist/cjs/core/CompactionEngine.js.map +1 -1
  90. package/dist/cjs/core/DirectiveChainTracker.d.ts +1 -1
  91. package/dist/cjs/core/DirectiveChainTracker.d.ts.map +1 -1
  92. package/dist/cjs/core/DirectiveChainTracker.js +5 -5
  93. package/dist/cjs/core/DirectiveChainTracker.js.map +1 -1
  94. package/dist/cjs/core/Events.d.ts +1 -1
  95. package/dist/cjs/core/Events.d.ts.map +1 -1
  96. package/dist/cjs/core/Events.js +15 -15
  97. package/dist/cjs/core/Events.js.map +1 -1
  98. package/dist/cjs/core/Flow.d.ts +4 -4
  99. package/dist/cjs/core/Flow.d.ts.map +1 -1
  100. package/dist/cjs/core/Flow.js +15 -15
  101. package/dist/cjs/core/Flow.js.map +1 -1
  102. package/dist/cjs/core/FlowRouter.d.ts +4 -4
  103. package/dist/cjs/core/FlowRouter.d.ts.map +1 -1
  104. package/dist/cjs/core/FlowRouter.js +92 -70
  105. package/dist/cjs/core/FlowRouter.js.map +1 -1
  106. package/dist/cjs/core/PersistenceManager.d.ts +1 -1
  107. package/dist/cjs/core/PersistenceManager.d.ts.map +1 -1
  108. package/dist/cjs/core/PersistenceManager.js +10 -10
  109. package/dist/cjs/core/PersistenceManager.js.map +1 -1
  110. package/dist/cjs/core/PromptComposer.d.ts +4 -4
  111. package/dist/cjs/core/PromptComposer.d.ts.map +1 -1
  112. package/dist/cjs/core/PromptComposer.js +13 -13
  113. package/dist/cjs/core/PromptComposer.js.map +1 -1
  114. package/dist/cjs/core/PromptSectionCache.d.ts +2 -2
  115. package/dist/cjs/core/PromptSectionCache.d.ts.map +1 -1
  116. package/dist/cjs/core/ResponseEngine.d.ts +4 -4
  117. package/dist/cjs/core/ResponseEngine.d.ts.map +1 -1
  118. package/dist/cjs/core/ResponseEngine.js +7 -7
  119. package/dist/cjs/core/ResponseEngine.js.map +1 -1
  120. package/dist/cjs/core/ResponseGenerationError.d.ts.map +1 -1
  121. package/dist/cjs/core/ResponseGenerationError.js +3 -5
  122. package/dist/cjs/core/ResponseGenerationError.js.map +1 -1
  123. package/dist/cjs/core/ResponseModal.d.ts +39 -10
  124. package/dist/cjs/core/ResponseModal.d.ts.map +1 -1
  125. package/dist/cjs/core/ResponseModal.js +195 -72
  126. package/dist/cjs/core/ResponseModal.js.map +1 -1
  127. package/dist/cjs/core/ResponsePipeline.d.ts +50 -12
  128. package/dist/cjs/core/ResponsePipeline.d.ts.map +1 -1
  129. package/dist/cjs/core/ResponsePipeline.js +301 -158
  130. package/dist/cjs/core/ResponsePipeline.js.map +1 -1
  131. package/dist/cjs/core/SessionFinalizer.d.ts +4 -4
  132. package/dist/cjs/core/SessionFinalizer.d.ts.map +1 -1
  133. package/dist/cjs/core/SessionFinalizer.js +36 -9
  134. package/dist/cjs/core/SessionFinalizer.js.map +1 -1
  135. package/dist/cjs/core/SessionManager.d.ts +15 -6
  136. package/dist/cjs/core/SessionManager.d.ts.map +1 -1
  137. package/dist/cjs/core/SessionManager.js +49 -22
  138. package/dist/cjs/core/SessionManager.js.map +1 -1
  139. package/dist/cjs/core/SignalCoordinator.d.ts +5 -5
  140. package/dist/cjs/core/SignalCoordinator.d.ts.map +1 -1
  141. package/dist/cjs/core/SignalCoordinator.js +12 -12
  142. package/dist/cjs/core/SignalCoordinator.js.map +1 -1
  143. package/dist/cjs/core/SignalEvaluator.d.ts +4 -4
  144. package/dist/cjs/core/SignalEvaluator.d.ts.map +1 -1
  145. package/dist/cjs/core/SignalEvaluator.js +6 -6
  146. package/dist/cjs/core/SignalEvaluator.js.map +1 -1
  147. package/dist/cjs/core/SignalProcessor.d.ts +6 -6
  148. package/dist/cjs/core/SignalProcessor.d.ts.map +1 -1
  149. package/dist/cjs/core/SignalProcessor.js +17 -89
  150. package/dist/cjs/core/SignalProcessor.js.map +1 -1
  151. package/dist/cjs/core/Step.d.ts +5 -5
  152. package/dist/cjs/core/Step.d.ts.map +1 -1
  153. package/dist/cjs/core/Step.js +65 -17
  154. package/dist/cjs/core/Step.js.map +1 -1
  155. package/dist/cjs/core/StepLifecycle.d.ts +18 -8
  156. package/dist/cjs/core/StepLifecycle.d.ts.map +1 -1
  157. package/dist/cjs/core/StepLifecycle.js +103 -20
  158. package/dist/cjs/core/StepLifecycle.js.map +1 -1
  159. package/dist/cjs/core/StreamingToolExecutor.d.ts +1 -1
  160. package/dist/cjs/core/StreamingToolExecutor.d.ts.map +1 -1
  161. package/dist/cjs/core/StreamingToolExecutor.js +30 -6
  162. package/dist/cjs/core/StreamingToolExecutor.js.map +1 -1
  163. package/dist/cjs/core/ToolLoopExecutor.d.ts +8 -4
  164. package/dist/cjs/core/ToolLoopExecutor.d.ts.map +1 -1
  165. package/dist/cjs/core/ToolLoopExecutor.js +189 -97
  166. package/dist/cjs/core/ToolLoopExecutor.js.map +1 -1
  167. package/dist/cjs/core/ToolManager.d.ts +6 -6
  168. package/dist/cjs/core/ToolManager.d.ts.map +1 -1
  169. package/dist/cjs/core/ToolManager.js +102 -79
  170. package/dist/cjs/core/ToolManager.js.map +1 -1
  171. package/dist/cjs/core/createAgent.d.ts +2 -2
  172. package/dist/cjs/core/createAgent.d.ts.map +1 -1
  173. package/dist/cjs/core/createAgent.js +2 -2
  174. package/dist/cjs/core/createAgent.js.map +1 -1
  175. package/dist/cjs/core/flow-namespace.d.ts +16 -1
  176. package/dist/cjs/core/flow-namespace.d.ts.map +1 -1
  177. package/dist/cjs/core/flow-namespace.js +26 -4
  178. package/dist/cjs/core/flow-namespace.js.map +1 -1
  179. package/dist/cjs/core/toolGates.d.ts +1 -1
  180. package/dist/cjs/core/toolGates.d.ts.map +1 -1
  181. package/dist/cjs/core/toolGates.js +3 -3
  182. package/dist/cjs/core/toolGates.js.map +1 -1
  183. package/dist/cjs/index.d.ts +50 -45
  184. package/dist/cjs/index.d.ts.map +1 -1
  185. package/dist/cjs/index.js +96 -88
  186. package/dist/cjs/index.js.map +1 -1
  187. package/dist/cjs/providers/AnthropicProvider.d.ts +25 -35
  188. package/dist/cjs/providers/AnthropicProvider.d.ts.map +1 -1
  189. package/dist/cjs/providers/AnthropicProvider.js +30 -426
  190. package/dist/cjs/providers/AnthropicProvider.js.map +1 -1
  191. package/dist/cjs/providers/DeepSeekProvider.d.ts +13 -34
  192. package/dist/cjs/providers/DeepSeekProvider.d.ts.map +1 -1
  193. package/dist/cjs/providers/DeepSeekProvider.js +17 -51
  194. package/dist/cjs/providers/DeepSeekProvider.js.map +1 -1
  195. package/dist/cjs/providers/GeminiProvider.d.ts +22 -75
  196. package/dist/cjs/providers/GeminiProvider.d.ts.map +1 -1
  197. package/dist/cjs/providers/GeminiProvider.js +32 -558
  198. package/dist/cjs/providers/GeminiProvider.js.map +1 -1
  199. package/dist/cjs/providers/GenericOpenAICompatibleProvider.d.ts +9 -10
  200. package/dist/cjs/providers/GenericOpenAICompatibleProvider.d.ts.map +1 -1
  201. package/dist/cjs/providers/GenericOpenAICompatibleProvider.js +14 -20
  202. package/dist/cjs/providers/GenericOpenAICompatibleProvider.js.map +1 -1
  203. package/dist/cjs/providers/OpenAICompatibleProvider.d.ts +26 -135
  204. package/dist/cjs/providers/OpenAICompatibleProvider.d.ts.map +1 -1
  205. package/dist/cjs/providers/OpenAICompatibleProvider.js +40 -496
  206. package/dist/cjs/providers/OpenAICompatibleProvider.js.map +1 -1
  207. package/dist/cjs/providers/OpenAIProvider.d.ts +14 -20
  208. package/dist/cjs/providers/OpenAIProvider.d.ts.map +1 -1
  209. package/dist/cjs/providers/OpenAIProvider.js +21 -28
  210. package/dist/cjs/providers/OpenAIProvider.js.map +1 -1
  211. package/dist/cjs/providers/OpenRouterProvider.d.ts +20 -24
  212. package/dist/cjs/providers/OpenRouterProvider.d.ts.map +1 -1
  213. package/dist/cjs/providers/OpenRouterProvider.js +22 -38
  214. package/dist/cjs/providers/OpenRouterProvider.js.map +1 -1
  215. package/dist/cjs/providers/ProviderAdapter.d.ts +94 -0
  216. package/dist/cjs/providers/ProviderAdapter.d.ts.map +1 -0
  217. package/dist/cjs/providers/ProviderAdapter.js +257 -0
  218. package/dist/cjs/providers/ProviderAdapter.js.map +1 -0
  219. package/dist/cjs/providers/index.d.ts +21 -18
  220. package/dist/cjs/providers/index.d.ts.map +1 -1
  221. package/dist/cjs/providers/index.js +23 -21
  222. package/dist/cjs/providers/index.js.map +1 -1
  223. package/dist/cjs/types/agent.d.ts +37 -11
  224. package/dist/cjs/types/agent.d.ts.map +1 -1
  225. package/dist/cjs/types/ai.d.ts +11 -21
  226. package/dist/cjs/types/ai.d.ts.map +1 -1
  227. package/dist/cjs/types/compaction.d.ts +2 -2
  228. package/dist/cjs/types/compaction.d.ts.map +1 -1
  229. package/dist/cjs/types/errors.d.ts +16 -20
  230. package/dist/cjs/types/errors.d.ts.map +1 -1
  231. package/dist/cjs/types/errors.js +17 -18
  232. package/dist/cjs/types/errors.js.map +1 -1
  233. package/dist/cjs/types/flow.d.ts +56 -39
  234. package/dist/cjs/types/flow.d.ts.map +1 -1
  235. package/dist/cjs/types/history.d.ts +1 -1
  236. package/dist/cjs/types/history.d.ts.map +1 -1
  237. package/dist/cjs/types/index.d.ts +17 -17
  238. package/dist/cjs/types/index.d.ts.map +1 -1
  239. package/dist/cjs/types/index.js +14 -14
  240. package/dist/cjs/types/index.js.map +1 -1
  241. package/dist/cjs/types/persistence.d.ts +2 -2
  242. package/dist/cjs/types/persistence.d.ts.map +1 -1
  243. package/dist/cjs/types/session.d.ts +4 -4
  244. package/dist/cjs/types/session.d.ts.map +1 -1
  245. package/dist/cjs/types/signals.d.ts +3 -3
  246. package/dist/cjs/types/signals.d.ts.map +1 -1
  247. package/dist/cjs/types/template.d.ts +2 -2
  248. package/dist/cjs/types/template.d.ts.map +1 -1
  249. package/dist/cjs/types/tool.d.ts +4 -2
  250. package/dist/cjs/types/tool.d.ts.map +1 -1
  251. package/dist/cjs/types/tool.js.map +1 -1
  252. package/dist/cjs/utils/condition.d.ts +1 -1
  253. package/dist/cjs/utils/condition.d.ts.map +1 -1
  254. package/dist/cjs/utils/condition.js +6 -6
  255. package/dist/cjs/utils/condition.js.map +1 -1
  256. package/dist/cjs/utils/event.d.ts +1 -1
  257. package/dist/cjs/utils/event.d.ts.map +1 -1
  258. package/dist/cjs/utils/event.js +2 -2
  259. package/dist/cjs/utils/event.js.map +1 -1
  260. package/dist/cjs/utils/history.d.ts +2 -2
  261. package/dist/cjs/utils/history.d.ts.map +1 -1
  262. package/dist/cjs/utils/history.js +15 -15
  263. package/dist/cjs/utils/history.js.map +1 -1
  264. package/dist/cjs/utils/index.d.ts +11 -13
  265. package/dist/cjs/utils/index.d.ts.map +1 -1
  266. package/dist/cjs/utils/index.js +57 -58
  267. package/dist/cjs/utils/index.js.map +1 -1
  268. package/dist/cjs/utils/serialize.d.ts +17 -0
  269. package/dist/cjs/utils/serialize.d.ts.map +1 -1
  270. package/dist/cjs/utils/serialize.js +33 -0
  271. package/dist/cjs/utils/serialize.js.map +1 -1
  272. package/dist/cjs/utils/session.d.ts +23 -3
  273. package/dist/cjs/utils/session.d.ts.map +1 -1
  274. package/dist/cjs/utils/session.js +40 -8
  275. package/dist/cjs/utils/session.js.map +1 -1
  276. package/dist/cjs/utils/template.d.ts +3 -3
  277. package/dist/cjs/utils/template.d.ts.map +1 -1
  278. package/dist/cjs/utils/template.js +5 -5
  279. package/dist/cjs/utils/template.js.map +1 -1
  280. package/dist/constants/index.d.ts +1 -0
  281. package/dist/constants/index.js +1 -1
  282. package/dist/core/Agent.d.ts +19 -11
  283. package/dist/core/Agent.d.ts.map +1 -1
  284. package/dist/core/Agent.js +53 -15
  285. package/dist/core/Agent.js.map +1 -1
  286. package/dist/core/AutoChainExecutor.d.ts +12 -22
  287. package/dist/core/AutoChainExecutor.d.ts.map +1 -1
  288. package/dist/core/AutoChainExecutor.js +27 -30
  289. package/dist/core/AutoChainExecutor.js.map +1 -1
  290. package/dist/core/BranchEvaluator.d.ts +4 -4
  291. package/dist/core/BranchEvaluator.d.ts.map +1 -1
  292. package/dist/core/BranchEvaluator.js +2 -2
  293. package/dist/core/BranchEvaluator.js.map +1 -1
  294. package/dist/core/CompactionEngine.d.ts +16 -3
  295. package/dist/core/CompactionEngine.d.ts.map +1 -1
  296. package/dist/core/CompactionEngine.js +30 -6
  297. package/dist/core/CompactionEngine.js.map +1 -1
  298. package/dist/core/DirectiveChainTracker.d.ts +1 -1
  299. package/dist/core/DirectiveChainTracker.d.ts.map +1 -1
  300. package/dist/core/DirectiveChainTracker.js +2 -2
  301. package/dist/core/DirectiveChainTracker.js.map +1 -1
  302. package/dist/core/Events.d.ts +1 -1
  303. package/dist/core/Events.d.ts.map +1 -1
  304. package/dist/core/Events.js +1 -1
  305. package/dist/core/Events.js.map +1 -1
  306. package/dist/core/Flow.d.ts +4 -4
  307. package/dist/core/Flow.d.ts.map +1 -1
  308. package/dist/core/Flow.js +3 -3
  309. package/dist/core/Flow.js.map +1 -1
  310. package/dist/core/FlowRouter.d.ts +4 -4
  311. package/dist/core/FlowRouter.d.ts.map +1 -1
  312. package/dist/core/FlowRouter.js +36 -14
  313. package/dist/core/FlowRouter.js.map +1 -1
  314. package/dist/core/PersistenceManager.d.ts +1 -1
  315. package/dist/core/PersistenceManager.d.ts.map +1 -1
  316. package/dist/core/PersistenceManager.js +3 -3
  317. package/dist/core/PersistenceManager.js.map +1 -1
  318. package/dist/core/PromptComposer.d.ts +4 -4
  319. package/dist/core/PromptComposer.d.ts.map +1 -1
  320. package/dist/core/PromptComposer.js +3 -3
  321. package/dist/core/PromptComposer.js.map +1 -1
  322. package/dist/core/PromptSectionCache.d.ts +2 -2
  323. package/dist/core/PromptSectionCache.d.ts.map +1 -1
  324. package/dist/core/ResponseEngine.d.ts +4 -4
  325. package/dist/core/ResponseEngine.d.ts.map +1 -1
  326. package/dist/core/ResponseEngine.js +2 -2
  327. package/dist/core/ResponseEngine.js.map +1 -1
  328. package/dist/core/ResponseGenerationError.d.ts.map +1 -1
  329. package/dist/core/ResponseGenerationError.js +3 -5
  330. package/dist/core/ResponseGenerationError.js.map +1 -1
  331. package/dist/core/ResponseModal.d.ts +39 -10
  332. package/dist/core/ResponseModal.d.ts.map +1 -1
  333. package/dist/core/ResponseModal.js +152 -29
  334. package/dist/core/ResponseModal.js.map +1 -1
  335. package/dist/core/ResponsePipeline.d.ts +50 -12
  336. package/dist/core/ResponsePipeline.d.ts.map +1 -1
  337. package/dist/core/ResponsePipeline.js +232 -89
  338. package/dist/core/ResponsePipeline.js.map +1 -1
  339. package/dist/core/SessionFinalizer.d.ts +4 -4
  340. package/dist/core/SessionFinalizer.d.ts.map +1 -1
  341. package/dist/core/SessionFinalizer.js +32 -5
  342. package/dist/core/SessionFinalizer.js.map +1 -1
  343. package/dist/core/SessionManager.d.ts +15 -6
  344. package/dist/core/SessionManager.d.ts.map +1 -1
  345. package/dist/core/SessionManager.js +46 -19
  346. package/dist/core/SessionManager.js.map +1 -1
  347. package/dist/core/SignalCoordinator.d.ts +5 -5
  348. package/dist/core/SignalCoordinator.d.ts.map +1 -1
  349. package/dist/core/SignalCoordinator.js +2 -2
  350. package/dist/core/SignalCoordinator.js.map +1 -1
  351. package/dist/core/SignalEvaluator.d.ts +4 -4
  352. package/dist/core/SignalEvaluator.d.ts.map +1 -1
  353. package/dist/core/SignalEvaluator.js +2 -2
  354. package/dist/core/SignalEvaluator.js.map +1 -1
  355. package/dist/core/SignalProcessor.d.ts +6 -6
  356. package/dist/core/SignalProcessor.d.ts.map +1 -1
  357. package/dist/core/SignalProcessor.js +7 -79
  358. package/dist/core/SignalProcessor.js.map +1 -1
  359. package/dist/core/Step.d.ts +5 -5
  360. package/dist/core/Step.d.ts.map +1 -1
  361. package/dist/core/Step.js +53 -5
  362. package/dist/core/Step.js.map +1 -1
  363. package/dist/core/StepLifecycle.d.ts +18 -8
  364. package/dist/core/StepLifecycle.d.ts.map +1 -1
  365. package/dist/core/StepLifecycle.js +98 -15
  366. package/dist/core/StepLifecycle.js.map +1 -1
  367. package/dist/core/StreamingToolExecutor.d.ts +1 -1
  368. package/dist/core/StreamingToolExecutor.d.ts.map +1 -1
  369. package/dist/core/StreamingToolExecutor.js +29 -5
  370. package/dist/core/StreamingToolExecutor.js.map +1 -1
  371. package/dist/core/ToolLoopExecutor.d.ts +8 -4
  372. package/dist/core/ToolLoopExecutor.d.ts.map +1 -1
  373. package/dist/core/ToolLoopExecutor.js +157 -65
  374. package/dist/core/ToolLoopExecutor.js.map +1 -1
  375. package/dist/core/ToolManager.d.ts +6 -6
  376. package/dist/core/ToolManager.d.ts.map +1 -1
  377. package/dist/core/ToolManager.js +44 -21
  378. package/dist/core/ToolManager.js.map +1 -1
  379. package/dist/core/createAgent.d.ts +2 -2
  380. package/dist/core/createAgent.d.ts.map +1 -1
  381. package/dist/core/createAgent.js +1 -1
  382. package/dist/core/createAgent.js.map +1 -1
  383. package/dist/core/flow-namespace.d.ts +16 -1
  384. package/dist/core/flow-namespace.d.ts.map +1 -1
  385. package/dist/core/flow-namespace.js +23 -1
  386. package/dist/core/flow-namespace.js.map +1 -1
  387. package/dist/core/toolGates.d.ts +1 -1
  388. package/dist/core/toolGates.d.ts.map +1 -1
  389. package/dist/core/toolGates.js +1 -1
  390. package/dist/core/toolGates.js.map +1 -1
  391. package/dist/index.d.ts +50 -45
  392. package/dist/index.d.ts.map +1 -1
  393. package/dist/index.js +34 -30
  394. package/dist/index.js.map +1 -1
  395. package/dist/providers/AnthropicProvider.d.ts +25 -35
  396. package/dist/providers/AnthropicProvider.d.ts.map +1 -1
  397. package/dist/providers/AnthropicProvider.js +30 -423
  398. package/dist/providers/AnthropicProvider.js.map +1 -1
  399. package/dist/providers/DeepSeekProvider.d.ts +13 -34
  400. package/dist/providers/DeepSeekProvider.d.ts.map +1 -1
  401. package/dist/providers/DeepSeekProvider.js +16 -47
  402. package/dist/providers/DeepSeekProvider.js.map +1 -1
  403. package/dist/providers/GeminiProvider.d.ts +22 -75
  404. package/dist/providers/GeminiProvider.d.ts.map +1 -1
  405. package/dist/providers/GeminiProvider.js +32 -558
  406. package/dist/providers/GeminiProvider.js.map +1 -1
  407. package/dist/providers/GenericOpenAICompatibleProvider.d.ts +9 -10
  408. package/dist/providers/GenericOpenAICompatibleProvider.d.ts.map +1 -1
  409. package/dist/providers/GenericOpenAICompatibleProvider.js +13 -16
  410. package/dist/providers/GenericOpenAICompatibleProvider.js.map +1 -1
  411. package/dist/providers/OpenAICompatibleProvider.d.ts +26 -135
  412. package/dist/providers/OpenAICompatibleProvider.d.ts.map +1 -1
  413. package/dist/providers/OpenAICompatibleProvider.js +39 -495
  414. package/dist/providers/OpenAICompatibleProvider.js.map +1 -1
  415. package/dist/providers/OpenAIProvider.d.ts +14 -20
  416. package/dist/providers/OpenAIProvider.d.ts.map +1 -1
  417. package/dist/providers/OpenAIProvider.js +20 -24
  418. package/dist/providers/OpenAIProvider.js.map +1 -1
  419. package/dist/providers/OpenRouterProvider.d.ts +20 -24
  420. package/dist/providers/OpenRouterProvider.d.ts.map +1 -1
  421. package/dist/providers/OpenRouterProvider.js +21 -34
  422. package/dist/providers/OpenRouterProvider.js.map +1 -1
  423. package/dist/providers/ProviderAdapter.d.ts +94 -0
  424. package/dist/providers/ProviderAdapter.d.ts.map +1 -0
  425. package/dist/providers/ProviderAdapter.js +251 -0
  426. package/dist/providers/ProviderAdapter.js.map +1 -0
  427. package/dist/providers/index.d.ts +21 -18
  428. package/dist/providers/index.d.ts.map +1 -1
  429. package/dist/providers/index.js +13 -10
  430. package/dist/providers/index.js.map +1 -1
  431. package/dist/types/agent.d.ts +37 -11
  432. package/dist/types/agent.d.ts.map +1 -1
  433. package/dist/types/ai.d.ts +11 -21
  434. package/dist/types/ai.d.ts.map +1 -1
  435. package/dist/types/compaction.d.ts +2 -2
  436. package/dist/types/compaction.d.ts.map +1 -1
  437. package/dist/types/errors.d.ts +16 -20
  438. package/dist/types/errors.d.ts.map +1 -1
  439. package/dist/types/errors.js +15 -16
  440. package/dist/types/errors.js.map +1 -1
  441. package/dist/types/flow.d.ts +56 -39
  442. package/dist/types/flow.d.ts.map +1 -1
  443. package/dist/types/history.d.ts +1 -1
  444. package/dist/types/history.d.ts.map +1 -1
  445. package/dist/types/index.d.ts +17 -17
  446. package/dist/types/index.d.ts.map +1 -1
  447. package/dist/types/index.js +4 -4
  448. package/dist/types/index.js.map +1 -1
  449. package/dist/types/persistence.d.ts +2 -2
  450. package/dist/types/persistence.d.ts.map +1 -1
  451. package/dist/types/session.d.ts +4 -4
  452. package/dist/types/session.d.ts.map +1 -1
  453. package/dist/types/signals.d.ts +3 -3
  454. package/dist/types/signals.d.ts.map +1 -1
  455. package/dist/types/template.d.ts +2 -2
  456. package/dist/types/template.d.ts.map +1 -1
  457. package/dist/types/tool.d.ts +4 -2
  458. package/dist/types/tool.d.ts.map +1 -1
  459. package/dist/types/tool.js.map +1 -1
  460. package/dist/utils/condition.d.ts +1 -1
  461. package/dist/utils/condition.d.ts.map +1 -1
  462. package/dist/utils/condition.js +2 -2
  463. package/dist/utils/condition.js.map +1 -1
  464. package/dist/utils/event.d.ts +1 -1
  465. package/dist/utils/event.d.ts.map +1 -1
  466. package/dist/utils/event.js +1 -1
  467. package/dist/utils/event.js.map +1 -1
  468. package/dist/utils/history.d.ts +2 -2
  469. package/dist/utils/history.d.ts.map +1 -1
  470. package/dist/utils/history.js +1 -1
  471. package/dist/utils/history.js.map +1 -1
  472. package/dist/utils/index.d.ts +11 -13
  473. package/dist/utils/index.d.ts.map +1 -1
  474. package/dist/utils/index.js +11 -12
  475. package/dist/utils/index.js.map +1 -1
  476. package/dist/utils/serialize.d.ts +17 -0
  477. package/dist/utils/serialize.d.ts.map +1 -1
  478. package/dist/utils/serialize.js +31 -0
  479. package/dist/utils/serialize.js.map +1 -1
  480. package/dist/utils/session.d.ts +23 -3
  481. package/dist/utils/session.d.ts.map +1 -1
  482. package/dist/utils/session.js +35 -6
  483. package/dist/utils/session.js.map +1 -1
  484. package/dist/utils/template.d.ts +3 -3
  485. package/dist/utils/template.d.ts.map +1 -1
  486. package/dist/utils/template.js +1 -1
  487. package/dist/utils/template.js.map +1 -1
  488. package/docs/concepts/architecture.md +3 -3
  489. package/docs/concepts/directives.md +1 -1
  490. package/docs/guides/error-handling.md +46 -45
  491. package/docs/guides/flow-control.md +8 -1
  492. package/docs/guides/instructions.md +15 -6
  493. package/docs/guides/persistence.md +12 -5
  494. package/docs/guides/streaming.md +10 -0
  495. package/docs/migration/README.md +4 -0
  496. package/docs/migration/v2-3-to-v2-4.md +4 -0
  497. package/docs/migration/v2-6-to-v2-7.md +246 -0
  498. package/docs/reference/adapters.md +15 -1
  499. package/docs/reference/branches.md +2 -0
  500. package/docs/reference/create-agent.md +28 -0
  501. package/docs/reference/directive.md +1 -1
  502. package/docs/reference/errors.md +30 -32
  503. package/docs/reference/providers.md +63 -60
  504. package/docs/reference/step.md +28 -21
  505. package/docs/reference/tool.md +14 -5
  506. package/docs/start/02-first-agent.md +8 -4
  507. package/docs/start/03-collect-data.md +19 -10
  508. package/examples/01-quickstart.ts +2 -2
  509. package/examples/02-data-extraction.ts +1 -1
  510. package/examples/03-tools.ts +1 -1
  511. package/examples/04-instructions.ts +2 -2
  512. package/examples/05-branching.ts +3 -3
  513. package/examples/06-flow-control.ts +3 -3
  514. package/examples/07-streaming.ts +1 -1
  515. package/examples/08-persistence.ts +2 -2
  516. package/examples/09-signals.ts +1 -1
  517. package/examples/tsconfig.json +6 -3
  518. package/package.json +9 -7
  519. package/src/adapters/MemoryAdapter.ts +33 -37
  520. package/src/adapters/MongoAdapter.ts +3 -3
  521. package/src/adapters/OpenSearchAdapter.ts +4 -4
  522. package/src/adapters/PostgreSQLAdapter.ts +26 -21
  523. package/src/adapters/PrismaAdapter.ts +4 -4
  524. package/src/adapters/RedisAdapter.ts +84 -37
  525. package/src/adapters/SQLiteAdapter.ts +13 -34
  526. package/src/adapters/index.ts +13 -13
  527. package/src/adapters/sessionRow.ts +57 -0
  528. package/src/core/Agent.ts +64 -18
  529. package/src/core/AutoChainExecutor.ts +44 -57
  530. package/src/core/BranchEvaluator.ts +5 -5
  531. package/src/core/CompactionEngine.ts +42 -8
  532. package/src/core/DirectiveChainTracker.ts +3 -3
  533. package/src/core/Events.ts +2 -2
  534. package/src/core/Flow.ts +9 -9
  535. package/src/core/FlowRouter.ts +46 -20
  536. package/src/core/PersistenceManager.ts +4 -4
  537. package/src/core/PromptComposer.ts +8 -8
  538. package/src/core/PromptSectionCache.ts +2 -2
  539. package/src/core/ResponseEngine.ts +6 -6
  540. package/src/core/ResponseGenerationError.ts +3 -6
  541. package/src/core/ResponseModal.ts +205 -39
  542. package/src/core/ResponsePipeline.ts +301 -107
  543. package/src/core/SessionFinalizer.ts +40 -10
  544. package/src/core/SessionManager.ts +61 -27
  545. package/src/core/SignalCoordinator.ts +7 -7
  546. package/src/core/SignalEvaluator.ts +6 -6
  547. package/src/core/SignalProcessor.ts +13 -93
  548. package/src/core/Step.ts +87 -10
  549. package/src/core/StepLifecycle.ts +129 -26
  550. package/src/core/StreamingToolExecutor.ts +33 -8
  551. package/src/core/ToolLoopExecutor.ts +206 -80
  552. package/src/core/ToolManager.ts +53 -26
  553. package/src/core/createAgent.ts +2 -2
  554. package/src/core/flow-namespace.ts +31 -2
  555. package/src/core/toolGates.ts +2 -2
  556. package/src/index.ts +59 -45
  557. package/src/providers/AnthropicProvider.ts +44 -595
  558. package/src/providers/DeepSeekProvider.ts +27 -92
  559. package/src/providers/GeminiProvider.ts +41 -752
  560. package/src/providers/GenericOpenAICompatibleProvider.ts +19 -27
  561. package/src/providers/OpenAICompatibleProvider.ts +58 -764
  562. package/src/providers/OpenAIProvider.ts +31 -55
  563. package/src/providers/OpenRouterProvider.ts +40 -70
  564. package/src/providers/ProviderAdapter.ts +368 -0
  565. package/src/providers/index.ts +21 -23
  566. package/src/types/agent.ts +36 -11
  567. package/src/types/ai.ts +11 -21
  568. package/src/types/compaction.ts +2 -2
  569. package/src/types/errors.ts +17 -35
  570. package/src/types/flow.ts +44 -46
  571. package/src/types/history.ts +1 -1
  572. package/src/types/index.ts +18 -17
  573. package/src/types/persistence.ts +2 -2
  574. package/src/types/session.ts +4 -4
  575. package/src/types/signals.ts +3 -3
  576. package/src/types/template.ts +2 -2
  577. package/src/types/tool.ts +4 -2
  578. package/src/utils/condition.ts +3 -3
  579. package/src/utils/event.ts +1 -1
  580. package/src/utils/history.ts +3 -3
  581. package/src/utils/index.ts +14 -15
  582. package/src/utils/serialize.ts +38 -0
  583. package/src/utils/session.ts +46 -9
  584. package/src/utils/template.ts +3 -3
  585. package/dist/cjs/core/DirectiveBus.d.ts +0 -88
  586. package/dist/cjs/core/DirectiveBus.d.ts.map +0 -1
  587. package/dist/cjs/core/DirectiveBus.js +0 -196
  588. package/dist/cjs/core/DirectiveBus.js.map +0 -1
  589. package/dist/cjs/providers/errorClassification.d.ts +0 -61
  590. package/dist/cjs/providers/errorClassification.d.ts.map +0 -1
  591. package/dist/cjs/providers/errorClassification.js +0 -123
  592. package/dist/cjs/providers/errorClassification.js.map +0 -1
  593. package/dist/cjs/utils/retry.d.ts +0 -67
  594. package/dist/cjs/utils/retry.d.ts.map +0 -1
  595. package/dist/cjs/utils/retry.js +0 -201
  596. package/dist/cjs/utils/retry.js.map +0 -1
  597. package/dist/core/DirectiveBus.d.ts +0 -88
  598. package/dist/core/DirectiveBus.d.ts.map +0 -1
  599. package/dist/core/DirectiveBus.js +0 -192
  600. package/dist/core/DirectiveBus.js.map +0 -1
  601. package/dist/providers/errorClassification.d.ts +0 -61
  602. package/dist/providers/errorClassification.d.ts.map +0 -1
  603. package/dist/providers/errorClassification.js +0 -116
  604. package/dist/providers/errorClassification.js.map +0 -1
  605. package/dist/utils/retry.d.ts +0 -67
  606. package/dist/utils/retry.d.ts.map +0 -1
  607. package/dist/utils/retry.js +0 -193
  608. package/dist/utils/retry.js.map +0 -1
  609. package/src/core/DirectiveBus.ts +0 -248
  610. package/src/providers/errorClassification.ts +0 -172
  611. package/src/utils/retry.ts +0 -274
@@ -2,17 +2,17 @@
2
2
  * Agent-related type definitions
3
3
  */
4
4
 
5
- import type { AgentStructuredResponse, AiProvider } from "./ai";
6
- import type { Tool } from "./tool";
7
- import type { Directive, FlowOptions, StepRef, StoppedReason } from "./flow";
8
- import type { PersistenceConfig } from "./persistence";
9
- import type { SessionState } from "./session";
10
- import type { Signal, SignalFiring } from "./signals";
11
- import type { StructuredSchema } from "./schema";
12
- import type { Event } from "./history";
13
- import type { Template } from "./template";
14
- import type { ConditionWhen, ConditionIf } from "./flow";
15
- import type { PromptCacheConfig } from "./prompt-cache";
5
+ import type { AgentStructuredResponse, AiProvider } from "./ai.js";
6
+ import type { Tool } from "./tool.js";
7
+ import type { Directive, FlowOptions, StepRef, StoppedReason } from "./flow.js";
8
+ import type { PersistenceConfig } from "./persistence.js";
9
+ import type { SessionState } from "./session.js";
10
+ import type { Signal, SignalFiring } from "./signals.js";
11
+ import type { StructuredSchema } from "./schema.js";
12
+ import type { Event } from "./history.js";
13
+ import type { Template } from "./template.js";
14
+ import type { ConditionWhen, ConditionIf } from "./flow.js";
15
+ import type { PromptCacheConfig } from "./prompt-cache.js";
16
16
 
17
17
  /**
18
18
  * Context passed to every lifecycle hook (flow and step).
@@ -126,6 +126,13 @@ export interface AgentOptions<TContext = unknown, TData = unknown> {
126
126
  * Rendered into the system prompt as "who you are and how you communicate."
127
127
  */
128
128
  persona?: Template<TContext>;
129
+ /**
130
+ * Hard bound on session.history length (default: 400). The oldest entries
131
+ * are trimmed — never splitting an assistant/tool pair — when the bound is
132
+ * exceeded and no compaction strategy shrank the history first. Set 0 to
133
+ * disable bounding entirely.
134
+ */
135
+ maxHistoryMessages?: number;
129
136
  /** Enable debug logging */
130
137
  debug?: boolean;
131
138
  /** Default context data available to the agent */
@@ -330,6 +337,13 @@ export interface AppliedInstruction {
330
337
  scopeRef?: string;
331
338
  }
332
339
 
340
+ /** A flow that left its active position during a turn. */
341
+ export interface EndedFlow {
342
+ flowId: string;
343
+ title?: string;
344
+ reason: StoppedReason;
345
+ }
346
+
333
347
  export interface AgentResponse<TData = Record<string, unknown>> {
334
348
  message: string;
335
349
  session?: SessionState<TData>;
@@ -350,6 +364,17 @@ export interface AgentResponse<TData = Record<string, unknown>> {
350
364
  * Mirrors the observability framing of `executedSteps` and `appliedInstructions`.
351
365
  */
352
366
  triggeredSignals?: SignalFiring<unknown, TData>[];
367
+ /**
368
+ * Provider-reported usage for this turn's primary generation (routing and
369
+ * extraction sub-calls are not included).
370
+ */
371
+ metadata?: { tokensUsed?: number };
372
+ /**
373
+ * Flows that LEFT their active position this turn — completions, redirects,
374
+ * resets. planTurn knows these internally; surfaced so consumers stop
375
+ * re-deriving them from executedSteps + session cursor inspection.
376
+ */
377
+ endedFlows?: EndedFlow[];
353
378
  }
354
379
 
355
380
  export interface AgentResponseStreamChunk<TData = Record<string, unknown>> {
package/src/types/ai.ts CHANGED
@@ -2,31 +2,21 @@
2
2
  * AI provider types
3
3
  */
4
4
 
5
- import type { HistoryItem } from "./history";
5
+ import type { Effort } from "@providerkit/core";
6
+ import type { HistoryItem } from "./history.js";
6
7
 
7
8
  /**
8
- * Reasoning/thinking configuration for AI models
9
+ * How hard the model thinks before answering.
10
+ *
11
+ * v3 takes `@providerkit/core`'s effort union, which every provider speaks:
12
+ * "none" | "low" | "medium" | "high" | "max". Absent means the provider's own
13
+ * default and is never sent. v2's "minimal" is spelled "low"; `summary` and
14
+ * `includeThoughts` are gone because they are no longer choices — the shapes
15
+ * that need them get them switched on whenever an effort is set, which is the
16
+ * only setting that ever produced reasoning output.
9
17
  */
10
18
  export interface ReasoningConfig {
11
- /**
12
- * Effort level for reasoning models (OpenAI: gpt-5, o-series)
13
- * - minimal: Fastest, least reasoning
14
- * - low: Basic reasoning
15
- * - medium: Balanced reasoning
16
- * - high: Maximum reasoning effort
17
- */
18
- effort?: "minimal" | "low" | "medium" | "high";
19
- /**
20
- * Summary detail level of reasoning process
21
- * - auto: Model decides
22
- * - concise: Brief summary
23
- * - detailed: Full reasoning details
24
- */
25
- summary?: "auto" | "concise" | "detailed";
26
- /**
27
- * Whether to include thinking/reasoning in response (Gemini)
28
- */
29
- includeThoughts?: boolean;
19
+ effort?: Effort;
30
20
  }
31
21
 
32
22
  /**
@@ -2,8 +2,8 @@
2
2
  * Context compaction types for managing conversation history size
3
3
  */
4
4
 
5
- import type { AiProvider } from "./ai";
6
- import type { HistoryItem } from "./history";
5
+ import type { AiProvider } from "./ai.js";
6
+ import type { HistoryItem } from "./history.js";
7
7
 
8
8
  /**
9
9
  * Configuration for the compaction engine.
@@ -2,6 +2,23 @@
2
2
  * Typed error classes for @falai/agent.
3
3
  */
4
4
 
5
+ /**
6
+ * The normalized provider failure, and the kinds it comes in.
7
+ *
8
+ * v3 re-exports these from `@providerkit/core` rather than keeping a second
9
+ * copy. The taxonomy is wider there — thirteen kinds named by what actually
10
+ * fixes them, where this package had eight — so a caller can now tell an
11
+ * exhausted balance from a per-minute throttle, a plan that never included the
12
+ * API from a wrong key, and an outgrown context window from a bad request.
13
+ *
14
+ * Breaking: the kind lives on `error.kind`, not `error.code`, and the spellings
15
+ * changed with the taxonomy (`rate_limited` is `rate`, `overloaded` is
16
+ * `overload`, `invalid_request` splits into `invalid`, `context`, `model` and
17
+ * `content`). `schema_rejected` is gone: nothing ever produced it.
18
+ */
19
+ export { ProviderError } from "@providerkit/core";
20
+ export type { ErrorKind } from "@providerkit/core";
21
+
5
22
  /**
6
23
  * Typed error for not-yet-implemented surface. Subclass of Error (not of
7
24
  * FlowConfigurationError) so handlers can distinguish "not yet built" from
@@ -17,41 +34,6 @@ export class NotImplementedError extends Error {
17
34
  }
18
35
  }
19
36
 
20
- /**
21
- * Normalized error codes for AI provider failures.
22
- *
23
- * Providers map their SDK/HTTP errors onto these codes so callers can
24
- * handle failures uniformly regardless of which provider is configured.
25
- */
26
- export type ProviderErrorCode =
27
- | 'rate_limited'
28
- | 'overloaded'
29
- | 'auth'
30
- | 'invalid_request'
31
- | 'schema_rejected'
32
- | 'timeout'
33
- | 'network'
34
- | 'unknown';
35
-
36
- /**
37
- * Normalized error thrown by AI providers for terminal failures — i.e.
38
- * after retries and backup models (if any) have been exhausted.
39
- *
40
- * The original SDK/HTTP error is preserved as `cause` for debugging and
41
- * provider-specific handling.
42
- */
43
- export class ProviderError extends Error {
44
- constructor(
45
- public readonly code: ProviderErrorCode,
46
- public readonly provider: string,
47
- message: string,
48
- public readonly cause?: unknown,
49
- ) {
50
- super(message);
51
- this.name = 'ProviderError';
52
- }
53
- }
54
-
55
37
  /**
56
38
  * Thrown by the persistence layer when a session save carries a stale
57
39
  * `version` — i.e. another writer persisted the session after this one
package/src/types/flow.ts CHANGED
@@ -2,10 +2,10 @@
2
2
  * Flow/Journey DSL type definitions
3
3
  */
4
4
 
5
- import type { Tool } from "./tool";
6
- import type { StructuredSchema } from "./schema";
7
- import type { Instruction, HookContext, ExitReason } from "./agent";
8
- import type { Template } from "./template";
5
+ import type { Tool } from "./tool.js";
6
+ import type { StructuredSchema } from "./schema.js";
7
+ import type { Instruction, HookContext, ExitReason } from "./agent.js";
8
+ import type { Template } from "./template.js";
9
9
 
10
10
  // ─── Condition types (v2 when/if split) ──────────────────────────────────────
11
11
 
@@ -14,7 +14,7 @@ import type { Template } from "./template";
14
14
  * May be async. Used on `if` fields (free to evaluate, no LLM cost).
15
15
  */
16
16
  export type ConditionPredicate<TContext = unknown, TData = unknown> = (
17
- ctx: { data: Partial<TData>; context: TContext; session: import("./session").SessionState<TData>; history: Event[] }
17
+ ctx: { data: Partial<TData>; context: TContext; session: import("./session.js").SessionState<TData>; history: Event[] }
18
18
  ) => boolean | Promise<boolean>;
19
19
 
20
20
  /**
@@ -31,8 +31,8 @@ export type ConditionIf<TContext = unknown, TData = unknown> =
31
31
  * `when` — they belong on `if` only.
32
32
  */
33
33
  export type ConditionWhen = string | string[];
34
- import type { SessionState } from "./session";
35
- import type { Event } from "./history";
34
+ import type { SessionState } from "./session.js";
35
+ import type { Event } from "./history.js";
36
36
 
37
37
  /**
38
38
  * Reason why execution stopped.
@@ -59,21 +59,32 @@ export type StoppedReason =
59
59
  * Result that a prepare/finalize hook may return to issue directives.
60
60
  * All fields are optional — returning void is also valid.
61
61
  */
62
- export interface PrepareResult {
62
+ export interface PrepareResult<TContext = unknown, TData = unknown> {
63
63
  /** Partial data to merge into session.data */
64
- dataUpdate?: Record<string, unknown>;
64
+ dataUpdate?: Partial<TData>;
65
65
  /** Partial context to merge into the agent context */
66
- contextUpdate?: Record<string, unknown>;
66
+ contextUpdate?: Partial<TContext>;
67
67
  /** If true, stop the auto-step chain and end the turn with `reply` */
68
68
  halt?: boolean;
69
69
  /** Verbatim reply to send when halting */
70
70
  reply?: string;
71
71
  /** Jump to a step within the current flow */
72
- goToStep?: string;
72
+ goToStep?: string | { step: string; flow?: string; data?: Partial<TData>; reason?: string; };
73
73
  /** Jump to another flow */
74
- goTo?: string;
74
+ goTo?: string | { flow?: string; step?: string; data?: Partial<TData>; reason?: string; carry?: 'preserve' | 'reset'; };
75
75
  /** Mark the current flow as complete */
76
- complete?: boolean;
76
+ complete?: true | { next?: Directive<unknown, unknown>; reason?: string; };
77
+ /**
78
+ * Prompt lines appended to this turn's generation prompt. Pre-LLM
79
+ * augmentation: honored by auto steps' prepare; other step kinds drop it
80
+ * with a loud warning rather than silently ignoring it.
81
+ */
82
+ appendPrompt?: string[];
83
+ /**
84
+ * Extra tools made available for this turn only. Same auto-step-only
85
+ * honoring as {@link appendPrompt}.
86
+ */
87
+ injectTools?: Tool[];
77
88
  }
78
89
 
79
90
 
@@ -416,46 +427,32 @@ export interface FlowOptions<TContext = unknown, TData = unknown> {
416
427
  }
417
428
 
418
429
  /**
419
- * Step lifecycle hooks for managing step-specific behavior.
430
+ * Step lifecycle hooks for managing step-specific behavior. Desugared onto the
431
+ * equivalent top-level `prepare` / `finalize` fields by the Step constructor —
432
+ * both spellings run through the same lifecycle machinery, and declaring both
433
+ * runs them in sequence with their returns merged (Algorithm 4).
420
434
  *
421
- * Pre-LLM hooks (`onEnter`, `prepare`) return `void | Directive`.
422
- * Post-LLM hooks (`finalize`) return `void | Directive`.
423
- * Informational hooks (`onExit`) return `void`.
435
+ * `prepare` runs before the AI responds; `finalize` runs after the turn's
436
+ * generation completes (before persistence). Both may return a Directive to
437
+ * write state or redirect flow.
424
438
  */
425
439
  export interface StepLifecycleHooks<TContext = unknown, TData = unknown> {
426
440
  /**
427
- * Called on step entry. May return a Directive to augment the prompt,
428
- * inject tools, halt, or redirect.
429
- * Pre-LLM fields (`appendPrompt`, `injectTools`, `halt`) are honored here.
430
- */
431
- onEnter?: (
432
- ctx: HookContext<TContext, TData>
433
- ) => void | Directive<TContext, TData> | Promise<void | Directive<TContext, TData>>;
434
-
435
- /**
436
- * Called when the step is exited. Informational only — cannot influence flow control.
437
- * Receives the reason the step was exited.
438
- */
439
- onExit?: (
440
- ctx: HookContext<TContext, TData>,
441
- reason: ExitReason
442
- ) => void | Promise<void>;
443
-
444
- /**
445
- * Called pre-LLM. May return a Directive to augment the prompt,
446
- * inject tools, or halt the LLM call.
447
- * Pre-LLM fields (`appendPrompt`, `injectTools`, `halt`) are honored here.
441
+ * Called pre-LLM (alongside any top-level `prepare`). May return a Directive
442
+ * to write state or redirect flow.
448
443
  */
449
444
  prepare?: (
450
- ctx: HookContext<TContext, TData>
445
+ context: TContext,
446
+ data?: Partial<TData>
451
447
  ) => void | Directive<TContext, TData> | Promise<void | Directive<TContext, TData>>;
452
448
 
453
449
  /**
454
- * Called post-LLM. May return a Directive to redirect flow, write state,
455
- * or emit a verbatim reply.
450
+ * Called after generation (alongside any top-level `finalize`, before
451
+ * persistence). May return a Directive to redirect flow or write state.
456
452
  */
457
453
  finalize?: (
458
- ctx: HookContext<TContext, TData>
454
+ context: TContext,
455
+ data?: Partial<TData>
459
456
  ) => void | Directive<TContext, TData> | Promise<void | Directive<TContext, TData>>;
460
457
  }
461
458
 
@@ -475,12 +472,12 @@ export interface StepOptions<TContext = unknown, TData = unknown> {
475
472
  prepare?:
476
473
  | string
477
474
  | Tool<TContext, TData>
478
- | ((context: TContext, data?: Partial<TData>) => void | PrepareResult | Promise<void | PrepareResult>);
475
+ | ((context: TContext, data?: Partial<TData>) => void | PrepareResult<TContext, TData> | Promise<void | PrepareResult<TContext, TData>>);
479
476
  /** Programmatic function or tool to run after AI responds */
480
477
  finalize?:
481
478
  | string
482
479
  | Tool<TContext, TData>
483
- | ((context: TContext, data?: Partial<TData>) => void | PrepareResult | Promise<void | PrepareResult>);
480
+ | ((context: TContext, data?: Partial<TData>) => void | PrepareResult<TContext, TData> | Promise<void | PrepareResult<TContext, TData>>);
484
481
 
485
482
  /**
486
483
  * Fields to collect from the conversation in this step
@@ -569,8 +566,9 @@ export interface StepOptions<TContext = unknown, TData = unknown> {
569
566
  branches?: BranchMap<TContext, TData>;
570
567
 
571
568
  /**
572
- * Step lifecycle hooks for managing step-specific behavior.
573
- * Provides onEnter, onExit, prepare, and finalize hooks that receive HookContext.
569
+ * Step lifecycle hooks an alternative spelling of the top-level
570
+ * `prepare` / `finalize` fields. Both spellings run when declared together;
571
+ * returns are merged via Algorithm 4.
574
572
  */
575
573
  hooks?: StepLifecycleHooks<TContext, TData>;
576
574
  }
@@ -16,7 +16,7 @@ export enum MessageRole {
16
16
  SYSTEM = "system",
17
17
  }
18
18
 
19
- import type { SessionState } from "./session";
19
+ import type { SessionState } from "./session.js";
20
20
 
21
21
  /**
22
22
  * Types of events in the interaction history
@@ -12,13 +12,14 @@ export type {
12
12
  AppliedInstruction,
13
13
  AgentResponseStreamChunk,
14
14
  AgentResponse,
15
+ EndedFlow,
15
16
  ContextLifecycleHooks,
16
17
  ContextProvider,
17
18
  ValidationError,
18
19
  ValidationResult,
19
20
  HookContext,
20
21
  ExitReason,
21
- } from "./agent";
22
+ } from "./agent.js";
22
23
 
23
24
  // History types
24
25
  export type {
@@ -38,8 +39,8 @@ export type {
38
39
  AssistantHistoryItem,
39
40
  SystemHistoryItem,
40
41
  ToolHistoryItem,
41
- } from "./history";
42
- export { EventKind, MessageRole } from "./history";
42
+ } from "./history.js";
43
+ export { EventKind, MessageRole } from "./history.js";
43
44
 
44
45
  // Flow types
45
46
  export type {
@@ -59,10 +60,10 @@ export type {
59
60
  ConditionWhen,
60
61
  StoppedReason,
61
62
  PrepareResult,
62
- } from "./flow";
63
+ } from "./flow.js";
63
64
 
64
65
  // Session types
65
- export type { SessionState } from "./session";
66
+ export type { SessionState } from "./session.js";
66
67
 
67
68
  // Signals types (canonical source)
68
69
  export type {
@@ -76,7 +77,7 @@ export type {
76
77
  SignalSchema,
77
78
  SignalsState,
78
79
  SignalTriggerState,
79
- } from "./signals";
80
+ } from "./signals.js";
80
81
 
81
82
  // Tool types
82
83
  export type {
@@ -95,21 +96,21 @@ export type {
95
96
  ValidationConfig,
96
97
  ApiCallConfig,
97
98
  ComputationConfig
98
- } from "./tool";
99
- export { ToolScope } from "./tool";
99
+ } from "./tool.js";
100
+ export { ToolScope } from "./tool.js";
100
101
 
101
102
  // Compaction types
102
103
  export type {
103
104
  CompactionOptions,
104
105
  CompactionResult,
105
- } from "./compaction";
106
+ } from "./compaction.js";
106
107
 
107
108
  // Prompt cache types
108
109
  export type {
109
110
  PromptSectionType,
110
111
  PromptCacheConfig,
111
112
  SectionCompute,
112
- } from "./prompt-cache";
113
+ } from "./prompt-cache.js";
113
114
 
114
115
  // AI provider types
115
116
  export type {
@@ -120,10 +121,10 @@ export type {
120
121
  ReasoningConfig,
121
122
  GenerateMessageStreamChunk,
122
123
  ProviderCapabilities,
123
- } from "./ai";
124
+ } from "./ai.js";
124
125
 
125
126
  // Schema types
126
- export type { StructuredSchema } from "./schema";
127
+ export type { StructuredSchema } from "./schema.js";
127
128
 
128
129
  // Persistence types
129
130
  export type {
@@ -139,18 +140,18 @@ export type {
139
140
  SaveMessageOptions,
140
141
  CollectedStateData,
141
142
  SessionUpdateOptions,
142
- } from "./persistence";
143
+ } from "./persistence.js";
143
144
 
144
145
  // Template types
145
146
  export type {
146
147
  Template,
147
148
  TemplateContext,
148
149
  ConditionEvaluationResult
149
- } from "./template";
150
+ } from "./template.js";
150
151
 
151
152
  // Error types
152
- export { NotImplementedError, SessionConflictError, ProviderError } from "./errors";
153
- export type { ProviderErrorCode } from "./errors";
153
+ export { NotImplementedError, SessionConflictError, ProviderError } from "./errors.js";
154
+ export type { ErrorKind } from "./errors.js";
154
155
 
155
156
  // Internal — ConditionTemplate is NOT exported from the public surface in v2.
156
157
  // It remains internally for the condition evaluator utility.
@@ -160,4 +161,4 @@ export {
160
161
  createConditionEvaluator,
161
162
  extractAIContextStrings,
162
163
  hasProgrammaticConditions
163
- } from "../utils/condition";
164
+ } from "../utils/condition.js";
@@ -3,8 +3,8 @@
3
3
  * Support for optional database persistence (Prisma, etc.)
4
4
  */
5
5
 
6
- import type { Event, MessageRole } from "./history";
7
- import type { SessionState } from "./session";
6
+ import type { Event, MessageRole } from "./history.js";
7
+ import type { SessionState } from "./session.js";
8
8
 
9
9
  /**
10
10
  * Session status enum
@@ -2,12 +2,12 @@
2
2
  * Session step types for tracking conversation progress
3
3
  */
4
4
 
5
- import type { History } from "./history";
6
- import type { Directive } from "./flow";
7
- import type { SignalsState } from "./signals";
5
+ import type { History } from "./history.js";
6
+ import type { Directive } from "./flow.js";
7
+ import type { SignalsState } from "./signals.js";
8
8
 
9
9
  // Re-export for backward compatibility — canonical declarations live in ./signals.ts
10
- export type { SignalsState, SignalTriggerState } from "./signals";
10
+ export type { SignalsState, SignalTriggerState } from "./signals.js";
11
11
 
12
12
  /**
13
13
  * Session state tracks the current position in the conversation flow
@@ -7,9 +7,9 @@
7
7
  * compatibility within the same major.
8
8
  */
9
9
 
10
- import type { SessionState } from "./session";
11
- import type { Directive } from "./flow";
12
- import type { Event } from "./history";
10
+ import type { SessionState } from "./session.js";
11
+ import type { Directive } from "./flow.js";
12
+ import type { Event } from "./history.js";
13
13
 
14
14
  // ──────────────────────────────────────────────────────────────────────────────
15
15
  // Persistence types (shape locked in v2.0 — DO NOT modify)
@@ -1,5 +1,5 @@
1
- import type { SessionState } from "./session";
2
- import type { Event, MessageRole } from "./history";
1
+ import type { SessionState } from "./session.js";
2
+ import type { Event, MessageRole } from "./history.js";
3
3
 
4
4
  /**
5
5
  * Context object passed to template functions for dynamic rendering.
package/src/types/tool.ts CHANGED
@@ -3,8 +3,8 @@
3
3
  * Tool system type definitions
4
4
  */
5
5
 
6
- import type { Event, StepRef, ValidationResult } from "./index";
7
- import type { Directive } from "./flow";
6
+ import type { Event, StepRef, ValidationResult } from "./index.js";
7
+ import type { Directive } from "./flow.js";
8
8
 
9
9
  /**
10
10
  * Context provided to tool handlers
@@ -65,6 +65,8 @@ export interface ToolResult<
65
65
  meta?: Record<string, unknown>;
66
66
  /** Emit a directive declaratively (alternative to ctx.dispatch). */
67
67
  directive?: Directive<TContext, TData>;
68
+ /** Emit multiple directives at once (alternative to repeated dispatch calls). */
69
+ directives?: Directive<TContext, TData>[];
68
70
  }
69
71
 
70
72
  /**
@@ -1,6 +1,6 @@
1
- import type { TemplateContext, ConditionEvaluationResult } from "../types/template";
2
- import { createTemplateContext } from "./template";
3
- import { logger } from './logger'
1
+ import type { TemplateContext, ConditionEvaluationResult } from "../types/template.js";
2
+ import { createTemplateContext } from "./template.js";
3
+ import { logger } from './logger.js'
4
4
 
5
5
  /**
6
6
  * Condition template — kept as a private type for internal use by the evaluator.
@@ -1,4 +1,4 @@
1
- import { type Event, EventKind } from "../types";
1
+ import { type Event, EventKind } from "../types/index.js";
2
2
  /**
3
3
  * Helper to extract last message from history
4
4
  */
@@ -3,9 +3,9 @@
3
3
  * Convert simplified history format to internal Event format
4
4
  */
5
5
 
6
- import type { Event, MessageEventData, ToolEventData, StatusEventData } from "../types";
7
- import { EventKind, MessageRole } from "../types";
8
- import type { History, HistoryItem, UserHistoryItem, AssistantHistoryItem, ToolHistoryItem } from "../types/history";
6
+ import type { Event, MessageEventData, ToolEventData, StatusEventData } from "../types/index.js";
7
+ import { EventKind, MessageRole } from "../types/index.js";
8
+ import type { History, HistoryItem, UserHistoryItem, AssistantHistoryItem, ToolHistoryItem } from "../types/history.js";
9
9
 
10
10
  /**
11
11
  * Convert a simplified history item to an internal Event
@@ -9,13 +9,16 @@ export {
9
9
  generateToolId,
10
10
  generateInlineToolId,
11
11
  generateSignalId,
12
- } from "./id";
12
+ } from "./id.js";
13
13
 
14
14
  // Session management
15
15
  export {
16
16
  createSession,
17
17
  createSessionId,
18
+ boundConversationHistory,
19
+ DEFAULT_MAX_HISTORY_MESSAGES,
18
20
  createPersistedState,
21
+ restoreSession,
19
22
  enterFlow,
20
23
  enterStep,
21
24
  completeCurrentFlow,
@@ -23,7 +26,7 @@ export {
23
26
  mergeCollected,
24
27
  sessionStepToData,
25
28
  sessionDataToStep,
26
- } from "./session";
29
+ } from "./session.js";
27
30
 
28
31
  // Template rendering
29
32
  export {
@@ -31,13 +34,13 @@ export {
31
34
  renderMany,
32
35
  formatKnowledgeBase,
33
36
  createTemplateContext,
34
- } from "./template";
37
+ } from "./template.js";
35
38
 
36
39
  // Cloning utilities
37
- export { cloneDeep } from "./clone";
40
+ export { cloneDeep } from "./clone.js";
38
41
 
39
42
  // Event utilities
40
- export { getLastMessageFromHistory } from "./event";
43
+ export { getLastMessageFromHistory } from "./event.js";
41
44
 
42
45
  // History utilities
43
46
  export {
@@ -49,17 +52,13 @@ export {
49
52
  assistantMessage,
50
53
  toolMessage,
51
54
  systemMessage,
52
- } from "./history";
55
+ } from "./history.js";
53
56
 
54
57
  // Logging
55
- export { LoggerLevel, logger } from "./logger";
56
-
57
- // Retry utilities
58
- export type { RetryOptions, StreamRetryOptions, RetryConfig } from "./retry";
59
- export { retry, withTimeoutAndRetry, withStreamRetry, resolveRetryConfig, combineAbortSignals } from "./retry";
58
+ export { LoggerLevel, logger } from "./logger.js";
60
59
 
61
60
  // Completion helpers
62
- export { effectiveMessageText, assertUsableCompletion } from "./completion";
61
+ export { effectiveMessageText, assertUsableCompletion } from "./completion.js";
63
62
 
64
63
  // Condition utilities
65
64
  export {
@@ -67,10 +66,10 @@ export {
67
66
  createConditionEvaluator,
68
67
  extractAIContextStrings,
69
68
  hasProgrammaticConditions,
70
- } from "./condition";
69
+ } from "./condition.js";
71
70
 
72
71
  // JSON utilities
73
- export { parseJSONResponse, tryParseJSONResponse } from "./json";
72
+ export { parseJSONResponse, tryParseJSONResponse } from "./json.js";
74
73
 
75
74
  // Serialization utilities
76
- export { serializeToolResult } from "./serialize";
75
+ export { serializeToolResult, isToolResultLike, extractResultDirectives } from "./serialize.js";