@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,1534 @@
1
+ import { t as __exportAll } from "./chunk-CkzbjWQW.mjs";
2
+ import { Nt as streamText, Z as generateId, a as isModelRef, et as generateText } from "./ai-runtime-CDzQztTt.mjs";
3
+ import { r as getErrorCode } from "./errors-Dtn-UeRi.mjs";
4
+ import { r as logGeneration } from "./audit-logger-CHIP8bRO.mjs";
5
+ import { n as postprocessText, r as preprocessMessages } from "./compliance-wrapper-CrOMHhHN.mjs";
6
+ import { n as createVercelBlobClient } from "./vercel-blob-adapter-CkOXLT2D.mjs";
7
+ import { t as createUpstashRedis } from "./upstash-adapter-D96Caq2O.mjs";
8
+ import { logError, logInfo, logWarn } from "@od-oneapp/shared/logs";
9
+
10
+ //#region src/pipelines/step-executor.ts
11
+ /**
12
+ * @fileoverview Step Executor
13
+ * Step Executor
14
+ * Executes individual pipeline steps with compliance
15
+ * Leverages AI SDK v6 native features (AbortSignal for timeouts, usage Promise)
16
+ */
17
+ /**
18
+ * Execute a single pipeline step with compliance
19
+ * Uses AI SDK v6 native features:
20
+ * - AbortSignal for timeouts
21
+ * - usage Promise for token tracking
22
+ * - Native streaming APIs
23
+ */
24
+ async function executeStep(step, previousResults, globalCompliance, actorId, runId) {
25
+ const startTime = Date.now();
26
+ const result = {
27
+ stepId: step.id,
28
+ stepName: step.name,
29
+ stepIndex: previousResults.length,
30
+ status: "running",
31
+ output: null,
32
+ phiDetections: [],
33
+ startedAt: /* @__PURE__ */ new Date(),
34
+ metadata: step.transformOutput ? { hasTransform: true } : void 0
35
+ };
36
+ const abortController = new AbortController();
37
+ const timeoutMs = step.timeoutMs ?? 12e4;
38
+ const timeoutId = setTimeout(() => abortController.abort(), timeoutMs);
39
+ try {
40
+ if (step.skipIf) {
41
+ if (await step.skipIf(previousResults)) {
42
+ clearTimeout(timeoutId);
43
+ result.status = "skipped";
44
+ result.completedAt = /* @__PURE__ */ new Date();
45
+ result.durationMs = Date.now() - startTime;
46
+ return result;
47
+ }
48
+ }
49
+ let messages;
50
+ if (step.transformInput) messages = await step.transformInput(previousResults);
51
+ else {
52
+ const lastOutput = previousResults[previousResults.length - 1]?.output;
53
+ if (typeof lastOutput === "string") messages = [{
54
+ role: "user",
55
+ content: lastOutput
56
+ }];
57
+ else messages = [{
58
+ role: "user",
59
+ content: "Continue"
60
+ }];
61
+ }
62
+ if (step.systemPrompt) messages = [{
63
+ role: "system",
64
+ content: step.systemPrompt
65
+ }, ...messages];
66
+ const compliance = {
67
+ ...globalCompliance,
68
+ ...step.compliance
69
+ };
70
+ const { messages: processedMessages, detections } = await preprocessMessages(messages, compliance);
71
+ result.phiDetections = detections;
72
+ const baseOptions = {
73
+ model: step.model,
74
+ messages: processedMessages,
75
+ temperature: step.temperature,
76
+ tools: step.tools,
77
+ abortSignal: abortController.signal
78
+ };
79
+ const options = step.maxTokens ? {
80
+ ...baseOptions,
81
+ maxOutputTokens: step.maxTokens
82
+ } : baseOptions;
83
+ let output;
84
+ let usage;
85
+ if (step.streaming) {
86
+ const streamResult = await streamText(options);
87
+ clearTimeout(timeoutId);
88
+ output = "";
89
+ for await (const chunk of streamResult.textStream) output += chunk;
90
+ usage = await streamResult.usage;
91
+ } else {
92
+ const generateResult = await generateText(options);
93
+ clearTimeout(timeoutId);
94
+ output = generateResult.text;
95
+ usage = await generateResult.usage;
96
+ }
97
+ result.usage = {
98
+ promptTokens: usage.inputTokens ?? 0,
99
+ completionTokens: usage.outputTokens ?? 0,
100
+ totalTokens: usage.totalTokens ?? 0
101
+ };
102
+ let finalOutput = output;
103
+ if (step.transformOutput) finalOutput = await step.transformOutput(output);
104
+ if (typeof finalOutput === "string") {
105
+ const { text: sanitized, detections: outputDetections } = await postprocessText(finalOutput, compliance);
106
+ finalOutput = sanitized;
107
+ result.phiDetections.push(...outputDetections);
108
+ }
109
+ result.output = finalOutput;
110
+ result.status = "completed";
111
+ result.completedAt = /* @__PURE__ */ new Date();
112
+ result.durationMs = Date.now() - startTime;
113
+ await logGeneration(actorId, JSON.stringify(messages), finalOutput, {
114
+ runId,
115
+ stepId: step.id,
116
+ stepName: step.name,
117
+ phiDetections: result.phiDetections.length,
118
+ usage: result.usage
119
+ });
120
+ return result;
121
+ } catch (error) {
122
+ clearTimeout(timeoutId);
123
+ result.status = "failed";
124
+ result.completedAt = /* @__PURE__ */ new Date();
125
+ result.durationMs = Date.now() - startTime;
126
+ const isTimeout = error instanceof Error && error.name === "AbortError";
127
+ result.error = {
128
+ message: isTimeout ? `Step timeout after ${timeoutMs}ms` : error instanceof Error ? error.message : "Unknown error",
129
+ code: isTimeout ? "TIMEOUT" : getErrorCode(error),
130
+ stack: error instanceof Error ? error.stack : void 0
131
+ };
132
+ await logGeneration(actorId, JSON.stringify({ step: step.id }), { error: result.error }, {
133
+ runId,
134
+ stepId: step.id,
135
+ stepName: step.name,
136
+ failed: true
137
+ });
138
+ return result;
139
+ }
140
+ }
141
+ /**
142
+ * Execute step with retry logic
143
+ * Note: Custom retry wrapper - AI SDK v6 doesn't have built-in retry yet
144
+ */
145
+ async function executeStepWithRetry(step, previousResults, globalCompliance, actorId, runId) {
146
+ const retry = step.retry ?? {
147
+ maxAttempts: 1,
148
+ delayMs: 0
149
+ };
150
+ let lastError = null;
151
+ for (let attempt = 0; attempt < retry.maxAttempts; attempt++) {
152
+ try {
153
+ const result = await executeStep(step, previousResults, globalCompliance, actorId, runId);
154
+ if (result.status === "completed" || result.status === "skipped") return result;
155
+ lastError = new Error(result.error?.message ?? "Step failed");
156
+ } catch (error) {
157
+ lastError = error instanceof Error ? error : /* @__PURE__ */ new Error("Unknown error");
158
+ }
159
+ if (attempt < retry.maxAttempts - 1) {
160
+ const delay = retry.backoff === "exponential" ? retry.delayMs * Math.pow(2, attempt) : retry.delayMs;
161
+ await new Promise((resolve) => setTimeout(resolve, delay));
162
+ }
163
+ }
164
+ throw lastError ?? /* @__PURE__ */ new Error("Step failed after retries");
165
+ }
166
+
167
+ //#endregion
168
+ //#region src/pipelines/validation.ts
169
+ /**
170
+ * @fileoverview Pipeline Validation Utilities
171
+ * Pipeline Validation Utilities
172
+ * Validate pipeline configurations before execution
173
+ */
174
+ /**
175
+ * Validate pipeline configuration
176
+ */
177
+ function validatePipelineConfig(config) {
178
+ const errors = [];
179
+ const warnings = [];
180
+ if (!config.id || config.id.trim() === "") errors.push({
181
+ field: "id",
182
+ message: "Pipeline ID is required",
183
+ severity: "error"
184
+ });
185
+ if (!config.name || config.name.trim() === "") errors.push({
186
+ field: "name",
187
+ message: "Pipeline name is required",
188
+ severity: "error"
189
+ });
190
+ if (!config.actorId || config.actorId.trim() === "") errors.push({
191
+ field: "actorId",
192
+ message: "Actor ID is required for audit compliance",
193
+ severity: "error"
194
+ });
195
+ if (!config.storage) errors.push({
196
+ field: "storage",
197
+ message: "Storage type is required",
198
+ severity: "error"
199
+ });
200
+ if (!config.steps || config.steps.length === 0) errors.push({
201
+ field: "steps",
202
+ message: "Pipeline must have at least one step",
203
+ severity: "error"
204
+ });
205
+ else {
206
+ config.steps.forEach((step, index) => {
207
+ const stepErrors = validatePipelineStep(step, index);
208
+ errors.push(...stepErrors.filter((e) => e.severity === "error"));
209
+ warnings.push(...stepErrors.filter((e) => e.severity === "warning"));
210
+ });
211
+ const stepIds = config.steps.map((s) => s.id);
212
+ const duplicates = stepIds.filter((id, index) => stepIds.indexOf(id) !== index);
213
+ if (duplicates.length > 0) errors.push({
214
+ field: "steps",
215
+ message: `Duplicate step IDs found: ${duplicates.join(", ")}`,
216
+ severity: "error"
217
+ });
218
+ }
219
+ if (!config.compliance) warnings.push({
220
+ field: "compliance",
221
+ message: "No compliance configuration provided",
222
+ severity: "warning"
223
+ });
224
+ if (!config.initialMessages || config.initialMessages.length === 0) warnings.push({
225
+ field: "initialMessages",
226
+ message: "No initial messages provided",
227
+ severity: "warning"
228
+ });
229
+ if (config.enableResumption && !config.resumeFromRunId) {}
230
+ if (config.resumeFromRunId && !config.enableResumption) warnings.push({
231
+ field: "resumeFromRunId",
232
+ message: "resumeFromRunId provided but enableResumption is false",
233
+ severity: "warning"
234
+ });
235
+ return {
236
+ valid: errors.length === 0,
237
+ errors,
238
+ warnings
239
+ };
240
+ }
241
+ /**
242
+ * Validate individual pipeline step
243
+ */
244
+ function validatePipelineStep(step, index) {
245
+ const errors = [];
246
+ const field = `steps[${index}]`;
247
+ if (!step.id || step.id.trim() === "") errors.push({
248
+ field: `${field}.id`,
249
+ message: `Step ${index}: ID is required`,
250
+ severity: "error"
251
+ });
252
+ if (!step.name || step.name.trim() === "") errors.push({
253
+ field: `${field}.name`,
254
+ message: `Step ${index}: Name is required`,
255
+ severity: "error"
256
+ });
257
+ if (!step.model) errors.push({
258
+ field: `${field}.model`,
259
+ message: `Step ${index}: Model is required`,
260
+ severity: "error"
261
+ });
262
+ else if (!isModelRef(step.model)) errors.push({
263
+ field: `${field}.model`,
264
+ message: `Step ${index}: Model must be a string or a language model instance`,
265
+ severity: "error"
266
+ });
267
+ if (step.temperature !== void 0 && (step.temperature < 0 || step.temperature > 2)) errors.push({
268
+ field: `${field}.temperature`,
269
+ message: `Step ${index}: Temperature must be between 0 and 2`,
270
+ severity: "error"
271
+ });
272
+ if (step.maxTokens !== void 0) {
273
+ if (step.maxTokens < 1) errors.push({
274
+ field: `${field}.maxTokens`,
275
+ message: `Step ${index}: maxTokens must be positive`,
276
+ severity: "error"
277
+ });
278
+ if (step.maxTokens > 1e5) errors.push({
279
+ field: `${field}.maxTokens`,
280
+ message: `Step ${index}: maxTokens seems unusually high (${step.maxTokens})`,
281
+ severity: "warning"
282
+ });
283
+ }
284
+ if (step.timeoutMs !== void 0) {
285
+ if (step.timeoutMs < 1e3) errors.push({
286
+ field: `${field}.timeoutMs`,
287
+ message: `Step ${index}: Timeout too short (minimum 1000ms recommended)`,
288
+ severity: "warning"
289
+ });
290
+ if (step.timeoutMs > 6e5) errors.push({
291
+ field: `${field}.timeoutMs`,
292
+ message: `Step ${index}: Timeout very long (${step.timeoutMs}ms = ${step.timeoutMs / 6e4} minutes)`,
293
+ severity: "warning"
294
+ });
295
+ }
296
+ if (step.retry) {
297
+ if (step.retry.maxAttempts < 1) errors.push({
298
+ field: `${field}.retry.maxAttempts`,
299
+ message: `Step ${index}: maxAttempts must be at least 1`,
300
+ severity: "error"
301
+ });
302
+ if (step.retry.maxAttempts > 10) errors.push({
303
+ field: `${field}.retry.maxAttempts`,
304
+ message: `Step ${index}: maxAttempts very high (${step.retry.maxAttempts})`,
305
+ severity: "warning"
306
+ });
307
+ if (step.retry.delayMs < 0) errors.push({
308
+ field: `${field}.retry.delayMs`,
309
+ message: `Step ${index}: Retry delay must be non-negative`,
310
+ severity: "error"
311
+ });
312
+ }
313
+ return errors;
314
+ }
315
+ /**
316
+ * Assert pipeline config is valid (throws on error)
317
+ */
318
+ function assertValidPipelineConfig(config) {
319
+ const result = validatePipelineConfig(config);
320
+ if (!result.valid) {
321
+ const errorMessages = result.errors.map((e) => ` - ${e.field}: ${e.message}`);
322
+ throw new Error(`Invalid pipeline configuration:\n${errorMessages.join("\n")}`);
323
+ }
324
+ if (result.warnings.length > 0) {
325
+ logWarn("Pipeline configuration warnings", { warnings: result.warnings });
326
+ result.warnings.forEach((w) => {
327
+ logWarn(` - ${w.field}: ${w.message}`, {
328
+ field: w.field,
329
+ message: w.message
330
+ });
331
+ });
332
+ }
333
+ }
334
+ /**
335
+ * Validate storage configuration
336
+ */
337
+ function validateStorageConfig(config) {
338
+ const errors = [];
339
+ const warnings = [];
340
+ if (config.type === "blob") {
341
+ if (!config.blob?.token) errors.push({
342
+ field: "blob.token",
343
+ message: "Blob token is required for blob storage",
344
+ severity: "error"
345
+ });
346
+ if (!config.redis?.url || !config.redis?.token) errors.push({
347
+ field: "redis",
348
+ message: "Redis configuration is required for blob storage",
349
+ severity: "error"
350
+ });
351
+ }
352
+ if (config.type === "postgres") {
353
+ if (!config.postgres?.connectionString) errors.push({
354
+ field: "postgres.connectionString",
355
+ message: "Connection string is required for postgres storage",
356
+ severity: "error"
357
+ });
358
+ if (!config.blob?.token) errors.push({
359
+ field: "blob.token",
360
+ message: "Blob token is required for postgres storage (artifacts)",
361
+ severity: "error"
362
+ });
363
+ }
364
+ return {
365
+ valid: errors.length === 0,
366
+ errors,
367
+ warnings
368
+ };
369
+ }
370
+
371
+ //#endregion
372
+ //#region src/pipelines/multi-step-wrapper.ts
373
+ /**
374
+ * @fileoverview Multi-Step Pipeline Executor
375
+ * Multi-Step Pipeline Executor
376
+ * Orchestrates execution of multi-step AI pipelines with compliance
377
+ */
378
+ /**
379
+ * Execute a compliant multi-step pipeline
380
+ *
381
+ * @throws {Error} If pipeline configuration is invalid
382
+ * @throws {Error} If storage initialization fails
383
+ * @throws {Error} If any step fails and cannot be retried
384
+ */
385
+ async function executeCompliantPipeline(config, storage) {
386
+ try {
387
+ assertValidPipelineConfig(config);
388
+ } catch (error) {
389
+ throw new Error(`Pipeline configuration validation failed: ${error instanceof Error ? error.message : "Unknown error"}`);
390
+ }
391
+ try {
392
+ await storage.initialize();
393
+ } catch (error) {
394
+ throw new Error(`Storage initialization failed: ${error instanceof Error ? error.message : "Unknown error"}. Check your storage configuration and credentials.`);
395
+ }
396
+ let run;
397
+ let startStepIndex = 0;
398
+ let previousResults = [];
399
+ if (config.resumeFromRunId) {
400
+ const existingRun = await storage.getRun(config.resumeFromRunId);
401
+ if (!existingRun) throw new Error(`Run ${config.resumeFromRunId} not found`);
402
+ run = existingRun;
403
+ startStepIndex = run.currentStepIndex;
404
+ previousResults = await storage.getStepResults(run.runId);
405
+ await storage.updateRun(run.runId, { status: "running" });
406
+ } else run = await storage.createRun(config);
407
+ const startTime = Date.now();
408
+ try {
409
+ const initialStep = config.steps[startStepIndex];
410
+ if (config.hooks?.onStepStart && initialStep) await config.hooks.onStepStart(initialStep, run.runId);
411
+ for (let i = startStepIndex; i < config.steps.length; i++) {
412
+ const step = config.steps[i];
413
+ if (!step) continue;
414
+ if (config.hooks?.onStepStart) await config.hooks.onStepStart(step, run.runId);
415
+ const result = await executeStepWithRetry(step, previousResults, config.compliance, config.actorId, run.runId);
416
+ if (result.output && typeof result.output === "string") result.artifacts = { output: await storage.storeArtifact(run.runId, step.id, {
417
+ type: "output",
418
+ content: result.output,
419
+ contentType: "text/plain"
420
+ }) };
421
+ await storage.addStepResult(run.runId, result);
422
+ previousResults.push(result);
423
+ await storage.updateRun(run.runId, {
424
+ currentStepIndex: i + 1,
425
+ totalPHIDetections: run.totalPHIDetections + result.phiDetections.length,
426
+ totalTokens: run.totalTokens + (result.usage?.totalTokens ?? 0)
427
+ });
428
+ if (config.hooks?.onStepComplete) await config.hooks.onStepComplete(result, run.runId);
429
+ if (result.status === "failed") throw new Error(`Step ${step.name} failed: ${result.error?.message}`);
430
+ }
431
+ const totalDurationMs = Date.now() - startTime;
432
+ await storage.updateRun(run.runId, {
433
+ status: "completed",
434
+ completedAt: /* @__PURE__ */ new Date(),
435
+ totalDurationMs
436
+ });
437
+ const finalResult = {
438
+ run: {
439
+ ...run,
440
+ status: "completed",
441
+ completedAt: /* @__PURE__ */ new Date(),
442
+ totalDurationMs,
443
+ steps: previousResults
444
+ },
445
+ output: previousResults[previousResults.length - 1]?.output,
446
+ steps: previousResults,
447
+ success: true,
448
+ compliance: {
449
+ totalPHIRedacted: previousResults.reduce((sum, r) => sum + r.phiDetections.length, 0),
450
+ phiByType: previousResults.flatMap((r) => r.phiDetections).reduce((acc, d) => {
451
+ acc[d.type] = (acc[d.type] || 0) + 1;
452
+ return acc;
453
+ }, {}),
454
+ totalAuditEvents: previousResults.length,
455
+ policyViolations: 0
456
+ }
457
+ };
458
+ if (config.hooks?.onPipelineComplete) await config.hooks.onPipelineComplete(previousResults, run.runId);
459
+ return finalResult;
460
+ } catch (error) {
461
+ const totalDurationMs = Date.now() - startTime;
462
+ await storage.updateRun(run.runId, {
463
+ status: "failed",
464
+ completedAt: /* @__PURE__ */ new Date(),
465
+ totalDurationMs,
466
+ error: {
467
+ message: error instanceof Error ? error.message : "Unknown error",
468
+ code: getErrorCode(error),
469
+ stack: error instanceof Error ? error.stack : void 0,
470
+ failedStep: config.steps[run.currentStepIndex]?.id
471
+ }
472
+ });
473
+ if (config.hooks?.onPipelineError) await config.hooks.onPipelineError(error instanceof Error ? error : /* @__PURE__ */ new Error("Unknown error"), run.runId);
474
+ return {
475
+ run: {
476
+ ...run,
477
+ status: "failed",
478
+ completedAt: /* @__PURE__ */ new Date(),
479
+ totalDurationMs,
480
+ steps: previousResults,
481
+ error: {
482
+ message: error instanceof Error ? error.message : "Unknown error",
483
+ code: getErrorCode(error),
484
+ stack: error instanceof Error ? error.stack : void 0,
485
+ failedStep: config.steps[run.currentStepIndex]?.id
486
+ }
487
+ },
488
+ output: null,
489
+ steps: previousResults,
490
+ success: false,
491
+ compliance: {
492
+ totalPHIRedacted: previousResults.reduce((sum, r) => sum + r.phiDetections.length, 0),
493
+ phiByType: previousResults.flatMap((r) => r.phiDetections).reduce((acc, d) => {
494
+ acc[d.type] = (acc[d.type] || 0) + 1;
495
+ return acc;
496
+ }, {}),
497
+ totalAuditEvents: previousResults.length,
498
+ policyViolations: 0
499
+ }
500
+ };
501
+ }
502
+ }
503
+ /**
504
+ * Execute pipeline with streaming updates
505
+ */
506
+ async function executeCompliantPipelineStream(config, storage) {
507
+ return new ReadableStream({ async start(controller) {
508
+ try {
509
+ await storage.initialize();
510
+ const run = await storage.createRun(config);
511
+ controller.enqueue({
512
+ type: "step_start",
513
+ runId: run.runId,
514
+ stepId: config.steps[0]?.id,
515
+ timestamp: /* @__PURE__ */ new Date(),
516
+ data: { step: config.steps[0] }
517
+ });
518
+ const previousResults = [];
519
+ for (let i = 0; i < config.steps.length; i++) {
520
+ const step = config.steps[i];
521
+ if (!step) continue;
522
+ controller.enqueue({
523
+ type: "step_start",
524
+ runId: run.runId,
525
+ stepId: step.id,
526
+ timestamp: /* @__PURE__ */ new Date(),
527
+ data: {
528
+ stepIndex: i,
529
+ stepName: step.name
530
+ }
531
+ });
532
+ try {
533
+ const result = await executeStepWithRetry(step, previousResults, config.compliance, config.actorId, run.runId);
534
+ if (result.output && typeof result.output === "string") result.artifacts = { output: await storage.storeArtifact(run.runId, step.id, {
535
+ type: "output",
536
+ content: result.output,
537
+ contentType: "text/plain"
538
+ }) };
539
+ await storage.addStepResult(run.runId, result);
540
+ previousResults.push(result);
541
+ await storage.updateRun(run.runId, { currentStepIndex: i + 1 });
542
+ controller.enqueue({
543
+ type: "step_complete",
544
+ runId: run.runId,
545
+ stepId: step.id,
546
+ timestamp: /* @__PURE__ */ new Date(),
547
+ data: result
548
+ });
549
+ if (result.phiDetections.length > 0) controller.enqueue({
550
+ type: "phi_detection",
551
+ runId: run.runId,
552
+ stepId: step.id,
553
+ timestamp: /* @__PURE__ */ new Date(),
554
+ data: { count: result.phiDetections.length }
555
+ });
556
+ } catch (error) {
557
+ controller.enqueue({
558
+ type: "step_error",
559
+ runId: run.runId,
560
+ stepId: step.id,
561
+ timestamp: /* @__PURE__ */ new Date(),
562
+ data: { error: error instanceof Error ? error.message : "Unknown error" }
563
+ });
564
+ await storage.updateRun(run.runId, {
565
+ status: "failed",
566
+ completedAt: /* @__PURE__ */ new Date()
567
+ });
568
+ controller.enqueue({
569
+ type: "pipeline_error",
570
+ runId: run.runId,
571
+ timestamp: /* @__PURE__ */ new Date(),
572
+ data: { error: error instanceof Error ? error.message : "Unknown error" }
573
+ });
574
+ controller.close();
575
+ return;
576
+ }
577
+ }
578
+ await storage.updateRun(run.runId, {
579
+ status: "completed",
580
+ completedAt: /* @__PURE__ */ new Date()
581
+ });
582
+ controller.enqueue({
583
+ type: "pipeline_complete",
584
+ runId: run.runId,
585
+ timestamp: /* @__PURE__ */ new Date(),
586
+ data: {
587
+ totalSteps: previousResults.length,
588
+ totalPHI: previousResults.reduce((sum, r) => sum + r.phiDetections.length, 0)
589
+ }
590
+ });
591
+ controller.close();
592
+ } catch (error) {
593
+ controller.error(error);
594
+ }
595
+ } });
596
+ }
597
+ /**
598
+ * Create resumption point for a paused pipeline
599
+ */
600
+ async function createResumptionPoint(runId, storage) {
601
+ const run = await storage.getRun(runId);
602
+ if (!run) throw new Error(`Run ${runId} not found`);
603
+ const previousResults = await storage.getStepResults(runId);
604
+ return (await storage.createResumptionPoint(runId, run.currentStepIndex, previousResults)).token;
605
+ }
606
+ /**
607
+ * Resume pipeline from token
608
+ */
609
+ async function resumePipeline(token, config, storage) {
610
+ const resumption = await storage.getResumptionPoint(token);
611
+ if (!resumption) throw new Error("Invalid or expired resumption token");
612
+ return executeCompliantPipeline({
613
+ ...config,
614
+ resumeFromRunId: resumption.runId
615
+ }, storage);
616
+ }
617
+
618
+ //#endregion
619
+ //#region src/pipelines/defaults.ts
620
+ /**
621
+ * Default compliance options for HIPAA-compliant pipelines
622
+ */
623
+ const HIPAA_COMPLIANCE = {
624
+ enablePHIRedaction: true,
625
+ enableABAC: true,
626
+ policyVersion: "v2.0"
627
+ };
628
+ /**
629
+ * Default compliance options for general use (PHI redaction only)
630
+ */
631
+ const BASIC_COMPLIANCE = {
632
+ enablePHIRedaction: true,
633
+ enableABAC: false,
634
+ policyVersion: "v2.0"
635
+ };
636
+ /**
637
+ * No compliance (for non-sensitive data)
638
+ */
639
+ const NO_COMPLIANCE = {
640
+ enablePHIRedaction: false,
641
+ enableABAC: false,
642
+ policyVersion: "v2.0"
643
+ };
644
+ /**
645
+ * Common temperature settings
646
+ */
647
+ const TEMPERATURES = {
648
+ factual: .1,
649
+ balanced: .4,
650
+ creative: .7,
651
+ experimental: .9
652
+ };
653
+ /**
654
+ * Common system prompts
655
+ */
656
+ const SYSTEM_PROMPTS = {
657
+ research: `You are a research assistant. Provide comprehensive, well-researched information.
658
+ Include key facts, concepts, and context. Be thorough and cite sources when possible.`,
659
+ analysis: `You are an expert analyst. Provide deep analysis with:
660
+ - Key insights and patterns
661
+ - Critical evaluation
662
+ - Implications and recommendations
663
+ - Knowledge gaps
664
+
665
+ Be thorough and analytical.`,
666
+ synthesis: `You are a synthesis expert. Create clear, actionable summaries with:
667
+ - Executive summary (3-5 sentences)
668
+ - Key findings
669
+ - Actionable recommendations
670
+ - Next steps
671
+
672
+ Write clearly for a general audience.`,
673
+ editor: `You are an expert editor. Improve clarity, coherence, and impact.
674
+ Focus on structure, flow, and readability. Preserve the author's voice.`,
675
+ critic: `You are a constructive critic. Identify areas for improvement while acknowledging strengths.
676
+ Be specific, actionable, and balanced in your feedback.`
677
+ };
678
+ /**
679
+ * Common timeouts (milliseconds)
680
+ */
681
+ const TIMEOUTS = {
682
+ quick: 3e4,
683
+ standard: 12e4,
684
+ long: 3e5,
685
+ veryLong: 6e5
686
+ };
687
+ /**
688
+ * Common retry configurations
689
+ */
690
+ const RETRY_CONFIGS = {
691
+ none: {
692
+ maxAttempts: 1,
693
+ delayMs: 0
694
+ },
695
+ standard: {
696
+ maxAttempts: 3,
697
+ delayMs: 1e3,
698
+ backoff: "exponential"
699
+ },
700
+ aggressive: {
701
+ maxAttempts: 5,
702
+ delayMs: 2e3,
703
+ backoff: "exponential"
704
+ },
705
+ quick: {
706
+ maxAttempts: 2,
707
+ delayMs: 500,
708
+ backoff: "linear"
709
+ }
710
+ };
711
+
712
+ //#endregion
713
+ //#region src/pipelines/message-transforms.ts
714
+ /**
715
+ * Use previous step's output as next input
716
+ * Most common pattern in pipelines
717
+ */
718
+ function usePreviousOutput(previousResults) {
719
+ const lastOutput = previousResults[previousResults.length - 1]?.output;
720
+ if (typeof lastOutput === "string") return [{
721
+ role: "user",
722
+ content: lastOutput
723
+ }];
724
+ return [{
725
+ role: "user",
726
+ content: "Continue with the previous result."
727
+ }];
728
+ }
729
+ /**
730
+ * Combine all previous outputs into one message
731
+ */
732
+ function combineAllOutputs(previousResults, separator = "\n\n---\n\n") {
733
+ return [{
734
+ role: "user",
735
+ content: previousResults.map((r) => r.output).filter((o) => typeof o === "string").join(separator)
736
+ }];
737
+ }
738
+ /**
739
+ * Create a message with context from previous step
740
+ */
741
+ function withContext(prompt, previousResults) {
742
+ const lastOutput = previousResults[previousResults.length - 1]?.output;
743
+ if (typeof lastOutput === "string") return [{
744
+ role: "user",
745
+ content: `${prompt}\n\nContext:\n${lastOutput}`
746
+ }];
747
+ return [{
748
+ role: "user",
749
+ content: prompt
750
+ }];
751
+ }
752
+ /**
753
+ * Create analysis prompt from research output
754
+ */
755
+ function analyzeResearch(previousResults) {
756
+ return [{
757
+ role: "user",
758
+ content: `Research findings:\n\n${previousResults[0]?.output}\n\nProvide your analysis.`
759
+ }];
760
+ }
761
+ /**
762
+ * Create synthesis prompt from research and analysis
763
+ */
764
+ function synthesizeResults(previousResults) {
765
+ return [{
766
+ role: "user",
767
+ content: `Research:\n${previousResults[0]?.output}\n\nAnalysis:\n${previousResults[1]?.output}\n\nProvide your synthesis.`
768
+ }];
769
+ }
770
+ /**
771
+ * Create refinement prompt
772
+ */
773
+ function refine(instruction, previousResults) {
774
+ const lastOutput = previousResults[previousResults.length - 1]?.output;
775
+ if (typeof lastOutput === "string") return [{
776
+ role: "user",
777
+ content: `Previous version:\n\n${lastOutput}\n\n${instruction}`
778
+ }];
779
+ return [{
780
+ role: "user",
781
+ content: instruction
782
+ }];
783
+ }
784
+
785
+ //#endregion
786
+ //#region src/pipelines/adapters/trace-storage-memory.ts
787
+ /**
788
+ * @fileoverview In-Memory Trace Storage Adapter
789
+ * In-Memory Trace Storage Adapter
790
+ * For testing and development (no persistence)
791
+ */
792
+ /**
793
+ * In-memory storage adapter
794
+ * - Fast for testing and development
795
+ * - No external dependencies
796
+ * - Data lost on process restart
797
+ */
798
+ var MemoryTraceStorage = class {
799
+ runs = /* @__PURE__ */ new Map();
800
+ steps = /* @__PURE__ */ new Map();
801
+ artifacts = /* @__PURE__ */ new Map();
802
+ resumptionPoints = /* @__PURE__ */ new Map();
803
+ actorIndex = /* @__PURE__ */ new Map();
804
+ pipelineIndex = /* @__PURE__ */ new Map();
805
+ async initialize() {}
806
+ async createRun(config) {
807
+ const runId = `${config.id}-${generateId()}`;
808
+ const run = {
809
+ runId,
810
+ pipelineId: config.id,
811
+ actorId: config.actorId,
812
+ status: "running",
813
+ steps: [],
814
+ currentStepIndex: 0,
815
+ startedAt: /* @__PURE__ */ new Date(),
816
+ totalPHIDetections: 0,
817
+ totalTokens: 0,
818
+ complianceMetrics: {
819
+ phiRedacted: 0,
820
+ abacChecks: 0,
821
+ auditEvents: 0,
822
+ approvalRequests: 0
823
+ },
824
+ metadata: config.metadata
825
+ };
826
+ this.runs.set(runId, run);
827
+ let actorRuns = this.actorIndex.get(config.actorId);
828
+ if (!actorRuns) {
829
+ actorRuns = /* @__PURE__ */ new Set();
830
+ this.actorIndex.set(config.actorId, actorRuns);
831
+ }
832
+ actorRuns.add(runId);
833
+ let pipelineRuns = this.pipelineIndex.get(config.id);
834
+ if (!pipelineRuns) {
835
+ pipelineRuns = /* @__PURE__ */ new Set();
836
+ this.pipelineIndex.set(config.id, pipelineRuns);
837
+ }
838
+ pipelineRuns.add(runId);
839
+ return run;
840
+ }
841
+ async getRun(runId) {
842
+ return this.runs.get(runId) ?? null;
843
+ }
844
+ async updateRun(runId, updates) {
845
+ const run = this.runs.get(runId);
846
+ if (!run) throw new Error(`Run ${runId} not found`);
847
+ Object.assign(run, updates);
848
+ this.runs.set(runId, run);
849
+ }
850
+ async addStepResult(runId, result) {
851
+ let runSteps = this.steps.get(runId);
852
+ if (!runSteps) {
853
+ runSteps = [];
854
+ this.steps.set(runId, runSteps);
855
+ }
856
+ runSteps.push(result);
857
+ }
858
+ async getStepResults(runId) {
859
+ return this.steps.get(runId) ?? [];
860
+ }
861
+ async storeArtifact(runId, stepId, artifact) {
862
+ const artifactId = `${runId}/${stepId}/${artifact.type}`;
863
+ this.artifacts.set(artifactId, artifact.content);
864
+ return `memory://${artifactId}`;
865
+ }
866
+ async getArtifact(url) {
867
+ const artifactId = url.replace("memory://", "");
868
+ const artifact = this.artifacts.get(artifactId);
869
+ if (!artifact) throw new Error(`Artifact not found: ${url}`);
870
+ return artifact;
871
+ }
872
+ async createResumptionPoint(runId, stepIndex, previousResults) {
873
+ const token = generateId();
874
+ const resumption = {
875
+ runId,
876
+ stepIndex,
877
+ previousResults,
878
+ token,
879
+ expiresAt: new Date(Date.now() + 3600 * 1e3)
880
+ };
881
+ this.resumptionPoints.set(token, resumption);
882
+ return resumption;
883
+ }
884
+ async getResumptionPoint(token) {
885
+ const resumption = this.resumptionPoints.get(token);
886
+ if (!resumption) return null;
887
+ if (resumption.expiresAt < /* @__PURE__ */ new Date()) {
888
+ this.resumptionPoints.delete(token);
889
+ return null;
890
+ }
891
+ return resumption;
892
+ }
893
+ async cleanupExpiredResumptionPoints() {
894
+ const now = /* @__PURE__ */ new Date();
895
+ let count = 0;
896
+ for (const [token, resumption] of this.resumptionPoints.entries()) if (resumption.expiresAt < now) {
897
+ this.resumptionPoints.delete(token);
898
+ count++;
899
+ }
900
+ return count;
901
+ }
902
+ async queryRunsByActor(actorId, options) {
903
+ let runs = [...this.actorIndex.get(actorId) ?? /* @__PURE__ */ new Set()].flatMap((id) => {
904
+ const run = this.runs.get(id);
905
+ return run ? [run] : [];
906
+ });
907
+ if (options?.status) runs = runs.filter((r) => r.status === options.status);
908
+ runs.sort((a, b) => b.startedAt.getTime() - a.startedAt.getTime());
909
+ const offset = options?.offset ?? 0;
910
+ const limit = options?.limit || 10;
911
+ return runs.slice(offset, offset + limit);
912
+ }
913
+ async queryRunsByPipeline(pipelineId, options) {
914
+ let runs = [...this.pipelineIndex.get(pipelineId) ?? /* @__PURE__ */ new Set()].flatMap((id) => {
915
+ const run = this.runs.get(id);
916
+ return run ? [run] : [];
917
+ });
918
+ if (options?.status) runs = runs.filter((r) => r.status === options.status);
919
+ runs.sort((a, b) => b.startedAt.getTime() - a.startedAt.getTime());
920
+ const offset = options?.offset ?? 0;
921
+ const limit = options?.limit || 10;
922
+ return runs.slice(offset, offset + limit);
923
+ }
924
+ async getComplianceMetrics(startDate, endDate, options) {
925
+ let runs = [...this.runs.values()];
926
+ runs = runs.filter((r) => r.startedAt >= startDate && r.startedAt <= endDate);
927
+ if (options?.actorId) runs = runs.filter((r) => r.actorId === options.actorId);
928
+ if (options?.pipelineId) runs = runs.filter((r) => r.pipelineId === options.pipelineId);
929
+ const metrics = {
930
+ totalRuns: runs.length,
931
+ totalPHIDetections: runs.reduce((sum, r) => sum + r.totalPHIDetections, 0),
932
+ totalAuditEvents: runs.reduce((sum, r) => sum + (r.complianceMetrics.auditEvents ?? 0), 0),
933
+ totalApprovals: runs.reduce((sum, r) => sum + (r.complianceMetrics.approvalRequests ?? 0), 0),
934
+ phiByType: {},
935
+ runsByStatus: {}
936
+ };
937
+ for (const run of runs) metrics.runsByStatus[run.status] = (metrics.runsByStatus[run.status] || 0) + 1;
938
+ return metrics;
939
+ }
940
+ async close() {}
941
+ /**
942
+ * Clear all data (useful for testing)
943
+ */
944
+ clear() {
945
+ this.runs.clear();
946
+ this.steps.clear();
947
+ this.artifacts.clear();
948
+ this.resumptionPoints.clear();
949
+ this.actorIndex.clear();
950
+ this.pipelineIndex.clear();
951
+ }
952
+ /**
953
+ * Get storage statistics
954
+ */
955
+ getStats() {
956
+ return {
957
+ runs: this.runs.size,
958
+ steps: [...this.steps.values()].reduce((sum, steps) => sum + steps.length, 0),
959
+ artifacts: this.artifacts.size,
960
+ resumptionPoints: this.resumptionPoints.size
961
+ };
962
+ }
963
+ };
964
+ /**
965
+ * Create in-memory storage adapter
966
+ */
967
+ function createMemoryTraceStorage() {
968
+ return new MemoryTraceStorage();
969
+ }
970
+
971
+ //#endregion
972
+ //#region src/pipelines/pipeline-presets.ts
973
+ /**
974
+ * @fileoverview Pipeline Presets
975
+ * Pipeline Presets
976
+ * Simplified API for common pipeline patterns
977
+ */
978
+ /**
979
+ * Execute a simple pipeline with sensible defaults
980
+ *
981
+ * @example
982
+ * ```typescript
983
+ * const result = await quickPipeline({
984
+ * name: 'Research Pipeline',
985
+ * query: 'What is AI safety?',
986
+ * steps: [
987
+ * { name: 'Research', model: openai('gpt-5.1-instant') },
988
+ * { name: 'Analyze', model: anthropic('claude-sonnet-4-5') },
989
+ * ],
990
+ * });
991
+ * console.log(result.output);
992
+ * ```
993
+ */
994
+ async function quickPipeline(options) {
995
+ const { name, steps: simpleSteps, query, userId = "default_user", storage = createMemoryTraceStorage(), enablePHI = true, enableABAC = false } = options;
996
+ const steps = simpleSteps.map((step, index) => {
997
+ const { transformInput } = step;
998
+ return {
999
+ id: `step_${index + 1}`,
1000
+ name: step.name,
1001
+ model: step.model,
1002
+ systemPrompt: step.systemPrompt,
1003
+ temperature: step.temperature ?? .7,
1004
+ streaming: true,
1005
+ transformInput: transformInput ? (previousResults) => {
1006
+ return transformInput(previousResults.at(-1)?.output ?? null);
1007
+ } : index === 0 ? () => [{
1008
+ role: "user",
1009
+ content: query
1010
+ }] : (previousResults) => {
1011
+ return [{
1012
+ role: "user",
1013
+ content: previousResults[previousResults.length - 1]?.output ?? query
1014
+ }];
1015
+ }
1016
+ };
1017
+ });
1018
+ const config = {
1019
+ id: `quick_${Date.now()}`,
1020
+ name,
1021
+ actorId: userId,
1022
+ storage: "blob",
1023
+ initialMessages: [{
1024
+ role: "user",
1025
+ content: query
1026
+ }],
1027
+ compliance: {
1028
+ enablePHIRedaction: enablePHI,
1029
+ enableABAC,
1030
+ policyVersion: "v2.0"
1031
+ },
1032
+ steps
1033
+ };
1034
+ assertValidPipelineConfig(config);
1035
+ return executeCompliantPipeline(config, storage);
1036
+ }
1037
+ /**
1038
+ * Create a two-step pipeline: Research → Synthesis
1039
+ *
1040
+ * @example
1041
+ * ```typescript
1042
+ * const result = await researchAndSynthesize({
1043
+ * query: 'What are the latest trends in AI?',
1044
+ * researchModel: openai('gpt-5.1-instant'),
1045
+ * synthesisModel: anthropic('claude-sonnet-4-5'),
1046
+ * });
1047
+ * ```
1048
+ */
1049
+ async function researchAndSynthesize(options) {
1050
+ return quickPipeline({
1051
+ name: "Research & Synthesis Pipeline",
1052
+ query: options.query,
1053
+ userId: options.userId,
1054
+ storage: options.storage,
1055
+ steps: [{
1056
+ name: "Research",
1057
+ model: options.researchModel,
1058
+ systemPrompt: "You are a research assistant. Provide comprehensive, well-researched information.",
1059
+ temperature: .3
1060
+ }, {
1061
+ name: "Synthesize",
1062
+ model: options.synthesisModel,
1063
+ systemPrompt: "You are a synthesis expert. Create a clear, concise summary with key insights.",
1064
+ temperature: .7,
1065
+ transformInput: (previousOutput) => [{
1066
+ role: "user",
1067
+ content: `Research findings:\n\n${previousOutput}\n\nProvide a synthesis with key insights.`
1068
+ }]
1069
+ }]
1070
+ });
1071
+ }
1072
+ /**
1073
+ * Create a three-step pipeline: Research → Analyze → Synthesize
1074
+ *
1075
+ * @example
1076
+ * ```typescript
1077
+ * const result = await deepResearchPipeline({
1078
+ * query: 'Explain quantum computing',
1079
+ * models: {
1080
+ * research: openai('gpt-5.1-instant'),
1081
+ * analysis: anthropic('claude-sonnet-4-5'),
1082
+ * synthesis: openai('gpt-5.1-thinking'),
1083
+ * },
1084
+ * });
1085
+ * ```
1086
+ */
1087
+ async function deepResearchPipeline(options) {
1088
+ return quickPipeline({
1089
+ name: "Deep Research Pipeline",
1090
+ query: options.query,
1091
+ userId: options.userId,
1092
+ storage: options.storage,
1093
+ steps: [
1094
+ {
1095
+ name: "Research",
1096
+ model: options.models.research,
1097
+ systemPrompt: "You are a research assistant. Gather comprehensive information.",
1098
+ temperature: .3
1099
+ },
1100
+ {
1101
+ name: "Analyze",
1102
+ model: options.models.analysis,
1103
+ systemPrompt: "You are an expert analyst. Provide deep analysis, identify patterns, and evaluate critically.",
1104
+ temperature: .5,
1105
+ transformInput: (previousOutput) => [{
1106
+ role: "user",
1107
+ content: `Research findings:\n\n${previousOutput}\n\nProvide your expert analysis.`
1108
+ }]
1109
+ },
1110
+ {
1111
+ name: "Synthesize",
1112
+ model: options.models.synthesis,
1113
+ systemPrompt: "You are a synthesis expert. Create an executive summary with actionable insights.",
1114
+ temperature: .7,
1115
+ transformInput: (previousOutput) => [{
1116
+ role: "user",
1117
+ content: `Analysis:\n\n${previousOutput}\n\nCreate a final synthesis with actionable insights.`
1118
+ }]
1119
+ }
1120
+ ]
1121
+ });
1122
+ }
1123
+ /**
1124
+ * Create a pipeline for iterative refinement
1125
+ *
1126
+ * @example
1127
+ * ```typescript
1128
+ * const result = await iterativeRefinement({
1129
+ * initialContent: 'Draft blog post about AI...',
1130
+ * refinementSteps: 3,
1131
+ * model: anthropic('claude-sonnet-4-5'),
1132
+ * });
1133
+ * ```
1134
+ */
1135
+ async function iterativeRefinement(options) {
1136
+ const steps = [];
1137
+ for (let i = 0; i < options.refinementSteps; i++) steps.push({
1138
+ name: `Refinement ${i + 1}`,
1139
+ model: options.model,
1140
+ systemPrompt: `You are an expert editor. Improve clarity, coherence, and impact. This is iteration ${i + 1} of ${options.refinementSteps}.`,
1141
+ temperature: .5,
1142
+ transformInput: i === 0 ? () => [{
1143
+ role: "user",
1144
+ content: options.initialContent
1145
+ }] : (previousOutput) => [{
1146
+ role: "user",
1147
+ content: `Previous version:\n\n${previousOutput}\n\nRefine and improve this further.`
1148
+ }]
1149
+ });
1150
+ return quickPipeline({
1151
+ name: "Iterative Refinement Pipeline",
1152
+ query: options.initialContent,
1153
+ userId: options.userId,
1154
+ storage: options.storage,
1155
+ steps
1156
+ });
1157
+ }
1158
+ /**
1159
+ * Execute pipeline with custom retry logic
1160
+ *
1161
+ * @example
1162
+ * ```typescript
1163
+ * const result = await pipelineWithRetry({
1164
+ * config: myPipelineConfig,
1165
+ * storage: myStorage,
1166
+ * maxRetries: 3,
1167
+ * });
1168
+ * ```
1169
+ */
1170
+ async function pipelineWithRetry(options) {
1171
+ const { config, storage, maxRetries = 3, retryDelay = 2e3 } = options;
1172
+ let lastError = null;
1173
+ for (let attempt = 0; attempt < maxRetries; attempt++) try {
1174
+ return await executeCompliantPipeline(config, storage);
1175
+ } catch (error) {
1176
+ lastError = error instanceof Error ? error : /* @__PURE__ */ new Error("Unknown error");
1177
+ logError(`Pipeline attempt ${attempt + 1} failed`, {
1178
+ error: lastError,
1179
+ attempt: attempt + 1,
1180
+ config
1181
+ });
1182
+ if (attempt < maxRetries - 1) await new Promise((resolve) => setTimeout(resolve, retryDelay * (attempt + 1)));
1183
+ }
1184
+ throw new Error(`Pipeline failed after ${maxRetries} attempts. Last error: ${lastError?.message}`);
1185
+ }
1186
+
1187
+ //#endregion
1188
+ //#region src/pipelines/trace-storage-interface.ts
1189
+ /**
1190
+ * Helper to create storage adapter
1191
+ *
1192
+ * For ESM compatibility, import adapters directly:
1193
+ * ```typescript
1194
+ * import { createBlobTraceStorage } from '#/lib/ai-onedigital/adapters/trace-storage-blob';
1195
+ * const storage = createBlobTraceStorage(config);
1196
+ * ```
1197
+ */
1198
+ function createTraceStorage(config) {
1199
+ switch (config.type) {
1200
+ case "blob": throw new Error("Use createBlobTraceStorage() directly from #/lib/ai-onedigital/adapters/trace-storage-blob");
1201
+ case "postgres": throw new Error("PostgresTraceStorage not yet implemented. See adapters/trace-storage-postgres/README.md");
1202
+ default: throw new Error(`Unknown storage type: ${config.type}. Use 'blob' or 'postgres'`);
1203
+ }
1204
+ }
1205
+
1206
+ //#endregion
1207
+ //#region src/pipelines/adapters/trace-storage-blob.ts
1208
+ /**
1209
+ * @fileoverview Blob Trace Storage Adapter
1210
+ * Blob Trace Storage Adapter
1211
+ * Uses Vercel Blob for artifacts + Upstash Redis for metadata
1212
+ */
1213
+ const DEFAULT_MAX_ARTIFACT_BYTES = 5 * 1024 * 1024;
1214
+ const stringifyArtifact = (value) => {
1215
+ const seen = /* @__PURE__ */ new WeakSet();
1216
+ return JSON.stringify(value, (key, current) => {
1217
+ if (typeof current === "bigint") return current.toString();
1218
+ if (typeof current === "object" && current !== null) {
1219
+ if (seen.has(current)) throw new Error("Artifact content contains a circular reference");
1220
+ seen.add(current);
1221
+ }
1222
+ return current;
1223
+ });
1224
+ };
1225
+ const serializeArtifactContent = (artifact, maxBytes) => {
1226
+ try {
1227
+ const { content: artifactContent } = artifact;
1228
+ let content;
1229
+ if (typeof artifactContent === "string") content = Buffer.from(artifactContent);
1230
+ else if (Buffer.isBuffer(artifactContent)) content = artifactContent;
1231
+ else content = Buffer.from(stringifyArtifact(artifactContent));
1232
+ if (content.byteLength > maxBytes) throw new Error(`Artifact content exceeds max size (${maxBytes} bytes)`);
1233
+ return content;
1234
+ } catch (error) {
1235
+ const message = error instanceof Error ? error.message : "Unknown error";
1236
+ throw new Error(`Failed to serialize artifact content: ${message}`);
1237
+ }
1238
+ };
1239
+ /**
1240
+ * Blob storage adapter
1241
+ * - Metadata: Upstash Redis (fast queries)
1242
+ * - Artifacts: Vercel Blob (large files)
1243
+ */
1244
+ var BlobTraceStorage = class {
1245
+ redis;
1246
+ blob;
1247
+ cacheTTL;
1248
+ artifactRetentionDays;
1249
+ artifactMaxBytes;
1250
+ resumptionTTL;
1251
+ constructor(config) {
1252
+ if (!config.redis) throw new Error("Redis configuration required for BlobTraceStorage");
1253
+ if (!config.blob) throw new Error("Blob configuration required for BlobTraceStorage");
1254
+ this.redis = createUpstashRedis({
1255
+ url: config.redis.url,
1256
+ token: config.redis.token
1257
+ });
1258
+ this.blob = createVercelBlobClient({
1259
+ token: config.blob.token,
1260
+ baseUrl: config.blob.baseUrl
1261
+ });
1262
+ this.cacheTTL = config.cacheTTL ?? 3600;
1263
+ this.artifactRetentionDays = config.artifactRetentionDays ?? 90;
1264
+ this.artifactMaxBytes = config.artifactMaxBytes ?? DEFAULT_MAX_ARTIFACT_BYTES;
1265
+ this.resumptionTTL = config.resumptionTTL || 3600;
1266
+ }
1267
+ async initialize() {
1268
+ try {
1269
+ await this.redis.ping();
1270
+ } catch (error) {
1271
+ throw new Error(`Failed to connect to Redis: ${error instanceof Error ? error.message : "Unknown error"}`);
1272
+ }
1273
+ }
1274
+ async createRun(config) {
1275
+ const runId = `${config.id}-${generateId()}`;
1276
+ const run = {
1277
+ runId,
1278
+ pipelineId: config.id,
1279
+ actorId: config.actorId,
1280
+ status: "running",
1281
+ steps: [],
1282
+ currentStepIndex: 0,
1283
+ startedAt: /* @__PURE__ */ new Date(),
1284
+ totalPHIDetections: 0,
1285
+ totalTokens: 0,
1286
+ complianceMetrics: {
1287
+ phiRedacted: 0,
1288
+ abacChecks: 0,
1289
+ auditEvents: 0,
1290
+ approvalRequests: 0
1291
+ },
1292
+ metadata: config.metadata
1293
+ };
1294
+ await this.redis.set(`run:${runId}`, JSON.stringify(run), { ex: this.cacheTTL });
1295
+ await this.redis.zadd(`actor:${config.actorId}:runs`, {
1296
+ score: Date.now(),
1297
+ member: runId
1298
+ });
1299
+ await this.redis.zadd(`pipeline:${config.id}:runs`, {
1300
+ score: Date.now(),
1301
+ member: runId
1302
+ });
1303
+ await this.redis.zadd("global:runs", {
1304
+ score: Date.now(),
1305
+ member: runId
1306
+ });
1307
+ return run;
1308
+ }
1309
+ async getRun(runId) {
1310
+ const data = await this.redis.get(`run:${runId}`);
1311
+ if (!data) return null;
1312
+ const run = JSON.parse(data);
1313
+ run.startedAt = new Date(run.startedAt);
1314
+ if (run.completedAt) run.completedAt = new Date(run.completedAt);
1315
+ return run;
1316
+ }
1317
+ async updateRun(runId, updates) {
1318
+ const run = await this.getRun(runId);
1319
+ if (!run) throw new Error(`Run ${runId} not found`);
1320
+ const updated = {
1321
+ ...run,
1322
+ ...updates
1323
+ };
1324
+ await this.redis.set(`run:${runId}`, JSON.stringify(updated), { ex: this.cacheTTL });
1325
+ }
1326
+ async addStepResult(runId, result) {
1327
+ await this.redis.set(`run:${runId}:step:${result.stepId}`, JSON.stringify(result), { ex: this.cacheTTL });
1328
+ await this.redis.zadd(`run:${runId}:steps`, {
1329
+ score: result.stepIndex,
1330
+ member: result.stepId
1331
+ });
1332
+ }
1333
+ async getStepResults(runId) {
1334
+ const stepIds = await this.redis.zrange(`run:${runId}:steps`, 0, -1);
1335
+ return (await Promise.all(stepIds.map(async (stepId) => {
1336
+ const data = await this.redis.get(`run:${runId}:step:${stepId}`);
1337
+ if (!data) return null;
1338
+ const step = JSON.parse(data);
1339
+ step.startedAt = new Date(step.startedAt);
1340
+ if (step.completedAt) step.completedAt = new Date(step.completedAt);
1341
+ return step;
1342
+ }))).filter((r) => r !== null);
1343
+ }
1344
+ async storeArtifact(runId, stepId, artifact) {
1345
+ const pathname = `pipelines/${runId}/${stepId}/${artifact.type}`;
1346
+ const content = serializeArtifactContent(artifact, this.artifactMaxBytes);
1347
+ return (await this.blob.put(pathname, content, {
1348
+ access: "public",
1349
+ contentType: artifact.contentType
1350
+ })).url;
1351
+ }
1352
+ async getArtifact(url) {
1353
+ const response = await fetch(url);
1354
+ if (!response.ok) throw new Error(`Failed to fetch artifact: ${response.statusText}`);
1355
+ const contentType = response.headers.get("content-type") ?? "";
1356
+ if (contentType.includes("application/json")) return await response.json();
1357
+ else if (contentType.includes("text/")) return await response.text();
1358
+ else return Buffer.from(await response.arrayBuffer());
1359
+ }
1360
+ async createResumptionPoint(runId, stepIndex, previousResults) {
1361
+ const token = generateId();
1362
+ const resumption = {
1363
+ runId,
1364
+ stepIndex,
1365
+ previousResults,
1366
+ token,
1367
+ expiresAt: new Date(Date.now() + this.resumptionTTL * 1e3)
1368
+ };
1369
+ await this.redis.set(`resumption:${token}`, JSON.stringify(resumption), { ex: this.resumptionTTL });
1370
+ return resumption;
1371
+ }
1372
+ async getResumptionPoint(token) {
1373
+ const data = await this.redis.get(`resumption:${token}`);
1374
+ if (!data) return null;
1375
+ const resumption = JSON.parse(data);
1376
+ resumption.expiresAt = new Date(resumption.expiresAt);
1377
+ resumption.previousResults = resumption.previousResults.map((r) => ({
1378
+ ...r,
1379
+ startedAt: new Date(r.startedAt),
1380
+ completedAt: r.completedAt ? new Date(r.completedAt) : void 0
1381
+ }));
1382
+ return resumption;
1383
+ }
1384
+ async cleanupExpiredResumptionPoints() {
1385
+ return 0;
1386
+ }
1387
+ async queryRunsByActor(actorId, options) {
1388
+ const limit = options?.limit ?? 10;
1389
+ const offset = options?.offset || 0;
1390
+ const runIds = await this.redis.zrange(`actor:${actorId}:runs`, offset, offset + limit - 1, { rev: true });
1391
+ let filtered = (await Promise.all(runIds.map((id) => this.getRun(id)))).filter((r) => r !== null);
1392
+ if (options?.status) filtered = filtered.filter((r) => r.status === options.status);
1393
+ return filtered;
1394
+ }
1395
+ async queryRunsByPipeline(pipelineId, options) {
1396
+ const limit = options?.limit ?? 10;
1397
+ const offset = options?.offset || 0;
1398
+ const runIds = await this.redis.zrange(`pipeline:${pipelineId}:runs`, offset, offset + limit - 1, { rev: true });
1399
+ let filtered = (await Promise.all(runIds.map((id) => this.getRun(id)))).filter((r) => r !== null);
1400
+ if (options?.status) filtered = filtered.filter((r) => r.status === options.status);
1401
+ return filtered;
1402
+ }
1403
+ async getComplianceMetrics(startDate, endDate, options) {
1404
+ let runIds;
1405
+ if (options?.actorId) runIds = await this.redis.zrange(`actor:${options.actorId}:runs`, startDate.getTime(), endDate.getTime(), { byScore: true });
1406
+ else if (options?.pipelineId) runIds = await this.redis.zrange(`pipeline:${options.pipelineId}:runs`, startDate.getTime(), endDate.getTime(), { byScore: true });
1407
+ else runIds = await this.redis.zrange("global:runs", startDate.getTime(), endDate.getTime(), { byScore: true });
1408
+ const validRuns = (await Promise.all(runIds.map((id) => this.getRun(id)))).filter((r) => r !== null);
1409
+ const metrics = {
1410
+ totalRuns: validRuns.length,
1411
+ totalPHIDetections: validRuns.reduce((sum, r) => sum + r.totalPHIDetections, 0),
1412
+ totalAuditEvents: validRuns.reduce((sum, r) => sum + r.complianceMetrics.auditEvents, 0),
1413
+ totalApprovals: validRuns.reduce((sum, r) => sum + r.complianceMetrics.approvalRequests, 0),
1414
+ phiByType: {},
1415
+ runsByStatus: {}
1416
+ };
1417
+ for (const run of validRuns) metrics.runsByStatus[run.status] = (metrics.runsByStatus[run.status] || 0) + 1;
1418
+ return metrics;
1419
+ }
1420
+ async close() {}
1421
+ };
1422
+ /**
1423
+ * Create blob storage adapter
1424
+ */
1425
+ function createBlobTraceStorage(config) {
1426
+ return new BlobTraceStorage(config);
1427
+ }
1428
+
1429
+ //#endregion
1430
+ //#region src/pipelines/storage-factory.ts
1431
+ /**
1432
+ * @fileoverview Storage Factory Helpers
1433
+ * Storage Factory Helpers
1434
+ * DRY helpers for creating storage adapters from environment variables
1435
+ */
1436
+ /**
1437
+ * Create storage adapter from environment variables
1438
+ * No config needed - reads from process.env automatically
1439
+ *
1440
+ * @example
1441
+ * ```typescript
1442
+ * const storage = createStorageFromEnv();
1443
+ * // Uses VERCEL_BLOB_READ_WRITE_TOKEN, UPSTASH_REDIS_URL, UPSTASH_REDIS_TOKEN
1444
+ * ```
1445
+ */
1446
+ function createStorageFromEnv(type = "blob") {
1447
+ if (type === "memory") return createMemoryTraceStorage();
1448
+ const blobToken = process.env.VERCEL_BLOB_READ_WRITE_TOKEN;
1449
+ const redisUrl = process.env.UPSTASH_REDIS_URL;
1450
+ const redisToken = process.env.UPSTASH_REDIS_TOKEN;
1451
+ if (!blobToken || !redisUrl || !redisToken) throw new Error(`Missing required environment variables for blob storage:\n${!blobToken ? " - VERCEL_BLOB_READ_WRITE_TOKEN\n" : ""}${!redisUrl ? " - UPSTASH_REDIS_URL\n" : ""}${!redisToken ? " - UPSTASH_REDIS_TOKEN\n" : ""}Set these in your .env file or use createMemoryTraceStorage() for testing.`);
1452
+ return createBlobTraceStorage({
1453
+ type: "blob",
1454
+ blob: { token: blobToken },
1455
+ redis: {
1456
+ url: redisUrl,
1457
+ token: redisToken
1458
+ }
1459
+ });
1460
+ }
1461
+ /**
1462
+ * Create storage for development (memory-based)
1463
+ * No environment variables required
1464
+ */
1465
+ function createDevStorage() {
1466
+ return createMemoryTraceStorage();
1467
+ }
1468
+ /**
1469
+ * Create storage for production (blob-based)
1470
+ * Validates all required environment variables
1471
+ */
1472
+ function createProdStorage() {
1473
+ return createStorageFromEnv("blob");
1474
+ }
1475
+ /**
1476
+ * Auto-detect storage type based on environment
1477
+ * Development: memory storage
1478
+ * Production: blob storage
1479
+ */
1480
+ function createAutoStorage() {
1481
+ const isDev = process.env.NODE_ENV === "development";
1482
+ const hasEnvVars = process.env.VERCEL_BLOB_READ_WRITE_TOKEN && process.env.UPSTASH_REDIS_URL && process.env.UPSTASH_REDIS_TOKEN;
1483
+ if (isDev && !hasEnvVars) {
1484
+ logInfo("[Pipeline] Using in-memory storage (development mode)");
1485
+ return createMemoryTraceStorage();
1486
+ }
1487
+ return createStorageFromEnv("blob");
1488
+ }
1489
+
1490
+ //#endregion
1491
+ //#region src/pipelines/index.ts
1492
+ var pipelines_exports = /* @__PURE__ */ __exportAll({
1493
+ BASIC_COMPLIANCE: () => BASIC_COMPLIANCE,
1494
+ BlobTraceStorage: () => BlobTraceStorage,
1495
+ HIPAA_COMPLIANCE: () => HIPAA_COMPLIANCE,
1496
+ MemoryTraceStorage: () => MemoryTraceStorage,
1497
+ NO_COMPLIANCE: () => NO_COMPLIANCE,
1498
+ RETRY_CONFIGS: () => RETRY_CONFIGS,
1499
+ SYSTEM_PROMPTS: () => SYSTEM_PROMPTS,
1500
+ TEMPERATURES: () => TEMPERATURES,
1501
+ TIMEOUTS: () => TIMEOUTS,
1502
+ analyzeResearch: () => analyzeResearch,
1503
+ assertValidPipelineConfig: () => assertValidPipelineConfig,
1504
+ combineAllOutputs: () => combineAllOutputs,
1505
+ createAutoStorage: () => createAutoStorage,
1506
+ createBlobTraceStorage: () => createBlobTraceStorage,
1507
+ createDevStorage: () => createDevStorage,
1508
+ createMemoryTraceStorage: () => createMemoryTraceStorage,
1509
+ createProdStorage: () => createProdStorage,
1510
+ createResumptionPoint: () => createResumptionPoint,
1511
+ createStorageFromEnv: () => createStorageFromEnv,
1512
+ createTraceStorage: () => createTraceStorage,
1513
+ deepResearchPipeline: () => deepResearchPipeline,
1514
+ executeCompliantPipeline: () => executeCompliantPipeline,
1515
+ executeCompliantPipelineStream: () => executeCompliantPipelineStream,
1516
+ executeStep: () => executeStep,
1517
+ executeStepWithRetry: () => executeStepWithRetry,
1518
+ iterativeRefinement: () => iterativeRefinement,
1519
+ pipelineWithRetry: () => pipelineWithRetry,
1520
+ quickPipeline: () => quickPipeline,
1521
+ refine: () => refine,
1522
+ researchAndSynthesize: () => researchAndSynthesize,
1523
+ resumePipeline: () => resumePipeline,
1524
+ synthesizeResults: () => synthesizeResults,
1525
+ usePreviousOutput: () => usePreviousOutput,
1526
+ validatePipelineConfig: () => validatePipelineConfig,
1527
+ validatePipelineStep: () => validatePipelineStep,
1528
+ validateStorageConfig: () => validateStorageConfig,
1529
+ withContext: () => withContext
1530
+ });
1531
+
1532
+ //#endregion
1533
+ export { BASIC_COMPLIANCE, BlobTraceStorage, HIPAA_COMPLIANCE, MemoryTraceStorage, NO_COMPLIANCE, RETRY_CONFIGS, SYSTEM_PROMPTS, TEMPERATURES, TIMEOUTS, analyzeResearch, assertValidPipelineConfig, combineAllOutputs, createAutoStorage, createBlobTraceStorage, createDevStorage, createMemoryTraceStorage, createProdStorage, createResumptionPoint, createStorageFromEnv, createTraceStorage, deepResearchPipeline, executeCompliantPipeline, executeCompliantPipelineStream, executeStep, executeStepWithRetry, iterativeRefinement, pipelineWithRetry, quickPipeline, refine, researchAndSynthesize, resumePipeline, synthesizeResults, pipelines_exports as t, usePreviousOutput, validatePipelineConfig, validatePipelineStep, validateStorageConfig, withContext };
1534
+ //# sourceMappingURL=pipelines.mjs.map