beddel 0.2.1 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (332) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +132 -21
  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 +143 -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 +150 -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 +58 -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 +66 -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 +42 -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 +95 -0
  89. package/dist/agents/index.d.ts.map +1 -0
  90. package/dist/agents/index.js +76 -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 +48 -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 +35 -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/mcp-tool/index.d.ts +14 -0
  110. package/dist/agents/mcp-tool/index.d.ts.map +1 -0
  111. package/dist/agents/mcp-tool/index.js +19 -0
  112. package/dist/agents/mcp-tool/index.js.map +1 -0
  113. package/dist/agents/mcp-tool/mcp-tool.handler.d.ts +12 -0
  114. package/dist/agents/mcp-tool/mcp-tool.handler.d.ts.map +1 -0
  115. package/dist/agents/mcp-tool/mcp-tool.handler.js +116 -0
  116. package/dist/agents/mcp-tool/mcp-tool.handler.js.map +1 -0
  117. package/dist/agents/mcp-tool/mcp-tool.schema.d.ts +19 -0
  118. package/dist/agents/mcp-tool/mcp-tool.schema.d.ts.map +1 -0
  119. package/dist/agents/mcp-tool/mcp-tool.schema.js +20 -0
  120. package/dist/agents/mcp-tool/mcp-tool.schema.js.map +1 -0
  121. package/dist/agents/mcp-tool/mcp-tool.types.d.ts +31 -0
  122. package/dist/agents/mcp-tool/mcp-tool.types.d.ts.map +1 -0
  123. package/dist/agents/mcp-tool/mcp-tool.types.js +6 -0
  124. package/dist/agents/mcp-tool/mcp-tool.types.js.map +1 -0
  125. package/dist/agents/mcp-tool/mcp-tool.yaml +71 -0
  126. package/dist/agents/rag/index.d.ts +15 -0
  127. package/dist/agents/rag/index.d.ts.map +1 -0
  128. package/dist/agents/rag/index.js +20 -0
  129. package/dist/agents/rag/index.js.map +1 -0
  130. package/dist/agents/rag/rag.handler.d.ts +8 -0
  131. package/dist/agents/rag/rag.handler.d.ts.map +1 -0
  132. package/dist/agents/rag/rag.handler.js +101 -0
  133. package/dist/agents/rag/rag.handler.js.map +1 -0
  134. package/dist/agents/rag/rag.schema.d.ts +27 -0
  135. package/dist/agents/rag/rag.schema.d.ts.map +1 -0
  136. package/dist/agents/rag/rag.schema.js +24 -0
  137. package/dist/agents/rag/rag.schema.js.map +1 -0
  138. package/dist/agents/rag/rag.types.d.ts +47 -0
  139. package/dist/agents/rag/rag.types.d.ts.map +1 -0
  140. package/dist/agents/rag/rag.types.js +6 -0
  141. package/dist/agents/rag/rag.types.js.map +1 -0
  142. package/dist/agents/rag/rag.yaml +89 -0
  143. package/dist/agents/{agentRegistry.d.ts → registry/agentRegistry.d.ts} +25 -1
  144. package/dist/agents/registry/agentRegistry.d.ts.map +1 -0
  145. package/dist/agents/{agentRegistry.js → registry/agentRegistry.js} +154 -4
  146. package/dist/agents/registry/agentRegistry.js.map +1 -0
  147. package/dist/agents/registry/index.d.ts +6 -0
  148. package/dist/agents/registry/index.d.ts.map +1 -0
  149. package/dist/agents/registry/index.js +10 -0
  150. package/dist/agents/registry/index.js.map +1 -0
  151. package/dist/agents/translator/index.d.ts +14 -0
  152. package/dist/agents/translator/index.d.ts.map +1 -0
  153. package/dist/agents/translator/index.js +19 -0
  154. package/dist/agents/translator/index.js.map +1 -0
  155. package/dist/agents/translator/translator.handler.d.ts +8 -0
  156. package/dist/agents/translator/translator.handler.d.ts.map +1 -0
  157. package/dist/agents/translator/translator.handler.js +83 -0
  158. package/dist/agents/translator/translator.handler.js.map +1 -0
  159. package/dist/agents/translator/translator.schema.d.ts +27 -0
  160. package/dist/agents/translator/translator.schema.d.ts.map +1 -0
  161. package/dist/agents/translator/translator.schema.js +28 -0
  162. package/dist/agents/translator/translator.schema.js.map +1 -0
  163. package/dist/agents/translator/translator.types.d.ts +40 -0
  164. package/dist/agents/translator/translator.types.d.ts.map +1 -0
  165. package/dist/agents/translator/translator.types.js +6 -0
  166. package/dist/agents/translator/translator.types.js.map +1 -0
  167. package/{src/agents/translator-agent.yaml → dist/agents/translator/translator.yaml} +27 -27
  168. package/dist/client/index.d.ts +89 -0
  169. package/dist/client/index.d.ts.map +1 -0
  170. package/dist/client/index.js +93 -0
  171. package/dist/client/index.js.map +1 -0
  172. package/dist/client/types.d.ts +17 -0
  173. package/dist/client/types.d.ts.map +1 -0
  174. package/dist/client/types.js +7 -0
  175. package/dist/client/types.js.map +1 -0
  176. package/dist/firebase/tenantManager.d.ts +34 -2
  177. package/dist/firebase/tenantManager.d.ts.map +1 -1
  178. package/dist/firebase/tenantManager.js +67 -1
  179. package/dist/firebase/tenantManager.js.map +1 -1
  180. package/dist/index.d.ts +8 -4
  181. package/dist/index.d.ts.map +1 -1
  182. package/dist/index.js +22 -7
  183. package/dist/index.js.map +1 -1
  184. package/dist/runtime/declarativeAgentRuntime.d.ts +14 -49
  185. package/dist/runtime/declarativeAgentRuntime.d.ts.map +1 -1
  186. package/dist/runtime/declarativeAgentRuntime.js +248 -355
  187. package/dist/runtime/declarativeAgentRuntime.js.map +1 -1
  188. package/dist/runtime/index.d.ts +12 -0
  189. package/dist/runtime/index.d.ts.map +1 -0
  190. package/dist/runtime/index.js +33 -0
  191. package/dist/runtime/index.js.map +1 -0
  192. package/dist/runtime/workflowExecutor.d.ts +30 -0
  193. package/dist/runtime/workflowExecutor.d.ts.map +1 -0
  194. package/dist/runtime/workflowExecutor.js +70 -0
  195. package/dist/runtime/workflowExecutor.js.map +1 -0
  196. package/dist/server/api/graphql.d.ts +1 -1
  197. package/dist/server/api/graphql.d.ts.map +1 -1
  198. package/dist/server/api/graphql.js +104 -62
  199. package/dist/server/api/graphql.js.map +1 -1
  200. package/dist/server/index.d.ts +2 -2
  201. package/dist/server/index.d.ts.map +1 -1
  202. package/dist/server/index.js +2 -2
  203. package/dist/server/index.js.map +1 -1
  204. package/dist/shared/index.d.ts +7 -0
  205. package/dist/shared/index.d.ts.map +1 -0
  206. package/dist/shared/index.js +23 -0
  207. package/dist/shared/index.js.map +1 -0
  208. package/dist/shared/types/agent.types.d.ts +50 -0
  209. package/dist/shared/types/agent.types.d.ts.map +1 -0
  210. package/dist/shared/types/agent.types.js +7 -0
  211. package/dist/shared/types/agent.types.js.map +1 -0
  212. package/dist/shared/types/execution.types.d.ts +42 -0
  213. package/dist/shared/types/execution.types.d.ts.map +1 -0
  214. package/dist/shared/types/execution.types.js +7 -0
  215. package/dist/shared/types/execution.types.js.map +1 -0
  216. package/dist/shared/types/index.d.ts +7 -0
  217. package/dist/shared/types/index.d.ts.map +1 -0
  218. package/dist/shared/types/index.js +23 -0
  219. package/dist/shared/types/index.js.map +1 -0
  220. package/dist/shared/types/schema.types.d.ts +52 -0
  221. package/dist/shared/types/schema.types.d.ts.map +1 -0
  222. package/dist/shared/types/schema.types.js +7 -0
  223. package/dist/shared/types/schema.types.js.map +1 -0
  224. package/dist/shared/utils/index.d.ts +5 -0
  225. package/dist/shared/utils/index.d.ts.map +1 -0
  226. package/dist/shared/utils/index.js +21 -0
  227. package/dist/shared/utils/index.js.map +1 -0
  228. package/dist/shared/utils/validation.d.ts +42 -0
  229. package/dist/shared/utils/validation.d.ts.map +1 -0
  230. package/dist/shared/utils/validation.js +93 -0
  231. package/dist/shared/utils/validation.js.map +1 -0
  232. package/dist/tenant/TenantManager.d.ts +152 -0
  233. package/dist/tenant/TenantManager.d.ts.map +1 -0
  234. package/dist/tenant/TenantManager.js +392 -0
  235. package/dist/tenant/TenantManager.js.map +1 -0
  236. package/dist/tenant/index.d.ts +47 -0
  237. package/dist/tenant/index.d.ts.map +1 -0
  238. package/dist/tenant/index.js +74 -0
  239. package/dist/tenant/index.js.map +1 -0
  240. package/dist/tenant/interfaces.d.ts +170 -0
  241. package/dist/tenant/interfaces.d.ts.map +1 -0
  242. package/dist/tenant/interfaces.js +67 -0
  243. package/dist/tenant/interfaces.js.map +1 -0
  244. package/dist/tenant/providerFactory.d.ts +43 -0
  245. package/dist/tenant/providerFactory.d.ts.map +1 -0
  246. package/dist/tenant/providerFactory.js +70 -0
  247. package/dist/tenant/providerFactory.js.map +1 -0
  248. package/dist/tenant/providerRegistry.d.ts +47 -0
  249. package/dist/tenant/providerRegistry.d.ts.map +1 -0
  250. package/dist/tenant/providerRegistry.js +79 -0
  251. package/dist/tenant/providerRegistry.js.map +1 -0
  252. package/dist/tenant/providers/FirebaseTenantProvider.d.ts +41 -0
  253. package/dist/tenant/providers/FirebaseTenantProvider.d.ts.map +1 -0
  254. package/dist/tenant/providers/FirebaseTenantProvider.js +290 -0
  255. package/dist/tenant/providers/FirebaseTenantProvider.js.map +1 -0
  256. package/dist/tenant/providers/InMemoryTenantProvider.d.ts +18 -0
  257. package/dist/tenant/providers/InMemoryTenantProvider.d.ts.map +1 -0
  258. package/dist/tenant/providers/InMemoryTenantProvider.js +137 -0
  259. package/dist/tenant/providers/InMemoryTenantProvider.js.map +1 -0
  260. package/package.json +48 -12
  261. package/src/agents/chat/chat.handler.ts +209 -0
  262. package/src/agents/chat/chat.schema.ts +33 -0
  263. package/src/agents/chat/chat.types.ts +46 -0
  264. package/src/agents/chat/chat.yaml +150 -0
  265. package/src/agents/chat/index.ts +21 -0
  266. package/src/agents/chromadb/chromadb.handler.ts +130 -0
  267. package/src/agents/chromadb/chromadb.schema.ts +35 -0
  268. package/src/agents/chromadb/chromadb.types.ts +52 -0
  269. package/src/agents/chromadb/chromadb.yaml +128 -0
  270. package/src/agents/chromadb/index.ts +20 -0
  271. package/src/agents/gemini-vectorize/gemini-vectorize.handler.ts +72 -0
  272. package/src/agents/gemini-vectorize/gemini-vectorize.schema.ts +22 -0
  273. package/src/agents/gemini-vectorize/gemini-vectorize.types.ts +34 -0
  274. package/src/agents/gemini-vectorize/gemini-vectorize.yaml +84 -0
  275. package/src/agents/gemini-vectorize/index.ts +20 -0
  276. package/src/agents/gitmcp/gitmcp.handler.ts +122 -0
  277. package/src/agents/gitmcp/gitmcp.schema.ts +20 -0
  278. package/src/agents/gitmcp/gitmcp.types.ts +33 -0
  279. package/src/agents/gitmcp/gitmcp.yaml +71 -0
  280. package/src/agents/gitmcp/index.ts +21 -0
  281. package/src/agents/image/image.handler.ts +82 -0
  282. package/src/agents/image/image.schema.ts +28 -0
  283. package/src/agents/image/image.types.ts +45 -0
  284. package/src/agents/image/image.yaml +86 -0
  285. package/src/agents/image/index.ts +19 -0
  286. package/src/agents/index.ts +59 -0
  287. package/src/agents/joker/index.ts +19 -0
  288. package/src/agents/joker/joker.handler.ts +60 -0
  289. package/src/agents/joker/joker.schema.ts +15 -0
  290. package/src/agents/joker/joker.types.ts +37 -0
  291. package/src/agents/joker/joker.yaml +47 -0
  292. package/src/agents/mcp-tool/index.ts +19 -0
  293. package/src/agents/mcp-tool/mcp-tool.handler.ts +112 -0
  294. package/src/agents/mcp-tool/mcp-tool.schema.ts +22 -0
  295. package/src/agents/mcp-tool/mcp-tool.types.ts +33 -0
  296. package/src/agents/mcp-tool/mcp-tool.yaml +71 -0
  297. package/src/agents/rag/index.ts +20 -0
  298. package/src/agents/rag/rag.handler.ts +119 -0
  299. package/src/agents/rag/rag.schema.ts +26 -0
  300. package/src/agents/rag/rag.types.ts +51 -0
  301. package/src/agents/rag/rag.yaml +89 -0
  302. package/src/agents/{agentRegistry.ts → registry/agentRegistry.ts} +161 -5
  303. package/src/agents/registry/index.ts +6 -0
  304. package/src/agents/translator/index.ts +19 -0
  305. package/src/agents/translator/translator.handler.ts +99 -0
  306. package/src/agents/translator/translator.schema.ts +30 -0
  307. package/src/agents/translator/translator.types.ts +42 -0
  308. package/src/agents/translator/translator.yaml +80 -0
  309. package/src/client/index.ts +53 -0
  310. package/src/client/types.ts +38 -0
  311. package/src/index.ts +48 -5
  312. package/src/runtime/declarativeAgentRuntime.ts +367 -489
  313. package/src/runtime/index.ts +31 -0
  314. package/src/runtime/workflowExecutor.ts +94 -0
  315. package/src/server/api/graphql.ts +109 -74
  316. package/src/server/index.ts +2 -2
  317. package/src/shared/index.ts +7 -0
  318. package/src/shared/types/agent.types.ts +80 -0
  319. package/src/shared/types/execution.types.ts +45 -0
  320. package/src/shared/types/index.ts +7 -0
  321. package/src/shared/types/schema.types.ts +55 -0
  322. package/src/shared/utils/index.ts +5 -0
  323. package/src/shared/utils/validation.ts +100 -0
  324. package/src/tenant/TenantManager.ts +488 -0
  325. package/src/tenant/index.ts +101 -0
  326. package/src/tenant/interfaces.ts +231 -0
  327. package/src/tenant/providerFactory.ts +75 -0
  328. package/src/tenant/providerRegistry.ts +86 -0
  329. package/src/tenant/providers/InMemoryTenantProvider.ts +168 -0
  330. package/dist/agents/agentRegistry.d.ts.map +0 -1
  331. package/dist/agents/agentRegistry.js.map +0 -1
  332. 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,57 @@ 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":
162
+ case 'genkit-joke':
187
163
  return this.executeGenkitJoke(step, variables, options);
188
- case "genkit-translation":
164
+ case 'genkit-translation':
189
165
  return this.executeGenkitTranslation(step, variables, options);
190
- case "genkit-image":
166
+ case 'genkit-image':
191
167
  return this.executeGenkitImage(step, variables, options);
192
- case "custom-action":
168
+ case 'custom-action':
193
169
  return this.executeCustomAction(step, variables, options);
170
+ case 'mcp-tool':
171
+ return this.executeMcpTool(step, variables, options);
172
+ case 'gemini-vectorize':
173
+ return this.executeGeminiVectorize(step, variables, options);
174
+ case 'chromadb':
175
+ return this.executeChromaDB(step, variables, options);
176
+ case 'gitmcp':
177
+ return this.executeGitMcp(step, variables, options);
178
+ case 'rag':
179
+ return this.executeRag(step, variables, options);
180
+ case 'chat':
181
+ return this.executeChat(step, variables, options);
182
+ case 'builtin-agent':
183
+ return this.executeBuiltinAgent(step, variables, options);
194
184
  default:
195
185
  throw new Error(`Unsupported workflow step type: ${step.type}`);
196
186
  }
197
187
  }
198
- /**
199
- * Execute output generator step
200
- */
188
+ // ============================================================================
189
+ // Output Generator (kept inline - orchestration logic)
190
+ // ============================================================================
201
191
  executeOutputGenerator(step, variables, options) {
202
- if (step.action?.type !== "generate" || !step.action.output) {
203
- throw new Error("Invalid output generator configuration");
192
+ if (step.action?.type !== 'generate' || !step.action.output) {
193
+ throw new Error('Invalid output generator configuration');
204
194
  }
205
- // Build output object
206
195
  const output = {};
207
- // Debug: Log available variables
208
- options.context.log(`Output generator: Available variables: ${Array.from(variables.keys()).join(", ")}`);
196
+ options.context.log(`Output generator: Available variables: ${Array.from(variables.keys()).join(', ')}`);
209
197
  for (const [key, valueExpr] of Object.entries(step.action.output)) {
210
- if (typeof valueExpr === "string" && valueExpr.startsWith("$")) {
198
+ if (typeof valueExpr === 'string' && valueExpr.startsWith('$')) {
211
199
  try {
212
200
  const reference = valueExpr.substring(1);
213
- options.context.log(`Output generator: Resolving reference ${valueExpr} -> ${reference}`);
214
201
  const resolved = this.resolveReference(reference, variables);
215
202
  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
203
  }
218
204
  catch (error) {
219
205
  options.context.log(`Output generator: Failed to resolve ${valueExpr}: ${error instanceof Error ? error.message : String(error)}`);
@@ -224,109 +210,177 @@ class DeclarativeAgentInterpreter {
224
210
  output[key] = valueExpr;
225
211
  }
226
212
  }
227
- options.context.log(`Output generator: Final output keys: ${Object.keys(output).join(", ")}`);
228
213
  return output;
229
214
  }
230
- /**
231
- * Execute Gemini Flash text helper for the joke agent
232
- */
215
+ // ============================================================================
216
+ // Delegated Handlers - Using extracted agent handlers
217
+ // ============================================================================
233
218
  async executeGenkitJoke(step, variables, options) {
234
- const prompt = typeof step.action?.prompt === "string" && step.action.prompt.trim().length
219
+ const prompt = typeof step.action?.prompt === 'string' && step.action.prompt.trim().length
235
220
  ? 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
221
+ : 'Tell a short and original joke that works for any audience.';
222
+ const temperature = typeof step.action?.temperature === 'number' ? step.action.temperature : 0.8;
223
+ const maxTokens = typeof step.action?.maxTokens === 'number' ? step.action.maxTokens : undefined;
224
+ const resultVar = typeof step.action?.result === 'string' && step.action.result.length > 0
244
225
  ? 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;
226
+ : 'jokerResult';
227
+ const result = await (0, workflowExecutor_1.executeJokeHandler)({ prompt, temperature, maxTokens }, options.props, options.context);
228
+ variables.set(resultVar, result);
229
+ return result;
249
230
  }
250
- /**
251
- * Execute translation step backed by Gemini Flash
252
- */
253
231
  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
232
+ const text = options.input?.texto || options.input?.text;
233
+ const sourceLanguage = options.input?.idioma_origem || options.input?.source_language;
234
+ const targetLanguage = options.input?.idioma_destino || options.input?.target_language;
235
+ const resultVar = typeof step.action?.result === 'string' && step.action.result.length > 0
258
236
  ? 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"
237
+ : 'translationResult';
238
+ const result = await (0, workflowExecutor_1.executeTranslationHandler)({
239
+ text,
240
+ source_language: sourceLanguage,
241
+ target_language: targetLanguage,
242
+ promptTemplate: typeof step.action?.promptTemplate === 'string'
265
243
  ? step.action.promptTemplate
266
244
  : undefined,
267
245
  }, options.props, options.context);
268
- variables.set(resultVar, translation);
269
- return translation;
246
+ variables.set(resultVar, result);
247
+ return result;
270
248
  }
271
- /**
272
- * Execute image generation step backed by Gemini Flash
273
- */
274
249
  async executeGenkitImage(step, variables, options) {
275
- const descricao = typeof options.input?.descricao === "string"
250
+ const description = typeof options.input?.descricao === 'string'
276
251
  ? options.input.descricao.trim()
277
- : "";
278
- const estilo = typeof options.input?.estilo === "string"
252
+ : typeof options.input?.description === 'string'
253
+ ? options.input.description.trim()
254
+ : '';
255
+ const style = typeof options.input?.estilo === 'string'
279
256
  ? options.input.estilo.trim()
280
- : "";
281
- const resolucaoInput = typeof options.input?.resolucao === "string"
257
+ : typeof options.input?.style === 'string'
258
+ ? options.input.style.trim()
259
+ : '';
260
+ const resolution = typeof options.input?.resolucao === 'string'
282
261
  ? options.input.resolucao.trim()
283
- : "";
284
- if (!descricao) {
285
- throw new Error("Missing required image input: descricao");
262
+ : typeof options.input?.resolution === 'string'
263
+ ? options.input.resolution.trim()
264
+ : '';
265
+ if (!description) {
266
+ throw new Error('Missing required image input: description');
286
267
  }
287
- if (!estilo) {
288
- throw new Error("Missing required image input: estilo");
268
+ if (!style) {
269
+ throw new Error('Missing required image input: style');
289
270
  }
290
- if (!resolucaoInput) {
291
- throw new Error("Missing required image input: resolucao");
271
+ if (!resolution) {
272
+ throw new Error('Missing required image input: resolution');
292
273
  }
293
- const promptTemplate = typeof step.action?.promptTemplate === "string" &&
274
+ const promptTemplate = typeof step.action?.promptTemplate === 'string' &&
294
275
  step.action.promptTemplate.trim().length > 0
295
276
  ? 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
277
+ : 'Create a detailed image in {{style}} style focusing on: {{description}}';
278
+ const resultVar = typeof step.action?.result === 'string' && step.action.result.length > 0
302
279
  ? step.action.result
303
- : "imageResult";
304
- const imageResult = await this.callGeminiFlashImage({
305
- prompt,
306
- estilo,
307
- resolucao: resolucaoInput,
280
+ : 'imageResult';
281
+ const result = await (0, workflowExecutor_1.executeImageHandler)({
282
+ description,
283
+ style,
284
+ resolution,
285
+ promptTemplate,
308
286
  }, 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;
287
+ variables.set(resultVar, result);
288
+ return result;
313
289
  }
314
- /**
315
- * Execute custom action backed by TypeScript implementation
316
- */
290
+ async executeMcpTool(step, variables, options) {
291
+ const serverUrl = this.resolveInputValue(step.action?.server_url, options.input, variables);
292
+ const toolName = this.resolveInputValue(step.action?.tool_name, options.input, variables);
293
+ const toolArguments = this.resolveInputValue(step.action?.tool_arguments, options.input, variables) || {};
294
+ const resultVar = step.action?.result || 'mcpResult';
295
+ const result = await (0, workflowExecutor_1.executeMcpToolHandler)({
296
+ server_url: serverUrl,
297
+ tool_name: toolName,
298
+ tool_arguments: toolArguments,
299
+ }, options.props, options.context);
300
+ variables.set(resultVar, result);
301
+ return result;
302
+ }
303
+ async executeGeminiVectorize(step, variables, options) {
304
+ const action = step.action?.action || 'embedSingle';
305
+ const resultVar = step.action?.result || 'vectorizeResult';
306
+ let result;
307
+ if (action === 'embedSingle') {
308
+ const text = this.resolveInputValue(step.action?.text, options.input, variables);
309
+ result = await (0, workflowExecutor_1.executeVectorizeHandler)({ action: 'embedSingle', text }, options.props, options.context);
310
+ }
311
+ else if (action === 'embedBatch') {
312
+ const texts = this.resolveInputValue(step.action?.texts, options.input, variables);
313
+ result = await (0, workflowExecutor_1.executeVectorizeHandler)({ action: 'embedBatch', texts }, options.props, options.context);
314
+ }
315
+ else {
316
+ throw new Error(`Unknown vectorize action: ${action}`);
317
+ }
318
+ variables.set(resultVar, result);
319
+ return result;
320
+ }
321
+ async executeChromaDB(step, variables, options) {
322
+ const action = this.resolveInputValue(step.action?.action, options.input, variables);
323
+ const collectionName = this.resolveInputValue(step.action?.collection_name, options.input, variables);
324
+ const resultVar = step.action?.result || 'chromaResult';
325
+ let params = { action, collection_name: collectionName };
326
+ if (action === 'hasData') {
327
+ params.min_count =
328
+ this.resolveInputValue(step.action?.min_count, options.input, variables) || 1;
329
+ }
330
+ else if (action === 'store') {
331
+ params.ids = this.resolveInputValue(step.action?.ids, options.input, variables);
332
+ params.vectors = this.resolveInputValue(step.action?.vectors, options.input, variables);
333
+ params.documents = this.resolveInputValue(step.action?.documents, options.input, variables);
334
+ params.metadatas = this.resolveInputValue(step.action?.metadatas, options.input, variables);
335
+ }
336
+ else if (action === 'search') {
337
+ params.query_vector = this.resolveInputValue(step.action?.query_vector, options.input, variables);
338
+ params.limit =
339
+ this.resolveInputValue(step.action?.limit, options.input, variables) || 5;
340
+ }
341
+ const result = await (0, workflowExecutor_1.executeChromaDBHandler)(params, options.props, options.context);
342
+ variables.set(resultVar, result);
343
+ return result;
344
+ }
345
+ async executeGitMcp(step, variables, options) {
346
+ const gitmcpUrl = this.resolveInputValue(step.action?.gitmcp_url, options.input, variables);
347
+ const resultVar = step.action?.result || 'gitmcpResult';
348
+ const result = await (0, workflowExecutor_1.executeGitMcpHandler)({ gitmcp_url: gitmcpUrl }, options.props, options.context);
349
+ variables.set(resultVar, result);
350
+ return result;
351
+ }
352
+ async executeRag(step, variables, options) {
353
+ const query = this.resolveInputValue(step.action?.query, options.input, variables);
354
+ const context = this.resolveInputValue(step.action?.context, options.input, variables) ||
355
+ this.resolveInputValue(step.action?.documents, options.input, variables);
356
+ const history = this.resolveInputValue(step.action?.history, options.input, variables);
357
+ const resultVar = step.action?.result || 'ragResult';
358
+ const result = await (0, workflowExecutor_1.executeRagHandler)({ query, context, documents: context, history }, options.props, options.context);
359
+ variables.set(resultVar, result);
360
+ return result;
361
+ }
362
+ async executeChat(step, variables, options) {
363
+ const messages = this.resolveInputValue(step.action?.messages, options.input, variables);
364
+ const query = this.resolveInputValue(step.action?.query, options.input, variables);
365
+ const resultVar = step.action?.result || 'chatResult';
366
+ const result = await (0, workflowExecutor_1.executeChatHandler)({ messages, query }, options.props, options.context);
367
+ variables.set(resultVar, result);
368
+ return result;
369
+ }
370
+ // ============================================================================
371
+ // Custom Action & Builtin Agent (orchestration logic)
372
+ // ============================================================================
317
373
  async executeCustomAction(step, variables, options) {
318
374
  const functionName = step.action?.function;
319
375
  if (!functionName) {
320
376
  throw new Error("Missing 'function' in custom-action");
321
377
  }
322
378
  options.context.log(`Custom action: Looking up function '${functionName}'`);
323
- // Retrieve Code Implementation
324
- const customFunc = agentRegistry_1.agentRegistry.getCustomFunction(functionName);
379
+ const customFunc = registry_1.agentRegistry.getCustomFunction(functionName);
325
380
  if (!customFunc) {
326
381
  throw new Error(`Custom function '${functionName}' not found in registry. ` +
327
382
  `Make sure the corresponding .ts file is in the /agents directory.`);
328
383
  }
329
- // Prepare Arguments
330
384
  const args = {
331
385
  input: options.input,
332
386
  variables: Object.fromEntries(variables),
@@ -334,13 +388,10 @@ class DeclarativeAgentInterpreter {
334
388
  context: options.context,
335
389
  };
336
390
  options.context.log(`Custom action: Executing function '${functionName}'`);
337
- // Execute Code
338
391
  try {
339
392
  const result = await customFunc(args);
340
- // Save Result
341
393
  if (step.action.result) {
342
394
  variables.set(step.action.result, result);
343
- options.context.log(`Custom action: Saved result to variable '${step.action.result}'`);
344
395
  }
345
396
  return result;
346
397
  }
@@ -351,266 +402,108 @@ class DeclarativeAgentInterpreter {
351
402
  throw new Error(`Custom action execution failed: ${errorMessage}`);
352
403
  }
353
404
  }
354
- /**
355
- * Evaluate value expression
356
- */
405
+ async executeBuiltinAgent(step, variables, options) {
406
+ const agentName = step.action?.agent;
407
+ const agentInput = this.resolveInputValue(step.action?.input, options.input, variables) || options.input;
408
+ const agentProps = step.action?.props || options.props;
409
+ const resultVar = step.action?.result || 'builtinResult';
410
+ if (!agentName) {
411
+ throw new Error('Missing required builtin-agent input: agent');
412
+ }
413
+ options.context.log(`[Builtin Agent] Invoking agent: ${agentName}`);
414
+ try {
415
+ const result = await registry_1.agentRegistry.executeAgent(agentName, agentInput, agentProps, options.context);
416
+ variables.set(resultVar, result);
417
+ return result;
418
+ }
419
+ catch (error) {
420
+ const message = error instanceof Error ? error.message : String(error);
421
+ options.context.log(`[Builtin Agent] Error: ${message}`);
422
+ throw new Error(`Builtin agent '${agentName}' execution failed: ${message}`);
423
+ }
424
+ }
425
+ // ============================================================================
426
+ // Helper Methods
427
+ // ============================================================================
428
+ resolveInputValue(value, input, variables) {
429
+ if (value === undefined || value === null)
430
+ return undefined;
431
+ if (typeof value === 'string' && value.startsWith('$')) {
432
+ const ref = value.substring(1);
433
+ if (ref.startsWith('input.')) {
434
+ const inputKey = ref.substring(6);
435
+ return this.getNestedValue(input, inputKey);
436
+ }
437
+ return this.resolveReference(ref, variables);
438
+ }
439
+ if (typeof value === 'string' && input[value] !== undefined) {
440
+ return input[value];
441
+ }
442
+ return value;
443
+ }
444
+ getNestedValue(obj, path) {
445
+ const parts = path.split('.');
446
+ let current = obj;
447
+ for (const part of parts) {
448
+ if (current == null)
449
+ return undefined;
450
+ current = current[part];
451
+ }
452
+ return current;
453
+ }
357
454
  evaluateValue(expr, variables) {
358
- // Handle string literals
359
455
  if (expr.startsWith('"') && expr.endsWith('"')) {
360
456
  if (expr.length - 2 > this.MAX_VARIABLE_SIZE) {
361
- throw new Error("Variable initialization exceeds maximum size");
457
+ throw new Error('Variable initialization exceeds maximum size');
362
458
  }
363
459
  return expr.slice(1, -1);
364
460
  }
365
461
  if (expr.startsWith("'") && expr.endsWith("'")) {
366
462
  if (expr.length - 2 > this.MAX_VARIABLE_SIZE) {
367
- throw new Error("Variable initialization exceeds maximum size");
463
+ throw new Error('Variable initialization exceeds maximum size');
368
464
  }
369
465
  return expr.slice(1, -1);
370
466
  }
371
467
  if (expr.length > this.MAX_VARIABLE_SIZE) {
372
- throw new Error("Variable initialization exceeds maximum size");
468
+ throw new Error('Variable initialization exceeds maximum size');
373
469
  }
374
- // Handle boolean literals
375
- if (expr === "true")
470
+ if (expr === 'true')
376
471
  return true;
377
- if (expr === "false")
472
+ if (expr === 'false')
378
473
  return false;
379
- // Handle null literal
380
- if (expr === "null")
474
+ if (expr === 'null')
381
475
  return null;
382
- // Handle variable references
383
- if (expr.startsWith("$")) {
476
+ if (expr.startsWith('$')) {
384
477
  return this.resolveReference(expr.substring(1), variables);
385
478
  }
386
- // Handle numbers
387
479
  if (/^-?\d+$/.test(expr))
388
480
  return parseInt(expr, 10);
389
481
  if (/^-?\d+\.\d+$/.test(expr))
390
482
  return parseFloat(expr);
391
483
  throw new Error(`Unsupported value expression: ${expr}`);
392
484
  }
393
- /**
394
- * Validate variable declaration
395
- */
396
485
  validateVariable(variable) {
397
486
  if (!variable.name || !variable.type) {
398
- throw new Error("Invalid variable declaration: missing name or type");
487
+ throw new Error('Invalid variable declaration: missing name or type');
399
488
  }
400
- if (!["string", "number", "boolean", "object"].includes(variable.type)) {
489
+ if (!['string', 'number', 'boolean', 'object'].includes(variable.type)) {
401
490
  throw new Error(`Unsupported variable type: ${variable.type}`);
402
491
  }
403
492
  }
404
- /**
405
- * Resolve variable reference, including nested properties (e.g., foo.bar.baz)
406
- */
407
493
  resolveReference(reference, variables) {
408
- const [varName, ...pathSegments] = reference.split(".");
494
+ const [varName, ...pathSegments] = reference.split('.');
409
495
  let value = variables.get(varName);
410
496
  if (value === undefined) {
411
497
  throw new Error(`Undefined variable referenced: ${varName}`);
412
498
  }
413
499
  for (const segment of pathSegments) {
414
- if (value == null || typeof value !== "object") {
500
+ if (value == null || typeof value !== 'object') {
415
501
  throw new Error(`Cannot resolve path '${reference}': segment '${segment}' is invalid`);
416
502
  }
417
503
  value = value[segment];
418
504
  }
419
505
  return value;
420
506
  }
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
507
  }
615
508
  exports.DeclarativeAgentInterpreter = DeclarativeAgentInterpreter;
616
509
  // Singleton instance