Skip to main content

Document Improver

A two-panel interface where users paste rough text on the left and watch a polished version stream into the right panel. Tokens appear as the model generates them—users see immediate progress rather than a loading spinner.

Server Code

The content field holds the input as a plain string. The improved field uses stream<string> because it accumulates progressively during generation—each append() broadcasts just that chunk, creating the token-by-token effect. The status field drives loading states. While 'improving', the UI disables the button and shows a cursor.

Client Code

The useSystem hook returns reactive state that updates whenever the server broadcasts changes. The blinking cursor appears while streaming and disappears when complete.

Running the Example

Open http://localhost:3000. Paste text, click Improve, watch it stream. Open a second tab—both display the same streaming output since they share state.

Variations

Revision History

Track previous improvements before starting each generation:

Multiple Styles

Parameterize the action for different tones:
TypeScript ensures the client passes a valid style argument.