# Generated by Django 5.2 on 2025-04-20 11:08

import django.contrib.postgres.fields
import django.db.models.deletion
import pgvector.django.indexes
import pgvector.django.vector
from django.conf import settings
from django.db import migrations, models
from pgvector.django import VectorExtension


class Migration(migrations.Migration):

    initial = True

    dependencies = [
        migrations.swappable_dependency(settings.AUTH_USER_MODEL),
    ]

    operations = [
        VectorExtension(),
        migrations.CreateModel(
            name="Agent",
            fields=[
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "name",
                    models.CharField(max_length=255, primary_key=True, serialize=False, unique=True),
                ),
                ("description", models.TextField(blank=True, null=True)),
                ("is_active", models.BooleanField(default=True)),
            ],
            options={
                "verbose_name": "agent",
                "verbose_name_plural": "agents",
            },
        ),
        migrations.CreateModel(
            name="Document",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("name", models.CharField(max_length=255)),
                ("source", models.CharField(blank=True, max_length=255, null=True)),
                ("url", models.CharField(blank=True, max_length=255, null=True)),
                ("content", models.TextField()),
                ("metadata", models.JSONField(blank=True, null=True)),
            ],
        ),
        migrations.CreateModel(
            name="Guardrail",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("name", models.CharField(max_length=255)),
                ("is_input_enabled", models.BooleanField(default=True)),
                ("is_output_enabled", models.BooleanField(default=True)),
                ("configuration", models.JSONField(blank=True, default=dict)),
                ("is_active", models.BooleanField(default=True)),
                (
                    "description",
                    models.TextField(
                        blank=True,
                        help_text="A description of what this guardrail checks for",
                        null=True,
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="ModelProvider",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "provider",
                    models.CharField(
                        choices=[
                            ("OPENAI", "Openai"),
                            ("ANTHROPIC", "Anthropic"),
                            ("GEMINI", "Gemini"),
                            ("GROQ", "Groq"),
                            ("GROK", "Grok"),
                            ("MISTRAL", "Mistral"),
                        ],
                        default="OPENAI",
                        max_length=100,
                    ),
                ),
                ("base_url", models.CharField(blank=True, max_length=255, null=True)),
                (
                    "api_key_variable",
                    models.CharField(blank=True, max_length=255, null=True),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="Prompt",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("name", models.CharField(max_length=55)),
                ("template", models.TextField()),
                (
                    "input_variables",
                    django.contrib.postgres.fields.ArrayField(
                        base_field=models.CharField(max_length=255),
                        blank=True,
                        default=list,
                        size=None,
                    ),
                ),
            ],
        ),
        migrations.CreateModel(
            name="Tool",
            fields=[
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "name",
                    models.CharField(max_length=255, primary_key=True, serialize=False, unique=True),
                ),
                ("description", models.TextField(blank=True, null=True)),
                ("is_active", models.BooleanField(default=True)),
                (
                    "parameters_schema",
                    models.JSONField(
                        default=dict,
                        help_text="JSON Schema defining the parameters this tool accepts",
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="Conversation",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                (
                    "title",
                    models.CharField(
                        blank=True,
                        default="New conversation",
                        max_length=255,
                        null=True,
                    ),
                ),
                ("is_active", models.BooleanField(default=True)),
                (
                    "agent",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="conversations",
                        to="django_ai_agent.agent",
                    ),
                ),
                (
                    "user",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="agent_conversations",
                        to=settings.AUTH_USER_MODEL,
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.AddField(
            model_name="agent",
            name="documents",
            field=models.ManyToManyField(
                blank=True,
                related_name="agents",
                to="django_ai_agent.document",
            ),
        ),
        migrations.CreateModel(
            name="DocumentChunk",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("index", models.IntegerField(blank=True, null=True)),
                ("content", models.TextField()),
                ("metadata", models.JSONField(blank=True, null=True)),
                (
                    "document",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.PROTECT,
                        related_name="chunks",
                        to="django_ai_agent.document",
                    ),
                ),
            ],
        ),
        migrations.AddField(
            model_name="agent",
            name="guardrail",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.SET_NULL,
                related_name="agents",
                to="django_ai_agent.guardrail",
            ),
        ),
        migrations.CreateModel(
            name="Message",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("message_history", models.JSONField()),
                (
                    "conversation",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="messages",
                        to="django_ai_agent.conversation",
                    ),
                ),
            ],
            options={
                "abstract": False,
            },
        ),
        migrations.CreateModel(
            name="ModelSettings",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("model_name", models.CharField(blank=True, max_length=100, null=True)),
                ("temperature", models.FloatField(blank=True, null=True)),
                ("max_tokens", models.IntegerField(blank=True, null=True)),
                ("top_p", models.FloatField(blank=True, null=True)),
                ("frequency_penalty", models.FloatField(blank=True, null=True)),
                ("presence_penalty", models.FloatField(blank=True, null=True)),
                (
                    "provider",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.CASCADE,
                        related_name="model_settings",
                        to="django_ai_agent.modelprovider",
                    ),
                ),
            ],
            options={
                "verbose_name": "model settings",
                "verbose_name_plural": "model settings",
            },
        ),
        migrations.AddField(
            model_name="agent",
            name="model_settings",
            field=models.ForeignKey(
                on_delete=django.db.models.deletion.CASCADE,
                related_name="agents",
                to="django_ai_agent.modelsettings",
            ),
        ),
        migrations.AddField(
            model_name="agent",
            name="system_prompt",
            field=models.ForeignKey(
                blank=True,
                null=True,
                on_delete=django.db.models.deletion.CASCADE,
                related_name="agents",
                to="django_ai_agent.prompt",
            ),
        ),
        migrations.AddField(
            model_name="agent",
            name="tools",
            field=models.ManyToManyField(blank=True, related_name="agents", to="django_ai_agent.tool"),
        ),
        migrations.CreateModel(
            name="OpenAIEmbedding",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("model", models.CharField(blank=True, max_length=255, null=True)),
                (
                    "embedding",
                    pgvector.django.vector.VectorField(blank=True, dimensions=1536, null=True),
                ),
                (
                    "chunk",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.PROTECT,
                        to="django_ai_agent.documentchunk",
                    ),
                ),
            ],
            options={
                "indexes": [
                    pgvector.django.indexes.HnswIndex(
                        ef_construction=64,
                        fields=["embedding"],
                        m=16,
                        name="openai_l1536_vectors_index",
                        opclasses=["vector_cosine_ops"],
                    )
                ],
            },
        ),
        migrations.CreateModel(
            name="VoyageAIEmbedding",
            fields=[
                (
                    "id",
                    models.BigAutoField(
                        auto_created=True,
                        primary_key=True,
                        serialize=False,
                        verbose_name="ID",
                    ),
                ),
                ("created_at", models.DateTimeField(auto_now_add=True)),
                ("updated_at", models.DateTimeField(auto_now=True)),
                ("model", models.CharField(blank=True, max_length=255, null=True)),
                (
                    "embedding",
                    pgvector.django.vector.VectorField(blank=True, dimensions=1024, null=True),
                ),
                (
                    "chunk",
                    models.ForeignKey(
                        on_delete=django.db.models.deletion.PROTECT,
                        to="django_ai_agent.documentchunk",
                    ),
                ),
            ],
            options={
                "indexes": [
                    pgvector.django.indexes.HnswIndex(
                        ef_construction=64,
                        fields=["embedding"],
                        m=16,
                        name="voaygeai_l1024_vectors_index",
                        opclasses=["vector_cosine_ops"],
                    )
                ],
            },
        ),
    ]
