Loading…
Loading…
ChaiChat is a browser chat client for trying multiple AI models. The project focuses on application state, streaming transport, local caches and explicit provider errors. Its source includes a Next.js App Router interface, Convex data access, Dexie storage and an AI SDK chat route.
The browser submits a message to the chat API. The server chooses the configured gateway and model, then returns a UI message stream. The interface updates as message events arrive and persists conversation state through its cache and database paths.
The current route supports Vercel AI Gateway and LLM Gateway. Some models do not support the requested streaming behavior. In those cases the code can use simulateStreamingMiddleware to present a generated response as a stream. That fallback is a display behavior; it is not proof that the model generated each displayed fragment incrementally.
The message provider first reads a synchronous localStorage snapshot for the selected chat. The cache provider limits this snapshot to the last 200 messages. It then loads messages from the Dexie and Convex paths and replaces the displayed state with that result.
This makes recent history available before a network round trip and permits reading cached conversations offline. A new model response still needs the selected gateway. Local history and live generation have different availability requirements.
Two successive loads are not a complete conflict-resolution protocol. The implementation needs tests for stale snapshots, a chat change during loading, failed cache reads, duplicate optimistic messages and branch updates. The current message provider can clear the visible list after a cache-load failure, so I do not claim that every offline or reconnect case preserves the displayed history.
The API uses streamText and returns a UIMessageStreamResponse with no-store caching. The inspected route and useChat integration do not implement resumable streams. Closing a tab or disconnecting from the network can end a response; reconnecting does not establish that the same generation resumes.
The route maps unsupported models to a 400 error, exhausted quota to 402, rate limits to 429 and internal failures to 500. These codes let the interface distinguish a configuration problem from a failed generation. A model-quality score would not test those application behaviors.
The client stores bring-your-own-key settings in browser storage. Requests can send user keys to the server route, which forwards model requests to the configured service. Keys therefore do not remain exclusively on the device during generation. Browser persistence is not an encryption guarantee.
Clerk provides account integration, and uploads use Uploadthing. These are external services with separate availability and permission boundaries. The project should expose failures from each service as actionable interface states.
The gallery contains the existing chat demonstration and interface screenshots. They show selected interface behavior. No disconnected-stream recovery measurement, multi-client conflict test or conversational-quality evaluation is reported here.
My contribution is the chat application and its integration of model gateways, state, caches and error handling. The models, database service and SDK are supplied by their respective providers. The source repository is the durable reference while the hosted domain is unavailable.
Completion, cancellation and partial replies
Deterministic request-state modelStep through a local request-state model and compare displayed text with a cacheable reply.
Interactive controls load when this figure enters view.
This local state machine uses five fixed text chunks and makes no provider request. Only completion marks a reply as cacheable. It illustrates cancellation and error handling, rather than executing the yo CLI or ChaiChat or measuring their provider reliability.
The corrected error helper handles typed 429 responses and undefined or structured provider errors. It checks insufficient_quota before rate limiting, so an exhausted balance does not suggest a retry. The streaming error path receives a usable message instead of crashing during normalization.
Six regression tests pass, with 17 assertions. Five fail against the original helper. The tests exercise the actual helper. They do not call a paid provider or verify database hydration, cached state, resumable streaming or the full app build.
Download the uncommitted source correction and tests. Read the source and file-hash manifest. The public app has not been deployed with this correction.