feat: add AirShelf core implementation

This commit is contained in:
zyc
2026-06-05 10:21:40 +08:00
parent 2ba1058329
commit cfdcd84a30
252 changed files with 70828 additions and 0 deletions
@@ -0,0 +1,171 @@
# Generated by Django 5.1.15 on 2026-05-29 03:59
import django.db.models.deletion
import uuid
from django.conf import settings
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
]
operations = [
migrations.CreateModel(
name="ModelConfig",
fields=[
(
"id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
("name", models.CharField(max_length=128)),
("display_name", models.CharField(max_length=128)),
(
"capability",
models.CharField(
choices=[
("text", "Text"),
("image", "Image"),
("video", "Video"),
("vision", "Vision"),
("export", "Export"),
],
max_length=32,
),
),
("endpoint", models.CharField(blank=True, max_length=255)),
(
"unit_price",
models.DecimalField(decimal_places=4, default=0, max_digits=12),
),
(
"status",
models.CharField(
choices=[("active", "Active"), ("disabled", "Disabled")],
default="active",
max_length=24,
),
),
("rate_limit_per_minute", models.PositiveIntegerField(default=60)),
("metadata", models.JSONField(blank=True, default=dict)),
],
),
migrations.CreateModel(
name="ModelProvider",
fields=[
(
"id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
("name", models.CharField(max_length=64, unique=True)),
("display_name", models.CharField(max_length=128)),
(
"status",
models.CharField(
choices=[("active", "Active"), ("disabled", "Disabled")],
default="active",
max_length=24,
),
),
("base_url", models.URLField(blank=True)),
("metadata", models.JSONField(blank=True, default=dict)),
],
options={
"abstract": False,
},
),
migrations.CreateModel(
name="AITask",
fields=[
(
"id",
models.UUIDField(
default=uuid.uuid4,
editable=False,
primary_key=True,
serialize=False,
),
),
("created_at", models.DateTimeField(auto_now_add=True)),
("updated_at", models.DateTimeField(auto_now=True)),
(
"task_type",
models.CharField(
choices=[
("script_generation", "Script Generation"),
("script_optimization", "Script Optimization"),
("product_image", "Product Image"),
("person_image", "Person Image"),
("scene_image", "Scene Image"),
("storyboard", "Storyboard"),
("video_segment", "Video Segment"),
("export", "Export"),
],
max_length=48,
),
),
(
"status",
models.CharField(
choices=[
("created", "Created"),
("reserved", "Reserved"),
("submitted", "Submitted"),
("polling", "Polling"),
("postprocessing", "Postprocessing"),
("succeeded", "Succeeded"),
("failed", "Failed"),
("compensating", "Compensating"),
("cancelled", "Cancelled"),
],
default="created",
max_length=32,
),
),
("idempotency_key", models.CharField(max_length=128, unique=True)),
("provider_task_id", models.CharField(blank=True, max_length=255)),
("request_payload", models.JSONField(blank=True, default=dict)),
("response_payload", models.JSONField(blank=True, default=dict)),
(
"estimated_cost",
models.DecimalField(decimal_places=4, default=0, max_digits=12),
),
(
"actual_cost",
models.DecimalField(decimal_places=4, default=0, max_digits=12),
),
("error_code", models.CharField(blank=True, max_length=64)),
("error_message", models.TextField(blank=True)),
("submitted_at", models.DateTimeField(blank=True, null=True)),
("completed_at", models.DateTimeField(blank=True, null=True)),
(
"created_by",
models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="created_%(class)s_set",
to=settings.AUTH_USER_MODEL,
),
),
],
),
]
@@ -0,0 +1,78 @@
# Generated by Django 5.1.15 on 2026-05-29 03:59
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
("accounts", "0001_initial"),
("ai", "0001_initial"),
("projects", "0001_initial"),
]
operations = [
migrations.AddField(
model_name="aitask",
name="project",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="ai_tasks",
to="projects.project",
),
),
migrations.AddField(
model_name="aitask",
name="team",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="%(class)s_set",
to="accounts.team",
),
),
migrations.AddField(
model_name="aitask",
name="model_config",
field=models.ForeignKey(
on_delete=django.db.models.deletion.PROTECT,
related_name="tasks",
to="ai.modelconfig",
),
),
migrations.AddField(
model_name="modelconfig",
name="provider",
field=models.ForeignKey(
on_delete=django.db.models.deletion.CASCADE,
related_name="models",
to="ai.modelprovider",
),
),
migrations.AddIndex(
model_name="aitask",
index=models.Index(
fields=["team", "status"], name="ai_aitask_team_id_710ece_idx"
),
),
migrations.AddIndex(
model_name="aitask",
index=models.Index(
fields=["project", "task_type"], name="ai_aitask_project_f2850d_idx"
),
),
migrations.AddIndex(
model_name="aitask",
index=models.Index(
fields=["provider_task_id"], name="ai_aitask_provide_67beef_idx"
),
),
migrations.AlterUniqueTogether(
name="modelconfig",
unique_together={("provider", "name", "capability")},
),
]
@@ -0,0 +1 @@