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-client-experience

AI client experience

The AI client experience connects a builder user to the AI authoring flow. It gives the user a page-scoped chat panel, shows the progress and result of each turn, presents questions as usable UI, and reflects AI changes in the builder canvas and script editor. It also explains changes that span several pages before and after the user applies them. The server agent runtime owns the AI work; this client layer keeps the user’s view clear and current. See AI-assisted building for the full system and AI agent runtime for the server-side turn lifecycle.

Chat panel

The chat panel is the main user surface for AI page work. It lives beside the builder canvas as the Chat left-panel tab and supports new requests, page context, image and video input, model selection, prompt improvement, cancellation, chat history, and slash commands for AI setup.

Panel role

The frontend/…/BuilderAIChatPanel.vue panel presents the conversation and its current state without making the user inspect agent events. A new or empty page offers build prompts. A page with content offers edit prompts. The composer sends only blocks that the user explicitly attaches, so canvas selection does not silently change the request’s scope. Multi-page work appears as a compact proposal or build record inside the same conversation.

Chat messages use one shared markdown policy for model output. Plain-text web addresses become links, sanitized markdown links open in a new tab, and the renderer keeps repeated streamed content responsive without weakening the allowed HTML set.

The panel keeps chats tied to the active page. Users can start, switch, and delete several sessions for that page. A page switch clears transient turn state and attaches the client to the new page’s event stream. The transcript follows new output while the reader stays at the bottom, but it stops moving when the reader scrolls up to inspect earlier content.

References: frontend/…/BuilderAIChatPanel.vue• L1-27 frontend/…/BuilderAIChatPanel.vue• L56-111 frontend/…/BuilderAIChatPanel.vue• L191-237 frontend/…/BuilderAIChatPanel.vue• L254-403 frontend/…/BuilderAIChatPanel.vue• L783-837 frontend/…/markdown.ts• L6-13 frontend/…/markdown.ts• L21-49 frontend/…/chatScroll.ts• L7-63

Attachments

The composer prepares visual input before it sends a message. It accepts images and short videos, converts images to model-sized data when needed, and represents a video as evenly spaced image frames because the vision request consumes images. Sent messages retain attachment thumbnails and enough video identity to show the source as one chat attachment.

The client limits the number of images and videos per message. It rejects other file types, rejects videos that are too long, reports unreadable media, and removes failed attachments instead of sending incomplete input.

References: frontend/…/attachments.ts• L4-15 frontend/…/attachments.ts• L19-35 frontend/…/attachments.ts• L45-95 frontend/…/attachments.ts• L107-125 frontend/…/attachments.ts• L144-173

Command menu

The command menu turns the chat composer into a small command surface for AI account and model actions. Typing / opens the available commands. A command can open filtered lists, nested levels, or a field for a secret or endpoint while the composer remains the active input.

Each level can load data asynchronously and report progress or errors. Back, Escape, and dismissal restore the user’s draft rather than losing it. Keyboard navigation and filtering apply to the active level, so provider and model actions remain usable without leaving the chat panel.

Provider commands load the current provider choices and then guide the user through an API key, a custom endpoint, or a ChatGPT sign-in. A successful connection refreshes the model registry and selects the provider’s best available model. Model commands fetch the current model groups and mark models without a usable key, so the picker reflects current service state rather than only a stale local list.

References: frontend/…/commandMenu.ts• L5-40 frontend/…/commandMenu.ts• L47-73 frontend/…/commandMenu.ts• L80-142 frontend/…/commandMenu.ts• L144-195 frontend/…/connect.ts• L13-210 frontend/…/models.ts• L6-45 frontend/…/providers.ts• L16-49 frontend/…/providers.ts• L51-184

User turn lifecycle

Each request becomes a user message followed by a temporary assistant message. The client saves the current page before it sends the request, so the server starts from the same draft that the user sees. It then replaces the temporary message as progress, streamed text, questions, tool results, completion, or failure arrive.

The panel also supports a single-turn revert action. A completed AI edit can restore the page and related scripts to the pre-turn state, then trim that turn and later messages from the session.

References: frontend/…/AIChatController.ts• L831-894 frontend/…/AIChatController.ts• L896-918 frontend/…/BuilderAIChatPanel.vue• L140-219

Multi-page build feedback

Multi-page build feedback makes a broad AI request safe to review before it changes several pages. A pending page card lists new pages and edits to existing pages, lets the user select which rows to apply, and reports the result for each row after the action. New pages are built one at a time after the user applies them.

The card turns page keys and server results into stable rows. Routes are normalized before matching results, created pages gain their new page ID when the server returns it, and a created page remains a separate build until its off-screen build finishes. The card can open a created or changed page, expand its change lines, and show created, changed, skipped, or failed outcomes.

A background build record stays compact while it runs. It names the page and current step, then becomes an expandable record with the timeline, summary, elapsed time, and optional diagnostic entry after the build ends. This lets the user monitor work without leaving the current page.

References: frontend/…/AIPageCard.vue• L1-90 frontend/…/AIPageCard.vue• L107-171 frontend/…/AIPageBuild.vue• L1-49 frontend/…/AIPageBuild.vue• L61-93 frontend/…/pageChanges.ts• L1-87 frontend/…/pageChanges.ts• L90-134

Turn timeline

The turn timeline explains what the agent is doing while a request runs. It separates the agent’s thinking, tool work, and short narration from the final answer, so a long turn remains understandable instead of looking stalled.

Turn progress

The timeline receives ordered steps for one assistant turn. A step can show thinking, a tool action, or text written between tool rounds. Thinking stays compact while it runs. It becomes expandable only when reasoning text has streamed, and an empty completed thinking step does not remain as a dead row. Open reasoning renders as muted markdown so its structure is readable without competing with the answer.

Tool runs with the same action collapse into one row. Repeated design-token work becomes a count of tokens, while edits prepared for several pages become one summary that names the number of pages. Grouped rows carry the latest status and the summed duration, so the timeline shows the work as one useful action rather than a noisy list of repeated calls.

The timeline adds a Working tail during idle parts of a live turn, such as streamed tool arguments or the start of a new round. It shows durations only when they add useful information. The same step data is stored in message metadata, so a reloaded session reads like a turn that was watched live.

References: frontend/…/AITurnTimeline.vue• L1-63 frontend/…/AITurnTimeline.vue• L66-143 frontend/…/types.ts• L75-87 frontend/…/AIChatController.ts• L486-554

UI-spec rendering

UI-spec rendering lets the agent ask focused questions inside the chat instead of forcing every choice through free text. The AIUISpec component turns a server-provided set of simple UI elements into a card that can show context and collect choices, text, images, colors, uploads, or an action.

Card interaction

The card is active only for the latest unanswered assistant message. A simple choice can submit at once. A larger card groups related controls into steps, lets the user move back, and sends one plain-language reply that includes the collected answers. A choice in a stepped question advances to the next step, while the final action submits the full set of values.

The card can show headings, text, lists, choice tiles, color swatches, images, dividers, text inputs, image uploads, named color roles, and action buttons. Uploaded images are sent as URLs. Color roles preserve the meaning of each slot, and untouched preset colors are marked as suggestions rather than fixed user decisions. If a card has no usable control, it provides a default way to continue.

Unknown UI element kinds are ignored. Image sources are limited to same-origin paths or HTTPS URLs. Color values are limited to plain CSS color forms before the client displays them, which prevents model-provided content from becoming an unsafe browser source or style.

References: frontend/…/AIUISpec.vue• L1-37 frontend/…/AIUISpec.vue• L39-224 frontend/…/AIUISpec.vue• L238-345 frontend/…/AIUISpec.vue• L346-399 frontend/…/AIUISpec.vue• L405-499

Answer summary

After a card is answered, the client replaces the live controls with a compact question-and-answer summary. It derives that summary from the next user reply instead of storing a second copy of every answer. This keeps replayed sessions consistent and removes the duplicate reply bubble when the card already shows the chosen values.

References: frontend/…/cardAnswers.ts• L1-3 frontend/…/cardAnswers.ts• L33-79 frontend/…/AIUISpec.vue• L238-259 frontend/…/BuilderAIChatPanel.vue• L553-593

Affected-item feedback

Affected-item feedback connects a completed AI turn to the builder objects it changed. It gives the user a small summary of updated blocks and scripts, then provides direct links to inspect each item in the canvas or script editor.

Change summary

The client records affected items before it applies each tool result. It merges repeated edits to the same item and keeps a list of changed properties. The final assistant message carries this metadata, along with any script names needed for turn undo.

The feedback stays collapsed by default. Its summary names the actual mix of blocks and scripts, so a script-only edit does not look like a block edit. Selecting a block moves focus to it. Selecting a script opens the matching code surface.

References: frontend/…/toolDispatch.ts• L32-38 frontend/…/toolDispatch.ts• L122-154 frontend/…/AIAffectedItems.vue• L1-31 frontend/…/AIChatController.ts• L640-698

Model and provider dialogs

Model and provider settings determine which AI services appear in the chat picker. The settings flow helps a site connect a provider, verify access, choose models, and later manage the enabled provider and model records. The chat command menu provides a second path for these same account and model tasks.

Provider setup

The setup flow guides a first-time site through provider choice, credentials, and model choice. It supports API-key providers, OpenAI-compatible endpoints, custom model lists, and browser-based sign-in where a provider uses OAuth. A site can save a provider for later repair even when its first key check reports a problem.

The provider dialog handles later edits. It keeps stored keys hidden, can test a provider, and can import the chat models exposed by a compatible endpoint. Disabling a provider hides its models from the chat without changing the rest of the site. The command menu exposes the same lifecycle as connected-provider rows and refreshes the registry after changes.

References: frontend/…/AISetupFlow.vue• L1-18 frontend/…/AISetupFlow.vue• L50-152 frontend/…/AISetupFlow.vue• L398-483 frontend/…/AIProviderDialog.vue• L1-77 frontend/…/AIProviderDialog.vue• L134-188 frontend/…/connect.ts• L13-210 frontend/…/providers.ts• L16-49 frontend/…/providers.ts• L129-173

Model selection

The model list groups enabled and disabled models under their providers. A model dialog sets the provider, provider model ID, and label. The chat refreshes its picker after settings close and selects a valid model when the old choice is no longer available.

The in-chat model menu fetches current provider groups and marks models with no usable key. The client checks whether the selected model has a usable key before sending. This matters when several providers exist: one model can be unavailable even though another provider makes the site look configured.

References: frontend/…/AIModelList.vue• L1-72 frontend/…/AIModelDialog.vue• L1-45 frontend/…/aiModels.ts• L8-28 frontend/…/AIChatController.ts• L171-226 frontend/…/BuilderAIChatPanel.vue• L308-319 frontend/…/models.ts• L6-45

Realtime updates

Realtime updates carry one AI turn from the server to the page that started it. The client listens to page-scoped ai_chat_* events and maps each event to a focused view update rather than polling for the whole conversation.

Event stream

The main event types represent progress, streamed content, tool batches, questions, completion, errors, timeline steps, and resource refreshes. Page IDs keep unrelated builder pages apart. Session IDs keep chat text and timeline steps in the selected session, while page-level canvas changes remain visible when another session on the same page is building.

The client removes listeners when the page or panel is no longer active. It also ignores stale session responses and replays an active page build when the user opens the page during generation.

References: frontend/…/realtime.ts• L1-49 frontend/…/AIChatController.ts• L242-270 frontend/…/AIChatController.ts• L476-512 frontend/…/AIChatController.ts• L619-754

Streamed preview

Page YAML can arrive before the final tool result. The client renders it as a temporary canvas preview and throttles redraws so the panel remains responsive. The final authoritative page operation replaces that preview. If the run fails or is cancelled before that replacement, the client releases the build state and reloads the saved draft.

While a preview is active, editor autosave stands down. This prevents partial or stale streamed content from becoming the saved page.

References: frontend/…/AIChatController.ts• L71-127 frontend/…/AIChatController.ts• L152-165 frontend/…/AIChatController.ts• L299-327 frontend/…/builderStore.ts• L46-50 frontend/…/pageStore.ts• L280-295

AI diagnostics

AI diagnostics give an engineer a compact view of how a model run ended and what happened inside its tool loop. The debug panel shows the selected model, stop reason, token use, context use, latency, round count, tool trace, tool failures, and raw run data without changing the normal authoring flow.

Run inspection

The panel presents high-level run health first. It marks completed, generated, capped, and unknown stop states, then exposes warnings for truncation, tool failures, repaired arguments, or stream retries. The trace connects each round to its tools and short model message, while expandable sections keep per-call token data and raw JSON available for deeper inspection.

References: frontend/…/AIDebugPanel.vue• L1-160 frontend/…/AIDebugPanel.vue• L163-233 frontend/…/AIDebugPanel.vue• L236-280

Builder result dispatch

Builder result dispatch turns AI tool results into the same page and script state that the builder UI already understands. The client applies the result to the live canvas, follows the most relevant changed block, and refreshes page-level data when a server tool changed data outside the block tree.

Page and script updates

The dispatcher handles whole-page replacements, block edits, block insertion and removal, block moves, and script changes. Server-expanded block data keeps the IDs that later AI operations target. Script operations update the local script view because the server has already saved the authoritative script.

Generated page descriptions pass through the same adapter for preview and final application. It maps the compact page description into builder blocks, turns icon descriptions into editable inline icons, normalizes binding keys to their local data context, and preserves dynamic data bindings. Repeater data becomes page data for rendering, while the client-created data assignments contain only the supplied JSON values.

The adapter can also recover a usable prefix while streamed YAML is incomplete. This lets the preview follow the model output without treating partial content as the final saved page.

The dispatcher also records the change scope used by affected-item feedback. This creates one path from an incoming tool result to both visible builder state and user-facing turn history.

References: frontend/…/toolDispatch.ts• L19-43 frontend/…/toolDispatch.ts• L67-81 frontend/…/toolDispatch.ts• L122-154 frontend/…/toolDispatch.ts• L250-351 frontend/…/yaml.ts• L32-71 frontend/…/yaml.ts• L97-194 frontend/…/yaml.ts• L196-238 frontend/…/AIChatController.ts• L556-617

Resource refresh

Some AI tools change shared state that the canvas does not load on every turn. A refresh event names the affected resource, and the client reloads design variables, page data, or the page document as needed. This keeps theme values, dynamic previews, and page settings current without a full editor reload.

References: frontend/…/AIChatController.ts• L556-573 frontend/…/realtime.ts• L16-18

Change checklist

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

  • Keep the ai_chat_* event names and page suffix aligned with the server event publisher. A mismatch can leave the panel silent while the agent still runs.
  • Keep the turn-step metadata shape aligned between live events and persisted chat messages. The timeline must render a watched turn and a reloaded turn in the same way.
  • Keep timeline grouping rules aligned with tool summaries and tool names. A change can turn repeated token or multi-page work into misleading rows or hide its latest status.
  • Keep UI-spec element labels, supported input kinds, stepped-question rules, and reply parsing aligned. A changed label rule can make a user’s answer disappear from the answered card or reach the model without its question.
  • Keep attachment limits, image and video preprocessing, stored attachment metadata, and server request limits aligned. A client preview can otherwise differ from the media that the model receives.
  • Keep the chat markdown allow-list and link behavior aligned across every chat surface. A change to one renderer can expose unsafe content or make a link replace the active builder session.
  • Keep command-menu levels, async results, input fields, keyboard exits, and draft restoration aligned with provider and model actions. A changed menu result can leave the composer focused on a stale level or show settings that no longer match the registry.
  • Keep provider connection results aligned with registry refresh and model selection. A connected provider must not leave the chat showing an old model list or an unusable selection.
  • Keep multi-page card keys, route normalization, result statuses, build records, and apply or skip actions aligned with the server page-change payload. A mismatch can apply the wrong row or hide the result for a created page.
  • Keep compact page-description fields, icon names, binding sources, normalized binding keys, and repeater data aligned between the model contract and the YAML adapter. A renamed field can leave generated content static, make repeated content empty, or render an icon as an unusable block.
  • Keep tool names and argument shapes aligned with ToolDispatcher and affected-item tracking. A new edit can change the canvas while leaving no useful feedback or undo scope.
  • Keep page-level resource names aligned between refresh events and the stores that reload variables, page data, or page settings.
  • Keep provider and model readiness rules aligned between settings, the model picker, the command menu, and the server’s request checks. A model that appears selectable must not fail only after submit.
  • Keep diagnostic stop reasons, trace fields, and warning fields aligned with the run data supplied to AIDebugPanel. A renamed field can make a failed run look successful or hide the cause.

Important failure modes

TriggerConsequenceGuard
A page-scoped realtime listener is not attached or is left attached to the old pageThe user sees no progress, or one page receives another page’s turnAttach and detach the full event family whenever the page ID changes
A streamed preview is treated as the saved pageA partial build can overwrite the user’s draftHold autosave during the build and restore the saved draft when no final authoritative result arrives
A tool changes theme variables or page data without a refresh eventThe canvas shows stale styles or dynamic content until a manual reloadEmit the named resource and handle it in the client refresh path
A model has no usable provider keyA request reaches the server only to failMark the model as unusable in the picker and show the setup link before submit
The reader scrolls up while streaming output and the transcript keeps forcing the bottomEarlier content is hard to inspect and the user loses their placeStop automatic following when the reader scrolls up, then resume only when they return to the latest output
A video is attached without frame conversion or exceeds the client limitThe request is too large or the selected model cannot use the mediaConvert supported videos to bounded image frames and reject unsupported or long files before send
A UI card uses a label that the reply parser cannot matchThe answered card does not show what the user selectedBuild card answers from the same question labels used to compose the reply
A model supplies an unsupported UI element or unsafe image or color valuePart of the question card disappears instead of becoming active contentSkip unknown elements and allow only approved image sources and color forms
Model markdown is inserted without the shared sanitizer or link policyChat content can add unsafe markup or navigate away from the active builder sessionRoute AI message content through renderMarkdown and keep its allow-list and link attributes restricted
A block change is applied before its affected item is recordedRemoved or changed items cannot appear in feedbackTrack the affected item before applying the operation
A page-change row loses its stable key or route normalizationThe user can apply the wrong page or cannot match a created page to its resultKeep new-page keys and result matching aligned with the page-change payload
A page description uses an unknown binding prefix or loses repeater data during conversionDynamic content does not resolve or repeated content renders without its dataKeep binding normalization and repeater-data transfer aligned with the page description contract
Streamed YAML is parsed as final content before it is completeA temporary preview can be mistaken for an authoritative pageUse partial parsing for preview only and let the final tool result replace it
Run data uses a stop or trace field that the debug panel does not recognizeThe diagnostic view shows an unknown or incomplete run stateKeep the debug payload fields and display mappings in sync
A command action updates provider state without refreshing the model registryThe composer shows an old provider or model listRefresh registry data and AI readiness after provider or model changes
Timeline grouping treats different tools or pages as the same actionThe user sees an inaccurate count or loses the detail needed to understand the turnKeep action matching, page extraction, and summary rules aligned with tool semantics

Key files

FileWhy to read it
frontend/…/BuilderAIChatPanel.vueMain chat surface and composition of the timeline, UI cards, affected feedback, page-change cards, session controls, command menu, attachments, and composer
frontend/…/AIChatController.tsClient owner for sessions, requests, realtime events, previews, completion, cancellation, and revert
frontend/…/realtime.tsContract for page-scoped AI event registration
frontend/…/attachments.tsBrowser preparation and display metadata for image and video attachments
frontend/…/chatScroll.tsTranscript follow and reader-position behavior during streamed output
frontend/…/commandMenu.tsCommand state machine for slash commands, filters, async levels, keyboard actions, and draft restoration
frontend/…/connect.tsProvider connection paths for keys, custom endpoints, and ChatGPT sign-in
frontend/…/models.tsCurrent model picker and model readiness shown inside the chat
frontend/…/providers.tsProvider connection, credential, model, enablement, refresh, and disconnect actions
frontend/…/AITurnTimeline.vueUser-facing representation of one AI turn’s progress, grouped work, reasoning disclosure, and idle state
frontend/…/AIPageCard.vueReview and apply surface for changes that span several pages
frontend/…/AIPageBuild.vueCompact status and result surface for a page built in the background
frontend/…/pageChanges.tsMapping from page-change payloads to proposal rows and result summaries
frontend/…/AIUISpec.vueGeneric renderer and reply composer for agent questions
frontend/…/markdown.tsShared safe rendering of AI markdown messages and chat links
frontend/…/yaml.tsConversion of streamed or complete page descriptions into builder blocks, icons, bindings, and repeater data
frontend/…/AIAffectedItems.vueExpandable links from a turn to changed blocks and scripts
frontend/…/toolDispatch.tsBoundary that applies AI results to the builder canvas and script state
frontend/…/AIDebugPanel.vueRun summary, tool trace, failure signals, token data, and raw diagnostic view
frontend/…/AISetupFlow.vueFirst-time provider connection and model selection journey
frontend/…/AIModelList.vueOngoing provider and model management surface
frontend/…/AIProviderDialog.vueProvider edit, key test, model import, and provider removal actions
frontend/…/AIModelDialog.vueModel identity and provider association dialog
frontend/…/builderStore.tsShared AI readiness and build-preview state used by the builder shell