Sanity
AI editing for your Sanity site.
Avocado Studio puts an AI editor and a click-to-edit live preview on top of a site whose content lives in Sanity. Sanity stays your content store: Avocado reads from it, drafts on its own working copy, and publishes back only the fields that changed.
- Content store
- Sanity — a template and a working example are included
- Rich text
- Portable Text, read and written back
- Publishing
- Field-level patches, list items addressed by
_key - Images
- The editor’s image picker searches your Sanity assets
- Framework
- Next.js 15 or 16, App Router
- Licence
- Apache-2.0, free to self-host
Sanity stays the source of truth
A small adapter connects Avocado to your Sanity dataset. It is read when an editing session starts and written on publish; in between, drafts, undo history and the chat live in Avocado’s own SQLite working copy, so experiments never touch your dataset. Give the adapter a read token and it can read Sanity’s draft perspective too.
Integrating an existing Next.js site? Run npm create avocado-site@latest inside it — the Sanity template is one of the options.
Publish a diff, not a snapshot
Every CMS read is a projection: an asset reference flattened to a URL, a reference resolved to a link, rich text rendered to something editable. Writing that projection back would replace the reference with the flattening. So Avocado publishes a diff: only the fields that changed, as Sanity patches.
- List items are matched on their
_key, not their position, so a reorder elsewhere cannot land an edit on the wrong row. - Changes a field diff cannot express safely — a replaced image, a retyped link, an added or removed list item, a new block — are reported back to you instead of guessed.
import { diffPage, groupPatches } from "@avocadostudio-ai/site-sdk/publish"
// …diff the edited page against what Sanity held when you read it…
for (const { documentId, set } of groupPatches(diff.patches)) {
await client.patch(documentId).set(set).commit()
}Portable Text survives the round trip
Rich text converts from Portable Text into the editor’s document and back. Blocks with a custom _type that no converter knows ride through untouched, and when the previous value is passed in, an unchanged block is written back as the stored object itself — keys, annotations and custom fields preserved byte for byte. Sanity sees a diff of what actually changed, not “every block replaced”.
One documented gap: Portable Text has no horizontal rule, so a rule typed in the editor is dropped rather than faked as a paragraph of dashes.
Your Sanity media library in the editor
One helper, cmsMediaSource, gives the editor’s image picker a tab that searches your Sanity assets. The credentials stay on your server; the browser never talks to Sanity directly.
import { cmsMediaSource, type CmsAdapter } from "@avocadostudio-ai/site-sdk/server"
export function sanityAdapter(): CmsAdapter {
return {
id: "sanity",
getPages: (options) => getSanityPages(options?.perspective),
getMedia: cmsMediaSource({
provider: "sanity",
projectId: process.env.NEXT_PUBLIC_SANITY_PROJECT_ID!,
dataset: process.env.NEXT_PUBLIC_SANITY_DATASET,
token: process.env.SANITY_API_TOKEN,
}),
}
}FAQ
Sanity: common questions
Does Avocado Studio replace Sanity or Sanity Studio?
No. Sanity remains your CMS and your schema stays as it is. Avocado Studio reads your documents and writes changes back as patches; it adds an AI and visual editing layer on the website, not a new content store.
Is Avocado Studio made by Sanity?
No. Avocado Studio is an independent open-source project, licensed Apache-2.0, that works with Sanity through its API.
Will AI edits overwrite my Portable Text?
No. Publishing sends only changed fields, unchanged Portable Text blocks are written back exactly as stored, and custom block types pass through untouched.
Can editors change content without touching Sanity Studio?
Yes. They describe the change in chat or click the block on the page, review it in the live preview of the real site, and publish; the change lands in Sanity as a patch.
Which AI models does it use with Sanity?
Whichever you bring: an Anthropic, OpenAI or Google Gemini API key. Avocado runs on your key and never resells tokens.
Try it on a real site in one command.
Scaffold the demo site with the editor, or run it inside an existing Next.js project to wire Avocado Studio in. Open source under Apache-2.0; bring your own Anthropic, OpenAI or Gemini key.
npm create avocado-site@latest