JDS.

Search docs

Find a page or component

Response

Markdown renderer that is safe to stream. Closes unterminated syntax as it arrives and highlights code with Shiki.

Retry with backoff

Wrap the call and double the delay after each failure:

ts
async function retry<T>(fn: () => Promise<T>, tries = 3) {  for (let i = 0; ; i++) {    try {      return await fn()    } catch (e) {      if (i >= tries - 1) throw e      await new Promise((r) => setTimeout(r, 2 ** i * 250))    }  }}
  • Cap the delay so users aren't left waiting
  • Only retry idempotent requests

Installation

pnpm dlx shadcn@latest add @jds/response

Usage

import { Response } from "@/components/ai/response"

<Response isAnimating={status === "streaming"}>{part.text}</Response>

API Reference

Response

PropTypeDefault
children

Markdown source.

string–
isAnimating

Streaming mode: fades in new tokens and repairs partial syntax.

booleanfalse