Skip to content

laguagu/claude-code-nextjs-skills / skills/nextjs-chatbot

nextjs-chatbot

Verified

Production Next.js web-chat integration: tool approval, persisted conversations, tool result UI, grounded retrieval, follow-up suggestions and embedded widgets. Use when building or debugging a web chatbot that needs these features. Use nextjs-shadcn for scaffolding and ai-sdk for general SDK APIs; multi-platform bots use Chat SDK.

FileKindSize
SKILL.mdskill md5.6 KB
hitl.mdmarkdown4.1 KB
persistence.mdmarkdown4.0 KB
popup-widget.mdmarkdown1.6 KB
search.mdmarkdown1.8 KB
suggestions.mdmarkdown1.4 KB
testing.mdmarkdown2.2 KB
tool-rendering.mdmarkdown1.7 KB
web-search.mdmarkdown1.6 KB

persistence.md

View on GitHub
# Conversation persistence

Use stable conversation and message IDs shared by the UI, storage and feedback
API. Authenticate ownership on every history, message, feedback, delete and
resume operation; possession of an ID is not authorization.

Keep the user message IDs generated by `useChat`. Give assistant responses a
server ID through the UI stream's `generateMessageId` (for example,
`createIdGenerator({ prefix: 'msg', size: 16 })`) or an explicit `start` part's
`messageId`. Pass `originalMessages` to preserve an assistant's ID on tool/
approval continuation. Without a shared server ID the client can invent one
that differs from the saved row, breaking feedback and later updates.

Store validated `UIMessage` data when restoring the same tool/source interface
matters. Keep schema/version information for migrations and retention rules.
If messages reference a session row, await its creation before dependent
writes. Make completion saves idempotent with an appropriate unique key; do
not replace missing IDs with history-array positions.

## Model replay

Prefer server-owned history plus a validated new client message. Validate
stored tools, metadata and custom data parts with compatible schemas before
processing. Use the installed `convertToModelMessages` contract, including its
async behavior. See [message persistence](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-message-persistence).

UI storage and model context are different concerns. Select complete turns
within the context budget, preserving required tool-call/result and reasoning/
provider relationships. Do not blanket-delete every `tool-*`, step or
`providerMetadata` part.

An OpenAI Responses item ID can depend on associated reasoning items or
provider-stored state. Persisted parts keep `providerMetadata.openai.itemId`, which the provider
replays as an item reference, so the second question of a restored thread can
fail with `Item 'msg_…' of type 'message' was provided without its required
'reasoning' item: 'rs_…'`. If restored replay fails,
inspect the retained sequence and the provider's supported replay mode. A
deliberately stateless text-only history may require removing provider IDs and
dependent parts together; that is a provider-specific conversion decision, not
a universal repair. Test the second question after a reload against the actual
provider.

## Completion and feedback

Save from the UI stream completion callback: `onEnd` in v7, `onFinish` in v6.
With `originalMessages`, it receives the updated `messages`, `responseMessage`
and `isAborted`; distinguish completion, failure and cancellation rather than
marking every callback a successful answer. Inspect the installed stream layer's
payload rather than assuming every API returns the full conversation.

Feedback can arrive before the assistant row is committed. Represent that
pending state explicitly and use bounded retries or a server queue. Associate
each retry with the current vote/generation so an older request cannot overwrite
a later choice. Preserve optimistic state only after a confirmed write; handle
non-success responses.

## Disconnect, resume and deletion

Choose whether cancellation should stop model work. `result.consumeStream()`
before returning the response (without awaiting it) drains the generation so
the save can run after a disconnect within the hosting lifetime; it does not
survive a process crash by itself. An explicit model abort still stops the work.

[Resumable streams](https://ai-sdk.dev/docs/ai-sdk-ui/chatbot-resume-streams)
need stream storage, conversation-to-stream mapping and authorized endpoints.
`resume: true` alone does not implement storage or durable execution. In a
resumable setup, `stop()` closes the client connection while generation can
continue. An explicit stop endpoint must persist the partial response, cancel
the active work and clear its stream record without clearing a newer stream.

Database cascades delete related database rows. Define cleanup for uploaded
files, external stores, traces and backups separately.
brainstormingobra/superpowersYou MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).Stars: 322kUpdated Claude CodeCodexVerifiedInstall
brand-guidelinesanthropics/skillsApplies Anthropic's official brand colors and typography to any sort of artifact that may benefit from having Anthropic's look-and-feel. Use it when brand colors or style guidelines, visual formatting, or company design standards apply.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
frontend-designanthropics/skillsGuidance for distinctive, intentional visual design when building new UI or reshaping an existing one. Helps with aesthetic direction, typography, and making choices that don't read as templated defaults.Stars: 198kUpdated Claude CodeCodexVerifiedInstall
mcp-builderanthropics/skillsGuide for creating high-quality MCP (Model Context Protocol) servers that enable LLMs to interact with external services through well-designed tools. Use when building MCP servers to integrate external APIs or services, whether in Python (FastMCP) or Node/TypeScript (MCP SDK).Stars: 198kUpdated Claude CodeCodexVerifiedInstall