kubiya-control-plane-api 0.9.15__py3-none-any.whl

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 (479) hide show
  1. control_plane_api/LICENSE +676 -0
  2. control_plane_api/README.md +350 -0
  3. control_plane_api/__init__.py +4 -0
  4. control_plane_api/__version__.py +8 -0
  5. control_plane_api/alembic/README +1 -0
  6. control_plane_api/alembic/env.py +121 -0
  7. control_plane_api/alembic/script.py.mako +28 -0
  8. control_plane_api/alembic/versions/2613c65c3dbe_initial_database_setup.py +32 -0
  9. control_plane_api/alembic/versions/2df520d4927d_merge_heads.py +28 -0
  10. control_plane_api/alembic/versions/43abf98d6a01_add_paused_status_to_executions.py +73 -0
  11. control_plane_api/alembic/versions/6289854264cb_merge_multiple_heads.py +28 -0
  12. control_plane_api/alembic/versions/6a4d4dc3d8dc_generate_execution_transitions.py +50 -0
  13. control_plane_api/alembic/versions/87d11cf0a783_add_disconnected_status_to_worker_.py +44 -0
  14. control_plane_api/alembic/versions/add_ephemeral_queue_support.py +85 -0
  15. control_plane_api/alembic/versions/add_model_type_to_llm_models.py +31 -0
  16. control_plane_api/alembic/versions/add_plan_executions_table.py +114 -0
  17. control_plane_api/alembic/versions/add_trace_span_tables.py +154 -0
  18. control_plane_api/alembic/versions/add_user_info_to_traces.py +36 -0
  19. control_plane_api/alembic/versions/adjusting_foreign_keys.py +32 -0
  20. control_plane_api/alembic/versions/b4983d976db2_initial_tables.py +1128 -0
  21. control_plane_api/alembic/versions/d181a3b40e71_rename_custom_metadata_to_metadata_in_.py +50 -0
  22. control_plane_api/alembic/versions/df9117888e82_add_missing_columns.py +82 -0
  23. control_plane_api/alembic/versions/f25de6ad895a_missing_migrations.py +34 -0
  24. control_plane_api/alembic/versions/f71305fb69b9_fix_ephemeral_queue_deletion_foreign_key.py +54 -0
  25. control_plane_api/alembic/versions/mark_local_exec_queues_as_ephemeral.py +68 -0
  26. control_plane_api/alembic.ini +148 -0
  27. control_plane_api/api/index.py +12 -0
  28. control_plane_api/app/__init__.py +11 -0
  29. control_plane_api/app/activities/__init__.py +20 -0
  30. control_plane_api/app/activities/agent_activities.py +384 -0
  31. control_plane_api/app/activities/plan_generation_activities.py +499 -0
  32. control_plane_api/app/activities/team_activities.py +424 -0
  33. control_plane_api/app/activities/temporal_cloud_activities.py +588 -0
  34. control_plane_api/app/config/__init__.py +35 -0
  35. control_plane_api/app/config/api_config.py +469 -0
  36. control_plane_api/app/config/config_loader.py +224 -0
  37. control_plane_api/app/config/model_pricing.py +323 -0
  38. control_plane_api/app/config/storage_config.py +159 -0
  39. control_plane_api/app/config.py +115 -0
  40. control_plane_api/app/controllers/__init__.py +0 -0
  41. control_plane_api/app/controllers/execution_environment_controller.py +1315 -0
  42. control_plane_api/app/database.py +135 -0
  43. control_plane_api/app/exceptions.py +408 -0
  44. control_plane_api/app/lib/__init__.py +11 -0
  45. control_plane_api/app/lib/environment.py +65 -0
  46. control_plane_api/app/lib/event_bus/__init__.py +17 -0
  47. control_plane_api/app/lib/event_bus/base.py +136 -0
  48. control_plane_api/app/lib/event_bus/manager.py +335 -0
  49. control_plane_api/app/lib/event_bus/providers/__init__.py +6 -0
  50. control_plane_api/app/lib/event_bus/providers/http_provider.py +166 -0
  51. control_plane_api/app/lib/event_bus/providers/nats_provider.py +324 -0
  52. control_plane_api/app/lib/event_bus/providers/redis_provider.py +233 -0
  53. control_plane_api/app/lib/event_bus/providers/websocket_provider.py +497 -0
  54. control_plane_api/app/lib/job_executor.py +330 -0
  55. control_plane_api/app/lib/kubiya_client.py +293 -0
  56. control_plane_api/app/lib/litellm_pricing.py +166 -0
  57. control_plane_api/app/lib/mcp_validation.py +163 -0
  58. control_plane_api/app/lib/nats/__init__.py +13 -0
  59. control_plane_api/app/lib/nats/credentials_manager.py +288 -0
  60. control_plane_api/app/lib/nats/listener.py +374 -0
  61. control_plane_api/app/lib/planning_prompt_builder.py +153 -0
  62. control_plane_api/app/lib/planning_tools/__init__.py +41 -0
  63. control_plane_api/app/lib/planning_tools/agents.py +409 -0
  64. control_plane_api/app/lib/planning_tools/agno_toolkit.py +836 -0
  65. control_plane_api/app/lib/planning_tools/base.py +119 -0
  66. control_plane_api/app/lib/planning_tools/cognitive_memory_tools.py +403 -0
  67. control_plane_api/app/lib/planning_tools/context_graph_tools.py +545 -0
  68. control_plane_api/app/lib/planning_tools/environments.py +218 -0
  69. control_plane_api/app/lib/planning_tools/knowledge.py +204 -0
  70. control_plane_api/app/lib/planning_tools/models.py +93 -0
  71. control_plane_api/app/lib/planning_tools/planning_service.py +646 -0
  72. control_plane_api/app/lib/planning_tools/resources.py +242 -0
  73. control_plane_api/app/lib/planning_tools/teams.py +334 -0
  74. control_plane_api/app/lib/policy_enforcer_client.py +1016 -0
  75. control_plane_api/app/lib/redis_client.py +803 -0
  76. control_plane_api/app/lib/sqlalchemy_utils.py +486 -0
  77. control_plane_api/app/lib/state_transition_tools/__init__.py +7 -0
  78. control_plane_api/app/lib/state_transition_tools/execution_context.py +388 -0
  79. control_plane_api/app/lib/storage/__init__.py +20 -0
  80. control_plane_api/app/lib/storage/base_provider.py +274 -0
  81. control_plane_api/app/lib/storage/provider_factory.py +157 -0
  82. control_plane_api/app/lib/storage/vercel_blob_provider.py +468 -0
  83. control_plane_api/app/lib/supabase.py +71 -0
  84. control_plane_api/app/lib/supabase_utils.py +138 -0
  85. control_plane_api/app/lib/task_planning/__init__.py +138 -0
  86. control_plane_api/app/lib/task_planning/agent_factory.py +308 -0
  87. control_plane_api/app/lib/task_planning/agents.py +389 -0
  88. control_plane_api/app/lib/task_planning/cache.py +218 -0
  89. control_plane_api/app/lib/task_planning/entity_resolver.py +273 -0
  90. control_plane_api/app/lib/task_planning/helpers.py +293 -0
  91. control_plane_api/app/lib/task_planning/hooks.py +474 -0
  92. control_plane_api/app/lib/task_planning/models.py +503 -0
  93. control_plane_api/app/lib/task_planning/plan_validator.py +166 -0
  94. control_plane_api/app/lib/task_planning/planning_workflow.py +2911 -0
  95. control_plane_api/app/lib/task_planning/runner.py +656 -0
  96. control_plane_api/app/lib/task_planning/streaming_hook.py +213 -0
  97. control_plane_api/app/lib/task_planning/workflow.py +424 -0
  98. control_plane_api/app/lib/templating/__init__.py +88 -0
  99. control_plane_api/app/lib/templating/compiler.py +278 -0
  100. control_plane_api/app/lib/templating/engine.py +178 -0
  101. control_plane_api/app/lib/templating/parsers/__init__.py +29 -0
  102. control_plane_api/app/lib/templating/parsers/base.py +96 -0
  103. control_plane_api/app/lib/templating/parsers/env.py +85 -0
  104. control_plane_api/app/lib/templating/parsers/graph.py +112 -0
  105. control_plane_api/app/lib/templating/parsers/secret.py +87 -0
  106. control_plane_api/app/lib/templating/parsers/simple.py +81 -0
  107. control_plane_api/app/lib/templating/resolver.py +366 -0
  108. control_plane_api/app/lib/templating/types.py +214 -0
  109. control_plane_api/app/lib/templating/validator.py +201 -0
  110. control_plane_api/app/lib/temporal_client.py +232 -0
  111. control_plane_api/app/lib/temporal_credentials_cache.py +178 -0
  112. control_plane_api/app/lib/temporal_credentials_service.py +203 -0
  113. control_plane_api/app/lib/validation/__init__.py +24 -0
  114. control_plane_api/app/lib/validation/runtime_validation.py +388 -0
  115. control_plane_api/app/main.py +531 -0
  116. control_plane_api/app/middleware/__init__.py +10 -0
  117. control_plane_api/app/middleware/auth.py +645 -0
  118. control_plane_api/app/middleware/exception_handler.py +267 -0
  119. control_plane_api/app/middleware/prometheus_middleware.py +173 -0
  120. control_plane_api/app/middleware/rate_limiting.py +384 -0
  121. control_plane_api/app/middleware/request_id.py +202 -0
  122. control_plane_api/app/models/__init__.py +40 -0
  123. control_plane_api/app/models/agent.py +90 -0
  124. control_plane_api/app/models/analytics.py +206 -0
  125. control_plane_api/app/models/associations.py +107 -0
  126. control_plane_api/app/models/auth_user.py +73 -0
  127. control_plane_api/app/models/context.py +161 -0
  128. control_plane_api/app/models/custom_integration.py +99 -0
  129. control_plane_api/app/models/environment.py +64 -0
  130. control_plane_api/app/models/execution.py +125 -0
  131. control_plane_api/app/models/execution_transition.py +50 -0
  132. control_plane_api/app/models/job.py +159 -0
  133. control_plane_api/app/models/llm_model.py +78 -0
  134. control_plane_api/app/models/orchestration.py +66 -0
  135. control_plane_api/app/models/plan_execution.py +102 -0
  136. control_plane_api/app/models/presence.py +49 -0
  137. control_plane_api/app/models/project.py +61 -0
  138. control_plane_api/app/models/project_management.py +85 -0
  139. control_plane_api/app/models/session.py +29 -0
  140. control_plane_api/app/models/skill.py +155 -0
  141. control_plane_api/app/models/system_tables.py +43 -0
  142. control_plane_api/app/models/task_planning.py +372 -0
  143. control_plane_api/app/models/team.py +86 -0
  144. control_plane_api/app/models/trace.py +257 -0
  145. control_plane_api/app/models/user_profile.py +54 -0
  146. control_plane_api/app/models/worker.py +221 -0
  147. control_plane_api/app/models/workflow.py +161 -0
  148. control_plane_api/app/models/workspace.py +50 -0
  149. control_plane_api/app/observability/__init__.py +177 -0
  150. control_plane_api/app/observability/context_logging.py +475 -0
  151. control_plane_api/app/observability/decorators.py +337 -0
  152. control_plane_api/app/observability/local_span_processor.py +702 -0
  153. control_plane_api/app/observability/metrics.py +303 -0
  154. control_plane_api/app/observability/middleware.py +246 -0
  155. control_plane_api/app/observability/optional.py +115 -0
  156. control_plane_api/app/observability/tracing.py +382 -0
  157. control_plane_api/app/policies/README.md +149 -0
  158. control_plane_api/app/policies/approved_users.rego +62 -0
  159. control_plane_api/app/policies/business_hours.rego +51 -0
  160. control_plane_api/app/policies/rate_limiting.rego +100 -0
  161. control_plane_api/app/policies/tool_enforcement/README.md +336 -0
  162. control_plane_api/app/policies/tool_enforcement/bash_command_validation.rego +71 -0
  163. control_plane_api/app/policies/tool_enforcement/business_hours_enforcement.rego +82 -0
  164. control_plane_api/app/policies/tool_enforcement/mcp_tool_allowlist.rego +58 -0
  165. control_plane_api/app/policies/tool_enforcement/production_safeguards.rego +80 -0
  166. control_plane_api/app/policies/tool_enforcement/role_based_tool_access.rego +44 -0
  167. control_plane_api/app/policies/tool_restrictions.rego +86 -0
  168. control_plane_api/app/routers/__init__.py +4 -0
  169. control_plane_api/app/routers/agents.py +382 -0
  170. control_plane_api/app/routers/agents_v2.py +1598 -0
  171. control_plane_api/app/routers/analytics.py +1310 -0
  172. control_plane_api/app/routers/auth.py +59 -0
  173. control_plane_api/app/routers/client_config.py +57 -0
  174. control_plane_api/app/routers/context_graph.py +561 -0
  175. control_plane_api/app/routers/context_manager.py +577 -0
  176. control_plane_api/app/routers/custom_integrations.py +490 -0
  177. control_plane_api/app/routers/enforcer.py +132 -0
  178. control_plane_api/app/routers/environment_context.py +252 -0
  179. control_plane_api/app/routers/environments.py +761 -0
  180. control_plane_api/app/routers/execution_environment.py +847 -0
  181. control_plane_api/app/routers/executions/__init__.py +28 -0
  182. control_plane_api/app/routers/executions/router.py +286 -0
  183. control_plane_api/app/routers/executions/services/__init__.py +22 -0
  184. control_plane_api/app/routers/executions/services/demo_worker_health.py +156 -0
  185. control_plane_api/app/routers/executions/services/status_service.py +420 -0
  186. control_plane_api/app/routers/executions/services/test_worker_health.py +480 -0
  187. control_plane_api/app/routers/executions/services/worker_health.py +514 -0
  188. control_plane_api/app/routers/executions/streaming/__init__.py +22 -0
  189. control_plane_api/app/routers/executions/streaming/deduplication.py +352 -0
  190. control_plane_api/app/routers/executions/streaming/event_buffer.py +353 -0
  191. control_plane_api/app/routers/executions/streaming/event_formatter.py +964 -0
  192. control_plane_api/app/routers/executions/streaming/history_loader.py +588 -0
  193. control_plane_api/app/routers/executions/streaming/live_source.py +693 -0
  194. control_plane_api/app/routers/executions/streaming/streamer.py +849 -0
  195. control_plane_api/app/routers/executions.py +4888 -0
  196. control_plane_api/app/routers/health.py +165 -0
  197. control_plane_api/app/routers/health_v2.py +394 -0
  198. control_plane_api/app/routers/integration_templates.py +496 -0
  199. control_plane_api/app/routers/integrations.py +287 -0
  200. control_plane_api/app/routers/jobs.py +1809 -0
  201. control_plane_api/app/routers/metrics.py +517 -0
  202. control_plane_api/app/routers/models.py +82 -0
  203. control_plane_api/app/routers/models_v2.py +628 -0
  204. control_plane_api/app/routers/plan_executions.py +1481 -0
  205. control_plane_api/app/routers/plan_generation_async.py +304 -0
  206. control_plane_api/app/routers/policies.py +669 -0
  207. control_plane_api/app/routers/presence.py +234 -0
  208. control_plane_api/app/routers/projects.py +987 -0
  209. control_plane_api/app/routers/runners.py +379 -0
  210. control_plane_api/app/routers/runtimes.py +172 -0
  211. control_plane_api/app/routers/secrets.py +171 -0
  212. control_plane_api/app/routers/skills.py +1010 -0
  213. control_plane_api/app/routers/skills_definitions.py +140 -0
  214. control_plane_api/app/routers/storage.py +456 -0
  215. control_plane_api/app/routers/task_planning.py +611 -0
  216. control_plane_api/app/routers/task_queues.py +650 -0
  217. control_plane_api/app/routers/team_context.py +274 -0
  218. control_plane_api/app/routers/teams.py +1747 -0
  219. control_plane_api/app/routers/templates.py +248 -0
  220. control_plane_api/app/routers/traces.py +571 -0
  221. control_plane_api/app/routers/websocket_client.py +479 -0
  222. control_plane_api/app/routers/websocket_executions_status.py +437 -0
  223. control_plane_api/app/routers/websocket_gateway.py +323 -0
  224. control_plane_api/app/routers/websocket_traces.py +576 -0
  225. control_plane_api/app/routers/worker_queues.py +2555 -0
  226. control_plane_api/app/routers/worker_websocket.py +419 -0
  227. control_plane_api/app/routers/workers.py +1004 -0
  228. control_plane_api/app/routers/workflows.py +204 -0
  229. control_plane_api/app/runtimes/__init__.py +6 -0
  230. control_plane_api/app/runtimes/validation.py +344 -0
  231. control_plane_api/app/schemas/__init__.py +1 -0
  232. control_plane_api/app/schemas/job_schemas.py +302 -0
  233. control_plane_api/app/schemas/mcp_schemas.py +311 -0
  234. control_plane_api/app/schemas/template_schemas.py +133 -0
  235. control_plane_api/app/schemas/trace_schemas.py +168 -0
  236. control_plane_api/app/schemas/worker_queue_observability_schemas.py +165 -0
  237. control_plane_api/app/services/__init__.py +1 -0
  238. control_plane_api/app/services/agno_planning_strategy.py +233 -0
  239. control_plane_api/app/services/agno_service.py +838 -0
  240. control_plane_api/app/services/claude_code_planning_service.py +203 -0
  241. control_plane_api/app/services/context_graph_client.py +224 -0
  242. control_plane_api/app/services/custom_integration_service.py +415 -0
  243. control_plane_api/app/services/integration_resolution_service.py +345 -0
  244. control_plane_api/app/services/litellm_service.py +394 -0
  245. control_plane_api/app/services/plan_generator.py +79 -0
  246. control_plane_api/app/services/planning_strategy.py +66 -0
  247. control_plane_api/app/services/planning_strategy_factory.py +118 -0
  248. control_plane_api/app/services/policy_service.py +615 -0
  249. control_plane_api/app/services/state_transition_service.py +755 -0
  250. control_plane_api/app/services/storage_service.py +593 -0
  251. control_plane_api/app/services/temporal_cloud_provisioning.py +150 -0
  252. control_plane_api/app/services/toolsets/context_graph_skill.py +432 -0
  253. control_plane_api/app/services/trace_retention.py +354 -0
  254. control_plane_api/app/services/worker_queue_metrics_service.py +190 -0
  255. control_plane_api/app/services/workflow_cancellation_manager.py +135 -0
  256. control_plane_api/app/services/workflow_operations_service.py +611 -0
  257. control_plane_api/app/skills/__init__.py +100 -0
  258. control_plane_api/app/skills/base.py +239 -0
  259. control_plane_api/app/skills/builtin/__init__.py +37 -0
  260. control_plane_api/app/skills/builtin/agent_communication/__init__.py +8 -0
  261. control_plane_api/app/skills/builtin/agent_communication/skill.py +246 -0
  262. control_plane_api/app/skills/builtin/code_ingestion/__init__.py +4 -0
  263. control_plane_api/app/skills/builtin/code_ingestion/skill.py +267 -0
  264. control_plane_api/app/skills/builtin/cognitive_memory/__init__.py +4 -0
  265. control_plane_api/app/skills/builtin/cognitive_memory/skill.py +174 -0
  266. control_plane_api/app/skills/builtin/contextual_awareness/__init__.py +4 -0
  267. control_plane_api/app/skills/builtin/contextual_awareness/skill.py +387 -0
  268. control_plane_api/app/skills/builtin/data_visualization/__init__.py +4 -0
  269. control_plane_api/app/skills/builtin/data_visualization/skill.py +154 -0
  270. control_plane_api/app/skills/builtin/docker/__init__.py +4 -0
  271. control_plane_api/app/skills/builtin/docker/skill.py +104 -0
  272. control_plane_api/app/skills/builtin/file_generation/__init__.py +4 -0
  273. control_plane_api/app/skills/builtin/file_generation/skill.py +94 -0
  274. control_plane_api/app/skills/builtin/file_system/__init__.py +4 -0
  275. control_plane_api/app/skills/builtin/file_system/skill.py +110 -0
  276. control_plane_api/app/skills/builtin/knowledge_api/__init__.py +5 -0
  277. control_plane_api/app/skills/builtin/knowledge_api/skill.py +124 -0
  278. control_plane_api/app/skills/builtin/python/__init__.py +4 -0
  279. control_plane_api/app/skills/builtin/python/skill.py +92 -0
  280. control_plane_api/app/skills/builtin/remote_filesystem/__init__.py +5 -0
  281. control_plane_api/app/skills/builtin/remote_filesystem/skill.py +170 -0
  282. control_plane_api/app/skills/builtin/shell/__init__.py +4 -0
  283. control_plane_api/app/skills/builtin/shell/skill.py +161 -0
  284. control_plane_api/app/skills/builtin/slack/__init__.py +3 -0
  285. control_plane_api/app/skills/builtin/slack/skill.py +302 -0
  286. control_plane_api/app/skills/builtin/workflow_executor/__init__.py +4 -0
  287. control_plane_api/app/skills/builtin/workflow_executor/skill.py +469 -0
  288. control_plane_api/app/skills/business_intelligence.py +189 -0
  289. control_plane_api/app/skills/config.py +63 -0
  290. control_plane_api/app/skills/loaders/__init__.py +14 -0
  291. control_plane_api/app/skills/loaders/base.py +73 -0
  292. control_plane_api/app/skills/loaders/filesystem_loader.py +199 -0
  293. control_plane_api/app/skills/registry.py +125 -0
  294. control_plane_api/app/utils/helpers.py +12 -0
  295. control_plane_api/app/utils/workflow_executor.py +354 -0
  296. control_plane_api/app/workflows/__init__.py +11 -0
  297. control_plane_api/app/workflows/agent_execution.py +520 -0
  298. control_plane_api/app/workflows/agent_execution_with_skills.py +223 -0
  299. control_plane_api/app/workflows/namespace_provisioning.py +326 -0
  300. control_plane_api/app/workflows/plan_generation.py +254 -0
  301. control_plane_api/app/workflows/team_execution.py +442 -0
  302. control_plane_api/scripts/seed_models.py +240 -0
  303. control_plane_api/scripts/validate_existing_tool_names.py +492 -0
  304. control_plane_api/shared/__init__.py +8 -0
  305. control_plane_api/shared/version.py +17 -0
  306. control_plane_api/test_deduplication.py +274 -0
  307. control_plane_api/test_executor_deduplication_e2e.py +309 -0
  308. control_plane_api/test_job_execution_e2e.py +283 -0
  309. control_plane_api/test_real_integration.py +193 -0
  310. control_plane_api/version.py +38 -0
  311. control_plane_api/worker/__init__.py +0 -0
  312. control_plane_api/worker/activities/__init__.py +0 -0
  313. control_plane_api/worker/activities/agent_activities.py +1585 -0
  314. control_plane_api/worker/activities/approval_activities.py +234 -0
  315. control_plane_api/worker/activities/job_activities.py +199 -0
  316. control_plane_api/worker/activities/runtime_activities.py +1167 -0
  317. control_plane_api/worker/activities/skill_activities.py +282 -0
  318. control_plane_api/worker/activities/team_activities.py +479 -0
  319. control_plane_api/worker/agent_runtime_server.py +370 -0
  320. control_plane_api/worker/binary_manager.py +333 -0
  321. control_plane_api/worker/config/__init__.py +31 -0
  322. control_plane_api/worker/config/worker_config.py +273 -0
  323. control_plane_api/worker/control_plane_client.py +1491 -0
  324. control_plane_api/worker/examples/analytics_integration_example.py +362 -0
  325. control_plane_api/worker/health_monitor.py +159 -0
  326. control_plane_api/worker/metrics.py +237 -0
  327. control_plane_api/worker/models/__init__.py +1 -0
  328. control_plane_api/worker/models/error_events.py +105 -0
  329. control_plane_api/worker/models/inputs.py +89 -0
  330. control_plane_api/worker/runtimes/__init__.py +35 -0
  331. control_plane_api/worker/runtimes/agent_runtime/runtime.py +485 -0
  332. control_plane_api/worker/runtimes/agno/__init__.py +34 -0
  333. control_plane_api/worker/runtimes/agno/config.py +248 -0
  334. control_plane_api/worker/runtimes/agno/hooks.py +385 -0
  335. control_plane_api/worker/runtimes/agno/mcp_builder.py +195 -0
  336. control_plane_api/worker/runtimes/agno/runtime.py +1063 -0
  337. control_plane_api/worker/runtimes/agno/utils.py +163 -0
  338. control_plane_api/worker/runtimes/base.py +979 -0
  339. control_plane_api/worker/runtimes/claude_code/__init__.py +38 -0
  340. control_plane_api/worker/runtimes/claude_code/cleanup.py +184 -0
  341. control_plane_api/worker/runtimes/claude_code/client_pool.py +529 -0
  342. control_plane_api/worker/runtimes/claude_code/config.py +829 -0
  343. control_plane_api/worker/runtimes/claude_code/hooks.py +482 -0
  344. control_plane_api/worker/runtimes/claude_code/litellm_proxy.py +1702 -0
  345. control_plane_api/worker/runtimes/claude_code/mcp_builder.py +467 -0
  346. control_plane_api/worker/runtimes/claude_code/mcp_discovery.py +558 -0
  347. control_plane_api/worker/runtimes/claude_code/runtime.py +1546 -0
  348. control_plane_api/worker/runtimes/claude_code/tool_mapper.py +403 -0
  349. control_plane_api/worker/runtimes/claude_code/utils.py +149 -0
  350. control_plane_api/worker/runtimes/factory.py +173 -0
  351. control_plane_api/worker/runtimes/model_utils.py +107 -0
  352. control_plane_api/worker/runtimes/validation.py +93 -0
  353. control_plane_api/worker/services/__init__.py +1 -0
  354. control_plane_api/worker/services/agent_communication_tools.py +908 -0
  355. control_plane_api/worker/services/agent_executor.py +485 -0
  356. control_plane_api/worker/services/agent_executor_v2.py +793 -0
  357. control_plane_api/worker/services/analytics_collector.py +457 -0
  358. control_plane_api/worker/services/analytics_service.py +464 -0
  359. control_plane_api/worker/services/approval_tools.py +310 -0
  360. control_plane_api/worker/services/approval_tools_agno.py +207 -0
  361. control_plane_api/worker/services/cancellation_manager.py +177 -0
  362. control_plane_api/worker/services/code_ingestion_tools.py +465 -0
  363. control_plane_api/worker/services/contextual_awareness_tools.py +405 -0
  364. control_plane_api/worker/services/data_visualization.py +834 -0
  365. control_plane_api/worker/services/event_publisher.py +531 -0
  366. control_plane_api/worker/services/jira_tools.py +257 -0
  367. control_plane_api/worker/services/remote_filesystem_tools.py +498 -0
  368. control_plane_api/worker/services/runtime_analytics.py +328 -0
  369. control_plane_api/worker/services/session_service.py +365 -0
  370. control_plane_api/worker/services/skill_context_enhancement.py +181 -0
  371. control_plane_api/worker/services/skill_factory.py +471 -0
  372. control_plane_api/worker/services/system_prompt_enhancement.py +410 -0
  373. control_plane_api/worker/services/team_executor.py +715 -0
  374. control_plane_api/worker/services/team_executor_v2.py +1866 -0
  375. control_plane_api/worker/services/tool_enforcement.py +254 -0
  376. control_plane_api/worker/services/workflow_executor/__init__.py +52 -0
  377. control_plane_api/worker/services/workflow_executor/event_processor.py +287 -0
  378. control_plane_api/worker/services/workflow_executor/event_publisher.py +210 -0
  379. control_plane_api/worker/services/workflow_executor/executors/__init__.py +15 -0
  380. control_plane_api/worker/services/workflow_executor/executors/base.py +270 -0
  381. control_plane_api/worker/services/workflow_executor/executors/json_executor.py +50 -0
  382. control_plane_api/worker/services/workflow_executor/executors/python_executor.py +50 -0
  383. control_plane_api/worker/services/workflow_executor/models.py +142 -0
  384. control_plane_api/worker/services/workflow_executor_tools.py +1748 -0
  385. control_plane_api/worker/skills/__init__.py +12 -0
  386. control_plane_api/worker/skills/builtin/context_graph_search/README.md +213 -0
  387. control_plane_api/worker/skills/builtin/context_graph_search/__init__.py +5 -0
  388. control_plane_api/worker/skills/builtin/context_graph_search/agno_impl.py +808 -0
  389. control_plane_api/worker/skills/builtin/context_graph_search/skill.yaml +67 -0
  390. control_plane_api/worker/skills/builtin/contextual_awareness/__init__.py +4 -0
  391. control_plane_api/worker/skills/builtin/contextual_awareness/agno_impl.py +62 -0
  392. control_plane_api/worker/skills/builtin/data_visualization/agno_impl.py +18 -0
  393. control_plane_api/worker/skills/builtin/data_visualization/skill.yaml +84 -0
  394. control_plane_api/worker/skills/builtin/docker/agno_impl.py +65 -0
  395. control_plane_api/worker/skills/builtin/docker/skill.yaml +60 -0
  396. control_plane_api/worker/skills/builtin/file_generation/agno_impl.py +47 -0
  397. control_plane_api/worker/skills/builtin/file_generation/skill.yaml +64 -0
  398. control_plane_api/worker/skills/builtin/file_system/agno_impl.py +32 -0
  399. control_plane_api/worker/skills/builtin/file_system/skill.yaml +54 -0
  400. control_plane_api/worker/skills/builtin/knowledge_api/__init__.py +4 -0
  401. control_plane_api/worker/skills/builtin/knowledge_api/agno_impl.py +50 -0
  402. control_plane_api/worker/skills/builtin/knowledge_api/skill.yaml +66 -0
  403. control_plane_api/worker/skills/builtin/python/agno_impl.py +25 -0
  404. control_plane_api/worker/skills/builtin/python/skill.yaml +60 -0
  405. control_plane_api/worker/skills/builtin/schema_fix_mixin.py +260 -0
  406. control_plane_api/worker/skills/builtin/shell/agno_impl.py +31 -0
  407. control_plane_api/worker/skills/builtin/shell/skill.yaml +60 -0
  408. control_plane_api/worker/skills/builtin/slack/__init__.py +3 -0
  409. control_plane_api/worker/skills/builtin/slack/agno_impl.py +1282 -0
  410. control_plane_api/worker/skills/builtin/slack/skill.yaml +276 -0
  411. control_plane_api/worker/skills/builtin/workflow_executor/agno_impl.py +62 -0
  412. control_plane_api/worker/skills/builtin/workflow_executor/skill.yaml +79 -0
  413. control_plane_api/worker/skills/loaders/__init__.py +5 -0
  414. control_plane_api/worker/skills/loaders/base.py +23 -0
  415. control_plane_api/worker/skills/loaders/filesystem_loader.py +357 -0
  416. control_plane_api/worker/skills/registry.py +208 -0
  417. control_plane_api/worker/tests/__init__.py +1 -0
  418. control_plane_api/worker/tests/conftest.py +12 -0
  419. control_plane_api/worker/tests/e2e/__init__.py +0 -0
  420. control_plane_api/worker/tests/e2e/test_context_graph_real_api.py +338 -0
  421. control_plane_api/worker/tests/e2e/test_context_graph_templates_e2e.py +523 -0
  422. control_plane_api/worker/tests/e2e/test_enforcement_e2e.py +344 -0
  423. control_plane_api/worker/tests/e2e/test_execution_flow.py +571 -0
  424. control_plane_api/worker/tests/e2e/test_single_execution_mode.py +656 -0
  425. control_plane_api/worker/tests/integration/__init__.py +0 -0
  426. control_plane_api/worker/tests/integration/test_builtin_skills_fixes.py +245 -0
  427. control_plane_api/worker/tests/integration/test_context_graph_search_integration.py +365 -0
  428. control_plane_api/worker/tests/integration/test_control_plane_integration.py +308 -0
  429. control_plane_api/worker/tests/integration/test_hook_enforcement_integration.py +579 -0
  430. control_plane_api/worker/tests/integration/test_scheduled_job_workflow.py +237 -0
  431. control_plane_api/worker/tests/integration/test_system_prompt_enhancement_integration.py +343 -0
  432. control_plane_api/worker/tests/unit/__init__.py +0 -0
  433. control_plane_api/worker/tests/unit/test_builtin_skill_autoload.py +396 -0
  434. control_plane_api/worker/tests/unit/test_context_graph_search.py +450 -0
  435. control_plane_api/worker/tests/unit/test_context_graph_templates.py +403 -0
  436. control_plane_api/worker/tests/unit/test_control_plane_client.py +401 -0
  437. control_plane_api/worker/tests/unit/test_control_plane_client_jobs.py +345 -0
  438. control_plane_api/worker/tests/unit/test_job_activities.py +353 -0
  439. control_plane_api/worker/tests/unit/test_skill_context_enhancement.py +321 -0
  440. control_plane_api/worker/tests/unit/test_system_prompt_enhancement.py +415 -0
  441. control_plane_api/worker/tests/unit/test_tool_enforcement.py +324 -0
  442. control_plane_api/worker/utils/__init__.py +1 -0
  443. control_plane_api/worker/utils/chunk_batcher.py +330 -0
  444. control_plane_api/worker/utils/environment.py +65 -0
  445. control_plane_api/worker/utils/error_publisher.py +260 -0
  446. control_plane_api/worker/utils/event_batcher.py +256 -0
  447. control_plane_api/worker/utils/logging_config.py +335 -0
  448. control_plane_api/worker/utils/logging_helper.py +326 -0
  449. control_plane_api/worker/utils/parameter_validator.py +120 -0
  450. control_plane_api/worker/utils/retry_utils.py +60 -0
  451. control_plane_api/worker/utils/streaming_utils.py +665 -0
  452. control_plane_api/worker/utils/tool_validation.py +332 -0
  453. control_plane_api/worker/utils/workspace_manager.py +163 -0
  454. control_plane_api/worker/websocket_client.py +393 -0
  455. control_plane_api/worker/worker.py +1297 -0
  456. control_plane_api/worker/workflows/__init__.py +0 -0
  457. control_plane_api/worker/workflows/agent_execution.py +909 -0
  458. control_plane_api/worker/workflows/scheduled_job_wrapper.py +332 -0
  459. control_plane_api/worker/workflows/team_execution.py +611 -0
  460. kubiya_control_plane_api-0.9.15.dist-info/METADATA +354 -0
  461. kubiya_control_plane_api-0.9.15.dist-info/RECORD +479 -0
  462. kubiya_control_plane_api-0.9.15.dist-info/WHEEL +5 -0
  463. kubiya_control_plane_api-0.9.15.dist-info/entry_points.txt +5 -0
  464. kubiya_control_plane_api-0.9.15.dist-info/licenses/LICENSE +676 -0
  465. kubiya_control_plane_api-0.9.15.dist-info/top_level.txt +3 -0
  466. scripts/__init__.py +1 -0
  467. scripts/migrations.py +39 -0
  468. scripts/seed_worker_queues.py +128 -0
  469. scripts/setup_agent_runtime.py +142 -0
  470. worker_internal/__init__.py +1 -0
  471. worker_internal/planner/__init__.py +1 -0
  472. worker_internal/planner/activities.py +1499 -0
  473. worker_internal/planner/agent_tools.py +197 -0
  474. worker_internal/planner/event_models.py +148 -0
  475. worker_internal/planner/event_publisher.py +67 -0
  476. worker_internal/planner/models.py +199 -0
  477. worker_internal/planner/retry_logic.py +134 -0
  478. worker_internal/planner/worker.py +300 -0
  479. worker_internal/planner/workflows.py +970 -0
@@ -0,0 +1,1128 @@
1
+ """initial_tables
2
+
3
+ Revision ID: b4983d976db2
4
+ Revises: 2613c65c3dbe
5
+ Create Date: 2025-11-20 11:57:16.385151
6
+
7
+ """
8
+ from typing import Sequence, Union
9
+
10
+ from alembic import op
11
+ import sqlalchemy as sa
12
+ from sqlalchemy.dialects import postgresql
13
+
14
+ # revision identifiers, used by Alembic.
15
+ revision: str = 'b4983d976db2'
16
+ down_revision: Union[str, Sequence[str], None] = '2613c65c3dbe'
17
+ branch_labels: Union[str, Sequence[str], None] = None
18
+ depends_on: Union[str, Sequence[str], None] = None
19
+
20
+
21
+ def upgrade() -> None:
22
+ """Upgrade schema."""
23
+ # ### commands auto generated by Alembic - please adjust! ###
24
+ op.create_table('context_resources',
25
+ sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
26
+ sa.Column('name', sa.Text(), nullable=False),
27
+ sa.Column('platform', sa.Text(), nullable=False),
28
+ sa.Column('organization', sa.Text(), nullable=False),
29
+ sa.Column('type', sa.Text(), server_default=sa.text("'integration'::text"), nullable=True),
30
+ sa.Column('status', sa.Text(), server_default=sa.text("'active'::text"), nullable=True),
31
+ sa.Column('description', sa.Text(), nullable=True),
32
+ sa.Column('metadata', postgresql.JSONB(astext_type=sa.Text()), server_default=sa.text("'{}'::jsonb"), nullable=True),
33
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
34
+ sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
35
+ sa.CheckConstraint("status = ANY (ARRAY['active'::text, 'inactive'::text, 'pending'::text, 'error'::text])", name='valid_status'),
36
+ sa.PrimaryKeyConstraint('id'),
37
+ sa.UniqueConstraint('name', name='context_resources_name_key')
38
+ )
39
+ op.create_index('idx_context_resources_name', 'context_resources', ['name'], unique=False)
40
+ op.create_index('idx_context_resources_org_platform', 'context_resources', ['organization', 'platform'], unique=False)
41
+ op.create_index('idx_context_resources_organization', 'context_resources', ['organization'], unique=False)
42
+ op.create_index('idx_context_resources_platform', 'context_resources', ['platform'], unique=False)
43
+ op.create_index('idx_context_resources_status', 'context_resources', ['status'], unique=False)
44
+ op.create_index('idx_context_resources_updated_at', 'context_resources', ['updated_at'], unique=False, postgresql_ops={'updated_at': 'DESC'})
45
+ op.create_table('environments',
46
+ sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
47
+ sa.Column('organization_id', sa.String(length=255), nullable=False),
48
+ sa.Column('name', sa.String(length=100), nullable=False),
49
+ sa.Column('display_name', sa.String(length=255), nullable=True),
50
+ sa.Column('description', sa.Text(), nullable=True),
51
+ sa.Column('tags', postgresql.JSONB(astext_type=sa.Text()), server_default=sa.text("'[]'::jsonb"), nullable=True),
52
+ sa.Column('settings', postgresql.JSONB(astext_type=sa.Text()), server_default=sa.text("'{}'::jsonb"), nullable=True),
53
+ sa.Column('status', sa.String(length=50), server_default=sa.text("'active'::character varying"), nullable=True),
54
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
55
+ sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
56
+ sa.Column('created_by', sa.String(length=255), nullable=True),
57
+ sa.Column('temporal_namespace_id', sa.UUID(), nullable=True),
58
+ sa.Column('worker_token', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=True),
59
+ sa.Column('provisioning_workflow_id', sa.String(length=255), nullable=True),
60
+ sa.Column('error_message', sa.Text(), nullable=True),
61
+ sa.Column('provisioned_at', sa.DateTime(timezone=True), nullable=True),
62
+ sa.Column('execution_environment', postgresql.JSONB(astext_type=sa.Text()), server_default=sa.text("'{}'::jsonb"), nullable=False),
63
+ sa.Column('policy_ids', sa.ARRAY(sa.String(length=255)), server_default=sa.text("'{}'::character varying[]"), nullable=True),
64
+ sa.CheckConstraint("status::text = ANY (ARRAY['pending'::character varying, 'provisioning'::character varying, 'ready'::character varying, 'active'::character varying, 'inactive'::character varying, 'error'::character varying, 'archived'::character varying]::text[])", name='task_queues_status_check'),
65
+ sa.PrimaryKeyConstraint('id'),
66
+ sa.UniqueConstraint('organization_id', 'name', name='unique_queue_name_per_org')
67
+ )
68
+ op.create_index('idx_environments_execution_environment', 'environments', ['execution_environment'], unique=False, postgresql_using='gin')
69
+ op.create_index('idx_environments_policy_ids', 'environments', ['policy_ids'], unique=False, postgresql_using='gin')
70
+ op.create_index('idx_task_queues_name', 'environments', ['organization_id', 'name'], unique=False)
71
+ op.create_index('idx_task_queues_namespace', 'environments', ['temporal_namespace_id'], unique=False)
72
+ op.create_index('idx_task_queues_org', 'environments', ['organization_id'], unique=False)
73
+ op.create_index('idx_task_queues_status', 'environments', ['organization_id', 'status'], unique=False, postgresql_where=sa.text("status::text = 'active'::text"))
74
+ op.create_index('idx_task_queues_worker_token', 'environments', ['worker_token'], unique=False)
75
+ op.create_table('llm_models',
76
+ sa.Column('id', sa.String(), nullable=False),
77
+ sa.Column('value', sa.String(), nullable=False),
78
+ sa.Column('label', sa.String(), nullable=False),
79
+ sa.Column('provider', sa.String(), nullable=False),
80
+ sa.Column('logo', sa.String(), nullable=True),
81
+ sa.Column('description', sa.Text(), nullable=True),
82
+ sa.Column('enabled', sa.Boolean(), nullable=False),
83
+ sa.Column('recommended', sa.Boolean(), nullable=False),
84
+ sa.Column('compatible_runtimes', sa.JSON(), nullable=False),
85
+ sa.Column('capabilities', sa.JSON(), nullable=False),
86
+ sa.Column('pricing', sa.JSON(), nullable=True),
87
+ sa.Column('display_order', sa.Integer(), nullable=False),
88
+ sa.Column('created_at', sa.DateTime(), nullable=False),
89
+ sa.Column('updated_at', sa.DateTime(), nullable=False),
90
+ sa.Column('created_by', sa.String(), nullable=True),
91
+ sa.PrimaryKeyConstraint('id')
92
+ )
93
+ op.create_index(op.f('ix_llm_models_enabled'), 'llm_models', ['enabled'], unique=False)
94
+ op.create_index(op.f('ix_llm_models_provider'), 'llm_models', ['provider'], unique=False)
95
+ op.create_index(op.f('ix_llm_models_value'), 'llm_models', ['value'], unique=True)
96
+ op.create_table('namespaces',
97
+ sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
98
+ sa.Column('organization_id', sa.String(length=255), nullable=False),
99
+ sa.Column('namespace_name', sa.String(length=255), nullable=False),
100
+ sa.Column('status', sa.String(length=50), server_default=sa.text("'provisioning'::character varying"), nullable=False),
101
+ sa.Column('temporal_host', sa.String(length=255), nullable=True),
102
+ sa.Column('api_key_encrypted', sa.Text(), nullable=True),
103
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
104
+ sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
105
+ sa.PrimaryKeyConstraint('id'),
106
+ sa.UniqueConstraint('namespace_name', name='namespaces_namespace_name_key')
107
+ )
108
+ op.create_index('idx_namespaces_organization_id', 'namespaces', ['organization_id'], unique=False)
109
+ op.create_index('idx_namespaces_status', 'namespaces', ['status'], unique=False)
110
+ op.create_table('orchestration_servers',
111
+ sa.Column('id', sa.Text(), server_default=sa.text('(gen_random_uuid())::text'), nullable=False),
112
+ sa.Column('user_id', sa.Text(), nullable=True),
113
+ sa.Column('organization_id', sa.Text(), nullable=True),
114
+ sa.Column('name', sa.Text(), nullable=False),
115
+ sa.Column('endpoint', sa.Text(), nullable=False),
116
+ sa.Column('description', sa.Text(), nullable=True),
117
+ sa.Column('config', postgresql.JSONB(astext_type=sa.Text()), server_default=sa.text("'{}'::jsonb"), nullable=True),
118
+ sa.Column('health_check_interval_seconds', sa.Integer(), server_default=sa.text('60'), nullable=True),
119
+ sa.Column('is_active', sa.Boolean(), server_default=sa.text('true'), nullable=True),
120
+ sa.Column('is_default', sa.Boolean(), server_default=sa.text('false'), nullable=True),
121
+ sa.Column('scope', sa.Text(), server_default=sa.text("'user'::text"), nullable=False),
122
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
123
+ sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
124
+ sa.PrimaryKeyConstraint('id')
125
+ )
126
+ op.create_index('idx_orchestration_servers_is_active', 'orchestration_servers', ['is_active'], unique=False)
127
+ op.create_index('idx_orchestration_servers_is_default', 'orchestration_servers', ['is_default'], unique=False)
128
+ op.create_index('idx_orchestration_servers_scope', 'orchestration_servers', ['scope'], unique=False)
129
+ op.create_index('idx_orchestration_servers_user_id', 'orchestration_servers', ['user_id'], unique=False)
130
+ op.create_table('profiles',
131
+ sa.Column('id', sa.UUID(), nullable=False),
132
+ sa.Column('email', sa.Text(), nullable=False),
133
+ sa.Column('full_name', sa.Text(), nullable=True),
134
+ sa.Column('avatar_url', sa.Text(), nullable=True),
135
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
136
+ sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
137
+ sa.PrimaryKeyConstraint('id'),
138
+ sa.UniqueConstraint('email')
139
+ )
140
+ op.create_index('idx_profiles_email', 'profiles', ['email'], unique=False)
141
+ op.create_table('policy_associations',
142
+ sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
143
+ sa.Column('organization_id', sa.String(length=255), nullable=False),
144
+ sa.Column('policy_id', sa.String(length=255), nullable=False),
145
+ sa.Column('policy_name', sa.String(length=255), nullable=False),
146
+ sa.Column('entity_type', sa.String(length=50), nullable=False),
147
+ sa.Column('entity_id', sa.UUID(), nullable=False),
148
+ sa.Column('enabled', sa.Boolean(), server_default=sa.text('true'), nullable=True),
149
+ sa.Column('priority', sa.Integer(), server_default=sa.text('0'), nullable=True),
150
+ sa.Column('metadata', sa.JSON(), server_default=sa.text("'{}'::jsonb"), nullable=True),
151
+ sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
152
+ sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
153
+ sa.Column('created_by', sa.String(length=255), nullable=True),
154
+ sa.CheckConstraint("entity_type IN ('agent', 'team', 'environment')", name='policy_associations_entity_type_check'),
155
+ sa.PrimaryKeyConstraint('id'),
156
+ sa.UniqueConstraint('policy_id', 'entity_type', 'entity_id', name='unique_policy_association'),
157
+ schema='public'
158
+ )
159
+ op.create_index('idx_policy_assoc_enabled', 'policy_associations', ['enabled'], unique=False, schema='public')
160
+ op.create_index('idx_policy_assoc_entity', 'policy_associations', ['entity_type', 'entity_id'], unique=False, schema='public')
161
+ op.create_index('idx_policy_assoc_entity_enabled', 'policy_associations', ['entity_type', 'entity_id', 'enabled', 'priority'], unique=False, schema='public', postgresql_ops={'priority': 'DESC'})
162
+ op.create_index('idx_policy_assoc_org', 'policy_associations', ['organization_id'], unique=False, schema='public')
163
+ op.create_index('idx_policy_assoc_policy', 'policy_associations', ['policy_id'], unique=False, schema='public')
164
+ op.create_index('idx_policy_assoc_priority', 'policy_associations', ['priority'], unique=False, schema='public', postgresql_ops={'priority': 'DESC'})
165
+ op.create_table('sessions',
166
+ sa.Column('execution_id', sa.Text(), nullable=False),
167
+ sa.Column('session_id', sa.Text(), nullable=False),
168
+ sa.Column('organization_id', sa.Text(), nullable=False),
169
+ sa.Column('user_id', sa.Text(), nullable=True),
170
+ sa.Column('messages', postgresql.JSONB(astext_type=sa.Text()), server_default=sa.text("'[]'::jsonb"), nullable=False),
171
+ sa.Column('metadata', postgresql.JSONB(astext_type=sa.Text()), server_default=sa.text("'{}'::jsonb"), nullable=True),
172
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
173
+ sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
174
+ sa.PrimaryKeyConstraint('execution_id')
175
+ )
176
+ op.create_index('idx_sessions_organization_id', 'sessions', ['organization_id'], unique=False)
177
+ op.create_index('idx_sessions_session_id', 'sessions', ['session_id'], unique=False)
178
+ op.create_index('idx_sessions_updated_at', 'sessions', ['updated_at'], unique=False, postgresql_ops={'updated_at': 'DESC'})
179
+ op.create_table('skills',
180
+ sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
181
+ sa.Column('organization_id', sa.String(length=255), nullable=False),
182
+ sa.Column('name', sa.String(length=255), nullable=False),
183
+ sa.Column('skill_type', sa.String(length=50), nullable=False),
184
+ sa.Column('description', sa.Text(), nullable=True),
185
+ sa.Column('icon', sa.String(length=50), server_default=sa.text("'Tool'::character varying"), nullable=True),
186
+ sa.Column('enabled', sa.Boolean(), server_default=sa.text('true'), nullable=True),
187
+ sa.Column('configuration', postgresql.JSONB(astext_type=sa.Text()), server_default=sa.text("'{}'::jsonb"), nullable=True),
188
+ sa.Column('created_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
189
+ sa.Column('updated_at', sa.DateTime(), server_default=sa.text('now()'), nullable=True),
190
+ sa.CheckConstraint("skill_type IN ('file_system', 'shell', 'python', 'docker', 'sleep', 'file_generation', 'data_visualization', 'workflow_executor', 'custom')", name='toolsets_type_check'),
191
+ sa.PrimaryKeyConstraint('id'),
192
+ sa.UniqueConstraint('organization_id', 'name', name='unique_toolset_per_org')
193
+ )
194
+ op.create_index('idx_skills_enabled', 'skills', ['enabled'], unique=False)
195
+ op.create_index('idx_skills_type', 'skills', ['skill_type'], unique=False)
196
+ op.create_index(op.f('ix_skills_organization_id'), 'skills', ['organization_id'], unique=False)
197
+ op.create_table('slash_commands',
198
+ sa.Column('id', sa.UUID(), nullable=False),
199
+ sa.Column('command', sa.Text(), nullable=False),
200
+ sa.Column('workflow_id', sa.Text(), nullable=False),
201
+ sa.Column('workflow_name', sa.Text(), nullable=False),
202
+ sa.Column('description', sa.Text(), nullable=True),
203
+ sa.Column('enabled', sa.Boolean(), nullable=True),
204
+ sa.Column('runner', sa.Text(), nullable=True),
205
+ sa.Column('args', sa.JSON(), nullable=True),
206
+ sa.Column('user_id', sa.Text(), nullable=False),
207
+ sa.Column('project_id', sa.Text(), nullable=False),
208
+ sa.Column('created_at', sa.DateTime(timezone=True), nullable=True),
209
+ sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
210
+ sa.Column('last_used', sa.DateTime(timezone=True), nullable=True),
211
+ sa.PrimaryKeyConstraint('id')
212
+ )
213
+ op.create_index(op.f('ix_slash_commands_user_id'), 'slash_commands', ['user_id'], unique=False)
214
+ op.create_table('temporal_namespaces',
215
+ sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
216
+ sa.Column('organization_id', sa.String(length=255), nullable=False),
217
+ sa.Column('namespace_name', sa.String(length=255), nullable=False),
218
+ sa.Column('account_id', sa.String(length=255), nullable=True),
219
+ sa.Column('region', sa.String(length=50), server_default=sa.text("'aws-us-east-1'::character varying"), nullable=True),
220
+ sa.Column('api_key_encrypted', sa.Text(), nullable=True),
221
+ sa.Column('certificate_encrypted', sa.Text(), nullable=True),
222
+ sa.Column('status', sa.String(length=50), server_default=sa.text("'pending'::character varying"), nullable=True),
223
+ sa.Column('provisioning_workflow_id', sa.String(length=255), nullable=True),
224
+ sa.Column('error_message', sa.Text(), nullable=True),
225
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
226
+ sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
227
+ sa.Column('provisioned_at', sa.DateTime(timezone=True), nullable=True),
228
+ sa.Column('created_by', sa.String(length=255), nullable=True),
229
+ sa.CheckConstraint("status::text = ANY (ARRAY['pending'::character varying, 'provisioning'::character varying, 'ready'::character varying, 'error'::character varying, 'archived'::character varying]::text[])", name='temporal_namespaces_status_check'),
230
+ sa.PrimaryKeyConstraint('id')
231
+ )
232
+ op.create_index('idx_temporal_namespaces_organization_id', 'temporal_namespaces', ['organization_id'], unique=False)
233
+ op.create_index('idx_temporal_namespaces_status', 'temporal_namespaces', ['status'], unique=False)
234
+ op.create_table('user_presence',
235
+ sa.Column('id', sa.String(), nullable=False),
236
+ sa.Column('user_id', sa.String(), nullable=False),
237
+ sa.Column('user_email', sa.String(), nullable=True),
238
+ sa.Column('user_name', sa.String(), nullable=True),
239
+ sa.Column('user_avatar', sa.String(), nullable=True),
240
+ sa.Column('agent_id', sa.String(), nullable=True),
241
+ sa.Column('session_id', sa.String(), nullable=True),
242
+ sa.Column('execution_id', sa.String(), nullable=True),
243
+ sa.Column('is_active', sa.Boolean(), nullable=False),
244
+ sa.Column('is_typing', sa.Boolean(), nullable=False),
245
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
246
+ sa.Column('last_active_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
247
+ sa.PrimaryKeyConstraint('id')
248
+ )
249
+ op.create_index('idx_presence_lookup', 'user_presence', ['agent_id', 'is_active', 'last_active_at'], unique=False)
250
+ op.create_index('idx_presence_user', 'user_presence', ['user_id', 'is_active'], unique=False)
251
+ op.create_index(op.f('ix_user_presence_agent_id'), 'user_presence', ['agent_id'], unique=False)
252
+ op.create_index(op.f('ix_user_presence_execution_id'), 'user_presence', ['execution_id'], unique=False)
253
+ op.create_index(op.f('ix_user_presence_session_id'), 'user_presence', ['session_id'], unique=False)
254
+ op.create_index(op.f('ix_user_presence_user_id'), 'user_presence', ['user_id'], unique=False)
255
+ op.create_table('workspaces',
256
+ sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
257
+ sa.Column('name', sa.String(length=255), nullable=False),
258
+ sa.Column('description', sa.Text(), nullable=True),
259
+ sa.Column('slug', sa.Text(), nullable=True),
260
+ sa.Column('logo_url', sa.Text(), nullable=True),
261
+ sa.Column('created_by', sa.UUID(), nullable=True),
262
+ sa.Column('owner_email', sa.Text(), nullable=True),
263
+ sa.Column('type', sa.Text(), server_default=sa.text("'hobby'::text"), nullable=False),
264
+ sa.Column('settings', postgresql.JSONB(astext_type=sa.Text()), server_default=sa.text("'{}'::jsonb"), nullable=True),
265
+ sa.Column('member_count', sa.Integer(), server_default=sa.text('1'), nullable=True),
266
+ sa.Column('stripe_customer_id', sa.Text(), nullable=True),
267
+ sa.Column('stripe_subscription_id', sa.Text(), nullable=True),
268
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
269
+ sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
270
+ sa.CheckConstraint("type = ANY (ARRAY['hobby'::text, 'enterprise'::text])", name='workspaces_type_check'),
271
+ sa.PrimaryKeyConstraint('id')
272
+ )
273
+ op.create_table('environment_contexts',
274
+ sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
275
+ sa.Column('environment_id', sa.UUID(), nullable=False),
276
+ sa.Column('entity_type', sa.String(length=50), server_default=sa.text("'environment'::character varying"), nullable=True),
277
+ sa.Column('organization_id', sa.UUID(), nullable=False),
278
+ sa.Column('knowledge_uuids', sa.ARRAY(sa.Text()), server_default=sa.text("'{}'::text[]"), nullable=True),
279
+ sa.Column('resource_ids', sa.ARRAY(sa.Text()), server_default=sa.text("'{}'::text[]"), nullable=True),
280
+ sa.Column('policy_ids', sa.ARRAY(sa.Text()), server_default=sa.text("'{}'::text[]"), nullable=True),
281
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
282
+ sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
283
+ sa.ForeignKeyConstraint(['environment_id'], ['environments.id'], ondelete='CASCADE'),
284
+ sa.PrimaryKeyConstraint('id'),
285
+ sa.UniqueConstraint('environment_id', 'organization_id', name='environment_contexts_environment_id_organization_id_key')
286
+ )
287
+ op.create_index('idx_environment_contexts_environment_id', 'environment_contexts', ['environment_id'], unique=False)
288
+ op.create_index('idx_environment_contexts_org_id', 'environment_contexts', ['organization_id'], unique=False)
289
+ op.create_table('orchestration_server_health',
290
+ sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
291
+ sa.Column('server_id', sa.Text(), nullable=False),
292
+ sa.Column('status', sa.Text(), nullable=False),
293
+ sa.Column('response_time_ms', sa.Integer(), nullable=True),
294
+ sa.Column('checked_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
295
+ sa.Column('error_message', sa.Text(), nullable=True),
296
+ sa.CheckConstraint("status IN ('healthy', 'degraded', 'unhealthy')", name='orchestration_server_health_status_check'),
297
+ sa.ForeignKeyConstraint(['server_id'], ['orchestration_servers.id'], ondelete='CASCADE'),
298
+ sa.PrimaryKeyConstraint('id')
299
+ )
300
+ op.create_index('idx_orchestration_server_health_checked_at', 'orchestration_server_health', [sa.literal_column('checked_at DESC')], unique=False)
301
+ op.create_index('idx_orchestration_server_health_server_id', 'orchestration_server_health', ['server_id'], unique=False)
302
+ op.create_table('projects',
303
+ sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
304
+ sa.Column('organization_id', sa.String(length=255), nullable=False),
305
+ sa.Column('name', sa.String(length=255), nullable=False),
306
+ sa.Column('key', sa.String(length=50), nullable=False),
307
+ sa.Column('description', sa.Text(), nullable=True),
308
+ sa.Column('settings', postgresql.JSONB(astext_type=sa.Text()), server_default=sa.text("'{}'::jsonb"), nullable=True),
309
+ sa.Column('status', sa.String(length=50), server_default=sa.text("'active'::character varying"), nullable=True),
310
+ sa.Column('visibility', sa.String(length=20), server_default=sa.text("'private'::character varying"), nullable=True),
311
+ sa.Column('owner_id', sa.String(length=255), nullable=True),
312
+ sa.Column('owner_email', sa.String(length=255), nullable=True),
313
+ sa.Column('environment_id', sa.UUID(), nullable=True),
314
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
315
+ sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
316
+ sa.Column('archived_at', sa.DateTime(timezone=True), nullable=True),
317
+ sa.CheckConstraint("status IN ('active', 'archived', 'draft')", name='projects_status_check'),
318
+ sa.CheckConstraint("visibility IN ('private', 'org')", name='projects_visibility_check'),
319
+ sa.ForeignKeyConstraint(['environment_id'], ['environments.id'], ondelete='SET NULL'),
320
+ sa.PrimaryKeyConstraint('id'),
321
+ sa.UniqueConstraint('organization_id', 'key', name='unique_project_key_per_org'),
322
+ sa.UniqueConstraint('organization_id', 'name', name='unique_project_name_per_org')
323
+ )
324
+ op.create_index('idx_projects_environment_id', 'projects', ['environment_id'], unique=False)
325
+ op.create_index('idx_projects_org_id', 'projects', ['organization_id'], unique=False)
326
+ op.create_index('idx_projects_owner', 'projects', ['owner_id'], unique=False)
327
+ op.create_index('idx_projects_status', 'projects', ['status'], unique=False, postgresql_where=sa.text("status = 'active'"))
328
+ op.create_index('idx_projects_visibility', 'projects', ['organization_id', 'visibility'], unique=False)
329
+ op.create_table('skill_associations',
330
+ sa.Column('id', sa.UUID(), nullable=False),
331
+ sa.Column('organization_id', sa.String(length=255), nullable=False),
332
+ sa.Column('skill_id', sa.UUID(), nullable=False),
333
+ sa.Column('entity_type', sa.String(length=50), nullable=False),
334
+ sa.Column('entity_id', sa.UUID(), nullable=False),
335
+ sa.Column('configuration_override', sa.JSON(), nullable=True),
336
+ sa.Column('created_at', sa.DateTime(), nullable=True),
337
+ sa.CheckConstraint("entity_type IN ('agent', 'team', 'environment')", name='toolset_associations_entity_type_check'),
338
+ sa.ForeignKeyConstraint(['skill_id'], ['skills.id'], ondelete='CASCADE'),
339
+ sa.PrimaryKeyConstraint('id'),
340
+ sa.UniqueConstraint('skill_id', 'entity_type', 'entity_id', name='unique_skill_entity')
341
+ )
342
+ op.create_index('ix_skill_associations_entity', 'skill_associations', ['entity_type', 'entity_id'], unique=False)
343
+ op.create_index('ix_skill_associations_org_skill', 'skill_associations', ['organization_id', 'skill_id'], unique=False)
344
+ op.create_index(op.f('ix_skill_associations_organization_id'), 'skill_associations', ['organization_id'], unique=False)
345
+ op.create_index('ix_skill_associations_skill_id', 'skill_associations', ['skill_id'], unique=False)
346
+ op.create_table('slash_command_executions',
347
+ sa.Column('id', sa.UUID(), nullable=False),
348
+ sa.Column('command_id', sa.UUID(), nullable=False),
349
+ sa.Column('args', sa.JSON(), nullable=True),
350
+ sa.Column('workflow_id', sa.Text(), nullable=False),
351
+ sa.Column('task_id', sa.UUID(), nullable=False),
352
+ sa.Column('status', sa.Text(), nullable=False),
353
+ sa.Column('started_at', sa.DateTime(timezone=True), nullable=True),
354
+ sa.Column('completed_at', sa.DateTime(timezone=True), nullable=True),
355
+ sa.Column('error', sa.Text(), nullable=True),
356
+ sa.Column('user_id', sa.Text(), nullable=False),
357
+ sa.ForeignKeyConstraint(['command_id'], ['slash_commands.id'], ondelete='CASCADE'),
358
+ sa.PrimaryKeyConstraint('id')
359
+ )
360
+ op.create_index('ix_slash_command_executions_command_id', 'slash_command_executions', ['command_id'], unique=False)
361
+ op.create_index('ix_slash_command_executions_user_id', 'slash_command_executions', ['user_id'], unique=False)
362
+ op.create_table('teams',
363
+ sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
364
+ sa.Column('organization_id', sa.String(length=255), nullable=False),
365
+ sa.Column('name', sa.String(length=255), nullable=False),
366
+ sa.Column('description', sa.Text(), nullable=True),
367
+ sa.Column('status', sa.String(length=50), server_default=sa.text("'idle'::character varying"), nullable=True),
368
+ sa.Column('coordination_type', sa.String(length=50), server_default=sa.text("'sequential'::character varying"), nullable=True),
369
+ sa.Column('configuration', postgresql.JSONB(astext_type=sa.Text()), server_default=sa.text("'{}'::jsonb"), nullable=True),
370
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
371
+ sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
372
+ sa.Column('last_active_at', sa.DateTime(timezone=True), nullable=True),
373
+ sa.Column('state', postgresql.JSONB(astext_type=sa.Text()), server_default=sa.text("'{}'::jsonb"), nullable=True),
374
+ sa.Column('error_message', sa.Text(), nullable=True),
375
+ sa.Column('visibility', sa.String(length=20), server_default=sa.text("'private'::character varying"), nullable=True),
376
+ sa.Column('environment_id', sa.UUID(), nullable=True),
377
+ sa.Column('skill_ids', sa.ARRAY(sa.UUID()), server_default=sa.text("'{}'::uuid[]"), nullable=True),
378
+ sa.Column('execution_environment', postgresql.JSONB(astext_type=sa.Text()), server_default=sa.text("'{}'::jsonb"), nullable=False),
379
+ sa.Column('policy_ids', sa.ARRAY(sa.String(length=255)), server_default=sa.text("'{}'::character varying[]"), nullable=True),
380
+ sa.Column('runtime', sa.Enum('default', 'claude_code', name='runtimetype'), server_default='default', nullable=False),
381
+ sa.Column('model_id', sa.String(), nullable=True),
382
+ sa.CheckConstraint("visibility IN ('private', 'org')", name='teams_visibility_check'),
383
+ sa.ForeignKeyConstraint(['environment_id'], ['environments.id'], ondelete='SET NULL'),
384
+ sa.PrimaryKeyConstraint('id'),
385
+ sa.UniqueConstraint('organization_id', 'name', name='teams_organization_id_name_key'),
386
+ sa.UniqueConstraint('organization_id', 'name', name='uq_team_org_name')
387
+ )
388
+ op.create_index('idx_teams_environment_id', 'teams', ['environment_id'], unique=False)
389
+ op.create_index('idx_teams_execution_environment', 'teams', ['execution_environment'], unique=False, postgresql_using='gin')
390
+ op.create_index('idx_teams_org', 'teams', ['organization_id'], unique=False)
391
+ op.create_index('idx_teams_policy_ids', 'teams', ['policy_ids'], unique=False, postgresql_using='gin')
392
+ op.create_index('idx_teams_status', 'teams', ['status'], unique=False)
393
+ op.create_index('idx_teams_toolset_ids', 'teams', ['skill_ids'], unique=False, postgresql_using='gin')
394
+ op.create_index('idx_teams_visibility', 'teams', ['organization_id', 'visibility'], unique=False)
395
+ op.create_index('ix_teams_runtime', 'teams', ['runtime'], unique=False)
396
+ op.create_table('user_profiles',
397
+ sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
398
+ sa.Column('email', sa.Text(), nullable=False),
399
+ sa.Column('name', sa.Text(), nullable=True),
400
+ sa.Column('first_name', sa.Text(), nullable=True),
401
+ sa.Column('last_name', sa.Text(), nullable=True),
402
+ sa.Column('avatar_url', sa.Text(), nullable=True),
403
+ sa.Column('auth0_id', sa.Text(), nullable=True),
404
+ sa.Column('workspace_type', sa.Text(), nullable=True),
405
+ sa.Column('primary_workspace_id', sa.UUID(), nullable=True),
406
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
407
+ sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
408
+ sa.CheckConstraint("workspace_type = ANY (ARRAY['hobby'::text, 'enterprise'::text])", name='user_profiles_workspace_type_check'),
409
+ sa.ForeignKeyConstraint(['primary_workspace_id'], ['workspaces.id'], ondelete='SET NULL'),
410
+ sa.PrimaryKeyConstraint('id')
411
+ )
412
+ op.create_table('worker_queues',
413
+ sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
414
+ sa.Column('organization_id', sa.Text(), nullable=False),
415
+ sa.Column('environment_id', sa.UUID(), nullable=False),
416
+ sa.Column('name', sa.Text(), nullable=False),
417
+ sa.Column('display_name', sa.Text(), nullable=True),
418
+ sa.Column('description', sa.Text(), nullable=True),
419
+ sa.Column('status', sa.Text(), server_default=sa.text("'active'::text"), nullable=False),
420
+ sa.Column('max_workers', sa.Integer(), nullable=True),
421
+ sa.Column('heartbeat_interval', sa.Integer(), server_default=sa.text('30'), nullable=True),
422
+ sa.Column('tags', sa.ARRAY(sa.Text()), server_default=sa.text("'{}'::text[]"), nullable=True),
423
+ sa.Column('settings', postgresql.JSONB(astext_type=sa.Text()), server_default=sa.text("'{}'::jsonb"), nullable=True),
424
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
425
+ sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
426
+ sa.Column('created_by', sa.Text(), nullable=True),
427
+ sa.ForeignKeyConstraint(['environment_id'], ['environments.id'], ondelete='CASCADE'),
428
+ sa.PrimaryKeyConstraint('id'),
429
+ sa.UniqueConstraint('environment_id', 'name', name='worker_queues_environment_id_name_key')
430
+ )
431
+ op.create_index('idx_worker_queues_env', 'worker_queues', ['environment_id'], unique=False)
432
+ op.create_index('idx_worker_queues_org', 'worker_queues', ['organization_id'], unique=False)
433
+ op.create_index('idx_worker_queues_status', 'worker_queues', ['status'], unique=False)
434
+ op.create_table('workers',
435
+ sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
436
+ sa.Column('organization_id', sa.String(length=255), nullable=False),
437
+ sa.Column('task_queue_id', sa.UUID(), nullable=False),
438
+ sa.Column('worker_name', sa.String(length=255), nullable=True),
439
+ sa.Column('worker_token', sa.UUID(), nullable=False),
440
+ sa.Column('worker_id', sa.String(length=255), nullable=True),
441
+ sa.Column('capabilities', postgresql.JSONB(astext_type=sa.Text()), server_default=sa.text("'{}'::jsonb"), nullable=True),
442
+ sa.Column('environment', postgresql.JSONB(astext_type=sa.Text()), server_default=sa.text("'{}'::jsonb"), nullable=True),
443
+ sa.Column('metadata', postgresql.JSONB(astext_type=sa.Text()), server_default=sa.text("'{}'::jsonb"), nullable=True),
444
+ sa.Column('status', sa.String(length=50), server_default=sa.text("'registered'::character varying"), nullable=True),
445
+ sa.Column('last_seen_at', sa.DateTime(timezone=True), nullable=True),
446
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
447
+ sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
448
+ sa.Column('registered_by', sa.String(length=255), nullable=True),
449
+ sa.CheckConstraint("status IN ('registered', 'active', 'inactive', 'offline', 'error')", name='workers_status_check'),
450
+ sa.ForeignKeyConstraint(['task_queue_id'], ['environments.id'], ondelete='CASCADE'),
451
+ sa.PrimaryKeyConstraint('id'),
452
+ sa.UniqueConstraint('worker_token', name='unique_worker_token')
453
+ )
454
+ op.create_index('idx_workers_org', 'workers', ['organization_id'], unique=False)
455
+ op.create_index('idx_workers_status', 'workers', ['organization_id', 'status'], unique=False)
456
+ op.create_index('idx_workers_task_queue', 'workers', ['task_queue_id'], unique=False)
457
+ op.create_index('idx_workers_token', 'workers', ['worker_token'], unique=False)
458
+ op.create_table('agents',
459
+ sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
460
+ sa.Column('organization_id', sa.String(length=255), nullable=False),
461
+ sa.Column('name', sa.String(length=255), nullable=False),
462
+ sa.Column('description', sa.Text(), nullable=True),
463
+ sa.Column('status', sa.String(length=50), server_default='idle', nullable=True),
464
+ sa.Column('capabilities', postgresql.JSONB(astext_type=sa.Text()), server_default=sa.text("'[]'::jsonb"), nullable=True),
465
+ sa.Column('configuration', postgresql.JSONB(astext_type=sa.Text()), server_default=sa.text("'{}'::jsonb"), nullable=True),
466
+ sa.Column('model_id', sa.String(length=100), nullable=True),
467
+ sa.Column('model_config', postgresql.JSONB(astext_type=sa.Text()), server_default=sa.text("'{}'::jsonb"), nullable=True),
468
+ sa.Column('team_id', sa.UUID(), nullable=True),
469
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
470
+ sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
471
+ sa.Column('last_active_at', sa.DateTime(timezone=True), nullable=True),
472
+ sa.Column('state', postgresql.JSONB(astext_type=sa.Text()), server_default=sa.text("'{}'::jsonb"), nullable=True),
473
+ sa.Column('error_message', sa.Text(), nullable=True),
474
+ sa.Column('runner_name', sa.String(length=100), nullable=True),
475
+ sa.Column('visibility', sa.String(length=20), server_default='private', nullable=True),
476
+ sa.Column('project_id', sa.UUID(), nullable=True),
477
+ sa.Column('environment_id', sa.UUID(), nullable=True),
478
+ sa.Column('toolset_ids', postgresql.ARRAY(sa.UUID()), server_default=sa.text("'{}'::uuid[]"), nullable=True),
479
+ sa.Column('runtime', sa.String(length=50), server_default='default', nullable=False),
480
+ sa.Column('execution_environment', postgresql.JSONB(astext_type=sa.Text()), server_default=sa.text("'{}'::jsonb"), nullable=False),
481
+ sa.Column('policy_ids', postgresql.ARRAY(sa.String(length=255)), server_default=sa.text("'{}'::character varying[]"), nullable=True),
482
+ sa.CheckConstraint("runtime IN ('default', 'claude_code')", name='chk_agents_runtime'),
483
+ sa.CheckConstraint("visibility IN ('private', 'org')", name='agents_visibility_check'),
484
+ sa.ForeignKeyConstraint(['environment_id'], ['environments.id'], ondelete='SET NULL'),
485
+ sa.ForeignKeyConstraint(['project_id'], ['projects.id'], ondelete='SET NULL'),
486
+ sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ondelete='SET NULL'),
487
+ sa.PrimaryKeyConstraint('id'),
488
+ sa.UniqueConstraint('organization_id', 'name', name='agents_organization_id_name_key')
489
+ )
490
+ op.create_index('idx_agents_environment_id', 'agents', ['environment_id'], unique=False)
491
+ op.create_index('idx_agents_execution_environment', 'agents', ['execution_environment'], unique=False, postgresql_using='gin')
492
+ op.create_index('idx_agents_org', 'agents', ['organization_id'], unique=False)
493
+ op.create_index('idx_agents_org_runtime', 'agents', ['organization_id', 'runtime'], unique=False)
494
+ op.create_index('idx_agents_policy_ids', 'agents', ['policy_ids'], unique=False, postgresql_using='gin')
495
+ op.create_index('idx_agents_project_id', 'agents', ['project_id'], unique=False)
496
+ op.create_index('idx_agents_runtime', 'agents', ['runtime'], unique=False)
497
+ op.create_index('idx_agents_status', 'agents', ['status'], unique=False)
498
+ op.create_index('idx_agents_team', 'agents', ['team_id'], unique=False)
499
+ op.create_index('idx_agents_team_id', 'agents', ['team_id'], unique=False)
500
+ op.create_index('idx_agents_toolset_ids', 'agents', ['toolset_ids'], unique=False, postgresql_using='gin')
501
+ op.create_index('idx_agents_visibility', 'agents', ['organization_id', 'visibility'], unique=False)
502
+ op.create_table('executions',
503
+ sa.Column('id', sa.UUID(), nullable=False),
504
+ sa.Column('organization_id', sa.String(length=255), nullable=False),
505
+ sa.Column('execution_type', sa.String(length=50), nullable=False),
506
+ sa.Column('entity_id', sa.UUID(), nullable=False),
507
+ sa.Column('entity_name', sa.String(length=255), nullable=True),
508
+ sa.Column('runner_name', sa.String(length=100), nullable=False),
509
+ sa.Column('user_id', sa.String(length=255), nullable=True),
510
+ sa.Column('user_email', sa.String(length=255), nullable=True),
511
+ sa.Column('user_name', sa.String(length=255), nullable=True),
512
+ sa.Column('user_avatar', sa.Text(), nullable=True),
513
+ sa.Column('trigger_source', sa.Enum('user', 'job_cron', 'job_webhook', 'job_manual', 'system', 'api', 'chat', name='executiontriggersource'), server_default='user', nullable=False),
514
+ sa.Column('trigger_metadata', sa.JSON(), nullable=True),
515
+ sa.Column('prompt', sa.Text(), nullable=False),
516
+ sa.Column('system_prompt', sa.Text(), nullable=True),
517
+ sa.Column('config', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
518
+ sa.Column('status', sa.String(length=50), nullable=True),
519
+ sa.Column('response', sa.Text(), nullable=True),
520
+ sa.Column('error_message', sa.Text(), nullable=True),
521
+ sa.Column('temporal_workflow_id', sa.String(length=255), nullable=True),
522
+ sa.Column('temporal_run_id', sa.String(length=255), nullable=True),
523
+ sa.Column('task_queue_name', sa.String(length=100), nullable=True),
524
+ sa.Column('usage', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
525
+ sa.Column('execution_metadata', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
526
+ sa.Column('worker_queue_id', sa.UUID(), nullable=True),
527
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
528
+ sa.Column('started_at', sa.DateTime(timezone=True), nullable=True),
529
+ sa.Column('completed_at', sa.DateTime(timezone=True), nullable=True),
530
+ sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
531
+ sa.ForeignKeyConstraint(['worker_queue_id'], ['worker_queues.id'], ),
532
+ sa.PrimaryKeyConstraint('id'),
533
+ sa.UniqueConstraint('temporal_workflow_id')
534
+ )
535
+ op.create_index('idx_executions_created', 'executions', [sa.literal_column('created_at DESC')], unique=False)
536
+ op.create_index('idx_executions_entity', 'executions', ['entity_id'], unique=False)
537
+ op.create_index('idx_executions_org', 'executions', ['organization_id'], unique=False)
538
+ op.create_index('idx_executions_run', 'executions', ['temporal_run_id'], unique=False, postgresql_where='temporal_run_id IS NOT NULL')
539
+ op.create_index('idx_executions_runner', 'executions', ['runner_name'], unique=False)
540
+ op.create_index('idx_executions_status', 'executions', ['status'], unique=False)
541
+ op.create_index('idx_executions_task_queue', 'executions', ['task_queue_name'], unique=False)
542
+ op.create_index('idx_executions_user', 'executions', ['user_id'], unique=False)
543
+ op.create_index('idx_executions_user_email', 'executions', ['user_email'], unique=False)
544
+ op.create_index('idx_executions_user_id', 'executions', ['user_id'], unique=False)
545
+ op.create_index('idx_executions_worker_queue_id', 'executions', ['worker_queue_id'], unique=False)
546
+ op.create_index('idx_executions_workflow', 'executions', ['temporal_workflow_id'], unique=False, postgresql_where='temporal_workflow_id IS NOT NULL')
547
+ op.create_index(op.f('ix_executions_organization_id'), 'executions', ['organization_id'], unique=False)
548
+ op.create_index(op.f('ix_executions_trigger_source'), 'executions', ['trigger_source'], unique=False)
549
+ op.create_index(op.f('ix_executions_user_id'), 'executions', ['user_id'], unique=False)
550
+ op.create_index(op.f('ix_executions_worker_queue_id'), 'executions', ['worker_queue_id'], unique=False)
551
+ op.create_table('project_contexts',
552
+ sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
553
+ sa.Column('project_id', sa.UUID(), nullable=False),
554
+ sa.Column('entity_type', sa.String(length=50), server_default=sa.text("'project'::character varying"), nullable=True),
555
+ sa.Column('organization_id', sa.UUID(), nullable=False),
556
+ sa.Column('knowledge_uuids', sa.ARRAY(sa.Text()), server_default=sa.text("'{}'::text[]"), nullable=True),
557
+ sa.Column('resource_ids', sa.ARRAY(sa.Text()), server_default=sa.text("'{}'::text[]"), nullable=True),
558
+ sa.Column('policy_ids', sa.ARRAY(sa.Text()), server_default=sa.text("'{}'::text[]"), nullable=True),
559
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
560
+ sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
561
+ sa.ForeignKeyConstraint(['project_id'], ['projects.id'], ondelete='CASCADE'),
562
+ sa.PrimaryKeyConstraint('id'),
563
+ sa.UniqueConstraint('project_id', 'organization_id', name='project_contexts_project_id_organization_id_key')
564
+ )
565
+ op.create_index('idx_project_contexts_org_id', 'project_contexts', ['organization_id'], unique=False)
566
+ op.create_index('idx_project_contexts_project_id', 'project_contexts', ['project_id'], unique=False)
567
+ op.create_table('project_teams',
568
+ sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
569
+ sa.Column('project_id', sa.UUID(), nullable=False),
570
+ sa.Column('team_id', sa.UUID(), nullable=False),
571
+ sa.Column('role', sa.String(length=50), nullable=True),
572
+ sa.Column('added_by', sa.String(length=255), nullable=True),
573
+ sa.Column('added_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
574
+ sa.ForeignKeyConstraint(['project_id'], ['projects.id'], ondelete='CASCADE'),
575
+ sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ondelete='CASCADE'),
576
+ sa.PrimaryKeyConstraint('id'),
577
+ sa.UniqueConstraint('project_id', 'team_id', name='unique_project_team')
578
+ )
579
+ op.create_index('idx_project_teams_project', 'project_teams', ['project_id'], unique=False)
580
+ op.create_index('idx_project_teams_team', 'project_teams', ['team_id'], unique=False)
581
+ op.create_table('team_contexts',
582
+ sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
583
+ sa.Column('team_id', sa.UUID(), nullable=False),
584
+ sa.Column('entity_type', sa.String(length=50), server_default=sa.text("'team'::character varying"), nullable=True),
585
+ sa.Column('organization_id', sa.UUID(), nullable=False),
586
+ sa.Column('knowledge_uuids', sa.ARRAY(sa.Text()), server_default=sa.text("'{}'::text[]"), nullable=True),
587
+ sa.Column('resource_ids', sa.ARRAY(sa.Text()), server_default=sa.text("'{}'::text[]"), nullable=True),
588
+ sa.Column('policy_ids', sa.ARRAY(sa.Text()), server_default=sa.text("'{}'::text[]"), nullable=True),
589
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
590
+ sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
591
+ sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ondelete='CASCADE'),
592
+ sa.PrimaryKeyConstraint('id'),
593
+ sa.UniqueConstraint('team_id', 'organization_id', name='team_contexts_team_id_organization_id_key')
594
+ )
595
+ op.create_index('idx_team_contexts_org_id', 'team_contexts', ['organization_id'], unique=False)
596
+ op.create_index('idx_team_contexts_team_id', 'team_contexts', ['team_id'], unique=False)
597
+ op.create_table('team_environments',
598
+ sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
599
+ sa.Column('team_id', sa.UUID(), nullable=False),
600
+ sa.Column('environment_id', sa.UUID(), nullable=False),
601
+ sa.Column('organization_id', sa.String(), nullable=False),
602
+ sa.Column('assigned_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
603
+ sa.Column('assigned_by', sa.String(), nullable=True),
604
+ sa.ForeignKeyConstraint(['environment_id'], ['environments.id'], ondelete='CASCADE'),
605
+ sa.ForeignKeyConstraint(['team_id'], ['teams.id'], ondelete='CASCADE'),
606
+ sa.PrimaryKeyConstraint('id'),
607
+ sa.UniqueConstraint('team_id', 'environment_id', name='uq_team_environment')
608
+ )
609
+ op.create_index('idx_team_environments_environment_id', 'team_environments', ['environment_id'], unique=False)
610
+ op.create_index('idx_team_environments_org_env', 'team_environments', ['organization_id', 'environment_id'], unique=False)
611
+ op.create_index('idx_team_environments_org_id', 'team_environments', ['organization_id'], unique=False)
612
+ op.create_index('idx_team_environments_team_id', 'team_environments', ['team_id'], unique=False)
613
+ op.create_table('worker_heartbeats',
614
+ sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
615
+ sa.Column('organization_id', sa.String(length=255), nullable=False),
616
+ sa.Column('worker_id', sa.String(length=255), nullable=False),
617
+ sa.Column('hostname', sa.String(length=255), nullable=True),
618
+ sa.Column('worker_metadata', postgresql.JSONB(astext_type=sa.Text()), server_default=sa.text("'{}'::jsonb"), nullable=True),
619
+ sa.Column('last_heartbeat', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
620
+ sa.Column('status', sa.String(length=50), server_default=sa.text("'active'::character varying"), nullable=True),
621
+ sa.Column('tasks_processed', sa.Integer(), server_default=sa.text('0'), nullable=True),
622
+ sa.Column('current_task_id', sa.UUID(), nullable=True),
623
+ sa.Column('registered_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
624
+ sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
625
+ sa.Column('worker_registration_id', sa.UUID(), nullable=True),
626
+ sa.Column('worker_queue_id', sa.UUID(), nullable=True),
627
+ sa.Column('environment_name', sa.String(length=255), nullable=True),
628
+ sa.Column('worker_token', sa.UUID(), nullable=True),
629
+ sa.CheckConstraint("status IN ('active', 'idle', 'busy', 'offline')", name='worker_heartbeats_status_check'),
630
+ sa.ForeignKeyConstraint(['worker_queue_id'], ['worker_queues.id'], ondelete='CASCADE'),
631
+ sa.ForeignKeyConstraint(['worker_registration_id'], ['workers.id'], ondelete='SET NULL'),
632
+ sa.PrimaryKeyConstraint('id'),
633
+ sa.UniqueConstraint('organization_id', 'worker_id', name='unique_worker_instance')
634
+ )
635
+ op.create_index('idx_worker_heartbeats_environment', 'worker_heartbeats', ['organization_id', 'environment_name'], unique=False)
636
+ op.create_index('idx_worker_heartbeats_last_heartbeat', 'worker_heartbeats', ['last_heartbeat'], unique=False)
637
+ op.create_index('idx_worker_heartbeats_org', 'worker_heartbeats', ['organization_id'], unique=False)
638
+ op.create_index('idx_worker_heartbeats_org_status', 'worker_heartbeats', ['organization_id', 'status'], unique=False)
639
+ op.create_index('idx_worker_heartbeats_org_status_heartbeat', 'worker_heartbeats', ['organization_id', 'status', sa.literal_column('last_heartbeat DESC')], unique=False)
640
+ op.create_index('idx_worker_heartbeats_queue', 'worker_heartbeats', ['worker_queue_id'], unique=False)
641
+ op.create_index('idx_worker_heartbeats_queue_status_heartbeat', 'worker_heartbeats', ['worker_queue_id', 'status', sa.literal_column('last_heartbeat DESC')], unique=False)
642
+ op.create_index('idx_worker_heartbeats_status', 'worker_heartbeats', ['organization_id', 'status'], unique=False)
643
+ op.create_index('idx_worker_heartbeats_token', 'worker_heartbeats', ['worker_token'], unique=False)
644
+ op.create_table('workflows',
645
+ sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
646
+ sa.Column('workspace_id', sa.UUID(), nullable=False),
647
+ sa.Column('name', sa.String(length=255), nullable=False),
648
+ sa.Column('description', sa.Text(), nullable=True),
649
+ sa.Column('slug', sa.String(length=255), nullable=True),
650
+ sa.Column('definition', postgresql.JSONB(astext_type=sa.Text()), nullable=False),
651
+ sa.Column('definition_format', sa.String(length=10), server_default=sa.text("'json'::character varying"), nullable=True),
652
+ sa.Column('status', sa.String(length=50), server_default=sa.text("'draft'::character varying"), nullable=True),
653
+ sa.Column('trigger_type', sa.String(length=50), nullable=True),
654
+ sa.Column('trigger_config', postgresql.JSONB(astext_type=sa.Text()), nullable=True),
655
+ sa.Column('upstash_schedule_id', sa.String(length=255), nullable=True),
656
+ sa.Column('upstash_webhook_id', sa.String(length=255), nullable=True),
657
+ sa.Column('created_by', sa.UUID(), nullable=True),
658
+ sa.Column('updated_by', sa.UUID(), nullable=True),
659
+ sa.Column('published_at', sa.DateTime(timezone=True), nullable=True),
660
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
661
+ sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
662
+ sa.Column('is_test', sa.Boolean(), server_default=sa.text('false'), nullable=True),
663
+ sa.Column('expires_at', sa.DateTime(timezone=True), nullable=True),
664
+ sa.Column('owner_id', sa.Text(), nullable=True),
665
+ sa.Column('owner_email', sa.Text(), nullable=True),
666
+ sa.Column('version', sa.Integer(), server_default=sa.text('1'), nullable=True),
667
+ sa.Column('tags', postgresql.ARRAY(sa.Text()), server_default=sa.text("'{}'::text[]"), nullable=True),
668
+ sa.Column('metadata', postgresql.JSONB(astext_type=sa.Text()), server_default=sa.text("'{}'::jsonb"), nullable=True),
669
+ sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True),
670
+ sa.CheckConstraint("definition_format::text = ANY (ARRAY['json'::character varying::text, 'yaml'::character varying::text])", name='workflows_definition_format_check'),
671
+ sa.CheckConstraint("status::text = ANY (ARRAY['draft'::character varying::text, 'published'::character varying::text, 'archived'::character varying::text])", name='workflows_status_check'),
672
+ sa.CheckConstraint("trigger_type::text = ANY (ARRAY['manual'::character varying::text, 'webhook'::character varying::text, 'schedule'::character varying::text])", name='workflows_trigger_type_check'),
673
+ sa.ForeignKeyConstraint(['created_by'], ['user_profiles.id'], ondelete='SET NULL'),
674
+ sa.ForeignKeyConstraint(['updated_by'], ['user_profiles.id'], ondelete='SET NULL'),
675
+ sa.ForeignKeyConstraint(['workspace_id'], ['workspaces.id'], ondelete='CASCADE'),
676
+ sa.PrimaryKeyConstraint('id'),
677
+ sa.UniqueConstraint('slug', name='workflows_slug_key'),
678
+ sa.UniqueConstraint('workspace_id', 'slug', name='unique_workflow_slug_per_workspace')
679
+ )
680
+ op.create_index('idx_workflows_is_test_expires', 'workflows', ['is_test', 'expires_at'], unique=False, postgresql_where=sa.text('is_test = true AND expires_at IS NOT NULL'))
681
+ op.create_index('idx_workflows_slug', 'workflows', ['slug'], unique=False)
682
+ op.create_index('idx_workflows_status', 'workflows', ['status'], unique=False)
683
+ op.create_index('idx_workflows_workspace_id', 'workflows', ['workspace_id'], unique=False)
684
+ op.create_table('agent_contexts',
685
+ sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
686
+ sa.Column('agent_id', sa.UUID(), nullable=False),
687
+ sa.Column('entity_type', sa.String(length=50), server_default=sa.text("'agent'::character varying"), nullable=True),
688
+ sa.Column('organization_id', sa.UUID(), nullable=False),
689
+ sa.Column('knowledge_uuids', sa.ARRAY(sa.Text()), server_default=sa.text("'{}'::text[]"), nullable=True),
690
+ sa.Column('resource_ids', sa.ARRAY(sa.Text()), server_default=sa.text("'{}'::text[]"), nullable=True),
691
+ sa.Column('policy_ids', sa.ARRAY(sa.Text()), server_default=sa.text("'{}'::text[]"), nullable=True),
692
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
693
+ sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
694
+ sa.ForeignKeyConstraint(['agent_id'], ['agents.id'], ondelete='CASCADE'),
695
+ sa.PrimaryKeyConstraint('id'),
696
+ sa.UniqueConstraint('agent_id', 'organization_id', name='agent_contexts_agent_id_organization_id_key')
697
+ )
698
+ op.create_index('idx_agent_contexts_agent_id', 'agent_contexts', ['agent_id'], unique=False)
699
+ op.create_index('idx_agent_contexts_org_id', 'agent_contexts', ['organization_id'], unique=False)
700
+ op.create_table('agent_environments',
701
+ sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
702
+ sa.Column('agent_id', sa.UUID(), nullable=False),
703
+ sa.Column('environment_id', sa.UUID(), nullable=False),
704
+ sa.Column('organization_id', sa.String(), nullable=False),
705
+ sa.Column('assigned_at', sa.DateTime(), server_default=sa.text('now()'), nullable=False),
706
+ sa.Column('assigned_by', sa.String(), nullable=True),
707
+ sa.ForeignKeyConstraint(['agent_id'], ['agents.id'], ondelete='CASCADE'),
708
+ sa.ForeignKeyConstraint(['environment_id'], ['environments.id'], ondelete='CASCADE'),
709
+ sa.PrimaryKeyConstraint('id'),
710
+ sa.UniqueConstraint('agent_id', 'environment_id', name='uq_agent_environment')
711
+ )
712
+ op.create_index('idx_agent_environments_agent_id', 'agent_environments', ['agent_id'], unique=False)
713
+ op.create_index('idx_agent_environments_environment_id', 'agent_environments', ['environment_id'], unique=False)
714
+ op.create_index('idx_agent_environments_org_env', 'agent_environments', ['organization_id', 'environment_id'], unique=False)
715
+ op.create_index('idx_agent_environments_org_id', 'agent_environments', ['organization_id'], unique=False)
716
+ op.create_table('execution_participants',
717
+ sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
718
+ sa.Column('execution_id', sa.UUID(), nullable=False),
719
+ sa.Column('organization_id', sa.String(), nullable=False),
720
+ sa.Column('user_id', sa.String(), nullable=False),
721
+ sa.Column('user_email', sa.String(), nullable=True),
722
+ sa.Column('user_name', sa.String(), nullable=True),
723
+ sa.Column('user_avatar', sa.String(), nullable=True),
724
+ sa.Column('role', sa.Enum('owner', 'collaborator', 'viewer', name='participant_role'), server_default='collaborator', nullable=False),
725
+ sa.Column('joined_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
726
+ sa.Column('last_active_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
727
+ sa.ForeignKeyConstraint(['execution_id'], ['executions.id'], ondelete='CASCADE'),
728
+ sa.PrimaryKeyConstraint('id'),
729
+ sa.UniqueConstraint('execution_id', 'user_id', name='unique_execution_user')
730
+ )
731
+ op.create_index('idx_execution_participants_execution', 'execution_participants', ['execution_id'], unique=False)
732
+ op.create_index('idx_execution_participants_org', 'execution_participants', ['organization_id'], unique=False)
733
+ op.create_index('idx_execution_participants_user', 'execution_participants', ['user_id'], unique=False)
734
+ op.create_table('execution_tasks',
735
+ sa.Column('id', sa.UUID(), nullable=False),
736
+ sa.Column('organization_id', sa.String(), nullable=False),
737
+ sa.Column('execution_id', sa.UUID(), nullable=False),
738
+ sa.Column('task_number', sa.Integer(), nullable=True),
739
+ sa.Column('task_id', sa.String(), nullable=True),
740
+ sa.Column('task_description', sa.Text(), nullable=False),
741
+ sa.Column('task_type', sa.String(), nullable=True),
742
+ sa.Column('status', sa.String(), server_default=sa.text("'pending'::character varying"), nullable=False),
743
+ sa.Column('started_at', sa.DateTime(timezone=True), nullable=True),
744
+ sa.Column('completed_at', sa.DateTime(timezone=True), nullable=True),
745
+ sa.Column('duration_ms', sa.Integer(), nullable=True),
746
+ sa.Column('result', sa.Text(), nullable=True),
747
+ sa.Column('error_message', sa.Text(), nullable=True),
748
+ sa.Column('custom_metadata', sa.JSON(), server_default=sa.text("'{}'::json"), nullable=False),
749
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
750
+ sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
751
+ sa.ForeignKeyConstraint(['execution_id'], ['executions.id'], ondelete='CASCADE'),
752
+ sa.PrimaryKeyConstraint('id')
753
+ )
754
+ op.create_index(op.f('ix_execution_tasks_execution_id'), 'execution_tasks', ['execution_id'], unique=False)
755
+ op.create_index('ix_execution_tasks_org_execution', 'execution_tasks', ['organization_id', 'execution_id'], unique=False)
756
+ op.create_index('ix_execution_tasks_org_status', 'execution_tasks', ['organization_id', 'status'], unique=False)
757
+ op.create_index(op.f('ix_execution_tasks_organization_id'), 'execution_tasks', ['organization_id'], unique=False)
758
+ op.create_table('execution_turns',
759
+ sa.Column('id', sa.UUID(), nullable=False),
760
+ sa.Column('organization_id', sa.String(), nullable=False),
761
+ sa.Column('execution_id', sa.UUID(), nullable=False),
762
+ sa.Column('turn_number', sa.Integer(), nullable=False),
763
+ sa.Column('turn_id', sa.String(), nullable=True),
764
+ sa.Column('model', sa.String(), nullable=False),
765
+ sa.Column('model_provider', sa.String(), nullable=True),
766
+ sa.Column('started_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
767
+ sa.Column('completed_at', sa.DateTime(timezone=True), nullable=True),
768
+ sa.Column('duration_ms', sa.Integer(), nullable=True),
769
+ sa.Column('input_tokens', sa.Integer(), server_default=sa.text('0'), nullable=True),
770
+ sa.Column('output_tokens', sa.Integer(), server_default=sa.text('0'), nullable=True),
771
+ sa.Column('cache_read_tokens', sa.Integer(), server_default=sa.text('0'), nullable=True),
772
+ sa.Column('cache_creation_tokens', sa.Integer(), server_default=sa.text('0'), nullable=True),
773
+ sa.Column('total_tokens', sa.Integer(), server_default=sa.text('0'), nullable=True),
774
+ sa.Column('input_cost', sa.Float(), server_default=sa.text('0'), nullable=True),
775
+ sa.Column('output_cost', sa.Float(), server_default=sa.text('0'), nullable=True),
776
+ sa.Column('cache_read_cost', sa.Float(), server_default=sa.text('0'), nullable=True),
777
+ sa.Column('cache_creation_cost', sa.Float(), server_default=sa.text('0'), nullable=True),
778
+ sa.Column('total_cost', sa.Float(), server_default=sa.text('0'), nullable=True),
779
+ sa.Column('runtime_minutes', sa.Float(), server_default=sa.text('0'), nullable=True),
780
+ sa.Column('model_weight', sa.Float(), server_default=sa.text('1'), nullable=True),
781
+ sa.Column('tool_calls_weight', sa.Float(), server_default=sa.text('1'), nullable=True),
782
+ sa.Column('aem_value', sa.Float(), server_default=sa.text('0'), nullable=True),
783
+ sa.Column('aem_cost', sa.Float(), server_default=sa.text('0'), nullable=True),
784
+ sa.Column('finish_reason', sa.String(), nullable=True),
785
+ sa.Column('response_preview', sa.Text(), nullable=True),
786
+ sa.Column('tools_called_count', sa.Integer(), server_default=sa.text('0'), nullable=False),
787
+ sa.Column('tools_called_names', sa.JSON(), server_default=sa.text("'[]'::json"), nullable=False),
788
+ sa.Column('error_message', sa.Text(), nullable=True),
789
+ sa.Column('metrics', sa.JSON(), server_default=sa.text("'{}'::json"), nullable=False),
790
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
791
+ sa.ForeignKeyConstraint(['execution_id'], ['executions.id'], ondelete='CASCADE'),
792
+ sa.PrimaryKeyConstraint('id')
793
+ )
794
+ op.create_index(op.f('ix_execution_turns_execution_id'), 'execution_turns', ['execution_id'], unique=False)
795
+ op.create_index('ix_execution_turns_org_cost', 'execution_turns', ['organization_id', 'total_cost'], unique=False)
796
+ op.create_index('ix_execution_turns_org_created', 'execution_turns', ['organization_id', 'created_at'], unique=False)
797
+ op.create_index('ix_execution_turns_org_execution', 'execution_turns', ['organization_id', 'execution_id'], unique=False)
798
+ op.create_index('ix_execution_turns_org_model', 'execution_turns', ['organization_id', 'model'], unique=False)
799
+ op.create_index(op.f('ix_execution_turns_organization_id'), 'execution_turns', ['organization_id'], unique=False)
800
+ op.create_table('jobs',
801
+ sa.Column('id', sa.String(length=255), nullable=False),
802
+ sa.Column('organization_id', sa.String(length=255), nullable=False),
803
+ sa.Column('name', sa.String(length=255), nullable=False),
804
+ sa.Column('description', sa.Text(), nullable=True),
805
+ sa.Column('enabled', sa.Boolean(), nullable=False),
806
+ sa.Column('status', sa.String(length=50), nullable=False),
807
+ sa.Column('trigger_type', sa.String(length=50), nullable=False),
808
+ sa.Column('cron_schedule', sa.String(length=255), nullable=True),
809
+ sa.Column('cron_timezone', sa.String(length=100), nullable=True),
810
+ sa.Column('webhook_url_path', sa.String(length=500), nullable=True),
811
+ sa.Column('webhook_secret', sa.String(length=500), nullable=True),
812
+ sa.Column('temporal_schedule_id', sa.String(length=255), nullable=True),
813
+ sa.Column('planning_mode', sa.String(length=50), nullable=False),
814
+ sa.Column('entity_type', sa.String(length=50), nullable=True),
815
+ sa.Column('entity_id', sa.String(length=255), nullable=True),
816
+ sa.Column('entity_name', sa.String(length=255), nullable=True),
817
+ sa.Column('prompt_template', sa.Text(), nullable=False),
818
+ sa.Column('system_prompt', sa.Text(), nullable=True),
819
+ sa.Column('executor_type', sa.String(length=50), nullable=False),
820
+ sa.Column('worker_queue_name', sa.String(length=255), nullable=True),
821
+ sa.Column('environment_name', sa.String(length=255), nullable=True),
822
+ sa.Column('config', sa.JSON(), nullable=True),
823
+ sa.Column('execution_environment', sa.JSON(), nullable=True),
824
+ sa.Column('last_execution_at', sa.DateTime(timezone=True), nullable=True),
825
+ sa.Column('next_execution_at', sa.DateTime(timezone=True), nullable=True),
826
+ sa.Column('total_executions', sa.Integer(), nullable=False),
827
+ sa.Column('successful_executions', sa.Integer(), nullable=False),
828
+ sa.Column('failed_executions', sa.Integer(), nullable=False),
829
+ sa.Column('execution_history', sa.JSON(), nullable=True),
830
+ sa.Column('created_by', sa.String(length=255), nullable=True),
831
+ sa.Column('updated_by', sa.String(length=255), nullable=True),
832
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
833
+ sa.Column('updated_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
834
+ sa.Column('last_triggered_at', sa.DateTime(timezone=True), nullable=True),
835
+ sa.Column('last_execution_id', sa.UUID(), nullable=True),
836
+ sa.ForeignKeyConstraint(['last_execution_id'], ['executions.id'], ondelete='SET NULL'),
837
+ sa.PrimaryKeyConstraint('id'),
838
+ sa.UniqueConstraint('temporal_schedule_id'),
839
+ sa.UniqueConstraint('webhook_url_path')
840
+ )
841
+ op.create_index('idx_jobs_created_at', 'jobs', ['created_at'], unique=False)
842
+ op.create_index('idx_jobs_enabled', 'jobs', ['enabled'], unique=False)
843
+ op.create_index('idx_jobs_name', 'jobs', ['organization_id', 'name'], unique=False)
844
+ op.create_index('idx_jobs_next_execution_at', 'jobs', ['next_execution_at'], unique=False)
845
+ op.create_index('idx_jobs_organization_id', 'jobs', ['organization_id'], unique=False)
846
+ op.create_index('idx_jobs_status', 'jobs', ['status'], unique=False)
847
+ op.create_index('idx_jobs_temporal_schedule_id', 'jobs', ['temporal_schedule_id'], unique=False)
848
+ op.create_index('idx_jobs_trigger_type', 'jobs', ['trigger_type'], unique=False)
849
+ op.create_index('idx_jobs_webhook_url_path', 'jobs', ['webhook_url_path'], unique=False)
850
+ op.create_table('project_agents',
851
+ sa.Column('id', sa.UUID(), server_default=sa.text('gen_random_uuid()'), nullable=False),
852
+ sa.Column('project_id', sa.UUID(), nullable=False),
853
+ sa.Column('agent_id', sa.UUID(), nullable=False),
854
+ sa.Column('role', sa.String(length=50), nullable=True),
855
+ sa.Column('added_by', sa.String(length=255), nullable=True),
856
+ sa.Column('added_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
857
+ sa.ForeignKeyConstraint(['agent_id'], ['agents.id'], ondelete='CASCADE'),
858
+ sa.ForeignKeyConstraint(['project_id'], ['projects.id'], ondelete='CASCADE'),
859
+ sa.PrimaryKeyConstraint('id'),
860
+ sa.UniqueConstraint('project_id', 'agent_id', name='unique_project_agent')
861
+ )
862
+ op.create_index('idx_project_agents_agent', 'project_agents', ['agent_id'], unique=False)
863
+ op.create_index('idx_project_agents_project', 'project_agents', ['project_id'], unique=False)
864
+ op.create_table('execution_tool_calls',
865
+ sa.Column('id', sa.UUID(), nullable=False),
866
+ sa.Column('organization_id', sa.String(), nullable=False),
867
+ sa.Column('execution_id', sa.UUID(), nullable=False),
868
+ sa.Column('turn_id', sa.UUID(), nullable=True),
869
+ sa.Column('tool_name', sa.String(), nullable=False),
870
+ sa.Column('tool_use_id', sa.String(), nullable=True),
871
+ sa.Column('started_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
872
+ sa.Column('completed_at', sa.DateTime(timezone=True), nullable=True),
873
+ sa.Column('duration_ms', sa.Integer(), nullable=True),
874
+ sa.Column('tool_input', sa.JSON(), nullable=True),
875
+ sa.Column('tool_output', sa.Text(), nullable=True),
876
+ sa.Column('tool_output_size', sa.Integer(), nullable=True),
877
+ sa.Column('success', sa.Boolean(), server_default=sa.text('true'), nullable=False),
878
+ sa.Column('error_message', sa.Text(), nullable=True),
879
+ sa.Column('error_type', sa.String(), nullable=True),
880
+ sa.Column('metadata', sa.JSON(), server_default=sa.text("'{}'::json"), nullable=False),
881
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
882
+ sa.ForeignKeyConstraint(['execution_id'], ['executions.id'], ondelete='CASCADE'),
883
+ sa.ForeignKeyConstraint(['turn_id'], ['execution_turns.id'], ondelete='CASCADE'),
884
+ sa.PrimaryKeyConstraint('id')
885
+ )
886
+ op.create_index(op.f('ix_execution_tool_calls_execution_id'), 'execution_tool_calls', ['execution_id'], unique=False)
887
+ op.create_index('ix_execution_tool_calls_org_created', 'execution_tool_calls', ['organization_id', 'created_at'], unique=False)
888
+ op.create_index('ix_execution_tool_calls_org_execution', 'execution_tool_calls', ['organization_id', 'execution_id'], unique=False)
889
+ op.create_index('ix_execution_tool_calls_org_success', 'execution_tool_calls', ['organization_id', 'success'], unique=False)
890
+ op.create_index('ix_execution_tool_calls_org_tool', 'execution_tool_calls', ['organization_id', 'tool_name'], unique=False)
891
+ op.create_index(op.f('ix_execution_tool_calls_organization_id'), 'execution_tool_calls', ['organization_id'], unique=False)
892
+ op.create_index(op.f('ix_execution_tool_calls_tool_name'), 'execution_tool_calls', ['tool_name'], unique=False)
893
+ op.create_index(op.f('ix_execution_tool_calls_turn_id'), 'execution_tool_calls', ['turn_id'], unique=False)
894
+ op.create_table('job_executions',
895
+ sa.Column('id', sa.String(length=255), nullable=False),
896
+ sa.Column('job_id', sa.String(length=255), nullable=False),
897
+ sa.Column('organization_id', sa.String(length=255), nullable=False),
898
+ sa.Column('trigger_type', sa.String(length=50), nullable=False),
899
+ sa.Column('trigger_metadata', sa.JSON(), nullable=True),
900
+ sa.Column('execution_status', sa.String(length=50), nullable=True),
901
+ sa.Column('execution_duration_ms', sa.Integer(), nullable=True),
902
+ sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
903
+ sa.Column('execution_id', sa.UUID(), nullable=False),
904
+ sa.ForeignKeyConstraint(['execution_id'], ['executions.id'], ondelete='CASCADE'),
905
+ sa.ForeignKeyConstraint(['job_id'], ['jobs.id'], ondelete='CASCADE'),
906
+ sa.PrimaryKeyConstraint('id')
907
+ )
908
+ op.create_index('idx_job_executions_created_at', 'job_executions', ['created_at'], unique=False)
909
+ op.create_index('idx_job_executions_execution_id', 'job_executions', ['execution_id'], unique=False)
910
+ op.create_index('idx_job_executions_execution_status', 'job_executions', ['execution_status'], unique=False)
911
+ op.create_index('idx_job_executions_job_id', 'job_executions', ['job_id'], unique=False)
912
+ op.create_index('idx_job_executions_organization_id', 'job_executions', ['organization_id'], unique=False)
913
+ op.create_index('idx_job_executions_trigger_type', 'job_executions', ['trigger_type'], unique=False)
914
+ # ### end Alembic commands ###
915
+
916
+
917
+ def downgrade() -> None:
918
+ """Downgrade schema."""
919
+ # ### commands auto generated by Alembic - please adjust! ###
920
+ op.drop_index('idx_job_executions_trigger_type', table_name='job_executions')
921
+ op.drop_index('idx_job_executions_organization_id', table_name='job_executions')
922
+ op.drop_index('idx_job_executions_job_id', table_name='job_executions')
923
+ op.drop_index('idx_job_executions_execution_status', table_name='job_executions')
924
+ op.drop_index('idx_job_executions_execution_id', table_name='job_executions')
925
+ op.drop_index('idx_job_executions_created_at', table_name='job_executions')
926
+ op.drop_table('job_executions')
927
+ op.drop_index(op.f('ix_execution_tool_calls_turn_id'), table_name='execution_tool_calls')
928
+ op.drop_index(op.f('ix_execution_tool_calls_tool_name'), table_name='execution_tool_calls')
929
+ op.drop_index(op.f('ix_execution_tool_calls_organization_id'), table_name='execution_tool_calls')
930
+ op.drop_index('ix_execution_tool_calls_org_tool', table_name='execution_tool_calls')
931
+ op.drop_index('ix_execution_tool_calls_org_success', table_name='execution_tool_calls')
932
+ op.drop_index('ix_execution_tool_calls_org_execution', table_name='execution_tool_calls')
933
+ op.drop_index('ix_execution_tool_calls_org_created', table_name='execution_tool_calls')
934
+ op.drop_index(op.f('ix_execution_tool_calls_execution_id'), table_name='execution_tool_calls')
935
+ op.drop_table('execution_tool_calls')
936
+ op.drop_index('idx_project_agents_project', table_name='project_agents')
937
+ op.drop_index('idx_project_agents_agent', table_name='project_agents')
938
+ op.drop_table('project_agents')
939
+ op.drop_index('idx_jobs_webhook_url_path', table_name='jobs')
940
+ op.drop_index('idx_jobs_trigger_type', table_name='jobs')
941
+ op.drop_index('idx_jobs_temporal_schedule_id', table_name='jobs')
942
+ op.drop_index('idx_jobs_status', table_name='jobs')
943
+ op.drop_index('idx_jobs_organization_id', table_name='jobs')
944
+ op.drop_index('idx_jobs_next_execution_at', table_name='jobs')
945
+ op.drop_index('idx_jobs_name', table_name='jobs')
946
+ op.drop_index('idx_jobs_enabled', table_name='jobs')
947
+ op.drop_index('idx_jobs_created_at', table_name='jobs')
948
+ op.drop_table('jobs')
949
+ op.drop_index(op.f('ix_execution_turns_organization_id'), table_name='execution_turns')
950
+ op.drop_index('ix_execution_turns_org_model', table_name='execution_turns')
951
+ op.drop_index('ix_execution_turns_org_execution', table_name='execution_turns')
952
+ op.drop_index('ix_execution_turns_org_created', table_name='execution_turns')
953
+ op.drop_index('ix_execution_turns_org_cost', table_name='execution_turns')
954
+ op.drop_index(op.f('ix_execution_turns_execution_id'), table_name='execution_turns')
955
+ op.drop_table('execution_turns')
956
+ op.drop_index(op.f('ix_execution_tasks_organization_id'), table_name='execution_tasks')
957
+ op.drop_index('ix_execution_tasks_org_status', table_name='execution_tasks')
958
+ op.drop_index('ix_execution_tasks_org_execution', table_name='execution_tasks')
959
+ op.drop_index(op.f('ix_execution_tasks_execution_id'), table_name='execution_tasks')
960
+ op.drop_table('execution_tasks')
961
+ op.drop_index('idx_execution_participants_user', table_name='execution_participants')
962
+ op.drop_index('idx_execution_participants_org', table_name='execution_participants')
963
+ op.drop_index('idx_execution_participants_execution', table_name='execution_participants')
964
+ op.drop_table('execution_participants')
965
+ op.drop_index('idx_agent_environments_org_id', table_name='agent_environments')
966
+ op.drop_index('idx_agent_environments_org_env', table_name='agent_environments')
967
+ op.drop_index('idx_agent_environments_environment_id', table_name='agent_environments')
968
+ op.drop_index('idx_agent_environments_agent_id', table_name='agent_environments')
969
+ op.drop_table('agent_environments')
970
+ op.drop_index('idx_agent_contexts_org_id', table_name='agent_contexts')
971
+ op.drop_index('idx_agent_contexts_agent_id', table_name='agent_contexts')
972
+ op.drop_table('agent_contexts')
973
+ op.drop_index('idx_workflows_workspace_id', table_name='workflows')
974
+ op.drop_index('idx_workflows_status', table_name='workflows')
975
+ op.drop_index('idx_workflows_slug', table_name='workflows')
976
+ op.drop_index('idx_workflows_is_test_expires', table_name='workflows', postgresql_where=sa.text('is_test = true AND expires_at IS NOT NULL'))
977
+ op.drop_table('workflows')
978
+ op.drop_index('idx_worker_heartbeats_token', table_name='worker_heartbeats')
979
+ op.drop_index('idx_worker_heartbeats_status', table_name='worker_heartbeats')
980
+ op.drop_index('idx_worker_heartbeats_queue_status_heartbeat', table_name='worker_heartbeats')
981
+ op.drop_index('idx_worker_heartbeats_queue', table_name='worker_heartbeats')
982
+ op.drop_index('idx_worker_heartbeats_org_status_heartbeat', table_name='worker_heartbeats')
983
+ op.drop_index('idx_worker_heartbeats_org_status', table_name='worker_heartbeats')
984
+ op.drop_index('idx_worker_heartbeats_org', table_name='worker_heartbeats')
985
+ op.drop_index('idx_worker_heartbeats_last_heartbeat', table_name='worker_heartbeats')
986
+ op.drop_index('idx_worker_heartbeats_environment', table_name='worker_heartbeats')
987
+ op.drop_table('worker_heartbeats')
988
+ op.drop_index('idx_team_environments_team_id', table_name='team_environments')
989
+ op.drop_index('idx_team_environments_org_id', table_name='team_environments')
990
+ op.drop_index('idx_team_environments_org_env', table_name='team_environments')
991
+ op.drop_index('idx_team_environments_environment_id', table_name='team_environments')
992
+ op.drop_table('team_environments')
993
+ op.drop_index('idx_team_contexts_team_id', table_name='team_contexts')
994
+ op.drop_index('idx_team_contexts_org_id', table_name='team_contexts')
995
+ op.drop_table('team_contexts')
996
+ op.drop_index('idx_project_teams_team', table_name='project_teams')
997
+ op.drop_index('idx_project_teams_project', table_name='project_teams')
998
+ op.drop_table('project_teams')
999
+ op.drop_index('idx_project_contexts_project_id', table_name='project_contexts')
1000
+ op.drop_index('idx_project_contexts_org_id', table_name='project_contexts')
1001
+ op.drop_table('project_contexts')
1002
+ op.drop_index(op.f('ix_executions_worker_queue_id'), table_name='executions')
1003
+ op.drop_index(op.f('ix_executions_user_id'), table_name='executions')
1004
+ op.drop_index(op.f('ix_executions_trigger_source'), table_name='executions')
1005
+ op.drop_index(op.f('ix_executions_organization_id'), table_name='executions')
1006
+ op.drop_index('idx_executions_workflow', table_name='executions', postgresql_where='temporal_workflow_id IS NOT NULL')
1007
+ op.drop_index('idx_executions_worker_queue_id', table_name='executions')
1008
+ op.drop_index('idx_executions_user_id', table_name='executions')
1009
+ op.drop_index('idx_executions_user_email', table_name='executions')
1010
+ op.drop_index('idx_executions_user', table_name='executions')
1011
+ op.drop_index('idx_executions_task_queue', table_name='executions')
1012
+ op.drop_index('idx_executions_status', table_name='executions')
1013
+ op.drop_index('idx_executions_runner', table_name='executions')
1014
+ op.drop_index('idx_executions_run', table_name='executions', postgresql_where='temporal_run_id IS NOT NULL')
1015
+ op.drop_index('idx_executions_org', table_name='executions')
1016
+ op.drop_index('idx_executions_entity', table_name='executions')
1017
+ op.drop_index('idx_executions_created', table_name='executions')
1018
+ op.drop_table('executions')
1019
+ op.drop_index('idx_agents_visibility', table_name='agents')
1020
+ op.drop_index('idx_agents_toolset_ids', table_name='agents', postgresql_using='gin')
1021
+ op.drop_index('idx_agents_team_id', table_name='agents')
1022
+ op.drop_index('idx_agents_team', table_name='agents')
1023
+ op.drop_index('idx_agents_status', table_name='agents')
1024
+ op.drop_index('idx_agents_runtime', table_name='agents')
1025
+ op.drop_index('idx_agents_project_id', table_name='agents')
1026
+ op.drop_index('idx_agents_policy_ids', table_name='agents', postgresql_using='gin')
1027
+ op.drop_index('idx_agents_org_runtime', table_name='agents')
1028
+ op.drop_index('idx_agents_org', table_name='agents')
1029
+ op.drop_index('idx_agents_execution_environment', table_name='agents', postgresql_using='gin')
1030
+ op.drop_index('idx_agents_environment_id', table_name='agents')
1031
+ op.drop_table('agents')
1032
+ op.drop_index('idx_workers_token', table_name='workers')
1033
+ op.drop_index('idx_workers_task_queue', table_name='workers')
1034
+ op.drop_index('idx_workers_status', table_name='workers')
1035
+ op.drop_index('idx_workers_org', table_name='workers')
1036
+ op.drop_table('workers')
1037
+ op.drop_index('idx_worker_queues_status', table_name='worker_queues')
1038
+ op.drop_index('idx_worker_queues_org', table_name='worker_queues')
1039
+ op.drop_index('idx_worker_queues_env', table_name='worker_queues')
1040
+ op.drop_table('worker_queues')
1041
+ op.drop_table('user_profiles')
1042
+ op.drop_index('ix_teams_runtime', table_name='teams')
1043
+ op.drop_index('idx_teams_visibility', table_name='teams')
1044
+ op.drop_index('idx_teams_toolset_ids', table_name='teams', postgresql_using='gin')
1045
+ op.drop_index('idx_teams_status', table_name='teams')
1046
+ op.drop_index('idx_teams_policy_ids', table_name='teams', postgresql_using='gin')
1047
+ op.drop_index('idx_teams_org', table_name='teams')
1048
+ op.drop_index('idx_teams_execution_environment', table_name='teams', postgresql_using='gin')
1049
+ op.drop_index('idx_teams_environment_id', table_name='teams')
1050
+ op.drop_table('teams')
1051
+ op.drop_index('ix_slash_command_executions_user_id', table_name='slash_command_executions')
1052
+ op.drop_index('ix_slash_command_executions_command_id', table_name='slash_command_executions')
1053
+ op.drop_table('slash_command_executions')
1054
+ op.drop_index('ix_skill_associations_skill_id', table_name='skill_associations')
1055
+ op.drop_index(op.f('ix_skill_associations_organization_id'), table_name='skill_associations')
1056
+ op.drop_index('ix_skill_associations_org_skill', table_name='skill_associations')
1057
+ op.drop_index('ix_skill_associations_entity', table_name='skill_associations')
1058
+ op.drop_table('skill_associations')
1059
+ op.drop_index('idx_projects_visibility', table_name='projects')
1060
+ op.drop_index('idx_projects_status', table_name='projects', postgresql_where=sa.text("status = 'active'"))
1061
+ op.drop_index('idx_projects_owner', table_name='projects')
1062
+ op.drop_index('idx_projects_org_id', table_name='projects')
1063
+ op.drop_index('idx_projects_environment_id', table_name='projects')
1064
+ op.drop_table('projects')
1065
+ op.drop_index('idx_orchestration_server_health_server_id', table_name='orchestration_server_health')
1066
+ op.drop_index('idx_orchestration_server_health_checked_at', table_name='orchestration_server_health')
1067
+ op.drop_table('orchestration_server_health')
1068
+ op.drop_index('idx_environment_contexts_org_id', table_name='environment_contexts')
1069
+ op.drop_index('idx_environment_contexts_environment_id', table_name='environment_contexts')
1070
+ op.drop_table('environment_contexts')
1071
+ op.drop_table('workspaces')
1072
+ op.drop_index(op.f('ix_user_presence_user_id'), table_name='user_presence')
1073
+ op.drop_index(op.f('ix_user_presence_session_id'), table_name='user_presence')
1074
+ op.drop_index(op.f('ix_user_presence_execution_id'), table_name='user_presence')
1075
+ op.drop_index(op.f('ix_user_presence_agent_id'), table_name='user_presence')
1076
+ op.drop_index('idx_presence_user', table_name='user_presence')
1077
+ op.drop_index('idx_presence_lookup', table_name='user_presence')
1078
+ op.drop_table('user_presence')
1079
+ op.drop_index('idx_temporal_namespaces_status', table_name='temporal_namespaces')
1080
+ op.drop_index('idx_temporal_namespaces_organization_id', table_name='temporal_namespaces')
1081
+ op.drop_table('temporal_namespaces')
1082
+ op.drop_index(op.f('ix_slash_commands_user_id'), table_name='slash_commands')
1083
+ op.drop_table('slash_commands')
1084
+ op.drop_index(op.f('ix_skills_organization_id'), table_name='skills')
1085
+ op.drop_index('idx_skills_type', table_name='skills')
1086
+ op.drop_index('idx_skills_enabled', table_name='skills')
1087
+ op.drop_table('skills')
1088
+ op.drop_index('idx_sessions_updated_at', table_name='sessions', postgresql_ops={'updated_at': 'DESC'})
1089
+ op.drop_index('idx_sessions_session_id', table_name='sessions')
1090
+ op.drop_index('idx_sessions_organization_id', table_name='sessions')
1091
+ op.drop_table('sessions')
1092
+ op.drop_index('idx_policy_assoc_priority', table_name='policy_associations', schema='public', postgresql_ops={'priority': 'DESC'})
1093
+ op.drop_index('idx_policy_assoc_policy', table_name='policy_associations', schema='public')
1094
+ op.drop_index('idx_policy_assoc_org', table_name='policy_associations', schema='public')
1095
+ op.drop_index('idx_policy_assoc_entity_enabled', table_name='policy_associations', schema='public', postgresql_ops={'priority': 'DESC'})
1096
+ op.drop_index('idx_policy_assoc_entity', table_name='policy_associations', schema='public')
1097
+ op.drop_index('idx_policy_assoc_enabled', table_name='policy_associations', schema='public')
1098
+ op.drop_table('policy_associations', schema='public')
1099
+ op.drop_index('idx_profiles_email', table_name='profiles')
1100
+ op.drop_table('profiles')
1101
+ op.drop_index('idx_orchestration_servers_user_id', table_name='orchestration_servers')
1102
+ op.drop_index('idx_orchestration_servers_scope', table_name='orchestration_servers')
1103
+ op.drop_index('idx_orchestration_servers_is_default', table_name='orchestration_servers')
1104
+ op.drop_index('idx_orchestration_servers_is_active', table_name='orchestration_servers')
1105
+ op.drop_table('orchestration_servers')
1106
+ op.drop_index('idx_namespaces_status', table_name='namespaces')
1107
+ op.drop_index('idx_namespaces_organization_id', table_name='namespaces')
1108
+ op.drop_table('namespaces')
1109
+ op.drop_index(op.f('ix_llm_models_value'), table_name='llm_models')
1110
+ op.drop_index(op.f('ix_llm_models_provider'), table_name='llm_models')
1111
+ op.drop_index(op.f('ix_llm_models_enabled'), table_name='llm_models')
1112
+ op.drop_table('llm_models')
1113
+ op.drop_index('idx_task_queues_worker_token', table_name='environments')
1114
+ op.drop_index('idx_task_queues_status', table_name='environments', postgresql_where=sa.text("status::text = 'active'::text"))
1115
+ op.drop_index('idx_task_queues_org', table_name='environments')
1116
+ op.drop_index('idx_task_queues_namespace', table_name='environments')
1117
+ op.drop_index('idx_task_queues_name', table_name='environments')
1118
+ op.drop_index('idx_environments_policy_ids', table_name='environments', postgresql_using='gin')
1119
+ op.drop_index('idx_environments_execution_environment', table_name='environments', postgresql_using='gin')
1120
+ op.drop_table('environments')
1121
+ op.drop_index('idx_context_resources_updated_at', table_name='context_resources', postgresql_ops={'updated_at': 'DESC'})
1122
+ op.drop_index('idx_context_resources_status', table_name='context_resources')
1123
+ op.drop_index('idx_context_resources_platform', table_name='context_resources')
1124
+ op.drop_index('idx_context_resources_organization', table_name='context_resources')
1125
+ op.drop_index('idx_context_resources_org_platform', table_name='context_resources')
1126
+ op.drop_index('idx_context_resources_name', table_name='context_resources')
1127
+ op.drop_table('context_resources')
1128
+ # ### end Alembic commands ###