Build a public AI summarizer with saved history #

View this page as Markdown

On this page

Prompt:

Build a public page where anyone can summarize a note and read saved notes and summaries. Keep that history in PostgreSQL. Visitors do not sign in. Test in development before I approve production.

This sequence joins the existing database, AI and web client guides. Follow their examples where linked, adapting them into one application. Keep its source text and generated summaries in database rows so they survive a page reload or an application restart.

This is a shared public history: every visitor can read the saved text. Choose it only for material intended to be public. For private notes belonging to each signed-in user, start with Build a notes app with sign-in and a database.

What your AI tool does #

Your AI builds one backend with a database, adds a route that calls AI, and gives the browser a form and a history view. It tests the combined behavior before deployment and reports what it checked.

What you need #

Before your AI starts #

Read this sequence and the linked procedures before running them. The database walkthrough can deploy: use it to prepare the files first, then return here before its deploy step. Confirm that the person wants development before the first deploy. With nobody to ask, turn it on only if their request already asks for development. Otherwise stop and report before deploying.

No visitor credential is needed for the public page. The backend calls AI with its own platform credential, which stays on the server. Put no database URL or platform credential in browser files.

Steps #

1. Prepare the database-backed service #

Start with Build a database-backed service. Use its scaffold or adapt its example files, then prepare the manifest, migrations and data layer. Keep the public audience because this summarizer is for anyone, as the project states. Keep the database-backed health check. Stop before deployment.

Adapt the notes table to keep the submitted text and a summary that can be empty while AI is unavailable. Use a new migration for a schema already used in production. Follow Keep the schema as migrations.

Give the backend routes to save a note, record its summary and read the saved history. Use parameterized queries as the database walkthrough does. A failed AI call must leave a readable saved note whose summary is still absent.

A shared database is one monthly item for the application; stored files are charged by size (Stay inside the Free Allowance).

2. Add the AI call to the backend #

Follow Call an AI model to take the AI Allowance package and write its transport. Keep both Database and AI Allowance entries in the manifest's packages list.

From the note-submission route, save the text, call generateText with a request for a short summary, and store the returned text against that note. Return the saved note and summary to the browser. Never take the platform credential from the browser.

For allowance_unavailable, keep the note saved and show that no summary is available. This refusal is not an account pause: the application can keep serving.

For account_paused alone, follow Handle an account pause: stop outbound work without retrying. That section also covers provider capacity failures and the other fallback choices.

3. Add the public form and history view #

Follow Serve a web client for the page, script and styles under client/. Have the form post text to the backend and fetch saved history on page load. Display a missing summary clearly.

The browser calls the backend on its own hostname. It never calls the platform's AI route directly. Render saved text and AI output as text, so a visitor's markup is not executed. Keep files under client/ public and free of credentials.

4. Test the code, then create the application and run locally #

Use Test your application locally with the Database and AI Allowance test doubles. Check a successful summary and an unavailable-AI answer: both keep the original note, and only the successful answer stores a summary.

Create the application, then call tzcloud_create_environment with its identifier and environment: "development", as Test in development, then promote describes. Submit the complete manifest, then follow Run your app on your computer for local settings and credentials. Keep the same application identifier for deployment.

Check the public page without signing in. Submit a note, reload, and check that history comes from the backend. Restart the local service and read the same database again. Test doubles prove the code paths; they do not prove a hosted deploy or a live AI call.

5. Deploy to development and check the result #

For the application you created, submit any manifest changes and deploy the combined files using Deploy from your computer, or Deploy from a chat. Development must already be on, so the deploy reaches it.

Open the development address the platform returns, without signing in. Submit a note, read its summary, then reload and confirm the saved history. If AI is unavailable, confirm that the note remains with no summary; report the successful live summary as unchecked.

For a hosted restart check, follow Restart an environment on development, then read the same history again. If your connection offers no restart tool, report hosted restart persistence as unchecked. Read status and logs if a check fails. Keep development's records separate from production's.

6. Approve production and check it #

Follow the promotion guide's checks and ask before promoting. With no prior approval and nobody available to ask, stop before the promote and report the development version and unchecked production results. After an approved promote, read production's serving version and open its returned address. Production has its own database; the development test note is not copied there.

Check production reads. On an app with real users, obtain the person's approval in this run before submitting a test note on production. With nobody available to approve it, leave the production write and live summary unchecked on an app with real users, and report them.

Expected result #

A visitor can submit text without signing in and read its saved summary in the shared history. Reloading the page or restarting the backend keeps the database records. An unavailable AI answer leaves the submitted note readable with no summary.

Your AI reports the address, serving version and checks passed, including which live AI calls or production writes remain unchecked.

Refusals #

Use the refusals reference and the linked guides for the operation that failed. These are common cases, not the full list.

Refusal Cause Remedy
allowance_application_required The AI call used an account-wide credential. Keep the call in the backend using its application's platform credential.
allowance_unavailable No platform key or price is in effect for the AI route. Keep the saved note, show that its summary is unavailable, and follow the AI guide's fallback.
account_paused The account has paused. Follow the AI guide's stop rule; do not retry outbound work.

For database connection or migration failures, use Add a database: Refusals. Report the failed step and leave any unproved result unchecked.