How ToExperimentalFor developerFor agency

Build a CMS and agent workflows in your application

Create a rich-text newsroom or a support agent with customer-owned roles, providers, approvals and recovery.

Last updated 2026-11-26

What you'll achieve

  • Build an editable CMS with rich text, private fields and scheduled publication
  • Configure a customer-owned agent with versioned tools, budgets and approval
  • Resume work safely after conflicting edits, worker restarts and lost replies

Create a newsroom or a support agent

A newsroom needs two views of an article. An editor sees the working draft and internal notes. A reader sees the last published revision. An editorial agent can draft from approved sources and ask a publisher to review the exact revision. A support agent can classify a ticket and route it to a queue. Both kits run inside your application. You own the data, roles, provider accounts, code and interface.

Use Node 22.18 or newer. From a fresh directory, download the versioned helper from BlinkHost's public CLI repository and check its SHA-256 before running the generator. Keep this terminal open. Choose one of the two generator commands and give it a new directory.

kit_release=https://github.com/blinkhost-ltd/blinkhost-cli/releases/download/app-helpers-v0.1.1
kit_file=blinkhost-app-helpers-0.1.1.tgz
kit_dir=$(mktemp -d)
kit_url="$kit_release/$kit_file"
kit_sha256=5130fe332e97b16706630e5010b15d7f7e8c237743e33513fc1e6bbded53e407
kit_sri=sha512-18WVkPQGaPgL4rMY95ZzPvacs6V49MYQHBrAOwSsMd6IsA1pkqqOgEwNGRzYmbC0vIAC1TEQTT3ouf9H6pNouQ==
curl --fail --location --proto '=https' --proto-redir '=https' --output "$kit_dir/download" "$kit_url" &&
  node -e 'const fs=require("node:fs"),c=require("node:crypto"); if(c.createHash("sha256").update(fs.readFileSync(process.argv[1])).digest("hex")!==process.argv[2]) process.exit(1)' "$kit_dir/download" "$kit_sha256" &&
  mv "$kit_dir/download" "$kit_dir/$kit_file"

Continue only after the checksum succeeds. The generator below installs from the verified local archive.

npm exec --yes --offline --ignore-scripts --package="$kit_dir/$kit_file" -- blinkhost-app-kit cms react newsroom
npm exec --yes --offline --ignore-scripts --package="$kit_dir/$kit_file" -- blinkhost-app-kit agents support-desk

Change into the directory you generated. Create the lockfile using the public archive URL, verify the pinned archive integrity and install. The CMS workspaces also install their framework dependencies. Commit package.json and package-lock.json. With those files in a fresh checkout, npm ci verifies the locked package bytes.

npm install --package-lock-only --ignore-scripts --save-exact "$kit_url" &&
  node -e 'const p=require("./package-lock.json").packages["node_modules/@blinkhost/app-helpers"]; if(p?.version!=="0.1.1" || p.resolved!==process.argv[1] || p.integrity!==process.argv[2]) process.exit(1)' "$kit_url" "$kit_sri" &&
  npm ci && npm test

For a CMS project, run npm run build before npm start. The server prints a loopback sign-in URL and temporary role tokens. Use the React studio at /?studio&localUploads. The HTML, Astro, Vue, Svelte and Solid choices generate a public site in that framework and an editable React studio at /studio/?localUploads. The framework-independent client is available at @blinkhost/app-helpers/cms-ui. The workflow panel is at /flows/. Role tokens and the deterministic model in this starter are for local development.

Configure your hosted backend

Choose your backend module name. For a module named customer-kit, run npm run build:hosted -- customer-kit in the generated project. Publish web/dist/ as your static site for a CMS starter, or dist/ for the agents-only starter. Readers open /. The React editor opens at /?studio and the other editors at /studio/index.html. Workflows open at /flows/index.html. The generated browser clients call /_server_islands/customer-kit/api/cms/ and /_server_islands/customer-kit/api/workflows/ on the same origin.

The backend kits are JavaScript with TypeScript declarations. Copy the generated server/app.js, server/investigation.js and server/hosted.js to your JavaScript/TypeScript backend module. Export hostedHandler({origin,moduleName:'customer-kit',resolveSite}) as its default handler, with the same module name used for the static build and the exact origin customers visit. Apply the complete CMS_SCHEMA_SQL and WORKFLOW_SCHEMA_SQL exports through your application's migrations before serving requests. Pin the DEFAULT database binding's ID and generation in trusted server configuration.

In the backend module directory, start with your module's package.json. The compiler accepts exact versions in package.json and installs packages offline using the archive integrity in package-lock.json. Run these commands in the same terminal, then commit both files. If your application imports the optional SDK adapter, set include_sdk=1 first. Both archives must be resolved together because the adapter depends on the core helper.

set -- "$kit_url"
if [ "${include_sdk:-0}" = 1 ]; then
  set -- "$@" "$kit_release/blinkhost-app-helpers-sdk-0.1.1.tgz"
fi
npm install --package-lock-only --ignore-scripts --save-exact "$@" &&
  node --input-type=commonjs - "$kit_url" "$kit_sri" "${include_sdk:-0}" <<'JS'
const fs = require('node:fs');
const [coreUrl, coreIntegrity, includeSdk] = process.argv.slice(2);
const packages = [['@blinkhost/app-helpers', coreUrl, coreIntegrity]];
if (includeSdk === '1') {
  packages.push(['@blinkhost/app-helpers-sdk',
    new URL('blinkhost-app-helpers-sdk-0.1.1.tgz', coreUrl).href,
    'sha512-J/st5PpRrDbUZ3SbV/+nNMd98vI9mP4nYu2i6ok024yj466E9aRe0ERJ/KwssArq246QtSlBfGhb8IgVcWkYbw==']);
}
const manifest = JSON.parse(fs.readFileSync('package.json'));
const lock = JSON.parse(fs.readFileSync('package-lock.json'));
for (const [name, url, integrity] of packages) {
  const entry = lock.packages['node_modules/' + name];
  if (entry?.version !== '0.1.1' || entry.resolved !== url || entry.integrity !== integrity)
    throw new Error('Unexpected package or integrity for ' + name);
  manifest.dependencies[name] = lock.packages[''].dependencies[name] = entry.version;
}
for (const [file, data] of [['package.json', manifest], ['package-lock.json', lock]])
  fs.writeFileSync(file, JSON.stringify(data, null, 2) + '\n');
JS

Implement resolveSite using your own routing, session verifier, role directory, model provider and ticket adapter. Choose the tenant on the server, including for public reads. Authenticate private requests with a verified customer application session. Cookie-authenticated mutations require JSON, an exact configured Origin and the X-CMS-Request: 1 header. Keep model, identity, email and storage credentials in customer backend secrets. Your users sign in to your application.

Edit and publish content

Start with the editable articles, authors and sources collections in server/app.js. Define fields, validation, relations and private fields such as reviewer notes. For a custom rich-text block, declare its fields in the collection and supply a renderer in your frontend. Render text with framework escaping or DOM text nodes. Store images in customer-owned private storage. Your upload resolver must confirm the provider receipt, tenant, actor, intended asset, size and permitted type before registering the immutable object. Keep storage keys server-side.

In the studio, publish an author, write an article and attach the author or an authorized image. Preview the draft and send it for review. A publisher can publish it immediately or schedule it. A new draft of a published article leaves the previous publication visible. Private fields stay out of the public projection. Withdrawing a referenced image can hide the article on the next read. The starter uses no-store so a cached response cannot continue serving withdrawn content.

For your own interface, use the version your editor actually loaded. Given a configured CMS, verified editor and publisher, and an existing draft with complete fields, the server can submit and publish it as follows.

const key = {collection: 'articles', id: 'release-guide'};
const review = await cms.submitReview({...key, actor: editor, expectedVersion: draft.version});
await cms.publish({...key, actor: publisher, expectedVersion: review.version});
const publicArticle = await cms.getPublished(key);

On a version conflict, reload the primary draft and let the editor reconcile competing edits. Use history and restore to copy a previous revision into a new draft. For a timed release, call schedule with the expected version and a future Unix timestamp in milliseconds. The schedule pins a revision. Saving another edit cancels that schedule.

Run a versioned agent

At /flows/, sign in as support, start a support run and advance it to classify a ticket and route it to billing or support. Refresh and reopen its ID to inspect the durable result. Try the editorial flow as an editor. Choose approved source revisions, generate a cited draft, and submit it. A publisher opens the same run, previews the article, checks the proposed revision and approves the action. Changing the article invalidates the old publication proposal.

Define your graph, input validation, allowed tools, role checks and per-run budget in server/app.js. The graph can transform data, branch, execute a tool, wait for a permitted event or request approval. The server selects available tools and checks model outputs. Supply a deterministic adapter for repeatable local tests. For live generation, the generated server/provider.js exports createProviderModel for a customer-configured Chat Completions or Anthropic Messages endpoint. Give it the endpoint, model, named secret and output limits. Limit which data you send to the provider.

const key = {tenant: site.tenant, runId: 'ticket-run-42'};
await workflows.start(actor, {...key, workflow: 'support', version: 1,
  input: {ticket: 'ticket-42', message: 'Please check my invoice'}});
const progress = await workflows.tick(actor, key);

Choose a stable run ID. A matching start recovers the existing run. Each tick advances one step and dispatches at most one tool. For protected actions, pass the exact stored run revision and proposed action to approve. Before dispatch, recheck the owner, reviewer's current role, arguments, tool version and cost. Keep old graph and tool versions available while their runs are open. Set maxSpend for the run and a conservative charge for each tool, including model calls. The starter uses microdollars. Configure the provider's token and time bounds to fit those charges. Actual provider billing is measured by your provider.

For a model-directed example, open Support investigation at /flows/ using the support session. Ask about ticket-one. The model can read the scoped ticket, read its history, propose an internal note, finish or refuse. A separate support reviewer approves the exact proposed note. The application sets the tool list and checks the current authority, turn count and budget. Replace the tools, model and policy in the editable customer starter. This example uses four local identities including the support reviewer.

For public static HTML, the Astro starter accepts CMS_ASTRO_MODE=snapshot and a customer CMS_PUBLIC_ORIGIN at build time. It reads the public collection and emits article pages. Rebuild and replace the static output when content changes or is withdrawn. The default live reader checks visibility at request time.

Schedule and recover work

Run npm run worker against the same local state for one sweep. For ongoing hosted work, configure an authenticated customer scheduler to call hostedWorkPage(sdk, site, {queue, after, limit}). Use a queue for each collection and a workflows queue. Persist the returned after and follow it even after an empty page. When it is null, the sweep is finished. Start the next sweep from the beginning. The CMS worker uses listDue and publishDue to release due revisions after rechecking the scheduling publisher's current role. The workflow worker advances eligible runs. A parked approval still requires an authorized human.

If a CMS write returns outcome_unknown, keep its operation ID and original expected version. Inspect the transaction receipt and the entry on the primary before deciding to retry. For a workflow tool, use ctx.action.id as the receiver's idempotency key and call ctx.check() just before dispatch. An interrupted tool call can leave the run unknown and its budget reserved. Use reconcile to look up the exact receiver receipt. Report an applied result when confirmed. Report not_applied only after the receiver has permanently prevented the outstanding attempt from applying. If the provider cannot establish the outcome, leave the action pending for operator review.

Run npm test in your generated project. Edit server/test-application.mjs to supply sample model decisions and exercise your own approval rules. The editorial example saves model-suggested tags alongside a draft for review. Before connecting a live service, exercise two tenants, a revoked publisher, two editors racing to save, a withdrawn image, an approval followed by a changed draft, repeated starts, a worker restart and a lost provider reply. Check the public view, persisted revisions and recorded receiver effects. The generated project's guides/CMS.md, guides/CMS-FRONTENDS.md and guides/WORKFLOWS.md include the adapter contracts and extension examples.

Help improve this page

Sign in to send page-specific feedback. For account-specific help, email support@blinkhost.me.