beddel 0.2.2 → 0.3.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 (357) hide show
  1. package/CHANGELOG.md +50 -0
  2. package/README.md +117 -14
  3. package/dist/agents/chat/chat.handler.d.ts +12 -0
  4. package/dist/agents/chat/chat.handler.d.ts.map +1 -0
  5. package/dist/agents/chat/chat.handler.js +145 -0
  6. package/dist/agents/chat/chat.handler.js.map +1 -0
  7. package/dist/agents/chat/chat.schema.d.ts +38 -0
  8. package/dist/agents/chat/chat.schema.d.ts.map +1 -0
  9. package/dist/agents/chat/chat.schema.js +31 -0
  10. package/dist/agents/chat/chat.schema.js.map +1 -0
  11. package/dist/agents/chat/chat.types.d.ts +42 -0
  12. package/dist/agents/chat/chat.types.d.ts.map +1 -0
  13. package/dist/agents/chat/chat.types.js +6 -0
  14. package/dist/agents/chat/chat.types.js.map +1 -0
  15. package/dist/agents/chat/chat.yaml +148 -0
  16. package/dist/agents/chat/index.d.ts +16 -0
  17. package/dist/agents/chat/index.d.ts.map +1 -0
  18. package/dist/agents/chat/index.js +21 -0
  19. package/dist/agents/chat/index.js.map +1 -0
  20. package/dist/agents/chromadb/chromadb.handler.d.ts +12 -0
  21. package/dist/agents/chromadb/chromadb.handler.d.ts.map +1 -0
  22. package/dist/agents/chromadb/chromadb.handler.js +139 -0
  23. package/dist/agents/chromadb/chromadb.handler.js.map +1 -0
  24. package/dist/agents/chromadb/chromadb.schema.d.ts +36 -0
  25. package/dist/agents/chromadb/chromadb.schema.d.ts.map +1 -0
  26. package/dist/agents/chromadb/chromadb.schema.js +33 -0
  27. package/dist/agents/chromadb/chromadb.schema.js.map +1 -0
  28. package/dist/agents/chromadb/chromadb.types.d.ts +49 -0
  29. package/dist/agents/chromadb/chromadb.types.d.ts.map +1 -0
  30. package/dist/agents/chromadb/chromadb.types.js +6 -0
  31. package/dist/agents/chromadb/chromadb.types.js.map +1 -0
  32. package/dist/agents/chromadb/chromadb.yaml +128 -0
  33. package/dist/agents/chromadb/index.d.ts +15 -0
  34. package/dist/agents/chromadb/index.d.ts.map +1 -0
  35. package/dist/agents/chromadb/index.js +20 -0
  36. package/dist/agents/chromadb/index.js.map +1 -0
  37. package/dist/agents/gemini-vectorize/gemini-vectorize.handler.d.ts +8 -0
  38. package/dist/agents/gemini-vectorize/gemini-vectorize.handler.d.ts.map +1 -0
  39. package/dist/agents/gemini-vectorize/gemini-vectorize.handler.js +61 -0
  40. package/dist/agents/gemini-vectorize/gemini-vectorize.handler.js.map +1 -0
  41. package/dist/agents/gemini-vectorize/gemini-vectorize.schema.d.ts +22 -0
  42. package/dist/agents/gemini-vectorize/gemini-vectorize.schema.d.ts.map +1 -0
  43. package/dist/agents/gemini-vectorize/gemini-vectorize.schema.js +20 -0
  44. package/dist/agents/gemini-vectorize/gemini-vectorize.schema.js.map +1 -0
  45. package/dist/agents/gemini-vectorize/gemini-vectorize.types.d.ts +32 -0
  46. package/dist/agents/gemini-vectorize/gemini-vectorize.types.d.ts.map +1 -0
  47. package/dist/agents/gemini-vectorize/gemini-vectorize.types.js +6 -0
  48. package/dist/agents/gemini-vectorize/gemini-vectorize.types.js.map +1 -0
  49. package/dist/agents/gemini-vectorize/gemini-vectorize.yaml +84 -0
  50. package/dist/agents/gemini-vectorize/index.d.ts +15 -0
  51. package/dist/agents/gemini-vectorize/index.d.ts.map +1 -0
  52. package/dist/agents/gemini-vectorize/index.js +20 -0
  53. package/dist/agents/gemini-vectorize/index.js.map +1 -0
  54. package/dist/agents/gitmcp/gitmcp.handler.d.ts +12 -0
  55. package/dist/agents/gitmcp/gitmcp.handler.d.ts.map +1 -0
  56. package/dist/agents/gitmcp/gitmcp.handler.js +95 -0
  57. package/dist/agents/gitmcp/gitmcp.handler.js.map +1 -0
  58. package/dist/agents/gitmcp/gitmcp.schema.d.ts +17 -0
  59. package/dist/agents/gitmcp/gitmcp.schema.d.ts.map +1 -0
  60. package/dist/agents/gitmcp/gitmcp.schema.js +18 -0
  61. package/dist/agents/gitmcp/gitmcp.schema.js.map +1 -0
  62. package/dist/agents/gitmcp/gitmcp.types.d.ts +31 -0
  63. package/dist/agents/gitmcp/gitmcp.types.d.ts.map +1 -0
  64. package/dist/agents/gitmcp/gitmcp.types.js +6 -0
  65. package/dist/agents/gitmcp/gitmcp.types.js.map +1 -0
  66. package/dist/agents/gitmcp/gitmcp.yaml +71 -0
  67. package/dist/agents/gitmcp/index.d.ts +16 -0
  68. package/dist/agents/gitmcp/index.d.ts.map +1 -0
  69. package/dist/agents/gitmcp/index.js +21 -0
  70. package/dist/agents/gitmcp/index.js.map +1 -0
  71. package/dist/agents/image/image.handler.d.ts +8 -0
  72. package/dist/agents/image/image.handler.d.ts.map +1 -0
  73. package/dist/agents/image/image.handler.js +69 -0
  74. package/dist/agents/image/image.handler.js.map +1 -0
  75. package/dist/agents/image/image.schema.d.ts +29 -0
  76. package/dist/agents/image/image.schema.d.ts.map +1 -0
  77. package/dist/agents/image/image.schema.js +26 -0
  78. package/dist/agents/image/image.schema.js.map +1 -0
  79. package/dist/agents/image/image.types.d.ts +43 -0
  80. package/dist/agents/image/image.types.d.ts.map +1 -0
  81. package/dist/agents/image/image.types.js +6 -0
  82. package/dist/agents/image/image.types.js.map +1 -0
  83. package/{src/agents/image-agent.yaml → dist/agents/image/image.yaml} +21 -21
  84. package/dist/agents/image/index.d.ts +14 -0
  85. package/dist/agents/image/index.d.ts.map +1 -0
  86. package/dist/agents/image/index.js +19 -0
  87. package/dist/agents/image/index.js.map +1 -0
  88. package/dist/agents/index.d.ts +104 -0
  89. package/dist/agents/index.d.ts.map +1 -0
  90. package/dist/agents/index.js +82 -0
  91. package/dist/agents/index.js.map +1 -0
  92. package/dist/agents/joker/index.d.ts +14 -0
  93. package/dist/agents/joker/index.d.ts.map +1 -0
  94. package/dist/agents/joker/index.js +19 -0
  95. package/dist/agents/joker/index.js.map +1 -0
  96. package/dist/agents/joker/joker.handler.d.ts +8 -0
  97. package/dist/agents/joker/joker.handler.d.ts.map +1 -0
  98. package/dist/agents/joker/joker.handler.js +44 -0
  99. package/dist/agents/joker/joker.handler.js.map +1 -0
  100. package/dist/agents/joker/joker.schema.d.ts +12 -0
  101. package/dist/agents/joker/joker.schema.d.ts.map +1 -0
  102. package/dist/agents/joker/joker.schema.js +13 -0
  103. package/dist/agents/joker/joker.schema.js.map +1 -0
  104. package/dist/agents/joker/joker.types.d.ts +36 -0
  105. package/dist/agents/joker/joker.types.d.ts.map +1 -0
  106. package/dist/agents/joker/joker.types.js +6 -0
  107. package/dist/agents/joker/joker.types.js.map +1 -0
  108. package/{src/agents/joker-agent.yaml → dist/agents/joker/joker.yaml} +4 -4
  109. package/dist/agents/llm/index.d.ts +15 -0
  110. package/dist/agents/llm/index.d.ts.map +1 -0
  111. package/dist/agents/llm/index.js +20 -0
  112. package/dist/agents/llm/index.js.map +1 -0
  113. package/dist/agents/llm/llm.handler.d.ts +8 -0
  114. package/dist/agents/llm/llm.handler.d.ts.map +1 -0
  115. package/dist/agents/llm/llm.handler.js +64 -0
  116. package/dist/agents/llm/llm.handler.js.map +1 -0
  117. package/dist/agents/llm/llm.schema.d.ts +26 -0
  118. package/dist/agents/llm/llm.schema.d.ts.map +1 -0
  119. package/dist/agents/llm/llm.schema.js +23 -0
  120. package/dist/agents/llm/llm.schema.js.map +1 -0
  121. package/dist/agents/llm/llm.types.d.ts +34 -0
  122. package/dist/agents/llm/llm.types.d.ts.map +1 -0
  123. package/dist/agents/llm/llm.types.js +7 -0
  124. package/dist/agents/llm/llm.types.js.map +1 -0
  125. package/dist/agents/llm/llm.yaml +87 -0
  126. package/dist/agents/mcp-tool/index.d.ts +14 -0
  127. package/dist/agents/mcp-tool/index.d.ts.map +1 -0
  128. package/dist/agents/mcp-tool/index.js +19 -0
  129. package/dist/agents/mcp-tool/index.js.map +1 -0
  130. package/dist/agents/mcp-tool/mcp-tool.handler.d.ts +12 -0
  131. package/dist/agents/mcp-tool/mcp-tool.handler.d.ts.map +1 -0
  132. package/dist/agents/mcp-tool/mcp-tool.handler.js +116 -0
  133. package/dist/agents/mcp-tool/mcp-tool.handler.js.map +1 -0
  134. package/dist/agents/mcp-tool/mcp-tool.schema.d.ts +19 -0
  135. package/dist/agents/mcp-tool/mcp-tool.schema.d.ts.map +1 -0
  136. package/dist/agents/mcp-tool/mcp-tool.schema.js +20 -0
  137. package/dist/agents/mcp-tool/mcp-tool.schema.js.map +1 -0
  138. package/dist/agents/mcp-tool/mcp-tool.types.d.ts +31 -0
  139. package/dist/agents/mcp-tool/mcp-tool.types.d.ts.map +1 -0
  140. package/dist/agents/mcp-tool/mcp-tool.types.js +6 -0
  141. package/dist/agents/mcp-tool/mcp-tool.types.js.map +1 -0
  142. package/dist/agents/mcp-tool/mcp-tool.yaml +71 -0
  143. package/dist/agents/rag/index.d.ts +15 -0
  144. package/dist/agents/rag/index.d.ts.map +1 -0
  145. package/dist/agents/rag/index.js +20 -0
  146. package/dist/agents/rag/index.js.map +1 -0
  147. package/dist/agents/rag/rag.handler.d.ts +9 -0
  148. package/dist/agents/rag/rag.handler.d.ts.map +1 -0
  149. package/dist/agents/rag/rag.handler.js +78 -0
  150. package/dist/agents/rag/rag.handler.js.map +1 -0
  151. package/dist/agents/rag/rag.schema.d.ts +27 -0
  152. package/dist/agents/rag/rag.schema.d.ts.map +1 -0
  153. package/dist/agents/rag/rag.schema.js +24 -0
  154. package/dist/agents/rag/rag.schema.js.map +1 -0
  155. package/dist/agents/rag/rag.types.d.ts +42 -0
  156. package/dist/agents/rag/rag.types.d.ts.map +1 -0
  157. package/dist/agents/rag/rag.types.js +7 -0
  158. package/dist/agents/rag/rag.types.js.map +1 -0
  159. package/dist/agents/rag/rag.yaml +89 -0
  160. package/dist/agents/{agentRegistry.d.ts → registry/agentRegistry.d.ts} +30 -1
  161. package/dist/agents/registry/agentRegistry.d.ts.map +1 -0
  162. package/dist/agents/{agentRegistry.js → registry/agentRegistry.js} +187 -5
  163. package/dist/agents/registry/agentRegistry.js.map +1 -0
  164. package/dist/agents/registry/index.d.ts +6 -0
  165. package/dist/agents/registry/index.d.ts.map +1 -0
  166. package/dist/agents/registry/index.js +10 -0
  167. package/dist/agents/registry/index.js.map +1 -0
  168. package/dist/agents/translator/index.d.ts +14 -0
  169. package/dist/agents/translator/index.d.ts.map +1 -0
  170. package/dist/agents/translator/index.js +19 -0
  171. package/dist/agents/translator/index.js.map +1 -0
  172. package/dist/agents/translator/translator.handler.d.ts +8 -0
  173. package/dist/agents/translator/translator.handler.d.ts.map +1 -0
  174. package/dist/agents/translator/translator.handler.js +81 -0
  175. package/dist/agents/translator/translator.handler.js.map +1 -0
  176. package/dist/agents/translator/translator.schema.d.ts +27 -0
  177. package/dist/agents/translator/translator.schema.d.ts.map +1 -0
  178. package/dist/agents/translator/translator.schema.js +28 -0
  179. package/dist/agents/translator/translator.schema.js.map +1 -0
  180. package/dist/agents/translator/translator.types.d.ts +41 -0
  181. package/dist/agents/translator/translator.types.d.ts.map +1 -0
  182. package/dist/agents/translator/translator.types.js +6 -0
  183. package/dist/agents/translator/translator.types.js.map +1 -0
  184. package/{src/agents/translator-agent.yaml → dist/agents/translator/translator.yaml} +27 -27
  185. package/dist/client/index.d.ts +89 -0
  186. package/dist/client/index.d.ts.map +1 -0
  187. package/dist/client/index.js +93 -0
  188. package/dist/client/index.js.map +1 -0
  189. package/dist/client/types.d.ts +17 -0
  190. package/dist/client/types.d.ts.map +1 -0
  191. package/dist/client/types.js +7 -0
  192. package/dist/client/types.js.map +1 -0
  193. package/dist/firebase/tenantManager.d.ts +34 -2
  194. package/dist/firebase/tenantManager.d.ts.map +1 -1
  195. package/dist/firebase/tenantManager.js +67 -1
  196. package/dist/firebase/tenantManager.js.map +1 -1
  197. package/dist/index.d.ts +10 -4
  198. package/dist/index.d.ts.map +1 -1
  199. package/dist/index.js +24 -7
  200. package/dist/index.js.map +1 -1
  201. package/dist/runtime/declarativeAgentRuntime.d.ts +17 -52
  202. package/dist/runtime/declarativeAgentRuntime.d.ts.map +1 -1
  203. package/dist/runtime/declarativeAgentRuntime.js +259 -361
  204. package/dist/runtime/declarativeAgentRuntime.js.map +1 -1
  205. package/dist/runtime/index.d.ts +14 -0
  206. package/dist/runtime/index.d.ts.map +1 -0
  207. package/dist/runtime/index.js +38 -0
  208. package/dist/runtime/index.js.map +1 -0
  209. package/dist/runtime/llmProviderFactory.d.ts +47 -0
  210. package/dist/runtime/llmProviderFactory.d.ts.map +1 -0
  211. package/dist/runtime/llmProviderFactory.js +119 -0
  212. package/dist/runtime/llmProviderFactory.js.map +1 -0
  213. package/dist/runtime/workflowExecutor.d.ts +31 -0
  214. package/dist/runtime/workflowExecutor.d.ts.map +1 -0
  215. package/dist/runtime/workflowExecutor.js +80 -0
  216. package/dist/runtime/workflowExecutor.js.map +1 -0
  217. package/dist/server/api/graphql.js +3 -3
  218. package/dist/server/api/graphql.js.map +1 -1
  219. package/dist/server/index.d.ts +2 -2
  220. package/dist/server/index.d.ts.map +1 -1
  221. package/dist/server/index.js +2 -2
  222. package/dist/server/index.js.map +1 -1
  223. package/dist/shared/index.d.ts +7 -0
  224. package/dist/shared/index.d.ts.map +1 -0
  225. package/dist/shared/index.js +23 -0
  226. package/dist/shared/index.js.map +1 -0
  227. package/dist/shared/types/agent.types.d.ts +63 -0
  228. package/dist/shared/types/agent.types.d.ts.map +1 -0
  229. package/dist/shared/types/agent.types.js +18 -0
  230. package/dist/shared/types/agent.types.js.map +1 -0
  231. package/dist/shared/types/execution.types.d.ts +42 -0
  232. package/dist/shared/types/execution.types.d.ts.map +1 -0
  233. package/dist/shared/types/execution.types.js +7 -0
  234. package/dist/shared/types/execution.types.js.map +1 -0
  235. package/dist/shared/types/index.d.ts +7 -0
  236. package/dist/shared/types/index.d.ts.map +1 -0
  237. package/dist/shared/types/index.js +23 -0
  238. package/dist/shared/types/index.js.map +1 -0
  239. package/dist/shared/types/schema.types.d.ts +52 -0
  240. package/dist/shared/types/schema.types.d.ts.map +1 -0
  241. package/dist/shared/types/schema.types.js +7 -0
  242. package/dist/shared/types/schema.types.js.map +1 -0
  243. package/dist/shared/utils/index.d.ts +5 -0
  244. package/dist/shared/utils/index.d.ts.map +1 -0
  245. package/dist/shared/utils/index.js +21 -0
  246. package/dist/shared/utils/index.js.map +1 -0
  247. package/dist/shared/utils/validation.d.ts +42 -0
  248. package/dist/shared/utils/validation.d.ts.map +1 -0
  249. package/dist/shared/utils/validation.js +93 -0
  250. package/dist/shared/utils/validation.js.map +1 -0
  251. package/dist/tenant/TenantManager.d.ts +152 -0
  252. package/dist/tenant/TenantManager.d.ts.map +1 -0
  253. package/dist/tenant/TenantManager.js +392 -0
  254. package/dist/tenant/TenantManager.js.map +1 -0
  255. package/dist/tenant/index.d.ts +47 -0
  256. package/dist/tenant/index.d.ts.map +1 -0
  257. package/dist/tenant/index.js +74 -0
  258. package/dist/tenant/index.js.map +1 -0
  259. package/dist/tenant/interfaces.d.ts +170 -0
  260. package/dist/tenant/interfaces.d.ts.map +1 -0
  261. package/dist/tenant/interfaces.js +67 -0
  262. package/dist/tenant/interfaces.js.map +1 -0
  263. package/dist/tenant/providerFactory.d.ts +43 -0
  264. package/dist/tenant/providerFactory.d.ts.map +1 -0
  265. package/dist/tenant/providerFactory.js +70 -0
  266. package/dist/tenant/providerFactory.js.map +1 -0
  267. package/dist/tenant/providerRegistry.d.ts +47 -0
  268. package/dist/tenant/providerRegistry.d.ts.map +1 -0
  269. package/dist/tenant/providerRegistry.js +79 -0
  270. package/dist/tenant/providerRegistry.js.map +1 -0
  271. package/dist/tenant/providers/FirebaseTenantProvider.d.ts +41 -0
  272. package/dist/tenant/providers/FirebaseTenantProvider.d.ts.map +1 -0
  273. package/dist/tenant/providers/FirebaseTenantProvider.js +290 -0
  274. package/dist/tenant/providers/FirebaseTenantProvider.js.map +1 -0
  275. package/dist/tenant/providers/InMemoryTenantProvider.d.ts +18 -0
  276. package/dist/tenant/providers/InMemoryTenantProvider.d.ts.map +1 -0
  277. package/dist/tenant/providers/InMemoryTenantProvider.js +137 -0
  278. package/dist/tenant/providers/InMemoryTenantProvider.js.map +1 -0
  279. package/package.json +46 -10
  280. package/src/agents/chat/chat.handler.ts +211 -0
  281. package/src/agents/chat/chat.schema.ts +33 -0
  282. package/src/agents/chat/chat.types.ts +46 -0
  283. package/src/agents/chat/chat.yaml +148 -0
  284. package/src/agents/chat/index.ts +21 -0
  285. package/src/agents/chromadb/chromadb.handler.ts +130 -0
  286. package/src/agents/chromadb/chromadb.schema.ts +35 -0
  287. package/src/agents/chromadb/chromadb.types.ts +52 -0
  288. package/src/agents/chromadb/chromadb.yaml +128 -0
  289. package/src/agents/chromadb/index.ts +20 -0
  290. package/src/agents/gemini-vectorize/gemini-vectorize.handler.ts +75 -0
  291. package/src/agents/gemini-vectorize/gemini-vectorize.schema.ts +22 -0
  292. package/src/agents/gemini-vectorize/gemini-vectorize.types.ts +34 -0
  293. package/src/agents/gemini-vectorize/gemini-vectorize.yaml +84 -0
  294. package/src/agents/gemini-vectorize/index.ts +20 -0
  295. package/src/agents/gitmcp/gitmcp.handler.ts +122 -0
  296. package/src/agents/gitmcp/gitmcp.schema.ts +20 -0
  297. package/src/agents/gitmcp/gitmcp.types.ts +33 -0
  298. package/src/agents/gitmcp/gitmcp.yaml +71 -0
  299. package/src/agents/gitmcp/index.ts +21 -0
  300. package/src/agents/image/image.handler.ts +86 -0
  301. package/src/agents/image/image.schema.ts +28 -0
  302. package/src/agents/image/image.types.ts +46 -0
  303. package/src/agents/image/image.yaml +86 -0
  304. package/src/agents/image/index.ts +19 -0
  305. package/src/agents/index.ts +63 -0
  306. package/src/agents/joker/index.ts +19 -0
  307. package/src/agents/joker/joker.handler.ts +55 -0
  308. package/src/agents/joker/joker.schema.ts +15 -0
  309. package/src/agents/joker/joker.types.ts +38 -0
  310. package/src/agents/joker/joker.yaml +47 -0
  311. package/src/agents/llm/index.ts +20 -0
  312. package/src/agents/llm/llm.handler.ts +82 -0
  313. package/src/agents/llm/llm.schema.ts +25 -0
  314. package/src/agents/llm/llm.types.ts +37 -0
  315. package/src/agents/llm/llm.yaml +87 -0
  316. package/src/agents/mcp-tool/index.ts +19 -0
  317. package/src/agents/mcp-tool/mcp-tool.handler.ts +112 -0
  318. package/src/agents/mcp-tool/mcp-tool.schema.ts +22 -0
  319. package/src/agents/mcp-tool/mcp-tool.types.ts +33 -0
  320. package/src/agents/mcp-tool/mcp-tool.yaml +71 -0
  321. package/src/agents/rag/index.ts +20 -0
  322. package/src/agents/rag/rag.handler.ts +95 -0
  323. package/src/agents/rag/rag.schema.ts +26 -0
  324. package/src/agents/rag/rag.types.ts +45 -0
  325. package/src/agents/rag/rag.yaml +89 -0
  326. package/src/agents/{agentRegistry.ts → registry/agentRegistry.ts} +195 -6
  327. package/src/agents/registry/index.ts +6 -0
  328. package/src/agents/translator/index.ts +19 -0
  329. package/src/agents/translator/translator.handler.ts +97 -0
  330. package/src/agents/translator/translator.schema.ts +30 -0
  331. package/src/agents/translator/translator.types.ts +43 -0
  332. package/src/agents/translator/translator.yaml +80 -0
  333. package/src/client/index.ts +53 -0
  334. package/src/client/types.ts +38 -0
  335. package/src/index.ts +56 -5
  336. package/src/runtime/declarativeAgentRuntime.ts +378 -495
  337. package/src/runtime/index.ts +36 -0
  338. package/src/runtime/llmProviderFactory.ts +145 -0
  339. package/src/runtime/workflowExecutor.ts +107 -0
  340. package/src/server/api/graphql.ts +1 -1
  341. package/src/server/index.ts +2 -2
  342. package/src/shared/index.ts +7 -0
  343. package/src/shared/types/agent.types.ts +100 -0
  344. package/src/shared/types/execution.types.ts +45 -0
  345. package/src/shared/types/index.ts +7 -0
  346. package/src/shared/types/schema.types.ts +55 -0
  347. package/src/shared/utils/index.ts +5 -0
  348. package/src/shared/utils/validation.ts +100 -0
  349. package/src/tenant/TenantManager.ts +488 -0
  350. package/src/tenant/index.ts +101 -0
  351. package/src/tenant/interfaces.ts +231 -0
  352. package/src/tenant/providerFactory.ts +75 -0
  353. package/src/tenant/providerRegistry.ts +86 -0
  354. package/src/tenant/providers/InMemoryTenantProvider.ts +168 -0
  355. package/dist/agents/agentRegistry.d.ts.map +0 -1
  356. package/dist/agents/agentRegistry.js.map +0 -1
  357. package/src/firebase/tenantManager.ts +0 -443
@@ -2,6 +2,8 @@
2
2
  /**
3
3
  * Declarative Agent Runtime - YAML Interpreter for Beddel Declarative Protocol
4
4
  * Safely interprets declarative YAML agent definitions without dynamic code execution
5
+ *
6
+ * Phase 3 Refactored: Delegates to individual agent handlers via workflowExecutor
5
7
  */
6
8
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
7
9
  if (k2 === undefined) k2 = k;
@@ -38,22 +40,21 @@ var __importStar = (this && this.__importStar) || (function () {
38
40
  })();
39
41
  Object.defineProperty(exports, "__esModule", { value: true });
40
42
  exports.declarativeInterpreter = exports.DeclarativeAgentInterpreter = void 0;
43
+ require("server-only");
41
44
  const yaml = __importStar(require("js-yaml"));
42
- const ai_1 = require("ai");
43
- const google_1 = require("@ai-sdk/google");
44
- const agentRegistry_1 = require("../agents/agentRegistry");
45
+ const registry_1 = require("../agents/registry");
45
46
  const schemaCompiler_1 = require("./schemaCompiler");
47
+ // Import handlers from workflowExecutor
48
+ const workflowExecutor_1 = require("./workflowExecutor");
46
49
  /**
47
50
  * Safe declarative YAML interpreter - no dynamic code execution
51
+ * Delegates execution to individual agent handlers
48
52
  */
49
53
  class DeclarativeAgentInterpreter {
50
54
  constructor() {
51
- this.MAX_VARIABLE_SIZE = 1024; // 1KB max variable size
52
- this.MAX_WORKFLOW_STEPS = 100; // Prevent infinite loops
53
- this.MAX_OUTPUT_SIZE = 5 * 1024 * 1024; // 5MB max output to accommodate image payloads
54
- this.GEMINI_MODEL = "models/gemini-2.5-flash";
55
- this.GEMINI_IMAGE_MODEL = "imagen-4.0-fast-generate-001";
56
- this.SUPPORTED_TRANSLATION_LANGUAGES = ["pt", "en", "es", "fr"];
55
+ this.MAX_VARIABLE_SIZE = 1024;
56
+ this.MAX_WORKFLOW_STEPS = 100;
57
+ this.MAX_OUTPUT_SIZE = 5 * 1024 * 1024;
57
58
  this.schemaCompiler = new schemaCompiler_1.DeclarativeSchemaCompiler();
58
59
  }
59
60
  /**
@@ -62,45 +63,35 @@ class DeclarativeAgentInterpreter {
62
63
  async interpret(options) {
63
64
  const startTime = Date.now();
64
65
  try {
65
- // Parse and validate YAML
66
66
  const agent = this.parseYaml(options.yamlContent);
67
67
  this.validateAgentDefinition(agent);
68
- // Compile schemas and validate input up front
69
68
  const schemas = this.buildSchemaSet(agent);
70
- const validatedInput = this.validateAgainstSchema(options.input, schemas.input, "input", options.context);
69
+ const validatedInput = this.validateAgainstSchema(options.input, schemas.input, 'input', options.context);
71
70
  const executionOptions = {
72
71
  ...options,
73
72
  input: validatedInput,
74
73
  };
75
- // Execute declarative logic
76
74
  const result = await this.executeWorkflow(agent, executionOptions);
77
- // Validate output
78
- const validatedOutput = this.validateAgainstSchema(result, schemas.output, "output", options.context);
75
+ const validatedOutput = this.validateAgainstSchema(result, schemas.output, 'output', options.context);
79
76
  this.enforceOutputSize(validatedOutput);
80
77
  const executionTime = Date.now() - startTime;
81
78
  options.context.log(`Declarative agent executed in ${executionTime}ms`);
82
79
  return validatedOutput;
83
80
  }
84
81
  catch (error) {
85
- const executionTime = Date.now() - startTime;
86
82
  options.context.log(`Declarative agent execution failed: ${error}`);
87
- options.context.setError(error instanceof Error
88
- ? error.message
89
- : "Unknown declarative agent error");
83
+ options.context.setError(error instanceof Error ? error.message : 'Unknown declarative agent error');
90
84
  throw error;
91
85
  }
92
86
  }
93
- /**
94
- * Parse and validate YAML content
95
- */
96
87
  parseYaml(yamlContent) {
97
88
  try {
98
89
  const parsed = yaml.load(yamlContent);
99
- if (!parsed || typeof parsed !== "object") {
100
- throw new Error("Invalid YAML: expected object");
90
+ if (!parsed || typeof parsed !== 'object') {
91
+ throw new Error('Invalid YAML: expected object');
101
92
  }
102
93
  if (!parsed.agent || !parsed.logic || !parsed.schema) {
103
- throw new Error("Invalid agent definition: missing required sections");
94
+ throw new Error('Invalid agent definition: missing required sections');
104
95
  }
105
96
  return parsed;
106
97
  }
@@ -108,22 +99,15 @@ class DeclarativeAgentInterpreter {
108
99
  throw new Error(`YAML parsing failed: ${error}`);
109
100
  }
110
101
  }
111
- /**
112
- * Validate agent definition structure
113
- */
114
102
  validateAgentDefinition(agent) {
115
- // Validate protocol version
116
- if (agent.agent.protocol !== "beddel-declarative-protocol/v2.0") {
103
+ if (agent.agent.protocol !== 'beddel-declarative-protocol/v2.0') {
117
104
  throw new Error(`Unsupported protocol: ${agent.agent.protocol}`);
118
105
  }
119
- // Validate schema
120
106
  if (!agent.schema.input || !agent.schema.output) {
121
- throw new Error("Invalid schema: missing input or output definition");
107
+ throw new Error('Invalid schema: missing input or output definition');
122
108
  }
123
- // Validate workflow
124
- if (!Array.isArray(agent.logic.workflow) ||
125
- agent.logic.workflow.length === 0) {
126
- throw new Error("Invalid workflow: must be non-empty array");
109
+ if (!Array.isArray(agent.logic.workflow) || agent.logic.workflow.length === 0) {
110
+ throw new Error('Invalid workflow: must be non-empty array');
127
111
  }
128
112
  if (agent.logic.workflow.length > this.MAX_WORKFLOW_STEPS) {
129
113
  throw new Error(`Workflow too complex: max ${this.MAX_WORKFLOW_STEPS} steps allowed`);
@@ -131,8 +115,8 @@ class DeclarativeAgentInterpreter {
131
115
  }
132
116
  buildSchemaSet(agent) {
133
117
  return {
134
- input: this.schemaCompiler.compile(agent.schema.input, "schema.input"),
135
- output: this.schemaCompiler.compile(agent.schema.output, "schema.output"),
118
+ input: this.schemaCompiler.compile(agent.schema.input, 'schema.input'),
119
+ output: this.schemaCompiler.compile(agent.schema.output, 'schema.output'),
136
120
  };
137
121
  }
138
122
  validateAgainstSchema(data, schema, phase, context) {
@@ -140,9 +124,9 @@ class DeclarativeAgentInterpreter {
140
124
  if (!validationResult.success) {
141
125
  const issues = validationResult.error.issues;
142
126
  const issueSummary = issues
143
- .map((issue) => `${issue.path.join(".") || "root"}: ${issue.message}`)
144
- .join("; ");
145
- const label = phase === "input" ? "Input" : "Output";
127
+ .map((issue) => `${issue.path.join('.') || 'root'}: ${issue.message}`)
128
+ .join('; ');
129
+ const label = phase === 'input' ? 'Input' : 'Output';
146
130
  const message = `${label} validation failed: ${issueSummary}`;
147
131
  context.setError(message);
148
132
  throw new schemaCompiler_1.DeclarativeSchemaValidationError(message, phase, issues);
@@ -155,13 +139,9 @@ class DeclarativeAgentInterpreter {
155
139
  throw new Error(`Output size exceeds maximum allowed: ${outputSize} > ${this.MAX_OUTPUT_SIZE}`);
156
140
  }
157
141
  }
158
- /**
159
- * Execute declarative workflow
160
- */
161
142
  async executeWorkflow(agent, options) {
162
143
  const variables = new Map();
163
144
  let output = undefined;
164
- // Initialize variables
165
145
  if (agent.logic.variables) {
166
146
  for (const variable of agent.logic.variables) {
167
147
  this.validateVariable(variable);
@@ -169,51 +149,62 @@ class DeclarativeAgentInterpreter {
169
149
  variables.set(variable.name, value);
170
150
  }
171
151
  }
172
- // Execute workflow steps
173
152
  for (const step of agent.logic.workflow) {
174
153
  output = await this.executeWorkflowStep(step, variables, options);
175
154
  }
176
155
  return output;
177
156
  }
178
- /**
179
- * Execute single workflow step
180
- */
181
157
  async executeWorkflowStep(step, variables, options) {
182
158
  options.context.log(`Executing workflow step: ${step.name} (${step.type})`);
183
159
  switch (step.type) {
184
- case "output-generator":
160
+ case 'output-generator':
185
161
  return this.executeOutputGenerator(step, variables, options);
186
- case "genkit-joke":
187
- return this.executeGenkitJoke(step, variables, options);
188
- case "genkit-translation":
189
- return this.executeGenkitTranslation(step, variables, options);
190
- case "genkit-image":
191
- return this.executeGenkitImage(step, variables, options);
192
- case "custom-action":
162
+ // Preferred step types
163
+ case 'joke':
164
+ case 'genkit-joke':
165
+ return this.executeJoke(step, variables, options);
166
+ case 'translation':
167
+ case 'genkit-translation':
168
+ return this.executeTranslation(step, variables, options);
169
+ case 'image':
170
+ case 'genkit-image':
171
+ return this.executeImage(step, variables, options);
172
+ case 'vectorize':
173
+ case 'gemini-vectorize':
174
+ return this.executeVectorize(step, variables, options);
175
+ case 'custom-action':
193
176
  return this.executeCustomAction(step, variables, options);
177
+ case 'mcp-tool':
178
+ return this.executeMcpTool(step, variables, options);
179
+ case 'chromadb':
180
+ return this.executeChromaDB(step, variables, options);
181
+ case 'gitmcp':
182
+ return this.executeGitMcp(step, variables, options);
183
+ case 'rag':
184
+ return this.executeRag(step, variables, options);
185
+ case 'chat':
186
+ return this.executeChat(step, variables, options);
187
+ case 'builtin-agent':
188
+ return this.executeBuiltinAgent(step, variables, options);
194
189
  default:
195
190
  throw new Error(`Unsupported workflow step type: ${step.type}`);
196
191
  }
197
192
  }
198
- /**
199
- * Execute output generator step
200
- */
193
+ // ============================================================================
194
+ // Output Generator (kept inline - orchestration logic)
195
+ // ============================================================================
201
196
  executeOutputGenerator(step, variables, options) {
202
- if (step.action?.type !== "generate" || !step.action.output) {
203
- throw new Error("Invalid output generator configuration");
197
+ if (step.action?.type !== 'generate' || !step.action.output) {
198
+ throw new Error('Invalid output generator configuration');
204
199
  }
205
- // Build output object
206
200
  const output = {};
207
- // Debug: Log available variables
208
- options.context.log(`Output generator: Available variables: ${Array.from(variables.keys()).join(", ")}`);
201
+ options.context.log(`Output generator: Available variables: ${Array.from(variables.keys()).join(', ')}`);
209
202
  for (const [key, valueExpr] of Object.entries(step.action.output)) {
210
- if (typeof valueExpr === "string" && valueExpr.startsWith("$")) {
203
+ if (typeof valueExpr === 'string' && valueExpr.startsWith('$')) {
211
204
  try {
212
205
  const reference = valueExpr.substring(1);
213
- options.context.log(`Output generator: Resolving reference ${valueExpr} -> ${reference}`);
214
206
  const resolved = this.resolveReference(reference, variables);
215
207
  output[key] = resolved;
216
- options.context.log(`Output generator: Resolved ${key} = ${typeof resolved === "string" ? resolved.substring(0, 50) + "..." : JSON.stringify(resolved).substring(0, 100)}`);
217
208
  }
218
209
  catch (error) {
219
210
  options.context.log(`Output generator: Failed to resolve ${valueExpr}: ${error instanceof Error ? error.message : String(error)}`);
@@ -224,109 +215,177 @@ class DeclarativeAgentInterpreter {
224
215
  output[key] = valueExpr;
225
216
  }
226
217
  }
227
- options.context.log(`Output generator: Final output keys: ${Object.keys(output).join(", ")}`);
228
218
  return output;
229
219
  }
230
- /**
231
- * Execute Gemini Flash text helper for the joke agent
232
- */
233
- async executeGenkitJoke(step, variables, options) {
234
- const prompt = typeof step.action?.prompt === "string" && step.action.prompt.trim().length
220
+ // ============================================================================
221
+ // Delegated Handlers - Using extracted agent handlers
222
+ // ============================================================================
223
+ async executeJoke(step, variables, options) {
224
+ const prompt = typeof step.action?.prompt === 'string' && step.action.prompt.trim().length
235
225
  ? step.action.prompt.trim()
236
- : "Conte uma piada curta e original em português.";
237
- const temperature = typeof step.action?.temperature === "number"
238
- ? step.action.temperature
239
- : 0.8;
240
- const maxTokens = typeof step.action?.maxTokens === "number"
241
- ? step.action.maxTokens
242
- : undefined;
243
- const resultVar = typeof step.action?.result === "string" && step.action.result.length > 0
226
+ : 'Tell a short and original joke that works for any audience.';
227
+ const temperature = typeof step.action?.temperature === 'number' ? step.action.temperature : 0.8;
228
+ const maxTokens = typeof step.action?.maxTokens === 'number' ? step.action.maxTokens : undefined;
229
+ const resultVar = typeof step.action?.result === 'string' && step.action.result.length > 0
244
230
  ? step.action.result
245
- : "jokerResult";
246
- const joke = await this.callGeminiFlashText({ prompt, temperature, maxTokens }, options.props, options.context);
247
- variables.set(resultVar, joke);
248
- return joke;
231
+ : 'jokerResult';
232
+ const result = await (0, workflowExecutor_1.executeJokeHandler)({ prompt, temperature, maxTokens }, options.props, options.context);
233
+ variables.set(resultVar, result);
234
+ return result;
249
235
  }
250
- /**
251
- * Execute translation step backed by Gemini Flash
252
- */
253
- async executeGenkitTranslation(step, variables, options) {
254
- const texto = options.input?.texto;
255
- const idiomaOrigem = options.input?.idioma_origem;
256
- const idiomaDestino = options.input?.idioma_destino;
257
- const resultVar = typeof step.action?.result === "string" && step.action.result.length > 0
236
+ async executeTranslation(step, variables, options) {
237
+ const text = options.input?.texto || options.input?.text;
238
+ const sourceLanguage = options.input?.idioma_origem || options.input?.source_language;
239
+ const targetLanguage = options.input?.idioma_destino || options.input?.target_language;
240
+ const resultVar = typeof step.action?.result === 'string' && step.action.result.length > 0
258
241
  ? step.action.result
259
- : "translationResult";
260
- const translation = await this.callGeminiFlashTranslation({
261
- texto,
262
- idioma_origem: idiomaOrigem,
263
- idioma_destino: idiomaDestino,
264
- promptTemplate: typeof step.action?.promptTemplate === "string"
242
+ : 'translationResult';
243
+ const result = await (0, workflowExecutor_1.executeTranslationHandler)({
244
+ text,
245
+ source_language: sourceLanguage,
246
+ target_language: targetLanguage,
247
+ promptTemplate: typeof step.action?.promptTemplate === 'string'
265
248
  ? step.action.promptTemplate
266
249
  : undefined,
267
250
  }, options.props, options.context);
268
- variables.set(resultVar, translation);
269
- return translation;
251
+ variables.set(resultVar, result);
252
+ return result;
270
253
  }
271
- /**
272
- * Execute image generation step backed by Gemini Flash
273
- */
274
- async executeGenkitImage(step, variables, options) {
275
- const descricao = typeof options.input?.descricao === "string"
254
+ async executeImage(step, variables, options) {
255
+ const description = typeof options.input?.descricao === 'string'
276
256
  ? options.input.descricao.trim()
277
- : "";
278
- const estilo = typeof options.input?.estilo === "string"
257
+ : typeof options.input?.description === 'string'
258
+ ? options.input.description.trim()
259
+ : '';
260
+ const style = typeof options.input?.estilo === 'string'
279
261
  ? options.input.estilo.trim()
280
- : "";
281
- const resolucaoInput = typeof options.input?.resolucao === "string"
262
+ : typeof options.input?.style === 'string'
263
+ ? options.input.style.trim()
264
+ : '';
265
+ const resolution = typeof options.input?.resolucao === 'string'
282
266
  ? options.input.resolucao.trim()
283
- : "";
284
- if (!descricao) {
285
- throw new Error("Missing required image input: descricao");
267
+ : typeof options.input?.resolution === 'string'
268
+ ? options.input.resolution.trim()
269
+ : '';
270
+ if (!description) {
271
+ throw new Error('Missing required image input: description');
286
272
  }
287
- if (!estilo) {
288
- throw new Error("Missing required image input: estilo");
273
+ if (!style) {
274
+ throw new Error('Missing required image input: style');
289
275
  }
290
- if (!resolucaoInput) {
291
- throw new Error("Missing required image input: resolucao");
276
+ if (!resolution) {
277
+ throw new Error('Missing required image input: resolution');
292
278
  }
293
- const promptTemplate = typeof step.action?.promptTemplate === "string" &&
279
+ const promptTemplate = typeof step.action?.promptTemplate === 'string' &&
294
280
  step.action.promptTemplate.trim().length > 0
295
281
  ? step.action.promptTemplate
296
- : "Gere uma imagem detalhada no estilo {{estilo}} baseada na descrição: {{descricao}}";
297
- const prompt = promptTemplate
298
- .replace(/{{descricao}}/g, descricao)
299
- .replace(/{{estilo}}/g, estilo)
300
- .trim();
301
- const resultVar = typeof step.action?.result === "string" && step.action.result.length > 0
282
+ : 'Create a detailed image in {{style}} style focusing on: {{description}}';
283
+ const resultVar = typeof step.action?.result === 'string' && step.action.result.length > 0
302
284
  ? step.action.result
303
- : "imageResult";
304
- const imageResult = await this.callGeminiFlashImage({
305
- prompt,
306
- estilo,
307
- resolucao: resolucaoInput,
285
+ : 'imageResult';
286
+ const result = await (0, workflowExecutor_1.executeImageHandler)({
287
+ description,
288
+ style,
289
+ resolution,
290
+ promptTemplate,
308
291
  }, options.props, options.context);
309
- variables.set(resultVar, imageResult);
310
- options.context.log(`Image generator: Saved result in variable '${resultVar}' with keys: ${Object.keys(imageResult).join(", ")}`);
311
- options.context.log(`Image generator: imageResult.image_url exists: ${!!imageResult?.image_url}`);
312
- return imageResult;
292
+ variables.set(resultVar, result);
293
+ return result;
313
294
  }
314
- /**
315
- * Execute custom action backed by TypeScript implementation
316
- */
295
+ async executeMcpTool(step, variables, options) {
296
+ const serverUrl = this.resolveInputValue(step.action?.server_url, options.input, variables);
297
+ const toolName = this.resolveInputValue(step.action?.tool_name, options.input, variables);
298
+ const toolArguments = this.resolveInputValue(step.action?.tool_arguments, options.input, variables) || {};
299
+ const resultVar = step.action?.result || 'mcpResult';
300
+ const result = await (0, workflowExecutor_1.executeMcpToolHandler)({
301
+ server_url: serverUrl,
302
+ tool_name: toolName,
303
+ tool_arguments: toolArguments,
304
+ }, options.props, options.context);
305
+ variables.set(resultVar, result);
306
+ return result;
307
+ }
308
+ async executeVectorize(step, variables, options) {
309
+ const action = step.action?.action || 'embedSingle';
310
+ const resultVar = step.action?.result || 'vectorizeResult';
311
+ let result;
312
+ if (action === 'embedSingle') {
313
+ const text = this.resolveInputValue(step.action?.text, options.input, variables);
314
+ result = await (0, workflowExecutor_1.executeVectorizeHandler)({ action: 'embedSingle', text }, options.props, options.context);
315
+ }
316
+ else if (action === 'embedBatch') {
317
+ const texts = this.resolveInputValue(step.action?.texts, options.input, variables);
318
+ result = await (0, workflowExecutor_1.executeVectorizeHandler)({ action: 'embedBatch', texts }, options.props, options.context);
319
+ }
320
+ else {
321
+ throw new Error(`Unknown vectorize action: ${action}`);
322
+ }
323
+ variables.set(resultVar, result);
324
+ return result;
325
+ }
326
+ async executeChromaDB(step, variables, options) {
327
+ const action = this.resolveInputValue(step.action?.action, options.input, variables);
328
+ const collectionName = this.resolveInputValue(step.action?.collection_name, options.input, variables);
329
+ const resultVar = step.action?.result || 'chromaResult';
330
+ let params = { action, collection_name: collectionName };
331
+ if (action === 'hasData') {
332
+ params.min_count =
333
+ this.resolveInputValue(step.action?.min_count, options.input, variables) || 1;
334
+ }
335
+ else if (action === 'store') {
336
+ params.ids = this.resolveInputValue(step.action?.ids, options.input, variables);
337
+ params.vectors = this.resolveInputValue(step.action?.vectors, options.input, variables);
338
+ params.documents = this.resolveInputValue(step.action?.documents, options.input, variables);
339
+ params.metadatas = this.resolveInputValue(step.action?.metadatas, options.input, variables);
340
+ }
341
+ else if (action === 'search') {
342
+ params.query_vector = this.resolveInputValue(step.action?.query_vector, options.input, variables);
343
+ params.limit =
344
+ this.resolveInputValue(step.action?.limit, options.input, variables) || 5;
345
+ }
346
+ const result = await (0, workflowExecutor_1.executeChromaDBHandler)(params, options.props, options.context);
347
+ variables.set(resultVar, result);
348
+ return result;
349
+ }
350
+ async executeGitMcp(step, variables, options) {
351
+ const gitmcpUrl = this.resolveInputValue(step.action?.gitmcp_url, options.input, variables);
352
+ const resultVar = step.action?.result || 'gitmcpResult';
353
+ const result = await (0, workflowExecutor_1.executeGitMcpHandler)({ gitmcp_url: gitmcpUrl }, options.props, options.context);
354
+ variables.set(resultVar, result);
355
+ return result;
356
+ }
357
+ async executeRag(step, variables, options) {
358
+ const query = this.resolveInputValue(step.action?.query, options.input, variables);
359
+ const context = this.resolveInputValue(step.action?.context, options.input, variables) ||
360
+ this.resolveInputValue(step.action?.documents, options.input, variables);
361
+ const history = this.resolveInputValue(step.action?.history, options.input, variables);
362
+ const resultVar = step.action?.result || 'ragResult';
363
+ const result = await (0, workflowExecutor_1.executeRagHandler)({ query, context, documents: context, history }, options.props, options.context);
364
+ variables.set(resultVar, result);
365
+ return result;
366
+ }
367
+ async executeChat(step, variables, options) {
368
+ const messages = this.resolveInputValue(step.action?.messages, options.input, variables);
369
+ const query = this.resolveInputValue(step.action?.query, options.input, variables);
370
+ const resultVar = step.action?.result || 'chatResult';
371
+ const result = await (0, workflowExecutor_1.executeChatHandler)({ messages, query }, options.props, options.context);
372
+ variables.set(resultVar, result);
373
+ return result;
374
+ }
375
+ // ============================================================================
376
+ // Custom Action & Builtin Agent (orchestration logic)
377
+ // ============================================================================
317
378
  async executeCustomAction(step, variables, options) {
318
379
  const functionName = step.action?.function;
319
380
  if (!functionName) {
320
381
  throw new Error("Missing 'function' in custom-action");
321
382
  }
322
383
  options.context.log(`Custom action: Looking up function '${functionName}'`);
323
- // Retrieve Code Implementation
324
- const customFunc = agentRegistry_1.agentRegistry.getCustomFunction(functionName);
384
+ const customFunc = registry_1.agentRegistry.getCustomFunction(functionName);
325
385
  if (!customFunc) {
326
386
  throw new Error(`Custom function '${functionName}' not found in registry. ` +
327
387
  `Make sure the corresponding .ts file is in the /agents directory.`);
328
388
  }
329
- // Prepare Arguments
330
389
  const args = {
331
390
  input: options.input,
332
391
  variables: Object.fromEntries(variables),
@@ -334,13 +393,10 @@ class DeclarativeAgentInterpreter {
334
393
  context: options.context,
335
394
  };
336
395
  options.context.log(`Custom action: Executing function '${functionName}'`);
337
- // Execute Code
338
396
  try {
339
397
  const result = await customFunc(args);
340
- // Save Result
341
398
  if (step.action.result) {
342
399
  variables.set(step.action.result, result);
343
- options.context.log(`Custom action: Saved result to variable '${step.action.result}'`);
344
400
  }
345
401
  return result;
346
402
  }
@@ -351,266 +407,108 @@ class DeclarativeAgentInterpreter {
351
407
  throw new Error(`Custom action execution failed: ${errorMessage}`);
352
408
  }
353
409
  }
354
- /**
355
- * Evaluate value expression
356
- */
410
+ async executeBuiltinAgent(step, variables, options) {
411
+ const agentName = step.action?.agent;
412
+ const agentInput = this.resolveInputValue(step.action?.input, options.input, variables) || options.input;
413
+ const agentProps = step.action?.props || options.props;
414
+ const resultVar = step.action?.result || 'builtinResult';
415
+ if (!agentName) {
416
+ throw new Error('Missing required builtin-agent input: agent');
417
+ }
418
+ options.context.log(`[Builtin Agent] Invoking agent: ${agentName}`);
419
+ try {
420
+ const result = await registry_1.agentRegistry.executeAgent(agentName, agentInput, agentProps, options.context);
421
+ variables.set(resultVar, result);
422
+ return result;
423
+ }
424
+ catch (error) {
425
+ const message = error instanceof Error ? error.message : String(error);
426
+ options.context.log(`[Builtin Agent] Error: ${message}`);
427
+ throw new Error(`Builtin agent '${agentName}' execution failed: ${message}`);
428
+ }
429
+ }
430
+ // ============================================================================
431
+ // Helper Methods
432
+ // ============================================================================
433
+ resolveInputValue(value, input, variables) {
434
+ if (value === undefined || value === null)
435
+ return undefined;
436
+ if (typeof value === 'string' && value.startsWith('$')) {
437
+ const ref = value.substring(1);
438
+ if (ref.startsWith('input.')) {
439
+ const inputKey = ref.substring(6);
440
+ return this.getNestedValue(input, inputKey);
441
+ }
442
+ return this.resolveReference(ref, variables);
443
+ }
444
+ if (typeof value === 'string' && input[value] !== undefined) {
445
+ return input[value];
446
+ }
447
+ return value;
448
+ }
449
+ getNestedValue(obj, path) {
450
+ const parts = path.split('.');
451
+ let current = obj;
452
+ for (const part of parts) {
453
+ if (current == null)
454
+ return undefined;
455
+ current = current[part];
456
+ }
457
+ return current;
458
+ }
357
459
  evaluateValue(expr, variables) {
358
- // Handle string literals
359
460
  if (expr.startsWith('"') && expr.endsWith('"')) {
360
461
  if (expr.length - 2 > this.MAX_VARIABLE_SIZE) {
361
- throw new Error("Variable initialization exceeds maximum size");
462
+ throw new Error('Variable initialization exceeds maximum size');
362
463
  }
363
464
  return expr.slice(1, -1);
364
465
  }
365
466
  if (expr.startsWith("'") && expr.endsWith("'")) {
366
467
  if (expr.length - 2 > this.MAX_VARIABLE_SIZE) {
367
- throw new Error("Variable initialization exceeds maximum size");
468
+ throw new Error('Variable initialization exceeds maximum size');
368
469
  }
369
470
  return expr.slice(1, -1);
370
471
  }
371
472
  if (expr.length > this.MAX_VARIABLE_SIZE) {
372
- throw new Error("Variable initialization exceeds maximum size");
473
+ throw new Error('Variable initialization exceeds maximum size');
373
474
  }
374
- // Handle boolean literals
375
- if (expr === "true")
475
+ if (expr === 'true')
376
476
  return true;
377
- if (expr === "false")
477
+ if (expr === 'false')
378
478
  return false;
379
- // Handle null literal
380
- if (expr === "null")
479
+ if (expr === 'null')
381
480
  return null;
382
- // Handle variable references
383
- if (expr.startsWith("$")) {
481
+ if (expr.startsWith('$')) {
384
482
  return this.resolveReference(expr.substring(1), variables);
385
483
  }
386
- // Handle numbers
387
484
  if (/^-?\d+$/.test(expr))
388
485
  return parseInt(expr, 10);
389
486
  if (/^-?\d+\.\d+$/.test(expr))
390
487
  return parseFloat(expr);
391
488
  throw new Error(`Unsupported value expression: ${expr}`);
392
489
  }
393
- /**
394
- * Validate variable declaration
395
- */
396
490
  validateVariable(variable) {
397
491
  if (!variable.name || !variable.type) {
398
- throw new Error("Invalid variable declaration: missing name or type");
492
+ throw new Error('Invalid variable declaration: missing name or type');
399
493
  }
400
- if (!["string", "number", "boolean", "object"].includes(variable.type)) {
494
+ if (!['string', 'number', 'boolean', 'object'].includes(variable.type)) {
401
495
  throw new Error(`Unsupported variable type: ${variable.type}`);
402
496
  }
403
497
  }
404
- /**
405
- * Resolve variable reference, including nested properties (e.g., foo.bar.baz)
406
- */
407
498
  resolveReference(reference, variables) {
408
- const [varName, ...pathSegments] = reference.split(".");
499
+ const [varName, ...pathSegments] = reference.split('.');
409
500
  let value = variables.get(varName);
410
501
  if (value === undefined) {
411
502
  throw new Error(`Undefined variable referenced: ${varName}`);
412
503
  }
413
504
  for (const segment of pathSegments) {
414
- if (value == null || typeof value !== "object") {
505
+ if (value == null || typeof value !== 'object') {
415
506
  throw new Error(`Cannot resolve path '${reference}': segment '${segment}' is invalid`);
416
507
  }
417
508
  value = value[segment];
418
509
  }
419
510
  return value;
420
511
  }
421
- /**
422
- * Ensure we have a Gemini API key before calling Genkit helpers
423
- */
424
- ensureGeminiApiKey(props) {
425
- const apiKey = props?.gemini_api_key?.trim();
426
- if (!apiKey) {
427
- throw new Error("Missing required prop: gemini_api_key. Configure a valid Gemini API key before calling this agent.");
428
- }
429
- return apiKey;
430
- }
431
- createGeminiModel(props) {
432
- const apiKey = this.ensureGeminiApiKey(props);
433
- const google = (0, google_1.createGoogleGenerativeAI)({ apiKey });
434
- const model = google(this.GEMINI_MODEL);
435
- return model;
436
- }
437
- createGeminiImageModel(props) {
438
- const apiKey = this.ensureGeminiApiKey(props);
439
- const google = (0, google_1.createGoogleGenerativeAI)({ apiKey });
440
- return google.image(this.GEMINI_IMAGE_MODEL);
441
- }
442
- async callGeminiFlashText(params, props, context) {
443
- const prompt = params.prompt?.trim();
444
- if (!prompt) {
445
- throw new Error("Gemini Flash text helper requires a prompt");
446
- }
447
- const temperature = typeof params.temperature === "number" ? params.temperature : 0.7;
448
- const maxTokens = typeof params.maxTokens === "number" ? params.maxTokens : undefined;
449
- const model = this.createGeminiModel(props);
450
- const startTime = Date.now();
451
- try {
452
- context.log(`Invoking Gemini Flash text helper (temperature=${temperature}, maxTokens=${typeof maxTokens === "number" ? maxTokens : "provider-default"})`);
453
- const generationOptions = {
454
- model,
455
- prompt,
456
- temperature,
457
- };
458
- if (typeof maxTokens === "number") {
459
- generationOptions.maxOutputTokens = maxTokens;
460
- }
461
- const { text, content } = await (0, ai_1.generateText)(generationOptions);
462
- const contentText = content
463
- ? content
464
- .map((part) => typeof part?.text === "string" ? part.text : "")
465
- .join(" ")
466
- .trim()
467
- : "";
468
- const finalText = (text || "").trim() || contentText || "";
469
- if (!finalText) {
470
- throw new Error("Gemini Flash text helper returned empty response");
471
- }
472
- return {
473
- texto: finalText,
474
- metadados: {
475
- modelo_utilizado: this.GEMINI_MODEL,
476
- tempo_processamento: Date.now() - startTime,
477
- temperature,
478
- max_tokens: typeof maxTokens === "number" ? maxTokens : null,
479
- prompt_utilizado: prompt,
480
- },
481
- };
482
- }
483
- catch (error) {
484
- const message = error instanceof Error ? error.message : "Unknown Gemini Flash error";
485
- context.log(`Gemini Flash text helper failed: ${message}`);
486
- context.setError(message);
487
- throw error;
488
- }
489
- }
490
- async callGeminiFlashTranslation(params, props, context) {
491
- const texto = params.texto?.trim();
492
- const idiomaOrigem = params.idioma_origem?.trim().toLowerCase();
493
- const idiomaDestino = params.idioma_destino?.trim().toLowerCase();
494
- if (!texto || !idiomaOrigem || !idiomaDestino) {
495
- throw new Error("Missing required translation parameters: texto, idioma_origem, idioma_destino");
496
- }
497
- if (idiomaOrigem === idiomaDestino) {
498
- return {
499
- texto_traduzido: texto,
500
- metadados: {
501
- modelo_utilizado: this.GEMINI_MODEL,
502
- tempo_processamento: 0,
503
- confianca: 1,
504
- idiomas_suportados: this.SUPPORTED_TRANSLATION_LANGUAGES,
505
- idiomas_solicitados: {
506
- origem: idiomaOrigem,
507
- destino: idiomaDestino,
508
- },
509
- prompt_utilizado: "Bypass: idiomas de origem e destino são iguais",
510
- },
511
- };
512
- }
513
- const template = params.promptTemplate && params.promptTemplate.trim().length > 0
514
- ? params.promptTemplate
515
- : `Traduza o texto abaixo de {{idioma_origem}} para {{idioma_destino}}.
516
- Responda somente com o texto traduzido sem comentários adicionais.
517
-
518
- Texto:
519
- {{texto}}`;
520
- const prompt = template
521
- .replace(/{{texto}}/g, texto)
522
- .replace(/{{idioma_origem}}/g, idiomaOrigem)
523
- .replace(/{{idioma_destino}}/g, idiomaDestino)
524
- .trim();
525
- const model = this.createGeminiModel(props);
526
- const startTime = Date.now();
527
- try {
528
- context.log(`Invoking Gemini Flash translation helper (${idiomaOrigem}->${idiomaDestino})`);
529
- const { text, content } = await (0, ai_1.generateText)({
530
- model,
531
- prompt,
532
- temperature: 0.2,
533
- });
534
- const contentText = content
535
- ? content
536
- .map((part) => typeof part?.text === "string" ? part.text : "")
537
- .join(" ")
538
- .trim()
539
- : "";
540
- const translatedText = (text || "").trim() || contentText || "";
541
- if (!translatedText) {
542
- throw new Error("Gemini Flash translation returned empty response");
543
- }
544
- return {
545
- texto_traduzido: translatedText,
546
- metadados: {
547
- modelo_utilizado: this.GEMINI_MODEL,
548
- tempo_processamento: Date.now() - startTime,
549
- confianca: 0.85,
550
- idiomas_suportados: this.SUPPORTED_TRANSLATION_LANGUAGES,
551
- idiomas_solicitados: {
552
- origem: idiomaOrigem,
553
- destino: idiomaDestino,
554
- },
555
- prompt_utilizado: prompt,
556
- },
557
- };
558
- }
559
- catch (error) {
560
- const message = error instanceof Error ? error.message : "Unknown translation error";
561
- context.log(`Gemini Flash translation failed: ${message}`);
562
- context.setError(message);
563
- throw error;
564
- }
565
- }
566
- async callGeminiFlashImage(params, props, context) {
567
- const prompt = params.prompt?.trim();
568
- const estilo = params.estilo?.trim();
569
- const resolucao = params.resolucao?.trim();
570
- if (!prompt) {
571
- throw new Error("Gemini Flash image helper requires a prompt");
572
- }
573
- if (!estilo) {
574
- throw new Error("Gemini Flash image helper requires an estilo value");
575
- }
576
- if (!resolucao || !/^\d+x\d+$/.test(resolucao)) {
577
- throw new Error("Gemini Flash image helper requires uma resolução no formato LARGURAxALTURA (ex: 1024x1024)");
578
- }
579
- const model = this.createGeminiImageModel(props);
580
- const startTime = Date.now();
581
- try {
582
- context.log(`Invoking Gemini Flash image helper (estilo=${estilo}, resolucao=${resolucao})`);
583
- const result = await (0, ai_1.experimental_generateImage)({
584
- model,
585
- prompt,
586
- size: resolucao,
587
- });
588
- const image = result.image;
589
- if (!image?.base64 || !image.mediaType) {
590
- throw new Error("Gemini Flash image helper returned an invalid file");
591
- }
592
- const normalizedBase64 = image.base64.replace(/\s+/g, "");
593
- const imageUrl = `data:${image.mediaType};base64,${normalizedBase64}`;
594
- return {
595
- image_url: imageUrl,
596
- image_base64: normalizedBase64,
597
- media_type: image.mediaType,
598
- prompt_utilizado: prompt,
599
- metadados: {
600
- modelo_utilizado: this.GEMINI_IMAGE_MODEL,
601
- tempo_processamento: Date.now() - startTime,
602
- estilo,
603
- resolucao,
604
- },
605
- };
606
- }
607
- catch (error) {
608
- const message = error instanceof Error ? error.message : "Unknown image error";
609
- context.log(`Gemini Flash image helper failed: ${message}`);
610
- context.setError(message);
611
- throw error;
612
- }
613
- }
614
512
  }
615
513
  exports.DeclarativeAgentInterpreter = DeclarativeAgentInterpreter;
616
514
  // Singleton instance