@od-oneapp/ai-platform 0.1.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 (872) hide show
  1. package/README.md +235 -0
  2. package/dist/agents-base.d.mts +12 -0
  3. package/dist/agents-base.d.mts.map +1 -0
  4. package/dist/agents-base.mjs +20 -0
  5. package/dist/agents-base.mjs.map +1 -0
  6. package/dist/agents-control-flow.d.mts +115 -0
  7. package/dist/agents-control-flow.d.mts.map +1 -0
  8. package/dist/agents-control-flow.mjs +514 -0
  9. package/dist/agents-control-flow.mjs.map +1 -0
  10. package/dist/agents-coordinator.d.mts +11 -0
  11. package/dist/agents-coordinator.d.mts.map +1 -0
  12. package/dist/agents-coordinator.mjs +12 -0
  13. package/dist/agents-coordinator.mjs.map +1 -0
  14. package/dist/agents-experimental.d.mts +153 -0
  15. package/dist/agents-experimental.d.mts.map +1 -0
  16. package/dist/agents-experimental.mjs +580 -0
  17. package/dist/agents-experimental.mjs.map +1 -0
  18. package/dist/agents-fallback.d.mts +10 -0
  19. package/dist/agents-fallback.d.mts.map +1 -0
  20. package/dist/agents-fallback.mjs +15 -0
  21. package/dist/agents-fallback.mjs.map +1 -0
  22. package/dist/agents-multi-swarm.d.mts +9 -0
  23. package/dist/agents-multi-swarm.d.mts.map +1 -0
  24. package/dist/agents-multi-swarm.mjs +44 -0
  25. package/dist/agents-multi-swarm.mjs.map +1 -0
  26. package/dist/agents-multi.d.mts +10 -0
  27. package/dist/agents-multi.d.mts.map +1 -0
  28. package/dist/agents-multi.mjs +44 -0
  29. package/dist/agents-multi.mjs.map +1 -0
  30. package/dist/agents-observability.d.mts +161 -0
  31. package/dist/agents-observability.d.mts.map +1 -0
  32. package/dist/agents-observability.mjs +550 -0
  33. package/dist/agents-observability.mjs.map +1 -0
  34. package/dist/agents-patterns.d.mts +9 -0
  35. package/dist/agents-patterns.d.mts.map +1 -0
  36. package/dist/agents-patterns.mjs +18 -0
  37. package/dist/agents-patterns.mjs.map +1 -0
  38. package/dist/agents-persistence.d.mts +234 -0
  39. package/dist/agents-persistence.d.mts.map +1 -0
  40. package/dist/agents-persistence.mjs +447 -0
  41. package/dist/agents-persistence.mjs.map +1 -0
  42. package/dist/agents-triage.d.mts +11 -0
  43. package/dist/agents-triage.d.mts.map +1 -0
  44. package/dist/agents-triage.mjs +13 -0
  45. package/dist/agents-triage.mjs.map +1 -0
  46. package/dist/agents-workflows.d.mts +9 -0
  47. package/dist/agents-workflows.d.mts.map +1 -0
  48. package/dist/agents-workflows.mjs +9 -0
  49. package/dist/agents-workflows.mjs.map +1 -0
  50. package/dist/agents.d.mts +30 -0
  51. package/dist/agents.d.mts.map +1 -0
  52. package/dist/agents.mjs +50 -0
  53. package/dist/agents.mjs.map +1 -0
  54. package/dist/aggregation-8KJF1uzp.d.mts +276 -0
  55. package/dist/aggregation-8KJF1uzp.d.mts.map +1 -0
  56. package/dist/aggregation-BDop87kL.mjs +1180 -0
  57. package/dist/aggregation-BDop87kL.mjs.map +1 -0
  58. package/dist/ai-runtime-CDzQztTt.mjs +85 -0
  59. package/dist/ai-runtime-CDzQztTt.mjs.map +1 -0
  60. package/dist/ai-runtime-DIwOEc6g.d.mts +56 -0
  61. package/dist/ai-runtime-DIwOEc6g.d.mts.map +1 -0
  62. package/dist/ai-sdk-error-integration-D0GDqrM0.d.mts +553 -0
  63. package/dist/ai-sdk-error-integration-D0GDqrM0.d.mts.map +1 -0
  64. package/dist/approval-queue-BcDDQ4oQ.mjs +104 -0
  65. package/dist/approval-queue-BcDDQ4oQ.mjs.map +1 -0
  66. package/dist/approval-queue-CiKiFT9z.d.mts +21 -0
  67. package/dist/approval-queue-CiKiFT9z.d.mts.map +1 -0
  68. package/dist/audio-BzvN7r10.d.mts +79 -0
  69. package/dist/audio-BzvN7r10.d.mts.map +1 -0
  70. package/dist/audio-vBG_62ME.mjs +226 -0
  71. package/dist/audio-vBG_62ME.mjs.map +1 -0
  72. package/dist/audit-logger-Bb2JIcIk.d.mts +12 -0
  73. package/dist/audit-logger-Bb2JIcIk.d.mts.map +1 -0
  74. package/dist/audit-logger-CHIP8bRO.mjs +596 -0
  75. package/dist/audit-logger-CHIP8bRO.mjs.map +1 -0
  76. package/dist/auto-resume-BpUNbPtp.d.mts +160 -0
  77. package/dist/auto-resume-BpUNbPtp.d.mts.map +1 -0
  78. package/dist/auto-resume-BuFRNvAX.mjs +638 -0
  79. package/dist/auto-resume-BuFRNvAX.mjs.map +1 -0
  80. package/dist/budget-guard-C83KCH9V.d.mts +52 -0
  81. package/dist/budget-guard-C83KCH9V.d.mts.map +1 -0
  82. package/dist/budget-guard-d_b5rq4u.mjs +158 -0
  83. package/dist/budget-guard-d_b5rq4u.mjs.map +1 -0
  84. package/dist/budget-guard-gyhJS00s.mjs +234 -0
  85. package/dist/budget-guard-gyhJS00s.mjs.map +1 -0
  86. package/dist/buffer-BC8mvXHE.d.mts +98 -0
  87. package/dist/buffer-BC8mvXHE.d.mts.map +1 -0
  88. package/dist/buffer-CefJGbRy.mjs +289 -0
  89. package/dist/buffer-CefJGbRy.mjs.map +1 -0
  90. package/dist/caching-adapters.d.mts +5 -0
  91. package/dist/caching-adapters.mjs +3 -0
  92. package/dist/caching-strategies.d.mts +52 -0
  93. package/dist/caching-strategies.d.mts.map +1 -0
  94. package/dist/caching-strategies.mjs +703 -0
  95. package/dist/caching-strategies.mjs.map +1 -0
  96. package/dist/caching.d.mts +14 -0
  97. package/dist/caching.d.mts.map +1 -0
  98. package/dist/caching.mjs +15 -0
  99. package/dist/caching.mjs.map +1 -0
  100. package/dist/catalog.d.mts +19 -0
  101. package/dist/catalog.d.mts.map +1 -0
  102. package/dist/catalog.mjs +1114 -0
  103. package/dist/catalog.mjs.map +1 -0
  104. package/dist/chunk-CkzbjWQW.mjs +20 -0
  105. package/dist/circuit-breaker-DoKWPORd.mjs +262 -0
  106. package/dist/circuit-breaker-DoKWPORd.mjs.map +1 -0
  107. package/dist/circuit-breaker-Mey3E7tW.d.mts +64 -0
  108. package/dist/circuit-breaker-Mey3E7tW.d.mts.map +1 -0
  109. package/dist/citation-generator-C-9RpbHq.mjs +103 -0
  110. package/dist/citation-generator-C-9RpbHq.mjs.map +1 -0
  111. package/dist/citation-generator-CDSymDs_.d.mts +18 -0
  112. package/dist/citation-generator-CDSymDs_.d.mts.map +1 -0
  113. package/dist/client-CpacYDIE.mjs +882 -0
  114. package/dist/client-CpacYDIE.mjs.map +1 -0
  115. package/dist/client.d.mts +103 -0
  116. package/dist/client.d.mts.map +1 -0
  117. package/dist/client.mjs +470 -0
  118. package/dist/client.mjs.map +1 -0
  119. package/dist/compliance-approval-queue-DQGLojAm.mjs +172 -0
  120. package/dist/compliance-approval-queue-DQGLojAm.mjs.map +1 -0
  121. package/dist/compliance-approval-queue-IrMxFfSJ.d.mts +99 -0
  122. package/dist/compliance-approval-queue-IrMxFfSJ.d.mts.map +1 -0
  123. package/dist/compliance-wrapper-CrOMHhHN.mjs +528 -0
  124. package/dist/compliance-wrapper-CrOMHhHN.mjs.map +1 -0
  125. package/dist/conditions-DmQ6Y1Wt.mjs +179 -0
  126. package/dist/conditions-DmQ6Y1Wt.mjs.map +1 -0
  127. package/dist/conditions-zDrKfrc3.d.mts +42 -0
  128. package/dist/conditions-zDrKfrc3.d.mts.map +1 -0
  129. package/dist/console-BGMxxPZN.mjs +181 -0
  130. package/dist/console-BGMxxPZN.mjs.map +1 -0
  131. package/dist/console-DqEqZd4A.d.mts +76 -0
  132. package/dist/console-DqEqZd4A.d.mts.map +1 -0
  133. package/dist/controller-BOy3-xbC.mjs +501 -0
  134. package/dist/controller-BOy3-xbC.mjs.map +1 -0
  135. package/dist/controller-Y0NGosbJ.d.mts +104 -0
  136. package/dist/controller-Y0NGosbJ.d.mts.map +1 -0
  137. package/dist/coordinator-agent-BglqZLwo.d.mts +54 -0
  138. package/dist/coordinator-agent-BglqZLwo.d.mts.map +1 -0
  139. package/dist/coordinator-agent-WFWBRL-G.mjs +236 -0
  140. package/dist/coordinator-agent-WFWBRL-G.mjs.map +1 -0
  141. package/dist/crypto-8ABhc3TD.mjs +40 -0
  142. package/dist/crypto-8ABhc3TD.mjs.map +1 -0
  143. package/dist/environment-CSoJb0SW.mjs +255 -0
  144. package/dist/environment-CSoJb0SW.mjs.map +1 -0
  145. package/dist/error-handling-DNVkm6RY.mjs +1334 -0
  146. package/dist/error-handling-DNVkm6RY.mjs.map +1 -0
  147. package/dist/errors-CQ8tF4dP.mjs +985 -0
  148. package/dist/errors-CQ8tF4dP.mjs.map +1 -0
  149. package/dist/errors-CfYdVeum.d.mts +212 -0
  150. package/dist/errors-CfYdVeum.d.mts.map +1 -0
  151. package/dist/errors-Dtn-UeRi.mjs +61 -0
  152. package/dist/errors-Dtn-UeRi.mjs.map +1 -0
  153. package/dist/evaluator-Cs84qkr8.mjs +91 -0
  154. package/dist/evaluator-Cs84qkr8.mjs.map +1 -0
  155. package/dist/evaluator-optimizer-De67_mJC.mjs +1086 -0
  156. package/dist/evaluator-optimizer-De67_mJC.mjs.map +1 -0
  157. package/dist/evaluator-optimizer-pattern-B5939s2Z.mjs +367 -0
  158. package/dist/evaluator-optimizer-pattern-B5939s2Z.mjs.map +1 -0
  159. package/dist/evaluator-optimizer-pattern-D1AJrzBD.d.mts +72 -0
  160. package/dist/evaluator-optimizer-pattern-D1AJrzBD.d.mts.map +1 -0
  161. package/dist/factory-DP6VSl8C.mjs +307 -0
  162. package/dist/factory-DP6VSl8C.mjs.map +1 -0
  163. package/dist/generative-ui-catalog.d.mts +8 -0
  164. package/dist/generative-ui-catalog.d.mts.map +1 -0
  165. package/dist/generative-ui-catalog.mjs +679 -0
  166. package/dist/generative-ui-catalog.mjs.map +1 -0
  167. package/dist/generative-ui-registry.d.mts +195 -0
  168. package/dist/generative-ui-registry.d.mts.map +1 -0
  169. package/dist/generative-ui-registry.mjs +250 -0
  170. package/dist/generative-ui-registry.mjs.map +1 -0
  171. package/dist/generative-ui-stream.d.mts +23 -0
  172. package/dist/generative-ui-stream.d.mts.map +1 -0
  173. package/dist/generative-ui-stream.mjs +219 -0
  174. package/dist/generative-ui-stream.mjs.map +1 -0
  175. package/dist/generative-ui-types.d.mts +123 -0
  176. package/dist/generative-ui-types.d.mts.map +1 -0
  177. package/dist/generative-ui-types.mjs +1 -0
  178. package/dist/generative-ui.d.mts +13 -0
  179. package/dist/generative-ui.d.mts.map +1 -0
  180. package/dist/generative-ui.mjs +21 -0
  181. package/dist/generative-ui.mjs.map +1 -0
  182. package/dist/governance-audit.d.mts +3 -0
  183. package/dist/governance-audit.mjs +3 -0
  184. package/dist/governance-compliance.d.mts +5 -0
  185. package/dist/governance-compliance.mjs +4 -0
  186. package/dist/governance-policies.d.mts +4 -0
  187. package/dist/governance-policies.mjs +4 -0
  188. package/dist/governance-tenancy.d.mts +3 -0
  189. package/dist/governance-tenancy.mjs +3 -0
  190. package/dist/governance.d.mts +88 -0
  191. package/dist/governance.d.mts.map +1 -0
  192. package/dist/governance.mjs +432 -0
  193. package/dist/governance.mjs.map +1 -0
  194. package/dist/grounding-attribution.d.mts +63 -0
  195. package/dist/grounding-attribution.d.mts.map +1 -0
  196. package/dist/grounding-attribution.mjs +259 -0
  197. package/dist/grounding-attribution.mjs.map +1 -0
  198. package/dist/grounding-citation.d.mts +2 -0
  199. package/dist/grounding-citation.mjs +3 -0
  200. package/dist/grounding-context.d.mts +9 -0
  201. package/dist/grounding-context.d.mts.map +1 -0
  202. package/dist/grounding-context.mjs +19 -0
  203. package/dist/grounding-context.mjs.map +1 -0
  204. package/dist/grounding-embed.d.mts +102 -0
  205. package/dist/grounding-embed.d.mts.map +1 -0
  206. package/dist/grounding-embed.mjs +417 -0
  207. package/dist/grounding-embed.mjs.map +1 -0
  208. package/dist/grounding-hallucination.d.mts +44 -0
  209. package/dist/grounding-hallucination.d.mts.map +1 -0
  210. package/dist/grounding-hallucination.mjs +115 -0
  211. package/dist/grounding-hallucination.mjs.map +1 -0
  212. package/dist/grounding-proof-map.d.mts +9 -0
  213. package/dist/grounding-proof-map.d.mts.map +1 -0
  214. package/dist/grounding-proof-map.mjs +26 -0
  215. package/dist/grounding-proof-map.mjs.map +1 -0
  216. package/dist/grounding-rag.d.mts +10 -0
  217. package/dist/grounding-rag.d.mts.map +1 -0
  218. package/dist/grounding-rag.mjs +27 -0
  219. package/dist/grounding-rag.mjs.map +1 -0
  220. package/dist/grounding-verification.d.mts +48 -0
  221. package/dist/grounding-verification.d.mts.map +1 -0
  222. package/dist/grounding-verification.mjs +224 -0
  223. package/dist/grounding-verification.mjs.map +1 -0
  224. package/dist/grounding.d.mts +24 -0
  225. package/dist/grounding.d.mts.map +1 -0
  226. package/dist/grounding.mjs +77 -0
  227. package/dist/grounding.mjs.map +1 -0
  228. package/dist/hitl-active-learning.d.mts +41 -0
  229. package/dist/hitl-active-learning.d.mts.map +1 -0
  230. package/dist/hitl-active-learning.mjs +178 -0
  231. package/dist/hitl-active-learning.mjs.map +1 -0
  232. package/dist/hitl-annotation.d.mts +74 -0
  233. package/dist/hitl-annotation.d.mts.map +1 -0
  234. package/dist/hitl-annotation.mjs +170 -0
  235. package/dist/hitl-annotation.mjs.map +1 -0
  236. package/dist/hitl-approval.d.mts +2 -0
  237. package/dist/hitl-approval.mjs +3 -0
  238. package/dist/hitl-feedback.d.mts +59 -0
  239. package/dist/hitl-feedback.d.mts.map +1 -0
  240. package/dist/hitl-feedback.mjs +137 -0
  241. package/dist/hitl-feedback.mjs.map +1 -0
  242. package/dist/hitl-review.d.mts +2 -0
  243. package/dist/hitl-review.mjs +3 -0
  244. package/dist/hitl.d.mts +14 -0
  245. package/dist/hitl.d.mts.map +1 -0
  246. package/dist/hitl.mjs +22 -0
  247. package/dist/hitl.mjs.map +1 -0
  248. package/dist/index-B17HT-VL.d.mts +285 -0
  249. package/dist/index-B17HT-VL.d.mts.map +1 -0
  250. package/dist/index-BDwgsK9B.d.mts +101 -0
  251. package/dist/index-BDwgsK9B.d.mts.map +1 -0
  252. package/dist/index-BGgMn_Ev.d.mts +2615 -0
  253. package/dist/index-BGgMn_Ev.d.mts.map +1 -0
  254. package/dist/index-DOqe5r9G.d.mts +318 -0
  255. package/dist/index-DOqe5r9G.d.mts.map +1 -0
  256. package/dist/index-DotINT7o.d.mts +1004 -0
  257. package/dist/index-DotINT7o.d.mts.map +1 -0
  258. package/dist/index-URlW7aD1.d.mts +67 -0
  259. package/dist/index-URlW7aD1.d.mts.map +1 -0
  260. package/dist/index.d.mts +64 -0
  261. package/dist/index.d.mts.map +1 -0
  262. package/dist/index.mjs +46 -0
  263. package/dist/index.mjs.map +1 -0
  264. package/dist/integrations-blob-storage.d.mts +25 -0
  265. package/dist/integrations-blob-storage.d.mts.map +1 -0
  266. package/dist/integrations-blob-storage.mjs +3 -0
  267. package/dist/integrations-notifications.d.mts +2 -0
  268. package/dist/integrations-notifications.mjs +3 -0
  269. package/dist/integrations-rate-limit.d.mts +27 -0
  270. package/dist/integrations-rate-limit.d.mts.map +1 -0
  271. package/dist/integrations-rate-limit.mjs +30 -0
  272. package/dist/integrations-rate-limit.mjs.map +1 -0
  273. package/dist/integrations-redis.d.mts +3 -0
  274. package/dist/integrations-redis.mjs +3 -0
  275. package/dist/integrations-stream.d.mts +14 -0
  276. package/dist/integrations-stream.d.mts.map +1 -0
  277. package/dist/integrations-stream.mjs +3 -0
  278. package/dist/integrations.d.mts +7 -0
  279. package/dist/integrations.mjs +7 -0
  280. package/dist/log-adapter-BLegSZtz.d.mts +16 -0
  281. package/dist/log-adapter-BLegSZtz.d.mts.map +1 -0
  282. package/dist/log-adapter-PPe_2Pwv.mjs +28 -0
  283. package/dist/log-adapter-PPe_2Pwv.mjs.map +1 -0
  284. package/dist/loop-BOYEtr2g.mjs +520 -0
  285. package/dist/loop-BOYEtr2g.mjs.map +1 -0
  286. package/dist/loop-C-tBBOqi.d.mts +219 -0
  287. package/dist/loop-C-tBBOqi.d.mts.map +1 -0
  288. package/dist/middleware-5wQ9bANW.mjs +306 -0
  289. package/dist/middleware-5wQ9bANW.mjs.map +1 -0
  290. package/dist/middleware-C1apSrj0.mjs +613 -0
  291. package/dist/middleware-C1apSrj0.mjs.map +1 -0
  292. package/dist/middleware-C7k0uItW.d.mts +9 -0
  293. package/dist/middleware-C7k0uItW.d.mts.map +1 -0
  294. package/dist/middleware-CZQCTHfl.mjs +366 -0
  295. package/dist/middleware-CZQCTHfl.mjs.map +1 -0
  296. package/dist/models.d.mts +11 -0
  297. package/dist/models.d.mts.map +1 -0
  298. package/dist/models.mjs +32 -0
  299. package/dist/models.mjs.map +1 -0
  300. package/dist/observability-analytics.d.mts +107 -0
  301. package/dist/observability-analytics.d.mts.map +1 -0
  302. package/dist/observability-analytics.mjs +409 -0
  303. package/dist/observability-analytics.mjs.map +1 -0
  304. package/dist/observability-cost.d.mts +10 -0
  305. package/dist/observability-cost.d.mts.map +1 -0
  306. package/dist/observability-cost.mjs +15 -0
  307. package/dist/observability-cost.mjs.map +1 -0
  308. package/dist/observability-telemetry.d.mts +111 -0
  309. package/dist/observability-telemetry.d.mts.map +1 -0
  310. package/dist/observability-telemetry.mjs +343 -0
  311. package/dist/observability-telemetry.mjs.map +1 -0
  312. package/dist/observability-tracing.d.mts +10 -0
  313. package/dist/observability-tracing.d.mts.map +1 -0
  314. package/dist/observability-tracing.mjs +17 -0
  315. package/dist/observability-tracing.mjs.map +1 -0
  316. package/dist/observability.d.mts +15 -0
  317. package/dist/observability.d.mts.map +1 -0
  318. package/dist/observability.mjs +17 -0
  319. package/dist/observability.mjs.map +1 -0
  320. package/dist/optimizer-DhXXpci6.mjs +97 -0
  321. package/dist/optimizer-DhXXpci6.mjs.map +1 -0
  322. package/dist/output-multimodal.d.mts +9 -0
  323. package/dist/output-multimodal.d.mts.map +1 -0
  324. package/dist/output-multimodal.mjs +18 -0
  325. package/dist/output-multimodal.mjs.map +1 -0
  326. package/dist/output.d.mts +11 -0
  327. package/dist/output.d.mts.map +1 -0
  328. package/dist/output.mjs +40 -0
  329. package/dist/output.mjs.map +1 -0
  330. package/dist/pii-filter-3AxmYSiu.d.mts +23 -0
  331. package/dist/pii-filter-3AxmYSiu.d.mts.map +1 -0
  332. package/dist/pipelines.d.mts +448 -0
  333. package/dist/pipelines.d.mts.map +1 -0
  334. package/dist/pipelines.mjs +1534 -0
  335. package/dist/pipelines.mjs.map +1 -0
  336. package/dist/prompt-injection-DQXchzsV.d.mts +8 -0
  337. package/dist/prompt-injection-DQXchzsV.d.mts.map +1 -0
  338. package/dist/prompt-injection-RpoLPwSa.mjs +52 -0
  339. package/dist/prompt-injection-RpoLPwSa.mjs.map +1 -0
  340. package/dist/prompts.d.mts +192 -0
  341. package/dist/prompts.d.mts.map +1 -0
  342. package/dist/prompts.mjs +732 -0
  343. package/dist/prompts.mjs.map +1 -0
  344. package/dist/protocol-DfBiEsnl.d.mts +112 -0
  345. package/dist/protocol-DfBiEsnl.d.mts.map +1 -0
  346. package/dist/quota-manager-0iPMkQWN.d.mts +62 -0
  347. package/dist/quota-manager-0iPMkQWN.d.mts.map +1 -0
  348. package/dist/quota-manager-D_N7FuQ2.mjs +180 -0
  349. package/dist/quota-manager-D_N7FuQ2.mjs.map +1 -0
  350. package/dist/redaction-utils-DcQwsiNh.mjs +438 -0
  351. package/dist/redaction-utils-DcQwsiNh.mjs.map +1 -0
  352. package/dist/redis-CpsSrF8K.mjs +102 -0
  353. package/dist/redis-CpsSrF8K.mjs.map +1 -0
  354. package/dist/redis-CwguYFGh.d.mts +33 -0
  355. package/dist/redis-CwguYFGh.d.mts.map +1 -0
  356. package/dist/registry-CsD3iTIx.mjs +190 -0
  357. package/dist/registry-CsD3iTIx.mjs.map +1 -0
  358. package/dist/registry-DVPWzkXR.d.mts +36 -0
  359. package/dist/registry-DVPWzkXR.d.mts.map +1 -0
  360. package/dist/reranking-BpWYhYzl.d.mts +72 -0
  361. package/dist/reranking-BpWYhYzl.d.mts.map +1 -0
  362. package/dist/reranking-Ck8aKZW7.mjs +331 -0
  363. package/dist/reranking-Ck8aKZW7.mjs.map +1 -0
  364. package/dist/resumable-adapter-CO1HtsgJ.mjs +21 -0
  365. package/dist/resumable-adapter-CO1HtsgJ.mjs.map +1 -0
  366. package/dist/review-trigger-DmAsiQlM.d.mts +24 -0
  367. package/dist/review-trigger-DmAsiQlM.d.mts.map +1 -0
  368. package/dist/review-trigger-DwXfpww9.mjs +112 -0
  369. package/dist/review-trigger-DwXfpww9.mjs.map +1 -0
  370. package/dist/safe-context-BynhkTKR.d.mts +54 -0
  371. package/dist/safe-context-BynhkTKR.d.mts.map +1 -0
  372. package/dist/safe-context-C5A3Wv3b.mjs +143 -0
  373. package/dist/safe-context-C5A3Wv3b.mjs.map +1 -0
  374. package/dist/schema-Bu2noOZ4.mjs +27 -0
  375. package/dist/schema-Bu2noOZ4.mjs.map +1 -0
  376. package/dist/schema-CwFvuCnA.mjs +97 -0
  377. package/dist/schema-CwFvuCnA.mjs.map +1 -0
  378. package/dist/schema-Wz-1-ro9.d.mts +37 -0
  379. package/dist/schema-Wz-1-ro9.d.mts.map +1 -0
  380. package/dist/schemas-CxQtxIga.mjs +62 -0
  381. package/dist/schemas-CxQtxIga.mjs.map +1 -0
  382. package/dist/schemas-DBOhxgW7.d.mts +32 -0
  383. package/dist/schemas-DBOhxgW7.d.mts.map +1 -0
  384. package/dist/schemas-Dp_OCqBt.d.mts +63 -0
  385. package/dist/schemas-Dp_OCqBt.d.mts.map +1 -0
  386. package/dist/schemas-SwCsnT0z.mjs +83 -0
  387. package/dist/schemas-SwCsnT0z.mjs.map +1 -0
  388. package/dist/sdk-errors.d.mts +2 -0
  389. package/dist/sdk-errors.mjs +3 -0
  390. package/dist/sdk-experimental.d.mts +59 -0
  391. package/dist/sdk-experimental.d.mts.map +1 -0
  392. package/dist/sdk-experimental.mjs +193 -0
  393. package/dist/sdk-experimental.mjs.map +1 -0
  394. package/dist/sdk-stop-conditions.d.mts +3 -0
  395. package/dist/sdk-stop-conditions.mjs +3 -0
  396. package/dist/sdk.d.mts +15 -0
  397. package/dist/sdk.d.mts.map +1 -0
  398. package/dist/sdk.mjs +50 -0
  399. package/dist/sdk.mjs.map +1 -0
  400. package/dist/security-guardrails.d.mts +3 -0
  401. package/dist/security-guardrails.mjs +3 -0
  402. package/dist/security-injection.d.mts +2 -0
  403. package/dist/security-injection.mjs +3 -0
  404. package/dist/security.d.mts +12 -0
  405. package/dist/security.d.mts.map +1 -0
  406. package/dist/security.mjs +18 -0
  407. package/dist/security.mjs.map +1 -0
  408. package/dist/server.d.mts +420 -0
  409. package/dist/server.d.mts.map +1 -0
  410. package/dist/server.mjs +2225 -0
  411. package/dist/server.mjs.map +1 -0
  412. package/dist/shared.d.mts +2 -0
  413. package/dist/shared.mjs +3 -0
  414. package/dist/streaming-control.d.mts +2 -0
  415. package/dist/streaming-control.mjs +4 -0
  416. package/dist/streaming-core.d.mts +4 -0
  417. package/dist/streaming-core.mjs +3 -0
  418. package/dist/streaming-infra-resilience.d.mts +120 -0
  419. package/dist/streaming-infra-resilience.d.mts.map +1 -0
  420. package/dist/streaming-infra-resilience.mjs +358 -0
  421. package/dist/streaming-infra-resilience.mjs.map +1 -0
  422. package/dist/streaming-infra-transport.d.mts +57 -0
  423. package/dist/streaming-infra-transport.d.mts.map +1 -0
  424. package/dist/streaming-infra-transport.mjs +488 -0
  425. package/dist/streaming-infra-transport.mjs.map +1 -0
  426. package/dist/streaming-infra.d.mts +5 -0
  427. package/dist/streaming-infra.mjs +5 -0
  428. package/dist/streaming.d.mts +17 -0
  429. package/dist/streaming.d.mts.map +1 -0
  430. package/dist/streaming.mjs +71 -0
  431. package/dist/streaming.mjs.map +1 -0
  432. package/dist/telemetry-2eKMojIb.mjs +1046 -0
  433. package/dist/telemetry-2eKMojIb.mjs.map +1 -0
  434. package/dist/telemetry-C2t03dwD.d.mts +59 -0
  435. package/dist/telemetry-C2t03dwD.d.mts.map +1 -0
  436. package/dist/tool-Btbththq.d.mts +253 -0
  437. package/dist/tool-Btbththq.d.mts.map +1 -0
  438. package/dist/tool-JSf8JXZ8.mjs +1150 -0
  439. package/dist/tool-JSf8JXZ8.mjs.map +1 -0
  440. package/dist/tool-safety-CZO8a4D4.d.mts +60 -0
  441. package/dist/tool-safety-CZO8a4D4.d.mts.map +1 -0
  442. package/dist/tool-safety-DXtYDXod.mjs +319 -0
  443. package/dist/tool-safety-DXtYDXod.mjs.map +1 -0
  444. package/dist/tools-BuS2Uv0q.mjs +1708 -0
  445. package/dist/tools-BuS2Uv0q.mjs.map +1 -0
  446. package/dist/tools-approval.d.mts +99 -0
  447. package/dist/tools-approval.d.mts.map +1 -0
  448. package/dist/tools-approval.mjs +395 -0
  449. package/dist/tools-approval.mjs.map +1 -0
  450. package/dist/tools-compliance.d.mts +67 -0
  451. package/dist/tools-compliance.d.mts.map +1 -0
  452. package/dist/tools-compliance.mjs +330 -0
  453. package/dist/tools-compliance.mjs.map +1 -0
  454. package/dist/tools-computer.d.mts +25 -0
  455. package/dist/tools-computer.d.mts.map +1 -0
  456. package/dist/tools-computer.mjs +64 -0
  457. package/dist/tools-computer.mjs.map +1 -0
  458. package/dist/tools-core.d.mts +3 -0
  459. package/dist/tools-core.mjs +3 -0
  460. package/dist/tools-mcp.d.mts +3 -0
  461. package/dist/tools-mcp.mjs +5 -0
  462. package/dist/tools-superpowers.d.mts +2 -0
  463. package/dist/tools-superpowers.mjs +3 -0
  464. package/dist/tools.d.mts +401 -0
  465. package/dist/tools.d.mts.map +1 -0
  466. package/dist/tools.mjs +1921 -0
  467. package/dist/tools.mjs.map +1 -0
  468. package/dist/transport-selector-D-Ib05X1.mjs +1936 -0
  469. package/dist/transport-selector-D-Ib05X1.mjs.map +1 -0
  470. package/dist/triage-agent-BEsXg5sw.d.mts +63 -0
  471. package/dist/triage-agent-BEsXg5sw.d.mts.map +1 -0
  472. package/dist/triage-agent-CBsfX-HW.mjs +167 -0
  473. package/dist/triage-agent-CBsfX-HW.mjs.map +1 -0
  474. package/dist/types-BPnq3GQo.d.mts +23 -0
  475. package/dist/types-BPnq3GQo.d.mts.map +1 -0
  476. package/dist/types-BjWgimpY.d.mts +16 -0
  477. package/dist/types-BjWgimpY.d.mts.map +1 -0
  478. package/dist/types-BxD-5btB.d.mts +41 -0
  479. package/dist/types-BxD-5btB.d.mts.map +1 -0
  480. package/dist/types-By-r93bE.d.mts +36 -0
  481. package/dist/types-By-r93bE.d.mts.map +1 -0
  482. package/dist/types-CLBWFRZN.d.mts +69 -0
  483. package/dist/types-CLBWFRZN.d.mts.map +1 -0
  484. package/dist/types-CQ0HFd0u.d.mts +62 -0
  485. package/dist/types-CQ0HFd0u.d.mts.map +1 -0
  486. package/dist/types-D3zJb59_.d.mts +47 -0
  487. package/dist/types-D3zJb59_.d.mts.map +1 -0
  488. package/dist/types-DJnugQX0.d.mts +80 -0
  489. package/dist/types-DJnugQX0.d.mts.map +1 -0
  490. package/dist/types-DbUfMCnT.d.mts +70 -0
  491. package/dist/types-DbUfMCnT.d.mts.map +1 -0
  492. package/dist/upstash-adapter-D96Caq2O.mjs +22 -0
  493. package/dist/upstash-adapter-D96Caq2O.mjs.map +1 -0
  494. package/dist/upstash-adapter-DD4433dx.d.mts +8 -0
  495. package/dist/upstash-adapter-DD4433dx.d.mts.map +1 -0
  496. package/dist/utils-BlYhcD6M.mjs +319 -0
  497. package/dist/utils-BlYhcD6M.mjs.map +1 -0
  498. package/dist/utils-DpJGOb3y.d.mts +120 -0
  499. package/dist/utils-DpJGOb3y.d.mts.map +1 -0
  500. package/dist/vercel-blob-adapter-CkOXLT2D.mjs +25 -0
  501. package/dist/vercel-blob-adapter-CkOXLT2D.mjs.map +1 -0
  502. package/dist/xai-CbV_dCnP.mjs +1600 -0
  503. package/dist/xai-CbV_dCnP.mjs.map +1 -0
  504. package/package.json +479 -0
  505. package/src/agents/base/factory.ts +382 -0
  506. package/src/agents/base/index.ts +8 -0
  507. package/src/agents/base/schemas.ts +117 -0
  508. package/src/agents/base/types.ts +192 -0
  509. package/src/agents/control-flow/index.ts +683 -0
  510. package/src/agents/coordinator/coordinator-agent.ts +381 -0
  511. package/src/agents/coordinator/index.ts +6 -0
  512. package/src/agents/default-agent.ts +211 -0
  513. package/src/agents/evaluator-optimizer/README.md +612 -0
  514. package/src/agents/evaluator-optimizer/evaluator-optimizer.example.ts +437 -0
  515. package/src/agents/evaluator-optimizer/evaluator.ts +282 -0
  516. package/src/agents/evaluator-optimizer/index.test.ts +416 -0
  517. package/src/agents/evaluator-optimizer/index.ts +519 -0
  518. package/src/agents/evaluator-optimizer/optimizer.ts +322 -0
  519. package/src/agents/evaluator-optimizer/schema.ts +302 -0
  520. package/src/agents/evaluator-optimizer/utils.ts +42 -0
  521. package/src/agents/experimental/index.ts +1095 -0
  522. package/src/agents/experimental/types.ts +212 -0
  523. package/src/agents/fallback/index.ts +18 -0
  524. package/src/agents/fallback/recovery/circuit-breaker.ts +166 -0
  525. package/src/agents/fallback/strategies/model-fallback.ts +192 -0
  526. package/src/agents/fallback/types.ts +87 -0
  527. package/src/agents/governance-agent.ts +446 -0
  528. package/src/agents/index.ts +79 -0
  529. package/src/agents/multi/coordination/index.ts +6 -0
  530. package/src/agents/multi/coordination/message-bus.ts +144 -0
  531. package/src/agents/multi/index.ts +6 -0
  532. package/src/agents/multi/state/index.ts +162 -0
  533. package/src/agents/multi/supervisor/index.ts +7 -0
  534. package/src/agents/multi/supervisor/supervisor.ts +254 -0
  535. package/src/agents/multi/swarm/aggregation.ts +466 -0
  536. package/src/agents/multi/swarm/communication.ts +388 -0
  537. package/src/agents/multi/swarm/coordination.ts +380 -0
  538. package/src/agents/multi/swarm/index.ts +73 -0
  539. package/src/agents/multi/swarm/swarm-executor.ts +479 -0
  540. package/src/agents/multi/types.ts +181 -0
  541. package/src/agents/observability/index.ts +914 -0
  542. package/src/agents/orchestrator.ts +218 -0
  543. package/src/agents/patterns/README.md +512 -0
  544. package/src/agents/patterns/evaluator-optimizer-pattern.example.ts +455 -0
  545. package/src/agents/patterns/evaluator-optimizer-pattern.ts +653 -0
  546. package/src/agents/patterns/index.ts +26 -0
  547. package/src/agents/persistence/index.ts +726 -0
  548. package/src/agents/tools/index.ts +291 -0
  549. package/src/agents/tools/mcp.ts +188 -0
  550. package/src/agents/triage/index.ts +6 -0
  551. package/src/agents/triage/triage-agent.ts +280 -0
  552. package/src/agents/workflows/index.ts +6 -0
  553. package/src/agents/workflows/interfaces.ts +36 -0
  554. package/src/agents/workflows/schema.ts +20 -0
  555. package/src/caching/adapters/index.ts +7 -0
  556. package/src/caching/adapters/memory.ts +77 -0
  557. package/src/caching/adapters/redis.ts +60 -0
  558. package/src/caching/index.ts +17 -0
  559. package/src/caching/middleware.ts +452 -0
  560. package/src/caching/strategies/index.ts +1008 -0
  561. package/src/caching/types.ts +47 -0
  562. package/src/catalog.ts +921 -0
  563. package/src/client/chat-usage.ts +53 -0
  564. package/src/client/hooks.ts +343 -0
  565. package/src/client/index.ts +36 -0
  566. package/src/client/message-utils.ts +29 -0
  567. package/src/client/use-generative-ui.ts +174 -0
  568. package/src/client/utils.ts +66 -0
  569. package/src/generative-ui/catalog.ts +653 -0
  570. package/src/generative-ui/index.ts +82 -0
  571. package/src/generative-ui/registry.ts +273 -0
  572. package/src/generative-ui/stream.ts +324 -0
  573. package/src/generative-ui/types.ts +376 -0
  574. package/src/governance/audit/audit-logger.ts +239 -0
  575. package/src/governance/audit/audit-schema.ts +82 -0
  576. package/src/governance/audit/index.ts +6 -0
  577. package/src/governance/compliance/abac/policy-engine.ts +175 -0
  578. package/src/governance/compliance/abac/types.ts +40 -0
  579. package/src/governance/compliance/approval/compliance-approval-queue.ts +217 -0
  580. package/src/governance/compliance/index.ts +16 -0
  581. package/src/governance/compliance/schemas.ts +68 -0
  582. package/src/governance/compliance/types.ts +143 -0
  583. package/src/governance/compliance/validators/phi-detector.ts +145 -0
  584. package/src/governance/compliance/validators/redaction-utils.ts +176 -0
  585. package/src/governance/compliance/validators/safe-harbor.ts +135 -0
  586. package/src/governance/entitlements/index.ts +585 -0
  587. package/src/governance/entitlements/middleware.ts +651 -0
  588. package/src/governance/entitlements/rate-limiter.ts +711 -0
  589. package/src/governance/index.ts +32 -0
  590. package/src/governance/policies/guardrails.ts +1121 -0
  591. package/src/governance/policies/index.ts +42 -0
  592. package/src/governance/policies/loop-controls.ts +136 -0
  593. package/src/governance/policies/telemetry.ts +63 -0
  594. package/src/governance/tenancy/index.ts +30 -0
  595. package/src/governance/tenancy/isolation/context.ts +92 -0
  596. package/src/governance/tenancy/isolation/index.ts +13 -0
  597. package/src/governance/tenancy/quotas/index.ts +11 -0
  598. package/src/governance/tenancy/quotas/quota-manager.ts +180 -0
  599. package/src/governance/tenancy/types.ts +66 -0
  600. package/src/governance/types.ts +16 -0
  601. package/src/governance/versioning/index.ts +573 -0
  602. package/src/grounding/attribution/index.ts +424 -0
  603. package/src/grounding/citation/citation-generator.ts +174 -0
  604. package/src/grounding/citation/index.ts +12 -0
  605. package/src/grounding/context/index.ts +32 -0
  606. package/src/grounding/context/safe-context.ts +116 -0
  607. package/src/grounding/context/types.ts +62 -0
  608. package/src/grounding/context-engineering/error-handling.ts +359 -0
  609. package/src/grounding/context-engineering/index.ts +23 -0
  610. package/src/grounding/context-engineering/memory.ts +559 -0
  611. package/src/grounding/context-engineering/tool-masking.ts +338 -0
  612. package/src/grounding/embed/index.ts +704 -0
  613. package/src/grounding/embed/reranking.ts +604 -0
  614. package/src/grounding/hallucination/index.ts +223 -0
  615. package/src/grounding/index.ts +82 -0
  616. package/src/grounding/proof-map/applyPatch.ts +172 -0
  617. package/src/grounding/proof-map/index.ts +41 -0
  618. package/src/grounding/proof-map/loop.ts +275 -0
  619. package/src/grounding/proof-map/schema.ts +217 -0
  620. package/src/grounding/rag/__tests__/pipeline.test.ts +274 -0
  621. package/src/grounding/rag/__tests__/tool.test.ts +202 -0
  622. package/src/grounding/rag/__tests__/trace.test.ts +229 -0
  623. package/src/grounding/rag/circuit-breaker.ts +152 -0
  624. package/src/grounding/rag/index.ts +64 -0
  625. package/src/grounding/rag/pipeline.ts +602 -0
  626. package/src/grounding/rag/tool.ts +281 -0
  627. package/src/grounding/rag/trace.ts +503 -0
  628. package/src/grounding/rag/types.ts +284 -0
  629. package/src/grounding/retrieval/in-memory-store.ts +107 -0
  630. package/src/grounding/sources/index.ts +943 -0
  631. package/src/grounding/tests/applyPatch.test.ts +194 -0
  632. package/src/grounding/tests/loop.test.ts +141 -0
  633. package/src/grounding/tests/schema.test.ts +160 -0
  634. package/src/grounding/types.ts +100 -0
  635. package/src/grounding/verification/index.ts +419 -0
  636. package/src/hitl/active-learning/index.ts +332 -0
  637. package/src/hitl/annotation/index.ts +362 -0
  638. package/src/hitl/approval/approval-queue.ts +132 -0
  639. package/src/hitl/approval/index.ts +5 -0
  640. package/src/hitl/feedback/index.ts +284 -0
  641. package/src/hitl/index.ts +69 -0
  642. package/src/hitl/review/index.ts +6 -0
  643. package/src/hitl/review/review-trigger.ts +162 -0
  644. package/src/hitl/types.ts +126 -0
  645. package/src/index.ts +125 -0
  646. package/src/integrations/blob-storage/index.ts +7 -0
  647. package/src/integrations/blob-storage/types.ts +28 -0
  648. package/src/integrations/blob-storage/vercel-blob-adapter.ts +35 -0
  649. package/src/integrations/index.ts +15 -0
  650. package/src/integrations/notifications/index.ts +7 -0
  651. package/src/integrations/notifications/log-adapter.ts +30 -0
  652. package/src/integrations/notifications/types.ts +27 -0
  653. package/src/integrations/rate-limit/index.ts +7 -0
  654. package/src/integrations/rate-limit/types.ts +26 -0
  655. package/src/integrations/rate-limit/upstash-adapter.ts +45 -0
  656. package/src/integrations/redis/index.ts +7 -0
  657. package/src/integrations/redis/types.ts +67 -0
  658. package/src/integrations/redis/upstash-adapter.ts +18 -0
  659. package/src/integrations/stream/index.ts +7 -0
  660. package/src/integrations/stream/resumable-adapter.ts +20 -0
  661. package/src/integrations/stream/types.ts +21 -0
  662. package/src/internal/__tests__/hallucination.test.ts +162 -0
  663. package/src/internal/__tests__/models.test.ts +104 -0
  664. package/src/internal/__tests__/sdk-errors.test.ts +201 -0
  665. package/src/internal/__tests__/stop-conditions.test.ts +210 -0
  666. package/src/internal/shared/ai-types.ts +942 -0
  667. package/src/internal/testing/evaluators.ts +575 -0
  668. package/src/internal/testing/index.ts +960 -0
  669. package/src/internal/ui/data-parts.ts +511 -0
  670. package/src/internal/ui/type-guards.ts +344 -0
  671. package/src/internal/ui-factories/__tests__/ui-factories.test.ts +548 -0
  672. package/src/internal/ui-factories/artifact-factory.ts +667 -0
  673. package/src/internal/ui-factories/index.ts +82 -0
  674. package/src/internal/ui-factories/shimmer-manager.ts +220 -0
  675. package/src/internal/ui-factories/status-helpers.ts +149 -0
  676. package/src/internal/ui-factories/tool-renderer.ts +167 -0
  677. package/src/internal/ui-factories/types.ts +235 -0
  678. package/src/models/capabilities.ts +88 -0
  679. package/src/models/index.ts +16 -0
  680. package/src/models/provider-factory.ts +229 -0
  681. package/src/models/providers/anthropic.ts +539 -0
  682. package/src/models/providers/google.ts +354 -0
  683. package/src/models/providers/index.ts +21 -0
  684. package/src/models/providers/openai.ts +346 -0
  685. package/src/models/providers/perplexity.ts +276 -0
  686. package/src/models/providers/shared.ts +90 -0
  687. package/src/models/providers/xai.ts +269 -0
  688. package/src/models/registry.ts +208 -0
  689. package/src/models/routing/index.ts +45 -0
  690. package/src/models/routing/intent-router.ts +143 -0
  691. package/src/models/routing/model-router.ts +300 -0
  692. package/src/models/routing/types.ts +106 -0
  693. package/src/models/types.ts +23 -0
  694. package/src/observability/analytics/index.ts +593 -0
  695. package/src/observability/cost/index.ts +16 -0
  696. package/src/observability/cost/tracking/budget-guard.ts +110 -0
  697. package/src/observability/cost/tracking/usage-tracker.ts +120 -0
  698. package/src/observability/cost/types.ts +85 -0
  699. package/src/observability/index.ts +17 -0
  700. package/src/observability/telemetry/index.ts +508 -0
  701. package/src/observability/tracing/index.ts +30 -0
  702. package/src/observability/tracing/otel/ai-instrumentation.ts +193 -0
  703. package/src/observability/tracing/otel/exporters/console.ts +58 -0
  704. package/src/observability/tracing/otel/exporters/index.ts +6 -0
  705. package/src/observability/tracing/provenance.ts +769 -0
  706. package/src/observability/tracing/types.ts +92 -0
  707. package/src/output/__tests__/output.test.ts +737 -0
  708. package/src/output/element-stream.ts +678 -0
  709. package/src/output/errors.ts +108 -0
  710. package/src/output/factories.ts +392 -0
  711. package/src/output/index.ts +98 -0
  712. package/src/output/multimodal/EXPORTS.md +306 -0
  713. package/src/output/multimodal/IMPLEMENTATION_SUMMARY.md +421 -0
  714. package/src/output/multimodal/README.md +349 -0
  715. package/src/output/multimodal/SETUP_GUIDE.md +472 -0
  716. package/src/output/multimodal/audio.ts +650 -0
  717. package/src/output/multimodal/image.ts +22 -0
  718. package/src/output/multimodal/index.ts +32 -0
  719. package/src/output/multimodal/providers.example.ts +375 -0
  720. package/src/output/validator.ts +495 -0
  721. package/src/pipelines/adapters/trace-storage-blob.ts +458 -0
  722. package/src/pipelines/adapters/trace-storage-memory.ts +319 -0
  723. package/src/pipelines/defaults.ts +109 -0
  724. package/src/pipelines/index.ts +24 -0
  725. package/src/pipelines/message-transforms.ts +107 -0
  726. package/src/pipelines/multi-step-wrapper.ts +433 -0
  727. package/src/pipelines/pipeline-presets.ts +339 -0
  728. package/src/pipelines/step-executor.ts +257 -0
  729. package/src/pipelines/storage-factory.ts +85 -0
  730. package/src/pipelines/trace-storage-interface.ts +216 -0
  731. package/src/pipelines/types.ts +255 -0
  732. package/src/pipelines/validation.ts +323 -0
  733. package/src/prompts/index.ts +271 -0
  734. package/src/prompts/model-variants.ts +410 -0
  735. package/src/prompts/templates.ts +327 -0
  736. package/src/sdk/errors/base.ts +296 -0
  737. package/src/sdk/errors/index.ts +31 -0
  738. package/src/sdk/errors/utils.ts +148 -0
  739. package/src/sdk/experimental/index.ts +286 -0
  740. package/src/sdk/index.ts +25 -0
  741. package/src/sdk/middleware/ai-middleware.ts +95 -0
  742. package/src/sdk/middleware/cache.ts +154 -0
  743. package/src/sdk/middleware/circuit-breaker.ts +388 -0
  744. package/src/sdk/middleware/compose.ts +81 -0
  745. package/src/sdk/middleware/deduplication.ts +307 -0
  746. package/src/sdk/middleware/index.ts +660 -0
  747. package/src/sdk/middleware/model-middleware.ts +200 -0
  748. package/src/sdk/stop-conditions/conditions.ts +209 -0
  749. package/src/sdk/stop-conditions/index.ts +35 -0
  750. package/src/sdk/stop-conditions/types.ts +59 -0
  751. package/src/security/guardrails/index.ts +6 -0
  752. package/src/security/guardrails/middleware.ts +465 -0
  753. package/src/security/guardrails/pii-filter.ts +396 -0
  754. package/src/security/index.ts +33 -0
  755. package/src/security/injection/index.ts +5 -0
  756. package/src/security/injection/prompt-injection.ts +64 -0
  757. package/src/security/types.ts +85 -0
  758. package/src/server/cache/crypto.ts +47 -0
  759. package/src/server/cache/performance.ts +79 -0
  760. package/src/server/error-handler.ts +93 -0
  761. package/src/server/errors.ts +73 -0
  762. package/src/server/helpers.ts +944 -0
  763. package/src/server/http.ts +156 -0
  764. package/src/server/index.ts +12 -0
  765. package/src/server/messages/__tests__/messages.test.ts +720 -0
  766. package/src/server/messages/converter.ts +245 -0
  767. package/src/server/messages/data-parts.ts +338 -0
  768. package/src/server/messages/extraction.ts +328 -0
  769. package/src/server/messages/index.ts +126 -0
  770. package/src/server/messages/types.ts +355 -0
  771. package/src/server/messages/window.ts +450 -0
  772. package/src/server/rate-limit/env.ts +8 -0
  773. package/src/server/rate-limit/rate-limit.ts +165 -0
  774. package/src/server/routes/HEALTH_CHECK.md +502 -0
  775. package/src/server/routes/IMPLEMENTATION_SUMMARY.md +432 -0
  776. package/src/server/routes/QUICK_START.md +327 -0
  777. package/src/server/routes/README.md +357 -0
  778. package/src/server/routes/__tests__/routes.test.ts +628 -0
  779. package/src/server/routes/agent-route.ts +224 -0
  780. package/src/server/routes/agent-routes.ts +191 -0
  781. package/src/server/routes/embed-config.ts +181 -0
  782. package/src/server/routes/health-check.example.ts +507 -0
  783. package/src/server/routes/health-check.test.ts +533 -0
  784. package/src/server/routes/health-check.ts +639 -0
  785. package/src/server/routes/health-check.types.ts +217 -0
  786. package/src/server/routes/index.ts +32 -0
  787. package/src/server/routes/types.ts +274 -0
  788. package/src/shared/__tests__/schemas.test.ts +317 -0
  789. package/src/shared/ai-runtime.ts +139 -0
  790. package/src/shared/ai-types.ts +133 -0
  791. package/src/shared/index.ts +30 -0
  792. package/src/shared/sdk-runtime.ts +198 -0
  793. package/src/shared/sdk-types.ts +301 -0
  794. package/src/streaming/control/__tests__/streaming-control.test.ts +708 -0
  795. package/src/streaming/control/budget-guard.ts +264 -0
  796. package/src/streaming/control/controller.ts +255 -0
  797. package/src/streaming/control/index.ts +105 -0
  798. package/src/streaming/control/smoothing.ts +201 -0
  799. package/src/streaming/control/step-limit.ts +215 -0
  800. package/src/streaming/control/types.ts +234 -0
  801. package/src/streaming/core/auto-resume.ts +276 -0
  802. package/src/streaming/core/index.ts +85 -0
  803. package/src/streaming/core/multi-step.ts +471 -0
  804. package/src/streaming/core/protocol.ts +194 -0
  805. package/src/streaming/core/types.ts +182 -0
  806. package/src/streaming/index.ts +97 -0
  807. package/src/streaming/infra/backpressure/buffer.ts +210 -0
  808. package/src/streaming/infra/backpressure/index.ts +6 -0
  809. package/src/streaming/infra/index.ts +75 -0
  810. package/src/streaming/infra/multiplexing/index.ts +311 -0
  811. package/src/streaming/infra/resilience/index.ts +684 -0
  812. package/src/streaming/infra/transform/index.ts +15 -0
  813. package/src/streaming/infra/transform/stream-transforms.ts +166 -0
  814. package/src/streaming/infra/transport/index.ts +774 -0
  815. package/src/streaming/infra/types.ts +118 -0
  816. package/src/streaming/infra-extra/types.ts +118 -0
  817. package/src/tools/advanced/caching.ts +299 -0
  818. package/src/tools/advanced/generator.ts +267 -0
  819. package/src/tools/advanced/hitl.ts +251 -0
  820. package/src/tools/advanced/index.ts +9 -0
  821. package/src/tools/advanced/llm-tool.ts +208 -0
  822. package/src/tools/approval/FILES.md +449 -0
  823. package/src/tools/approval/IMPLEMENTATION_SUMMARY.md +567 -0
  824. package/src/tools/approval/QUICK_START.md +362 -0
  825. package/src/tools/approval/README.md +514 -0
  826. package/src/tools/approval/advanced-approval-queue.ts +7 -0
  827. package/src/tools/approval/approval.example.ts +571 -0
  828. package/src/tools/approval/in-memory-queue.ts +405 -0
  829. package/src/tools/approval/index.ts +737 -0
  830. package/src/tools/approval/middleware.ts +590 -0
  831. package/src/tools/approval/queue-factory.ts +162 -0
  832. package/src/tools/approval/redis-queue.ts +327 -0
  833. package/src/tools/approval/testing.ts +493 -0
  834. package/src/tools/approval/types.ts +221 -0
  835. package/src/tools/approval/with-approval.ts +366 -0
  836. package/src/tools/artifacts/artifact-tools.ts +273 -0
  837. package/src/tools/artifacts/index.ts +6 -0
  838. package/src/tools/compliance/compliance-wrapper.ts +789 -0
  839. package/src/tools/compliance/create-compliant-stream.ts +226 -0
  840. package/src/tools/compliance/index.ts +8 -0
  841. package/src/tools/compliance/phi-redaction.ts +406 -0
  842. package/src/tools/compliance/tool-wrapper.ts +306 -0
  843. package/src/tools/computer/index.ts +99 -0
  844. package/src/tools/computer/types.ts +41 -0
  845. package/src/tools/core/abort.ts +202 -0
  846. package/src/tools/core/factory.ts +197 -0
  847. package/src/tools/core/index.ts +8 -0
  848. package/src/tools/core/tool-safety.ts +112 -0
  849. package/src/tools/generic/index.ts +9 -0
  850. package/src/tools/generic/json-schema-tool.ts +301 -0
  851. package/src/tools/generic/tiptap-context.ts +619 -0
  852. package/src/tools/generic/web-search-tool.ts +82 -0
  853. package/src/tools/generic/web-search.ts +142 -0
  854. package/src/tools/index.ts +36 -0
  855. package/src/tools/mcp/ai-sdk-error-integration.ts +401 -0
  856. package/src/tools/mcp/client.ts +988 -0
  857. package/src/tools/mcp/connection-manager.ts +380 -0
  858. package/src/tools/mcp/connection-pool.ts +408 -0
  859. package/src/tools/mcp/edge-runtime.ts +318 -0
  860. package/src/tools/mcp/environment.ts +310 -0
  861. package/src/tools/mcp/index.ts +20 -0
  862. package/src/tools/mcp/next-pattern.ts +401 -0
  863. package/src/tools/mcp/stream-lifecycle-integration.ts +617 -0
  864. package/src/tools/mcp/tool-cache.ts +359 -0
  865. package/src/tools/mcp/transport-selector.ts +492 -0
  866. package/src/tools/mcp/transports.ts +99 -0
  867. package/src/tools/simple-factory.ts +55 -0
  868. package/src/tools/superpowers/index.ts +122 -0
  869. package/src/tools/superpowers/prompts/index.ts +533 -0
  870. package/src/tools/superpowers/schemas/index.ts +701 -0
  871. package/src/tools/superpowers/tools/index.ts +721 -0
  872. package/src/tools/validation-wrapper.ts +97 -0
@@ -0,0 +1,1180 @@
1
+ import { z } from "zod";
2
+ import { logError, logInfo } from "@od-oneapp/shared/logs";
3
+ import { EventEmitter } from "node:events";
4
+
5
+ //#region src/agents/multi/swarm/swarm-executor.ts
6
+ /**
7
+ * Swarm Executor - Core agent swarm coordination
8
+ * Based on VERCEL_AI_SDK_V6_PATTERNS.md section 4.4
9
+ * Orchestrates multiple agents working in parallel with various coordination strategies
10
+ */
11
+ /**
12
+ * Agent definition schema
13
+ * Describes an individual agent in the swarm
14
+ */
15
+ const AgentDefinitionSchema = z.object({
16
+ id: z.string().describe("Unique identifier for the agent"),
17
+ name: z.string().describe("Human-readable agent name"),
18
+ role: z.string().describe("Role/responsibility of the agent"),
19
+ description: z.string().describe("What this agent does"),
20
+ dependencies: z.array(z.string()).default([]).describe("IDs of agents this one depends on"),
21
+ config: z.record(z.string(), z.unknown()).optional().describe("Agent-specific configuration")
22
+ });
23
+ /**
24
+ * Agent result from execution
25
+ */
26
+ const AgentResultSchema = z.object({
27
+ agentId: z.string(),
28
+ agentName: z.string(),
29
+ status: z.enum([
30
+ "success",
31
+ "failed",
32
+ "timeout",
33
+ "skipped"
34
+ ]),
35
+ result: z.unknown().optional(),
36
+ error: z.string().optional(),
37
+ startTime: z.number(),
38
+ endTime: z.number(),
39
+ duration: z.number(),
40
+ metadata: z.record(z.string(), z.unknown()).optional()
41
+ });
42
+ /**
43
+ * Swarm timing information
44
+ */
45
+ const SwarmTimingSchema = z.object({
46
+ startTime: z.number(),
47
+ endTime: z.number(),
48
+ totalDuration: z.number(),
49
+ parallelDuration: z.number(),
50
+ sequentialDuration: z.number(),
51
+ agentTimings: z.record(z.string(), z.number())
52
+ });
53
+ /**
54
+ * Swarm configuration
55
+ */
56
+ const SwarmConfigSchema = z.object({
57
+ agents: z.array(AgentDefinitionSchema),
58
+ coordinator: z.enum([
59
+ "sequential",
60
+ "parallel",
61
+ "hybrid",
62
+ "custom"
63
+ ]),
64
+ maxConcurrency: z.number().min(1).default(4),
65
+ timeout: z.number().min(1e3).default(3e4),
66
+ aggregation: z.enum([
67
+ "merge",
68
+ "vote",
69
+ "consensus",
70
+ "weighted",
71
+ "custom"
72
+ ]).default("merge"),
73
+ enableLogging: z.boolean().default(false),
74
+ retryPolicy: z.object({
75
+ maxRetries: z.number().min(0).default(0),
76
+ retryDelay: z.number().min(0).default(1e3),
77
+ retryableErrors: z.array(z.string()).optional()
78
+ }).optional()
79
+ });
80
+ /**
81
+ * Swarm task definition
82
+ */
83
+ const SwarmTaskSchema = z.object({
84
+ taskId: z.string(),
85
+ description: z.string(),
86
+ params: z.record(z.string(), z.unknown()).optional(),
87
+ targetAgents: z.array(z.string()).optional().describe("Specific agents to run; empty = all"),
88
+ context: z.record(z.string(), z.unknown()).optional().describe("Shared context passed to all agents")
89
+ });
90
+ /**
91
+ * Swarm execution result
92
+ */
93
+ const SwarmResultSchema = z.object({
94
+ taskId: z.string(),
95
+ results: z.record(z.string(), AgentResultSchema),
96
+ aggregated: z.unknown().optional(),
97
+ timing: SwarmTimingSchema,
98
+ status: z.enum([
99
+ "completed",
100
+ "partial",
101
+ "failed"
102
+ ]),
103
+ error: z.string().optional()
104
+ });
105
+ /**
106
+ * Factory function to create a swarm executor
107
+ */
108
+ function createSwarm(config) {
109
+ return new SwarmExecutor(config);
110
+ }
111
+ /**
112
+ * Main swarm executor implementation
113
+ */
114
+ var SwarmExecutor = class {
115
+ config;
116
+ agentMap;
117
+ constructor(config) {
118
+ this.config = config;
119
+ this.agentMap = new Map(config.agents.map((agent) => [agent.id, agent]));
120
+ }
121
+ async execute(task) {
122
+ const startTime = Date.now();
123
+ const results = /* @__PURE__ */ new Map();
124
+ if (this.config.enableLogging) {
125
+ logInfo(`[Swarm] Starting execution of task: ${task.taskId}`);
126
+ logInfo(`[Swarm] Coordination strategy: ${this.config.coordinator}`);
127
+ }
128
+ try {
129
+ const targetAgents = task.targetAgents ?? [];
130
+ const agentsToRun = targetAgents.length > 0 ? this.config.agents.filter((a) => targetAgents.includes(a.id)) : this.config.agents;
131
+ if (this.config.enableLogging) logInfo(`[Swarm] Running ${agentsToRun.length} agents`);
132
+ let parallelDuration = 0;
133
+ let sequentialDuration = 0;
134
+ switch (this.config.coordinator) {
135
+ case "sequential":
136
+ sequentialDuration = await this.executeSequential(agentsToRun, task, results);
137
+ break;
138
+ case "parallel":
139
+ parallelDuration = await this.executeParallel(agentsToRun, task, results);
140
+ break;
141
+ case "hybrid": {
142
+ const { parallel, sequential } = await this.executeHybrid(agentsToRun, task, results);
143
+ parallelDuration = parallel;
144
+ sequentialDuration = sequential;
145
+ break;
146
+ }
147
+ case "custom":
148
+ await this.executeParallel(agentsToRun, task, results);
149
+ break;
150
+ }
151
+ const endTime = Date.now();
152
+ const totalDuration = endTime - startTime;
153
+ const aggregated = await this.aggregateResults(Array.from(results.values()));
154
+ const timing = {
155
+ startTime,
156
+ endTime,
157
+ totalDuration,
158
+ parallelDuration,
159
+ sequentialDuration,
160
+ agentTimings: this.extractAgentTimings(results)
161
+ };
162
+ const status = Array.from(results.values()).every((r) => r.status === "success") ? "completed" : Array.from(results.values()).some((r) => r.status === "success") ? "partial" : "failed";
163
+ if (this.config.enableLogging) {
164
+ logInfo(`[Swarm] Task ${task.taskId} completed with status: ${status}`);
165
+ logInfo(`[Swarm] Total duration: ${totalDuration}ms`);
166
+ }
167
+ return {
168
+ taskId: task.taskId,
169
+ results: Object.fromEntries(results),
170
+ aggregated,
171
+ timing,
172
+ status
173
+ };
174
+ } catch (error) {
175
+ const endTime = Date.now();
176
+ const totalDuration = endTime - startTime;
177
+ return {
178
+ taskId: task.taskId,
179
+ results: Object.fromEntries(results),
180
+ timing: {
181
+ startTime,
182
+ endTime,
183
+ totalDuration,
184
+ parallelDuration: 0,
185
+ sequentialDuration: totalDuration,
186
+ agentTimings: this.extractAgentTimings(results)
187
+ },
188
+ status: "failed",
189
+ error: error instanceof Error ? error.message : "Unknown error"
190
+ };
191
+ }
192
+ }
193
+ async executeSequential(agents, task, results) {
194
+ const startTime = Date.now();
195
+ for (const agent of agents) try {
196
+ const result = await this.executeAgent(agent, task);
197
+ results.set(agent.id, result);
198
+ } catch (error) {
199
+ results.set(agent.id, {
200
+ agentId: agent.id,
201
+ agentName: agent.name,
202
+ status: "failed",
203
+ error: error instanceof Error ? error.message : "Unknown error",
204
+ startTime: Date.now(),
205
+ endTime: Date.now(),
206
+ duration: 0
207
+ });
208
+ }
209
+ return Date.now() - startTime;
210
+ }
211
+ async executeParallel(agents, task, results) {
212
+ const startTime = Date.now();
213
+ const chunks = this.chunkArray(agents, this.config.maxConcurrency);
214
+ for (const chunk of chunks) {
215
+ const promises = chunk.map(async (agent) => {
216
+ try {
217
+ const result = await this.executeAgent(agent, task);
218
+ results.set(agent.id, result);
219
+ } catch (error) {
220
+ results.set(agent.id, {
221
+ agentId: agent.id,
222
+ agentName: agent.name,
223
+ status: "failed",
224
+ error: error instanceof Error ? error.message : "Unknown error",
225
+ startTime: Date.now(),
226
+ endTime: Date.now(),
227
+ duration: 0
228
+ });
229
+ }
230
+ });
231
+ await Promise.all(promises);
232
+ }
233
+ return Date.now() - startTime;
234
+ }
235
+ async executeHybrid(agents, task, results) {
236
+ const parallelAgents = agents.filter((a) => !a.dependencies || a.dependencies.length === 0);
237
+ const parallelDuration = await this.executeParallel(parallelAgents, task, results);
238
+ const dependentAgents = agents.filter((a) => a.dependencies && a.dependencies.length > 0);
239
+ return {
240
+ parallel: parallelDuration,
241
+ sequential: await this.executeSequential(dependentAgents, task, results)
242
+ };
243
+ }
244
+ async executeAgent(agent, task) {
245
+ const startTime = Date.now();
246
+ const timeoutMs = this.config.timeout;
247
+ try {
248
+ const executionPromise = this.simulateAgentExecution(agent, task);
249
+ const timeoutPromise = new Promise((resolve, reject) => {
250
+ setTimeout(() => reject(/* @__PURE__ */ new Error("AGENT_TIMEOUT")), timeoutMs);
251
+ });
252
+ await Promise.race([executionPromise, timeoutPromise]);
253
+ const endTime = Date.now();
254
+ const duration = endTime - startTime;
255
+ return {
256
+ agentId: agent.id,
257
+ agentName: agent.name,
258
+ status: "success",
259
+ result: {
260
+ processedAt: (/* @__PURE__ */ new Date()).toISOString(),
261
+ role: agent.role,
262
+ taskId: task.taskId
263
+ },
264
+ startTime,
265
+ endTime,
266
+ duration
267
+ };
268
+ } catch (error) {
269
+ const endTime = Date.now();
270
+ const duration = endTime - startTime;
271
+ if (error instanceof Error && error.message === "AGENT_TIMEOUT") return {
272
+ agentId: agent.id,
273
+ agentName: agent.name,
274
+ status: "timeout",
275
+ error: `Agent execution exceeded timeout of ${timeoutMs}ms`,
276
+ startTime,
277
+ endTime,
278
+ duration
279
+ };
280
+ return {
281
+ agentId: agent.id,
282
+ agentName: agent.name,
283
+ status: "failed",
284
+ error: error instanceof Error ? error.message : "Unknown error",
285
+ startTime,
286
+ endTime,
287
+ duration
288
+ };
289
+ }
290
+ }
291
+ async simulateAgentExecution(agent, task) {
292
+ const delay = Math.random() * 100 + 50;
293
+ await new Promise((resolve) => setTimeout(resolve, delay));
294
+ }
295
+ async aggregateResults(results) {
296
+ switch (this.config.aggregation) {
297
+ case "merge": return this.mergeResults(results);
298
+ case "vote": return this.voteOnResults(results);
299
+ case "consensus": return this.consensusResults(results);
300
+ case "weighted": return this.mergeResults(results);
301
+ case "custom": return this.mergeResults(results);
302
+ default: return this.mergeResults(results);
303
+ }
304
+ }
305
+ mergeResults(results) {
306
+ return {
307
+ totalAgents: results.length,
308
+ successfulAgents: results.filter((r) => r.status === "success").length,
309
+ failedAgents: results.filter((r) => r.status === "failed").length,
310
+ agentResults: results.map((r) => ({
311
+ agentId: r.agentId,
312
+ status: r.status,
313
+ duration: r.duration
314
+ }))
315
+ };
316
+ }
317
+ voteOnResults(results) {
318
+ const successCount = results.filter((r) => r.status === "success").length;
319
+ const failureCount = results.filter((r) => r.status === "failed").length;
320
+ return {
321
+ consensus: successCount > failureCount ? "success" : "failure",
322
+ successVotes: successCount,
323
+ failureVotes: failureCount,
324
+ totalVotes: results.length
325
+ };
326
+ }
327
+ consensusResults(results) {
328
+ const totalResults = results.length;
329
+ const successfulResults = results.filter((r) => r.status === "success").length;
330
+ const confidenceScore = totalResults > 0 ? successfulResults / totalResults : 0;
331
+ return {
332
+ consensus: confidenceScore >= .5,
333
+ confidenceScore: Math.round(confidenceScore * 100) / 100,
334
+ successfulResults,
335
+ totalResults,
336
+ details: results.map((r) => ({
337
+ agentId: r.agentId,
338
+ status: r.status
339
+ }))
340
+ };
341
+ }
342
+ extractAgentTimings(results) {
343
+ const timings = {};
344
+ results.forEach((result, agentId) => {
345
+ timings[agentId] = result.duration;
346
+ });
347
+ return timings;
348
+ }
349
+ chunkArray(array, size) {
350
+ const chunks = [];
351
+ for (let i = 0; i < array.length; i += size) chunks.push(array.slice(i, i + size));
352
+ return chunks;
353
+ }
354
+ getAgent(agentId) {
355
+ return this.agentMap.get(agentId);
356
+ }
357
+ getAgents() {
358
+ return this.config.agents;
359
+ }
360
+ getConfig() {
361
+ return this.config;
362
+ }
363
+ };
364
+ /**
365
+ * Execute a swarm with a given task
366
+ */
367
+ async function executeSwarm(swarm, task) {
368
+ return swarm.execute(task);
369
+ }
370
+
371
+ //#endregion
372
+ //#region src/agents/multi/swarm/coordination.ts
373
+ /**
374
+ * Coordination Strategies - Different execution patterns for agent swarms
375
+ * Based on VERCEL_AI_SDK_V6_PATTERNS.md section 4.4
376
+ * Provides sequential, parallel, hybrid, and dependency-aware coordination
377
+ */
378
+ /**
379
+ * Sequential execution strategy
380
+ * Agents run one after another in order
381
+ * Useful for: Tasks with strict ordering requirements or low parallelism
382
+ */
383
+ async function sequentialExecution(agents, task, executeAgent) {
384
+ const results = [];
385
+ for (const agent of agents) try {
386
+ const result = await executeAgent(agent, task);
387
+ results.push(result);
388
+ } catch (error) {
389
+ results.push({
390
+ agentId: agent.id,
391
+ agentName: agent.name,
392
+ status: "failed",
393
+ error: error instanceof Error ? error.message : "Unknown error",
394
+ startTime: Date.now(),
395
+ endTime: Date.now(),
396
+ duration: 0
397
+ });
398
+ }
399
+ return results;
400
+ }
401
+ /**
402
+ * Parallel execution strategy
403
+ * Agents run concurrently up to maxConcurrency limit
404
+ * Useful for: Independent tasks that can run simultaneously
405
+ */
406
+ async function parallelExecution(agents, task, executeAgent, maxConcurrency = 4) {
407
+ const results = [];
408
+ const chunks = chunkArray(agents, maxConcurrency);
409
+ for (const chunk of chunks) {
410
+ const promises = chunk.map(async (agent) => {
411
+ try {
412
+ return await executeAgent(agent, task);
413
+ } catch (error) {
414
+ return {
415
+ agentId: agent.id,
416
+ agentName: agent.name,
417
+ status: "failed",
418
+ error: error instanceof Error ? error.message : "Unknown error",
419
+ startTime: Date.now(),
420
+ endTime: Date.now(),
421
+ duration: 0
422
+ };
423
+ }
424
+ });
425
+ const chunkResults = await Promise.all(promises);
426
+ results.push(...chunkResults);
427
+ }
428
+ return results;
429
+ }
430
+ /**
431
+ * Hybrid execution strategy
432
+ * Combines sequential and parallel execution based on dependencies
433
+ * Agents with no dependencies run in parallel
434
+ * Agents with dependencies run sequentially after their dependencies
435
+ * Useful for: Complex workflows with mixed dependency patterns
436
+ */
437
+ async function hybridExecution(agents, task, executeAgent, maxConcurrency = 4) {
438
+ const phases = buildExecutionPhases(createDependencyGraph(agents));
439
+ const results = [];
440
+ const completedAgents = /* @__PURE__ */ new Set();
441
+ for (const phase of phases) if (phase.parallel) {
442
+ const phaseResults = await parallelExecution(phase.agents, task, executeAgent, maxConcurrency);
443
+ results.push(...phaseResults);
444
+ for (const r of phaseResults) completedAgents.add(r.agentId);
445
+ } else {
446
+ const phaseResults = await sequentialExecution(phase.agents, task, executeAgent);
447
+ results.push(...phaseResults);
448
+ for (const r of phaseResults) completedAgents.add(r.agentId);
449
+ }
450
+ return results;
451
+ }
452
+ /**
453
+ * Create a dependency graph from agents
454
+ * Analyzes agent dependencies and builds a directed acyclic graph
455
+ */
456
+ function createDependencyGraph(agents) {
457
+ const agentMap = new Map(agents.map((a) => [a.id, a]));
458
+ const nodes = [];
459
+ for (const agent of agents) {
460
+ for (const depId of agent.dependencies || []) if (!agentMap.has(depId)) throw new Error(`Agent "${agent.id}" depends on unknown agent "${depId}"`);
461
+ nodes.push({
462
+ agentId: agent.id,
463
+ agent,
464
+ dependencies: agent.dependencies || [],
465
+ dependents: [],
466
+ level: 0
467
+ });
468
+ }
469
+ for (const node of nodes) for (const depId of node.dependencies) {
470
+ const depNode = nodes.find((n) => n.agentId === depId);
471
+ if (depNode) depNode.dependents.push(node.agentId);
472
+ }
473
+ calculateLevels(nodes);
474
+ return nodes;
475
+ }
476
+ /**
477
+ * Build execution phases from dependency graph
478
+ * Groups agents into phases that can be executed together
479
+ */
480
+ function buildExecutionPhases(graph) {
481
+ const phases = [];
482
+ const maxLevel = Math.max(...graph.map((n) => n.level), 0);
483
+ for (let level = 0; level <= maxLevel; level++) {
484
+ const agentsAtLevel = graph.filter((n) => n.level === level).map((n) => n.agent);
485
+ if (agentsAtLevel.length > 0) phases.push({
486
+ phaseId: `phase_${level}`,
487
+ agents: agentsAtLevel,
488
+ dependsOn: level > 0 ? [`phase_${level - 1}`] : [],
489
+ parallel: agentsAtLevel.length > 1
490
+ });
491
+ }
492
+ return phases;
493
+ }
494
+ /**
495
+ * Validate dependency graph for cycles
496
+ * Returns true if graph is acyclic, false if cycles detected
497
+ */
498
+ function validateDependencyGraph(graph) {
499
+ const visited = /* @__PURE__ */ new Set();
500
+ const recursionStack = /* @__PURE__ */ new Set();
501
+ const hasCycle = (nodeId) => {
502
+ visited.add(nodeId);
503
+ recursionStack.add(nodeId);
504
+ const node = graph.find((n) => n.agentId === nodeId);
505
+ if (!node) return false;
506
+ for (const depId of node.dependencies) if (!visited.has(depId)) {
507
+ if (hasCycle(depId)) return true;
508
+ } else if (recursionStack.has(depId)) return true;
509
+ recursionStack.delete(nodeId);
510
+ return false;
511
+ };
512
+ for (const node of graph) if (!visited.has(node.agentId)) {
513
+ if (hasCycle(node.agentId)) return false;
514
+ }
515
+ return true;
516
+ }
517
+ /**
518
+ * Get agents that are ready to execute
519
+ * Returns agents whose dependencies have all been satisfied
520
+ */
521
+ function getReadyAgents(graph, completedAgents) {
522
+ return graph.filter((node) => {
523
+ if (completedAgents.has(node.agentId)) return false;
524
+ return node.dependencies.every((depId) => completedAgents.has(depId));
525
+ });
526
+ }
527
+ /**
528
+ * Get all agents that depend on a specific agent
529
+ */
530
+ function getDependentAgents(nodeId, graph) {
531
+ const node = graph.find((n) => n.agentId === nodeId);
532
+ if (!node) return [];
533
+ return graph.filter((n) => node.dependents.includes(n.agentId));
534
+ }
535
+ /**
536
+ * Get all agents that a specific agent depends on
537
+ */
538
+ function getDependencies(nodeId, graph) {
539
+ const node = graph.find((n) => n.agentId === nodeId);
540
+ if (!node) return [];
541
+ return graph.filter((n) => node.dependencies.includes(n.agentId));
542
+ }
543
+ /**
544
+ * Calculate execution order based on dependencies
545
+ */
546
+ function calculateExecutionOrder(graph) {
547
+ const order = [];
548
+ const visited = /* @__PURE__ */ new Set();
549
+ const visit = (nodeId) => {
550
+ if (visited.has(nodeId)) return;
551
+ visited.add(nodeId);
552
+ const node = graph.find((n) => n.agentId === nodeId);
553
+ if (!node) return;
554
+ for (const depId of node.dependencies) visit(depId);
555
+ const { level } = node;
556
+ if (!order[level]) order[level] = [];
557
+ order[level].push(nodeId);
558
+ };
559
+ for (const node of graph) visit(node.agentId);
560
+ return order.filter((group) => group.length > 0);
561
+ }
562
+ /**
563
+ * Helper: Calculate levels in dependency graph (topological sort)
564
+ */
565
+ function calculateLevels(nodes) {
566
+ const visited = /* @__PURE__ */ new Set();
567
+ const calculateLevel = (nodeId) => {
568
+ const node = nodes.find((n) => n.agentId === nodeId);
569
+ if (!node) return 0;
570
+ if (visited.has(nodeId)) return node.level;
571
+ visited.add(nodeId);
572
+ if (node.dependencies.length === 0) node.level = 0;
573
+ else node.level = Math.max(...node.dependencies.map((depId) => {
574
+ if (!nodes.find((n) => n.agentId === depId)) return 0;
575
+ return calculateLevel(depId);
576
+ }), 0) + 1;
577
+ return node.level;
578
+ };
579
+ for (const node of nodes) calculateLevel(node.agentId);
580
+ }
581
+ /**
582
+ * Helper: Split array into chunks
583
+ */
584
+ function chunkArray(array, size) {
585
+ const chunks = [];
586
+ for (let i = 0; i < array.length; i += size) chunks.push(array.slice(i, i + size));
587
+ return chunks;
588
+ }
589
+ /**
590
+ * Coordination strategy schema for configuration
591
+ */
592
+ const CoordinationStrategySchema = z.object({
593
+ type: z.enum([
594
+ "sequential",
595
+ "parallel",
596
+ "hybrid",
597
+ "custom"
598
+ ]),
599
+ maxConcurrency: z.number().min(1).default(4),
600
+ enableDependencyTracking: z.boolean().default(true),
601
+ allowPartialFailure: z.boolean().default(true),
602
+ timeoutPerAgent: z.number().min(1e3).default(3e4)
603
+ });
604
+
605
+ //#endregion
606
+ //#region src/agents/multi/swarm/communication.ts
607
+ /**
608
+ * Communication Layer - Inter-agent messaging system
609
+ * Based on VERCEL_AI_SDK_V6_PATTERNS.md section 4.4
610
+ * Enables agents to communicate and coordinate during execution
611
+ */
612
+ /**
613
+ * Message schema for inter-agent communication
614
+ */
615
+ const MessageSchema = z.object({
616
+ messageId: z.string().describe("Unique message identifier"),
617
+ senderId: z.string().describe("ID of agent sending the message"),
618
+ senderName: z.string().describe("Name of agent sending the message"),
619
+ recipientId: z.string().optional().describe("ID of specific recipient; undefined = broadcast"),
620
+ topic: z.string().describe("Message topic for categorization"),
621
+ type: z.enum([
622
+ "request",
623
+ "response",
624
+ "notification",
625
+ "query",
626
+ "update"
627
+ ]),
628
+ payload: z.unknown().describe("Message content"),
629
+ timestamp: z.number(),
630
+ correlationId: z.string().optional().describe("Links related messages"),
631
+ priority: z.enum([
632
+ "low",
633
+ "normal",
634
+ "high",
635
+ "critical"
636
+ ]).default("normal"),
637
+ metadata: z.record(z.string(), z.unknown()).optional()
638
+ });
639
+ /**
640
+ * Create a message bus for inter-agent communication
641
+ */
642
+ function createMessageBus() {
643
+ return new MessageBusImpl();
644
+ }
645
+ /**
646
+ * Message bus implementation
647
+ */
648
+ var MessageBusImpl = class extends EventEmitter {
649
+ messageHistory = [];
650
+ subscriptions = /* @__PURE__ */ new Map();
651
+ queryHandlers = /* @__PURE__ */ new Map();
652
+ messageCounter = 0;
653
+ broadcast(message) {
654
+ const fullMessage = {
655
+ ...message,
656
+ messageId: this.generateMessageId(),
657
+ timestamp: Date.now(),
658
+ recipientId: void 0
659
+ };
660
+ this.recordMessage(fullMessage);
661
+ this.emit("broadcast", fullMessage);
662
+ this.notifySubscribers(fullMessage);
663
+ }
664
+ sendToAgent(recipientId, message) {
665
+ const fullMessage = {
666
+ ...message,
667
+ messageId: this.generateMessageId(),
668
+ timestamp: Date.now(),
669
+ recipientId
670
+ };
671
+ this.recordMessage(fullMessage);
672
+ this.emit(`message:${recipientId}`, fullMessage);
673
+ this.notifySubscribers(fullMessage);
674
+ }
675
+ subscribe(agentId, handler, topic) {
676
+ const subscriptionId = `sub_${Date.now()}_${Math.random().toString(36).substring(7)}`;
677
+ const subscription = {
678
+ subscriptionId,
679
+ agentId,
680
+ topic,
681
+ handler,
682
+ unsubscribe: () => {
683
+ this.unsubscribe(subscriptionId);
684
+ }
685
+ };
686
+ const key = topic ? `${agentId}:${topic}` : agentId;
687
+ let subscriptions = this.subscriptions.get(key);
688
+ if (!subscriptions) {
689
+ subscriptions = [];
690
+ this.subscriptions.set(key, subscriptions);
691
+ }
692
+ subscriptions.push(subscription);
693
+ return subscription;
694
+ }
695
+ async query(agentId, query) {
696
+ const handler = this.queryHandlers.get(agentId);
697
+ if (!handler) throw new Error(`No query handler registered for agent: ${agentId}`);
698
+ return handler(query);
699
+ }
700
+ getMessageHistory(topic) {
701
+ if (!topic) return [...this.messageHistory];
702
+ return this.messageHistory.filter((m) => m.topic === topic);
703
+ }
704
+ clearHistory() {
705
+ this.messageHistory = [];
706
+ }
707
+ /**
708
+ * Register a query handler for an agent
709
+ */
710
+ registerQueryHandler(agentId, handler) {
711
+ this.queryHandlers.set(agentId, handler);
712
+ }
713
+ /**
714
+ * Get all subscriptions for an agent
715
+ */
716
+ getSubscriptions(agentId) {
717
+ const subscriptions = [];
718
+ this.subscriptions.forEach((subs) => {
719
+ subscriptions.push(...subs.filter((s) => s.agentId === agentId));
720
+ });
721
+ return subscriptions;
722
+ }
723
+ /**
724
+ * Private: Notify relevant subscribers
725
+ */
726
+ notifySubscribers(message) {
727
+ const allSubscribers = Array.from(this.subscriptions.values()).flat().filter((s) => {
728
+ if (message.recipientId && s.agentId !== message.recipientId && s.agentId !== "*") return false;
729
+ if (s.topic && s.topic !== message.topic) return false;
730
+ return true;
731
+ });
732
+ const seen = /* @__PURE__ */ new Set();
733
+ const uniqueSubscribers = allSubscribers.filter((s) => {
734
+ if (seen.has(s.subscriptionId)) return false;
735
+ seen.add(s.subscriptionId);
736
+ return true;
737
+ });
738
+ for (const subscription of uniqueSubscribers) (async () => {
739
+ try {
740
+ await subscription.handler(message);
741
+ } catch (error) {
742
+ logError(`Error in message handler for ${subscription.agentId}`, { error: error instanceof Error ? error : new Error(String(error)) });
743
+ }
744
+ })();
745
+ }
746
+ /**
747
+ * Private: Record message in history
748
+ */
749
+ recordMessage(message) {
750
+ this.messageHistory.push(message);
751
+ if (this.messageHistory.length > 1e3) this.messageHistory = this.messageHistory.slice(-1e3);
752
+ }
753
+ /**
754
+ * Private: Generate unique message ID
755
+ */
756
+ generateMessageId() {
757
+ return `msg_${++this.messageCounter}_${Date.now()}`;
758
+ }
759
+ /**
760
+ * Private: Unsubscribe
761
+ */
762
+ unsubscribe(subscriptionId) {
763
+ this.subscriptions.forEach((subs) => {
764
+ const index = subs.findIndex((s) => s.subscriptionId === subscriptionId);
765
+ if (index !== -1) subs.splice(index, 1);
766
+ });
767
+ }
768
+ };
769
+ /**
770
+ * Broadcast a message to all agents
771
+ */
772
+ function broadcastMessage(bus, message) {
773
+ bus.broadcast(message);
774
+ }
775
+ /**
776
+ * Route a message to a specific agent
777
+ */
778
+ function routeMessage(bus, recipientId, message) {
779
+ bus.sendToAgent(recipientId, message);
780
+ }
781
+ /**
782
+ * Subscribe to messages
783
+ */
784
+ function subscribeToMessages(bus, agentId, handler, topic) {
785
+ return bus.subscribe(agentId, handler, topic);
786
+ }
787
+ /**
788
+ * Message builder helper
789
+ */
790
+ var MessageBuilder = class {
791
+ message = {};
792
+ from(senderId, senderName) {
793
+ this.message.senderId = senderId;
794
+ this.message.senderName = senderName;
795
+ return this;
796
+ }
797
+ to(recipientId) {
798
+ this.message.recipientId = recipientId;
799
+ return this;
800
+ }
801
+ topic(topic) {
802
+ this.message.topic = topic;
803
+ return this;
804
+ }
805
+ type(type) {
806
+ this.message.type = type;
807
+ return this;
808
+ }
809
+ payload(payload) {
810
+ this.message.payload = payload;
811
+ return this;
812
+ }
813
+ priority(priority) {
814
+ this.message.priority = priority;
815
+ return this;
816
+ }
817
+ correlationId(correlationId) {
818
+ this.message.correlationId = correlationId;
819
+ return this;
820
+ }
821
+ metadata(metadata) {
822
+ this.message.metadata = metadata;
823
+ return this;
824
+ }
825
+ build() {
826
+ if (!this.message.senderId || !this.message.senderName || !this.message.topic || !this.message.type || this.message.payload === void 0) throw new Error("Missing required message fields: senderId, senderName, topic, type, payload");
827
+ return {
828
+ senderId: this.message.senderId,
829
+ senderName: this.message.senderName,
830
+ recipientId: this.message.recipientId,
831
+ topic: this.message.topic,
832
+ type: this.message.type,
833
+ payload: this.message.payload,
834
+ priority: this.message.priority || "normal",
835
+ correlationId: this.message.correlationId,
836
+ metadata: this.message.metadata
837
+ };
838
+ }
839
+ };
840
+ /**
841
+ * Request-response pattern helper
842
+ */
843
+ async function sendRequest(bus, from, to, topic, payload) {
844
+ const correlationId = `req_${Date.now()}_${Math.random().toString(36).substring(7)}`;
845
+ const message = new MessageBuilder().from(from.id, from.name).to(to).topic(topic).type("request").payload(payload).correlationId(correlationId).build();
846
+ return new Promise((resolve, reject) => {
847
+ let subscription = null;
848
+ const timeoutId = setTimeout(() => {
849
+ subscription?.unsubscribe();
850
+ reject(/* @__PURE__ */ new Error(`Request timeout for correlation ID: ${correlationId}`));
851
+ }, 5e3);
852
+ subscription = subscribeToMessages(bus, from.id, (msg) => {
853
+ if (msg.correlationId === correlationId && msg.type === "response") {
854
+ clearTimeout(timeoutId);
855
+ subscription?.unsubscribe();
856
+ resolve(msg.payload);
857
+ }
858
+ });
859
+ routeMessage(bus, to, message);
860
+ });
861
+ }
862
+
863
+ //#endregion
864
+ //#region src/agents/multi/swarm/aggregation.ts
865
+ /**
866
+ * Result Aggregation - Combining outputs from multiple agents
867
+ * Based on VERCEL_AI_SDK_V6_PATTERNS.md section 4.4
868
+ * Provides strategies for merging, voting, and consensus-based result aggregation
869
+ */
870
+ /**
871
+ * Aggregation result
872
+ */
873
+ const AggregationResultSchema = z.object({
874
+ strategy: z.enum([
875
+ "merge",
876
+ "vote",
877
+ "consensus",
878
+ "weighted",
879
+ "custom"
880
+ ]),
881
+ finalResult: z.unknown(),
882
+ confidence: z.number().min(0).max(1),
883
+ details: z.record(z.string(), z.unknown()).optional(),
884
+ timestamp: z.number()
885
+ });
886
+ /**
887
+ * Aggregate results from multiple agents
888
+ * Combines outputs based on specified strategy
889
+ */
890
+ function aggregateResults(results, options = {}) {
891
+ const strategy = options.strategy || "merge";
892
+ const timestamp = Date.now();
893
+ let finalResult;
894
+ let confidence;
895
+ let details;
896
+ switch (strategy) {
897
+ case "merge": {
898
+ const { result: mergedResult, confidence: mergedConfidence, details: mergedDetails } = mergeResults(results);
899
+ finalResult = mergedResult;
900
+ confidence = mergedConfidence;
901
+ details = mergedDetails;
902
+ break;
903
+ }
904
+ case "vote": {
905
+ const { result: votedResult, confidence: votedConfidence, details: votedDetails } = voteOnResults(results);
906
+ finalResult = votedResult;
907
+ confidence = votedConfidence;
908
+ details = votedDetails;
909
+ break;
910
+ }
911
+ case "consensus": {
912
+ const { result: consensusResultValue, confidence: consensusConfidence, details: consensusInfo } = consensusResult(results);
913
+ finalResult = consensusResultValue;
914
+ confidence = consensusConfidence;
915
+ details = consensusInfo;
916
+ break;
917
+ }
918
+ case "weighted": {
919
+ const { result: weightedResult, confidence: weightedConfidence, details: weightedDetails } = weightedAggregation(results, options.weights || {});
920
+ finalResult = weightedResult;
921
+ confidence = weightedConfidence;
922
+ details = weightedDetails;
923
+ break;
924
+ }
925
+ case "custom": {
926
+ const { result: fallbackResult, confidence: fallbackConfidence, details: fallbackDetails } = mergeResults(results);
927
+ finalResult = fallbackResult;
928
+ confidence = fallbackConfidence;
929
+ details = fallbackDetails;
930
+ break;
931
+ }
932
+ default: {
933
+ const { result: fallbackResult, confidence: fallbackConfidence, details: fallbackDetails } = mergeResults(results);
934
+ finalResult = fallbackResult;
935
+ confidence = fallbackConfidence;
936
+ details = fallbackDetails;
937
+ }
938
+ }
939
+ return {
940
+ strategy,
941
+ finalResult,
942
+ confidence,
943
+ details,
944
+ timestamp
945
+ };
946
+ }
947
+ /**
948
+ * Merge results from all agents
949
+ * Combines all successful results into a single output
950
+ */
951
+ function mergeResults(results) {
952
+ const successfulResults = results.filter((r) => r.status === "success");
953
+ const failedResults = results.filter((r) => r.status === "failed");
954
+ const mergedData = {};
955
+ const agentSummaries = [];
956
+ for (const result of results) {
957
+ const { agentId, agentName, status, duration, result: agentResult } = result;
958
+ agentSummaries.push({
959
+ agentId,
960
+ agentName,
961
+ status,
962
+ duration
963
+ });
964
+ if (status === "success" && agentResult) mergedData[agentId] = agentResult;
965
+ }
966
+ const confidence = successfulResults.length / (successfulResults.length + failedResults.length) || 0;
967
+ return {
968
+ result: {
969
+ merged: mergedData,
970
+ summary: {
971
+ total: results.length,
972
+ successful: successfulResults.length,
973
+ failed: failedResults.length
974
+ }
975
+ },
976
+ confidence: Math.round(confidence * 100) / 100,
977
+ details: {
978
+ agentSummaries,
979
+ timestamp: Date.now()
980
+ }
981
+ };
982
+ }
983
+ /**
984
+ * Vote on results - majority voting
985
+ * Returns the most common successful result
986
+ */
987
+ function voteOnResults(results) {
988
+ const successfulResults = results.filter((r) => r.status === "success");
989
+ if (successfulResults.length === 0) return {
990
+ result: null,
991
+ confidence: 0,
992
+ details: { error: "No successful results to vote on" }
993
+ };
994
+ const votes = /* @__PURE__ */ new Map();
995
+ for (const result of successfulResults) {
996
+ const key = JSON.stringify(result.result);
997
+ if (!votes.has(key)) votes.set(key, {
998
+ count: 0,
999
+ agents: [],
1000
+ result
1001
+ });
1002
+ const vote = votes.get(key);
1003
+ if (!vote) continue;
1004
+ vote.count++;
1005
+ vote.agents.push(result.agentId);
1006
+ }
1007
+ let majority = null;
1008
+ for (const vote of votes.values()) if (!majority || vote.count > majority.count) majority = vote;
1009
+ if (!majority) return {
1010
+ result: null,
1011
+ confidence: 0,
1012
+ details: { error: "Could not determine majority vote" }
1013
+ };
1014
+ const confidence = majority.count / successfulResults.length;
1015
+ return {
1016
+ result: majority.result.result,
1017
+ confidence: Math.round(confidence * 100) / 100,
1018
+ details: {
1019
+ majorityVotes: majority.count,
1020
+ totalVotes: successfulResults.length,
1021
+ votingAgents: majority.agents,
1022
+ timestamp: Date.now()
1023
+ }
1024
+ };
1025
+ }
1026
+ /**
1027
+ * Consensus result - weighted consensus
1028
+ * Builds consensus from majority agreement with confidence scores
1029
+ */
1030
+ function consensusResult(results) {
1031
+ const successfulResults = results.filter((r) => r.status === "success");
1032
+ if (successfulResults.length === 0) return {
1033
+ result: null,
1034
+ confidence: 0,
1035
+ details: { error: "No successful results for consensus" }
1036
+ };
1037
+ const groups = /* @__PURE__ */ new Map();
1038
+ for (const result of successfulResults) {
1039
+ const key = JSON.stringify(result.result);
1040
+ let group = groups.get(key);
1041
+ if (!group) {
1042
+ group = {
1043
+ count: 0,
1044
+ agents: []
1045
+ };
1046
+ groups.set(key, group);
1047
+ }
1048
+ group.count++;
1049
+ group.agents.push(result.agentId);
1050
+ }
1051
+ let consensusGroup = null;
1052
+ for (const [key, group] of groups) if (group.count / successfulResults.length > .5) {
1053
+ consensusGroup = {
1054
+ count: group.count,
1055
+ agents: group.agents,
1056
+ result: JSON.parse(key)
1057
+ };
1058
+ break;
1059
+ }
1060
+ if (!consensusGroup) {
1061
+ let maxCount = 0;
1062
+ let maxKey = null;
1063
+ for (const [key, group] of groups) if (group.count > maxCount) {
1064
+ maxCount = group.count;
1065
+ maxKey = key;
1066
+ }
1067
+ if (maxKey) {
1068
+ const group = groups.get(maxKey);
1069
+ if (group) consensusGroup = {
1070
+ count: maxCount,
1071
+ agents: group.agents,
1072
+ result: JSON.parse(maxKey)
1073
+ };
1074
+ }
1075
+ }
1076
+ if (!consensusGroup) return {
1077
+ result: null,
1078
+ confidence: 0,
1079
+ details: { error: "Could not establish consensus" }
1080
+ };
1081
+ const confidence = consensusGroup.count / successfulResults.length;
1082
+ return {
1083
+ result: consensusGroup.result,
1084
+ confidence: Math.round(confidence * 100) / 100,
1085
+ details: {
1086
+ consensusAgents: consensusGroup.agents,
1087
+ agreeingCount: consensusGroup.count,
1088
+ totalSuccessful: successfulResults.length,
1089
+ totalAgents: results.length,
1090
+ timestamp: Date.now()
1091
+ }
1092
+ };
1093
+ }
1094
+ /**
1095
+ * Weighted aggregation
1096
+ * Combines results using specified weights for each agent
1097
+ */
1098
+ function weightedAggregation(results, weights = {}) {
1099
+ const successfulResults = results.filter((r) => r.status === "success");
1100
+ if (successfulResults.length === 0) return {
1101
+ result: null,
1102
+ confidence: 0,
1103
+ details: { error: "No successful results for weighted aggregation" }
1104
+ };
1105
+ const normalizedWeights = {};
1106
+ let totalWeight = 0;
1107
+ for (const result of successfulResults) {
1108
+ const weight = weights[result.agentId] || 1;
1109
+ normalizedWeights[result.agentId] = weight;
1110
+ totalWeight += weight;
1111
+ }
1112
+ const weightedResults = [];
1113
+ let totalConfidence = 0;
1114
+ for (const result of successfulResults) {
1115
+ const weight = (normalizedWeights[result.agentId] ?? 0) / totalWeight;
1116
+ weightedResults.push({
1117
+ result: result.result,
1118
+ weight,
1119
+ agentId: result.agentId
1120
+ });
1121
+ totalConfidence += weight;
1122
+ }
1123
+ const aggregatedData = {};
1124
+ for (const wr of weightedResults) if (typeof wr.result === "object" && wr.result !== null) {
1125
+ for (const [key, value] of Object.entries(wr.result)) if (typeof value === "number") aggregatedData[key] = (aggregatedData[key] || 0) + value * wr.weight;
1126
+ }
1127
+ return {
1128
+ result: aggregatedData,
1129
+ confidence: Math.round(totalConfidence * 100) / 100,
1130
+ details: {
1131
+ weightedResults: weightedResults.map((wr) => ({
1132
+ agentId: wr.agentId,
1133
+ weight: wr.weight
1134
+ })),
1135
+ timestamp: Date.now()
1136
+ }
1137
+ };
1138
+ }
1139
+ /**
1140
+ * Build a custom aggregator
1141
+ */
1142
+ function buildCustomAggregator(aggregateFn) {
1143
+ return { aggregate: async (results) => {
1144
+ return {
1145
+ strategy: "custom",
1146
+ finalResult: aggregateFn(results),
1147
+ confidence: results.length ? results.filter((r) => r.status === "success").length / results.length : 0,
1148
+ timestamp: Date.now()
1149
+ };
1150
+ } };
1151
+ }
1152
+ /**
1153
+ * Compare aggregation strategies
1154
+ * Returns metrics for different strategies applied to same results
1155
+ */
1156
+ function compareStrategies(results) {
1157
+ const strategies = [
1158
+ "merge",
1159
+ "vote",
1160
+ "consensus",
1161
+ "weighted"
1162
+ ];
1163
+ const comparisons = {};
1164
+ for (const strategy of strategies) try {
1165
+ comparisons[strategy] = aggregateResults(results, { strategy });
1166
+ } catch (error) {
1167
+ comparisons[strategy] = {
1168
+ strategy,
1169
+ finalResult: null,
1170
+ confidence: 0,
1171
+ details: { error: error instanceof Error ? error.message : "Unknown error" },
1172
+ timestamp: Date.now()
1173
+ };
1174
+ }
1175
+ return comparisons;
1176
+ }
1177
+
1178
+ //#endregion
1179
+ export { SwarmResultSchema as A, hybridExecution as C, AgentDefinitionSchema as D, validateDependencyGraph as E, SwarmTimingSchema as M, createSwarm as N, AgentResultSchema as O, executeSwarm as P, getReadyAgents as S, sequentialExecution as T, buildExecutionPhases as _, consensusResult as a, getDependencies as b, weightedAggregation as c, broadcastMessage as d, createMessageBus as f, CoordinationStrategySchema as g, subscribeToMessages as h, compareStrategies as i, SwarmTaskSchema as j, SwarmConfigSchema as k, MessageBuilder as l, sendRequest as m, aggregateResults as n, mergeResults as o, routeMessage as p, buildCustomAggregator as r, voteOnResults as s, AggregationResultSchema as t, MessageSchema as u, calculateExecutionOrder as v, parallelExecution as w, getDependentAgents as x, createDependencyGraph as y };
1180
+ //# sourceMappingURL=aggregation-BDop87kL.mjs.map