@defai.digital/contracts 13.0.3

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 (388) hide show
  1. package/LICENSE +214 -0
  2. package/dist/ability/v1/index.d.ts +5 -0
  3. package/dist/ability/v1/index.d.ts.map +1 -0
  4. package/dist/ability/v1/index.js +5 -0
  5. package/dist/ability/v1/index.js.map +1 -0
  6. package/dist/ability/v1/schema.d.ts +288 -0
  7. package/dist/ability/v1/schema.d.ts.map +1 -0
  8. package/dist/ability/v1/schema.js +138 -0
  9. package/dist/ability/v1/schema.js.map +1 -0
  10. package/dist/agent/v1/index.d.ts +8 -0
  11. package/dist/agent/v1/index.d.ts.map +1 -0
  12. package/dist/agent/v1/index.js +31 -0
  13. package/dist/agent/v1/index.js.map +1 -0
  14. package/dist/agent/v1/schema.d.ts +4055 -0
  15. package/dist/agent/v1/schema.d.ts.map +1 -0
  16. package/dist/agent/v1/schema.js +970 -0
  17. package/dist/agent/v1/schema.js.map +1 -0
  18. package/dist/agent/v1/storage-port.d.ts +172 -0
  19. package/dist/agent/v1/storage-port.d.ts.map +1 -0
  20. package/dist/agent/v1/storage-port.js +10 -0
  21. package/dist/agent/v1/storage-port.js.map +1 -0
  22. package/dist/analysis/v1/index.d.ts +7 -0
  23. package/dist/analysis/v1/index.d.ts.map +1 -0
  24. package/dist/analysis/v1/index.js +21 -0
  25. package/dist/analysis/v1/index.js.map +1 -0
  26. package/dist/analysis/v1/schema.d.ts +348 -0
  27. package/dist/analysis/v1/schema.d.ts.map +1 -0
  28. package/dist/analysis/v1/schema.js +252 -0
  29. package/dist/analysis/v1/schema.js.map +1 -0
  30. package/dist/cli/v1/index.d.ts +8 -0
  31. package/dist/cli/v1/index.d.ts.map +1 -0
  32. package/dist/cli/v1/index.js +46 -0
  33. package/dist/cli/v1/index.js.map +1 -0
  34. package/dist/cli/v1/output.d.ts +347 -0
  35. package/dist/cli/v1/output.d.ts.map +1 -0
  36. package/dist/cli/v1/output.js +288 -0
  37. package/dist/cli/v1/output.js.map +1 -0
  38. package/dist/cli/v1/schema.d.ts +494 -0
  39. package/dist/cli/v1/schema.d.ts.map +1 -0
  40. package/dist/cli/v1/schema.js +342 -0
  41. package/dist/cli/v1/schema.js.map +1 -0
  42. package/dist/config/v1/config.d.ts +887 -0
  43. package/dist/config/v1/config.d.ts.map +1 -0
  44. package/dist/config/v1/config.js +348 -0
  45. package/dist/config/v1/config.js.map +1 -0
  46. package/dist/config/v1/errors.d.ts +84 -0
  47. package/dist/config/v1/errors.d.ts.map +1 -0
  48. package/dist/config/v1/errors.js +150 -0
  49. package/dist/config/v1/errors.js.map +1 -0
  50. package/dist/config/v1/events.d.ts +416 -0
  51. package/dist/config/v1/events.d.ts.map +1 -0
  52. package/dist/config/v1/events.js +204 -0
  53. package/dist/config/v1/events.js.map +1 -0
  54. package/dist/config/v1/index.d.ts +11 -0
  55. package/dist/config/v1/index.d.ts.map +1 -0
  56. package/dist/config/v1/index.js +49 -0
  57. package/dist/config/v1/index.js.map +1 -0
  58. package/dist/config/v1/operations.d.ts +293 -0
  59. package/dist/config/v1/operations.d.ts.map +1 -0
  60. package/dist/config/v1/operations.js +172 -0
  61. package/dist/config/v1/operations.js.map +1 -0
  62. package/dist/config/v1/provider-config.d.ts +124 -0
  63. package/dist/config/v1/provider-config.d.ts.map +1 -0
  64. package/dist/config/v1/provider-config.js +123 -0
  65. package/dist/config/v1/provider-config.js.map +1 -0
  66. package/dist/constants.d.ts +292 -0
  67. package/dist/constants.d.ts.map +1 -0
  68. package/dist/constants.js +370 -0
  69. package/dist/constants.js.map +1 -0
  70. package/dist/context/v1/index.d.ts +5 -0
  71. package/dist/context/v1/index.d.ts.map +1 -0
  72. package/dist/context/v1/index.js +13 -0
  73. package/dist/context/v1/index.js.map +1 -0
  74. package/dist/context/v1/schema.d.ts +289 -0
  75. package/dist/context/v1/schema.d.ts.map +1 -0
  76. package/dist/context/v1/schema.js +145 -0
  77. package/dist/context/v1/schema.js.map +1 -0
  78. package/dist/cross-cutting/v1/dead-letter.d.ts +305 -0
  79. package/dist/cross-cutting/v1/dead-letter.d.ts.map +1 -0
  80. package/dist/cross-cutting/v1/dead-letter.js +172 -0
  81. package/dist/cross-cutting/v1/dead-letter.js.map +1 -0
  82. package/dist/cross-cutting/v1/idempotency.d.ts +222 -0
  83. package/dist/cross-cutting/v1/idempotency.d.ts.map +1 -0
  84. package/dist/cross-cutting/v1/idempotency.js +170 -0
  85. package/dist/cross-cutting/v1/idempotency.js.map +1 -0
  86. package/dist/cross-cutting/v1/index.d.ts +14 -0
  87. package/dist/cross-cutting/v1/index.d.ts.map +1 -0
  88. package/dist/cross-cutting/v1/index.js +18 -0
  89. package/dist/cross-cutting/v1/index.js.map +1 -0
  90. package/dist/cross-cutting/v1/retention.d.ts +347 -0
  91. package/dist/cross-cutting/v1/retention.d.ts.map +1 -0
  92. package/dist/cross-cutting/v1/retention.js +178 -0
  93. package/dist/cross-cutting/v1/retention.js.map +1 -0
  94. package/dist/cross-cutting/v1/saga.d.ts +358 -0
  95. package/dist/cross-cutting/v1/saga.d.ts.map +1 -0
  96. package/dist/cross-cutting/v1/saga.js +219 -0
  97. package/dist/cross-cutting/v1/saga.js.map +1 -0
  98. package/dist/design/v1/index.d.ts +5 -0
  99. package/dist/design/v1/index.d.ts.map +1 -0
  100. package/dist/design/v1/index.js +5 -0
  101. package/dist/design/v1/index.js.map +1 -0
  102. package/dist/design/v1/schema.d.ts +748 -0
  103. package/dist/design/v1/schema.d.ts.map +1 -0
  104. package/dist/design/v1/schema.js +316 -0
  105. package/dist/design/v1/schema.js.map +1 -0
  106. package/dist/discussion/v1/index.d.ts +10 -0
  107. package/dist/discussion/v1/index.d.ts.map +1 -0
  108. package/dist/discussion/v1/index.js +21 -0
  109. package/dist/discussion/v1/index.js.map +1 -0
  110. package/dist/discussion/v1/schema.d.ts +1186 -0
  111. package/dist/discussion/v1/schema.d.ts.map +1 -0
  112. package/dist/discussion/v1/schema.js +560 -0
  113. package/dist/discussion/v1/schema.js.map +1 -0
  114. package/dist/file-system/v1/index.d.ts +7 -0
  115. package/dist/file-system/v1/index.d.ts.map +1 -0
  116. package/dist/file-system/v1/index.js +7 -0
  117. package/dist/file-system/v1/index.js.map +1 -0
  118. package/dist/file-system/v1/schema.d.ts +644 -0
  119. package/dist/file-system/v1/schema.d.ts.map +1 -0
  120. package/dist/file-system/v1/schema.js +278 -0
  121. package/dist/file-system/v1/schema.js.map +1 -0
  122. package/dist/guard/v1/index.d.ts +9 -0
  123. package/dist/guard/v1/index.d.ts.map +1 -0
  124. package/dist/guard/v1/index.js +10 -0
  125. package/dist/guard/v1/index.js.map +1 -0
  126. package/dist/guard/v1/schema.d.ts +308 -0
  127. package/dist/guard/v1/schema.d.ts.map +1 -0
  128. package/dist/guard/v1/schema.js +267 -0
  129. package/dist/guard/v1/schema.js.map +1 -0
  130. package/dist/index.d.ts +68 -0
  131. package/dist/index.d.ts.map +1 -0
  132. package/dist/index.js +117 -0
  133. package/dist/index.js.map +1 -0
  134. package/dist/iterate/v1/index.d.ts +5 -0
  135. package/dist/iterate/v1/index.d.ts.map +1 -0
  136. package/dist/iterate/v1/index.js +13 -0
  137. package/dist/iterate/v1/index.js.map +1 -0
  138. package/dist/iterate/v1/schema.d.ts +693 -0
  139. package/dist/iterate/v1/schema.d.ts.map +1 -0
  140. package/dist/iterate/v1/schema.js +244 -0
  141. package/dist/iterate/v1/schema.js.map +1 -0
  142. package/dist/mcp/v1/index.d.ts +8 -0
  143. package/dist/mcp/v1/index.d.ts.map +1 -0
  144. package/dist/mcp/v1/index.js +20 -0
  145. package/dist/mcp/v1/index.js.map +1 -0
  146. package/dist/mcp/v1/prompts/index.d.ts +5 -0
  147. package/dist/mcp/v1/prompts/index.d.ts.map +1 -0
  148. package/dist/mcp/v1/prompts/index.js +5 -0
  149. package/dist/mcp/v1/prompts/index.js.map +1 -0
  150. package/dist/mcp/v1/prompts/schema.d.ts +266 -0
  151. package/dist/mcp/v1/prompts/schema.d.ts.map +1 -0
  152. package/dist/mcp/v1/prompts/schema.js +138 -0
  153. package/dist/mcp/v1/prompts/schema.js.map +1 -0
  154. package/dist/mcp/v1/rate-limit.schema.d.ts +175 -0
  155. package/dist/mcp/v1/rate-limit.schema.d.ts.map +1 -0
  156. package/dist/mcp/v1/rate-limit.schema.js +164 -0
  157. package/dist/mcp/v1/rate-limit.schema.js.map +1 -0
  158. package/dist/mcp/v1/resources/index.d.ts +5 -0
  159. package/dist/mcp/v1/resources/index.d.ts.map +1 -0
  160. package/dist/mcp/v1/resources/index.js +5 -0
  161. package/dist/mcp/v1/resources/index.js.map +1 -0
  162. package/dist/mcp/v1/resources/schema.d.ts +169 -0
  163. package/dist/mcp/v1/resources/schema.d.ts.map +1 -0
  164. package/dist/mcp/v1/resources/schema.js +118 -0
  165. package/dist/mcp/v1/resources/schema.js.map +1 -0
  166. package/dist/mcp/v1/runtime/cache.d.ts +204 -0
  167. package/dist/mcp/v1/runtime/cache.d.ts.map +1 -0
  168. package/dist/mcp/v1/runtime/cache.js +92 -0
  169. package/dist/mcp/v1/runtime/cache.js.map +1 -0
  170. package/dist/mcp/v1/runtime/index.d.ts +5 -0
  171. package/dist/mcp/v1/runtime/index.d.ts.map +1 -0
  172. package/dist/mcp/v1/runtime/index.js +9 -0
  173. package/dist/mcp/v1/runtime/index.js.map +1 -0
  174. package/dist/mcp/v1/runtime/limits.d.ts +113 -0
  175. package/dist/mcp/v1/runtime/limits.d.ts.map +1 -0
  176. package/dist/mcp/v1/runtime/limits.js +95 -0
  177. package/dist/mcp/v1/runtime/limits.js.map +1 -0
  178. package/dist/mcp/v1/runtime/response.d.ts +467 -0
  179. package/dist/mcp/v1/runtime/response.d.ts.map +1 -0
  180. package/dist/mcp/v1/runtime/response.js +130 -0
  181. package/dist/mcp/v1/runtime/response.js.map +1 -0
  182. package/dist/mcp/v1/runtime/timeout.d.ts +116 -0
  183. package/dist/mcp/v1/runtime/timeout.d.ts.map +1 -0
  184. package/dist/mcp/v1/runtime/timeout.js +116 -0
  185. package/dist/mcp/v1/runtime/timeout.js.map +1 -0
  186. package/dist/mcp/v1/schema.d.ts +171 -0
  187. package/dist/mcp/v1/schema.d.ts.map +1 -0
  188. package/dist/mcp/v1/schema.js +97 -0
  189. package/dist/mcp/v1/schema.js.map +1 -0
  190. package/dist/mcp/v1/tools/agent.d.ts +485 -0
  191. package/dist/mcp/v1/tools/agent.d.ts.map +1 -0
  192. package/dist/mcp/v1/tools/agent.js +264 -0
  193. package/dist/mcp/v1/tools/agent.js.map +1 -0
  194. package/dist/mcp/v1/tools/guard.d.ts +243 -0
  195. package/dist/mcp/v1/tools/guard.d.ts.map +1 -0
  196. package/dist/mcp/v1/tools/guard.js +136 -0
  197. package/dist/mcp/v1/tools/guard.js.map +1 -0
  198. package/dist/mcp/v1/tools/index.d.ts +15 -0
  199. package/dist/mcp/v1/tools/index.d.ts.map +1 -0
  200. package/dist/mcp/v1/tools/index.js +22 -0
  201. package/dist/mcp/v1/tools/index.js.map +1 -0
  202. package/dist/mcp/v1/tools/memory.d.ts +569 -0
  203. package/dist/mcp/v1/tools/memory.d.ts.map +1 -0
  204. package/dist/mcp/v1/tools/memory.js +319 -0
  205. package/dist/mcp/v1/tools/memory.js.map +1 -0
  206. package/dist/mcp/v1/tools/session.d.ts +545 -0
  207. package/dist/mcp/v1/tools/session.d.ts.map +1 -0
  208. package/dist/mcp/v1/tools/session.js +309 -0
  209. package/dist/mcp/v1/tools/session.js.map +1 -0
  210. package/dist/mcp/v1/tools/tool-list-schemas.d.ts +354 -0
  211. package/dist/mcp/v1/tools/tool-list-schemas.d.ts.map +1 -0
  212. package/dist/mcp/v1/tools/tool-list-schemas.js +140 -0
  213. package/dist/mcp/v1/tools/tool-list-schemas.js.map +1 -0
  214. package/dist/mcp/v1/tools/trace.d.ts +282 -0
  215. package/dist/mcp/v1/tools/trace.d.ts.map +1 -0
  216. package/dist/mcp/v1/tools/trace.js +94 -0
  217. package/dist/mcp/v1/tools/trace.js.map +1 -0
  218. package/dist/mcp/v1/tools/workflow.d.ts +146 -0
  219. package/dist/mcp/v1/tools/workflow.d.ts.map +1 -0
  220. package/dist/mcp/v1/tools/workflow.js +68 -0
  221. package/dist/mcp/v1/tools/workflow.js.map +1 -0
  222. package/dist/mcp/v1/trace/index.d.ts +5 -0
  223. package/dist/mcp/v1/trace/index.d.ts.map +1 -0
  224. package/dist/mcp/v1/trace/index.js +5 -0
  225. package/dist/mcp/v1/trace/index.js.map +1 -0
  226. package/dist/mcp/v1/trace/tool-trace.d.ts +107 -0
  227. package/dist/mcp/v1/trace/tool-trace.d.ts.map +1 -0
  228. package/dist/mcp/v1/trace/tool-trace.js +91 -0
  229. package/dist/mcp/v1/trace/tool-trace.js.map +1 -0
  230. package/dist/memory/v1/index.d.ts +2 -0
  231. package/dist/memory/v1/index.d.ts.map +1 -0
  232. package/dist/memory/v1/index.js +2 -0
  233. package/dist/memory/v1/index.js.map +1 -0
  234. package/dist/memory/v1/schema.d.ts +188 -0
  235. package/dist/memory/v1/schema.d.ts.map +1 -0
  236. package/dist/memory/v1/schema.js +108 -0
  237. package/dist/memory/v1/schema.js.map +1 -0
  238. package/dist/ml-lifecycle/v1/index.d.ts +12 -0
  239. package/dist/ml-lifecycle/v1/index.d.ts.map +1 -0
  240. package/dist/ml-lifecycle/v1/index.js +12 -0
  241. package/dist/ml-lifecycle/v1/index.js.map +1 -0
  242. package/dist/ml-lifecycle/v1/schema.d.ts +1207 -0
  243. package/dist/ml-lifecycle/v1/schema.d.ts.map +1 -0
  244. package/dist/ml-lifecycle/v1/schema.js +481 -0
  245. package/dist/ml-lifecycle/v1/schema.js.map +1 -0
  246. package/dist/orchestration/v1/index.d.ts +5 -0
  247. package/dist/orchestration/v1/index.d.ts.map +1 -0
  248. package/dist/orchestration/v1/index.js +23 -0
  249. package/dist/orchestration/v1/index.js.map +1 -0
  250. package/dist/orchestration/v1/schema.d.ts +1384 -0
  251. package/dist/orchestration/v1/schema.d.ts.map +1 -0
  252. package/dist/orchestration/v1/schema.js +394 -0
  253. package/dist/orchestration/v1/schema.js.map +1 -0
  254. package/dist/provider/v1/circuit-breaker.d.ts +151 -0
  255. package/dist/provider/v1/circuit-breaker.d.ts.map +1 -0
  256. package/dist/provider/v1/circuit-breaker.js +119 -0
  257. package/dist/provider/v1/circuit-breaker.js.map +1 -0
  258. package/dist/provider/v1/health.d.ts +246 -0
  259. package/dist/provider/v1/health.d.ts.map +1 -0
  260. package/dist/provider/v1/health.js +190 -0
  261. package/dist/provider/v1/health.js.map +1 -0
  262. package/dist/provider/v1/index.d.ts +13 -0
  263. package/dist/provider/v1/index.d.ts.map +1 -0
  264. package/dist/provider/v1/index.js +17 -0
  265. package/dist/provider/v1/index.js.map +1 -0
  266. package/dist/provider/v1/port.d.ts +237 -0
  267. package/dist/provider/v1/port.d.ts.map +1 -0
  268. package/dist/provider/v1/port.js +113 -0
  269. package/dist/provider/v1/port.js.map +1 -0
  270. package/dist/provider/v1/rate-limit.d.ts +214 -0
  271. package/dist/provider/v1/rate-limit.d.ts.map +1 -0
  272. package/dist/provider/v1/rate-limit.js +165 -0
  273. package/dist/provider/v1/rate-limit.js.map +1 -0
  274. package/dist/resilience/v1/circuit-breaker.d.ts +135 -0
  275. package/dist/resilience/v1/circuit-breaker.d.ts.map +1 -0
  276. package/dist/resilience/v1/circuit-breaker.js +105 -0
  277. package/dist/resilience/v1/circuit-breaker.js.map +1 -0
  278. package/dist/resilience/v1/index.d.ts +17 -0
  279. package/dist/resilience/v1/index.d.ts.map +1 -0
  280. package/dist/resilience/v1/index.js +17 -0
  281. package/dist/resilience/v1/index.js.map +1 -0
  282. package/dist/resilience/v1/loop-guard.d.ts +123 -0
  283. package/dist/resilience/v1/loop-guard.d.ts.map +1 -0
  284. package/dist/resilience/v1/loop-guard.js +96 -0
  285. package/dist/resilience/v1/loop-guard.js.map +1 -0
  286. package/dist/resilience/v1/metrics.d.ts +323 -0
  287. package/dist/resilience/v1/metrics.d.ts.map +1 -0
  288. package/dist/resilience/v1/metrics.js +183 -0
  289. package/dist/resilience/v1/metrics.js.map +1 -0
  290. package/dist/resilience/v1/rate-limiter.d.ts +122 -0
  291. package/dist/resilience/v1/rate-limiter.d.ts.map +1 -0
  292. package/dist/resilience/v1/rate-limiter.js +119 -0
  293. package/dist/resilience/v1/rate-limiter.js.map +1 -0
  294. package/dist/resilience/v1/resource-limits.d.ts +146 -0
  295. package/dist/resilience/v1/resource-limits.d.ts.map +1 -0
  296. package/dist/resilience/v1/resource-limits.js +130 -0
  297. package/dist/resilience/v1/resource-limits.js.map +1 -0
  298. package/dist/review/v1/index.d.ts +7 -0
  299. package/dist/review/v1/index.d.ts.map +1 -0
  300. package/dist/review/v1/index.js +23 -0
  301. package/dist/review/v1/index.js.map +1 -0
  302. package/dist/review/v1/schema.d.ts +1284 -0
  303. package/dist/review/v1/schema.d.ts.map +1 -0
  304. package/dist/review/v1/schema.js +423 -0
  305. package/dist/review/v1/schema.js.map +1 -0
  306. package/dist/routing/v1/index.d.ts +2 -0
  307. package/dist/routing/v1/index.d.ts.map +1 -0
  308. package/dist/routing/v1/index.js +2 -0
  309. package/dist/routing/v1/index.js.map +1 -0
  310. package/dist/routing/v1/schema.d.ts +315 -0
  311. package/dist/routing/v1/schema.d.ts.map +1 -0
  312. package/dist/routing/v1/schema.js +103 -0
  313. package/dist/routing/v1/schema.js.map +1 -0
  314. package/dist/scaffold/v1/index.d.ts +7 -0
  315. package/dist/scaffold/v1/index.d.ts.map +1 -0
  316. package/dist/scaffold/v1/index.js +7 -0
  317. package/dist/scaffold/v1/index.js.map +1 -0
  318. package/dist/scaffold/v1/schema.d.ts +351 -0
  319. package/dist/scaffold/v1/schema.d.ts.map +1 -0
  320. package/dist/scaffold/v1/schema.js +238 -0
  321. package/dist/scaffold/v1/schema.js.map +1 -0
  322. package/dist/session/v1/index.d.ts +7 -0
  323. package/dist/session/v1/index.d.ts.map +1 -0
  324. package/dist/session/v1/index.js +23 -0
  325. package/dist/session/v1/index.js.map +1 -0
  326. package/dist/session/v1/schema.d.ts +1156 -0
  327. package/dist/session/v1/schema.d.ts.map +1 -0
  328. package/dist/session/v1/schema.js +315 -0
  329. package/dist/session/v1/schema.js.map +1 -0
  330. package/dist/storage/v1/index.d.ts +9 -0
  331. package/dist/storage/v1/index.d.ts.map +1 -0
  332. package/dist/storage/v1/index.js +21 -0
  333. package/dist/storage/v1/index.js.map +1 -0
  334. package/dist/storage/v1/schema.d.ts +411 -0
  335. package/dist/storage/v1/schema.d.ts.map +1 -0
  336. package/dist/storage/v1/schema.js +167 -0
  337. package/dist/storage/v1/schema.js.map +1 -0
  338. package/dist/telemetry/v1/index.d.ts +5 -0
  339. package/dist/telemetry/v1/index.d.ts.map +1 -0
  340. package/dist/telemetry/v1/index.js +5 -0
  341. package/dist/telemetry/v1/index.js.map +1 -0
  342. package/dist/telemetry/v1/schema.d.ts +747 -0
  343. package/dist/telemetry/v1/schema.d.ts.map +1 -0
  344. package/dist/telemetry/v1/schema.js +300 -0
  345. package/dist/telemetry/v1/schema.js.map +1 -0
  346. package/dist/token-budget/v1/index.d.ts +7 -0
  347. package/dist/token-budget/v1/index.d.ts.map +1 -0
  348. package/dist/token-budget/v1/index.js +25 -0
  349. package/dist/token-budget/v1/index.js.map +1 -0
  350. package/dist/token-budget/v1/schema.d.ts +588 -0
  351. package/dist/token-budget/v1/schema.d.ts.map +1 -0
  352. package/dist/token-budget/v1/schema.js +239 -0
  353. package/dist/token-budget/v1/schema.js.map +1 -0
  354. package/dist/trace/v1/index.d.ts +2 -0
  355. package/dist/trace/v1/index.d.ts.map +1 -0
  356. package/dist/trace/v1/index.js +4 -0
  357. package/dist/trace/v1/index.js.map +1 -0
  358. package/dist/trace/v1/schema.d.ts +531 -0
  359. package/dist/trace/v1/schema.d.ts.map +1 -0
  360. package/dist/trace/v1/schema.js +243 -0
  361. package/dist/trace/v1/schema.js.map +1 -0
  362. package/dist/workflow/v1/index.d.ts +3 -0
  363. package/dist/workflow/v1/index.d.ts.map +1 -0
  364. package/dist/workflow/v1/index.js +8 -0
  365. package/dist/workflow/v1/index.js.map +1 -0
  366. package/dist/workflow/v1/schema.d.ts +267 -0
  367. package/dist/workflow/v1/schema.d.ts.map +1 -0
  368. package/dist/workflow/v1/schema.js +95 -0
  369. package/dist/workflow/v1/schema.js.map +1 -0
  370. package/dist/workflow/v1/step-guard.d.ts +571 -0
  371. package/dist/workflow/v1/step-guard.d.ts.map +1 -0
  372. package/dist/workflow/v1/step-guard.js +305 -0
  373. package/dist/workflow/v1/step-guard.js.map +1 -0
  374. package/dist/workflow-templates/v1/index.d.ts +8 -0
  375. package/dist/workflow-templates/v1/index.d.ts.map +1 -0
  376. package/dist/workflow-templates/v1/index.js +8 -0
  377. package/dist/workflow-templates/v1/index.js.map +1 -0
  378. package/dist/workflow-templates/v1/schema.d.ts +714 -0
  379. package/dist/workflow-templates/v1/schema.d.ts.map +1 -0
  380. package/dist/workflow-templates/v1/schema.js +168 -0
  381. package/dist/workflow-templates/v1/schema.js.map +1 -0
  382. package/package.json +142 -0
  383. package/src/guard/v1/policy.schema.json +56 -0
  384. package/src/mcp/v1/tools.schema.json +108 -0
  385. package/src/memory/v1/event.schema.json +136 -0
  386. package/src/routing/v1/decision.schema.json +155 -0
  387. package/src/trace/v1/event.schema.json +197 -0
  388. package/src/workflow/v1/workflow.schema.json +142 -0
@@ -0,0 +1,970 @@
1
+ /**
2
+ * Agent Domain Contracts v1
3
+ *
4
+ * Zod schemas for agent profiles, orchestration, and events.
5
+ */
6
+ import { z } from 'zod';
7
+ // ============================================================================
8
+ // Supporting Schemas
9
+ // ============================================================================
10
+ /**
11
+ * Agent personality traits
12
+ */
13
+ export const AgentPersonalitySchema = z.object({
14
+ traits: z.array(z.string().max(100)).max(10).optional(),
15
+ catchphrase: z.string().max(200).optional(),
16
+ communicationStyle: z.string().max(200).optional(),
17
+ decisionMaking: z.string().max(200).optional(),
18
+ });
19
+ /**
20
+ * Ability selection configuration
21
+ */
22
+ export const AbilitySelectionSchema = z.object({
23
+ core: z.array(z.string().max(100)).max(50).optional(),
24
+ taskBased: z.record(z.string(), z.array(z.string())).optional(),
25
+ loadAll: z.boolean().optional(),
26
+ });
27
+ /**
28
+ * Redirect rule for agent selection
29
+ */
30
+ export const RedirectRuleSchema = z.object({
31
+ phrase: z.string().max(500),
32
+ suggest: z.string().max(100),
33
+ });
34
+ /**
35
+ * Agent category for routing classification
36
+ *
37
+ * Categories help CLI understand agent roles:
38
+ * - orchestrator: Delegates to others (CEO, CTO, architecture)
39
+ * - implementer: Executes tasks directly (backend, frontend, devops)
40
+ * - reviewer: Reviews/audits work (reviewer, security, quality)
41
+ * - specialist: Domain expert (blockchain, ml-engineer, quantum)
42
+ * - generalist: Fallback agent (standard)
43
+ */
44
+ export const AgentCategorySchema = z.enum([
45
+ 'orchestrator',
46
+ 'implementer',
47
+ 'reviewer',
48
+ 'specialist',
49
+ 'generalist',
50
+ ]);
51
+ /**
52
+ * Selection metadata for agent routing
53
+ *
54
+ * Invariants:
55
+ * - INV-AGT-SEL-005: exampleTasks boost confidence when matched
56
+ * - INV-AGT-SEL-006: notForTasks reduce confidence when matched
57
+ */
58
+ export const SelectionMetadataSchema = z.object({
59
+ primaryIntents: z.array(z.string().max(100)).max(20).optional(),
60
+ secondarySignals: z.array(z.string().max(100)).max(20).optional(),
61
+ negativeIntents: z.array(z.string().max(100)).max(20).optional(),
62
+ redirectWhen: z.array(RedirectRuleSchema).max(10).optional(),
63
+ keywords: z.array(z.string().max(50)).max(50).optional(),
64
+ antiKeywords: z.array(z.string().max(50)).max(50).optional(),
65
+ // NEW: Explicit task examples for better matching
66
+ exampleTasks: z.array(z.string().max(200)).max(10).optional()
67
+ .describe('Example tasks this agent handles well'),
68
+ notForTasks: z.array(z.string().max(200)).max(10).optional()
69
+ .describe('Tasks this agent should NOT handle'),
70
+ // NEW: Agent category for grouping
71
+ agentCategory: AgentCategorySchema.optional()
72
+ .describe('Agent classification for routing'),
73
+ });
74
+ /**
75
+ * Provider affinity configuration for multi-model discussions
76
+ *
77
+ * Invariants:
78
+ * - INV-AGT-AFF-001: Preferred providers are prioritized in discussions
79
+ * - INV-AGT-AFF-002: Default synthesizer is used for consensus when not specified
80
+ */
81
+ export const ProviderAffinitySchema = z.object({
82
+ /** Preferred providers for this agent's discussions (ordered by preference) */
83
+ preferred: z.array(z.string().max(50)).max(6).optional(),
84
+ /** Provider to use for synthesis/consensus */
85
+ defaultSynthesizer: z.string().max(50).optional(),
86
+ /** Providers to exclude from discussions */
87
+ excluded: z.array(z.string().max(50)).max(6).optional(),
88
+ /** Override provider for specific task types */
89
+ taskOverrides: z.record(z.string(), z.string().max(50)).optional(),
90
+ /** Provider-specific temperature overrides */
91
+ temperatureOverrides: z.record(z.string(), z.number().min(0).max(2)).optional(),
92
+ });
93
+ /**
94
+ * Orchestration configuration
95
+ */
96
+ export const OrchestrationConfigSchema = z.object({
97
+ maxDelegationDepth: z.number().int().min(0).max(10).optional(),
98
+ canReadWorkspaces: z.array(z.string().max(100)).max(20).optional(),
99
+ canWriteToShared: z.boolean().optional(),
100
+ delegationTimeout: z.number().int().min(1000).max(600000).optional(),
101
+ });
102
+ /**
103
+ * Agent retry policy for workflow steps
104
+ */
105
+ export const AgentRetryPolicySchema = z.object({
106
+ maxAttempts: z.number().int().min(1).max(10),
107
+ backoffMs: z.number().int().min(100).max(60000),
108
+ backoffMultiplier: z.number().min(1).max(5),
109
+ retryOn: z
110
+ .array(z.enum(['timeout', 'rateLimit', 'serverError', 'networkError']))
111
+ .optional(),
112
+ });
113
+ /**
114
+ * Agent step type enumeration (includes 'delegate' and 'discuss' for multi-model)
115
+ */
116
+ export const AgentStepTypeSchema = z.enum([
117
+ 'prompt',
118
+ 'tool',
119
+ 'conditional',
120
+ 'loop',
121
+ 'parallel',
122
+ 'delegate',
123
+ 'discuss', // Multi-model discussion step
124
+ ]);
125
+ /**
126
+ * Agent workflow step schema (extended with agent-specific fields)
127
+ */
128
+ export const AgentWorkflowStepSchema = z.object({
129
+ stepId: z.string().min(1).max(100),
130
+ name: z.string().min(1).max(200),
131
+ description: z.string().max(1000).optional(),
132
+ type: AgentStepTypeSchema,
133
+ config: z.record(z.string(), z.unknown()).default({}),
134
+ dependencies: z.array(z.string().max(100)).max(20).optional(),
135
+ condition: z.string().max(500).optional(),
136
+ parallel: z.boolean().optional(),
137
+ retryPolicy: AgentRetryPolicySchema.optional(),
138
+ timeoutMs: z.number().int().min(1000).max(600000).optional(),
139
+ keyQuestions: z.array(z.string().max(500)).max(10).optional(),
140
+ outputs: z.array(z.string().max(100)).max(20).optional(),
141
+ streaming: z.boolean().optional(),
142
+ saveToMemory: z.boolean().optional(),
143
+ checkpoint: z.boolean().optional(),
144
+ });
145
+ // ============================================================================
146
+ // Agent Profile Schema
147
+ // ============================================================================
148
+ /**
149
+ * Base agent profile schema (without workflow validation)
150
+ */
151
+ const AgentProfileBaseSchema = z.object({
152
+ // Identity
153
+ agentId: z
154
+ .string()
155
+ .min(1)
156
+ .max(50)
157
+ .regex(/^[a-zA-Z][a-zA-Z0-9_-]*$/, 'Agent ID must start with letter and contain only alphanumeric, dash, underscore'),
158
+ displayName: z.string().max(100).optional(),
159
+ version: z
160
+ .string()
161
+ .regex(/^\d+\.\d+\.\d+$/, 'Version must be SemVer format')
162
+ .optional(),
163
+ description: z.string().min(1).max(2000),
164
+ // Role and Expertise
165
+ role: z.string().max(200).optional(),
166
+ expertise: z.array(z.string().max(100)).max(20).optional(),
167
+ capabilities: z.array(z.string().max(100)).max(50).optional(),
168
+ // System Prompt
169
+ systemPrompt: z.string().max(10000).optional(),
170
+ // Workflow Definition (uses agent-specific workflow step)
171
+ workflow: z.array(AgentWorkflowStepSchema).max(100).optional(),
172
+ // Personality
173
+ personality: AgentPersonalitySchema.optional(),
174
+ // Abilities
175
+ abilities: AbilitySelectionSchema.optional(),
176
+ // Thinking Patterns
177
+ thinkingPatterns: z.array(z.string().max(500)).max(20).optional(),
178
+ // Dependencies
179
+ dependencies: z.array(z.string().max(50)).max(20).optional(),
180
+ // Execution Settings
181
+ parallel: z.boolean().optional(),
182
+ temperature: z.number().min(0).max(2).optional(),
183
+ maxTokens: z.number().int().min(1).max(200000).optional(),
184
+ // Orchestration
185
+ orchestration: OrchestrationConfigSchema.optional(),
186
+ // Provider Affinity (for multi-model discussions)
187
+ providerAffinity: ProviderAffinitySchema.optional(),
188
+ // Selection Metadata
189
+ selectionMetadata: SelectionMetadataSchema.optional(),
190
+ // Team and Collaboration
191
+ team: z.string().max(100).optional(),
192
+ collaboratesWith: z.array(z.string().max(50)).max(20).optional(),
193
+ // Additional Metadata
194
+ tags: z.array(z.string().max(50)).max(20).optional(),
195
+ priority: z.number().int().min(1).max(100).optional(),
196
+ enabled: z.boolean().default(true),
197
+ metadata: z.record(z.string(), z.unknown()).optional(),
198
+ // Timestamps (managed by system)
199
+ createdAt: z.string().datetime().optional(),
200
+ updatedAt: z.string().datetime().optional(),
201
+ });
202
+ /**
203
+ * Agent profile schema - the aggregate root for agents
204
+ *
205
+ * Includes workflow validation:
206
+ * - INV-AGT-WF-001: Prompt-type workflow steps must have non-empty 'prompt' in config
207
+ * - INV-AGT-WF-002: Delegate-type workflow steps must have 'targetAgent' in config
208
+ * - INV-AGT-WF-003: Step dependencies must reference existing step IDs
209
+ */
210
+ export const AgentProfileSchema = AgentProfileBaseSchema.superRefine((data, ctx) => {
211
+ // Skip validation if no workflow
212
+ if (!data.workflow || data.workflow.length === 0) {
213
+ return;
214
+ }
215
+ const workflow = data.workflow;
216
+ const stepIds = new Set(workflow.map((s) => s.stepId));
217
+ for (let i = 0; i < workflow.length; i++) {
218
+ const step = workflow[i];
219
+ // INV-AGT-WF-001: Validate prompt steps have non-empty prompt
220
+ if (step.type === 'prompt') {
221
+ const config = step.config;
222
+ const prompt = config.prompt;
223
+ if (!prompt || (typeof prompt === 'string' && prompt.trim() === '')) {
224
+ ctx.addIssue({
225
+ code: z.ZodIssueCode.custom,
226
+ message: `Workflow step "${step.stepId}" is type "prompt" but has no "prompt" in config. Prompt steps require a non-empty prompt string.`,
227
+ path: ['workflow', i, 'config', 'prompt'],
228
+ });
229
+ }
230
+ }
231
+ // INV-AGT-WF-002: Validate delegate steps have targetAgent
232
+ if (step.type === 'delegate') {
233
+ const config = step.config;
234
+ const targetAgent = config.targetAgent;
235
+ if (!targetAgent || (typeof targetAgent === 'string' && targetAgent.trim() === '')) {
236
+ ctx.addIssue({
237
+ code: z.ZodIssueCode.custom,
238
+ message: `Workflow step "${step.stepId}" is type "delegate" but has no "targetAgent" in config. Delegate steps require a target agent ID.`,
239
+ path: ['workflow', i, 'config', 'targetAgent'],
240
+ });
241
+ }
242
+ }
243
+ // INV-AGT-WF-003: Validate dependencies reference existing steps
244
+ if (step.dependencies && step.dependencies.length > 0) {
245
+ for (const dep of step.dependencies) {
246
+ if (!stepIds.has(dep)) {
247
+ ctx.addIssue({
248
+ code: z.ZodIssueCode.custom,
249
+ message: `Workflow step "${step.stepId}" depends on "${dep}" which does not exist in the workflow.`,
250
+ path: ['workflow', i, 'dependencies'],
251
+ });
252
+ }
253
+ }
254
+ }
255
+ }
256
+ });
257
+ // ============================================================================
258
+ // Agent Run Options
259
+ // ============================================================================
260
+ /**
261
+ * Options for running an agent
262
+ */
263
+ export const AgentRunOptionsSchema = z.object({
264
+ // Memory
265
+ memory: z.boolean().optional(),
266
+ saveMemory: z.boolean().optional(),
267
+ // Session
268
+ sessionId: z.string().uuid().optional(),
269
+ createSession: z.boolean().optional(),
270
+ // Provider
271
+ provider: z.string().max(50).optional(),
272
+ model: z.string().max(100).optional(),
273
+ // Output
274
+ format: z.enum(['text', 'json']).optional(),
275
+ verbose: z.boolean().optional(),
276
+ debug: z.boolean().optional(),
277
+ quiet: z.boolean().optional(),
278
+ // Execution
279
+ parallel: z.boolean().optional(),
280
+ streaming: z.boolean().optional(),
281
+ resumable: z.boolean().optional(),
282
+ checkpoint: z.boolean().optional(),
283
+ // Idempotency
284
+ idempotencyKey: z.string().uuid().optional(),
285
+ // Delegation context (for tracking delegation depth and chain)
286
+ // INV-DT-001: Used to enforce max delegation depth
287
+ // INV-DT-002: Used to prevent circular delegations
288
+ delegationContext: z.lazy(() => z.object({
289
+ currentDepth: z.number().int().min(0),
290
+ maxDepth: z.number().int().min(1).max(10),
291
+ delegationChain: z.array(z.string()),
292
+ initiatorAgentId: z.string(),
293
+ rootTaskId: z.string().uuid(),
294
+ startedAt: z.string().datetime().optional(),
295
+ })).optional(),
296
+ });
297
+ // ============================================================================
298
+ // Agent Events
299
+ // ============================================================================
300
+ /**
301
+ * Agent event types
302
+ */
303
+ export const AgentEventTypeSchema = z.enum([
304
+ 'agent.registered',
305
+ 'agent.started',
306
+ 'agent.stageStarted',
307
+ 'agent.stageCompleted',
308
+ 'agent.stageFailed',
309
+ 'agent.delegated',
310
+ 'agent.delegationReturned',
311
+ 'agent.completed',
312
+ 'agent.failed',
313
+ ]);
314
+ /**
315
+ * Agent error schema
316
+ */
317
+ export const AgentErrorSchema = z.object({
318
+ code: z.string(),
319
+ message: z.string(),
320
+ stepId: z.string().optional(),
321
+ retryable: z.boolean().optional(),
322
+ details: z.record(z.string(), z.unknown()).optional(),
323
+ });
324
+ /**
325
+ * Agent event payload variants
326
+ */
327
+ export const AgentEventPayloadSchema = z.discriminatedUnion('type', [
328
+ z.object({
329
+ type: z.literal('registered'),
330
+ profile: AgentProfileSchema,
331
+ }),
332
+ z.object({
333
+ type: z.literal('started'),
334
+ sessionId: z.string().uuid().optional(),
335
+ input: z.unknown(),
336
+ }),
337
+ z.object({
338
+ type: z.literal('stageStarted'),
339
+ stepId: z.string(),
340
+ stageName: z.string(),
341
+ }),
342
+ z.object({
343
+ type: z.literal('stageCompleted'),
344
+ stepId: z.string(),
345
+ output: z.unknown(),
346
+ }),
347
+ z.object({
348
+ type: z.literal('stageFailed'),
349
+ stepId: z.string(),
350
+ error: AgentErrorSchema,
351
+ }),
352
+ z.object({
353
+ type: z.literal('delegated'),
354
+ targetAgent: z.string(),
355
+ task: z.string(),
356
+ }),
357
+ z.object({
358
+ type: z.literal('delegationReturned'),
359
+ fromAgent: z.string(),
360
+ result: z.unknown(),
361
+ }),
362
+ z.object({
363
+ type: z.literal('completed'),
364
+ output: z.unknown(),
365
+ durationMs: z.number(),
366
+ }),
367
+ z.object({
368
+ type: z.literal('failed'),
369
+ error: AgentErrorSchema,
370
+ }),
371
+ ]);
372
+ /**
373
+ * Base event schema
374
+ */
375
+ export const BaseEventSchema = z.object({
376
+ eventId: z.string().uuid(),
377
+ timestamp: z.string().datetime(),
378
+ version: z.number().int().min(1),
379
+ correlationId: z.string().uuid(),
380
+ causationId: z.string().uuid().optional(),
381
+ spanId: z.string().optional(),
382
+ traceId: z.string().optional(),
383
+ });
384
+ /**
385
+ * Agent event schema
386
+ */
387
+ export const AgentEventSchema = BaseEventSchema.extend({
388
+ aggregateId: z.string(), // agentId
389
+ type: AgentEventTypeSchema,
390
+ payload: AgentEventPayloadSchema,
391
+ });
392
+ // ============================================================================
393
+ // Agent Result
394
+ // ============================================================================
395
+ /**
396
+ * Agent execution result
397
+ */
398
+ export const AgentResultSchema = z.object({
399
+ success: z.boolean(),
400
+ agentId: z.string(),
401
+ sessionId: z.string().uuid().optional(),
402
+ output: z.unknown().optional(),
403
+ stepResults: z
404
+ .array(z.object({
405
+ stepId: z.string(),
406
+ success: z.boolean(),
407
+ output: z.unknown().optional(),
408
+ durationMs: z.number(),
409
+ retryCount: z.number().int().min(0),
410
+ skipped: z.boolean(),
411
+ error: AgentErrorSchema.optional(),
412
+ }))
413
+ .optional(),
414
+ error: AgentErrorSchema.optional(),
415
+ totalDurationMs: z.number(),
416
+ });
417
+ // ============================================================================
418
+ // Error Codes
419
+ // ============================================================================
420
+ /**
421
+ * Agent error codes
422
+ */
423
+ export const AgentErrorCode = {
424
+ AGENT_NOT_FOUND: 'AGENT_NOT_FOUND',
425
+ AGENT_VALIDATION_ERROR: 'AGENT_VALIDATION_ERROR',
426
+ AGENT_DELEGATION_DEPTH_EXCEEDED: 'AGENT_DELEGATION_DEPTH_EXCEEDED',
427
+ AGENT_DELEGATION_TIMEOUT: 'AGENT_DELEGATION_TIMEOUT',
428
+ AGENT_STAGE_FAILED: 'AGENT_STAGE_FAILED',
429
+ AGENT_DEPENDENCY_FAILED: 'AGENT_DEPENDENCY_FAILED',
430
+ AGENT_PERMISSION_DENIED: 'AGENT_PERMISSION_DENIED',
431
+ AGENT_ALREADY_RUNNING: 'AGENT_ALREADY_RUNNING',
432
+ AGENT_WORKFLOW_INVALID: 'AGENT_WORKFLOW_INVALID',
433
+ };
434
+ // ============================================================================
435
+ // Validation Functions
436
+ // ============================================================================
437
+ /**
438
+ * Validates an agent profile
439
+ */
440
+ export function validateAgentProfile(data) {
441
+ return AgentProfileSchema.parse(data);
442
+ }
443
+ /**
444
+ * Safely validates an agent profile
445
+ */
446
+ export function safeValidateAgentProfile(data) {
447
+ const result = AgentProfileSchema.safeParse(data);
448
+ if (result.success) {
449
+ return { success: true, data: result.data };
450
+ }
451
+ return { success: false, error: result.error };
452
+ }
453
+ /**
454
+ * Validates agent run options
455
+ */
456
+ export function validateAgentRunOptions(data) {
457
+ return AgentRunOptionsSchema.parse(data);
458
+ }
459
+ // ============================================================================
460
+ // Checkpoint Contracts
461
+ // ============================================================================
462
+ /**
463
+ * Checkpoint configuration
464
+ *
465
+ * Invariants:
466
+ * - INV-CP-001: Checkpoint contains all data needed to resume
467
+ * - INV-CP-002: Resumed execution starts from step after checkpoint
468
+ */
469
+ export const CheckpointConfigSchema = z.object({
470
+ /** Enable checkpointing */
471
+ enabled: z.boolean().default(true),
472
+ /** Checkpoint after every N steps (0 = every step) */
473
+ intervalSteps: z.number().int().min(0).max(100).default(1),
474
+ /** Checkpoint retention period in hours */
475
+ retentionHours: z.number().int().min(1).max(720).default(24),
476
+ /** Include memory snapshot in checkpoint */
477
+ includeMemory: z.boolean().default(false),
478
+ /** Max checkpoints to retain per agent */
479
+ maxCheckpoints: z.number().int().min(1).max(100).default(10),
480
+ });
481
+ /**
482
+ * Memory snapshot item for checkpoint
483
+ */
484
+ export const MemorySnapshotItemSchema = z.object({
485
+ key: z.string(),
486
+ value: z.unknown(),
487
+ namespace: z.string().optional(),
488
+ });
489
+ /**
490
+ * Checkpoint schema - persisted execution state
491
+ */
492
+ export const CheckpointSchema = z.object({
493
+ /** Unique checkpoint identifier */
494
+ checkpointId: z.string().uuid(),
495
+ /** Agent that created this checkpoint */
496
+ agentId: z.string(),
497
+ /** Session if applicable */
498
+ sessionId: z.string().uuid().optional(),
499
+ /** Workflow if applicable */
500
+ workflowId: z.string().optional(),
501
+ /** Current step index (0-based) */
502
+ stepIndex: z.number().int().min(0),
503
+ /** ID of the last completed step */
504
+ completedStepId: z.string(),
505
+ /** Accumulated outputs from completed steps */
506
+ stepOutputs: z.record(z.string(), z.unknown()),
507
+ /** Execution context at checkpoint time */
508
+ context: z.record(z.string(), z.unknown()),
509
+ /** Memory state snapshot (if configured) */
510
+ memorySnapshot: z.array(MemorySnapshotItemSchema).optional(),
511
+ /** Checkpoint creation time */
512
+ createdAt: z.string().datetime(),
513
+ /** Checkpoint expiration time */
514
+ expiresAt: z.string().datetime().optional(),
515
+ });
516
+ /**
517
+ * Resume context from checkpoint
518
+ */
519
+ export const ResumeContextSchema = z.object({
520
+ /** Step index to resume from */
521
+ startFromStep: z.number().int().min(0),
522
+ /** Outputs from previously completed steps */
523
+ previousOutputs: z.record(z.string(), z.unknown()),
524
+ /** Execution context */
525
+ context: z.record(z.string(), z.unknown()),
526
+ /** Memory snapshot to restore */
527
+ memorySnapshot: z.array(MemorySnapshotItemSchema).optional(),
528
+ });
529
+ /**
530
+ * Checkpoint error codes
531
+ */
532
+ export const CheckpointErrorCodes = {
533
+ CHECKPOINT_NOT_FOUND: 'CHECKPOINT_NOT_FOUND',
534
+ CHECKPOINT_EXPIRED: 'CHECKPOINT_EXPIRED',
535
+ CHECKPOINT_INVALID: 'CHECKPOINT_INVALID',
536
+ CHECKPOINT_SAVE_FAILED: 'CHECKPOINT_SAVE_FAILED',
537
+ };
538
+ // ============================================================================
539
+ // Delegation Contracts
540
+ // ============================================================================
541
+ /**
542
+ * Delegation context - tracks delegation chain
543
+ *
544
+ * Invariants:
545
+ * - INV-DT-001: Depth never exceeds maxDepth
546
+ * - INV-DT-002: No circular delegations (agent can't delegate to itself or ancestors)
547
+ */
548
+ export const DelegationContextSchema = z.object({
549
+ /** Current depth in delegation chain */
550
+ currentDepth: z.number().int().min(0),
551
+ /** Maximum allowed delegation depth */
552
+ maxDepth: z.number().int().min(1).max(10),
553
+ /** Chain of agent IDs in delegation (oldest first) */
554
+ delegationChain: z.array(z.string()),
555
+ /** Original initiator agent ID */
556
+ initiatorAgentId: z.string(),
557
+ /** Root task ID for correlation */
558
+ rootTaskId: z.string().uuid(),
559
+ /** Timestamp when delegation chain started */
560
+ startedAt: z.string().datetime().optional(),
561
+ });
562
+ /**
563
+ * Delegation request
564
+ */
565
+ export const DelegationRequestSchema = z.object({
566
+ /** Agent initiating the delegation */
567
+ fromAgentId: z.string(),
568
+ /** Target agent to delegate to */
569
+ toAgentId: z.string(),
570
+ /** Task description */
571
+ task: z.string().max(5000),
572
+ /** Delegation context for tracking */
573
+ context: DelegationContextSchema,
574
+ /** Timeout for delegated task in ms */
575
+ timeout: z.number().int().min(1000).max(600000).optional(),
576
+ /** Input data for delegated agent */
577
+ input: z.unknown().optional(),
578
+ });
579
+ /**
580
+ * Delegation result
581
+ */
582
+ export const DelegationResultSchema = z.object({
583
+ /** Whether delegation succeeded */
584
+ success: z.boolean(),
585
+ /** Agent that handled the delegation */
586
+ handledBy: z.string(),
587
+ /** Result from delegated agent */
588
+ result: z.unknown().optional(),
589
+ /** Error if delegation failed */
590
+ error: AgentErrorSchema.optional(),
591
+ /** Duration of delegated execution */
592
+ durationMs: z.number().int().min(0),
593
+ /** Final delegation depth reached */
594
+ finalDepth: z.number().int().min(0),
595
+ });
596
+ /**
597
+ * Delegation check result
598
+ */
599
+ export const DelegationCheckResultSchema = z.object({
600
+ /** Whether delegation is allowed */
601
+ allowed: z.boolean(),
602
+ /** Reason if not allowed */
603
+ reason: z.string().optional(),
604
+ /** Detailed message */
605
+ message: z.string().optional(),
606
+ });
607
+ /**
608
+ * Delegation error codes
609
+ */
610
+ export const DelegationErrorCodes = {
611
+ MAX_DEPTH_EXCEEDED: 'DELEGATION_MAX_DEPTH_EXCEEDED',
612
+ CIRCULAR_DELEGATION: 'DELEGATION_CIRCULAR',
613
+ TARGET_NOT_FOUND: 'DELEGATION_TARGET_NOT_FOUND',
614
+ TARGET_UNAVAILABLE: 'DELEGATION_TARGET_UNAVAILABLE',
615
+ TIMEOUT: 'DELEGATION_TIMEOUT',
616
+ PERMISSION_DENIED: 'DELEGATION_PERMISSION_DENIED',
617
+ };
618
+ // ============================================================================
619
+ // Parallel Execution Contracts
620
+ // ============================================================================
621
+ /**
622
+ * Parallel execution failure strategy
623
+ */
624
+ export const ParallelFailureStrategySchema = z.enum([
625
+ 'failFast', // Cancel remaining steps, fail immediately
626
+ 'failSafe', // Wait for all steps, collect errors
627
+ 'continueOnError', // Continue execution, log errors
628
+ ]);
629
+ /**
630
+ * Parallel execution configuration
631
+ *
632
+ * Invariants:
633
+ * - INV-PE-001: Independent steps execute concurrently
634
+ * - INV-PE-002: Dependencies honored (DAG ordering)
635
+ * - INV-PE-003: Concurrency limit respected
636
+ */
637
+ export const ParallelExecutionConfigSchema = z.object({
638
+ /** Enable parallel execution */
639
+ enabled: z.boolean().default(true),
640
+ /** Maximum concurrent steps (INV-PE-003) */
641
+ maxConcurrency: z.number().int().min(1).max(10).default(5),
642
+ /** Strategy when one parallel step fails */
643
+ failureStrategy: ParallelFailureStrategySchema.default('failFast'),
644
+ /** Timeout for entire parallel group in ms */
645
+ groupTimeoutMs: z.number().int().min(1000).max(600000).optional(),
646
+ /** Enable step-level checkpointing in parallel groups */
647
+ checkpointParallel: z.boolean().default(false),
648
+ });
649
+ /**
650
+ * Parallel step result
651
+ */
652
+ export const ParallelStepResultSchema = z.object({
653
+ /** Step identifier */
654
+ stepId: z.string(),
655
+ /** Whether step succeeded */
656
+ success: z.boolean(),
657
+ /** Step output */
658
+ output: z.unknown().optional(),
659
+ /** Error message if failed */
660
+ error: z.string().optional(),
661
+ /** Error code if failed */
662
+ errorCode: z.string().optional(),
663
+ /** Step duration in ms */
664
+ durationMs: z.number().int().min(0),
665
+ /** Whether step was cancelled */
666
+ cancelled: z.boolean().optional(),
667
+ /** Retry count for this step */
668
+ retryCount: z.number().int().min(0).optional(),
669
+ });
670
+ /**
671
+ * Parallel group execution result
672
+ */
673
+ export const ParallelGroupResultSchema = z.object({
674
+ /** Group identifier */
675
+ groupId: z.string().uuid(),
676
+ /** Results for each step in the group */
677
+ stepResults: z.array(ParallelStepResultSchema),
678
+ /** Total duration for the group in ms */
679
+ totalDurationMs: z.number().int().min(0),
680
+ /** Whether all steps succeeded */
681
+ allSucceeded: z.boolean(),
682
+ /** List of failed step IDs */
683
+ failedSteps: z.array(z.string()),
684
+ /** List of cancelled step IDs */
685
+ cancelledSteps: z.array(z.string()).optional(),
686
+ /** Number of steps executed */
687
+ stepsExecuted: z.number().int().min(0),
688
+ /** Number of steps skipped */
689
+ stepsSkipped: z.number().int().min(0).optional(),
690
+ });
691
+ /**
692
+ * Parallel execution error codes
693
+ */
694
+ export const ParallelExecutionErrorCodes = {
695
+ GROUP_TIMEOUT: 'PARALLEL_GROUP_TIMEOUT',
696
+ STEP_FAILED: 'PARALLEL_STEP_FAILED',
697
+ CONCURRENCY_EXCEEDED: 'PARALLEL_CONCURRENCY_EXCEEDED',
698
+ CIRCULAR_DEPENDENCY: 'PARALLEL_CIRCULAR_DEPENDENCY',
699
+ };
700
+ // ============================================================================
701
+ // Validation Functions for New Contracts
702
+ // ============================================================================
703
+ /**
704
+ * Validates checkpoint configuration
705
+ */
706
+ export function validateCheckpointConfig(data) {
707
+ return CheckpointConfigSchema.parse(data);
708
+ }
709
+ /**
710
+ * Validates a checkpoint
711
+ */
712
+ export function validateCheckpoint(data) {
713
+ return CheckpointSchema.parse(data);
714
+ }
715
+ /**
716
+ * Validates delegation context
717
+ */
718
+ export function validateDelegationContext(data) {
719
+ return DelegationContextSchema.parse(data);
720
+ }
721
+ /**
722
+ * Validates delegation request
723
+ */
724
+ export function validateDelegationRequest(data) {
725
+ return DelegationRequestSchema.parse(data);
726
+ }
727
+ /**
728
+ * Validates parallel execution configuration
729
+ */
730
+ export function validateParallelExecutionConfig(data) {
731
+ return ParallelExecutionConfigSchema.parse(data);
732
+ }
733
+ /**
734
+ * Creates default checkpoint configuration
735
+ */
736
+ export function createDefaultCheckpointConfig() {
737
+ return CheckpointConfigSchema.parse({});
738
+ }
739
+ /**
740
+ * Creates default parallel execution configuration
741
+ */
742
+ export function createDefaultParallelExecutionConfig() {
743
+ return ParallelExecutionConfigSchema.parse({});
744
+ }
745
+ /**
746
+ * Creates initial delegation context for root agent
747
+ */
748
+ export function createRootDelegationContext(agentId, taskId, maxDepth = 3) {
749
+ return {
750
+ currentDepth: 0,
751
+ maxDepth,
752
+ delegationChain: [agentId],
753
+ initiatorAgentId: agentId,
754
+ rootTaskId: taskId,
755
+ startedAt: new Date().toISOString(),
756
+ };
757
+ }
758
+ // ============================================================================
759
+ // Tool Executor Contracts
760
+ // ============================================================================
761
+ /**
762
+ * Tool execution result
763
+ *
764
+ * Invariants:
765
+ * - INV-TOOL-001: Tool execution must validate inputs before execution
766
+ * - INV-TOOL-002: Tool results must be immutable after creation
767
+ */
768
+ export const ToolExecutionResultSchema = z.object({
769
+ /** Whether the tool execution succeeded */
770
+ success: z.boolean(),
771
+ /** Output from the tool (any JSON-serializable value) */
772
+ output: z.unknown().optional(),
773
+ /** Error message if execution failed */
774
+ error: z.string().optional(),
775
+ /** Error code if execution failed */
776
+ errorCode: z.string().optional(),
777
+ /** Whether the error is retryable */
778
+ retryable: z.boolean().optional(),
779
+ /** Execution duration in milliseconds */
780
+ durationMs: z.number().int().min(0).optional(),
781
+ });
782
+ /**
783
+ * Tool execution request
784
+ */
785
+ export const ToolExecutionRequestSchema = z.object({
786
+ /** Name of the tool to execute */
787
+ toolName: z.string().min(1).max(100),
788
+ /** Arguments to pass to the tool */
789
+ args: z.record(z.string(), z.unknown()),
790
+ /** Timeout in milliseconds */
791
+ timeoutMs: z.number().int().min(1000).max(600000).optional(),
792
+ /** Idempotency key for safe retries */
793
+ idempotencyKey: z.string().uuid().optional(),
794
+ });
795
+ /**
796
+ * Tool executor interface schema (for documentation/validation)
797
+ *
798
+ * This interface is implemented by tool execution bridges that connect
799
+ * agent/workflow execution to actual tool handlers.
800
+ *
801
+ * Invariants:
802
+ * - INV-TOOL-001: Tool execution must validate inputs before execution
803
+ * - INV-TOOL-002: Tool results must be immutable (frozen) after creation
804
+ * - INV-TOOL-003: Unknown tools must return error, not throw
805
+ */
806
+ export const ToolExecutorConfigSchema = z.object({
807
+ /** Default timeout for tool execution in ms */
808
+ defaultTimeoutMs: z.number().int().min(1000).max(600000).default(60000),
809
+ /** Whether to validate inputs against tool schemas */
810
+ validateInputs: z.boolean().default(true),
811
+ /** Whether to freeze outputs for immutability */
812
+ freezeOutputs: z.boolean().default(true),
813
+ });
814
+ /**
815
+ * Tool executor error codes
816
+ */
817
+ export const ToolExecutorErrorCodes = {
818
+ TOOL_NOT_FOUND: 'TOOL_NOT_FOUND',
819
+ TOOL_VALIDATION_ERROR: 'TOOL_VALIDATION_ERROR',
820
+ TOOL_EXECUTION_ERROR: 'TOOL_EXECUTION_ERROR',
821
+ TOOL_TIMEOUT: 'TOOL_TIMEOUT',
822
+ TOOL_PERMISSION_DENIED: 'TOOL_PERMISSION_DENIED',
823
+ };
824
+ /**
825
+ * Validates tool execution result
826
+ */
827
+ export function validateToolExecutionResult(data) {
828
+ return ToolExecutionResultSchema.parse(data);
829
+ }
830
+ /**
831
+ * Validates tool execution request
832
+ */
833
+ export function validateToolExecutionRequest(data) {
834
+ return ToolExecutionRequestSchema.parse(data);
835
+ }
836
+ /**
837
+ * Creates a successful tool execution result
838
+ */
839
+ export function createToolExecutionSuccess(output, durationMs) {
840
+ return Object.freeze({
841
+ success: true,
842
+ output,
843
+ durationMs,
844
+ });
845
+ }
846
+ /**
847
+ * Creates a failed tool execution result
848
+ */
849
+ export function createToolExecutionFailure(error, errorCode, retryable = false, durationMs) {
850
+ return Object.freeze({
851
+ success: false,
852
+ error,
853
+ errorCode,
854
+ retryable,
855
+ durationMs,
856
+ });
857
+ }
858
+ // ============================================================================
859
+ // Agent Selection Contracts (MCP Tools)
860
+ // ============================================================================
861
+ /**
862
+ * Agent recommendation request schema
863
+ *
864
+ * Invariants:
865
+ * - INV-AGT-SEL-001: Selection is deterministic (same input = same output)
866
+ * - INV-AGT-SEL-004: Always returns at least one result (fallback to 'standard')
867
+ */
868
+ export const AgentRecommendRequestSchema = z.object({
869
+ /** Task description to match against agents */
870
+ task: z.string().min(1).max(2000).describe('Task description to match'),
871
+ /** Filter by team */
872
+ team: z.string().max(100).optional().describe('Filter by team'),
873
+ /** Required capabilities */
874
+ requiredCapabilities: z.array(z.string().max(100)).max(10).optional()
875
+ .describe('Required capabilities'),
876
+ /** Agents to exclude from matching */
877
+ excludeAgents: z.array(z.string().max(50)).max(20).optional()
878
+ .describe('Agents to exclude'),
879
+ /** Maximum number of results */
880
+ maxResults: z.number().int().min(1).max(10).default(3)
881
+ .describe('Max recommendations'),
882
+ });
883
+ /**
884
+ * Agent match result (used in alternatives)
885
+ */
886
+ export const AgentMatchSchema = z.object({
887
+ agentId: z.string(),
888
+ confidence: z.number().min(0).max(1),
889
+ reason: z.string().optional(),
890
+ });
891
+ /**
892
+ * Agent recommendation result schema
893
+ *
894
+ * Invariants:
895
+ * - INV-AGT-SEL-002: Confidence is between 0 and 1
896
+ * - INV-AGT-SEL-003: Results sorted by confidence descending
897
+ */
898
+ export const AgentRecommendResultSchema = z.object({
899
+ /** Best matching agent ID */
900
+ recommended: z.string().describe('Best matching agent ID'),
901
+ /** Match confidence 0-1 */
902
+ confidence: z.number().min(0).max(1).describe('Match confidence 0-1'),
903
+ /** Why this agent was selected */
904
+ reason: z.string().describe('Why this agent was selected'),
905
+ /** Alternative agent matches */
906
+ alternatives: z.array(AgentMatchSchema).describe('Alternative agent matches'),
907
+ });
908
+ /**
909
+ * Agent capabilities query request schema
910
+ */
911
+ export const AgentCapabilitiesRequestSchema = z.object({
912
+ /** Filter by agent category */
913
+ category: AgentCategorySchema.optional()
914
+ .describe('Filter by agent category'),
915
+ /** Include disabled agents */
916
+ includeDisabled: z.boolean().default(false)
917
+ .describe('Include disabled agents'),
918
+ });
919
+ /**
920
+ * Agent capabilities result schema
921
+ */
922
+ export const AgentCapabilitiesResultSchema = z.object({
923
+ /** All unique capabilities */
924
+ capabilities: z.array(z.string()).describe('All unique capabilities'),
925
+ /** Capability → agent IDs mapping */
926
+ agentsByCapability: z.record(z.string(), z.array(z.string()))
927
+ .describe('Capability → agent IDs'),
928
+ /** Agent ID → capabilities mapping */
929
+ capabilitiesByAgent: z.record(z.string(), z.array(z.string()))
930
+ .describe('Agent ID → capabilities'),
931
+ /** Agent ID → category mapping */
932
+ categoriesByAgent: z.record(z.string(), AgentCategorySchema).optional()
933
+ .describe('Agent ID → category'),
934
+ });
935
+ /**
936
+ * Agent selection context for the selector
937
+ */
938
+ export const AgentSelectionContextSchema = z.object({
939
+ team: z.string().optional(),
940
+ requiredCapabilities: z.array(z.string()).optional(),
941
+ excludeAgents: z.array(z.string()).optional(),
942
+ });
943
+ // ============================================================================
944
+ // Validation Functions for Selection Contracts
945
+ // ============================================================================
946
+ /**
947
+ * Validates agent recommendation request
948
+ */
949
+ export function validateAgentRecommendRequest(data) {
950
+ return AgentRecommendRequestSchema.parse(data);
951
+ }
952
+ /**
953
+ * Validates agent recommendation result
954
+ */
955
+ export function validateAgentRecommendResult(data) {
956
+ return AgentRecommendResultSchema.parse(data);
957
+ }
958
+ /**
959
+ * Validates agent capabilities request
960
+ */
961
+ export function validateAgentCapabilitiesRequest(data) {
962
+ return AgentCapabilitiesRequestSchema.parse(data);
963
+ }
964
+ /**
965
+ * Validates agent capabilities result
966
+ */
967
+ export function validateAgentCapabilitiesResult(data) {
968
+ return AgentCapabilitiesResultSchema.parse(data);
969
+ }
970
+ //# sourceMappingURL=schema.js.map