@kilnai/core 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 (609) hide show
  1. package/dist/agents/circuit-breaker.d.ts +26 -0
  2. package/dist/agents/circuit-breaker.d.ts.map +1 -0
  3. package/dist/agents/circuit-breaker.js +90 -0
  4. package/dist/agents/circuit-breaker.js.map +1 -0
  5. package/dist/agents/context-compressor.d.ts +13 -0
  6. package/dist/agents/context-compressor.d.ts.map +1 -0
  7. package/dist/agents/context-compressor.js +21 -0
  8. package/dist/agents/context-compressor.js.map +1 -0
  9. package/dist/agents/index.d.ts +68 -0
  10. package/dist/agents/index.d.ts.map +1 -0
  11. package/dist/agents/index.js +13 -0
  12. package/dist/agents/index.js.map +1 -0
  13. package/dist/agents/infrastructure/anthropic.d.ts +24 -0
  14. package/dist/agents/infrastructure/anthropic.d.ts.map +1 -0
  15. package/dist/agents/infrastructure/anthropic.js +226 -0
  16. package/dist/agents/infrastructure/anthropic.js.map +1 -0
  17. package/dist/agents/infrastructure/deepseek.d.ts +10 -0
  18. package/dist/agents/infrastructure/deepseek.d.ts.map +1 -0
  19. package/dist/agents/infrastructure/deepseek.js +14 -0
  20. package/dist/agents/infrastructure/deepseek.js.map +1 -0
  21. package/dist/agents/infrastructure/ollama.d.ts +20 -0
  22. package/dist/agents/infrastructure/ollama.d.ts.map +1 -0
  23. package/dist/agents/infrastructure/ollama.js +128 -0
  24. package/dist/agents/infrastructure/ollama.js.map +1 -0
  25. package/dist/agents/infrastructure/openai-compat.d.ts +25 -0
  26. package/dist/agents/infrastructure/openai-compat.d.ts.map +1 -0
  27. package/dist/agents/infrastructure/openai-compat.js +211 -0
  28. package/dist/agents/infrastructure/openai-compat.js.map +1 -0
  29. package/dist/agents/infrastructure/openai.d.ts +12 -0
  30. package/dist/agents/infrastructure/openai.d.ts.map +1 -0
  31. package/dist/agents/infrastructure/openai.js +16 -0
  32. package/dist/agents/infrastructure/openai.js.map +1 -0
  33. package/dist/agents/infrastructure/retry.d.ts +10 -0
  34. package/dist/agents/infrastructure/retry.d.ts.map +1 -0
  35. package/dist/agents/infrastructure/retry.js +22 -0
  36. package/dist/agents/infrastructure/retry.js.map +1 -0
  37. package/dist/agents/mcp-client.d.ts +22 -0
  38. package/dist/agents/mcp-client.d.ts.map +1 -0
  39. package/dist/agents/mcp-client.js +104 -0
  40. package/dist/agents/mcp-client.js.map +1 -0
  41. package/dist/agents/model-pricing.d.ts +9 -0
  42. package/dist/agents/model-pricing.d.ts.map +1 -0
  43. package/dist/agents/model-pricing.js +17 -0
  44. package/dist/agents/model-pricing.js.map +1 -0
  45. package/dist/agents/provider-registry.d.ts +25 -0
  46. package/dist/agents/provider-registry.d.ts.map +1 -0
  47. package/dist/agents/provider-registry.js +62 -0
  48. package/dist/agents/provider-registry.js.map +1 -0
  49. package/dist/agents/tool-cache.d.ts +13 -0
  50. package/dist/agents/tool-cache.d.ts.map +1 -0
  51. package/dist/agents/tool-cache.js +52 -0
  52. package/dist/agents/tool-cache.js.map +1 -0
  53. package/dist/agents/tool-rag.d.ts +15 -0
  54. package/dist/agents/tool-rag.d.ts.map +1 -0
  55. package/dist/agents/tool-rag.js +92 -0
  56. package/dist/agents/tool-rag.js.map +1 -0
  57. package/dist/agents/tool-registry.d.ts +29 -0
  58. package/dist/agents/tool-registry.d.ts.map +1 -0
  59. package/dist/agents/tool-registry.js +64 -0
  60. package/dist/agents/tool-registry.js.map +1 -0
  61. package/dist/cost/cost-tracker.d.ts +27 -0
  62. package/dist/cost/cost-tracker.d.ts.map +1 -0
  63. package/dist/cost/cost-tracker.js +103 -0
  64. package/dist/cost/cost-tracker.js.map +1 -0
  65. package/dist/cost/index.d.ts +30 -0
  66. package/dist/cost/index.d.ts.map +1 -0
  67. package/dist/cost/index.js +2 -0
  68. package/dist/cost/index.js.map +1 -0
  69. package/dist/domain/domain-package-adapter.d.ts +13 -0
  70. package/dist/domain/domain-package-adapter.d.ts.map +1 -0
  71. package/dist/domain/domain-package-adapter.js +66 -0
  72. package/dist/domain/domain-package-adapter.js.map +1 -0
  73. package/dist/domain/domain-registry.d.ts +26 -0
  74. package/dist/domain/domain-registry.d.ts.map +1 -0
  75. package/dist/domain/domain-registry.js +119 -0
  76. package/dist/domain/domain-registry.js.map +1 -0
  77. package/dist/domain/index.d.ts +22 -0
  78. package/dist/domain/index.d.ts.map +1 -0
  79. package/dist/domain/index.js +30 -0
  80. package/dist/domain/index.js.map +1 -0
  81. package/dist/domain/yaml-parser.d.ts +18 -0
  82. package/dist/domain/yaml-parser.d.ts.map +1 -0
  83. package/dist/domain/yaml-parser.js +47 -0
  84. package/dist/domain/yaml-parser.js.map +1 -0
  85. package/dist/domain/yaml-schema.d.ts +26 -0
  86. package/dist/domain/yaml-schema.d.ts.map +1 -0
  87. package/dist/domain/yaml-schema.js +66 -0
  88. package/dist/domain/yaml-schema.js.map +1 -0
  89. package/dist/engine/composites/app.d.ts +39 -0
  90. package/dist/engine/composites/app.d.ts.map +1 -0
  91. package/dist/engine/composites/app.js +125 -0
  92. package/dist/engine/composites/app.js.map +1 -0
  93. package/dist/engine/composites/router.d.ts +20 -0
  94. package/dist/engine/composites/router.d.ts.map +1 -0
  95. package/dist/engine/composites/router.js +31 -0
  96. package/dist/engine/composites/router.js.map +1 -0
  97. package/dist/engine/composites/team.d.ts +36 -0
  98. package/dist/engine/composites/team.d.ts.map +1 -0
  99. package/dist/engine/composites/team.js +100 -0
  100. package/dist/engine/composites/team.js.map +1 -0
  101. package/dist/engine/domain/a2a-config.d.ts +53 -0
  102. package/dist/engine/domain/a2a-config.d.ts.map +1 -0
  103. package/dist/engine/domain/a2a-config.js +32 -0
  104. package/dist/engine/domain/a2a-config.js.map +1 -0
  105. package/dist/engine/domain/agent.d.ts +18 -0
  106. package/dist/engine/domain/agent.d.ts.map +1 -0
  107. package/dist/engine/domain/agent.js +4 -0
  108. package/dist/engine/domain/agent.js.map +1 -0
  109. package/dist/engine/domain/capability.d.ts +24 -0
  110. package/dist/engine/domain/capability.d.ts.map +1 -0
  111. package/dist/engine/domain/capability.js +3 -0
  112. package/dist/engine/domain/capability.js.map +1 -0
  113. package/dist/engine/domain/channel.d.ts +37 -0
  114. package/dist/engine/domain/channel.d.ts.map +1 -0
  115. package/dist/engine/domain/channel.js +4 -0
  116. package/dist/engine/domain/channel.js.map +1 -0
  117. package/dist/engine/domain/chunker.d.ts +22 -0
  118. package/dist/engine/domain/chunker.d.ts.map +1 -0
  119. package/dist/engine/domain/chunker.js +3 -0
  120. package/dist/engine/domain/chunker.js.map +1 -0
  121. package/dist/engine/domain/content.d.ts +57 -0
  122. package/dist/engine/domain/content.d.ts.map +1 -0
  123. package/dist/engine/domain/content.js +63 -0
  124. package/dist/engine/domain/content.js.map +1 -0
  125. package/dist/engine/domain/cron.d.ts +15 -0
  126. package/dist/engine/domain/cron.d.ts.map +1 -0
  127. package/dist/engine/domain/cron.js +114 -0
  128. package/dist/engine/domain/cron.js.map +1 -0
  129. package/dist/engine/domain/embedding.d.ts +9 -0
  130. package/dist/engine/domain/embedding.d.ts.map +1 -0
  131. package/dist/engine/domain/embedding.js +4 -0
  132. package/dist/engine/domain/embedding.js.map +1 -0
  133. package/dist/engine/domain/eval-config.d.ts +36 -0
  134. package/dist/engine/domain/eval-config.d.ts.map +1 -0
  135. package/dist/engine/domain/eval-config.js +155 -0
  136. package/dist/engine/domain/eval-config.js.map +1 -0
  137. package/dist/engine/domain/knowledge-config.d.ts +34 -0
  138. package/dist/engine/domain/knowledge-config.d.ts.map +1 -0
  139. package/dist/engine/domain/knowledge-config.js +62 -0
  140. package/dist/engine/domain/knowledge-config.js.map +1 -0
  141. package/dist/engine/domain/mcp-config.d.ts +15 -0
  142. package/dist/engine/domain/mcp-config.d.ts.map +1 -0
  143. package/dist/engine/domain/mcp-config.js +26 -0
  144. package/dist/engine/domain/mcp-config.js.map +1 -0
  145. package/dist/engine/domain/memory.d.ts +17 -0
  146. package/dist/engine/domain/memory.d.ts.map +1 -0
  147. package/dist/engine/domain/memory.js +4 -0
  148. package/dist/engine/domain/memory.js.map +1 -0
  149. package/dist/engine/domain/modality.d.ts +5 -0
  150. package/dist/engine/domain/modality.d.ts.map +1 -0
  151. package/dist/engine/domain/modality.js +19 -0
  152. package/dist/engine/domain/modality.js.map +1 -0
  153. package/dist/engine/domain/orchestrator-config.d.ts +11 -0
  154. package/dist/engine/domain/orchestrator-config.d.ts.map +1 -0
  155. package/dist/engine/domain/orchestrator-config.js +4 -0
  156. package/dist/engine/domain/orchestrator-config.js.map +1 -0
  157. package/dist/engine/domain/prompt-assembler.d.ts +32 -0
  158. package/dist/engine/domain/prompt-assembler.d.ts.map +1 -0
  159. package/dist/engine/domain/prompt-assembler.js +60 -0
  160. package/dist/engine/domain/prompt-assembler.js.map +1 -0
  161. package/dist/engine/domain/safety-config.d.ts +51 -0
  162. package/dist/engine/domain/safety-config.d.ts.map +1 -0
  163. package/dist/engine/domain/safety-config.js +74 -0
  164. package/dist/engine/domain/safety-config.js.map +1 -0
  165. package/dist/engine/domain/speech-config.d.ts +53 -0
  166. package/dist/engine/domain/speech-config.d.ts.map +1 -0
  167. package/dist/engine/domain/speech-config.js +26 -0
  168. package/dist/engine/domain/speech-config.js.map +1 -0
  169. package/dist/engine/domain/task.d.ts +16 -0
  170. package/dist/engine/domain/task.d.ts.map +1 -0
  171. package/dist/engine/domain/task.js +4 -0
  172. package/dist/engine/domain/task.js.map +1 -0
  173. package/dist/engine/domain/tool-selection-config.d.ts +12 -0
  174. package/dist/engine/domain/tool-selection-config.d.ts.map +1 -0
  175. package/dist/engine/domain/tool-selection-config.js +22 -0
  176. package/dist/engine/domain/tool-selection-config.js.map +1 -0
  177. package/dist/engine/domain/trigger.d.ts +43 -0
  178. package/dist/engine/domain/trigger.d.ts.map +1 -0
  179. package/dist/engine/domain/trigger.js +39 -0
  180. package/dist/engine/domain/trigger.js.map +1 -0
  181. package/dist/engine/domain/vector-store.d.ts +27 -0
  182. package/dist/engine/domain/vector-store.d.ts.map +1 -0
  183. package/dist/engine/domain/vector-store.js +3 -0
  184. package/dist/engine/domain/vector-store.js.map +1 -0
  185. package/dist/engine/domain/workflow.d.ts +11 -0
  186. package/dist/engine/domain/workflow.d.ts.map +1 -0
  187. package/dist/engine/domain/workflow.js +4 -0
  188. package/dist/engine/domain/workflow.js.map +1 -0
  189. package/dist/engine/error-catalog.d.ts +8 -0
  190. package/dist/engine/error-catalog.d.ts.map +1 -0
  191. package/dist/engine/error-catalog.js +335 -0
  192. package/dist/engine/error-catalog.js.map +1 -0
  193. package/dist/engine/errors.d.ts +18 -0
  194. package/dist/engine/errors.d.ts.map +1 -0
  195. package/dist/engine/errors.js +20 -0
  196. package/dist/engine/errors.js.map +1 -0
  197. package/dist/engine/gateway/delegation-config.d.ts +52 -0
  198. package/dist/engine/gateway/delegation-config.d.ts.map +1 -0
  199. package/dist/engine/gateway/delegation-config.js +48 -0
  200. package/dist/engine/gateway/delegation-config.js.map +1 -0
  201. package/dist/engine/gateway/gateway-config.d.ts +33 -0
  202. package/dist/engine/gateway/gateway-config.d.ts.map +1 -0
  203. package/dist/engine/gateway/gateway-config.js +61 -0
  204. package/dist/engine/gateway/gateway-config.js.map +1 -0
  205. package/dist/engine/gateway/gateway-loader.d.ts +10 -0
  206. package/dist/engine/gateway/gateway-loader.d.ts.map +1 -0
  207. package/dist/engine/gateway/gateway-loader.js +150 -0
  208. package/dist/engine/gateway/gateway-loader.js.map +1 -0
  209. package/dist/engine/gateway/mode-b-config.d.ts +44 -0
  210. package/dist/engine/gateway/mode-b-config.d.ts.map +1 -0
  211. package/dist/engine/gateway/mode-b-config.js +45 -0
  212. package/dist/engine/gateway/mode-b-config.js.map +1 -0
  213. package/dist/engine/gateway/mode-b-loader.d.ts +14 -0
  214. package/dist/engine/gateway/mode-b-loader.d.ts.map +1 -0
  215. package/dist/engine/gateway/mode-b-loader.js +104 -0
  216. package/dist/engine/gateway/mode-b-loader.js.map +1 -0
  217. package/dist/engine/gateway/observability-config.d.ts +19 -0
  218. package/dist/engine/gateway/observability-config.d.ts.map +1 -0
  219. package/dist/engine/gateway/observability-config.js +27 -0
  220. package/dist/engine/gateway/observability-config.js.map +1 -0
  221. package/dist/engine/gateway/tenant-config.d.ts +59 -0
  222. package/dist/engine/gateway/tenant-config.d.ts.map +1 -0
  223. package/dist/engine/gateway/tenant-config.js +44 -0
  224. package/dist/engine/gateway/tenant-config.js.map +1 -0
  225. package/dist/engine/index.d.ts +49 -0
  226. package/dist/engine/index.d.ts.map +1 -0
  227. package/dist/engine/index.js +27 -0
  228. package/dist/engine/index.js.map +1 -0
  229. package/dist/engine/loader/app-loader.d.ts +18 -0
  230. package/dist/engine/loader/app-loader.d.ts.map +1 -0
  231. package/dist/engine/loader/app-loader.js +947 -0
  232. package/dist/engine/loader/app-loader.js.map +1 -0
  233. package/dist/engine/loader/preset-loader.d.ts +13 -0
  234. package/dist/engine/loader/preset-loader.d.ts.map +1 -0
  235. package/dist/engine/loader/preset-loader.js +51 -0
  236. package/dist/engine/loader/preset-loader.js.map +1 -0
  237. package/dist/eval/dataset-loader.d.ts +3 -0
  238. package/dist/eval/dataset-loader.d.ts.map +1 -0
  239. package/dist/eval/dataset-loader.js +70 -0
  240. package/dist/eval/dataset-loader.js.map +1 -0
  241. package/dist/eval/experiment-comparator.d.ts +16 -0
  242. package/dist/eval/experiment-comparator.d.ts.map +1 -0
  243. package/dist/eval/experiment-comparator.js +34 -0
  244. package/dist/eval/experiment-comparator.js.map +1 -0
  245. package/dist/eval/experiment-runner.d.ts +20 -0
  246. package/dist/eval/experiment-runner.d.ts.map +1 -0
  247. package/dist/eval/experiment-runner.js +54 -0
  248. package/dist/eval/experiment-runner.js.map +1 -0
  249. package/dist/eval/index.d.ts +21 -0
  250. package/dist/eval/index.d.ts.map +1 -0
  251. package/dist/eval/index.js +19 -0
  252. package/dist/eval/index.js.map +1 -0
  253. package/dist/eval/scorer-factory.d.ts +4 -0
  254. package/dist/eval/scorer-factory.d.ts.map +1 -0
  255. package/dist/eval/scorer-factory.js +67 -0
  256. package/dist/eval/scorer-factory.js.map +1 -0
  257. package/dist/eval/scorers/coherence-scorer.d.ts +8 -0
  258. package/dist/eval/scorers/coherence-scorer.d.ts.map +1 -0
  259. package/dist/eval/scorers/coherence-scorer.js +22 -0
  260. package/dist/eval/scorers/coherence-scorer.js.map +1 -0
  261. package/dist/eval/scorers/composite-scorer.d.ts +8 -0
  262. package/dist/eval/scorers/composite-scorer.d.ts.map +1 -0
  263. package/dist/eval/scorers/composite-scorer.js +19 -0
  264. package/dist/eval/scorers/composite-scorer.js.map +1 -0
  265. package/dist/eval/scorers/contains-scorer.d.ts +8 -0
  266. package/dist/eval/scorers/contains-scorer.d.ts.map +1 -0
  267. package/dist/eval/scorers/contains-scorer.js +30 -0
  268. package/dist/eval/scorers/contains-scorer.js.map +1 -0
  269. package/dist/eval/scorers/cost-scorer.d.ts +8 -0
  270. package/dist/eval/scorers/cost-scorer.d.ts.map +1 -0
  271. package/dist/eval/scorers/cost-scorer.js +19 -0
  272. package/dist/eval/scorers/cost-scorer.js.map +1 -0
  273. package/dist/eval/scorers/custom-prompt-scorer.d.ts +9 -0
  274. package/dist/eval/scorers/custom-prompt-scorer.d.ts.map +1 -0
  275. package/dist/eval/scorers/custom-prompt-scorer.js +24 -0
  276. package/dist/eval/scorers/custom-prompt-scorer.js.map +1 -0
  277. package/dist/eval/scorers/exact-match-scorer.d.ts +6 -0
  278. package/dist/eval/scorers/exact-match-scorer.d.ts.map +1 -0
  279. package/dist/eval/scorers/exact-match-scorer.js +16 -0
  280. package/dist/eval/scorers/exact-match-scorer.js.map +1 -0
  281. package/dist/eval/scorers/faithfulness-scorer.d.ts +8 -0
  282. package/dist/eval/scorers/faithfulness-scorer.d.ts.map +1 -0
  283. package/dist/eval/scorers/faithfulness-scorer.js +27 -0
  284. package/dist/eval/scorers/faithfulness-scorer.js.map +1 -0
  285. package/dist/eval/scorers/hallucination-scorer.d.ts +8 -0
  286. package/dist/eval/scorers/hallucination-scorer.d.ts.map +1 -0
  287. package/dist/eval/scorers/hallucination-scorer.js +31 -0
  288. package/dist/eval/scorers/hallucination-scorer.js.map +1 -0
  289. package/dist/eval/scorers/json-validity-scorer.d.ts +8 -0
  290. package/dist/eval/scorers/json-validity-scorer.d.ts.map +1 -0
  291. package/dist/eval/scorers/json-validity-scorer.js +32 -0
  292. package/dist/eval/scorers/json-validity-scorer.js.map +1 -0
  293. package/dist/eval/scorers/latency-scorer.d.ts +8 -0
  294. package/dist/eval/scorers/latency-scorer.d.ts.map +1 -0
  295. package/dist/eval/scorers/latency-scorer.js +19 -0
  296. package/dist/eval/scorers/latency-scorer.js.map +1 -0
  297. package/dist/eval/scorers/length-scorer.d.ts +9 -0
  298. package/dist/eval/scorers/length-scorer.d.ts.map +1 -0
  299. package/dist/eval/scorers/length-scorer.js +26 -0
  300. package/dist/eval/scorers/length-scorer.js.map +1 -0
  301. package/dist/eval/scorers/parse-llm-response.d.ts +5 -0
  302. package/dist/eval/scorers/parse-llm-response.d.ts.map +1 -0
  303. package/dist/eval/scorers/parse-llm-response.js +13 -0
  304. package/dist/eval/scorers/parse-llm-response.js.map +1 -0
  305. package/dist/eval/scorers/relevance-scorer.d.ts +8 -0
  306. package/dist/eval/scorers/relevance-scorer.d.ts.map +1 -0
  307. package/dist/eval/scorers/relevance-scorer.js +23 -0
  308. package/dist/eval/scorers/relevance-scorer.js.map +1 -0
  309. package/dist/eval/scorers/toxicity-scorer.d.ts +8 -0
  310. package/dist/eval/scorers/toxicity-scorer.d.ts.map +1 -0
  311. package/dist/eval/scorers/toxicity-scorer.js +26 -0
  312. package/dist/eval/scorers/toxicity-scorer.js.map +1 -0
  313. package/dist/eval/types.d.ts +51 -0
  314. package/dist/eval/types.d.ts.map +1 -0
  315. package/dist/eval/types.js +3 -0
  316. package/dist/eval/types.js.map +1 -0
  317. package/dist/events/event-bus.d.ts +36 -0
  318. package/dist/events/event-bus.d.ts.map +1 -0
  319. package/dist/events/event-bus.js +116 -0
  320. package/dist/events/event-bus.js.map +1 -0
  321. package/dist/events/event-store.d.ts +11 -0
  322. package/dist/events/event-store.d.ts.map +1 -0
  323. package/dist/events/event-store.js +2 -0
  324. package/dist/events/event-store.js.map +1 -0
  325. package/dist/events/index.d.ts +295 -0
  326. package/dist/events/index.d.ts.map +1 -0
  327. package/dist/events/index.js +48 -0
  328. package/dist/events/index.js.map +1 -0
  329. package/dist/events/trace.d.ts +30 -0
  330. package/dist/events/trace.d.ts.map +1 -0
  331. package/dist/events/trace.js +45 -0
  332. package/dist/events/trace.js.map +1 -0
  333. package/dist/index.d.ts +58 -0
  334. package/dist/index.d.ts.map +1 -0
  335. package/dist/index.js +42 -0
  336. package/dist/index.js.map +1 -0
  337. package/dist/knowledge/index.d.ts +10 -0
  338. package/dist/knowledge/index.d.ts.map +1 -0
  339. package/dist/knowledge/index.js +9 -0
  340. package/dist/knowledge/index.js.map +1 -0
  341. package/dist/knowledge/infrastructure/memory-vector-store.d.ts +12 -0
  342. package/dist/knowledge/infrastructure/memory-vector-store.d.ts.map +1 -0
  343. package/dist/knowledge/infrastructure/memory-vector-store.js +71 -0
  344. package/dist/knowledge/infrastructure/memory-vector-store.js.map +1 -0
  345. package/dist/knowledge/infrastructure/ollama-embedding.d.ts +15 -0
  346. package/dist/knowledge/infrastructure/ollama-embedding.d.ts.map +1 -0
  347. package/dist/knowledge/infrastructure/ollama-embedding.js +38 -0
  348. package/dist/knowledge/infrastructure/ollama-embedding.js.map +1 -0
  349. package/dist/knowledge/infrastructure/openai-embedding.d.ts +18 -0
  350. package/dist/knowledge/infrastructure/openai-embedding.d.ts.map +1 -0
  351. package/dist/knowledge/infrastructure/openai-embedding.js +66 -0
  352. package/dist/knowledge/infrastructure/openai-embedding.js.map +1 -0
  353. package/dist/knowledge/knowledge-capability.d.ts +15 -0
  354. package/dist/knowledge/knowledge-capability.d.ts.map +1 -0
  355. package/dist/knowledge/knowledge-capability.js +36 -0
  356. package/dist/knowledge/knowledge-capability.js.map +1 -0
  357. package/dist/knowledge/markdown-chunker.d.ts +8 -0
  358. package/dist/knowledge/markdown-chunker.d.ts.map +1 -0
  359. package/dist/knowledge/markdown-chunker.js +146 -0
  360. package/dist/knowledge/markdown-chunker.js.map +1 -0
  361. package/dist/knowledge/recursive-chunker.d.ts +8 -0
  362. package/dist/knowledge/recursive-chunker.d.ts.map +1 -0
  363. package/dist/knowledge/recursive-chunker.js +73 -0
  364. package/dist/knowledge/recursive-chunker.js.map +1 -0
  365. package/dist/knowledge/reranker.d.ts +5 -0
  366. package/dist/knowledge/reranker.d.ts.map +1 -0
  367. package/dist/knowledge/reranker.js +3 -0
  368. package/dist/knowledge/reranker.js.map +1 -0
  369. package/dist/knowledge/retrieval-pipeline.d.ts +26 -0
  370. package/dist/knowledge/retrieval-pipeline.d.ts.map +1 -0
  371. package/dist/knowledge/retrieval-pipeline.js +56 -0
  372. package/dist/knowledge/retrieval-pipeline.js.map +1 -0
  373. package/dist/memory/chunk-importer.d.ts +16 -0
  374. package/dist/memory/chunk-importer.d.ts.map +1 -0
  375. package/dist/memory/chunk-importer.js +58 -0
  376. package/dist/memory/chunk-importer.js.map +1 -0
  377. package/dist/memory/compactor.d.ts +59 -0
  378. package/dist/memory/compactor.d.ts.map +1 -0
  379. package/dist/memory/compactor.js +100 -0
  380. package/dist/memory/compactor.js.map +1 -0
  381. package/dist/memory/decay-curves.d.ts +33 -0
  382. package/dist/memory/decay-curves.d.ts.map +1 -0
  383. package/dist/memory/decay-curves.js +48 -0
  384. package/dist/memory/decay-curves.js.map +1 -0
  385. package/dist/memory/developer-identity.d.ts +7 -0
  386. package/dist/memory/developer-identity.d.ts.map +1 -0
  387. package/dist/memory/developer-identity.js +20 -0
  388. package/dist/memory/developer-identity.js.map +1 -0
  389. package/dist/memory/git-sync-manager.d.ts +28 -0
  390. package/dist/memory/git-sync-manager.d.ts.map +1 -0
  391. package/dist/memory/git-sync-manager.js +77 -0
  392. package/dist/memory/git-sync-manager.js.map +1 -0
  393. package/dist/memory/index.d.ts +46 -0
  394. package/dist/memory/index.d.ts.map +1 -0
  395. package/dist/memory/index.js +11 -0
  396. package/dist/memory/index.js.map +1 -0
  397. package/dist/memory/memory-manager.d.ts +34 -0
  398. package/dist/memory/memory-manager.d.ts.map +1 -0
  399. package/dist/memory/memory-manager.js +151 -0
  400. package/dist/memory/memory-manager.js.map +1 -0
  401. package/dist/memory/project-store.d.ts +28 -0
  402. package/dist/memory/project-store.d.ts.map +1 -0
  403. package/dist/memory/project-store.js +159 -0
  404. package/dist/memory/project-store.js.map +1 -0
  405. package/dist/memory/sqlite-store.d.ts +41 -0
  406. package/dist/memory/sqlite-store.d.ts.map +1 -0
  407. package/dist/memory/sqlite-store.js +320 -0
  408. package/dist/memory/sqlite-store.js.map +1 -0
  409. package/dist/observability/index.d.ts +5 -0
  410. package/dist/observability/index.d.ts.map +1 -0
  411. package/dist/observability/index.js +3 -0
  412. package/dist/observability/index.js.map +1 -0
  413. package/dist/observability/otel-exporter.d.ts +41 -0
  414. package/dist/observability/otel-exporter.d.ts.map +1 -0
  415. package/dist/observability/otel-exporter.js +166 -0
  416. package/dist/observability/otel-exporter.js.map +1 -0
  417. package/dist/observability/span-mapper.d.ts +24 -0
  418. package/dist/observability/span-mapper.d.ts.map +1 -0
  419. package/dist/observability/span-mapper.js +375 -0
  420. package/dist/observability/span-mapper.js.map +1 -0
  421. package/dist/orchestrator/checkpoint-store.d.ts +9 -0
  422. package/dist/orchestrator/checkpoint-store.d.ts.map +1 -0
  423. package/dist/orchestrator/checkpoint-store.js +2 -0
  424. package/dist/orchestrator/checkpoint-store.js.map +1 -0
  425. package/dist/orchestrator/checkpoint-types.d.ts +30 -0
  426. package/dist/orchestrator/checkpoint-types.d.ts.map +1 -0
  427. package/dist/orchestrator/checkpoint-types.js +2 -0
  428. package/dist/orchestrator/checkpoint-types.js.map +1 -0
  429. package/dist/orchestrator/guardrails.d.ts +23 -0
  430. package/dist/orchestrator/guardrails.d.ts.map +1 -0
  431. package/dist/orchestrator/guardrails.js +136 -0
  432. package/dist/orchestrator/guardrails.js.map +1 -0
  433. package/dist/orchestrator/index.d.ts +45 -0
  434. package/dist/orchestrator/index.d.ts.map +1 -0
  435. package/dist/orchestrator/index.js +8 -0
  436. package/dist/orchestrator/index.js.map +1 -0
  437. package/dist/orchestrator/interrupt.d.ts +20 -0
  438. package/dist/orchestrator/interrupt.d.ts.map +1 -0
  439. package/dist/orchestrator/interrupt.js +4 -0
  440. package/dist/orchestrator/interrupt.js.map +1 -0
  441. package/dist/orchestrator/orchestrator.d.ts +170 -0
  442. package/dist/orchestrator/orchestrator.d.ts.map +1 -0
  443. package/dist/orchestrator/orchestrator.js +509 -0
  444. package/dist/orchestrator/orchestrator.js.map +1 -0
  445. package/dist/orchestrator/phase-machine.d.ts +48 -0
  446. package/dist/orchestrator/phase-machine.d.ts.map +1 -0
  447. package/dist/orchestrator/phase-machine.js +176 -0
  448. package/dist/orchestrator/phase-machine.js.map +1 -0
  449. package/dist/orchestrator/schemas.d.ts +145 -0
  450. package/dist/orchestrator/schemas.d.ts.map +1 -0
  451. package/dist/orchestrator/schemas.js +126 -0
  452. package/dist/orchestrator/schemas.js.map +1 -0
  453. package/dist/orchestrator/sqlite-checkpoint-store.d.ts +15 -0
  454. package/dist/orchestrator/sqlite-checkpoint-store.d.ts.map +1 -0
  455. package/dist/orchestrator/sqlite-checkpoint-store.js +98 -0
  456. package/dist/orchestrator/sqlite-checkpoint-store.js.map +1 -0
  457. package/dist/orchestrator/strategies/index.d.ts +28 -0
  458. package/dist/orchestrator/strategies/index.d.ts.map +1 -0
  459. package/dist/orchestrator/strategies/index.js +20 -0
  460. package/dist/orchestrator/strategies/index.js.map +1 -0
  461. package/dist/orchestrator/strategies/sequential-strategy.d.ts +13 -0
  462. package/dist/orchestrator/strategies/sequential-strategy.d.ts.map +1 -0
  463. package/dist/orchestrator/strategies/sequential-strategy.js +29 -0
  464. package/dist/orchestrator/strategies/sequential-strategy.js.map +1 -0
  465. package/dist/orchestrator/strategies/supervisor-strategy.d.ts +43 -0
  466. package/dist/orchestrator/strategies/supervisor-strategy.d.ts.map +1 -0
  467. package/dist/orchestrator/strategies/supervisor-strategy.js +118 -0
  468. package/dist/orchestrator/strategies/supervisor-strategy.js.map +1 -0
  469. package/dist/orchestrator/strategies/swarm-strategy.d.ts +36 -0
  470. package/dist/orchestrator/strategies/swarm-strategy.d.ts.map +1 -0
  471. package/dist/orchestrator/strategies/swarm-strategy.js +126 -0
  472. package/dist/orchestrator/strategies/swarm-strategy.js.map +1 -0
  473. package/dist/package/index.d.ts +7 -0
  474. package/dist/package/index.d.ts.map +1 -0
  475. package/dist/package/index.js +6 -0
  476. package/dist/package/index.js.map +1 -0
  477. package/dist/package/security.d.ts +18 -0
  478. package/dist/package/security.d.ts.map +1 -0
  479. package/dist/package/security.js +110 -0
  480. package/dist/package/security.js.map +1 -0
  481. package/dist/package/types.d.ts +34 -0
  482. package/dist/package/types.d.ts.map +1 -0
  483. package/dist/package/types.js +4 -0
  484. package/dist/package/types.js.map +1 -0
  485. package/dist/package/yaml-parser.d.ts +22 -0
  486. package/dist/package/yaml-parser.d.ts.map +1 -0
  487. package/dist/package/yaml-parser.js +109 -0
  488. package/dist/package/yaml-parser.js.map +1 -0
  489. package/dist/package/yaml-schema.d.ts +42 -0
  490. package/dist/package/yaml-schema.d.ts.map +1 -0
  491. package/dist/package/yaml-schema.js +141 -0
  492. package/dist/package/yaml-schema.js.map +1 -0
  493. package/dist/safety/content-classifier.d.ts +31 -0
  494. package/dist/safety/content-classifier.d.ts.map +1 -0
  495. package/dist/safety/content-classifier.js +107 -0
  496. package/dist/safety/content-classifier.js.map +1 -0
  497. package/dist/safety/index.d.ts +10 -0
  498. package/dist/safety/index.d.ts.map +1 -0
  499. package/dist/safety/index.js +10 -0
  500. package/dist/safety/index.js.map +1 -0
  501. package/dist/safety/pii-scanner.d.ts +26 -0
  502. package/dist/safety/pii-scanner.d.ts.map +1 -0
  503. package/dist/safety/pii-scanner.js +82 -0
  504. package/dist/safety/pii-scanner.js.map +1 -0
  505. package/dist/safety/rails.d.ts +33 -0
  506. package/dist/safety/rails.d.ts.map +1 -0
  507. package/dist/safety/rails.js +134 -0
  508. package/dist/safety/rails.js.map +1 -0
  509. package/dist/safety/safety-pipeline.d.ts +41 -0
  510. package/dist/safety/safety-pipeline.d.ts.map +1 -0
  511. package/dist/safety/safety-pipeline.js +153 -0
  512. package/dist/safety/safety-pipeline.js.map +1 -0
  513. package/dist/safety/types.d.ts +38 -0
  514. package/dist/safety/types.d.ts.map +1 -0
  515. package/dist/safety/types.js +3 -0
  516. package/dist/safety/types.js.map +1 -0
  517. package/dist/sandbox/index.d.ts +17 -0
  518. package/dist/sandbox/index.d.ts.map +1 -0
  519. package/dist/sandbox/index.js +4 -0
  520. package/dist/sandbox/index.js.map +1 -0
  521. package/dist/sandbox/network-filter.d.ts +13 -0
  522. package/dist/sandbox/network-filter.d.ts.map +1 -0
  523. package/dist/sandbox/network-filter.js +43 -0
  524. package/dist/sandbox/network-filter.js.map +1 -0
  525. package/dist/sandbox/path-validator.d.ts +16 -0
  526. package/dist/sandbox/path-validator.d.ts.map +1 -0
  527. package/dist/sandbox/path-validator.js +47 -0
  528. package/dist/sandbox/path-validator.js.map +1 -0
  529. package/dist/sandbox/policies.d.ts +38 -0
  530. package/dist/sandbox/policies.d.ts.map +1 -0
  531. package/dist/sandbox/policies.js +145 -0
  532. package/dist/sandbox/policies.js.map +1 -0
  533. package/dist/security/audit-log.d.ts +17 -0
  534. package/dist/security/audit-log.d.ts.map +1 -0
  535. package/dist/security/audit-log.js +214 -0
  536. package/dist/security/audit-log.js.map +1 -0
  537. package/dist/security/guardian.d.ts +24 -0
  538. package/dist/security/guardian.d.ts.map +1 -0
  539. package/dist/security/guardian.js +177 -0
  540. package/dist/security/guardian.js.map +1 -0
  541. package/dist/security/index.d.ts +10 -0
  542. package/dist/security/index.d.ts.map +1 -0
  543. package/dist/security/index.js +7 -0
  544. package/dist/security/index.js.map +1 -0
  545. package/dist/security/prompt-scanner.d.ts +23 -0
  546. package/dist/security/prompt-scanner.d.ts.map +1 -0
  547. package/dist/security/prompt-scanner.js +376 -0
  548. package/dist/security/prompt-scanner.js.map +1 -0
  549. package/dist/security/secret-store.d.ts +18 -0
  550. package/dist/security/secret-store.d.ts.map +1 -0
  551. package/dist/security/secret-store.js +123 -0
  552. package/dist/security/secret-store.js.map +1 -0
  553. package/dist/security/self-audit.d.ts +33 -0
  554. package/dist/security/self-audit.d.ts.map +1 -0
  555. package/dist/security/self-audit.js +142 -0
  556. package/dist/security/self-audit.js.map +1 -0
  557. package/dist/security/types.d.ts +107 -0
  558. package/dist/security/types.d.ts.map +1 -0
  559. package/dist/security/types.js +3 -0
  560. package/dist/security/types.js.map +1 -0
  561. package/dist/skill/index.d.ts +7 -0
  562. package/dist/skill/index.d.ts.map +1 -0
  563. package/dist/skill/index.js +4 -0
  564. package/dist/skill/index.js.map +1 -0
  565. package/dist/skill/skill-registry.d.ts +26 -0
  566. package/dist/skill/skill-registry.d.ts.map +1 -0
  567. package/dist/skill/skill-registry.js +81 -0
  568. package/dist/skill/skill-registry.js.map +1 -0
  569. package/dist/skill/types.d.ts +17 -0
  570. package/dist/skill/types.d.ts.map +1 -0
  571. package/dist/skill/types.js +2 -0
  572. package/dist/skill/types.js.map +1 -0
  573. package/dist/skill/yaml-parser.d.ts +18 -0
  574. package/dist/skill/yaml-parser.d.ts.map +1 -0
  575. package/dist/skill/yaml-parser.js +61 -0
  576. package/dist/skill/yaml-parser.js.map +1 -0
  577. package/dist/skill/yaml-schema.d.ts +20 -0
  578. package/dist/skill/yaml-schema.d.ts.map +1 -0
  579. package/dist/skill/yaml-schema.js +80 -0
  580. package/dist/skill/yaml-schema.js.map +1 -0
  581. package/dist/tree/batch-executor.d.ts +28 -0
  582. package/dist/tree/batch-executor.d.ts.map +1 -0
  583. package/dist/tree/batch-executor.js +78 -0
  584. package/dist/tree/batch-executor.js.map +1 -0
  585. package/dist/tree/index.d.ts +26 -0
  586. package/dist/tree/index.d.ts.map +1 -0
  587. package/dist/tree/index.js +3 -0
  588. package/dist/tree/index.js.map +1 -0
  589. package/dist/tree/task-tree.d.ts +74 -0
  590. package/dist/tree/task-tree.d.ts.map +1 -0
  591. package/dist/tree/task-tree.js +262 -0
  592. package/dist/tree/task-tree.js.map +1 -0
  593. package/dist/verification/coverage-parser.d.ts +6 -0
  594. package/dist/verification/coverage-parser.d.ts.map +1 -0
  595. package/dist/verification/coverage-parser.js +29 -0
  596. package/dist/verification/coverage-parser.js.map +1 -0
  597. package/dist/verification/gate-runner.d.ts +18 -0
  598. package/dist/verification/gate-runner.d.ts.map +1 -0
  599. package/dist/verification/gate-runner.js +63 -0
  600. package/dist/verification/gate-runner.js.map +1 -0
  601. package/dist/verification/index.d.ts +24 -0
  602. package/dist/verification/index.d.ts.map +1 -0
  603. package/dist/verification/index.js +4 -0
  604. package/dist/verification/index.js.map +1 -0
  605. package/dist/verification/verification-loop.d.ts +32 -0
  606. package/dist/verification/verification-loop.d.ts.map +1 -0
  607. package/dist/verification/verification-loop.js +71 -0
  608. package/dist/verification/verification-loop.js.map +1 -0
  609. package/package.json +58 -0
@@ -0,0 +1,947 @@
1
+ // Engine loader: AppLoader -- parses App YAML into typed composites
2
+ // Validates dependency graph: team refs in router must exist in teams
3
+ import { parse } from "yaml";
4
+ import { KilnError } from "../errors.js";
5
+ import { validateApp } from "../composites/app.js";
6
+ import { VALID_MODALITIES } from "../domain/modality.js";
7
+ import { validateVoiceConfig } from "../domain/speech-config.js";
8
+ import { validateKnowledgeConfig } from "../domain/knowledge-config.js";
9
+ import { validateEvalConfig } from "../domain/eval-config.js";
10
+ import { validateMcpConfig } from "../domain/mcp-config.js";
11
+ import { validateToolSelectionConfig } from "../domain/tool-selection-config.js";
12
+ import { validateSafetyConfig } from "../domain/safety-config.js";
13
+ /** Error class for YAML loader failures, aggregating all validation errors */
14
+ export class AppLoaderError extends KilnError {
15
+ errors;
16
+ constructor(errors) {
17
+ const msg = errors.map((e) => ` ${e.field}: ${e.message}`).join("\n");
18
+ super("APP_YAML_INVALID", `Invalid app YAML:\n${msg}`, {
19
+ context: { errors },
20
+ retryable: false,
21
+ });
22
+ this.name = "AppLoaderError";
23
+ this.errors = errors;
24
+ }
25
+ }
26
+ // ---------------------------------------------------------------------------
27
+ // Mapping helpers
28
+ // ---------------------------------------------------------------------------
29
+ const VALID_TIERS = ["reasoning", "coding", "fast"];
30
+ function mapAgent(identifier, raw, path) {
31
+ const errors = [];
32
+ // name: persona name from YAML (required) -- falls back to identifier for safety
33
+ const name = typeof raw.name === "string" && raw.name.trim() !== ""
34
+ ? raw.name.trim()
35
+ : identifier;
36
+ if (!raw.name || typeof raw.name !== "string" || raw.name.trim() === "") {
37
+ errors.push({ field: `${path}.name`, message: "must be a non-empty string (persona name)" });
38
+ }
39
+ // role: expertise / function (required)
40
+ const role = typeof raw.role === "string" ? raw.role.trim() : "";
41
+ if (!raw.role || typeof raw.role !== "string" || raw.role.trim() === "") {
42
+ errors.push({ field: `${path}.role`, message: "must be a non-empty string (expertise/function)" });
43
+ }
44
+ // goal: what agent is trying to achieve (required)
45
+ const goal = typeof raw.goal === "string" ? raw.goal.trim() : "";
46
+ if (!raw.goal || typeof raw.goal !== "string" || raw.goal.trim() === "") {
47
+ errors.push({ field: `${path}.goal`, message: "must be a non-empty string (what agent achieves)" });
48
+ }
49
+ // tier: model class (required)
50
+ const tier = raw.tier;
51
+ if (!tier || !VALID_TIERS.includes(tier)) {
52
+ errors.push({ field: `${path}.tier`, message: `must be one of: ${VALID_TIERS.join(", ")}` });
53
+ }
54
+ // tools: capability references (can be [])
55
+ const tools = [];
56
+ if (raw.tools !== undefined) {
57
+ if (!Array.isArray(raw.tools)) {
58
+ errors.push({ field: `${path}.tools`, message: "must be an array" });
59
+ }
60
+ else {
61
+ for (const t of raw.tools) {
62
+ if (typeof t !== "string") {
63
+ errors.push({ field: `${path}.tools`, message: "all entries must be strings" });
64
+ break;
65
+ }
66
+ tools.push(t);
67
+ }
68
+ }
69
+ }
70
+ // modalities: optional content type declarations
71
+ let modalities;
72
+ if (raw.modalities !== undefined) {
73
+ if (!Array.isArray(raw.modalities)) {
74
+ errors.push({ field: `${path}.modalities`, message: "must be an array" });
75
+ }
76
+ else {
77
+ modalities = [];
78
+ for (const m of raw.modalities) {
79
+ if (typeof m !== "string") {
80
+ errors.push({ field: `${path}.modalities`, message: "all entries must be strings" });
81
+ break;
82
+ }
83
+ if (!VALID_MODALITIES.includes(m)) {
84
+ errors.push({ field: `${path}.modalities`, message: `unknown modality "${m}", must be one of: ${VALID_MODALITIES.join(", ")}` });
85
+ }
86
+ else {
87
+ modalities.push(m);
88
+ }
89
+ }
90
+ }
91
+ }
92
+ const agent = {
93
+ name,
94
+ role,
95
+ goal,
96
+ tier: tier ?? "coding",
97
+ tools,
98
+ ...(typeof raw.backstory === "string" ? { backstory: raw.backstory.trim() } : {}),
99
+ ...(typeof raw.instructions === "string" ? { instructions: raw.instructions.trim() } : {}),
100
+ ...(typeof raw.structured === "boolean" ? { structured: raw.structured } : {}),
101
+ ...(typeof raw.count === "number" ? { count: raw.count } : {}),
102
+ ...(typeof raw.sandbox === "boolean" ? { sandbox: raw.sandbox } : {}),
103
+ ...(modalities && modalities.length > 0 ? { modalities } : {}),
104
+ };
105
+ return { agent, errors };
106
+ }
107
+ function mapWorkflow(raw, path) {
108
+ const errors = [];
109
+ const phases = [];
110
+ if (!raw.phases || !Array.isArray(raw.phases)) {
111
+ errors.push({ field: `${path}.phases`, message: "must be a non-empty array" });
112
+ }
113
+ else {
114
+ for (const p of raw.phases) {
115
+ if (typeof p !== "string") {
116
+ errors.push({ field: `${path}.phases`, message: "all entries must be strings" });
117
+ break;
118
+ }
119
+ phases.push(p);
120
+ }
121
+ }
122
+ const gates = {};
123
+ if (raw.gates !== undefined) {
124
+ if (typeof raw.gates !== "object" || raw.gates === null || Array.isArray(raw.gates)) {
125
+ errors.push({ field: `${path}.gates`, message: "must be an object" });
126
+ }
127
+ else {
128
+ for (const [phaseName, gateRaw] of Object.entries(raw.gates)) {
129
+ const requires = [];
130
+ if (Array.isArray(gateRaw?.requires)) {
131
+ for (const r of gateRaw.requires) {
132
+ if (typeof r === "string")
133
+ requires.push(r);
134
+ }
135
+ }
136
+ gates[phaseName] = { requires };
137
+ }
138
+ }
139
+ }
140
+ const workflow = {
141
+ phases,
142
+ gates,
143
+ ...(typeof raw.maxIterations === "number" ? { maxIterations: raw.maxIterations } : {}),
144
+ };
145
+ return { workflow, errors };
146
+ }
147
+ function mapCapability(raw, path) {
148
+ const errors = [];
149
+ if (!raw.name || typeof raw.name !== "string") {
150
+ errors.push({ field: `${path}.name`, message: "must be a non-empty string" });
151
+ }
152
+ if (!raw.description || typeof raw.description !== "string") {
153
+ errors.push({ field: `${path}.description`, message: "must be a non-empty string" });
154
+ }
155
+ const tags = [];
156
+ if (raw.tags !== undefined) {
157
+ if (!Array.isArray(raw.tags)) {
158
+ errors.push({ field: `${path}.tags`, message: "must be an array" });
159
+ }
160
+ else {
161
+ for (const t of raw.tags) {
162
+ if (typeof t === "string")
163
+ tags.push(t);
164
+ }
165
+ }
166
+ }
167
+ // Validate guardrailRetries
168
+ if (raw.guardrailRetries !== undefined) {
169
+ if (typeof raw.guardrailRetries !== "number" || !Number.isInteger(raw.guardrailRetries) || raw.guardrailRetries < 1) {
170
+ errors.push({ field: `${path}.guardrailRetries`, message: "must be a positive integer" });
171
+ }
172
+ }
173
+ // Validate outputSchema
174
+ if (raw.outputSchema !== undefined) {
175
+ if (typeof raw.outputSchema !== "object" || raw.outputSchema === null || Array.isArray(raw.outputSchema)) {
176
+ errors.push({ field: `${path}.outputSchema`, message: "must be a valid object" });
177
+ }
178
+ }
179
+ const capability = {
180
+ name: typeof raw.name === "string" ? raw.name : "",
181
+ description: typeof raw.description === "string" ? raw.description : "",
182
+ schema: typeof raw.schema === "object" && raw.schema !== null && !Array.isArray(raw.schema)
183
+ ? raw.schema
184
+ : {},
185
+ tags,
186
+ ...(raw.annotations ? { annotations: raw.annotations } : {}),
187
+ ...(typeof raw.type === "string" ? { type: raw.type } : {}),
188
+ ...(typeof raw.targetApp === "string" ? { targetApp: raw.targetApp } : {}),
189
+ ...(typeof raw.task === "string" ? { task: raw.task } : {}),
190
+ ...(typeof raw.timeout === "number" && raw.timeout > 0 ? { timeout: raw.timeout } : {}),
191
+ ...(typeof raw.guardrail === "string" ? { guardrail: raw.guardrail } : {}),
192
+ ...(typeof raw.guardrailRetries === "number" && Number.isInteger(raw.guardrailRetries) && raw.guardrailRetries >= 1
193
+ ? { guardrailRetries: raw.guardrailRetries }
194
+ : {}),
195
+ ...(typeof raw.outputSchema === "object" && raw.outputSchema !== null && !Array.isArray(raw.outputSchema)
196
+ ? { outputSchema: raw.outputSchema }
197
+ : {}),
198
+ };
199
+ if (raw.type === "delegation") {
200
+ if (typeof raw.targetApp !== "string" || raw.targetApp === "") {
201
+ errors.push({ field: `${path}.targetApp`, message: "required when type is 'delegation'" });
202
+ }
203
+ if (typeof raw.task !== "string" || raw.task === "") {
204
+ errors.push({ field: `${path}.task`, message: "required when type is 'delegation'" });
205
+ }
206
+ }
207
+ if (raw.type === "a2a") {
208
+ if (typeof raw.targetApp !== "string" || raw.targetApp === "") {
209
+ errors.push({ field: `${path}.targetApp`, message: "required when type is 'a2a' (must be agent URL)" });
210
+ }
211
+ }
212
+ return { capability, errors };
213
+ }
214
+ function mapQualityGate(raw, path) {
215
+ const errors = [];
216
+ if (!raw.name || typeof raw.name !== "string") {
217
+ errors.push({ field: `${path}.name`, message: "must be a non-empty string" });
218
+ }
219
+ if (!raw.command || typeof raw.command !== "string") {
220
+ errors.push({ field: `${path}.command`, message: "must be a non-empty string" });
221
+ }
222
+ if (!raw.description || typeof raw.description !== "string") {
223
+ errors.push({ field: `${path}.description`, message: "must be a non-empty string" });
224
+ }
225
+ const gate = {
226
+ name: typeof raw.name === "string" ? raw.name : "",
227
+ command: typeof raw.command === "string" ? raw.command : "",
228
+ description: typeof raw.description === "string" ? raw.description : "",
229
+ required: typeof raw.required === "boolean" ? raw.required : true,
230
+ };
231
+ return { gate, errors };
232
+ }
233
+ function mapTeam(name, raw, path) {
234
+ const errors = [];
235
+ const agents = {};
236
+ // Agents
237
+ if (!raw.agents || typeof raw.agents !== "object" || Array.isArray(raw.agents)) {
238
+ errors.push({ field: `${path}.agents`, message: "must be an object" });
239
+ }
240
+ else {
241
+ for (const [agentName, agentRaw] of Object.entries(raw.agents)) {
242
+ const { agent, errors: agentErrors } = mapAgent(agentName, agentRaw ?? {}, `${path}.agents.${agentName}`);
243
+ agents[agentName] = agent;
244
+ errors.push(...agentErrors);
245
+ }
246
+ }
247
+ // Workflow
248
+ let workflow = { phases: [], gates: {} };
249
+ if (!raw.workflow || typeof raw.workflow !== "object" || Array.isArray(raw.workflow)) {
250
+ errors.push({ field: `${path}.workflow`, message: "must be an object" });
251
+ }
252
+ else {
253
+ const { workflow: wf, errors: wfErrors } = mapWorkflow(raw.workflow, `${path}.workflow`);
254
+ workflow = wf;
255
+ errors.push(...wfErrors);
256
+ }
257
+ // Capabilities
258
+ const capabilities = [];
259
+ if (raw.capabilities !== undefined) {
260
+ if (!Array.isArray(raw.capabilities)) {
261
+ errors.push({ field: `${path}.capabilities`, message: "must be an array" });
262
+ }
263
+ else {
264
+ for (let i = 0; i < raw.capabilities.length; i++) {
265
+ const { capability, errors: capErrors } = mapCapability(raw.capabilities[i], `${path}.capabilities[${i}]`);
266
+ capabilities.push(capability);
267
+ errors.push(...capErrors);
268
+ }
269
+ }
270
+ }
271
+ // Quality gates -- support both `qualityGates` and `quality` keys
272
+ const qualityGates = [];
273
+ const rawGates = raw.qualityGates ?? raw.quality;
274
+ if (rawGates !== undefined) {
275
+ if (!Array.isArray(rawGates)) {
276
+ errors.push({ field: `${path}.qualityGates`, message: "must be an array" });
277
+ }
278
+ else {
279
+ for (let i = 0; i < rawGates.length; i++) {
280
+ const { gate, errors: gateErrors } = mapQualityGate(rawGates[i], `${path}.qualityGates[${i}]`);
281
+ qualityGates.push(gate);
282
+ errors.push(...gateErrors);
283
+ }
284
+ }
285
+ }
286
+ // Mode
287
+ const validModes = ["sequential", "supervisor", "swarm"];
288
+ let mode;
289
+ if (raw.mode !== undefined) {
290
+ if (typeof raw.mode !== "string" || !validModes.includes(raw.mode)) {
291
+ errors.push({ field: `${path}.mode`, message: `must be one of: ${validModes.join(", ")}` });
292
+ }
293
+ else {
294
+ mode = raw.mode;
295
+ }
296
+ }
297
+ // Manager
298
+ let manager;
299
+ if (raw.manager !== undefined) {
300
+ if (typeof raw.manager !== "string" || raw.manager === "") {
301
+ errors.push({ field: `${path}.manager`, message: "must be a non-empty string" });
302
+ }
303
+ else {
304
+ manager = raw.manager;
305
+ }
306
+ }
307
+ const team = {
308
+ name,
309
+ agents,
310
+ workflow,
311
+ capabilities,
312
+ qualityGates,
313
+ ...(mode ? { mode } : {}),
314
+ ...(manager ? { manager } : {}),
315
+ };
316
+ return { team, errors };
317
+ }
318
+ function mapRouter(raw, path) {
319
+ const errors = [];
320
+ const rules = [];
321
+ if (raw.rules !== undefined) {
322
+ if (!Array.isArray(raw.rules)) {
323
+ errors.push({ field: `${path}.rules`, message: "must be an array" });
324
+ }
325
+ else {
326
+ for (let i = 0; i < raw.rules.length; i++) {
327
+ const ruleRaw = raw.rules[i];
328
+ if (!ruleRaw.match || typeof ruleRaw.match !== "string") {
329
+ errors.push({ field: `${path}.rules[${i}].match`, message: "must be a non-empty string" });
330
+ }
331
+ if (!ruleRaw.team || typeof ruleRaw.team !== "string") {
332
+ errors.push({ field: `${path}.rules[${i}].team`, message: "must be a non-empty string" });
333
+ }
334
+ rules.push({
335
+ match: typeof ruleRaw.match === "string" ? ruleRaw.match : "",
336
+ team: typeof ruleRaw.team === "string" ? ruleRaw.team : "",
337
+ });
338
+ }
339
+ }
340
+ }
341
+ if (!raw.fallback || typeof raw.fallback !== "string") {
342
+ errors.push({ field: `${path}.fallback`, message: "must be a non-empty string" });
343
+ }
344
+ let classifier;
345
+ if (raw.classifier !== undefined) {
346
+ const classifierRaw = raw.classifier;
347
+ const { agent, errors: classifierErrors } = mapAgent("classifier", { ...classifierRaw, tier: classifierRaw.tier ?? "fast" }, `${path}.classifier`);
348
+ classifier = agent;
349
+ errors.push(...classifierErrors);
350
+ }
351
+ const router = {
352
+ rules,
353
+ fallback: typeof raw.fallback === "string" ? raw.fallback : "",
354
+ ...(classifier ? { classifier } : {}),
355
+ };
356
+ return { router, errors };
357
+ }
358
+ function mapMemory(raw, path) {
359
+ const errors = [];
360
+ const scopes = [];
361
+ if (!raw.scopes || !Array.isArray(raw.scopes)) {
362
+ errors.push({ field: `${path}.scopes`, message: "must be a non-empty array" });
363
+ }
364
+ else {
365
+ for (const s of raw.scopes) {
366
+ if (typeof s === "string")
367
+ scopes.push(s);
368
+ }
369
+ }
370
+ if (!raw.backend || typeof raw.backend !== "string") {
371
+ errors.push({ field: `${path}.backend`, message: "must be a non-empty string" });
372
+ }
373
+ const memory = {
374
+ scopes,
375
+ backend: typeof raw.backend === "string" ? raw.backend : "",
376
+ ...(typeof raw.sync === "string" ? { sync: raw.sync } : {}),
377
+ };
378
+ return { memory, errors };
379
+ }
380
+ const VALID_TRIGGER_TYPES = ["webhook", "event", "schedule"];
381
+ function mapTrigger(raw, path) {
382
+ const errors = [];
383
+ if (!raw.name || typeof raw.name !== "string") {
384
+ errors.push({ field: `${path}.name`, message: "must be a non-empty string" });
385
+ }
386
+ if (!raw.type || typeof raw.type !== "string" || !VALID_TRIGGER_TYPES.includes(raw.type)) {
387
+ errors.push({ field: `${path}.type`, message: `must be one of: ${VALID_TRIGGER_TYPES.join(", ")}` });
388
+ }
389
+ if (!raw.team || typeof raw.team !== "string") {
390
+ errors.push({ field: `${path}.team`, message: "must be a non-empty string" });
391
+ }
392
+ const base = {
393
+ name: typeof raw.name === "string" ? raw.name : "",
394
+ team: typeof raw.team === "string" ? raw.team : "",
395
+ ...(typeof raw.task === "string" ? { task: raw.task } : {}),
396
+ ...(typeof raw.enabled === "boolean" ? { enabled: raw.enabled } : {}),
397
+ };
398
+ const type = typeof raw.type === "string" ? raw.type : "";
399
+ switch (type) {
400
+ case "webhook": {
401
+ if (!raw.path || typeof raw.path !== "string") {
402
+ errors.push({ field: `${path}.path`, message: "must be a non-empty string" });
403
+ }
404
+ const trigger = {
405
+ ...base,
406
+ type: "webhook",
407
+ path: typeof raw.path === "string" ? raw.path : "",
408
+ ...(typeof raw.method === "string" ? { method: raw.method } : {}),
409
+ ...(typeof raw.secretEnv === "string" ? { secretEnv: raw.secretEnv } : {}),
410
+ };
411
+ return { trigger, errors };
412
+ }
413
+ case "event": {
414
+ if (!raw.event || typeof raw.event !== "string") {
415
+ errors.push({ field: `${path}.event`, message: "must be a non-empty string" });
416
+ }
417
+ const trigger = {
418
+ ...base,
419
+ type: "event",
420
+ event: typeof raw.event === "string" ? raw.event : "",
421
+ ...(raw.filter && typeof raw.filter === "object" && !Array.isArray(raw.filter)
422
+ ? { filter: raw.filter }
423
+ : {}),
424
+ };
425
+ return { trigger, errors };
426
+ }
427
+ case "schedule": {
428
+ if (!raw.cron || typeof raw.cron !== "string") {
429
+ errors.push({ field: `${path}.cron`, message: "must be a non-empty string" });
430
+ }
431
+ const trigger = {
432
+ ...base,
433
+ type: "schedule",
434
+ cron: typeof raw.cron === "string" ? raw.cron : "",
435
+ ...(typeof raw.timezone === "string" ? { timezone: raw.timezone } : {}),
436
+ };
437
+ return { trigger, errors };
438
+ }
439
+ default: {
440
+ // Return a webhook trigger as placeholder to satisfy the type system; the type error was already recorded
441
+ const trigger = {
442
+ ...base,
443
+ type: "webhook",
444
+ path: "",
445
+ };
446
+ return { trigger, errors };
447
+ }
448
+ }
449
+ }
450
+ function mapKnowledge(raw) {
451
+ const errors = [];
452
+ if (!raw || typeof raw !== "object") {
453
+ return { knowledge: undefined, errors: [] };
454
+ }
455
+ const rawEmbedding = raw.embedding;
456
+ const rawStore = raw.store;
457
+ const rawChunking = raw.chunking;
458
+ const embedding = {
459
+ provider: (typeof rawEmbedding?.provider === "string" ? rawEmbedding.provider : ""),
460
+ model: typeof rawEmbedding?.model === "string" ? rawEmbedding.model : undefined,
461
+ apiKeyEnv: typeof rawEmbedding?.apiKeyEnv === "string" ? rawEmbedding.apiKeyEnv : undefined,
462
+ baseUrl: typeof rawEmbedding?.baseUrl === "string" ? rawEmbedding.baseUrl : undefined,
463
+ };
464
+ const store = {
465
+ backend: (typeof rawStore?.backend === "string" ? rawStore.backend : ""),
466
+ connectionString: typeof rawStore?.connectionString === "string" ? rawStore.connectionString : undefined,
467
+ };
468
+ const chunking = {
469
+ strategy: (typeof rawChunking?.strategy === "string" ? rawChunking.strategy : ""),
470
+ chunkSize: typeof rawChunking?.chunkSize === "number" ? rawChunking.chunkSize : undefined,
471
+ chunkOverlap: typeof rawChunking?.chunkOverlap === "number" ? rawChunking.chunkOverlap : undefined,
472
+ };
473
+ const sources = [];
474
+ if (Array.isArray(raw.sources)) {
475
+ for (let i = 0; i < raw.sources.length; i++) {
476
+ const source = raw.sources[i];
477
+ if (!source)
478
+ continue;
479
+ const rawSourceChunking = source.chunking;
480
+ const sourceChunking = rawSourceChunking ? {
481
+ strategy: (typeof rawSourceChunking.strategy === "string" ? rawSourceChunking.strategy : ""),
482
+ chunkSize: typeof rawSourceChunking.chunkSize === "number" ? rawSourceChunking.chunkSize : undefined,
483
+ chunkOverlap: typeof rawSourceChunking.chunkOverlap === "number" ? rawSourceChunking.chunkOverlap : undefined,
484
+ } : undefined;
485
+ sources.push({
486
+ name: typeof source.name === "string" ? source.name : "",
487
+ path: typeof source.path === "string" ? source.path : "",
488
+ watch: typeof source.watch === "boolean" ? source.watch : undefined,
489
+ chunking: sourceChunking,
490
+ });
491
+ }
492
+ }
493
+ const allowedAgents = Array.isArray(raw.allowedAgents)
494
+ ? raw.allowedAgents.filter((a) => typeof a === "string")
495
+ : undefined;
496
+ const knowledge = {
497
+ embedding,
498
+ store,
499
+ chunking,
500
+ sources,
501
+ ...(allowedAgents && allowedAgents.length > 0 ? { allowedAgents } : {}),
502
+ };
503
+ const validationErrors = validateKnowledgeConfig(knowledge);
504
+ for (const ve of validationErrors) {
505
+ errors.push(ve);
506
+ }
507
+ return { knowledge: validationErrors.length > 0 ? undefined : knowledge, errors };
508
+ }
509
+ const VALID_SCORER_TYPES = [
510
+ "exact-match", "contains", "json-validity", "length", "latency", "cost",
511
+ "faithfulness", "relevance", "coherence", "hallucination", "toxicity",
512
+ "custom-prompt", "composite",
513
+ ];
514
+ function mapEvalScorer(raw) {
515
+ const errors = [];
516
+ const subScorers = [];
517
+ if (raw.scorers !== undefined && Array.isArray(raw.scorers)) {
518
+ for (let i = 0; i < raw.scorers.length; i++) {
519
+ const { scorer, errors: subErrors } = mapEvalScorer(raw.scorers[i]);
520
+ subScorers.push(scorer);
521
+ errors.push(...subErrors);
522
+ }
523
+ }
524
+ let scorerType = "exact-match";
525
+ if (typeof raw.type === "string" && VALID_SCORER_TYPES.includes(raw.type)) {
526
+ scorerType = raw.type;
527
+ }
528
+ else if (typeof raw.type === "string") {
529
+ errors.push({ field: "type", message: `unknown scorer type "${raw.type}", must be one of: ${VALID_SCORER_TYPES.join(", ")}` });
530
+ }
531
+ const scorer = {
532
+ name: typeof raw.name === "string" ? raw.name : "",
533
+ type: scorerType,
534
+ ...(subScorers.length > 0 ? { scorers: subScorers } : {}),
535
+ ...(typeof raw.schema === "object" && raw.schema !== null && !Array.isArray(raw.schema) ? { schema: raw.schema } : {}),
536
+ ...(typeof raw.prompt === "string" ? { prompt: raw.prompt } : {}),
537
+ ...(typeof raw.minLength === "number" ? { minLength: raw.minLength } : {}),
538
+ ...(typeof raw.maxLength === "number" ? { maxLength: raw.maxLength } : {}),
539
+ ...(typeof raw.maxLatencyMs === "number" ? { maxLatencyMs: raw.maxLatencyMs } : {}),
540
+ ...(typeof raw.maxCostUsd === "number" ? { maxCostUsd: raw.maxCostUsd } : {}),
541
+ ...(Array.isArray(raw.substrings) ? { substrings: raw.substrings.filter((s) => typeof s === "string") } : {}),
542
+ };
543
+ return { scorer, errors };
544
+ }
545
+ function mapEval(raw) {
546
+ const errors = [];
547
+ if (!raw || typeof raw !== "object") {
548
+ return { eval: undefined, errors: [] };
549
+ }
550
+ const datasets = [];
551
+ if (Array.isArray(raw.datasets)) {
552
+ for (const ds of raw.datasets) {
553
+ const rawDs = ds;
554
+ if (!rawDs)
555
+ continue;
556
+ datasets.push({
557
+ name: typeof rawDs.name === "string" ? rawDs.name : "",
558
+ path: typeof rawDs.path === "string" ? rawDs.path : "",
559
+ });
560
+ }
561
+ }
562
+ const scorers = [];
563
+ if (Array.isArray(raw.scorers)) {
564
+ for (const s of raw.scorers) {
565
+ const { scorer, errors: scorerErrors } = mapEvalScorer(s);
566
+ scorers.push(scorer);
567
+ errors.push(...scorerErrors);
568
+ }
569
+ }
570
+ const experiments = [];
571
+ if (Array.isArray(raw.experiments)) {
572
+ for (const exp of raw.experiments) {
573
+ const rawExp = exp;
574
+ if (!rawExp)
575
+ continue;
576
+ const expScorers = [];
577
+ if (Array.isArray(rawExp.scorers)) {
578
+ for (const s of rawExp.scorers) {
579
+ if (typeof s === "string")
580
+ expScorers.push(s);
581
+ }
582
+ }
583
+ experiments.push({
584
+ name: typeof rawExp.name === "string" ? rawExp.name : "",
585
+ dataset: typeof rawExp.dataset === "string" ? rawExp.dataset : "",
586
+ team: typeof rawExp.team === "string" ? rawExp.team : "",
587
+ scorers: expScorers,
588
+ ...(typeof rawExp.overrides === "object" && rawExp.overrides !== null && !Array.isArray(rawExp.overrides) ? { overrides: rawExp.overrides } : {}),
589
+ ...(typeof rawExp.compare === "string" ? { compare: rawExp.compare } : {}),
590
+ });
591
+ }
592
+ }
593
+ const evalConfig = {
594
+ datasets,
595
+ scorers,
596
+ experiments,
597
+ };
598
+ const validationErrors = validateEvalConfig(evalConfig);
599
+ for (const ve of validationErrors) {
600
+ errors.push({ field: `eval.${ve.field}`, message: ve.message });
601
+ }
602
+ return { eval: validationErrors.length > 0 ? undefined : evalConfig, errors };
603
+ }
604
+ function mapMcp(raw) {
605
+ const errors = [];
606
+ if (!raw || typeof raw !== "object") {
607
+ return { mcp: undefined, errors: [] };
608
+ }
609
+ const servers = [];
610
+ if (Array.isArray(raw.servers)) {
611
+ for (let i = 0; i < raw.servers.length; i++) {
612
+ const server = raw.servers[i];
613
+ if (!server)
614
+ continue;
615
+ let env;
616
+ if (server.env && typeof server.env === "object" && !Array.isArray(server.env)) {
617
+ const envObj = {};
618
+ for (const [key, value] of Object.entries(server.env)) {
619
+ if (typeof value === "string") {
620
+ envObj[key] = value;
621
+ }
622
+ }
623
+ if (Object.keys(envObj).length > 0) {
624
+ env = envObj;
625
+ }
626
+ }
627
+ servers.push({
628
+ name: typeof server.name === "string" ? server.name : "",
629
+ url: typeof server.url === "string" ? server.url : "",
630
+ ...(env && Object.keys(env).length > 0 ? { env } : {}),
631
+ ...(typeof server.reconnect === "boolean" ? { reconnect: server.reconnect } : {}),
632
+ });
633
+ }
634
+ }
635
+ const mcpConfig = { servers };
636
+ const validationErrors = validateMcpConfig(mcpConfig);
637
+ for (const ve of validationErrors) {
638
+ errors.push({ field: `mcp.${ve.field}`, message: ve.message });
639
+ }
640
+ return { mcp: validationErrors.length > 0 ? undefined : mcpConfig, errors };
641
+ }
642
+ function mapToolSelection(raw) {
643
+ const errors = [];
644
+ if (!raw || typeof raw !== "object") {
645
+ return { toolSelection: undefined, errors: [] };
646
+ }
647
+ const strategy = typeof raw.strategy === "string" ? raw.strategy : undefined;
648
+ const config = {
649
+ strategy: strategy ?? "all",
650
+ ...(typeof raw.maxTools === "number" ? { maxTools: raw.maxTools } : {}),
651
+ ...(typeof raw.threshold === "number" ? { threshold: raw.threshold } : {}),
652
+ };
653
+ const validationErrors = validateToolSelectionConfig(config);
654
+ for (const ve of validationErrors) {
655
+ errors.push({ field: `toolSelection.${ve.field}`, message: ve.message });
656
+ }
657
+ return { toolSelection: validationErrors.length > 0 ? undefined : config, errors };
658
+ }
659
+ function mapVoiceConfig(raw) {
660
+ const errors = [];
661
+ if (!raw || typeof raw !== "object") {
662
+ return { voice: undefined, errors: [] };
663
+ }
664
+ const rawStt = raw.stt;
665
+ const rawTts = raw.tts;
666
+ if (!rawStt || typeof rawStt !== "object") {
667
+ errors.push({ field: "voice.stt", message: "must be an object" });
668
+ }
669
+ if (!rawTts || typeof rawTts !== "object") {
670
+ errors.push({ field: "voice.tts", message: "must be an object" });
671
+ }
672
+ if (errors.length > 0)
673
+ return { voice: undefined, errors };
674
+ const stt = {
675
+ provider: (typeof rawStt.provider === "string" ? rawStt.provider : ""),
676
+ ...(typeof rawStt.model === "string" ? { model: rawStt.model } : {}),
677
+ ...(typeof rawStt.apiKeyEnv === "string" ? { apiKeyEnv: rawStt.apiKeyEnv } : {}),
678
+ ...(typeof rawStt.language === "string" ? { language: rawStt.language } : {}),
679
+ };
680
+ const tts = {
681
+ provider: (typeof rawTts.provider === "string" ? rawTts.provider : ""),
682
+ ...(typeof rawTts.model === "string" ? { model: rawTts.model } : {}),
683
+ ...(typeof rawTts.apiKeyEnv === "string" ? { apiKeyEnv: rawTts.apiKeyEnv } : {}),
684
+ ...(typeof rawTts.voice === "string" ? { voice: rawTts.voice } : {}),
685
+ };
686
+ const voice = { stt, tts };
687
+ const validationErrors = validateVoiceConfig(voice);
688
+ for (const ve of validationErrors) {
689
+ errors.push(ve);
690
+ }
691
+ return { voice: validationErrors.length > 0 ? undefined : voice, errors };
692
+ }
693
+ function mapSafety(raw) {
694
+ const errors = [];
695
+ if (!raw || typeof raw !== "object") {
696
+ return { safety: undefined, errors: [] };
697
+ }
698
+ let pii;
699
+ if (raw.pii !== undefined) {
700
+ const rawPii = raw.pii;
701
+ const detect = [];
702
+ if (Array.isArray(rawPii.detect)) {
703
+ for (const d of rawPii.detect) {
704
+ if (typeof d === "string")
705
+ detect.push(d);
706
+ }
707
+ }
708
+ const allowlist = [];
709
+ if (Array.isArray(rawPii.allowlist)) {
710
+ for (const a of rawPii.allowlist) {
711
+ if (typeof a === "string")
712
+ allowlist.push(a);
713
+ }
714
+ }
715
+ pii = {
716
+ detect,
717
+ action: (typeof rawPii.action === "string" ? rawPii.action : "detect"),
718
+ ...(typeof rawPii.deepScan === "boolean" ? { deepScan: rawPii.deepScan } : {}),
719
+ ...(allowlist.length > 0 ? { allowlist } : {}),
720
+ };
721
+ }
722
+ let content;
723
+ if (raw.content !== undefined) {
724
+ const rawContent = raw.content;
725
+ const categories = {};
726
+ if (rawContent.categories && typeof rawContent.categories === "object" && !Array.isArray(rawContent.categories)) {
727
+ for (const [cat, catConfig] of Object.entries(rawContent.categories)) {
728
+ if (!catConfig)
729
+ continue;
730
+ categories[cat] = {
731
+ threshold: typeof catConfig.threshold === "number" ? catConfig.threshold : 0.5,
732
+ action: (typeof catConfig.action === "string" ? catConfig.action : "block"),
733
+ };
734
+ }
735
+ }
736
+ content = {
737
+ enabled: typeof rawContent.enabled === "boolean" ? rawContent.enabled : true,
738
+ categories,
739
+ ...(typeof rawContent.deepScan === "boolean" ? { deepScan: rawContent.deepScan } : {}),
740
+ };
741
+ }
742
+ const rails = [];
743
+ if (raw.rails !== undefined) {
744
+ if (!Array.isArray(raw.rails)) {
745
+ errors.push({ field: "safety.rails", message: "must be an array" });
746
+ }
747
+ else {
748
+ for (let i = 0; i < raw.rails.length; i++) {
749
+ const rawRail = raw.rails[i];
750
+ if (!rawRail)
751
+ continue;
752
+ const railType = typeof rawRail.type === "string" ? rawRail.type : "";
753
+ switch (railType) {
754
+ case "topic": {
755
+ const block = Array.isArray(rawRail.block) ? rawRail.block.filter((b) => typeof b === "string") : [];
756
+ const escalate = Array.isArray(rawRail.escalate) ? rawRail.escalate.filter((e) => typeof e === "string") : [];
757
+ rails.push({ type: "topic", ...(block.length > 0 ? { block } : {}), ...(escalate.length > 0 ? { escalate } : {}) });
758
+ break;
759
+ }
760
+ case "competitor": {
761
+ const competitors = Array.isArray(rawRail.competitors) ? rawRail.competitors.filter((c) => typeof c === "string") : [];
762
+ rails.push({
763
+ type: "competitor",
764
+ competitors,
765
+ response: typeof rawRail.response === "string" ? rawRail.response : "",
766
+ });
767
+ break;
768
+ }
769
+ case "escalation": {
770
+ const triggers = Array.isArray(rawRail.triggers) ? rawRail.triggers.filter((t) => typeof t === "string") : [];
771
+ rails.push({ type: "escalation", triggers });
772
+ break;
773
+ }
774
+ case "compliance": {
775
+ const required = Array.isArray(rawRail.required) ? rawRail.required.filter((r) => typeof r === "string") : [];
776
+ const forbid = Array.isArray(rawRail.forbid) ? rawRail.forbid.filter((f) => typeof f === "string") : [];
777
+ rails.push({
778
+ type: "compliance",
779
+ ...(required.length > 0 ? { required } : {}),
780
+ ...(forbid.length > 0 ? { forbid } : {}),
781
+ });
782
+ break;
783
+ }
784
+ default:
785
+ errors.push({ field: `safety.rails[${i}].type`, message: `unknown rail type "${railType}"` });
786
+ }
787
+ }
788
+ }
789
+ }
790
+ const safety = {
791
+ ...(pii ? { pii } : {}),
792
+ ...(content ? { content } : {}),
793
+ ...(rails.length > 0 ? { rails } : {}),
794
+ };
795
+ const validationErrors = validateSafetyConfig(safety);
796
+ for (const ve of validationErrors) {
797
+ errors.push({ field: `safety.${ve.field}`, message: ve.message });
798
+ }
799
+ return { safety: validationErrors.length > 0 ? undefined : safety, errors };
800
+ }
801
+ // ---------------------------------------------------------------------------
802
+ // Public API
803
+ // ---------------------------------------------------------------------------
804
+ /** Parse a YAML string into a typed App composite. Throws AppLoaderError if invalid. */
805
+ export function parseAppYaml(content) {
806
+ let data;
807
+ try {
808
+ data = parse(content);
809
+ }
810
+ catch (err) {
811
+ throw new AppLoaderError([{ field: "yaml", message: String(err) }]);
812
+ }
813
+ const errors = [];
814
+ if (!data || typeof data !== "object" || Array.isArray(data)) {
815
+ throw new AppLoaderError([{ field: "root", message: "must be a YAML object" }]);
816
+ }
817
+ const raw = data;
818
+ // name
819
+ if (!raw.name || typeof raw.name !== "string") {
820
+ errors.push({ field: "name", message: "must be a non-empty string" });
821
+ }
822
+ // channels
823
+ const channels = [];
824
+ if (raw.channels !== undefined) {
825
+ if (!Array.isArray(raw.channels)) {
826
+ errors.push({ field: "channels", message: "must be an array" });
827
+ }
828
+ else {
829
+ for (const c of raw.channels) {
830
+ if (typeof c === "string")
831
+ channels.push(c);
832
+ }
833
+ }
834
+ }
835
+ // memory
836
+ let memory = { scopes: [], backend: "" };
837
+ if (!raw.memory || typeof raw.memory !== "object" || Array.isArray(raw.memory)) {
838
+ errors.push({ field: "memory", message: "must be an object" });
839
+ }
840
+ else {
841
+ const { memory: mem, errors: memErrors } = mapMemory(raw.memory, "memory");
842
+ memory = mem;
843
+ errors.push(...memErrors);
844
+ }
845
+ // teams
846
+ const teams = {};
847
+ if (!raw.teams || typeof raw.teams !== "object" || Array.isArray(raw.teams)) {
848
+ errors.push({ field: "teams", message: "must be an object" });
849
+ }
850
+ else {
851
+ for (const [teamName, teamRaw] of Object.entries(raw.teams)) {
852
+ const { team, errors: teamErrors } = mapTeam(teamName, teamRaw ?? {}, `teams.${teamName}`);
853
+ teams[teamName] = team;
854
+ errors.push(...teamErrors);
855
+ }
856
+ }
857
+ // router
858
+ let router = { rules: [], fallback: "" };
859
+ if (!raw.router || typeof raw.router !== "object" || Array.isArray(raw.router)) {
860
+ errors.push({ field: "router", message: "must be an object" });
861
+ }
862
+ else {
863
+ const { router: rt, errors: routerErrors } = mapRouter(raw.router, "router");
864
+ router = rt;
865
+ errors.push(...routerErrors);
866
+ }
867
+ // triggers (optional)
868
+ const triggers = [];
869
+ if (raw.triggers !== undefined) {
870
+ if (!Array.isArray(raw.triggers)) {
871
+ errors.push({ field: "triggers", message: "must be an array" });
872
+ }
873
+ else {
874
+ for (let i = 0; i < raw.triggers.length; i++) {
875
+ const { trigger, errors: triggerErrors } = mapTrigger(raw.triggers[i], `triggers[${i}]`);
876
+ triggers.push(trigger);
877
+ errors.push(...triggerErrors);
878
+ }
879
+ }
880
+ }
881
+ // knowledge (optional)
882
+ let knowledge;
883
+ if (raw.knowledge !== undefined) {
884
+ const { knowledge: knowledgeConfig, errors: knowledgeErrors } = mapKnowledge(raw.knowledge);
885
+ knowledge = knowledgeConfig;
886
+ errors.push(...knowledgeErrors);
887
+ }
888
+ // eval (optional)
889
+ let evalConfig;
890
+ if (raw.eval !== undefined) {
891
+ const { eval: parsedEval, errors: evalErrors } = mapEval(raw.eval);
892
+ evalConfig = parsedEval;
893
+ errors.push(...evalErrors);
894
+ }
895
+ // mcp (optional)
896
+ let mcpConfig;
897
+ if (raw.mcp !== undefined) {
898
+ const { mcp, errors: mcpErrors } = mapMcp(raw.mcp);
899
+ mcpConfig = mcp;
900
+ errors.push(...mcpErrors);
901
+ }
902
+ // toolSelection (optional)
903
+ let toolSelectionConfig;
904
+ if (raw.toolSelection !== undefined) {
905
+ const { toolSelection, errors: tsErrors } = mapToolSelection(raw.toolSelection);
906
+ toolSelectionConfig = toolSelection;
907
+ errors.push(...tsErrors);
908
+ }
909
+ // voice (optional)
910
+ let voiceConfig;
911
+ if (raw.voice !== undefined) {
912
+ const { voice, errors: voiceErrors } = mapVoiceConfig(raw.voice);
913
+ voiceConfig = voice;
914
+ errors.push(...voiceErrors);
915
+ }
916
+ // safety (optional)
917
+ let safetyConfig;
918
+ if (raw.safety !== undefined) {
919
+ const { safety, errors: safetyErrors } = mapSafety(raw.safety);
920
+ safetyConfig = safety;
921
+ errors.push(...safetyErrors);
922
+ }
923
+ if (errors.length > 0)
924
+ throw new AppLoaderError(errors);
925
+ return {
926
+ name: raw.name,
927
+ teams,
928
+ router,
929
+ memory,
930
+ channels,
931
+ ...(triggers.length > 0 ? { triggers } : {}),
932
+ ...(knowledge ? { knowledge } : {}),
933
+ ...(evalConfig ? { eval: evalConfig } : {}),
934
+ ...(mcpConfig ? { mcp: mcpConfig } : {}),
935
+ ...(toolSelectionConfig ? { toolSelection: toolSelectionConfig } : {}),
936
+ ...(voiceConfig ? { voice: voiceConfig } : {}),
937
+ ...(safetyConfig ? { safety: safetyConfig } : {}),
938
+ };
939
+ }
940
+ /** Validate the dependency graph of an App. Returns null if valid, AppLoaderError if not. */
941
+ export function validateAppGraph(app) {
942
+ const appErrors = validateApp(app);
943
+ if (appErrors.length === 0)
944
+ return null;
945
+ return new AppLoaderError(appErrors);
946
+ }
947
+ //# sourceMappingURL=app-loader.js.map