nodal-agents 0.1.2 → 0.1.4

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 (265) hide show
  1. package/README.md +81 -81
  2. package/cli.js +77 -20
  3. package/migrations/0000_flashy_clea.sql +528 -528
  4. package/migrations/0001_exotic_shooting_star.sql +2 -2
  5. package/migrations/0002_gray_devos.sql +38 -38
  6. package/migrations/0004_married_deadpool.sql +2 -2
  7. package/migrations/0006_credentials_table.sql +24 -24
  8. package/migrations/0007_free_speed.sql +16 -16
  9. package/migrations/0008_curious_thor_girl.sql +16 -16
  10. package/migrations/0009_agent_memory_token_budget.sql +1 -0
  11. package/migrations/0010_agent_workspace_root.sql +1 -0
  12. package/migrations/0011_agent_jobs_failed_delegations_count.sql +1 -0
  13. package/migrations/0012_agent_jobs_last_failed_delegation_slug.sql +2 -0
  14. package/migrations/0013_cascade_agent_fks.sql +39 -0
  15. package/migrations/0014_mcp_server_credentials.sql +24 -0
  16. package/migrations/0015_agent_mcp_servers_unique.sql +14 -0
  17. package/migrations/0016_drop_connector_entity_slug_unique.sql +10 -0
  18. package/migrations/0017_drop_mcp_server_entity_slug_unique.sql +9 -0
  19. package/migrations/meta/0009_snapshot.json +4712 -0
  20. package/migrations/meta/0010_snapshot.json +4718 -0
  21. package/migrations/meta/_journal.json +63 -0
  22. package/package.json +1 -1
  23. package/runner.js +22726 -8489
  24. package/web/.next/BUILD_ID +1 -1
  25. package/web/.next/app-path-routes-manifest.json +3 -2
  26. package/web/.next/build-manifest.json +6 -6
  27. package/web/.next/prerender-manifest.json +3 -3
  28. package/web/.next/react-loadable-manifest.json +2 -2
  29. package/web/.next/required-server-files.json +4 -5
  30. package/web/.next/routes-manifest.json +6 -0
  31. package/web/.next/server/app/(dashboard)/agents/[id]/edit/page.js +2 -2
  32. package/web/.next/server/app/(dashboard)/agents/[id]/edit/page.js.nft.json +1 -1
  33. package/web/.next/server/app/(dashboard)/agents/[id]/edit/page_client-reference-manifest.js +1 -1
  34. package/web/.next/server/app/(dashboard)/agents/[id]/telegram/page.js +2 -2
  35. package/web/.next/server/app/(dashboard)/agents/[id]/telegram/page.js.nft.json +1 -1
  36. package/web/.next/server/app/(dashboard)/agents/[id]/telegram/page_client-reference-manifest.js +1 -1
  37. package/web/.next/server/app/(dashboard)/agents/page.js +2 -2
  38. package/web/.next/server/app/(dashboard)/agents/page.js.nft.json +1 -1
  39. package/web/.next/server/app/(dashboard)/agents/page_client-reference-manifest.js +1 -1
  40. package/web/.next/server/app/(dashboard)/approvals/page.js +2 -2
  41. package/web/.next/server/app/(dashboard)/approvals/page.js.nft.json +1 -1
  42. package/web/.next/server/app/(dashboard)/approvals/page_client-reference-manifest.js +1 -1
  43. package/web/.next/server/app/(dashboard)/automations/page.js +2 -2
  44. package/web/.next/server/app/(dashboard)/automations/page.js.nft.json +1 -1
  45. package/web/.next/server/app/(dashboard)/automations/page_client-reference-manifest.js +1 -1
  46. package/web/.next/server/app/(dashboard)/billing/page.js +2 -2
  47. package/web/.next/server/app/(dashboard)/billing/page.js.nft.json +1 -1
  48. package/web/.next/server/app/(dashboard)/billing/page_client-reference-manifest.js +1 -1
  49. package/web/.next/server/app/(dashboard)/connectors/page.js +2 -2
  50. package/web/.next/server/app/(dashboard)/connectors/page.js.nft.json +1 -1
  51. package/web/.next/server/app/(dashboard)/connectors/page_client-reference-manifest.js +1 -1
  52. package/web/.next/server/app/(dashboard)/credentials/page.js +2 -2
  53. package/web/.next/server/app/(dashboard)/credentials/page.js.nft.json +1 -1
  54. package/web/.next/server/app/(dashboard)/credentials/page_client-reference-manifest.js +1 -1
  55. package/web/.next/server/app/(dashboard)/jobs/[id]/page.js +2 -2
  56. package/web/.next/server/app/(dashboard)/jobs/[id]/page.js.nft.json +1 -1
  57. package/web/.next/server/app/(dashboard)/jobs/[id]/page_client-reference-manifest.js +1 -1
  58. package/web/.next/server/app/(dashboard)/jobs/page.js +2 -2
  59. package/web/.next/server/app/(dashboard)/jobs/page.js.nft.json +1 -1
  60. package/web/.next/server/app/(dashboard)/jobs/page_client-reference-manifest.js +1 -1
  61. package/web/.next/server/app/(dashboard)/logs/page.js +2 -2
  62. package/web/.next/server/app/(dashboard)/logs/page.js.nft.json +1 -1
  63. package/web/.next/server/app/(dashboard)/logs/page_client-reference-manifest.js +1 -1
  64. package/web/.next/server/app/(dashboard)/mcp/page.js +2 -0
  65. package/web/.next/server/app/(dashboard)/mcp/page.js.nft.json +1 -0
  66. package/web/.next/server/app/(dashboard)/mcp/page_client-reference-manifest.js +1 -0
  67. package/web/.next/server/app/(dashboard)/memories/page.js +2 -2
  68. package/web/.next/server/app/(dashboard)/memories/page.js.nft.json +1 -1
  69. package/web/.next/server/app/(dashboard)/memories/page_client-reference-manifest.js +1 -1
  70. package/web/.next/server/app/(dashboard)/settings/page.js +2 -2
  71. package/web/.next/server/app/(dashboard)/settings/page.js.nft.json +1 -1
  72. package/web/.next/server/app/(dashboard)/settings/page_client-reference-manifest.js +1 -1
  73. package/web/.next/server/app/(dashboard)/skills/[id]/edit/page.js +2 -2
  74. package/web/.next/server/app/(dashboard)/skills/[id]/edit/page.js.nft.json +1 -1
  75. package/web/.next/server/app/(dashboard)/skills/[id]/edit/page_client-reference-manifest.js +1 -1
  76. package/web/.next/server/app/(dashboard)/skills/page.js +2 -2
  77. package/web/.next/server/app/(dashboard)/skills/page.js.nft.json +1 -1
  78. package/web/.next/server/app/(dashboard)/skills/page_client-reference-manifest.js +1 -1
  79. package/web/.next/server/app/(dashboard)/stats/page.js +2 -2
  80. package/web/.next/server/app/(dashboard)/stats/page.js.nft.json +1 -1
  81. package/web/.next/server/app/(dashboard)/stats/page_client-reference-manifest.js +1 -1
  82. package/web/.next/server/app/_global-error/page.js +3 -3
  83. package/web/.next/server/app/_global-error/page_client-reference-manifest.js +1 -1
  84. package/web/.next/server/app/_global-error.html +1 -1
  85. package/web/.next/server/app/_global-error.rsc +3 -3
  86. package/web/.next/server/app/_global-error.segments/_full.segment.rsc +3 -3
  87. package/web/.next/server/app/_global-error.segments/_global-error/__PAGE__.segment.rsc +1 -1
  88. package/web/.next/server/app/_global-error.segments/_global-error.segment.rsc +1 -1
  89. package/web/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  90. package/web/.next/server/app/_global-error.segments/_index.segment.rsc +3 -3
  91. package/web/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  92. package/web/.next/server/app/_not-found/page.js +2 -2
  93. package/web/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  94. package/web/.next/server/app/_not-found.html +1 -1
  95. package/web/.next/server/app/_not-found.rsc +4 -4
  96. package/web/.next/server/app/_not-found.segments/_full.segment.rsc +4 -4
  97. package/web/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  98. package/web/.next/server/app/_not-found.segments/_index.segment.rsc +4 -4
  99. package/web/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +2 -2
  100. package/web/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  101. package/web/.next/server/app/_not-found.segments/_tree.segment.rsc +2 -2
  102. package/web/.next/server/app/api/auth/[...all]/route.js +1 -1
  103. package/web/.next/server/app/api/auth/[...all]/route.js.nft.json +1 -1
  104. package/web/.next/server/app/api/auth/[...all]/route_client-reference-manifest.js +1 -1
  105. package/web/.next/server/app/api/health/route.js +1 -1
  106. package/web/.next/server/app/api/health/route_client-reference-manifest.js +1 -1
  107. package/web/.next/server/app/api/oauth/[provider]/callback/route.js +1 -1
  108. package/web/.next/server/app/api/oauth/[provider]/callback/route.js.nft.json +1 -1
  109. package/web/.next/server/app/api/oauth/[provider]/callback/route_client-reference-manifest.js +1 -1
  110. package/web/.next/server/app/api/oauth/[provider]/start/route.js +1 -1
  111. package/web/.next/server/app/api/oauth/[provider]/start/route.js.nft.json +1 -1
  112. package/web/.next/server/app/api/oauth/[provider]/start/route_client-reference-manifest.js +1 -1
  113. package/web/.next/server/app/auth/callback/route.js +1 -1
  114. package/web/.next/server/app/auth/callback/route_client-reference-manifest.js +1 -1
  115. package/web/.next/server/app/index.html +1 -1
  116. package/web/.next/server/app/index.rsc +4 -4
  117. package/web/.next/server/app/index.segments/__PAGE__.segment.rsc +1 -1
  118. package/web/.next/server/app/index.segments/_full.segment.rsc +4 -4
  119. package/web/.next/server/app/index.segments/_head.segment.rsc +1 -1
  120. package/web/.next/server/app/index.segments/_index.segment.rsc +4 -4
  121. package/web/.next/server/app/index.segments/_tree.segment.rsc +2 -2
  122. package/web/.next/server/app/login/page.js +2 -2
  123. package/web/.next/server/app/login/page.js.nft.json +1 -1
  124. package/web/.next/server/app/login/page_client-reference-manifest.js +1 -1
  125. package/web/.next/server/app/onboarding/page.js +2 -2
  126. package/web/.next/server/app/onboarding/page_client-reference-manifest.js +1 -1
  127. package/web/.next/server/app/onboarding.html +1 -1
  128. package/web/.next/server/app/onboarding.rsc +4 -4
  129. package/web/.next/server/app/onboarding.segments/_full.segment.rsc +4 -4
  130. package/web/.next/server/app/onboarding.segments/_head.segment.rsc +1 -1
  131. package/web/.next/server/app/onboarding.segments/_index.segment.rsc +4 -4
  132. package/web/.next/server/app/onboarding.segments/_tree.segment.rsc +2 -2
  133. package/web/.next/server/app/onboarding.segments/onboarding/__PAGE__.segment.rsc +1 -1
  134. package/web/.next/server/app/onboarding.segments/onboarding.segment.rsc +1 -1
  135. package/web/.next/server/app/page.js +2 -2
  136. package/web/.next/server/app/page_client-reference-manifest.js +1 -1
  137. package/web/.next/server/app-paths-manifest.json +3 -2
  138. package/web/.next/server/chunks/134.js +1 -0
  139. package/web/.next/server/chunks/{699.js → 145.js} +1 -1
  140. package/web/.next/server/chunks/159.js +4 -4
  141. package/web/.next/server/chunks/184.js +2 -0
  142. package/web/.next/server/chunks/352.js +16 -0
  143. package/web/.next/server/chunks/437.js +62 -0
  144. package/web/.next/server/chunks/574.js +1 -1
  145. package/web/.next/server/chunks/631.js +12 -0
  146. package/web/.next/server/chunks/676.js +1 -0
  147. package/web/.next/server/chunks/807.js +1 -1
  148. package/web/.next/server/chunks/{606.js → 826.js} +31 -31
  149. package/web/.next/server/middleware-build-manifest.js +1 -1
  150. package/web/.next/server/middleware-react-loadable-manifest.js +1 -1
  151. package/web/.next/server/middleware.js +1 -1
  152. package/web/.next/server/pages/404.html +1 -1
  153. package/web/.next/server/pages/500.html +1 -1
  154. package/web/.next/server/server-reference-manifest.js +1 -1
  155. package/web/.next/server/server-reference-manifest.json +1 -1
  156. package/web/.next/static/2lmxaWvI1cL9_1Ob3gIFq/_buildManifest.js +1 -0
  157. package/web/.next/static/chunks/1045-82c87c31d5a8f54b.js +1 -0
  158. package/web/.next/static/chunks/2186-88c3d89f10bc57c3.js +1 -0
  159. package/web/.next/static/chunks/3363-613d9ccc7fe8a233.js +1 -0
  160. package/web/.next/static/chunks/3426-ddba5bb6b1e3f0ee.js +1 -0
  161. package/web/.next/static/chunks/4678-5cbc08f56a4fb74d.js +1 -0
  162. package/web/.next/static/chunks/7203.f516c74ab9532e2b.js +1 -0
  163. package/web/.next/static/chunks/{724-1d09b7ea367babbe.js → 8724-68ad0e948ea9a1cd.js} +1 -1
  164. package/web/.next/static/chunks/9174.9225c199db752381.js +1 -0
  165. package/web/.next/static/chunks/9504-9ba984747b116953.js +1 -0
  166. package/web/.next/static/chunks/a7a8b010-8a97df7bbea35b50.js +1 -0
  167. package/web/.next/static/chunks/app/(dashboard)/agents/[id]/edit/page-2c38c08bef6182ce.js +1 -0
  168. package/web/.next/static/chunks/app/(dashboard)/agents/[id]/telegram/page-9ddc8c77a1ec33df.js +1 -0
  169. package/web/.next/static/chunks/app/(dashboard)/agents/page-567400cb256c565d.js +1 -0
  170. package/web/.next/static/chunks/app/(dashboard)/approvals/page-38f4fe347d505bff.js +1 -0
  171. package/web/.next/static/chunks/app/(dashboard)/automations/page-d8c09fb42eeeca4d.js +1 -0
  172. package/web/.next/static/chunks/app/(dashboard)/billing/page-736acdd0781484e6.js +1 -0
  173. package/web/.next/static/chunks/app/(dashboard)/connectors/page-63889db4bf76fe10.js +1 -0
  174. package/web/.next/static/chunks/app/(dashboard)/credentials/page-4867266b3111cdf6.js +1 -0
  175. package/web/.next/static/chunks/app/(dashboard)/jobs/[id]/page-285ef9a609cc1190.js +1 -0
  176. package/web/.next/static/chunks/app/(dashboard)/jobs/page-8b0b38b7651507ba.js +1 -0
  177. package/web/.next/static/chunks/app/(dashboard)/layout-5bf62b7b4daa56d5.js +2 -0
  178. package/web/.next/static/chunks/app/(dashboard)/logs/page-8e809e843e8a6f76.js +1 -0
  179. package/web/.next/static/chunks/app/(dashboard)/mcp/page-77dd7810003d6437.js +1 -0
  180. package/web/.next/static/chunks/app/(dashboard)/memories/page-f4541a2f37851596.js +1 -0
  181. package/web/.next/static/chunks/app/(dashboard)/settings/page-95e9ff0349e579ef.js +1 -0
  182. package/web/.next/static/chunks/app/(dashboard)/skills/[id]/edit/page-a1a65f3cc8a9df31.js +1 -0
  183. package/web/.next/static/chunks/app/(dashboard)/skills/page-747e409f9f34cc3c.js +1 -0
  184. package/web/.next/static/chunks/app/(dashboard)/stats/page-9162acbb9015dd27.js +1 -0
  185. package/web/.next/static/chunks/app/_global-error/page-9162acbb9015dd27.js +1 -0
  186. package/web/.next/static/chunks/app/_not-found/page-9162acbb9015dd27.js +1 -0
  187. package/web/.next/static/chunks/app/api/auth/[...all]/route-9162acbb9015dd27.js +1 -0
  188. package/web/.next/static/chunks/app/api/health/route-9162acbb9015dd27.js +1 -0
  189. package/web/.next/static/chunks/app/api/oauth/[provider]/callback/route-9162acbb9015dd27.js +1 -0
  190. package/web/.next/static/chunks/app/api/oauth/[provider]/start/route-9162acbb9015dd27.js +1 -0
  191. package/web/.next/static/chunks/app/auth/callback/route-9162acbb9015dd27.js +1 -0
  192. package/web/.next/static/chunks/app/error-055d3c6a12b2b05a.js +1 -0
  193. package/web/.next/static/chunks/app/layout-c01e1c13a9f4e701.js +1 -0
  194. package/web/.next/static/chunks/app/login/page-a47d35197589a25b.js +1 -0
  195. package/web/.next/static/chunks/app/not-found-736acdd0781484e6.js +1 -0
  196. package/web/.next/static/chunks/app/onboarding/page-9162acbb9015dd27.js +1 -0
  197. package/web/.next/static/chunks/app/page-9162acbb9015dd27.js +1 -0
  198. package/web/.next/static/chunks/e5009a55-c08124f2223b51cc.js +1 -0
  199. package/web/.next/static/chunks/framework-dfbc3562811a52e8.js +1 -0
  200. package/web/.next/static/chunks/main-200183420347a1ea.js +5 -0
  201. package/web/.next/static/chunks/main-app-d81ba9a45427346e.js +1 -0
  202. package/web/.next/static/chunks/next/dist/client/components/builtin/app-error-9162acbb9015dd27.js +1 -0
  203. package/web/.next/static/chunks/next/dist/client/components/builtin/forbidden-9162acbb9015dd27.js +1 -0
  204. package/web/.next/static/chunks/next/dist/client/components/builtin/global-error-146c676c80b91e46.js +1 -0
  205. package/web/.next/static/chunks/next/dist/client/components/builtin/unauthorized-9162acbb9015dd27.js +1 -0
  206. package/web/.next/static/chunks/webpack-821bd0359b891822.js +1 -0
  207. package/web/.next/static/css/221ca0dcaf2fa31f.css +1 -0
  208. package/web/server.js +1 -1
  209. package/web/.next/server/chunks/376.js +0 -1
  210. package/web/.next/server/chunks/515.js +0 -2
  211. package/web/.next/server/chunks/605.js +0 -12
  212. package/web/.next/server/chunks/754.js +0 -62
  213. package/web/.next/server/chunks/856.js +0 -1
  214. package/web/.next/server/chunks/869.js +0 -1
  215. package/web/.next/static/PYiZWn1aFZDBgQuyV7Mwx/_buildManifest.js +0 -1
  216. package/web/.next/static/chunks/174.f5bd28884efa0000.js +0 -1
  217. package/web/.next/static/chunks/203.02a2bd001ebbe608.js +0 -1
  218. package/web/.next/static/chunks/231-fbb2baea2de90085.js +0 -1
  219. package/web/.next/static/chunks/363-483f33abe1809381.js +0 -1
  220. package/web/.next/static/chunks/45-b78e94bb1c396542.js +0 -1
  221. package/web/.next/static/chunks/504-baed39064a242351.js +0 -1
  222. package/web/.next/static/chunks/511-487710d0fe16fbe3.js +0 -1
  223. package/web/.next/static/chunks/678-46261e73dea11bc7.js +0 -1
  224. package/web/.next/static/chunks/a7a8b010-64b9ea0922a3e9c1.js +0 -1
  225. package/web/.next/static/chunks/app/(dashboard)/agents/[id]/edit/page-1cbc88f6ea30c04e.js +0 -1
  226. package/web/.next/static/chunks/app/(dashboard)/agents/[id]/telegram/page-c3393e2e0665b0a7.js +0 -1
  227. package/web/.next/static/chunks/app/(dashboard)/agents/page-fe6937dec50415e9.js +0 -1
  228. package/web/.next/static/chunks/app/(dashboard)/approvals/page-9509351c92665fc1.js +0 -1
  229. package/web/.next/static/chunks/app/(dashboard)/automations/page-d06b5eb3ec1ada30.js +0 -1
  230. package/web/.next/static/chunks/app/(dashboard)/billing/page-88165ec8f0c4df6b.js +0 -1
  231. package/web/.next/static/chunks/app/(dashboard)/connectors/page-9189af92fc7cddd4.js +0 -1
  232. package/web/.next/static/chunks/app/(dashboard)/credentials/page-9ad4cfdfb3fda068.js +0 -1
  233. package/web/.next/static/chunks/app/(dashboard)/jobs/[id]/page-fdaeff5be0544e4c.js +0 -1
  234. package/web/.next/static/chunks/app/(dashboard)/jobs/page-c1ddb55d4de1ae7d.js +0 -1
  235. package/web/.next/static/chunks/app/(dashboard)/layout-7ad84dfaa376ab9f.js +0 -2
  236. package/web/.next/static/chunks/app/(dashboard)/logs/page-a6006d9cc2590a0a.js +0 -1
  237. package/web/.next/static/chunks/app/(dashboard)/memories/page-8466e02527ae909b.js +0 -1
  238. package/web/.next/static/chunks/app/(dashboard)/settings/page-d7dd2b7586e23ec9.js +0 -1
  239. package/web/.next/static/chunks/app/(dashboard)/skills/[id]/edit/page-7c1e1566a93b3a65.js +0 -1
  240. package/web/.next/static/chunks/app/(dashboard)/skills/page-30cbb1e29d7e5147.js +0 -1
  241. package/web/.next/static/chunks/app/(dashboard)/stats/page-ddf08b608a2840c5.js +0 -1
  242. package/web/.next/static/chunks/app/_global-error/page-ddf08b608a2840c5.js +0 -1
  243. package/web/.next/static/chunks/app/_not-found/page-ddf08b608a2840c5.js +0 -1
  244. package/web/.next/static/chunks/app/api/auth/[...all]/route-ddf08b608a2840c5.js +0 -1
  245. package/web/.next/static/chunks/app/api/health/route-ddf08b608a2840c5.js +0 -1
  246. package/web/.next/static/chunks/app/api/oauth/[provider]/callback/route-ddf08b608a2840c5.js +0 -1
  247. package/web/.next/static/chunks/app/api/oauth/[provider]/start/route-ddf08b608a2840c5.js +0 -1
  248. package/web/.next/static/chunks/app/auth/callback/route-ddf08b608a2840c5.js +0 -1
  249. package/web/.next/static/chunks/app/error-41d8134c91e8652d.js +0 -1
  250. package/web/.next/static/chunks/app/layout-fb836a3464648614.js +0 -1
  251. package/web/.next/static/chunks/app/login/page-176e4c02453c9ce9.js +0 -1
  252. package/web/.next/static/chunks/app/not-found-88165ec8f0c4df6b.js +0 -1
  253. package/web/.next/static/chunks/app/onboarding/page-ddf08b608a2840c5.js +0 -1
  254. package/web/.next/static/chunks/app/page-ddf08b608a2840c5.js +0 -1
  255. package/web/.next/static/chunks/e5009a55-3b270d90dfdebefa.js +0 -1
  256. package/web/.next/static/chunks/framework-a208e71e7c780968.js +0 -1
  257. package/web/.next/static/chunks/main-949172f5a58d52c4.js +0 -5
  258. package/web/.next/static/chunks/main-app-ad34d1b1511b9a1c.js +0 -1
  259. package/web/.next/static/chunks/next/dist/client/components/builtin/app-error-ddf08b608a2840c5.js +0 -1
  260. package/web/.next/static/chunks/next/dist/client/components/builtin/forbidden-ddf08b608a2840c5.js +0 -1
  261. package/web/.next/static/chunks/next/dist/client/components/builtin/global-error-c836ffb6bc7442ca.js +0 -1
  262. package/web/.next/static/chunks/next/dist/client/components/builtin/unauthorized-ddf08b608a2840c5.js +0 -1
  263. package/web/.next/static/chunks/webpack-ea6870dc3308aa05.js +0 -1
  264. package/web/.next/static/css/bd2cf2f17af36e40.css +0 -1
  265. /package/web/.next/static/{PYiZWn1aFZDBgQuyV7Mwx → 2lmxaWvI1cL9_1Ob3gIFq}/_ssgManifest.js +0 -0
@@ -1,529 +1,529 @@
1
- CREATE TABLE "user_profiles" (
2
- "user_id" uuid PRIMARY KEY NOT NULL,
3
- "display_name" text,
4
- "avatar_url" text,
5
- "timezone" text DEFAULT 'UTC' NOT NULL,
6
- "locale" text DEFAULT 'en' NOT NULL,
7
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
8
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL
9
- );
10
- --> statement-breakpoint
11
- CREATE TABLE "users" (
12
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
13
- "email" text NOT NULL,
14
- "password_hash" text,
15
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
16
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
17
- CONSTRAINT "users_email_unique" UNIQUE("email")
18
- );
19
- --> statement-breakpoint
20
- CREATE TABLE "entities" (
21
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
22
- "user_id" uuid NOT NULL,
23
- "name" text NOT NULL,
24
- "slug" text NOT NULL,
25
- "description" text,
26
- "icon" text DEFAULT '🏢',
27
- "industry" text,
28
- "goal" text,
29
- "mcp_token" uuid DEFAULT gen_random_uuid(),
30
- "created_at" timestamp with time zone DEFAULT now(),
31
- "updated_at" timestamp with time zone DEFAULT now(),
32
- CONSTRAINT "entities_slug_unique" UNIQUE("slug")
33
- );
34
- --> statement-breakpoint
35
- CREATE TABLE "entity_members" (
36
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
37
- "entity_id" uuid NOT NULL,
38
- "user_id" uuid NOT NULL,
39
- "role" text DEFAULT 'owner',
40
- "created_at" timestamp with time zone DEFAULT now(),
41
- CONSTRAINT "entity_members_role_check" CHECK ("entity_members"."role" IN ('owner', 'admin', 'member', 'viewer'))
42
- );
43
- --> statement-breakpoint
44
- CREATE TABLE "agent_assignments" (
45
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
46
- "orchestrator_id" uuid NOT NULL,
47
- "sub_agent_id" uuid NOT NULL,
48
- "entity_id" uuid NOT NULL,
49
- "instructions" text,
50
- "created_at" timestamp with time zone DEFAULT now() NOT NULL
51
- );
52
- --> statement-breakpoint
53
- CREATE TABLE "agent_budgets" (
54
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
55
- "agent_id" uuid,
56
- "entity_id" uuid,
57
- "daily_token_limit" bigint DEFAULT 0,
58
- "monthly_token_limit" bigint DEFAULT 0,
59
- "alert_threshold_pct" integer DEFAULT 80,
60
- "auto_pause" boolean DEFAULT false,
61
- "max_job_tokens" integer DEFAULT 150000,
62
- "created_at" timestamp with time zone DEFAULT now(),
63
- "updated_at" timestamp with time zone DEFAULT now(),
64
- CONSTRAINT "agent_budgets_agent_id_unique" UNIQUE("agent_id"),
65
- CONSTRAINT "agent_budgets_alert_threshold_pct_check" CHECK ("agent_budgets"."alert_threshold_pct" >= 0 AND "agent_budgets"."alert_threshold_pct" <= 100)
66
- );
67
- --> statement-breakpoint
68
- CREATE TABLE "agents" (
69
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
70
- "entity_id" uuid,
71
- "name" text NOT NULL,
72
- "slug" text NOT NULL,
73
- "personality" text NOT NULL,
74
- "model" text DEFAULT 'claude-sonnet-4-6-20260217',
75
- "active" boolean DEFAULT true,
76
- "is_default" boolean DEFAULT false,
77
- "role" text DEFAULT 'agent',
78
- "orchestrator_mode" text,
79
- "telegram_bot_token" text,
80
- "telegram_bot_username" text,
81
- "telegram_offset" bigint,
82
- "requires_approval" text[] DEFAULT '{}'::text[],
83
- "capabilities" text[] DEFAULT '{}'::text[],
84
- "task_context_template" text,
85
- "avatar_url" text,
86
- "system_agent" boolean DEFAULT false,
87
- "max_tokens_per_job" integer DEFAULT 0 NOT NULL,
88
- "enabled_builtin_tools" text[],
89
- "created_at" timestamp with time zone DEFAULT now(),
90
- "updated_at" timestamp with time zone DEFAULT now(),
91
- CONSTRAINT "agents_slug_unique" UNIQUE("slug"),
92
- CONSTRAINT "agents_role_check" CHECK ("agents"."role" IN ('agent', 'orchestrator', 'system')),
93
- CONSTRAINT "agents_orchestrator_mode_check" CHECK ("agents"."orchestrator_mode" IN ('router', 'planner') OR "agents"."orchestrator_mode" IS NULL),
94
- CONSTRAINT "agents_max_tokens_per_job_check" CHECK ("agents"."max_tokens_per_job" >= 0)
95
- );
96
- --> statement-breakpoint
97
- CREATE TABLE "agent_jobs" (
98
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
99
- "entity_id" uuid,
100
- "agent_id" uuid,
101
- "status" text DEFAULT 'pending',
102
- "channel" text NOT NULL,
103
- "task" text NOT NULL,
104
- "original_task" text,
105
- "chat_id" text,
106
- "system_prompt" text,
107
- "messages" jsonb DEFAULT '[]'::jsonb,
108
- "tools_used" text[] DEFAULT '{}'::text[],
109
- "turn" integer DEFAULT 0,
110
- "result" text,
111
- "error" text,
112
- "chain_count" integer DEFAULT 0,
113
- "request_id" text,
114
- "parent_job_id" uuid,
115
- "parent_request_id" text,
116
- "total_duration_ms" integer DEFAULT 0,
117
- "input_tokens" integer DEFAULT 0,
118
- "output_tokens" integer DEFAULT 0,
119
- "delegation_depth" integer DEFAULT 0,
120
- "pending_delegation" jsonb,
121
- "completed_at" timestamp with time zone,
122
- "created_at" timestamp with time zone DEFAULT now(),
123
- "updated_at" timestamp with time zone DEFAULT now(),
124
- CONSTRAINT "agent_jobs_status_check" CHECK ("agent_jobs"."status" IN ('pending','processing','completed','failed','awaiting_approval','awaiting_delegation','cancelled')),
125
- CONSTRAINT "agent_jobs_channel_check" CHECK ("agent_jobs"."channel" IN ('telegram','api','whatsapp','internal','cron','task-board','slack','discord'))
126
- );
127
- --> statement-breakpoint
128
- CREATE TABLE "agent_tasks" (
129
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
130
- "entity_id" uuid NOT NULL,
131
- "orchestrator_id" uuid NOT NULL,
132
- "title" text NOT NULL,
133
- "description" text,
134
- "status" text DEFAULT 'todo' NOT NULL,
135
- "priority" text DEFAULT 'medium' NOT NULL,
136
- "job_id" uuid,
137
- "result" text,
138
- "created_by_agent_id" uuid,
139
- "assigned_agent_id" uuid,
140
- "input_tokens" integer DEFAULT 0,
141
- "output_tokens" integer DEFAULT 0,
142
- "cost_usd" numeric(10, 6) DEFAULT '0',
143
- "depends_on" uuid[] DEFAULT '{}'::uuid[],
144
- "context" jsonb DEFAULT '{}'::jsonb,
145
- "root_job_id" uuid,
146
- "locked_at" timestamp with time zone,
147
- "locked_by" text,
148
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
149
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
150
- CONSTRAINT "agent_tasks_status_check" CHECK ("agent_tasks"."status" IN ('todo','in_progress','done','cancelled','blocked')),
151
- CONSTRAINT "agent_tasks_priority_check" CHECK ("agent_tasks"."priority" IN ('low','medium','high')),
152
- CONSTRAINT "agent_tasks_title_check" CHECK (char_length("agent_tasks"."title") <= 200),
153
- CONSTRAINT "agent_tasks_description_check" CHECK ("agent_tasks"."description" IS NULL OR char_length("agent_tasks"."description") <= 2000)
154
- );
155
- --> statement-breakpoint
156
- CREATE TABLE "connectors" (
157
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
158
- "entity_id" uuid,
159
- "name" text NOT NULL,
160
- "slug" text NOT NULL,
161
- "base_url" text,
162
- "api_key" text,
163
- "active" boolean DEFAULT true,
164
- "auth_type" text DEFAULT 'api_key' NOT NULL,
165
- "oauth_client_id" text,
166
- "oauth_client_secret" text,
167
- "oauth_refresh_token" text,
168
- "oauth_access_token" text,
169
- "oauth_token_expires_at" timestamp with time zone,
170
- "oauth_token_url" text,
171
- "oauth_scopes" text,
172
- "oauth_account_name" text,
173
- "created_at" timestamp with time zone DEFAULT now(),
174
- "updated_at" timestamp with time zone DEFAULT now(),
175
- CONSTRAINT "connectors_slug_unique" UNIQUE("slug"),
176
- CONSTRAINT "connectors_auth_type_check" CHECK ("connectors"."auth_type" IN ('api_key','oauth2','bearer','basic','none'))
177
- );
178
- --> statement-breakpoint
179
- CREATE TABLE "tool_calls" (
180
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
181
- "entity_id" uuid,
182
- "job_id" uuid,
183
- "tool_name" text NOT NULL,
184
- "tool_input" jsonb,
185
- "tool_output" text,
186
- "duration_ms" integer,
187
- "turn" integer,
188
- "created_at" timestamp with time zone DEFAULT now()
189
- );
190
- --> statement-breakpoint
191
- CREATE TABLE "approval_requests" (
192
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
193
- "entity_id" uuid,
194
- "job_id" uuid NOT NULL,
195
- "agent_id" uuid,
196
- "tool_name" text NOT NULL,
197
- "tool_input" jsonb NOT NULL,
198
- "status" text DEFAULT 'pending',
199
- "requested_at" timestamp with time zone DEFAULT now(),
200
- "resolved_at" timestamp with time zone,
201
- "resolved_by" text,
202
- "expires_at" timestamp with time zone DEFAULT now() + interval '1 hour',
203
- "notes" text,
204
- CONSTRAINT "approval_requests_status_check" CHECK ("approval_requests"."status" IN ('pending','approved','rejected','expired'))
205
- );
206
- --> statement-breakpoint
207
- CREATE TABLE "approval_rules" (
208
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
209
- "entity_id" uuid,
210
- "agent_id" uuid,
211
- "tool_name" text NOT NULL,
212
- "action" text NOT NULL,
213
- "condition_json" jsonb DEFAULT '{}'::jsonb,
214
- "created_at" timestamp with time zone DEFAULT now(),
215
- "updated_at" timestamp with time zone DEFAULT now(),
216
- CONSTRAINT "approval_rules_action_check" CHECK ("approval_rules"."action" IN ('auto_approve','require_approval','block'))
217
- );
218
- --> statement-breakpoint
219
- CREATE TABLE "agent_memory" (
220
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
221
- "entity_id" uuid,
222
- "agent_id" uuid,
223
- "fact" text NOT NULL,
224
- "category" text DEFAULT 'context',
225
- "importance" integer DEFAULT 3,
226
- "source" text DEFAULT 'agent',
227
- "skill_tags" text[] DEFAULT '{}'::text[],
228
- "memory_layer" text,
229
- "embedding" vector(1536),
230
- "valid_from" timestamp with time zone DEFAULT now(),
231
- "valid_to" timestamp with time zone,
232
- "fact_hash" text,
233
- "archived" boolean DEFAULT false,
234
- "last_accessed_at" timestamp with time zone DEFAULT now(),
235
- "access_count" integer DEFAULT 0,
236
- "created_at" timestamp with time zone DEFAULT now(),
237
- "updated_at" timestamp with time zone DEFAULT now(),
238
- CONSTRAINT "agent_memory_category_check" CHECK ("agent_memory"."category" IN ('preference','context','outcome','learned_rule')),
239
- CONSTRAINT "agent_memory_importance_check" CHECK ("agent_memory"."importance" >= 1 AND "agent_memory"."importance" <= 5),
240
- CONSTRAINT "agent_memory_source_check" CHECK ("agent_memory"."source" IN ('agent','reflection','manual'))
241
- );
242
- --> statement-breakpoint
243
- CREATE TABLE "webhook_triggers" (
244
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
245
- "entity_id" uuid,
246
- "agent_id" uuid,
247
- "name" text NOT NULL,
248
- "slug" text NOT NULL,
249
- "task_template" text NOT NULL,
250
- "active" boolean DEFAULT true,
251
- "secret" text,
252
- "last_triggered_at" timestamp with time zone,
253
- "trigger_count" integer DEFAULT 0,
254
- "created_at" timestamp with time zone DEFAULT now(),
255
- "updated_at" timestamp with time zone DEFAULT now(),
256
- CONSTRAINT "webhook_triggers_slug_unique" UNIQUE("slug")
257
- );
258
- --> statement-breakpoint
259
- CREATE TABLE "agent_skill_assignments" (
260
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
261
- "entity_id" uuid NOT NULL,
262
- "agent_id" uuid NOT NULL,
263
- "skill_id" uuid NOT NULL,
264
- "approval_overrides" jsonb DEFAULT '{}'::jsonb,
265
- "use_custom_instructions" boolean DEFAULT false NOT NULL,
266
- "enabled_operations" text[],
267
- "created_at" timestamp with time zone DEFAULT now() NOT NULL
268
- );
269
- --> statement-breakpoint
270
- CREATE TABLE "agent_skills" (
271
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
272
- "entity_id" uuid,
273
- "name" text NOT NULL,
274
- "slug" text NOT NULL,
275
- "content" text NOT NULL,
276
- "active" boolean DEFAULT true,
277
- "description" text,
278
- "default_content" text,
279
- "content_overridden" boolean DEFAULT false,
280
- "required_config" jsonb DEFAULT '[]'::jsonb,
281
- "operations" jsonb DEFAULT '[]'::jsonb,
282
- "required_builtins" text[] DEFAULT '{}'::text[] NOT NULL,
283
- "created_at" timestamp with time zone DEFAULT now(),
284
- "updated_at" timestamp with time zone DEFAULT now(),
285
- CONSTRAINT "agent_skills_name_unique" UNIQUE("name"),
286
- CONSTRAINT "agent_skills_slug_unique" UNIQUE("slug")
287
- );
288
- --> statement-breakpoint
289
- CREATE TABLE "skill_connectors" (
290
- "skill_id" uuid NOT NULL,
291
- "connector_id" uuid NOT NULL,
292
- "entity_id" uuid
293
- );
294
- --> statement-breakpoint
295
- CREATE TABLE "skill_versions" (
296
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
297
- "entity_id" uuid,
298
- "skill_id" uuid,
299
- "version" integer NOT NULL,
300
- "content" text NOT NULL,
301
- "name" text NOT NULL,
302
- "created_at" timestamp with time zone DEFAULT now()
303
- );
304
- --> statement-breakpoint
305
- CREATE TABLE "agent_schedules" (
306
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
307
- "entity_id" uuid,
308
- "agent_id" uuid NOT NULL,
309
- "type" text DEFAULT 'cron' NOT NULL,
310
- "name" text NOT NULL,
311
- "cron_expr" text NOT NULL,
312
- "task" text,
313
- "objectives" text,
314
- "active" boolean DEFAULT true,
315
- "last_run" timestamp with time zone,
316
- "next_run" timestamp with time zone,
317
- "last_status" text,
318
- "chat_id" text,
319
- "created_at" timestamp with time zone DEFAULT now(),
320
- "updated_at" timestamp with time zone DEFAULT now(),
321
- CONSTRAINT "agent_schedules_type_check" CHECK ("agent_schedules"."type" IN ('cron','heartbeat')),
322
- CONSTRAINT "agent_schedules_last_status_check" CHECK ("agent_schedules"."last_status" IN ('success','failed','no_action') OR "agent_schedules"."last_status" IS NULL)
323
- );
324
- --> statement-breakpoint
325
- CREATE TABLE "entity_llm_keys" (
326
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
327
- "entity_id" uuid NOT NULL,
328
- "provider" text NOT NULL,
329
- "api_key" text DEFAULT '' NOT NULL,
330
- "base_url" text,
331
- "nickname" text,
332
- "is_active" boolean DEFAULT true NOT NULL,
333
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
334
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL
335
- );
336
- --> statement-breakpoint
337
- CREATE TABLE "agent_runs" (
338
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
339
- "entity_id" uuid,
340
- "agent_id" uuid,
341
- "task" text NOT NULL,
342
- "result" text,
343
- "success" boolean DEFAULT true,
344
- "tools_used" text[] DEFAULT '{}'::text[],
345
- "tokens_used" integer,
346
- "input_tokens" integer,
347
- "output_tokens" integer,
348
- "duration_ms" integer,
349
- "key_source" text,
350
- "created_at" timestamp with time zone DEFAULT now(),
351
- CONSTRAINT "agent_runs_key_source_check" CHECK ("agent_runs"."key_source" IN ('entity','operator') OR "agent_runs"."key_source" IS NULL)
352
- );
353
- --> statement-breakpoint
354
- CREATE TABLE "agent_mcp_servers" (
355
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
356
- "entity_id" uuid NOT NULL,
357
- "agent_id" uuid NOT NULL,
358
- "mcp_server_id" uuid NOT NULL,
359
- "enabled_tools" jsonb,
360
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
361
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL
362
- );
363
- --> statement-breakpoint
364
- CREATE TABLE "mcp_connections" (
365
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
366
- "entity_id" uuid NOT NULL,
367
- "slug" text NOT NULL,
368
- "active" boolean DEFAULT true NOT NULL,
369
- "tool_config" jsonb DEFAULT '{}'::jsonb NOT NULL,
370
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
371
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL
372
- );
373
- --> statement-breakpoint
374
- CREATE TABLE "mcp_servers" (
375
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
376
- "entity_id" uuid,
377
- "name" text NOT NULL,
378
- "slug" text NOT NULL,
379
- "transport" text NOT NULL,
380
- "url" text,
381
- "command" text,
382
- "args" text[] DEFAULT '{}'::text[],
383
- "env_vars" jsonb DEFAULT '{}'::jsonb,
384
- "active" boolean DEFAULT true,
385
- "available_tools" jsonb,
386
- "created_at" timestamp with time zone DEFAULT now(),
387
- "updated_at" timestamp with time zone DEFAULT now(),
388
- CONSTRAINT "mcp_servers_transport_check" CHECK ("mcp_servers"."transport" IN ('http','stdio'))
389
- );
390
- --> statement-breakpoint
391
- CREATE TABLE "agent_plugins" (
392
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
393
- "entity_id" uuid,
394
- "name" text NOT NULL,
395
- "slug" text NOT NULL,
396
- "description" text,
397
- "plugin_type" text NOT NULL,
398
- "config" jsonb DEFAULT '{}'::jsonb,
399
- "active" boolean DEFAULT true,
400
- "hook" text NOT NULL,
401
- "webhook_url" text,
402
- "created_at" timestamp with time zone DEFAULT now(),
403
- "updated_at" timestamp with time zone DEFAULT now(),
404
- CONSTRAINT "agent_plugins_plugin_type_check" CHECK ("agent_plugins"."plugin_type" IN ('webhook','transform','schedule')),
405
- CONSTRAINT "agent_plugins_hook_check" CHECK ("agent_plugins"."hook" IN ('pre_task','post_task','pre_tool','post_tool','on_memory_save'))
406
- );
407
- --> statement-breakpoint
408
- CREATE TABLE "configurator_sessions" (
409
- "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
410
- "entity_id" uuid NOT NULL,
411
- "agent_id" uuid,
412
- "messages" jsonb DEFAULT '[]'::jsonb NOT NULL,
413
- "status" text DEFAULT 'active' NOT NULL,
414
- "turn_count" integer DEFAULT 0 NOT NULL,
415
- "created_at" timestamp with time zone DEFAULT now() NOT NULL,
416
- "updated_at" timestamp with time zone DEFAULT now() NOT NULL
417
- );
418
- --> statement-breakpoint
419
- CREATE TABLE "rate_limits" (
420
- "key" text PRIMARY KEY NOT NULL,
421
- "count" integer DEFAULT 1,
422
- "window_start" timestamp with time zone DEFAULT now()
423
- );
424
- --> statement-breakpoint
425
- ALTER TABLE "user_profiles" ADD CONSTRAINT "user_profiles_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
426
- ALTER TABLE "entities" ADD CONSTRAINT "entities_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
427
- ALTER TABLE "entity_members" ADD CONSTRAINT "entity_members_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
428
- ALTER TABLE "entity_members" ADD CONSTRAINT "entity_members_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
429
- ALTER TABLE "agent_assignments" ADD CONSTRAINT "agent_assignments_orchestrator_id_agents_id_fk" FOREIGN KEY ("orchestrator_id") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
430
- ALTER TABLE "agent_assignments" ADD CONSTRAINT "agent_assignments_sub_agent_id_agents_id_fk" FOREIGN KEY ("sub_agent_id") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
431
- ALTER TABLE "agent_assignments" ADD CONSTRAINT "agent_assignments_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
432
- ALTER TABLE "agent_budgets" ADD CONSTRAINT "agent_budgets_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
433
- ALTER TABLE "agent_budgets" ADD CONSTRAINT "agent_budgets_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
434
- ALTER TABLE "agents" ADD CONSTRAINT "agents_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
435
- ALTER TABLE "agent_jobs" ADD CONSTRAINT "agent_jobs_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
436
- ALTER TABLE "agent_jobs" ADD CONSTRAINT "agent_jobs_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
437
- ALTER TABLE "agent_tasks" ADD CONSTRAINT "agent_tasks_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
438
- ALTER TABLE "agent_tasks" ADD CONSTRAINT "agent_tasks_orchestrator_id_agents_id_fk" FOREIGN KEY ("orchestrator_id") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
439
- ALTER TABLE "agent_tasks" ADD CONSTRAINT "agent_tasks_job_id_agent_jobs_id_fk" FOREIGN KEY ("job_id") REFERENCES "public"."agent_jobs"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
440
- ALTER TABLE "agent_tasks" ADD CONSTRAINT "agent_tasks_created_by_agent_id_agents_id_fk" FOREIGN KEY ("created_by_agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
441
- ALTER TABLE "agent_tasks" ADD CONSTRAINT "agent_tasks_assigned_agent_id_agents_id_fk" FOREIGN KEY ("assigned_agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
442
- ALTER TABLE "connectors" ADD CONSTRAINT "connectors_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
443
- ALTER TABLE "tool_calls" ADD CONSTRAINT "tool_calls_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
444
- ALTER TABLE "tool_calls" ADD CONSTRAINT "tool_calls_job_id_agent_jobs_id_fk" FOREIGN KEY ("job_id") REFERENCES "public"."agent_jobs"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
445
- ALTER TABLE "approval_requests" ADD CONSTRAINT "approval_requests_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
446
- ALTER TABLE "approval_requests" ADD CONSTRAINT "approval_requests_job_id_agent_jobs_id_fk" FOREIGN KEY ("job_id") REFERENCES "public"."agent_jobs"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
447
- ALTER TABLE "approval_requests" ADD CONSTRAINT "approval_requests_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
448
- ALTER TABLE "approval_rules" ADD CONSTRAINT "approval_rules_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
449
- ALTER TABLE "approval_rules" ADD CONSTRAINT "approval_rules_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
450
- ALTER TABLE "agent_memory" ADD CONSTRAINT "agent_memory_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
451
- ALTER TABLE "agent_memory" ADD CONSTRAINT "agent_memory_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
452
- ALTER TABLE "webhook_triggers" ADD CONSTRAINT "webhook_triggers_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
453
- ALTER TABLE "webhook_triggers" ADD CONSTRAINT "webhook_triggers_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
454
- ALTER TABLE "agent_skill_assignments" ADD CONSTRAINT "agent_skill_assignments_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
455
- ALTER TABLE "agent_skill_assignments" ADD CONSTRAINT "agent_skill_assignments_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
456
- ALTER TABLE "agent_skill_assignments" ADD CONSTRAINT "agent_skill_assignments_skill_id_agent_skills_id_fk" FOREIGN KEY ("skill_id") REFERENCES "public"."agent_skills"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
457
- ALTER TABLE "agent_skills" ADD CONSTRAINT "agent_skills_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
458
- ALTER TABLE "skill_connectors" ADD CONSTRAINT "skill_connectors_skill_id_agent_skills_id_fk" FOREIGN KEY ("skill_id") REFERENCES "public"."agent_skills"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
459
- ALTER TABLE "skill_connectors" ADD CONSTRAINT "skill_connectors_connector_id_connectors_id_fk" FOREIGN KEY ("connector_id") REFERENCES "public"."connectors"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
460
- ALTER TABLE "skill_connectors" ADD CONSTRAINT "skill_connectors_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
461
- ALTER TABLE "skill_versions" ADD CONSTRAINT "skill_versions_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
462
- ALTER TABLE "skill_versions" ADD CONSTRAINT "skill_versions_skill_id_agent_skills_id_fk" FOREIGN KEY ("skill_id") REFERENCES "public"."agent_skills"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
463
- ALTER TABLE "agent_schedules" ADD CONSTRAINT "agent_schedules_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
464
- ALTER TABLE "agent_schedules" ADD CONSTRAINT "agent_schedules_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
465
- ALTER TABLE "entity_llm_keys" ADD CONSTRAINT "entity_llm_keys_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
466
- ALTER TABLE "agent_runs" ADD CONSTRAINT "agent_runs_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
467
- ALTER TABLE "agent_runs" ADD CONSTRAINT "agent_runs_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
468
- ALTER TABLE "agent_mcp_servers" ADD CONSTRAINT "agent_mcp_servers_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
469
- ALTER TABLE "agent_mcp_servers" ADD CONSTRAINT "agent_mcp_servers_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
470
- ALTER TABLE "agent_mcp_servers" ADD CONSTRAINT "agent_mcp_servers_mcp_server_id_mcp_servers_id_fk" FOREIGN KEY ("mcp_server_id") REFERENCES "public"."mcp_servers"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
471
- ALTER TABLE "mcp_connections" ADD CONSTRAINT "mcp_connections_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
472
- ALTER TABLE "mcp_servers" ADD CONSTRAINT "mcp_servers_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
473
- ALTER TABLE "agent_plugins" ADD CONSTRAINT "agent_plugins_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
474
- ALTER TABLE "configurator_sessions" ADD CONSTRAINT "configurator_sessions_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
475
- ALTER TABLE "configurator_sessions" ADD CONSTRAINT "configurator_sessions_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
476
- CREATE UNIQUE INDEX "entities_mcp_token_idx" ON "entities" USING btree ("mcp_token");--> statement-breakpoint
477
- CREATE INDEX "idx_entities_user_id" ON "entities" USING btree ("user_id");--> statement-breakpoint
478
- CREATE INDEX "idx_entity_members_entity_id" ON "entity_members" USING btree ("entity_id");--> statement-breakpoint
479
- CREATE INDEX "idx_entity_members_user_id" ON "entity_members" USING btree ("user_id");--> statement-breakpoint
480
- CREATE INDEX "idx_entity_members_user" ON "entity_members" USING btree ("user_id","entity_id");--> statement-breakpoint
481
- CREATE INDEX "idx_agent_budgets_entity_id" ON "agent_budgets" USING btree ("entity_id");--> statement-breakpoint
482
- CREATE INDEX "idx_agents_entity_id" ON "agents" USING btree ("entity_id");--> statement-breakpoint
483
- CREATE INDEX "idx_agent_jobs_entity_id" ON "agent_jobs" USING btree ("entity_id");--> statement-breakpoint
484
- CREATE INDEX "idx_agent_jobs_entity_created" ON "agent_jobs" USING btree ("entity_id","created_at" DESC);--> statement-breakpoint
485
- CREATE INDEX "idx_agent_jobs_entity_status_created" ON "agent_jobs" USING btree ("entity_id","status","created_at" DESC);--> statement-breakpoint
486
- CREATE INDEX "idx_agent_jobs_parent_job_id" ON "agent_jobs" USING btree ("parent_job_id");--> statement-breakpoint
487
- CREATE INDEX "idx_jobs_parent" ON "agent_jobs" USING btree ("parent_job_id");--> statement-breakpoint
488
- CREATE INDEX "idx_jobs_status" ON "agent_jobs" USING btree ("status","created_at");--> statement-breakpoint
489
- CREATE INDEX "idx_agent_tasks_entity" ON "agent_tasks" USING btree ("entity_id");--> statement-breakpoint
490
- CREATE INDEX "idx_agent_tasks_entity_status_created" ON "agent_tasks" USING btree ("entity_id","status","created_at" DESC);--> statement-breakpoint
491
- CREATE INDEX "idx_agent_tasks_orchestrator_status" ON "agent_tasks" USING btree ("orchestrator_id","status");--> statement-breakpoint
492
- CREATE INDEX "idx_agent_tasks_status" ON "agent_tasks" USING btree ("status");--> statement-breakpoint
493
- CREATE INDEX "idx_agent_tasks_assigned" ON "agent_tasks" USING btree ("assigned_agent_id");--> statement-breakpoint
494
- CREATE INDEX "idx_connectors_entity_id" ON "connectors" USING btree ("entity_id");--> statement-breakpoint
495
- CREATE INDEX "idx_tool_calls_entity_id" ON "tool_calls" USING btree ("entity_id");--> statement-breakpoint
496
- CREATE INDEX "idx_tool_calls_job" ON "tool_calls" USING btree ("job_id");--> statement-breakpoint
497
- CREATE INDEX "idx_tool_calls_job_created" ON "tool_calls" USING btree ("job_id","created_at" DESC);--> statement-breakpoint
498
- CREATE INDEX "idx_tool_calls_recent" ON "tool_calls" USING btree ("created_at" DESC);--> statement-breakpoint
499
- CREATE INDEX "idx_approval_requests_entity_id" ON "approval_requests" USING btree ("entity_id");--> statement-breakpoint
500
- CREATE INDEX "idx_approval_status" ON "approval_requests" USING btree ("status","requested_at");--> statement-breakpoint
501
- CREATE INDEX "idx_approval_requests_agent_id" ON "approval_requests" USING btree ("agent_id");--> statement-breakpoint
502
- CREATE INDEX "idx_approval_requests_job_id" ON "approval_requests" USING btree ("job_id");--> statement-breakpoint
503
- CREATE INDEX "idx_approval_rules_entity_id" ON "approval_rules" USING btree ("entity_id");--> statement-breakpoint
504
- CREATE INDEX "idx_agent_memory_entity_id" ON "agent_memory" USING btree ("entity_id");--> statement-breakpoint
505
- CREATE INDEX "idx_agent_memory_entity_active" ON "agent_memory" USING btree ("entity_id","archived","valid_to");--> statement-breakpoint
506
- CREATE INDEX "idx_agent_memory_archived" ON "agent_memory" USING btree ("archived");--> statement-breakpoint
507
- CREATE INDEX "idx_agent_memory_last_accessed" ON "agent_memory" USING btree ("last_accessed_at");--> statement-breakpoint
508
- CREATE INDEX "idx_agent_memory_layer" ON "agent_memory" USING btree ("memory_layer");--> statement-breakpoint
509
- CREATE INDEX "idx_agent_memory_fact_hash" ON "agent_memory" USING btree ("fact_hash");--> statement-breakpoint
510
- CREATE INDEX "idx_memory_category" ON "agent_memory" USING btree ("category","importance" DESC);--> statement-breakpoint
511
- CREATE INDEX "idx_webhook_triggers_entity_id" ON "webhook_triggers" USING btree ("entity_id");--> statement-breakpoint
512
- CREATE INDEX "idx_agent_skills_entity_id" ON "agent_skills" USING btree ("entity_id");--> statement-breakpoint
513
- CREATE INDEX "idx_skills_active" ON "agent_skills" USING btree ("active","slug");--> statement-breakpoint
514
- CREATE INDEX "idx_skill_connectors_entity_id" ON "skill_connectors" USING btree ("entity_id");--> statement-breakpoint
515
- CREATE INDEX "idx_skill_connectors_skill_id" ON "skill_connectors" USING btree ("skill_id");--> statement-breakpoint
516
- CREATE INDEX "idx_skill_versions_entity_id" ON "skill_versions" USING btree ("entity_id");--> statement-breakpoint
517
- CREATE INDEX "idx_skill_versions_skill_id" ON "skill_versions" USING btree ("skill_id","version" DESC);--> statement-breakpoint
518
- CREATE INDEX "idx_agent_schedules_entity_id" ON "agent_schedules" USING btree ("entity_id");--> statement-breakpoint
519
- CREATE INDEX "idx_schedules_active" ON "agent_schedules" USING btree ("active","next_run");--> statement-breakpoint
520
- CREATE INDEX "idx_entity_llm_keys_entity_id" ON "entity_llm_keys" USING btree ("entity_id");--> statement-breakpoint
521
- CREATE INDEX "idx_agent_runs_entity_id" ON "agent_runs" USING btree ("entity_id");--> statement-breakpoint
522
- CREATE INDEX "idx_agent_runs_agent_created" ON "agent_runs" USING btree ("agent_id","created_at" DESC);--> statement-breakpoint
523
- CREATE INDEX "idx_runs_agent" ON "agent_runs" USING btree ("agent_id","created_at" DESC);--> statement-breakpoint
524
- CREATE INDEX "idx_runs_recent" ON "agent_runs" USING btree ("created_at" DESC);--> statement-breakpoint
525
- CREATE INDEX "idx_agent_mcp_servers_agent" ON "agent_mcp_servers" USING btree ("agent_id");--> statement-breakpoint
526
- CREATE INDEX "idx_agent_mcp_servers_entity" ON "agent_mcp_servers" USING btree ("entity_id");--> statement-breakpoint
527
- CREATE INDEX "idx_mcp_connections_entity" ON "mcp_connections" USING btree ("entity_id");--> statement-breakpoint
528
- CREATE INDEX "idx_configurator_sessions_entity" ON "configurator_sessions" USING btree ("entity_id");--> statement-breakpoint
1
+ CREATE TABLE "user_profiles" (
2
+ "user_id" uuid PRIMARY KEY NOT NULL,
3
+ "display_name" text,
4
+ "avatar_url" text,
5
+ "timezone" text DEFAULT 'UTC' NOT NULL,
6
+ "locale" text DEFAULT 'en' NOT NULL,
7
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
8
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
9
+ );
10
+ --> statement-breakpoint
11
+ CREATE TABLE "users" (
12
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
13
+ "email" text NOT NULL,
14
+ "password_hash" text,
15
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
16
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
17
+ CONSTRAINT "users_email_unique" UNIQUE("email")
18
+ );
19
+ --> statement-breakpoint
20
+ CREATE TABLE "entities" (
21
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
22
+ "user_id" uuid NOT NULL,
23
+ "name" text NOT NULL,
24
+ "slug" text NOT NULL,
25
+ "description" text,
26
+ "icon" text DEFAULT '🏢',
27
+ "industry" text,
28
+ "goal" text,
29
+ "mcp_token" uuid DEFAULT gen_random_uuid(),
30
+ "created_at" timestamp with time zone DEFAULT now(),
31
+ "updated_at" timestamp with time zone DEFAULT now(),
32
+ CONSTRAINT "entities_slug_unique" UNIQUE("slug")
33
+ );
34
+ --> statement-breakpoint
35
+ CREATE TABLE "entity_members" (
36
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
37
+ "entity_id" uuid NOT NULL,
38
+ "user_id" uuid NOT NULL,
39
+ "role" text DEFAULT 'owner',
40
+ "created_at" timestamp with time zone DEFAULT now(),
41
+ CONSTRAINT "entity_members_role_check" CHECK ("entity_members"."role" IN ('owner', 'admin', 'member', 'viewer'))
42
+ );
43
+ --> statement-breakpoint
44
+ CREATE TABLE "agent_assignments" (
45
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
46
+ "orchestrator_id" uuid NOT NULL,
47
+ "sub_agent_id" uuid NOT NULL,
48
+ "entity_id" uuid NOT NULL,
49
+ "instructions" text,
50
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL
51
+ );
52
+ --> statement-breakpoint
53
+ CREATE TABLE "agent_budgets" (
54
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
55
+ "agent_id" uuid,
56
+ "entity_id" uuid,
57
+ "daily_token_limit" bigint DEFAULT 0,
58
+ "monthly_token_limit" bigint DEFAULT 0,
59
+ "alert_threshold_pct" integer DEFAULT 80,
60
+ "auto_pause" boolean DEFAULT false,
61
+ "max_job_tokens" integer DEFAULT 150000,
62
+ "created_at" timestamp with time zone DEFAULT now(),
63
+ "updated_at" timestamp with time zone DEFAULT now(),
64
+ CONSTRAINT "agent_budgets_agent_id_unique" UNIQUE("agent_id"),
65
+ CONSTRAINT "agent_budgets_alert_threshold_pct_check" CHECK ("agent_budgets"."alert_threshold_pct" >= 0 AND "agent_budgets"."alert_threshold_pct" <= 100)
66
+ );
67
+ --> statement-breakpoint
68
+ CREATE TABLE "agents" (
69
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
70
+ "entity_id" uuid,
71
+ "name" text NOT NULL,
72
+ "slug" text NOT NULL,
73
+ "personality" text NOT NULL,
74
+ "model" text DEFAULT 'claude-sonnet-4-6-20260217',
75
+ "active" boolean DEFAULT true,
76
+ "is_default" boolean DEFAULT false,
77
+ "role" text DEFAULT 'agent',
78
+ "orchestrator_mode" text,
79
+ "telegram_bot_token" text,
80
+ "telegram_bot_username" text,
81
+ "telegram_offset" bigint,
82
+ "requires_approval" text[] DEFAULT '{}'::text[],
83
+ "capabilities" text[] DEFAULT '{}'::text[],
84
+ "task_context_template" text,
85
+ "avatar_url" text,
86
+ "system_agent" boolean DEFAULT false,
87
+ "max_tokens_per_job" integer DEFAULT 0 NOT NULL,
88
+ "enabled_builtin_tools" text[],
89
+ "created_at" timestamp with time zone DEFAULT now(),
90
+ "updated_at" timestamp with time zone DEFAULT now(),
91
+ CONSTRAINT "agents_slug_unique" UNIQUE("slug"),
92
+ CONSTRAINT "agents_role_check" CHECK ("agents"."role" IN ('agent', 'orchestrator', 'system')),
93
+ CONSTRAINT "agents_orchestrator_mode_check" CHECK ("agents"."orchestrator_mode" IN ('router', 'planner') OR "agents"."orchestrator_mode" IS NULL),
94
+ CONSTRAINT "agents_max_tokens_per_job_check" CHECK ("agents"."max_tokens_per_job" >= 0)
95
+ );
96
+ --> statement-breakpoint
97
+ CREATE TABLE "agent_jobs" (
98
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
99
+ "entity_id" uuid,
100
+ "agent_id" uuid,
101
+ "status" text DEFAULT 'pending',
102
+ "channel" text NOT NULL,
103
+ "task" text NOT NULL,
104
+ "original_task" text,
105
+ "chat_id" text,
106
+ "system_prompt" text,
107
+ "messages" jsonb DEFAULT '[]'::jsonb,
108
+ "tools_used" text[] DEFAULT '{}'::text[],
109
+ "turn" integer DEFAULT 0,
110
+ "result" text,
111
+ "error" text,
112
+ "chain_count" integer DEFAULT 0,
113
+ "request_id" text,
114
+ "parent_job_id" uuid,
115
+ "parent_request_id" text,
116
+ "total_duration_ms" integer DEFAULT 0,
117
+ "input_tokens" integer DEFAULT 0,
118
+ "output_tokens" integer DEFAULT 0,
119
+ "delegation_depth" integer DEFAULT 0,
120
+ "pending_delegation" jsonb,
121
+ "completed_at" timestamp with time zone,
122
+ "created_at" timestamp with time zone DEFAULT now(),
123
+ "updated_at" timestamp with time zone DEFAULT now(),
124
+ CONSTRAINT "agent_jobs_status_check" CHECK ("agent_jobs"."status" IN ('pending','processing','completed','failed','awaiting_approval','awaiting_delegation','cancelled')),
125
+ CONSTRAINT "agent_jobs_channel_check" CHECK ("agent_jobs"."channel" IN ('telegram','api','whatsapp','internal','cron','task-board','slack','discord'))
126
+ );
127
+ --> statement-breakpoint
128
+ CREATE TABLE "agent_tasks" (
129
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
130
+ "entity_id" uuid NOT NULL,
131
+ "orchestrator_id" uuid NOT NULL,
132
+ "title" text NOT NULL,
133
+ "description" text,
134
+ "status" text DEFAULT 'todo' NOT NULL,
135
+ "priority" text DEFAULT 'medium' NOT NULL,
136
+ "job_id" uuid,
137
+ "result" text,
138
+ "created_by_agent_id" uuid,
139
+ "assigned_agent_id" uuid,
140
+ "input_tokens" integer DEFAULT 0,
141
+ "output_tokens" integer DEFAULT 0,
142
+ "cost_usd" numeric(10, 6) DEFAULT '0',
143
+ "depends_on" uuid[] DEFAULT '{}'::uuid[],
144
+ "context" jsonb DEFAULT '{}'::jsonb,
145
+ "root_job_id" uuid,
146
+ "locked_at" timestamp with time zone,
147
+ "locked_by" text,
148
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
149
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL,
150
+ CONSTRAINT "agent_tasks_status_check" CHECK ("agent_tasks"."status" IN ('todo','in_progress','done','cancelled','blocked')),
151
+ CONSTRAINT "agent_tasks_priority_check" CHECK ("agent_tasks"."priority" IN ('low','medium','high')),
152
+ CONSTRAINT "agent_tasks_title_check" CHECK (char_length("agent_tasks"."title") <= 200),
153
+ CONSTRAINT "agent_tasks_description_check" CHECK ("agent_tasks"."description" IS NULL OR char_length("agent_tasks"."description") <= 2000)
154
+ );
155
+ --> statement-breakpoint
156
+ CREATE TABLE "connectors" (
157
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
158
+ "entity_id" uuid,
159
+ "name" text NOT NULL,
160
+ "slug" text NOT NULL,
161
+ "base_url" text,
162
+ "api_key" text,
163
+ "active" boolean DEFAULT true,
164
+ "auth_type" text DEFAULT 'api_key' NOT NULL,
165
+ "oauth_client_id" text,
166
+ "oauth_client_secret" text,
167
+ "oauth_refresh_token" text,
168
+ "oauth_access_token" text,
169
+ "oauth_token_expires_at" timestamp with time zone,
170
+ "oauth_token_url" text,
171
+ "oauth_scopes" text,
172
+ "oauth_account_name" text,
173
+ "created_at" timestamp with time zone DEFAULT now(),
174
+ "updated_at" timestamp with time zone DEFAULT now(),
175
+ CONSTRAINT "connectors_slug_unique" UNIQUE("slug"),
176
+ CONSTRAINT "connectors_auth_type_check" CHECK ("connectors"."auth_type" IN ('api_key','oauth2','bearer','basic','none'))
177
+ );
178
+ --> statement-breakpoint
179
+ CREATE TABLE "tool_calls" (
180
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
181
+ "entity_id" uuid,
182
+ "job_id" uuid,
183
+ "tool_name" text NOT NULL,
184
+ "tool_input" jsonb,
185
+ "tool_output" text,
186
+ "duration_ms" integer,
187
+ "turn" integer,
188
+ "created_at" timestamp with time zone DEFAULT now()
189
+ );
190
+ --> statement-breakpoint
191
+ CREATE TABLE "approval_requests" (
192
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
193
+ "entity_id" uuid,
194
+ "job_id" uuid NOT NULL,
195
+ "agent_id" uuid,
196
+ "tool_name" text NOT NULL,
197
+ "tool_input" jsonb NOT NULL,
198
+ "status" text DEFAULT 'pending',
199
+ "requested_at" timestamp with time zone DEFAULT now(),
200
+ "resolved_at" timestamp with time zone,
201
+ "resolved_by" text,
202
+ "expires_at" timestamp with time zone DEFAULT now() + interval '1 hour',
203
+ "notes" text,
204
+ CONSTRAINT "approval_requests_status_check" CHECK ("approval_requests"."status" IN ('pending','approved','rejected','expired'))
205
+ );
206
+ --> statement-breakpoint
207
+ CREATE TABLE "approval_rules" (
208
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
209
+ "entity_id" uuid,
210
+ "agent_id" uuid,
211
+ "tool_name" text NOT NULL,
212
+ "action" text NOT NULL,
213
+ "condition_json" jsonb DEFAULT '{}'::jsonb,
214
+ "created_at" timestamp with time zone DEFAULT now(),
215
+ "updated_at" timestamp with time zone DEFAULT now(),
216
+ CONSTRAINT "approval_rules_action_check" CHECK ("approval_rules"."action" IN ('auto_approve','require_approval','block'))
217
+ );
218
+ --> statement-breakpoint
219
+ CREATE TABLE "agent_memory" (
220
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
221
+ "entity_id" uuid,
222
+ "agent_id" uuid,
223
+ "fact" text NOT NULL,
224
+ "category" text DEFAULT 'context',
225
+ "importance" integer DEFAULT 3,
226
+ "source" text DEFAULT 'agent',
227
+ "skill_tags" text[] DEFAULT '{}'::text[],
228
+ "memory_layer" text,
229
+ "embedding" vector(1536),
230
+ "valid_from" timestamp with time zone DEFAULT now(),
231
+ "valid_to" timestamp with time zone,
232
+ "fact_hash" text,
233
+ "archived" boolean DEFAULT false,
234
+ "last_accessed_at" timestamp with time zone DEFAULT now(),
235
+ "access_count" integer DEFAULT 0,
236
+ "created_at" timestamp with time zone DEFAULT now(),
237
+ "updated_at" timestamp with time zone DEFAULT now(),
238
+ CONSTRAINT "agent_memory_category_check" CHECK ("agent_memory"."category" IN ('preference','context','outcome','learned_rule')),
239
+ CONSTRAINT "agent_memory_importance_check" CHECK ("agent_memory"."importance" >= 1 AND "agent_memory"."importance" <= 5),
240
+ CONSTRAINT "agent_memory_source_check" CHECK ("agent_memory"."source" IN ('agent','reflection','manual'))
241
+ );
242
+ --> statement-breakpoint
243
+ CREATE TABLE "webhook_triggers" (
244
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
245
+ "entity_id" uuid,
246
+ "agent_id" uuid,
247
+ "name" text NOT NULL,
248
+ "slug" text NOT NULL,
249
+ "task_template" text NOT NULL,
250
+ "active" boolean DEFAULT true,
251
+ "secret" text,
252
+ "last_triggered_at" timestamp with time zone,
253
+ "trigger_count" integer DEFAULT 0,
254
+ "created_at" timestamp with time zone DEFAULT now(),
255
+ "updated_at" timestamp with time zone DEFAULT now(),
256
+ CONSTRAINT "webhook_triggers_slug_unique" UNIQUE("slug")
257
+ );
258
+ --> statement-breakpoint
259
+ CREATE TABLE "agent_skill_assignments" (
260
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
261
+ "entity_id" uuid NOT NULL,
262
+ "agent_id" uuid NOT NULL,
263
+ "skill_id" uuid NOT NULL,
264
+ "approval_overrides" jsonb DEFAULT '{}'::jsonb,
265
+ "use_custom_instructions" boolean DEFAULT false NOT NULL,
266
+ "enabled_operations" text[],
267
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL
268
+ );
269
+ --> statement-breakpoint
270
+ CREATE TABLE "agent_skills" (
271
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
272
+ "entity_id" uuid,
273
+ "name" text NOT NULL,
274
+ "slug" text NOT NULL,
275
+ "content" text NOT NULL,
276
+ "active" boolean DEFAULT true,
277
+ "description" text,
278
+ "default_content" text,
279
+ "content_overridden" boolean DEFAULT false,
280
+ "required_config" jsonb DEFAULT '[]'::jsonb,
281
+ "operations" jsonb DEFAULT '[]'::jsonb,
282
+ "required_builtins" text[] DEFAULT '{}'::text[] NOT NULL,
283
+ "created_at" timestamp with time zone DEFAULT now(),
284
+ "updated_at" timestamp with time zone DEFAULT now(),
285
+ CONSTRAINT "agent_skills_name_unique" UNIQUE("name"),
286
+ CONSTRAINT "agent_skills_slug_unique" UNIQUE("slug")
287
+ );
288
+ --> statement-breakpoint
289
+ CREATE TABLE "skill_connectors" (
290
+ "skill_id" uuid NOT NULL,
291
+ "connector_id" uuid NOT NULL,
292
+ "entity_id" uuid
293
+ );
294
+ --> statement-breakpoint
295
+ CREATE TABLE "skill_versions" (
296
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
297
+ "entity_id" uuid,
298
+ "skill_id" uuid,
299
+ "version" integer NOT NULL,
300
+ "content" text NOT NULL,
301
+ "name" text NOT NULL,
302
+ "created_at" timestamp with time zone DEFAULT now()
303
+ );
304
+ --> statement-breakpoint
305
+ CREATE TABLE "agent_schedules" (
306
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
307
+ "entity_id" uuid,
308
+ "agent_id" uuid NOT NULL,
309
+ "type" text DEFAULT 'cron' NOT NULL,
310
+ "name" text NOT NULL,
311
+ "cron_expr" text NOT NULL,
312
+ "task" text,
313
+ "objectives" text,
314
+ "active" boolean DEFAULT true,
315
+ "last_run" timestamp with time zone,
316
+ "next_run" timestamp with time zone,
317
+ "last_status" text,
318
+ "chat_id" text,
319
+ "created_at" timestamp with time zone DEFAULT now(),
320
+ "updated_at" timestamp with time zone DEFAULT now(),
321
+ CONSTRAINT "agent_schedules_type_check" CHECK ("agent_schedules"."type" IN ('cron','heartbeat')),
322
+ CONSTRAINT "agent_schedules_last_status_check" CHECK ("agent_schedules"."last_status" IN ('success','failed','no_action') OR "agent_schedules"."last_status" IS NULL)
323
+ );
324
+ --> statement-breakpoint
325
+ CREATE TABLE "entity_llm_keys" (
326
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
327
+ "entity_id" uuid NOT NULL,
328
+ "provider" text NOT NULL,
329
+ "api_key" text DEFAULT '' NOT NULL,
330
+ "base_url" text,
331
+ "nickname" text,
332
+ "is_active" boolean DEFAULT true NOT NULL,
333
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
334
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
335
+ );
336
+ --> statement-breakpoint
337
+ CREATE TABLE "agent_runs" (
338
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
339
+ "entity_id" uuid,
340
+ "agent_id" uuid,
341
+ "task" text NOT NULL,
342
+ "result" text,
343
+ "success" boolean DEFAULT true,
344
+ "tools_used" text[] DEFAULT '{}'::text[],
345
+ "tokens_used" integer,
346
+ "input_tokens" integer,
347
+ "output_tokens" integer,
348
+ "duration_ms" integer,
349
+ "key_source" text,
350
+ "created_at" timestamp with time zone DEFAULT now(),
351
+ CONSTRAINT "agent_runs_key_source_check" CHECK ("agent_runs"."key_source" IN ('entity','operator') OR "agent_runs"."key_source" IS NULL)
352
+ );
353
+ --> statement-breakpoint
354
+ CREATE TABLE "agent_mcp_servers" (
355
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
356
+ "entity_id" uuid NOT NULL,
357
+ "agent_id" uuid NOT NULL,
358
+ "mcp_server_id" uuid NOT NULL,
359
+ "enabled_tools" jsonb,
360
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
361
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
362
+ );
363
+ --> statement-breakpoint
364
+ CREATE TABLE "mcp_connections" (
365
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
366
+ "entity_id" uuid NOT NULL,
367
+ "slug" text NOT NULL,
368
+ "active" boolean DEFAULT true NOT NULL,
369
+ "tool_config" jsonb DEFAULT '{}'::jsonb NOT NULL,
370
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
371
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
372
+ );
373
+ --> statement-breakpoint
374
+ CREATE TABLE "mcp_servers" (
375
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
376
+ "entity_id" uuid,
377
+ "name" text NOT NULL,
378
+ "slug" text NOT NULL,
379
+ "transport" text NOT NULL,
380
+ "url" text,
381
+ "command" text,
382
+ "args" text[] DEFAULT '{}'::text[],
383
+ "env_vars" jsonb DEFAULT '{}'::jsonb,
384
+ "active" boolean DEFAULT true,
385
+ "available_tools" jsonb,
386
+ "created_at" timestamp with time zone DEFAULT now(),
387
+ "updated_at" timestamp with time zone DEFAULT now(),
388
+ CONSTRAINT "mcp_servers_transport_check" CHECK ("mcp_servers"."transport" IN ('http','stdio'))
389
+ );
390
+ --> statement-breakpoint
391
+ CREATE TABLE "agent_plugins" (
392
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
393
+ "entity_id" uuid,
394
+ "name" text NOT NULL,
395
+ "slug" text NOT NULL,
396
+ "description" text,
397
+ "plugin_type" text NOT NULL,
398
+ "config" jsonb DEFAULT '{}'::jsonb,
399
+ "active" boolean DEFAULT true,
400
+ "hook" text NOT NULL,
401
+ "webhook_url" text,
402
+ "created_at" timestamp with time zone DEFAULT now(),
403
+ "updated_at" timestamp with time zone DEFAULT now(),
404
+ CONSTRAINT "agent_plugins_plugin_type_check" CHECK ("agent_plugins"."plugin_type" IN ('webhook','transform','schedule')),
405
+ CONSTRAINT "agent_plugins_hook_check" CHECK ("agent_plugins"."hook" IN ('pre_task','post_task','pre_tool','post_tool','on_memory_save'))
406
+ );
407
+ --> statement-breakpoint
408
+ CREATE TABLE "configurator_sessions" (
409
+ "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL,
410
+ "entity_id" uuid NOT NULL,
411
+ "agent_id" uuid,
412
+ "messages" jsonb DEFAULT '[]'::jsonb NOT NULL,
413
+ "status" text DEFAULT 'active' NOT NULL,
414
+ "turn_count" integer DEFAULT 0 NOT NULL,
415
+ "created_at" timestamp with time zone DEFAULT now() NOT NULL,
416
+ "updated_at" timestamp with time zone DEFAULT now() NOT NULL
417
+ );
418
+ --> statement-breakpoint
419
+ CREATE TABLE "rate_limits" (
420
+ "key" text PRIMARY KEY NOT NULL,
421
+ "count" integer DEFAULT 1,
422
+ "window_start" timestamp with time zone DEFAULT now()
423
+ );
424
+ --> statement-breakpoint
425
+ ALTER TABLE "user_profiles" ADD CONSTRAINT "user_profiles_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
426
+ ALTER TABLE "entities" ADD CONSTRAINT "entities_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
427
+ ALTER TABLE "entity_members" ADD CONSTRAINT "entity_members_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
428
+ ALTER TABLE "entity_members" ADD CONSTRAINT "entity_members_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
429
+ ALTER TABLE "agent_assignments" ADD CONSTRAINT "agent_assignments_orchestrator_id_agents_id_fk" FOREIGN KEY ("orchestrator_id") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
430
+ ALTER TABLE "agent_assignments" ADD CONSTRAINT "agent_assignments_sub_agent_id_agents_id_fk" FOREIGN KEY ("sub_agent_id") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
431
+ ALTER TABLE "agent_assignments" ADD CONSTRAINT "agent_assignments_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
432
+ ALTER TABLE "agent_budgets" ADD CONSTRAINT "agent_budgets_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
433
+ ALTER TABLE "agent_budgets" ADD CONSTRAINT "agent_budgets_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
434
+ ALTER TABLE "agents" ADD CONSTRAINT "agents_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
435
+ ALTER TABLE "agent_jobs" ADD CONSTRAINT "agent_jobs_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
436
+ ALTER TABLE "agent_jobs" ADD CONSTRAINT "agent_jobs_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
437
+ ALTER TABLE "agent_tasks" ADD CONSTRAINT "agent_tasks_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
438
+ ALTER TABLE "agent_tasks" ADD CONSTRAINT "agent_tasks_orchestrator_id_agents_id_fk" FOREIGN KEY ("orchestrator_id") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
439
+ ALTER TABLE "agent_tasks" ADD CONSTRAINT "agent_tasks_job_id_agent_jobs_id_fk" FOREIGN KEY ("job_id") REFERENCES "public"."agent_jobs"("id") ON DELETE set null ON UPDATE no action;--> statement-breakpoint
440
+ ALTER TABLE "agent_tasks" ADD CONSTRAINT "agent_tasks_created_by_agent_id_agents_id_fk" FOREIGN KEY ("created_by_agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
441
+ ALTER TABLE "agent_tasks" ADD CONSTRAINT "agent_tasks_assigned_agent_id_agents_id_fk" FOREIGN KEY ("assigned_agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
442
+ ALTER TABLE "connectors" ADD CONSTRAINT "connectors_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
443
+ ALTER TABLE "tool_calls" ADD CONSTRAINT "tool_calls_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
444
+ ALTER TABLE "tool_calls" ADD CONSTRAINT "tool_calls_job_id_agent_jobs_id_fk" FOREIGN KEY ("job_id") REFERENCES "public"."agent_jobs"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
445
+ ALTER TABLE "approval_requests" ADD CONSTRAINT "approval_requests_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
446
+ ALTER TABLE "approval_requests" ADD CONSTRAINT "approval_requests_job_id_agent_jobs_id_fk" FOREIGN KEY ("job_id") REFERENCES "public"."agent_jobs"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
447
+ ALTER TABLE "approval_requests" ADD CONSTRAINT "approval_requests_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
448
+ ALTER TABLE "approval_rules" ADD CONSTRAINT "approval_rules_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
449
+ ALTER TABLE "approval_rules" ADD CONSTRAINT "approval_rules_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
450
+ ALTER TABLE "agent_memory" ADD CONSTRAINT "agent_memory_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
451
+ ALTER TABLE "agent_memory" ADD CONSTRAINT "agent_memory_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
452
+ ALTER TABLE "webhook_triggers" ADD CONSTRAINT "webhook_triggers_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
453
+ ALTER TABLE "webhook_triggers" ADD CONSTRAINT "webhook_triggers_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
454
+ ALTER TABLE "agent_skill_assignments" ADD CONSTRAINT "agent_skill_assignments_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
455
+ ALTER TABLE "agent_skill_assignments" ADD CONSTRAINT "agent_skill_assignments_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
456
+ ALTER TABLE "agent_skill_assignments" ADD CONSTRAINT "agent_skill_assignments_skill_id_agent_skills_id_fk" FOREIGN KEY ("skill_id") REFERENCES "public"."agent_skills"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
457
+ ALTER TABLE "agent_skills" ADD CONSTRAINT "agent_skills_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
458
+ ALTER TABLE "skill_connectors" ADD CONSTRAINT "skill_connectors_skill_id_agent_skills_id_fk" FOREIGN KEY ("skill_id") REFERENCES "public"."agent_skills"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
459
+ ALTER TABLE "skill_connectors" ADD CONSTRAINT "skill_connectors_connector_id_connectors_id_fk" FOREIGN KEY ("connector_id") REFERENCES "public"."connectors"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
460
+ ALTER TABLE "skill_connectors" ADD CONSTRAINT "skill_connectors_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
461
+ ALTER TABLE "skill_versions" ADD CONSTRAINT "skill_versions_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
462
+ ALTER TABLE "skill_versions" ADD CONSTRAINT "skill_versions_skill_id_agent_skills_id_fk" FOREIGN KEY ("skill_id") REFERENCES "public"."agent_skills"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
463
+ ALTER TABLE "agent_schedules" ADD CONSTRAINT "agent_schedules_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
464
+ ALTER TABLE "agent_schedules" ADD CONSTRAINT "agent_schedules_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
465
+ ALTER TABLE "entity_llm_keys" ADD CONSTRAINT "entity_llm_keys_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
466
+ ALTER TABLE "agent_runs" ADD CONSTRAINT "agent_runs_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
467
+ ALTER TABLE "agent_runs" ADD CONSTRAINT "agent_runs_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE no action ON UPDATE no action;--> statement-breakpoint
468
+ ALTER TABLE "agent_mcp_servers" ADD CONSTRAINT "agent_mcp_servers_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
469
+ ALTER TABLE "agent_mcp_servers" ADD CONSTRAINT "agent_mcp_servers_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
470
+ ALTER TABLE "agent_mcp_servers" ADD CONSTRAINT "agent_mcp_servers_mcp_server_id_mcp_servers_id_fk" FOREIGN KEY ("mcp_server_id") REFERENCES "public"."mcp_servers"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
471
+ ALTER TABLE "mcp_connections" ADD CONSTRAINT "mcp_connections_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
472
+ ALTER TABLE "mcp_servers" ADD CONSTRAINT "mcp_servers_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
473
+ ALTER TABLE "agent_plugins" ADD CONSTRAINT "agent_plugins_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
474
+ ALTER TABLE "configurator_sessions" ADD CONSTRAINT "configurator_sessions_entity_id_entities_id_fk" FOREIGN KEY ("entity_id") REFERENCES "public"."entities"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
475
+ ALTER TABLE "configurator_sessions" ADD CONSTRAINT "configurator_sessions_agent_id_agents_id_fk" FOREIGN KEY ("agent_id") REFERENCES "public"."agents"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint
476
+ CREATE UNIQUE INDEX "entities_mcp_token_idx" ON "entities" USING btree ("mcp_token");--> statement-breakpoint
477
+ CREATE INDEX "idx_entities_user_id" ON "entities" USING btree ("user_id");--> statement-breakpoint
478
+ CREATE INDEX "idx_entity_members_entity_id" ON "entity_members" USING btree ("entity_id");--> statement-breakpoint
479
+ CREATE INDEX "idx_entity_members_user_id" ON "entity_members" USING btree ("user_id");--> statement-breakpoint
480
+ CREATE INDEX "idx_entity_members_user" ON "entity_members" USING btree ("user_id","entity_id");--> statement-breakpoint
481
+ CREATE INDEX "idx_agent_budgets_entity_id" ON "agent_budgets" USING btree ("entity_id");--> statement-breakpoint
482
+ CREATE INDEX "idx_agents_entity_id" ON "agents" USING btree ("entity_id");--> statement-breakpoint
483
+ CREATE INDEX "idx_agent_jobs_entity_id" ON "agent_jobs" USING btree ("entity_id");--> statement-breakpoint
484
+ CREATE INDEX "idx_agent_jobs_entity_created" ON "agent_jobs" USING btree ("entity_id","created_at" DESC);--> statement-breakpoint
485
+ CREATE INDEX "idx_agent_jobs_entity_status_created" ON "agent_jobs" USING btree ("entity_id","status","created_at" DESC);--> statement-breakpoint
486
+ CREATE INDEX "idx_agent_jobs_parent_job_id" ON "agent_jobs" USING btree ("parent_job_id");--> statement-breakpoint
487
+ CREATE INDEX "idx_jobs_parent" ON "agent_jobs" USING btree ("parent_job_id");--> statement-breakpoint
488
+ CREATE INDEX "idx_jobs_status" ON "agent_jobs" USING btree ("status","created_at");--> statement-breakpoint
489
+ CREATE INDEX "idx_agent_tasks_entity" ON "agent_tasks" USING btree ("entity_id");--> statement-breakpoint
490
+ CREATE INDEX "idx_agent_tasks_entity_status_created" ON "agent_tasks" USING btree ("entity_id","status","created_at" DESC);--> statement-breakpoint
491
+ CREATE INDEX "idx_agent_tasks_orchestrator_status" ON "agent_tasks" USING btree ("orchestrator_id","status");--> statement-breakpoint
492
+ CREATE INDEX "idx_agent_tasks_status" ON "agent_tasks" USING btree ("status");--> statement-breakpoint
493
+ CREATE INDEX "idx_agent_tasks_assigned" ON "agent_tasks" USING btree ("assigned_agent_id");--> statement-breakpoint
494
+ CREATE INDEX "idx_connectors_entity_id" ON "connectors" USING btree ("entity_id");--> statement-breakpoint
495
+ CREATE INDEX "idx_tool_calls_entity_id" ON "tool_calls" USING btree ("entity_id");--> statement-breakpoint
496
+ CREATE INDEX "idx_tool_calls_job" ON "tool_calls" USING btree ("job_id");--> statement-breakpoint
497
+ CREATE INDEX "idx_tool_calls_job_created" ON "tool_calls" USING btree ("job_id","created_at" DESC);--> statement-breakpoint
498
+ CREATE INDEX "idx_tool_calls_recent" ON "tool_calls" USING btree ("created_at" DESC);--> statement-breakpoint
499
+ CREATE INDEX "idx_approval_requests_entity_id" ON "approval_requests" USING btree ("entity_id");--> statement-breakpoint
500
+ CREATE INDEX "idx_approval_status" ON "approval_requests" USING btree ("status","requested_at");--> statement-breakpoint
501
+ CREATE INDEX "idx_approval_requests_agent_id" ON "approval_requests" USING btree ("agent_id");--> statement-breakpoint
502
+ CREATE INDEX "idx_approval_requests_job_id" ON "approval_requests" USING btree ("job_id");--> statement-breakpoint
503
+ CREATE INDEX "idx_approval_rules_entity_id" ON "approval_rules" USING btree ("entity_id");--> statement-breakpoint
504
+ CREATE INDEX "idx_agent_memory_entity_id" ON "agent_memory" USING btree ("entity_id");--> statement-breakpoint
505
+ CREATE INDEX "idx_agent_memory_entity_active" ON "agent_memory" USING btree ("entity_id","archived","valid_to");--> statement-breakpoint
506
+ CREATE INDEX "idx_agent_memory_archived" ON "agent_memory" USING btree ("archived");--> statement-breakpoint
507
+ CREATE INDEX "idx_agent_memory_last_accessed" ON "agent_memory" USING btree ("last_accessed_at");--> statement-breakpoint
508
+ CREATE INDEX "idx_agent_memory_layer" ON "agent_memory" USING btree ("memory_layer");--> statement-breakpoint
509
+ CREATE INDEX "idx_agent_memory_fact_hash" ON "agent_memory" USING btree ("fact_hash");--> statement-breakpoint
510
+ CREATE INDEX "idx_memory_category" ON "agent_memory" USING btree ("category","importance" DESC);--> statement-breakpoint
511
+ CREATE INDEX "idx_webhook_triggers_entity_id" ON "webhook_triggers" USING btree ("entity_id");--> statement-breakpoint
512
+ CREATE INDEX "idx_agent_skills_entity_id" ON "agent_skills" USING btree ("entity_id");--> statement-breakpoint
513
+ CREATE INDEX "idx_skills_active" ON "agent_skills" USING btree ("active","slug");--> statement-breakpoint
514
+ CREATE INDEX "idx_skill_connectors_entity_id" ON "skill_connectors" USING btree ("entity_id");--> statement-breakpoint
515
+ CREATE INDEX "idx_skill_connectors_skill_id" ON "skill_connectors" USING btree ("skill_id");--> statement-breakpoint
516
+ CREATE INDEX "idx_skill_versions_entity_id" ON "skill_versions" USING btree ("entity_id");--> statement-breakpoint
517
+ CREATE INDEX "idx_skill_versions_skill_id" ON "skill_versions" USING btree ("skill_id","version" DESC);--> statement-breakpoint
518
+ CREATE INDEX "idx_agent_schedules_entity_id" ON "agent_schedules" USING btree ("entity_id");--> statement-breakpoint
519
+ CREATE INDEX "idx_schedules_active" ON "agent_schedules" USING btree ("active","next_run");--> statement-breakpoint
520
+ CREATE INDEX "idx_entity_llm_keys_entity_id" ON "entity_llm_keys" USING btree ("entity_id");--> statement-breakpoint
521
+ CREATE INDEX "idx_agent_runs_entity_id" ON "agent_runs" USING btree ("entity_id");--> statement-breakpoint
522
+ CREATE INDEX "idx_agent_runs_agent_created" ON "agent_runs" USING btree ("agent_id","created_at" DESC);--> statement-breakpoint
523
+ CREATE INDEX "idx_runs_agent" ON "agent_runs" USING btree ("agent_id","created_at" DESC);--> statement-breakpoint
524
+ CREATE INDEX "idx_runs_recent" ON "agent_runs" USING btree ("created_at" DESC);--> statement-breakpoint
525
+ CREATE INDEX "idx_agent_mcp_servers_agent" ON "agent_mcp_servers" USING btree ("agent_id");--> statement-breakpoint
526
+ CREATE INDEX "idx_agent_mcp_servers_entity" ON "agent_mcp_servers" USING btree ("entity_id");--> statement-breakpoint
527
+ CREATE INDEX "idx_mcp_connections_entity" ON "mcp_connections" USING btree ("entity_id");--> statement-breakpoint
528
+ CREATE INDEX "idx_configurator_sessions_entity" ON "configurator_sessions" USING btree ("entity_id");--> statement-breakpoint
529
529
  CREATE INDEX "idx_configurator_sessions_agent" ON "configurator_sessions" USING btree ("agent_id");