Introducing a new way to review your PRs.

Read the announcement

frappe / builder

Craft beautiful websites effortlessly with an intuitive visual builder and publish them instantly

View on GitHub

20 documents · Updated Nov 23, 2026

docs / ai-assisted-building

AI-assisted building

AI-assisted building lets an engineer or site editor describe a page in chat and receive a live, editable Builder page. The system joins model setup, a durable chat session, a server-side agent, and the page draft so model output becomes checked page changes rather than untrusted text. It can edit the open page, prepare changes for other pages, propose new pages, connect forms to data, and add shared editor capabilities.

Authoring flow

The authoring flow starts in the Builder editor and ends in one or more draft states. The browser owns the conversation view and canvas view. The server owns the model turn, accepted page state, and changes that wait for approval.

flowchart LR
    A[User prompt] --> B[Chat session]
    B --> C[Selected model and effort]
    C --> D[Queued server turn]
    D --> E{Agent action}
    E -->|Read or research| D
    E -->|Edit open page| F[Server draft]
    E -->|Build page| G[Live page preview]
    G --> F
    E -->|Prepare other-page edit| H[Page change card]
    E -->|Propose new page or durable action| H
    E -->|Ask or request choice| I[Conversation card]
    I --> B
    F --> J[Canvas mirror]
    H --> K{User decision}
    K -->|Apply| L[Other-page drafts or new pages]
    K -->|Skip| M[No change]
    D --> N[Session transcript]

Prompt submission

The client sends one user turn with the open page, the selected model, optional block selection, editor theme, effort level, and attachments. It saves unsaved canvas work before submission, checks that the model can handle the request, and starts a background server job so a long stream does not hold the web request open. The turn returns an accepted status while progress travels over realtime events. See AI client experience for the browser interaction model.

An image or video attachment becomes one or more image inputs. Video becomes sampled frames because vision models read images more reliably than video. The server saves attached images as private site files so later turns can replay them without trusting a client-supplied file path.

References: builder/…/api.py• L28-114 builder/…/attachments.py• L18-153 frontend/…/attachments.ts• L45-169

Agent decision

The server agent reads the current page and recent session context, then chooses the smallest action that can satisfy the request. It can inspect the site, edit the open page, build a full page, prepare a cross-page change, ask a question, or request approval for a sensitive action. The AI agent runtime page describes the decision loop and tool boundaries.

The agent uses the site's actual pages, components, data schema, theme, scripts, images, and permitted web sources as context. A full page build starts only when the conversational agent calls the generation action. The call hands a focused brief to a heavier generation model, which returns to the same turn so the agent can review the result and make repairs before it finishes.

References: builder/…/loop.py• L1-42 builder/…/registry.py• L1-23 builder/…/query.py• L71-121 builder/…/artifact.py• L233-298

Realtime feedback

The server reports progress, streamed text and reasoning, tool activity, preview frames, questions, completion, and errors through realtime events. The open page is the event channel for in-editor chat. An off-screen build sends page updates to its target page but keeps its progress in the open chat.

The client turns these events into a timeline, a live build row, page change cards, conversation cards, and canvas updates. It groups repeated tool work so the timeline explains the turn without becoming an inventory. Repeated token work and edits prepared for several pages become one summary. Thinking text stays collapsed until the reader opens it, while an idle turn shows a small working state. Chat follows new output while the reader is at the bottom, but it stops forcing scroll when the reader moves up. Chat Markdown is sanitized and links open outside the editor.

The user can guide a running turn without starting a second turn. A note waits for the next agent round, or the user can ask the agent to stop its current model step and read the note at once. The turn keeps its rounds, tool activity, usage, stop reason, retries, and failures. Secret values are removed from that trace.

References: builder/…/loop.py• L13-43 builder/…/loop.py• L132-182 builder/…/session.py• L414-475 frontend/…/AITurnTimeline.vue• L1-63 frontend/…/AITurnTimeline.vue• L71-176 frontend/…/chatScroll.ts• L7-63 frontend/…/markdown.ts• L40-81

Model configuration

AI calls use enabled provider and model records rather than a fixed model list. Site administrators connect a provider and enable models with the capabilities needed by the authoring flow. The chat keeps the selected model and thinking effort with the session and turn.

Provider connections

A provider defines how its models are reached and how credentials are supplied. A connection can use a provider key, the shared site key, or no key for a local gateway. The setup flow checks a real model call before it saves the connection. Provider credentials stay on the server and are resolved again when the worker starts.

ChatGPT uses a separate sign-in path through the Codex service. The server adapts that service's streamed response format to the common model interface, so the agent and page writer do not need a separate authoring flow.

References: builder/…/codex.py• L1-9 builder/…/codex.py• L50-70 builder/…/llm.py• L209-240

Model catalogue

Each enabled model supplies a label, provider route, context size, and input capabilities. Vision support controls whether the turn may include attached images or page screenshots. Discovery keeps the normal model picker current, while an administrator can add a served model that discovery does not list.

The client uses the catalogue to show valid choices and connection state. The server checks the same facts again before it queues a turn, so a stale browser cannot start a request that the selected provider cannot serve.

References: builder/…/api.py• L81-91 builder/…/codex.py• L73-106 builder/…/llm.py• L105-148 frontend/…/commandMenu.ts• L47-73

Model routing

The selected model serves conversation and page generation through a shared model layer. That layer maps it to a provider, endpoint, and credential. It also hides provider-specific stream formats, request limits, retry rules, and safe user-facing error messages.

The system retries temporary transport and provider failures, but it does not retry fixed errors such as invalid credentials, unavailable models, or policy denials. The queued job carries the model and turn inputs, not a provider secret.

References: builder/…/llm.py• L24-79 builder/…/llm.py• L217-240 builder/…/api.py• L90-110 builder/…/codex.py• L122-171

Chat sessions

A chat session is the durable conversation for one user. It gives later turns enough history to refine a page, records pages the chat has used or changed, and allows several independent chats to exist on one page.

Session history

User and assistant messages are stored with the session. The agent replays a bounded set of useful turns and keeps durable action outcomes in context. Vision models can receive recent attached images again. Each user message records the page from which it was sent, so a session can move between pages without losing the meaning of “this page.”

The client reloads the transcript when it opens, switches, or finishes a chat. A page reopens the most recently used session that has real messages. A new chat stays blank until its first prompt.

References: builder/…/session.py• L26-106 builder/…/session.py• L118-137 builder/…/session.py• L243-304 builder/…/session.py• L306-338

Attached context

Canvas selection alone does not change request scope. The user must attach selected blocks, which sends their identity and labels with the turn. Attached images are permissioned site references for later turns and page generation. A vision-capable model receives only usable image sources.

Page generation can also receive exact photos found by image search and visual geometry from reference pages. The generation step keeps searched photo URLs exact, checks brief image URLs before provider use, and gives the first reference page priority when several pages were read. This keeps the generator tied to real site material instead of URLs or layout details that the conversational model may lose while it writes a brief.

References: builder/…/attachments.py• L46-79 builder/…/artifact.py• L32-109 builder/…/artifact.py• L115-165 builder/…/artifact.py• L255-283 builder/…/images.py• L96-129

Conversational cards

The agent can pause with a card for a question, a choice, a small form, an image choice, a color role, or a sensitive-action request. The frontend renders these cards from a small shared set of UI elements. The user's answer returns as an ordinary chat message, so the agent continues with the same context.

Answered cards remain as a compact record of the question and answer. Their plain-text form also gives the agent a clear replay record when a later turn needs to continue the conversation.

References: builder/…/conversation.py• L1-13 builder/…/conversation.py• L54-119 frontend/…/AIUISpec.vue• L1-18 frontend/…/AIUISpec.vue• L190-220

Running turn control

A session allows one active turn at a time. While it runs, the user can queue notes, send a note immediately, or cancel the turn. Notes that the loop reads become normal user messages, so later turns retain the new direction. Cancellation keeps accepted work and reports that the turn stopped instead of presenting a false completion.

References: builder/…/session.py• L414-475 builder/…/api.py• L53-57 builder/…/loop.py• L128-135

Agent capabilities

The agent works across the page, the site's design system, data, scripts, settings, images, web sources, and editor extensions through named tools. A tool declares whether it reads, changes the page, changes server state, ends the turn, or streams a page artifact. Tool availability can depend on the user, selected model, and loaded skill.

Page inspection

The agent receives the open page in a compact page language and can request more detail when needed. It can inspect blocks, reference pages, components, scripts, records, data schemas, images, and rendered pages. It can also read public web pages or ask a focused research helper for source-backed findings.

These reads ground an answer or build in the site's real content and design rules. They also keep the agent from treating an external page as an editable Builder page.

References: builder/…/query.py• L1-5 builder/…/query.py• L71-121 builder/…/python.py• L1-9 builder/…/web.py• L1-9

Page editing

Small changes use ordered page edit operations for content, styles, attributes, bindings, structure, and scripts. The server checks each operation against the current page before it accepts it. Edits to the open page apply during the turn. Edits to another page are checked and held for a page change card.

The server applies accepted page and script changes first, then mirrors them to the canvas. The browser is therefore a live view of the draft, not a second source of truth. Page settings and theme values use server actions. Data connections use the page's supported data path.

References: builder/…/blocks.py• L1-26 builder/…/edits.py• L17-51 builder/…/settings.py• L23-91 builder/…/settings.py• L110-163 builder/…/loop.py• L7-11

Full page generation

When the agent decides to build a complete page, it passes a focused brief to a dedicated generation step on the selected heavy model. That step streams page markup as readable preview frames, parses the final result into the Builder page shape, and saves the draft. The final accepted operation carries the expanded page tree back to the client so both sides share the same block identity.

The generator combines the brief with the session context, attached or searched images, and measured geometry from reference pages. It checks image sources that the provider must fetch and keeps the latest preview in a short-lived buffer so an editor that loads or refreshes during a build can recover the current view. The saved draft and final accepted operation remain authoritative.

References: builder/…/prompts.py• L124-147 builder/…/artifact.py• L66-109 builder/…/artifact.py• L136-165 builder/…/artifact.py• L186-243 builder/…/artifact.py• L255-348

Dynamic page content

Data-driven pages use a page data script to read records or outside feeds and expose named values. Blocks and repeaters bind to those values. Static lists remain editable page content. Live records use the data path so later record changes can appear without rebuilding the page.

The agent reads the real data schema before it writes a data script. It proposes a new data type or sample records through approval when the site has no suitable source. A public form uses a private submission data type, a guest-safe Web Form, and page wiring so visitors can submit without direct data access.

References: builder/…/data.py• L1-9 builder/…/data.py• L31-90 builder/…/forms.py• L1-13 builder/…/forms-and-data.md• L6-12

Visual review

The agent can render the draft at desktop, tablet, or mobile size and review readable screenshot tiles when the selected model supports vision. The review checks layout breakage, missing content, contrast in light and dark modes, responsive behavior, and signs of a repeated stock design. A missing screenshot service or a text-only model does not block the page build.

The same preview can study another page as a visual reference without treating its blocks as editable. A page build should use the review to fix narrow problems with page edits rather than regenerate the whole page. The authoring guidance also separates a site-matching build from a fresh design. A matching build follows the chosen reference page and its shared assets. A fresh build chooses a distinct direction and avoids reflex colors, fonts, and copy patterns unless the user asks for them.

References: builder/…/preview.py• L21-35 builder/…/preview.py• L104-159 builder/…/preview.py• L194-211 builder/…/preview.py• L251-338 builder/…/prompts.py• L151-160

Reusable components

The agent can promote a designed page section into a reusable Builder Component or edit an existing component definition. Extraction keeps the designed section as a shared instance. A component edit updates the definition and synchronizes pages that embed it, which gives shared headers, footers, and other site-wide sections one change path.

Shared component behavior is part of that contract. A page-specific instance can override its content or props, while a component-level change affects every embedded page. The agent uses the component's own scripts and declared props when it needs reusable behavior rather than rebuilding shared chrome on one page.

References: builder/…/components.py• L1-7 builder/…/components.py• L17-65 builder/…/components.py• L90-138 builder/…/components.md• L6-9

Protected actions

Actions that affect the whole site or create durable data do not apply when the model proposes them. The server stores the proposal, the client shows Apply and Skip, and a user-triggered confirmation call performs the write. This boundary covers the home page, global settings, new data types, sample data, form connections, and other durable writes that need explicit consent.

Publishing follows a separate rule: it applies only when the user asks to publish. The user's explicit publish request is the approval, while a proposed home-page change or other sensitive setup action remains pending until the user chooses Apply.

After the user decides, the outcome becomes part of the session. The system can then resume the plan without making the user type a second continuation request.

References: builder/…/pending.py• L1-85 builder/…/settings.py• L166-227 builder/…/api.py• L125-171 frontend/…/AIPageCard.vue• L79-90

Page change application

Generated and edited content reaches the page through a server-authoritative draft path. The canvas shows accepted server changes. It does not decide which model output is valid.

Targeted page edits

For an existing page, the agent applies accepted operations to a server working tree first. The server saves the draft after each round and emits only operations that passed page checks. The client replays those operations on the canvas, which keeps the visible editor aligned with the stored draft.

Edit scripts can add, remove, move, replace, or patch blocks. The same path reports failed operations back to the agent, so the agent can adjust a narrow change instead of silently claiming success.

References: builder/…/edits.py• L26-115 builder/…/blocks.py• L19-53 builder/…/loop.py• L90-114

Page change approval

Changes outside the working page use an approval boundary because another page may change before review. The agent checks each other-page edit against a temporary page state and proposes new pages with a title, route, and build brief. It does not save either kind during the proposing turn.

The client presents one card with selectable rows for proposed pages and other-page edits. Applying can create new pages and replay checked edits. Each page reports its own result. Approved new pages are built in later off-screen turns, one page at a time, while the chat stays attached to the page where the request began.

References: builder/…/api.py• L174-195 frontend/…/AIPageCard.vue• L21-90 frontend/…/pageChanges.ts• L1-87 frontend/…/AIPageBuild.vue• L1-49

Page scripts and settings

Page behavior belongs in attached page or component scripts. Page metadata belongs in page settings. Theme values belong in shared design tokens. The agent changes these through their server paths so published assets, page data, and the open editor can refresh from the saved state.

Site-wide code and the home page use the protected-action path because they affect every visitor. Page-level settings and design tokens remain ordinary server actions because they belong to the working page or its reversible design system. Publishing is an explicit user action that applies through the normal publish path rather than through the pending-action card.

References: builder/…/settings.py• L23-91 builder/…/settings.py• L110-163 builder/…/settings.py• L166-204 builder/…/settings.py• L224-227

Draft safety

AI edits remain draft changes until the normal Builder publish action moves them to the live site. The system keeps page application, approval, and recovery separate so a model cannot turn a conversational suggestion into an unreviewed site-wide write.

Edit snapshots

The first page mutation in a turn can create one pre-turn snapshot. It covers the page blocks, page data script, attached script links, and script contents. Revert restores those parts as one unit and removes that turn and later messages from the session.

Protected actions have their own Apply and Skip result. They are not hidden inside page Revert because they may create data types, records, forms, or site-wide settings.

References: builder/…/loop.py• L90-105 builder/…/session.py• L476-496 builder/…/pending.py• L44-75

Partial work

Cancellation keeps changes that already applied and ends the turn with an honest status. Round checkpoints make earlier work durable if a later provider call fails. Session and page locks prevent overlapping turns from silently overwriting one another. A temporary stream failure retries the round before it applies operations. A failed server tool rolls back its own write so the agent can adjust.

If a turn reaches its round limit, the system keeps completed work and tells the user to continue. A generation stream can leave a partial preview, but the saved draft and final accepted operation remain authoritative. A preview service failure only removes visual review; it does not erase the draft.

References: builder/…/loop.py• L70-87 builder/…/artifact.py• L299-323 builder/…/preview.py• L261-301 builder/…/session.py• L414-475

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep server realtime event names and payloads aligned with the client timeline, build row, card, and canvas handlers. A renamed event can leave the page updated while chat still appears to run.
  • Keep the server working-tree applier, accepted operation shapes, and frontend dispatcher aligned. Generated trees and targeted edits must replay with the same block references.
  • Keep attachment limits, saved-file metadata, provider image parts, session replay, and vision capability checks aligned. A new attachment kind must work in the browser, transcript, model request, and generation step.
  • Keep generation briefs, searched-photo results, reference geometry, streamed preview frames, saved page trees, and final operations aligned. The preview is temporary, but the saved tree is authoritative.
  • Keep model catalogue capability data aligned with provider routing, readiness checks, command-menu choices, and Codex model discovery. Vision and credential failures must occur before a turn starts.
  • Keep queued job arguments free of credentials. The request may validate a key, but the worker must resolve it again when the job starts.
  • Keep tool side, availability, skill loading, terminal behavior, artifact generation, and frontend activity labels aligned when adding a capability.
  • Keep page-card row keys, selected skip rows, per-page results, and off-screen build metadata aligned. A new page must be created before its later build targets it.
  • Keep approval action kinds aligned across pending payloads, confirmation endpoints, apply handlers, and client cards. A new durable write must not bypass user approval, while publishing must remain limited to an explicit user request.
  • Keep snapshot coverage aligned with every new page, data-script, or page-script mutation. Revert must not claim to restore a change it did not capture.
  • Keep session page membership, message page metadata, attachment replay, and resumed-build page targets aligned when a chat moves between pages.
  • Keep generic card element kinds, their plain-text replay, and the frontend renderer aligned. An unknown or empty control must not strand the user without an answer path.
  • Keep form field order, submission data type, Web Form mapping, and attached submit script aligned. A visible form must save the same fields that the approval card describes.

Important failure modes

TriggerConsequenceGuard
The selected model has no usable provider or keyThe turn cannot make a valid model callThe client and server check model readiness before queueing the job
A credential is included in a queued jobA secret can persist in queue data or logsThe worker resolves its own credential when it starts
An image or page screenshot is sent to a text-only modelThe provider rejects the requestVision capability is checked before queueing and before visual review
A second turn starts on the same sessionConcurrent work can conflict or be rejectedA session run lock allows one active turn at a time
A generation stream stops before the final resultThe canvas can show a partial pageThe stream buffer is temporary and the saved draft is restored as truth
A page changes after an other-page proposal is reviewedThe proposal can target stale block referencesApply replays checked operations against the current page and reports page-level failure
A user skips one row in a page change cardThat page stays unchanged while other rows can applyThe apply request carries skipped row keys and the server handles each page separately
A proposed route is already owned by another pageThe new page is not createdRoute ownership is checked again during apply
A sensitive action is proposed without confirmationGlobal settings, data, home-page, or form writes could change without consentPending actions persist an explicit kind and apply only from a user-triggered endpoint
A public form writes directly to a private data typeGuest users could bypass the intended submission boundaryThe form connection uses a guest-safe Web Form and keeps the submission type private
A later agent round fails after earlier editsA whole turn could lose useful workThe server checkpoints accepted rounds and keeps partial work
A server tool fails after starting a writeA failed tool could leave a partial changeThe tool runs under a savepoint and returns failure for agent correction
A page build targets the open page instead of its off-screen pageThe wrong canvas can show or save the buildBuild events target the working page while chat events target the open page
A card has no usable controlThe user cannot answer and the turn stallsThe server sanitizes card elements and rejects empty choice groups or cards
A preview renderer is unavailable or a model cannot view imagesVisual review is skippedThe draft remains authoritative and the turn continues with a clear unavailable result

Key files

FileWhy to read it
builder/…/api.pyDefines prompt submission, background turns, confirmation, page-change apply, and resumed builds.
builder/…/session.pyExplains durable transcripts, page membership, context replay, attachments, locks, notes, and revert history.
builder/…/loop.pyShows the server turn, realtime contract, checkpoints, retries, tool rounds, and server-authoritative draft flow.
builder/…/registry.pyDefines tool sides, availability, skills, and streamed artifact boundaries.
builder/…/artifact.pyShows how a full-page build uses references and images, streams a preview, and saves the final page tree.
builder/…/edits.pyShows how targeted page edit scripts become accepted page operations and useful failure reports.
builder/…/pending.pyDefines the confirmation boundary for global settings, data creation, forms, home-page changes, and other durable actions.
builder/…/query.pyShows how the agent reads the open page and reference pages before it edits or builds.
builder/…/data.pyShows how real records and schemas ground data-driven pages.
builder/…/forms.pyShows how a public form is connected to private submissions through approval.
builder/…/preview.pyShows how the agent checks a draft visually across viewports and themes without making screenshots a hard dependency.
builder/…/attachments.pyDefines attachment persistence, permission checks, replay, and provider image inputs.
builder/…/llm.pyDefines provider-neutral routing, effort levels, retry classes, and safe error messages.
builder/…/codex.pyDefines the ChatGPT subscription route and its streamed model interface.
builder/…/prompts.pyDefines the common page language, agent guidance, generation contract, and design safeguards.
builder/…/components.mdExplains shared component scope, instance overrides, props, and component behavior.
frontend/…/AITurnTimeline.vueShows how model thinking, tool activity, repeated work, and turn state appear to the user.
frontend/…/AIUISpec.vueShows the shared renderer for questions, choices, uploads, and small forms.
frontend/…/AIPageCard.vueShows the approval and result view for other-page edits and new pages.
frontend/…/AIPageBuild.vueShows how an approved off-screen page build appears in the open chat.
frontend/…/pageChanges.tsDefines page-card rows, selection, result mapping, and later build status.
docs/ai-agent-runtime.mdChild page for the server agent loop, tools, locks, and application rules.
docs/ai-client-experience.mdChild page for the chat panel, session controls, streaming feedback, and canvas experience.