django-cfg 1.1.82__py3-none-any.whl → 1.2.0__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 (244) hide show
  1. django_cfg/__init__.py +20 -448
  2. django_cfg/apps/accounts/README.md +3 -3
  3. django_cfg/apps/accounts/admin/__init__.py +0 -2
  4. django_cfg/apps/accounts/admin/activity.py +2 -9
  5. django_cfg/apps/accounts/admin/filters.py +0 -42
  6. django_cfg/apps/accounts/admin/inlines.py +8 -8
  7. django_cfg/apps/accounts/admin/otp.py +5 -5
  8. django_cfg/apps/accounts/admin/registration_source.py +1 -8
  9. django_cfg/apps/accounts/admin/user.py +12 -20
  10. django_cfg/apps/accounts/managers/user_manager.py +2 -129
  11. django_cfg/apps/accounts/migrations/0006_remove_twilioresponse_otp_secret_and_more.py +46 -0
  12. django_cfg/apps/accounts/models.py +3 -123
  13. django_cfg/apps/accounts/serializers/otp.py +40 -44
  14. django_cfg/apps/accounts/serializers/profile.py +0 -2
  15. django_cfg/apps/accounts/services/otp_service.py +98 -186
  16. django_cfg/apps/accounts/signals.py +25 -15
  17. django_cfg/apps/accounts/utils/auth_email_service.py +84 -0
  18. django_cfg/apps/accounts/views/otp.py +35 -36
  19. django_cfg/apps/agents/README.md +129 -0
  20. django_cfg/apps/agents/__init__.py +68 -0
  21. django_cfg/apps/agents/admin/__init__.py +17 -0
  22. django_cfg/apps/agents/admin/execution_admin.py +460 -0
  23. django_cfg/apps/agents/admin/registry_admin.py +360 -0
  24. django_cfg/apps/agents/admin/toolsets_admin.py +482 -0
  25. django_cfg/apps/agents/apps.py +29 -0
  26. django_cfg/apps/agents/core/__init__.py +20 -0
  27. django_cfg/apps/agents/core/agent.py +281 -0
  28. django_cfg/apps/agents/core/dependencies.py +154 -0
  29. django_cfg/apps/agents/core/exceptions.py +66 -0
  30. django_cfg/apps/agents/core/models.py +106 -0
  31. django_cfg/apps/agents/core/orchestrator.py +391 -0
  32. django_cfg/apps/agents/examples/__init__.py +3 -0
  33. django_cfg/apps/agents/examples/simple_example.py +161 -0
  34. django_cfg/apps/agents/integration/__init__.py +14 -0
  35. django_cfg/apps/agents/integration/middleware.py +80 -0
  36. django_cfg/apps/agents/integration/registry.py +345 -0
  37. django_cfg/apps/agents/integration/signals.py +50 -0
  38. django_cfg/apps/agents/management/__init__.py +3 -0
  39. django_cfg/apps/agents/management/commands/__init__.py +3 -0
  40. django_cfg/apps/agents/management/commands/create_agent.py +365 -0
  41. django_cfg/apps/agents/management/commands/orchestrator_status.py +191 -0
  42. django_cfg/apps/agents/managers/__init__.py +23 -0
  43. django_cfg/apps/agents/managers/execution.py +236 -0
  44. django_cfg/apps/agents/managers/registry.py +254 -0
  45. django_cfg/apps/agents/managers/toolsets.py +496 -0
  46. django_cfg/apps/agents/migrations/0001_initial.py +286 -0
  47. django_cfg/apps/agents/migrations/__init__.py +5 -0
  48. django_cfg/apps/agents/models/__init__.py +15 -0
  49. django_cfg/apps/agents/models/execution.py +215 -0
  50. django_cfg/apps/agents/models/registry.py +220 -0
  51. django_cfg/apps/agents/models/toolsets.py +305 -0
  52. django_cfg/apps/agents/patterns/__init__.py +24 -0
  53. django_cfg/apps/agents/patterns/content_agents.py +234 -0
  54. django_cfg/apps/agents/toolsets/__init__.py +15 -0
  55. django_cfg/apps/agents/toolsets/cache_toolset.py +285 -0
  56. django_cfg/apps/agents/toolsets/django_toolset.py +220 -0
  57. django_cfg/apps/agents/toolsets/file_toolset.py +324 -0
  58. django_cfg/apps/agents/toolsets/orm_toolset.py +319 -0
  59. django_cfg/apps/agents/urls.py +46 -0
  60. django_cfg/apps/knowbase/README.md +150 -0
  61. django_cfg/apps/knowbase/__init__.py +27 -0
  62. django_cfg/apps/knowbase/admin/__init__.py +23 -0
  63. django_cfg/apps/knowbase/admin/archive_admin.py +857 -0
  64. django_cfg/apps/knowbase/admin/chat_admin.py +386 -0
  65. django_cfg/apps/knowbase/admin/document_admin.py +650 -0
  66. django_cfg/apps/knowbase/admin/external_data_admin.py +685 -0
  67. django_cfg/apps/knowbase/apps.py +81 -0
  68. django_cfg/apps/knowbase/config/README.md +176 -0
  69. django_cfg/apps/knowbase/config/__init__.py +51 -0
  70. django_cfg/apps/knowbase/config/constance_fields.py +186 -0
  71. django_cfg/apps/knowbase/config/constance_settings.py +200 -0
  72. django_cfg/apps/knowbase/config/settings.py +444 -0
  73. django_cfg/apps/knowbase/examples/__init__.py +3 -0
  74. django_cfg/apps/knowbase/examples/external_data_usage.py +191 -0
  75. django_cfg/apps/knowbase/management/__init__.py +0 -0
  76. django_cfg/apps/knowbase/management/commands/__init__.py +0 -0
  77. django_cfg/apps/knowbase/management/commands/knowbase_stats.py +158 -0
  78. django_cfg/apps/knowbase/management/commands/setup_knowbase.py +59 -0
  79. django_cfg/apps/knowbase/managers/__init__.py +22 -0
  80. django_cfg/apps/knowbase/managers/archive.py +426 -0
  81. django_cfg/apps/knowbase/managers/base.py +32 -0
  82. django_cfg/apps/knowbase/managers/chat.py +141 -0
  83. django_cfg/apps/knowbase/managers/document.py +203 -0
  84. django_cfg/apps/knowbase/managers/external_data.py +471 -0
  85. django_cfg/apps/knowbase/migrations/0001_initial.py +427 -0
  86. django_cfg/apps/knowbase/migrations/0002_archiveitem_archiveitemchunk_documentarchive_and_more.py +434 -0
  87. django_cfg/apps/knowbase/migrations/__init__.py +5 -0
  88. django_cfg/apps/knowbase/mixins/__init__.py +15 -0
  89. django_cfg/apps/knowbase/mixins/config.py +108 -0
  90. django_cfg/apps/knowbase/mixins/creator.py +81 -0
  91. django_cfg/apps/knowbase/mixins/examples/vehicle_model_example.py +199 -0
  92. django_cfg/apps/knowbase/mixins/external_data_mixin.py +813 -0
  93. django_cfg/apps/knowbase/mixins/service.py +362 -0
  94. django_cfg/apps/knowbase/models/__init__.py +41 -0
  95. django_cfg/apps/knowbase/models/archive.py +599 -0
  96. django_cfg/apps/knowbase/models/base.py +58 -0
  97. django_cfg/apps/knowbase/models/chat.py +157 -0
  98. django_cfg/apps/knowbase/models/document.py +267 -0
  99. django_cfg/apps/knowbase/models/external_data.py +376 -0
  100. django_cfg/apps/knowbase/serializers/__init__.py +68 -0
  101. django_cfg/apps/knowbase/serializers/archive_serializers.py +386 -0
  102. django_cfg/apps/knowbase/serializers/chat_serializers.py +137 -0
  103. django_cfg/apps/knowbase/serializers/document_serializers.py +94 -0
  104. django_cfg/apps/knowbase/serializers/external_data_serializers.py +256 -0
  105. django_cfg/apps/knowbase/serializers/public_serializers.py +74 -0
  106. django_cfg/apps/knowbase/services/__init__.py +40 -0
  107. django_cfg/apps/knowbase/services/archive/__init__.py +42 -0
  108. django_cfg/apps/knowbase/services/archive/archive_service.py +541 -0
  109. django_cfg/apps/knowbase/services/archive/chunking_service.py +791 -0
  110. django_cfg/apps/knowbase/services/archive/exceptions.py +52 -0
  111. django_cfg/apps/knowbase/services/archive/extraction_service.py +508 -0
  112. django_cfg/apps/knowbase/services/archive/vectorization_service.py +362 -0
  113. django_cfg/apps/knowbase/services/base.py +53 -0
  114. django_cfg/apps/knowbase/services/chat_service.py +239 -0
  115. django_cfg/apps/knowbase/services/document_service.py +144 -0
  116. django_cfg/apps/knowbase/services/embedding/__init__.py +43 -0
  117. django_cfg/apps/knowbase/services/embedding/async_processor.py +244 -0
  118. django_cfg/apps/knowbase/services/embedding/batch_processor.py +250 -0
  119. django_cfg/apps/knowbase/services/embedding/batch_result.py +61 -0
  120. django_cfg/apps/knowbase/services/embedding/models.py +229 -0
  121. django_cfg/apps/knowbase/services/embedding/processors.py +148 -0
  122. django_cfg/apps/knowbase/services/embedding/utils.py +176 -0
  123. django_cfg/apps/knowbase/services/prompt_builder.py +191 -0
  124. django_cfg/apps/knowbase/services/search_service.py +293 -0
  125. django_cfg/apps/knowbase/signals/__init__.py +21 -0
  126. django_cfg/apps/knowbase/signals/archive_signals.py +211 -0
  127. django_cfg/apps/knowbase/signals/chat_signals.py +37 -0
  128. django_cfg/apps/knowbase/signals/document_signals.py +143 -0
  129. django_cfg/apps/knowbase/signals/external_data_signals.py +157 -0
  130. django_cfg/apps/knowbase/tasks/__init__.py +39 -0
  131. django_cfg/apps/knowbase/tasks/archive_tasks.py +316 -0
  132. django_cfg/apps/knowbase/tasks/document_processing.py +341 -0
  133. django_cfg/apps/knowbase/tasks/external_data_tasks.py +341 -0
  134. django_cfg/apps/knowbase/tasks/maintenance.py +195 -0
  135. django_cfg/apps/knowbase/urls.py +43 -0
  136. django_cfg/apps/knowbase/utils/__init__.py +12 -0
  137. django_cfg/apps/knowbase/utils/chunk_settings.py +261 -0
  138. django_cfg/apps/knowbase/utils/text_processing.py +375 -0
  139. django_cfg/apps/knowbase/utils/validation.py +99 -0
  140. django_cfg/apps/knowbase/views/__init__.py +28 -0
  141. django_cfg/apps/knowbase/views/archive_views.py +469 -0
  142. django_cfg/apps/knowbase/views/base.py +49 -0
  143. django_cfg/apps/knowbase/views/chat_views.py +181 -0
  144. django_cfg/apps/knowbase/views/document_views.py +183 -0
  145. django_cfg/apps/knowbase/views/public_views.py +129 -0
  146. django_cfg/apps/leads/admin.py +70 -0
  147. django_cfg/apps/newsletter/admin.py +234 -0
  148. django_cfg/apps/newsletter/admin_filters.py +124 -0
  149. django_cfg/apps/support/admin.py +196 -0
  150. django_cfg/apps/support/admin_filters.py +71 -0
  151. django_cfg/apps/support/templates/support/chat/ticket_chat.html +1 -1
  152. django_cfg/apps/urls.py +5 -4
  153. django_cfg/cli/README.md +1 -1
  154. django_cfg/cli/commands/create_project.py +2 -2
  155. django_cfg/cli/commands/info.py +1 -1
  156. django_cfg/config.py +44 -0
  157. django_cfg/core/config.py +29 -82
  158. django_cfg/core/environment.py +1 -1
  159. django_cfg/core/generation.py +19 -107
  160. django_cfg/{integration.py → core/integration.py} +18 -16
  161. django_cfg/core/validation.py +1 -1
  162. django_cfg/management/__init__.py +1 -1
  163. django_cfg/management/commands/__init__.py +1 -1
  164. django_cfg/management/commands/auto_generate.py +482 -0
  165. django_cfg/management/commands/migrator.py +19 -101
  166. django_cfg/management/commands/test_email.py +1 -1
  167. django_cfg/middleware/README.md +0 -158
  168. django_cfg/middleware/__init__.py +0 -2
  169. django_cfg/middleware/user_activity.py +3 -3
  170. django_cfg/models/api.py +145 -0
  171. django_cfg/models/base.py +287 -0
  172. django_cfg/models/cache.py +4 -4
  173. django_cfg/models/constance.py +25 -88
  174. django_cfg/models/database.py +9 -9
  175. django_cfg/models/drf.py +3 -36
  176. django_cfg/models/email.py +163 -0
  177. django_cfg/models/environment.py +276 -0
  178. django_cfg/models/limits.py +1 -1
  179. django_cfg/models/logging.py +366 -0
  180. django_cfg/models/revolution.py +41 -2
  181. django_cfg/models/security.py +125 -0
  182. django_cfg/models/services.py +1 -1
  183. django_cfg/modules/__init__.py +2 -56
  184. django_cfg/modules/base.py +78 -52
  185. django_cfg/modules/django_currency/service.py +2 -2
  186. django_cfg/modules/django_email.py +2 -2
  187. django_cfg/modules/django_health.py +267 -0
  188. django_cfg/modules/django_llm/llm/client.py +79 -17
  189. django_cfg/modules/django_llm/translator/translator.py +2 -2
  190. django_cfg/modules/django_logger.py +2 -2
  191. django_cfg/modules/django_ngrok.py +2 -2
  192. django_cfg/modules/django_tasks.py +68 -3
  193. django_cfg/modules/django_telegram.py +3 -3
  194. django_cfg/modules/django_twilio/sendgrid_service.py +2 -2
  195. django_cfg/modules/django_twilio/service.py +2 -2
  196. django_cfg/modules/django_twilio/simple_service.py +2 -2
  197. django_cfg/modules/django_twilio/twilio_service.py +2 -2
  198. django_cfg/modules/django_unfold/__init__.py +69 -0
  199. django_cfg/modules/{unfold → django_unfold}/callbacks.py +23 -22
  200. django_cfg/modules/django_unfold/dashboard.py +278 -0
  201. django_cfg/modules/django_unfold/icons/README.md +145 -0
  202. django_cfg/modules/django_unfold/icons/__init__.py +12 -0
  203. django_cfg/modules/django_unfold/icons/constants.py +2851 -0
  204. django_cfg/modules/django_unfold/icons/generate_icons.py +486 -0
  205. django_cfg/modules/django_unfold/models/__init__.py +42 -0
  206. django_cfg/modules/django_unfold/models/config.py +601 -0
  207. django_cfg/modules/django_unfold/models/dashboard.py +206 -0
  208. django_cfg/modules/django_unfold/models/dropdown.py +40 -0
  209. django_cfg/modules/django_unfold/models/navigation.py +73 -0
  210. django_cfg/modules/django_unfold/models/tabs.py +25 -0
  211. django_cfg/modules/{unfold → django_unfold}/system_monitor.py +2 -2
  212. django_cfg/modules/django_unfold/utils.py +140 -0
  213. django_cfg/registry/__init__.py +23 -0
  214. django_cfg/registry/core.py +61 -0
  215. django_cfg/registry/exceptions.py +11 -0
  216. django_cfg/registry/modules.py +12 -0
  217. django_cfg/registry/services.py +26 -0
  218. django_cfg/registry/third_party.py +52 -0
  219. django_cfg/routing/__init__.py +19 -0
  220. django_cfg/routing/callbacks.py +198 -0
  221. django_cfg/routing/routers.py +48 -0
  222. django_cfg/templates/admin/layouts/dashboard_with_tabs.html +8 -9
  223. django_cfg/templatetags/__init__.py +0 -0
  224. django_cfg/templatetags/django_cfg.py +33 -0
  225. django_cfg/urls.py +33 -0
  226. django_cfg/utils/path_resolution.py +1 -1
  227. django_cfg/utils/smart_defaults.py +7 -61
  228. django_cfg/utils/toolkit.py +663 -0
  229. {django_cfg-1.1.82.dist-info → django_cfg-1.2.0.dist-info}/METADATA +83 -86
  230. django_cfg-1.2.0.dist-info/RECORD +441 -0
  231. django_cfg/archive/django_sample.zip +0 -0
  232. django_cfg/models/unfold.py +0 -271
  233. django_cfg/modules/unfold/__init__.py +0 -29
  234. django_cfg/modules/unfold/dashboard.py +0 -318
  235. django_cfg/pyproject.toml +0 -370
  236. django_cfg/routers.py +0 -83
  237. django_cfg-1.1.82.dist-info/RECORD +0 -278
  238. /django_cfg/{exceptions.py → core/exceptions.py} +0 -0
  239. /django_cfg/modules/{unfold → django_unfold}/models.py +0 -0
  240. /django_cfg/modules/{unfold → django_unfold}/tailwind.py +0 -0
  241. /django_cfg/{version_check.py → utils/version_check.py} +0 -0
  242. {django_cfg-1.1.82.dist-info → django_cfg-1.2.0.dist-info}/WHEEL +0 -0
  243. {django_cfg-1.1.82.dist-info → django_cfg-1.2.0.dist-info}/entry_points.txt +0 -0
  244. {django_cfg-1.1.82.dist-info → django_cfg-1.2.0.dist-info}/licenses/LICENSE +0 -0
@@ -0,0 +1,286 @@
1
+ # Generated by Django 5.2.6 on 2025-09-20 16:57
2
+
3
+ import django.db.models.deletion
4
+ import uuid
5
+ from django.conf import settings
6
+ from django.db import migrations, models
7
+
8
+
9
+ class Migration(migrations.Migration):
10
+
11
+ initial = True
12
+
13
+ dependencies = [
14
+ ('auth', '0012_alter_user_first_name_max_length'),
15
+ migrations.swappable_dependency(settings.AUTH_USER_MODEL),
16
+ ]
17
+
18
+ operations = [
19
+ migrations.CreateModel(
20
+ name='AgentDefinition',
21
+ fields=[
22
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
23
+ ('name', models.CharField(db_index=True, max_length=100, unique=True)),
24
+ ('display_name', models.CharField(blank=True, max_length=200)),
25
+ ('description', models.TextField()),
26
+ ('instructions', models.TextField(help_text='System prompt for the agent')),
27
+ ('deps_type', models.CharField(help_text='Python class name for dependencies', max_length=100)),
28
+ ('output_type', models.CharField(help_text='Python class name for output', max_length=100)),
29
+ ('model', models.CharField(default='openai:gpt-4o-mini', max_length=100)),
30
+ ('timeout', models.PositiveIntegerField(default=300, help_text='Timeout in seconds')),
31
+ ('max_retries', models.PositiveIntegerField(default=3)),
32
+ ('enable_caching', models.BooleanField(default=True)),
33
+ ('tools_config', models.JSONField(blank=True, default=dict, help_text='Configuration for agent tools')),
34
+ ('is_active', models.BooleanField(db_index=True, default=True)),
35
+ ('is_public', models.BooleanField(default=False, help_text='Available to all users')),
36
+ ('category', models.CharField(blank=True, db_index=True, max_length=50)),
37
+ ('tags', models.JSONField(blank=True, default=list, help_text='List of tags')),
38
+ ('version', models.CharField(default='1.0.0', max_length=20)),
39
+ ('created_at', models.DateTimeField(auto_now_add=True)),
40
+ ('updated_at', models.DateTimeField(auto_now=True)),
41
+ ('usage_count', models.PositiveIntegerField(default=0)),
42
+ ('last_used_at', models.DateTimeField(blank=True, null=True)),
43
+ ('allowed_groups', models.ManyToManyField(blank=True, help_text='Groups allowed to use this agent', related_name='allowed_agents', to='auth.group')),
44
+ ('allowed_users', models.ManyToManyField(blank=True, help_text='Users allowed to use this agent', related_name='allowed_agents', to=settings.AUTH_USER_MODEL)),
45
+ ('created_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='created_agents', to=settings.AUTH_USER_MODEL)),
46
+ ],
47
+ options={
48
+ 'db_table': 'orchestrator_agent_definitions',
49
+ 'ordering': ['name'],
50
+ },
51
+ ),
52
+ migrations.CreateModel(
53
+ name='AgentExecution',
54
+ fields=[
55
+ ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
56
+ ('agent_name', models.CharField(db_index=True, max_length=100)),
57
+ ('status', models.CharField(choices=[('pending', 'Pending'), ('running', 'Running'), ('completed', 'Completed'), ('failed', 'Failed'), ('cancelled', 'Cancelled')], db_index=True, default='pending', max_length=20)),
58
+ ('input_prompt', models.TextField()),
59
+ ('output_data', models.JSONField(blank=True, null=True)),
60
+ ('error_message', models.TextField(blank=True)),
61
+ ('execution_time', models.FloatField(blank=True, help_text='Execution time in seconds', null=True)),
62
+ ('tokens_used', models.IntegerField(default=0)),
63
+ ('cost', models.DecimalField(decimal_places=6, default=0, max_digits=10)),
64
+ ('cached', models.BooleanField(default=False)),
65
+ ('execution_order', models.PositiveIntegerField(default=0)),
66
+ ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
67
+ ('started_at', models.DateTimeField(blank=True, null=True)),
68
+ ('completed_at', models.DateTimeField(blank=True, null=True)),
69
+ ('agent_definition', models.ForeignKey(blank=True, help_text='Agent definition used for this execution', null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='executions', to='django_cfg_agents.agentdefinition')),
70
+ ('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
71
+ ],
72
+ options={
73
+ 'db_table': 'orchestrator_agent_executions',
74
+ 'ordering': ['-created_at'],
75
+ },
76
+ ),
77
+ migrations.CreateModel(
78
+ name='AgentTemplate',
79
+ fields=[
80
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
81
+ ('name', models.CharField(max_length=100, unique=True)),
82
+ ('description', models.TextField()),
83
+ ('template_config', models.JSONField(help_text='Template configuration')),
84
+ ('default_instructions', models.TextField()),
85
+ ('recommended_model', models.CharField(default='openai:gpt-4o-mini', max_length=100)),
86
+ ('category', models.CharField(db_index=True, max_length=50)),
87
+ ('use_cases', models.JSONField(default=list, help_text='List of use cases')),
88
+ ('created_at', models.DateTimeField(auto_now_add=True)),
89
+ ('updated_at', models.DateTimeField(auto_now=True)),
90
+ ('is_active', models.BooleanField(default=True)),
91
+ ('created_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
92
+ ],
93
+ options={
94
+ 'db_table': 'orchestrator_agent_templates',
95
+ 'ordering': ['category', 'name'],
96
+ },
97
+ ),
98
+ migrations.CreateModel(
99
+ name='ApprovalLog',
100
+ fields=[
101
+ ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
102
+ ('approval_id', models.CharField(db_index=True, max_length=100, unique=True)),
103
+ ('tool_name', models.CharField(max_length=100)),
104
+ ('tool_args', models.JSONField()),
105
+ ('justification', models.TextField(blank=True)),
106
+ ('status', models.CharField(choices=[('pending', 'Pending'), ('approved', 'Approved'), ('rejected', 'Rejected'), ('expired', 'Expired')], db_index=True, default='pending', max_length=20)),
107
+ ('rejection_reason', models.TextField(blank=True)),
108
+ ('requested_at', models.DateTimeField(auto_now_add=True)),
109
+ ('decided_at', models.DateTimeField(blank=True, null=True)),
110
+ ('expires_at', models.DateTimeField(blank=True, null=True)),
111
+ ('approved_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='approvals_given', to=settings.AUTH_USER_MODEL)),
112
+ ('rejected_by', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.SET_NULL, related_name='rejections_given', to=settings.AUTH_USER_MODEL)),
113
+ ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='approval_requests', to=settings.AUTH_USER_MODEL)),
114
+ ],
115
+ options={
116
+ 'db_table': 'orchestrator_approval_logs',
117
+ 'ordering': ['-requested_at'],
118
+ },
119
+ ),
120
+ migrations.CreateModel(
121
+ name='ToolExecution',
122
+ fields=[
123
+ ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
124
+ ('tool_name', models.CharField(db_index=True, max_length=100)),
125
+ ('toolset_name', models.CharField(blank=True, max_length=100)),
126
+ ('status', models.CharField(choices=[('pending', 'Pending'), ('running', 'Running'), ('completed', 'Completed'), ('failed', 'Failed')], db_index=True, default='pending', max_length=20)),
127
+ ('arguments', models.JSONField(help_text='Tool arguments')),
128
+ ('result', models.JSONField(blank=True, help_text='Tool execution result', null=True)),
129
+ ('error_message', models.TextField(blank=True)),
130
+ ('execution_time', models.FloatField(blank=True, null=True)),
131
+ ('retry_count', models.PositiveIntegerField(default=0)),
132
+ ('created_at', models.DateTimeField(auto_now_add=True)),
133
+ ('started_at', models.DateTimeField(blank=True, null=True)),
134
+ ('completed_at', models.DateTimeField(blank=True, null=True)),
135
+ ('agent_execution', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tool_executions', to='django_cfg_agents.agentexecution')),
136
+ ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
137
+ ],
138
+ options={
139
+ 'db_table': 'orchestrator_tool_executions',
140
+ 'ordering': ['-created_at'],
141
+ },
142
+ ),
143
+ migrations.CreateModel(
144
+ name='ToolPermission',
145
+ fields=[
146
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
147
+ ('tool_name', models.CharField(db_index=True, max_length=100)),
148
+ ('permission', models.CharField(choices=[('allow', 'Allow'), ('deny', 'Deny'), ('require_approval', 'Require Approval')], default='allow', max_length=20)),
149
+ ('conditions', models.JSONField(blank=True, default=dict, help_text='Conditions for permission (e.g., argument limits)')),
150
+ ('created_at', models.DateTimeField(auto_now_add=True)),
151
+ ('created_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='tool_permissions_created', to=settings.AUTH_USER_MODEL)),
152
+ ('user', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
153
+ ],
154
+ options={
155
+ 'db_table': 'orchestrator_tool_permissions',
156
+ },
157
+ ),
158
+ migrations.CreateModel(
159
+ name='ToolsetConfiguration',
160
+ fields=[
161
+ ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
162
+ ('name', models.CharField(max_length=100, unique=True)),
163
+ ('description', models.TextField()),
164
+ ('toolset_class', models.CharField(help_text='Python class path', max_length=200)),
165
+ ('config', models.JSONField(default=dict, help_text='Toolset configuration')),
166
+ ('is_active', models.BooleanField(default=True)),
167
+ ('created_at', models.DateTimeField(auto_now_add=True)),
168
+ ('updated_at', models.DateTimeField(auto_now=True)),
169
+ ('allowed_groups', models.ManyToManyField(blank=True, related_name='allowed_toolsets', to='auth.group')),
170
+ ('allowed_users', models.ManyToManyField(blank=True, related_name='allowed_toolsets', to=settings.AUTH_USER_MODEL)),
171
+ ('created_by', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
172
+ ],
173
+ options={
174
+ 'db_table': 'orchestrator_toolset_configurations',
175
+ 'ordering': ['name'],
176
+ },
177
+ ),
178
+ migrations.CreateModel(
179
+ name='WorkflowExecution',
180
+ fields=[
181
+ ('id', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)),
182
+ ('name', models.CharField(blank=True, max_length=200)),
183
+ ('pattern', models.CharField(choices=[('sequential', 'Sequential'), ('parallel', 'Parallel'), ('conditional', 'Conditional'), ('custom', 'Custom')], default='sequential', max_length=20)),
184
+ ('agent_names', models.JSONField(help_text='List of agent names in execution order')),
185
+ ('input_prompt', models.TextField()),
186
+ ('status', models.CharField(choices=[('pending', 'Pending'), ('running', 'Running'), ('completed', 'Completed'), ('failed', 'Failed'), ('cancelled', 'Cancelled'), ('paused', 'Paused')], db_index=True, default='pending', max_length=20)),
187
+ ('current_step', models.PositiveIntegerField(default=0)),
188
+ ('total_steps', models.PositiveIntegerField(default=0)),
189
+ ('config', models.JSONField(blank=True, default=dict, help_text='Workflow configuration')),
190
+ ('final_output', models.JSONField(blank=True, null=True)),
191
+ ('error_message', models.TextField(blank=True)),
192
+ ('total_execution_time', models.FloatField(blank=True, null=True)),
193
+ ('total_tokens_used', models.IntegerField(default=0)),
194
+ ('total_cost', models.DecimalField(decimal_places=6, default=0, max_digits=10)),
195
+ ('created_at', models.DateTimeField(auto_now_add=True, db_index=True)),
196
+ ('started_at', models.DateTimeField(blank=True, null=True)),
197
+ ('completed_at', models.DateTimeField(blank=True, null=True)),
198
+ ('user', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL)),
199
+ ],
200
+ options={
201
+ 'db_table': 'orchestrator_workflow_executions',
202
+ 'ordering': ['-created_at'],
203
+ },
204
+ ),
205
+ migrations.AddField(
206
+ model_name='agentexecution',
207
+ name='workflow_execution',
208
+ field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='agent_executions', to='django_cfg_agents.workflowexecution'),
209
+ ),
210
+ migrations.AddIndex(
211
+ model_name='agentdefinition',
212
+ index=models.Index(fields=['is_active', 'category'], name='orchestrato_is_acti_f9af43_idx'),
213
+ ),
214
+ migrations.AddIndex(
215
+ model_name='agentdefinition',
216
+ index=models.Index(fields=['created_by', '-created_at'], name='orchestrato_created_718e45_idx'),
217
+ ),
218
+ migrations.AddIndex(
219
+ model_name='agentdefinition',
220
+ index=models.Index(fields=['-usage_count'], name='orchestrato_usage_c_334175_idx'),
221
+ ),
222
+ migrations.AddIndex(
223
+ model_name='approvallog',
224
+ index=models.Index(fields=['status', 'requested_at'], name='orchestrato_status_8a3b00_idx'),
225
+ ),
226
+ migrations.AddIndex(
227
+ model_name='approvallog',
228
+ index=models.Index(fields=['user', '-requested_at'], name='orchestrato_user_id_5e6a95_idx'),
229
+ ),
230
+ migrations.AddIndex(
231
+ model_name='approvallog',
232
+ index=models.Index(fields=['approved_by', '-decided_at'], name='orchestrato_approve_c60dbe_idx'),
233
+ ),
234
+ migrations.AddIndex(
235
+ model_name='toolexecution',
236
+ index=models.Index(fields=['tool_name', 'status'], name='orchestrato_tool_na_1408d7_idx'),
237
+ ),
238
+ migrations.AddIndex(
239
+ model_name='toolexecution',
240
+ index=models.Index(fields=['user', '-created_at'], name='orchestrato_user_id_189593_idx'),
241
+ ),
242
+ migrations.AddIndex(
243
+ model_name='toolexecution',
244
+ index=models.Index(fields=['agent_execution', 'created_at'], name='orchestrato_agent_e_e6203f_idx'),
245
+ ),
246
+ migrations.AddIndex(
247
+ model_name='toolpermission',
248
+ index=models.Index(fields=['user', 'tool_name'], name='orchestrato_user_id_bb2dd9_idx'),
249
+ ),
250
+ migrations.AddIndex(
251
+ model_name='toolpermission',
252
+ index=models.Index(fields=['tool_name', 'permission'], name='orchestrato_tool_na_c47a6e_idx'),
253
+ ),
254
+ migrations.AlterUniqueTogether(
255
+ name='toolpermission',
256
+ unique_together={('user', 'tool_name')},
257
+ ),
258
+ migrations.AddIndex(
259
+ model_name='workflowexecution',
260
+ index=models.Index(fields=['status', 'created_at'], name='orchestrato_status_52c411_idx'),
261
+ ),
262
+ migrations.AddIndex(
263
+ model_name='workflowexecution',
264
+ index=models.Index(fields=['user', '-created_at'], name='orchestrato_user_id_daaa84_idx'),
265
+ ),
266
+ migrations.AddIndex(
267
+ model_name='workflowexecution',
268
+ index=models.Index(fields=['pattern', 'status'], name='orchestrato_pattern_dd9e33_idx'),
269
+ ),
270
+ migrations.AddIndex(
271
+ model_name='agentexecution',
272
+ index=models.Index(fields=['status', 'created_at'], name='orchestrato_status_a92529_idx'),
273
+ ),
274
+ migrations.AddIndex(
275
+ model_name='agentexecution',
276
+ index=models.Index(fields=['agent_name', 'user'], name='orchestrato_agent_n_741302_idx'),
277
+ ),
278
+ migrations.AddIndex(
279
+ model_name='agentexecution',
280
+ index=models.Index(fields=['user', '-created_at'], name='orchestrato_user_id_cd3699_idx'),
281
+ ),
282
+ migrations.AddIndex(
283
+ model_name='agentexecution',
284
+ index=models.Index(fields=['workflow_execution', 'execution_order'], name='orchestrato_workflo_d227b5_idx'),
285
+ ),
286
+ ]
@@ -0,0 +1,5 @@
1
+ """
2
+ Knowledge Base Migrations
3
+
4
+ Database migrations for the knowledge base application.
5
+ """
@@ -0,0 +1,15 @@
1
+ """
2
+ Django models for Django Orchestrator persistence.
3
+ """
4
+
5
+ from .execution import AgentExecution, WorkflowExecution
6
+ from .registry import AgentDefinition
7
+ from .toolsets import ToolExecution, ApprovalLog
8
+
9
+ __all__ = [
10
+ "AgentExecution",
11
+ "WorkflowExecution",
12
+ "AgentDefinition",
13
+ "ToolExecution",
14
+ "ApprovalLog",
15
+ ]
@@ -0,0 +1,215 @@
1
+ """
2
+ Django models for tracking agent and workflow executions.
3
+ """
4
+
5
+ import uuid
6
+ from django.db import models
7
+ from django.conf import settings
8
+ from django.utils import timezone
9
+
10
+
11
+ class AgentExecution(models.Model):
12
+ """Track individual agent executions."""
13
+
14
+ class Status(models.TextChoices):
15
+ PENDING = 'pending', 'Pending'
16
+ RUNNING = 'running', 'Running'
17
+ COMPLETED = 'completed', 'Completed'
18
+ FAILED = 'failed', 'Failed'
19
+ CANCELLED = 'cancelled', 'Cancelled'
20
+
21
+ id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
22
+ agent_name = models.CharField(max_length=100, db_index=True)
23
+ agent_definition = models.ForeignKey(
24
+ 'django_cfg_agents.AgentDefinition',
25
+ on_delete=models.SET_NULL,
26
+ null=True,
27
+ blank=True,
28
+ related_name='executions',
29
+ help_text="Agent definition used for this execution"
30
+ )
31
+ user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True, blank=True)
32
+
33
+ # Execution data
34
+ status = models.CharField(
35
+ max_length=20,
36
+ choices=Status.choices,
37
+ default=Status.PENDING,
38
+ db_index=True
39
+ )
40
+ input_prompt = models.TextField()
41
+ output_data = models.JSONField(null=True, blank=True)
42
+ error_message = models.TextField(blank=True)
43
+
44
+ # Metrics
45
+ execution_time = models.FloatField(null=True, blank=True, help_text="Execution time in seconds")
46
+ tokens_used = models.IntegerField(default=0)
47
+ cost = models.DecimalField(max_digits=10, decimal_places=6, default=0)
48
+ cached = models.BooleanField(default=False)
49
+
50
+ # Workflow context
51
+ workflow_execution = models.ForeignKey(
52
+ 'WorkflowExecution',
53
+ on_delete=models.CASCADE,
54
+ null=True,
55
+ blank=True,
56
+ related_name='agent_executions'
57
+ )
58
+ execution_order = models.PositiveIntegerField(default=0)
59
+
60
+ # Timestamps
61
+ created_at = models.DateTimeField(auto_now_add=True, db_index=True)
62
+ started_at = models.DateTimeField(null=True, blank=True)
63
+ completed_at = models.DateTimeField(null=True, blank=True)
64
+
65
+ # Custom managers
66
+ from ..managers.execution import AgentExecutionManager
67
+ objects = AgentExecutionManager()
68
+
69
+ class Meta:
70
+ db_table = 'orchestrator_agent_executions'
71
+ indexes = [
72
+ models.Index(fields=['status', 'created_at']),
73
+ models.Index(fields=['agent_name', 'user']),
74
+ models.Index(fields=['user', '-created_at']),
75
+ models.Index(fields=['workflow_execution', 'execution_order']),
76
+ ]
77
+ ordering = ['-created_at']
78
+
79
+ def __str__(self):
80
+ return f"AgentExecution({self.agent_name}, {self.status})"
81
+
82
+ def save(self, *args, **kwargs):
83
+ # Auto-set timestamps based on status
84
+ if self.status == self.Status.RUNNING and not self.started_at:
85
+ self.started_at = timezone.now()
86
+ elif self.status in [self.Status.COMPLETED, self.Status.FAILED] and not self.completed_at:
87
+ self.completed_at = timezone.now()
88
+
89
+ super().save(*args, **kwargs)
90
+
91
+ @property
92
+ def duration(self):
93
+ """Calculate execution duration."""
94
+ if self.started_at and self.completed_at:
95
+ return (self.completed_at - self.started_at).total_seconds()
96
+ return None
97
+
98
+ @property
99
+ def is_successful(self):
100
+ """Check if execution was successful."""
101
+ return self.status == self.Status.COMPLETED and not self.error_message
102
+
103
+
104
+ class WorkflowExecution(models.Model):
105
+ """Track multi-agent workflow executions."""
106
+
107
+ class Status(models.TextChoices):
108
+ PENDING = 'pending', 'Pending'
109
+ RUNNING = 'running', 'Running'
110
+ COMPLETED = 'completed', 'Completed'
111
+ FAILED = 'failed', 'Failed'
112
+ CANCELLED = 'cancelled', 'Cancelled'
113
+ PAUSED = 'paused', 'Paused'
114
+
115
+ class Pattern(models.TextChoices):
116
+ SEQUENTIAL = 'sequential', 'Sequential'
117
+ PARALLEL = 'parallel', 'Parallel'
118
+ CONDITIONAL = 'conditional', 'Conditional'
119
+ CUSTOM = 'custom', 'Custom'
120
+
121
+ id = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
122
+ name = models.CharField(max_length=200, blank=True)
123
+ user = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, null=True, blank=True)
124
+
125
+ # Workflow configuration
126
+ pattern = models.CharField(max_length=20, choices=Pattern.choices, default=Pattern.SEQUENTIAL)
127
+ agent_names = models.JSONField(help_text="List of agent names in execution order")
128
+ input_prompt = models.TextField()
129
+
130
+ # Execution state
131
+ status = models.CharField(
132
+ max_length=20,
133
+ choices=Status.choices,
134
+ default=Status.PENDING,
135
+ db_index=True
136
+ )
137
+ current_step = models.PositiveIntegerField(default=0)
138
+ total_steps = models.PositiveIntegerField(default=0)
139
+
140
+ # Configuration
141
+ config = models.JSONField(default=dict, blank=True, help_text="Workflow configuration")
142
+
143
+ # Results
144
+ final_output = models.JSONField(null=True, blank=True)
145
+ error_message = models.TextField(blank=True)
146
+
147
+ # Metrics
148
+ total_execution_time = models.FloatField(null=True, blank=True)
149
+ total_tokens_used = models.IntegerField(default=0)
150
+ total_cost = models.DecimalField(max_digits=10, decimal_places=6, default=0)
151
+
152
+ # Timestamps
153
+ created_at = models.DateTimeField(auto_now_add=True, db_index=True)
154
+ started_at = models.DateTimeField(null=True, blank=True)
155
+ completed_at = models.DateTimeField(null=True, blank=True)
156
+
157
+ # Custom managers
158
+ from ..managers.execution import WorkflowExecutionManager
159
+ objects = WorkflowExecutionManager()
160
+
161
+ class Meta:
162
+ db_table = 'orchestrator_workflow_executions'
163
+ indexes = [
164
+ models.Index(fields=['status', 'created_at']),
165
+ models.Index(fields=['user', '-created_at']),
166
+ models.Index(fields=['pattern', 'status']),
167
+ ]
168
+ ordering = ['-created_at']
169
+
170
+ def __str__(self):
171
+ return f"WorkflowExecution({self.name or self.id}, {self.status})"
172
+
173
+ def save(self, *args, **kwargs):
174
+ # Auto-set total_steps from agent_names
175
+ if self.agent_names:
176
+ self.total_steps = len(self.agent_names)
177
+
178
+ # Auto-set timestamps based on status
179
+ if self.status == self.Status.RUNNING and not self.started_at:
180
+ self.started_at = timezone.now()
181
+ elif self.status in [self.Status.COMPLETED, self.Status.FAILED] and not self.completed_at:
182
+ self.completed_at = timezone.now()
183
+
184
+ super().save(*args, **kwargs)
185
+
186
+ @property
187
+ def duration(self):
188
+ """Calculate workflow duration."""
189
+ if self.started_at and self.completed_at:
190
+ return (self.completed_at - self.started_at).total_seconds()
191
+ return None
192
+
193
+ @property
194
+ def progress_percentage(self):
195
+ """Calculate progress percentage."""
196
+ if self.total_steps == 0:
197
+ return 0
198
+ return (self.current_step / self.total_steps) * 100
199
+
200
+ @property
201
+ def is_successful(self):
202
+ """Check if workflow was successful."""
203
+ return self.status == self.Status.COMPLETED and not self.error_message
204
+
205
+ def get_agent_executions(self):
206
+ """Get related agent executions in order."""
207
+ return self.agent_executions.order_by('execution_order')
208
+
209
+ def get_successful_executions(self):
210
+ """Get successful agent executions."""
211
+ return self.agent_executions.filter(status=AgentExecution.Status.COMPLETED)
212
+
213
+ def get_failed_executions(self):
214
+ """Get failed agent executions."""
215
+ return self.agent_executions.filter(status=AgentExecution.Status.FAILED)