From 13db471f8a32b5d2507374048b2384adda735e7d Mon Sep 17 00:00:00 2001 From: Nathaneil Flurry Date: Mon, 26 Oct 2026 08:11:52 +0000 Subject: [PATCH 1/3] docs(guides): add AI-generated app guide outlines --- .../guides/database-per-ai-generated-app.mdx | 40 ++++++++++++++++ .../content/guides/host-ai-generated-apps.mdx | 48 +++++++++++++++++++ docs/content/guides/self-modifying-agent.mdx | 47 ++++++++++++++++++ docs/sidebar.json | 24 ++++++++++ 4 files changed, 159 insertions(+) create mode 100644 docs/content/guides/database-per-ai-generated-app.mdx create mode 100644 docs/content/guides/host-ai-generated-apps.mdx create mode 100644 docs/content/guides/self-modifying-agent.mdx diff --git a/docs/content/guides/database-per-ai-generated-app.mdx b/docs/content/guides/database-per-ai-generated-app.mdx new file mode 100644 index 000000000..7236d155e --- /dev/null +++ b/docs/content/guides/database-per-ai-generated-app.mdx @@ -0,0 +1,40 @@ +--- +title: "Database per Generated App" +description: "Give every app your users generate its own SQLite database without provisioning a database for each one." +--- + + + +## TODO + +This page is not written yet. The outline below is what it will cover. + +### What we'll build + +- A generated app whose Actors store its data in SQLite, with tables the app defines in its own code. +- Migrations that run inside the Actor when it starts, so a new release can change the schema. +- A deploy step that ships only code, with no database to create, connect, or pay for per app. +- A way for your platform to read an app's data through the same Actor actions. + +### Similar tools + +This is the same job as Supabase for AI builders, Neon for AI agents with claimable Postgres, Turso with a database per app, or Convex for AI app builders. On Rivet the database is part of each app's Actors, so it exists as soon as the app gets its first request and needs no connection string. diff --git a/docs/content/guides/host-ai-generated-apps.mdx b/docs/content/guides/host-ai-generated-apps.mdx new file mode 100644 index 000000000..074faece1 --- /dev/null +++ b/docs/content/guides/host-ai-generated-apps.mdx @@ -0,0 +1,48 @@ +--- +title: "Host AI-Generated Apps" +description: "Deploy each app that your app builder generates as its own live app, with its own URL, backend, and data." +--- + + + +## TODO + +This page is not written yet. The outline below is what it will cover. + +### What we'll build + +- A `/generate` route that turns a user's prompt into an app's files and deploys them. +- A build and repair loop that sends build errors back to the model before anything goes live. +- One Dynamic App per user project, served from your own server at its own path. +- App Actors that give each project its own backend state and SQLite database. + +### Similar tools + +This is the same job as Vercel for Platforms with the v0 Platform API, Cloudflare Workers for Platforms, Freestyle, or Netlify. On Rivet the apps run inside your own server through a router you control, and each one comes with durable Actors instead of a separate database to set up. + +### Open questions + +- `appsRouter` serves each app under a path such as `/apps/:appId/`. Custom domains and wildcard subdomains per app are unverified. +- Dynamic Apps is in preview, and its API may change before general availability. diff --git a/docs/content/guides/self-modifying-agent.mdx b/docs/content/guides/self-modifying-agent.mdx new file mode 100644 index 000000000..f43620891 --- /dev/null +++ b/docs/content/guides/self-modifying-agent.mdx @@ -0,0 +1,47 @@ +--- +title: "Self-Modifying Agents" +description: "Build an agent that writes new tools for itself, deploys them as code, and uses them on its next turn without losing their data." +--- + + + +## TODO + +This page is not written yet. The outline below is what it will cover. + +### What we'll build + +- An agent with a tool that writes code for new tools and publishes it to the agent's own Dynamic App. +- A build and repair loop that sends build errors back to the model until the release compiles. +- App Actors that hold each tool's data, so it is still there after the next release. +- A tool list that the agent refreshes from its app before each turn, so new tools show up on the next turn. + +### Similar tools + +This is the same job as Cloudflare Dynamic Workers with Code Mode, Letta self-editing agents, or a Voyager-style skill library. On Rivet the generated tools run as a deployed app with their own durable Actors, so a tool can keep data between calls and across new versions of its code. + +### Open questions + +- Dynamic Apps is in preview, and its API may change. +- A failed build never replaces the active release. Rolling back to an earlier release that built but misbehaves is unverified. +- Actor state carries across releases only if the generated code migrates its own schema. Confirm how migrations run when a release changes the schema. diff --git a/docs/sidebar.json b/docs/sidebar.json index ea5d31216..bf76085e3 100644 --- a/docs/sidebar.json +++ b/docs/sidebar.json @@ -100,5 +100,29 @@ } ] } + ], + "guides": [ + { + "title": "AI-Generated Apps", + "pages": [ + { + "title": "Self-Modifying Agents", + "href": "/guides/self-modifying-agent" + }, + { + "title": "Host AI-Generated Apps", + "href": "/guides/host-ai-generated-apps" + } + ] + }, + { + "title": "Databases", + "pages": [ + { + "title": "Database per Generated App", + "href": "/guides/database-per-ai-generated-app" + } + ] + } ] } From a281861db03515be5a42916af6a0a1e53291ff6a Mon Sep 17 00:00:00 2001 From: Nathaneil Flurry Date: Mon, 26 Oct 2026 08:24:33 +0000 Subject: [PATCH 2/3] docs(guides): trim guides to the first set Amp-Thread-ID: https://ampcode.com/threads/T-701c2418-eebe-4bb7-b664-5b737970ed67 Co-authored-by: Amp --- .../guides/database-per-ai-generated-app.mdx | 40 ---------------- docs/content/guides/self-modifying-agent.mdx | 47 ------------------- docs/sidebar.json | 13 ----- 3 files changed, 100 deletions(-) delete mode 100644 docs/content/guides/database-per-ai-generated-app.mdx delete mode 100644 docs/content/guides/self-modifying-agent.mdx diff --git a/docs/content/guides/database-per-ai-generated-app.mdx b/docs/content/guides/database-per-ai-generated-app.mdx deleted file mode 100644 index 7236d155e..000000000 --- a/docs/content/guides/database-per-ai-generated-app.mdx +++ /dev/null @@ -1,40 +0,0 @@ ---- -title: "Database per Generated App" -description: "Give every app your users generate its own SQLite database without provisioning a database for each one." ---- - - - -## TODO - -This page is not written yet. The outline below is what it will cover. - -### What we'll build - -- A generated app whose Actors store its data in SQLite, with tables the app defines in its own code. -- Migrations that run inside the Actor when it starts, so a new release can change the schema. -- A deploy step that ships only code, with no database to create, connect, or pay for per app. -- A way for your platform to read an app's data through the same Actor actions. - -### Similar tools - -This is the same job as Supabase for AI builders, Neon for AI agents with claimable Postgres, Turso with a database per app, or Convex for AI app builders. On Rivet the database is part of each app's Actors, so it exists as soon as the app gets its first request and needs no connection string. diff --git a/docs/content/guides/self-modifying-agent.mdx b/docs/content/guides/self-modifying-agent.mdx deleted file mode 100644 index f43620891..000000000 --- a/docs/content/guides/self-modifying-agent.mdx +++ /dev/null @@ -1,47 +0,0 @@ ---- -title: "Self-Modifying Agents" -description: "Build an agent that writes new tools for itself, deploys them as code, and uses them on its next turn without losing their data." ---- - - - -## TODO - -This page is not written yet. The outline below is what it will cover. - -### What we'll build - -- An agent with a tool that writes code for new tools and publishes it to the agent's own Dynamic App. -- A build and repair loop that sends build errors back to the model until the release compiles. -- App Actors that hold each tool's data, so it is still there after the next release. -- A tool list that the agent refreshes from its app before each turn, so new tools show up on the next turn. - -### Similar tools - -This is the same job as Cloudflare Dynamic Workers with Code Mode, Letta self-editing agents, or a Voyager-style skill library. On Rivet the generated tools run as a deployed app with their own durable Actors, so a tool can keep data between calls and across new versions of its code. - -### Open questions - -- Dynamic Apps is in preview, and its API may change. -- A failed build never replaces the active release. Rolling back to an earlier release that built but misbehaves is unverified. -- Actor state carries across releases only if the generated code migrates its own schema. Confirm how migrations run when a release changes the schema. diff --git a/docs/sidebar.json b/docs/sidebar.json index bf76085e3..94c1e636d 100644 --- a/docs/sidebar.json +++ b/docs/sidebar.json @@ -105,24 +105,11 @@ { "title": "AI-Generated Apps", "pages": [ - { - "title": "Self-Modifying Agents", - "href": "/guides/self-modifying-agent" - }, { "title": "Host AI-Generated Apps", "href": "/guides/host-ai-generated-apps" } ] - }, - { - "title": "Databases", - "pages": [ - { - "title": "Database per Generated App", - "href": "/guides/database-per-ai-generated-app" - } - ] } ] } From cb5fd8224409f0bb388bbc4936a0c41f4246c60c Mon Sep 17 00:00:00 2001 From: Nathaneil Flurry Date: Mon, 26 Oct 2026 09:31:55 +0000 Subject: [PATCH 3/3] docs(guides): write host AI-generated apps guide --- .../content/guides/host-ai-generated-apps.mdx | 175 +++++++++++++++--- examples/apps-ai-builder/src/server.ts | 6 + 2 files changed, 156 insertions(+), 25 deletions(-) diff --git a/docs/content/guides/host-ai-generated-apps.mdx b/docs/content/guides/host-ai-generated-apps.mdx index 074faece1..3d5162ce2 100644 --- a/docs/content/guides/host-ai-generated-apps.mdx +++ b/docs/content/guides/host-ai-generated-apps.mdx @@ -3,46 +3,171 @@ title: "Host AI-Generated Apps" description: "Deploy each app that your app builder generates as its own live app, with its own URL, backend, and data." --- +import ExampleLinkBar from "@/components/docs/ExampleLinkBar.astro"; + + + -## TODO - -This page is not written yet. The outline below is what it will cover. +Your app builder turns each user's prompt into a running app, and your own server builds, deploys, and serves it. -### What we'll build +What we'll build: -- A `/generate` route that turns a user's prompt into an app's files and deploys them. +- A `/deploy/:name` route that turns a user's prompt into an app's files and deploys them. - A build and repair loop that sends build errors back to the model before anything goes live. - One Dynamic App per user project, served from your own server at its own path. - App Actors that give each project its own backend state and SQLite database. -### Similar tools + +Dynamic Apps is in preview and its API is subject to change. + + + + + + +Use Node.js 22: + +```sh +npm add @rivet-dev/dynamic-apps @ai-sdk/anthropic ai zod hono @hono/node-server +npm add --save-dev tsx +npm pkg set type=module +``` + + + + + +Set your model key. `AI_MODEL` is optional and defaults to `claude-sonnet-4-5`: + +```sh +ANTHROPIC_API_KEY=sk-ant-... +AI_MODEL=claude-sonnet-4-5 +``` + +In local development, Dynamic Apps connects to the local Rivet Engine, so there is nothing else to set. To deploy to Rivet Cloud, also set `RIVET_CLOUD_TOKEN`. See [Connect to Rivet](/dynamic-apps/docs/connect). + + + + + +The model starts from a small seed app and may only change a fixed list of files: + + + + + + +- `loadSeed` reads the seed from `fixtures/app/`. It's a Hono app that default-exports its fetch handler, which is the layout `deployApp` expects. Starting from files that already build gives the model less to get wrong. +- `validateFiles` keeps only the paths in `editablePaths` and rejects any file over 64 KiB. Anything else the model returns is dropped, so it can't add a lockfile, a config file, or a file outside the project. +- `maxRepairs` caps how many times a failed build goes back to the model. It's used in the deploy step. + + +Generated code is untrusted. Each app builds and runs in its own agentOS VM, but your server decides what the model may write and who may call the route that deploys it. Put authentication and rate limits in front of `/deploy/:name` before you expose it. + + + + + + +`revise` asks the model for the complete file tree. It writes the first version and fixes each failed build: + + + +- `generateObject` with `filesSchema` makes the model return a map from path to file contents, so there is no code to cut out of a chat reply. +- `webServerSkill` and `rivetActorsSkill` come from `@rivet-dev/dynamic-apps`. They give the model a starter project that builds and the rules for serving it, such as exporting a fetch handler instead of opening a port. With `rivetActorsSkill` the model can add Rivet Actors for state that lasts. See [Generate](/dynamic-apps/docs/generate). +- The prompt always includes the current files. On a repair it also includes the diagnostics from the failed build, so the model edits what it wrote instead of starting over. + + + + + +`generateApp` deploys the files and loops until a build succeeds: + + + +- `deployApp` installs dependencies and runs `npm run build` in a sandboxed build VM. When the build fails, it rejects with an error whose `code` starts with `dynamic_apps_` and whose `metadata` holds the compiler output. +- Only errors with a `dynamic_apps_` code go back to the model, such as a failed build or a missing entrypoint. Any other error is thrown right away. After `maxRepairs` failed attempts the last error is thrown too. +- The diagnostics are capped at 16 KiB so a long compiler log doesn't fill the prompt. +- A failed build never replaces the active release. Visitors keep the last working version until a new one builds. See [Deploy](/dynamic-apps/docs/deploy). +- `appId` is the project name from the URL. Deploying the same name again replaces that project's app, and each name gets its own Rivet namespace for its Actors and data. + + + + + +The server has a route that deploys apps and a router that serves them: + + + +- `POST /deploy/:name` checks that the prompt is a string of at most 4,000 characters, then returns what `deployApp` returns: the app's release, endpoint, namespace, pool, and a token when one is needed. +- `server.route("/apps", appsRouter)` serves every app under its own path. A request to `/apps/team-board/api/items` reaches the `team-board` app's fetch handler as `/api/items`. See [Route](/dynamic-apps/docs/routing). +- `/api/rivet/*` is a private callback that lets Rivet reach your server to manage deployments. Forward it to `appsRouter` as shown. +- Requests run in a cached agentOS VM inside the same process, so there is no extra network hop between your server and the app. + + +This example serves apps by path, such as `/apps/:name/`. This guide does not cover custom domains or a subdomain per app. + + + + + + +Start the server: + +```sh +npx tsx src/server.ts +``` + +Ask for an app: + +```sh +curl -X POST http://localhost:3000/deploy/team-board \ + -H "content-type: application/json" \ + -d '{"prompt":"Build a team board where people post ideas and vote on them."}' +``` + +The request returns after the app is built and live. Then open `http://localhost:3000/apps/team-board/`. Send another prompt to the same name to replace it with a new version. + + + + + +## Next steps -This is the same job as Vercel for Platforms with the v0 Platform API, Cloudflare Workers for Platforms, Freestyle, or Netlify. On Rivet the apps run inside your own server through a router you control, and each one comes with durable Actors instead of a separate database to set up. +- [SQLite](/dynamic-apps/docs/sqlite): connect to a generated app's Actors from your own code. +- [Multiplayer](/dynamic-apps/docs/multiplayer): build apps where many users share live state. +- [Workflows](/dynamic-apps/docs/workflows): run long, multi-step jobs inside a generated app. +- [Frontends & Static Sites](/dynamic-apps/docs/static-websites): add `public/index.html` to `editablePaths` and the seed so the model can write a frontend. +- [Authentication](/dynamic-apps/docs/authentication): add middleware that checks who can open each app. +- [Collecting Logs](/dynamic-apps/docs/logging): see build and runtime logs from generated apps. -### Open questions +## Related docs -- `appsRouter` serves each app under a path such as `/apps/:appId/`. Custom domains and wildcard subdomains per app are unverified. -- Dynamic Apps is in preview, and its API may change before general availability. +- [Generate](/dynamic-apps/docs/generate): the skills and the file schema. +- [Deploy](/dynamic-apps/docs/deploy): bundle requirements and the repair loop. +- [Route](/dynamic-apps/docs/routing): how `appsRouter` maps paths to apps. +- [Architecture](/dynamic-apps/docs/architecture): how builds and requests run in agentOS VMs. diff --git a/examples/apps-ai-builder/src/server.ts b/examples/apps-ai-builder/src/server.ts index 0959d72ed..bfa503933 100644 --- a/examples/apps-ai-builder/src/server.ts +++ b/examples/apps-ai-builder/src/server.ts @@ -11,6 +11,7 @@ import { generateObject } from "ai"; import { Hono } from "hono"; import { z } from "zod"; +// docs:start limits const editablePaths = [ "package.json", "tsconfig.json", @@ -46,6 +47,7 @@ function validateFiles(value: Record): Record { } return files; } +// docs:end limits // docs:start generate async function revise( @@ -73,6 +75,7 @@ async function revise( } // docs:end generate +// docs:start deploy async function generateApp(appId: string, prompt: string) { let files = await revise(prompt, await loadSeed()); for (let attempt = 0; attempt <= maxRepairs; attempt += 1) { @@ -106,7 +109,9 @@ async function generateApp(appId: string, prompt: string) { } throw new Error("unreachable"); } +// docs:end deploy +// docs:start routes const server = new Hono(); server.all("/api/rivet/*", (c) => appsRouter.fetch(c.req.raw)); @@ -126,6 +131,7 @@ server.post("/deploy/:name", async (context) => { ); }); server.route("/apps", appsRouter); +// docs:end routes serve({ fetch: server.fetch,