Altered Digital Migration

AI Features

AI transform fallback, content cleanup, and schema generation powered by a capability-first model registry.

Capability-first model registry

The AI service uses a capability-first model registry — each AI job is matched to the model best suited for it, with primary + fallback chains:

CapabilityPrimaryFallbacksUsed by
chatglm-5.2glm-5.1, claude-haiku-4-5Onboarding chat (future)
classifyqwen2.5:7b (local)glm-5.2Site analysis complexity
generatedeepseek-v4-proglm-5.2, claude-haiku-4-5Meta descriptions
jsondeepseek-v4-proglm-5.2, gpt-4o-miniQuotes, transforms, schema
visionclaude-haiku-4-5gpt-4o-mini, gemini-2.5-flashAlt text generation
codedeepseek-v4-proclaude-sonnet-4-6, gpt-4oSchema generation
long_contextgemini-2.5-proclaude-sonnet-4-6, gpt-4oLarge site analysis

Why glm-5.2 is excluded from vision: glm-5.2 doesn't handle images well. The vision capability deliberately routes to Claude Haiku / GPT-4o-mini / Gemini Flash instead — matching models to jobs.

AI Transform Fallback

When the deterministic page-builder parser returns confidence below 0.7, the Worker calls the AI service /api/transform route:

  1. The raw builder block (Elementor JSON, WPBakery shortcodes, etc.) is sent with the asset map and target schema.
  2. The json capability produces a Portable Text blocks array, validated against a Zod schema.
  3. On validation failure, the router auto-retries with a stricter prompt.
  4. If every model fails, a deterministic fallback wraps the raw block in a wpBlock (flagged aiFallback: true) so no content is lost.

Results are cached for 24 hours by content hash.

AI Content Cleanup

The /api/cleanup route handles three cleanup types:

Alt text generation

Filters documents with empty mainImage.alt, sends the image URL + page title to the vision capability, and generates concise alt text (max 125 chars). Returns patches that the Worker applies via patchDocument.

Meta descriptions

Filters documents with empty seo.metaDescription, sends the title to the generate capability, and produces a 155-char SEO meta description.

Slug cleanup

Non-ASCII or invalid slugs are transliterated deterministically (NFKD normalization + combining-mark stripping + a Latin transliteration map). No model call needed — this runs for free.

Trigger cleanup via the dashboard or the Worker /v2/cleanup route.

AI Schema Generation

The /api/schema-generate route proposes a complete Sanity Studio schema from your site analysis:

  1. The code capability (deepseek-v4 → claude-sonnet → gpt-4o) receives your post types, ACF field groups, taxonomies, and builder distribution.
  2. It returns an array of TypeScript files (one per document type + a blocks.ts for object types), each validated to contain defineType / defineField.
  3. If every model is unavailable, a deterministic scaffold is generated from the raw counts.

Preview, copy, or download the schema from Altered Digital → Schema Preview.

Cost & budget enforcement

Each AI call has a tier (local or cloud). Cloud calls bill against your tenant's AI budget (set when you pay upfront). When the budget is exhausted, the router downshifts to local-only models; if no local model applies, the route uses its deterministic fallback.

You can monitor AI spend in your Altered Digital dashboard.

On this page