@snowcone-app/chat-contracts
v0.3.0
Published
Wire contract for the Snowcone chat orchestrator — AI SDK UIMessage data-part payloads and UI Message Stream chunk types, shared by the backend emitter, www /create, and third-party chat clients.
Maintainers
Readme
@snowcone-app/chat-contracts
Types for the Snowcone AI design-chat wire contract.
Snowcone's chat endpoint (POST https://api.snowcone.app/ai-generations/chat/stream)
speaks the AI SDK UI Message Stream protocol over SSE, so any AI SDK v5+/v6
client (useChat, assistant-ui, …) can consume it directly. This package is the
typed contract for what streams back: the data-part payloads (generated images,
product suggestions, mockup cards, committed designs, progress stages) and the
chunk union.
Full integration guide: https://developers.snowcone.app/guides/ai-chat
Install
npm install @snowcone-app/chat-contractsTyping your messages
import { useChat } from "@ai-sdk/react";
import type { UIMessage } from "ai";
import type { SnowconeChatDataParts } from "@snowcone-app/chat-contracts";
type SnowconeUIMessage = UIMessage<never, SnowconeChatDataParts>;
const { messages, sendMessage } = useChat<SnowconeUIMessage>({ /* … */ });Every part in message.parts is then discriminated: data-images,
data-products, data-mockup, data-design, plus the transient data-stage
progress labels.
Data parts
| Part type | Payload | Meaning |
|---|---|---|
| data-images | ChatImagesData | AI-generated or processed artwork this turn (image count varies by pipeline — don't assume a fixed grid) |
| data-products | ChatProductsData | Product suggestions from catalog search — price/lowestPrice are integer USD cents (3772 = $37.72) |
| data-mockup | ChatMockupData | A product mockup preview card, including the variantId it was rendered for |
| data-design | ChatDesignData | Result of an explicit save/commit |
| data-stage | ChatStageData | Transient progress label ("generating image", …) — rendered live, never persisted |
A data-mockup part carries viewUrl/editorUrl only for a committed
design; a stateless preview has neither, and your UI should offer a Save
affordance instead (the orchestrator never auto-commits). When committing,
pass the part's variantId along so the saved design renders the same
variant (color) the user previewed.
Server helpers
UI_MESSAGE_STREAM_HEADERS, encodeSseChunk, and encodeSseDone are the SSE
framing helpers Snowcone's backend uses to emit the protocol. You only need
them if you re-emit or transform the stream; a pass-through proxy (the normal
integration) does not.
License
MIT
