Add image assets embeddable in artifact content

Agents can now put images inside markdown/HTML artifacts instead of only
posting them as standalone artifacts.

- New Asset model: an image uploaded ahead of the artifact that embeds it.
- POST /api/assets uploads an image (image/* only, 50 MB cap) and returns
  a stable URL the agent references normally, e.g. ![chart](url). No custom
  syntax; existing markdown/fragment rendering handles it.
- GET /assets/{id} serves the image, owner-scoped (404 for other users).
- On artifact creation the content is scanned for asset URLs and matching
  assets are attached to it, so the image dies with the artifact it belongs
  to. Uploads never referenced are swept after a 24h grace period.
- Quota: assets count toward the owner's quota at upload time and can
  trigger eviction; evicting an artifact frees its assets too, and usage
  now sums artifacts plus assets.
- daybook_post.py gains --upload-image, which prints the URL to embed.
- Docs and SKILL.md cover the upload-then-reference workflow.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
ritte 2026-07-24 12:24:51 +02:00
parent 13f728bcd6
commit bf8d1fe244
9 changed files with 316 additions and 10 deletions

View file

@ -78,3 +78,28 @@ class UserProfile(models.Model):
def __str__(self):
return f"{self.user} quota={self.quota_bytes}"
class Asset(models.Model):
"""An image uploaded for embedding inside an artifact's content.
Uploaded before the artifact exists, so `artifact` is null until the
artifact referencing its URL is created. Unattached assets are swept
after ASSET_ORPHAN_GRACE; attached ones die with their artifact.
"""
id = models.CharField(max_length=12, primary_key=True)
owner = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE, related_name="assets")
artifact = models.ForeignKey(
Artifact, on_delete=models.CASCADE, related_name="assets", null=True, blank=True
)
path = models.CharField(max_length=500)
content_type = models.CharField(max_length=100)
size_bytes = models.BigIntegerField(default=0)
created_at = models.DateTimeField(auto_now_add=True)
class Meta:
ordering = ["-created_at"]
def __str__(self):
return f"{self.id} ({self.content_type})"