Introducing a new way to review your PRs.

Read the announcement

getnao / nao

👾 nao is the #1 open source agentic BI. (1) Create context with nao-core cli, (2) deploy nao chat interface for everyone

View on GitHub

23 documents · Updated Nov 23, 2026

docs / story-delivery-and-sharing

Story delivery, sharing, and rendering

Stories turn query-backed analysis into pages that people can view, refresh, share, embed, download, or receive as scheduled updates. The delivery path keeps the story source, current data, theme, and rendered visual blocks aligned across the main app, shared views, offline files, and notifications.

Delivery model

Story application builds

A custom story becomes a browser application before a viewer or export can use it. The build creates the boundary between authored story files and the host that supplies data, theme, and supported story capabilities.

The build must produce a valid application before the story can become a deliverable page. This same built application supports live mounting and self-contained HTML or PDF output.

References: apps/…/story-app-build.ts• L20-74 apps/…/story-app-build.worker.ts• L341-450 apps/…/story-app.ts• L8-31

Story runtime mounting

The story runtime mounts the built application in a separate story frame. React stories render into a root element. HTML stories keep their page shell and use the nao browser API to request data, narratives, theme changes, and saved state.

The host and story communicate through a narrow message channel. This channel carries query results, errors, theme updates, editing actions, table exports, and keyboard input without giving the story direct access to the host application.

This diagram shows how a built story becomes a live page and how data moves back to the host.

flowchart LR
    S[Story files] --> B[Story build]
    B --> F[Story frame]
    F --> R[Story runtime]
    R --> V[Charts, maps, tables, and story UI]
    F <--> H[Story host]
    H --> Q[Query and narrative services]
    Q --> H

References: apps/…/story-host.ts• L61-104 apps/…/story-host.ts• L217-278 apps/…/story-app.ts• L208-242

Live data refresh

Query refresh and cache use

Live stories use the latest published story version to find the queries that feed their blocks. The refresh path runs those queries in their intended data source. It stores the result with its source information and returns data and narrative text for rendering.

Viewers normally receive cached data first while the cache is valid. An expired or missing cache can trigger a refresh. A caller can also show stored data while refresh runs. A story with no cache can request data directly for an unfiltered latest view.

References: apps/…/live-story.ts• L83-147 apps/…/live-story.ts• L165-231 apps/…/system-prompt.tsx• L612

Scheduled refresh

The refresh worker updates live stories on their schedule and records success or failure for the activity feed and notifications. A keyed story lock prevents overlapping refresh work for the same story.

After a successful refresh, the system can deliver the new result to story recipients. Delivery uses the refreshed query data so the notice and its attachments describe the same update.

References: apps/…/story-refresh.handler.ts• L45-123 apps/…/story-refresh.handler.ts• L124-147

Scheduled delivery

Story delivery sends a refreshed story to selected users through the configured notification channels. The delivery schedule can use its own cron rule or run as part of story refresh when both schedules match.

Delivery checks that recipients can open the story. It can create or extend story access for specific recipients before it sends the story link, email content, and file attachments.

References: apps/…/story-delivery.service.ts• L11-59 apps/…/story-delivery.handler.ts• L74-107 apps/…/story-delivery.handler.ts• L137-186

Story access and sharing

In-app story views

The story route resolves the story before it chooses the view. Owners see the editable or preview form that matches the story type. Other viewers see the shared form. A standalone story view loads its version, theme, query data, and access state before it presents the story.

Custom story viewers can enter through a shared chat or a chat replay. The viewer routes check project access and shared-chat rules before they expose story files, versions, query data, model or SQL actions, saved state, narratives, chart plugins, map boundaries, or downloads. Downloads use the selected version and record the viewer and sharing context for analytics.

The shared-chat path allows a project member when the share is open, or an allowed user when the share targets specific users. The replay path is limited to project admins and context admins. Both paths resolve access before serving any story resource.

Owners can switch a standalone story between preview and code editing, save valid changes, inspect or restore versions, share or download the story, open it in chat, and view its analytics. The shared view stays read-only while its access policy controls refresh, chat, duplication, and related actions.

References: apps/…/_sidebar-layout.stories.$storyId.tsx• L12-34 apps/…/owned-story-page.tsx• L31-75 apps/…/shared-story-page.tsx• L29-66 apps/…/standalone-story-page.tsx• L37-103 apps/…/standalone-story-page.tsx• L105-225 apps/…/custom-story-viewer.routes.ts• L42-87 apps/…/custom-story-viewer.routes.ts• L180-246

Public story embeds

An embed presents the latest permitted story through a public route that is separate from the signed-in story page. The embed token identifies the story and its project. The server checks that token, loads the latest story data, and returns only the content needed for the embedded view.

The embedded page can open the story in the main app and can offer PDF or HTML download. Expired or invalid access produces an unavailable story instead of exposing story data.

References: apps/…/embed-story.ts• L24-65 apps/…/embed.routes.ts• L32-51 apps/…/embed.story.$storyId.tsx• L21-63

Data access in shared views

Shared views combine saved query results with live query access when the story is configured for an unfiltered latest view. Filters use the saved result path so the displayed data matches the filter context and the viewer's access boundary.

This lets a shared story stay useful when its cache is fresh while still supporting a no-cache mode for current data. Live embeds do not refetch only because the viewer returns to the browser window. The viewer sees loading, empty, or unavailable states instead of a visual that silently uses the wrong data source.

References: apps/…/shared-story-page.tsx• L191-241 apps/…/shared-story-page.tsx• L245-299 apps/…/story-embeds.tsx• L56-81

Visual rendering

Story segment rendering

Classic story content is split into segments such as text, charts, tables, maps, filters, and grids. The renderer keeps that order, places blocks in the declared grid, and sends each visual type to its matching embed.

The same visual contracts serve owner pages, shared pages, and embedded pages. Standalone views pass the story code, theme, and selected query data into the shared tab and block surface. This keeps chart and map behavior consistent while the data source changes between cached, live, and exported modes.

References: apps/…/story-rendering.tsx• L20-68 apps/…/story-rendering.tsx• L83-139 apps/…/story-embeds.tsx• L84-214 apps/…/standalone-story-page.tsx• L227-323

Story tab navigation

Tabbed stories give viewers page-level navigation while authors organize content into named tabs. The tab surface keeps the active page, inactive pages, and drop targets clear. Its layout and borders follow the story theme in previews and rendered views.

References: apps/…/story-tabs-bar.tsx• L12-32 apps/…/story-tabs-bar.tsx• L74-162 apps/…/story-tabs-bar.tsx• L164-293 apps/…/story-theme-brand-styles.ts• L114-129

Chart and table blocks

Chart blocks turn query rows into configured visual series. Table blocks turn the same rows into a data table with its column rules. Both blocks show a clear loading, empty, or unavailable state when their query result is not ready.

In an editable owner view, chart and table controls can send a block change back to the story. The saved result is a new story version. Later views then use the updated visual contract rather than a temporary screen change.

References: apps/…/story-embeds.tsx• L84-162 apps/…/story-embeds.tsx• L216-268 apps/…/story-chart-embed.tsx• L117-257 apps/…/story-table-embed.tsx• L56-105

Map blocks

Map blocks resolve rows into points or regions before they reach the map view. The renderer checks the map keys, limits visible points, and reports when rows do not contain usable coordinates.

Map tiles and optional boundary data remain part of the map display contract. A map can therefore render in the main story, a public embed, or an export without changing how the story describes its geographic data.

References: apps/…/story-map-embed.tsx• L11-37 apps/…/story-embeds.tsx• L164-214 apps/…/story-map-tiles.ts• L1-120

Story theme management

A story theme is the project-wide visual contract for story identity, surfaces, text, blocks, tables, charts, and typography. Admins can apply or disable it for all stories, edit light and dark variants, preview the result, and keep a saved theme without applying it.

Theme generation can use brand sources such as a website, image, PDF, document, ZIP, logo, white-label settings, or admin guidance. The result records its sources and notes, keeps an uploaded logo, and derives the other colour variant so the brand stays consistent while surfaces and text remain readable.

References: apps/…/story-theme-settings.tsx• L94-185 apps/…/story-theme-settings.tsx• L192-243 apps/…/story-theme-settings.tsx• L270-540 apps/…/generate.ts• L51-57 apps/…/generate.ts• L115-140 apps/…/story-theme-pair.ts• L28-31 apps/…/story-theme-pair.ts• L63-121

Themes and print frames

The story document applies the active theme's fonts, colours, block styles, table styles, chart palette, brand header, base styles, kit styles, and story styles in a fixed order. The runtime can replace the selected light or dark theme while the story remains mounted.

Slides use a fixed canvas for screen and print layout. In print mode, the deck places one slide on each page. This keeps the PDF layout close to the on-screen deck.

References: apps/…/story-document.ts• L154-176 apps/…/story-theme.ts• L283-351 apps/…/story-theme-brand-styles.ts• L17-47 apps/…/slides.tsx• L52-60 apps/…/slides.tsx• L180-200

Export and delivery assets

Offline story documents

An HTML export packages the story application, runtime, theme, styles, query results, narratives, saved shared state, chart plugin sources, and map boundary data into one document. The document can run without the host and can keep interactive behavior such as chart tooltips and slide navigation.

The export keeps only the query results used by the selected story version. It loads the saved narratives and unattended state for that story. It also includes only the map boundaries named by that version. A custom story without a built application cannot produce an incomplete document; export stops with the build error instead.

The export builder accepts caller-provided narratives and state when a delivery path already has them. Otherwise it loads the saved values. This keeps PDF output and direct document output aligned while allowing a refresh run to use the same update data.

References: apps/…/custom-story-export.ts• L18-25 apps/…/custom-story-export.ts• L27-63 apps/…/custom-story-export.ts• L65-98 apps/…/story-document.ts• L30-51 apps/…/story-document.ts• L83-96

PDF rendering

PDF output uses the same self-contained story document as HTML output and then renders it in print mode. Custom stories include their current narratives, unattended shared state, chart plugins, and required map boundaries before the document is rendered.

This shared path matters because a PDF should show the same story structure, theme, charts, maps, and tables as the live story. A story that cannot build its current application cannot produce a valid custom-story export.

References: apps/…/custom-story-export.ts• L32-40 apps/…/custom-story-export.ts• L43-88 apps/…/story-host.ts• L145-151

Shared-view downloads

Custom story viewers can request an HTML or PDF download for the latest version or a selected version. The download route first resolves viewer access, then checks that the selected version is a custom story, records the download context, and renders the submitted story snapshot with the active story fonts.

This path keeps a shared download inside the same project and chat access boundary as the live view. The selected version is part of the recorded event, so delivery history identifies which story state produced the file.

References: apps/…/custom-story-viewer.routes.ts• L180-208 apps/…/custom-story-viewer.routes.ts• L211-246 apps/…/story-snapshot.ts• L1-80

Scheduled delivery combines a story link with a PDF attachment. Classic stories can also include rendered email content and its image assets. Custom stories use the self-contained PDF path because their visual surface is an application rather than only a text document.

The link remains the access point for the latest story. The attachment is the point-in-time result produced during the same delivery run.

References: apps/…/story-delivery.handler.ts• L137-186 apps/…/story-delivery.handler.ts• L195-210 apps/…/story-email.ts• L1-200

Change checklist

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

  • Keep the story build contract, runtime module map, and frame message types aligned. A mismatch can make a story build successfully but fail when it mounts.
  • Keep story-code validation, dirty state, and save controls aligned with the build contract. A change in one can let an invalid draft appear ready to deliver or block a valid draft.
  • Keep the query IDs selected during refresh, shared viewing, and export creation aligned. Missing IDs can produce a page that loads but has empty visual blocks.
  • Keep the custom viewer's shared-chat and replay access rules paired with every file, data, state, plugin, boundary, and download route. A new viewer action must not bypass project or share checks.
  • Keep chart plugin sources and map boundary keys in the built story and export context. A mismatch can leave a live chart or map usable while its offline copy is incomplete.
  • Keep print flags, slide attributes, and PDF page rules aligned. A change in one can make screen decks work while PDF pages split or scale incorrectly.
  • Keep public embed token checks paired with both story loading and download routes. A new delivery path must not bypass the project and resource checks.
  • Keep scheduled delivery and refresh schedules distinct when they do not coincide. Removing that distinction can send duplicate updates.
  • Keep the light and dark theme variants aligned on brand identity, chart series, and readable contrast. A change to one variant must not make the other lose the brand or become unreadable.
  • Keep theme variables and shared brand selectors aligned with the story elements that consume them. A renamed tab, block, table, or chart surface can silently lose its project theme.
  • Keep generated theme source notes and uploaded logo handling paired with theme saves. Otherwise a later review can misstate how the applied visual identity was produced.

Important failure modes

TriggerConsequenceGuard
A custom story has no valid entry or uses an unsupported importThe story has no deliverable applicationBuild-time entry and import diagnostics in apps/…/story-app-build.ts
Story code contains validation errorsThe editor marks the draft invalid and the page can keep it from being saved as the next story versionDraft validation and validity reporting in apps/…/story-code-view.tsx• L60-84 and apps/…/story-code-view.tsx• L143-166
A live query refresh failsThe viewer may keep the stored result and the refresh failure is recordedCache fallback in apps/…/live-story.ts• L191-220 and activity handling in apps/…/story-refresh.handler.ts• L124-147
Shared-chat access is missing or a replay viewer lacks an admin roleCustom story data, files, and downloads are rejectedViewer access resolution in apps/…/custom-story-viewer.routes.ts• L218-246
An embed token is invalid, expired, or for another projectThe public page or download is rejectedToken and project checks in apps/…/embed-story.ts• L24-38
A chart, table, or map query has no usable rowsThe block shows an explicit empty or unavailable stateBlock guards in apps/…/story-embeds.tsx• L113-134 and apps/…/story-map-embed.tsx• L18-24
A scheduled delivery has no valid recipientsDelivery is rejected or skipped instead of sending to nobodySchedule validation in apps/…/story-delivery.service.ts• L11-27 and recipient resolution in apps/…/story-delivery.handler.ts• L110-134
A story application throws during mountThe frame reports the error and shows a crash messageRuntime error reporting in apps/…/story-host.ts• L75-86 and apps/…/story-host.ts• L405-438
A custom story version has no built applicationHTML and PDF export fail instead of producing an incomplete documentExport guard in apps/…/custom-story-export.ts• L65-72
A selected shared-view version is missing or is not customThe download is rejected instead of returning the wrong story formatVersion and format check in apps/…/custom-story-viewer.routes.ts• L183-188
A saved theme has invalid values or too few chart coloursThe theme cannot be applied as a valid story visual contractTheme schema validation in apps/…/story-theme.ts• L99-174 and save validation in apps/…/story-theme-settings.tsx• L160-168
A generated theme cannot read its sources or load a project modelThe system reports the source limit or model problem, then uses a guarded fallback when possibleSource and fallback handling in apps/…/generate.ts• L313-375 and apps/…/generate.ts• L405-466
A theme's light or dark counterpart loses surface contrastBlocks, charts, or brand identity can blend into the page in that colour schemeVariant derivation and contrast repair in apps/…/story-theme-pair.ts• L69-121

Key files

FileWhy to read it
apps/…/story-app-build.tsDefines how authored custom stories become deliverable applications.
apps/…/story-app.tsDefines the shared story app, runtime, export, and host-frame contracts.
apps/…/story-host.tsShows how a mounted story requests data and reports actions or errors.
apps/…/standalone-story-page.tsxShows how a standalone story loads version data, sharing, editing, filters, and visual blocks into one viewer.
apps/…/live-story.tsExplains refresh, cache, narrative, and query-data behavior.
apps/…/story-embeds.tsxShows the common chart, map, and table rendering path.
apps/…/story-tabs-bar.tsxShows tab navigation and the editing actions that shape multi-page stories.
apps/…/shared-story-page.tsxShows how shared viewers combine access, refresh, and rendering.
apps/…/custom-story-viewer.routes.tsShows how shared-chat and replay viewers access custom story data and downloads.
apps/…/embed-story.tsShows how public story content is checked and assembled.
apps/…/custom-story-export.tsShows how custom story data and visual assets become self-contained HTML and PDF input.
apps/…/story-document.tsDefines the self-contained document used for HTML and PDF output.
apps/…/story-theme.tsDefines the story visual contract and the values passed into rendered story surfaces.
apps/…/story-theme-pair.tsExplains how light and dark story variants preserve brand identity and readable contrast.
apps/…/story-theme-brand-styles.tsShows how theme rules style story text, controls, KPI tiles, charts, filters, tabs, and headers.
apps/…/story-theme-settings.tsxShows how admins apply, edit, preview, generate, and save project story themes.
apps/…/generate.tsExplains how brand sources become a theme pair with source notes and guarded fallbacks.
apps/…/story-delivery.handler.tsShows how refreshed stories become links, attachments, and notifications.

See Stories and visualization for the product-level story model and Story authoring and library management for creation, editing, and library state.