# Generated by Django 5.2 on 2025-11-17 20:37

from django.db import migrations, models


def _set_default_model_prefixes(apps, schema_editor):
    LLMProvider = apps.get_model('api', 'LLMProvider')
    default_prefixes = {
        'openai': 'openai/',
        'openrouter': 'openrouter/',
        'anthropic': 'anthropic/',
        'fireworks': 'fireworks_ai/',
    }
    for key, prefix in default_prefixes.items():
        try:
            provider = LLMProvider.objects.filter(key=key).first()
            if provider and not provider.model_prefix:
                provider.model_prefix = prefix
                provider.save(update_fields=['model_prefix'])
        except Exception:
            # Best-effort; skip if provider is missing or the table has not been populated yet.
            continue


class Migration(migrations.Migration):

    dependencies = [
        ('api', '0187_persistentagentsystemmessagebroadcast'),
    ]

    operations = [
        migrations.AddField(
            model_name='llmprovider',
            name='model_prefix',
            field=models.CharField(blank=True, help_text="Optional prefix automatically added to model identifiers (e.g., 'openrouter/').", max_length=64),
        ),
        migrations.RunPython(_set_default_model_prefixes, migrations.RunPython.noop),
        migrations.AlterField(
            model_name='persistentagentsystemstep',
            name='code',
            field=models.CharField(choices=[('PROCESS_EVENTS', 'Process Events'), ('PEER_LINK_CREATED', 'Peer Link Created'), ('SNAPSHOT', 'Snapshot'), ('CREDENTIALS_PROVIDED', 'Credentials Provided'), ('CONTACTS_APPROVED', 'Contacts Approved'), ('LLM_CONFIGURATION_REQUIRED', 'LLM Configuration Required'), ('PROACTIVE_TRIGGER', 'Proactive Trigger'), ('SYSTEM_DIRECTIVE', 'System Directive')], max_length=64),
        ),
    ]
