TemplatesArtifacts

Chart Artifact

Loading pattern preview

Problems solved

Technical challenges this implementation handles out of the box.
  • Generate burn-rate chart artifacts from financial chat requests
  • Stream progressive chart data while analysis runs
  • Compute runway and expense insights alongside the visualization

Use cases

Products and workflows this pattern is designed to support.
  • Startup burn-rate dashboards
  • Finance copilots that plot runway
  • Budget review chats with live charts
  • Investor update visualization tools

Setup

Requirements, wiring steps, and what this pattern adds to your project.

Getting started

Pick how you want to pull this pattern in. Then wire env vars and routes the same way.

  1. 1

    Download → Next.js app

    Use Download → Next.js app in the preview toolbar. You get a zip scaffold (Pro downloads rewrite preview `/view/.../api/*` paths to `/api/*` automatically).

  2. 2

    Extract the zip and install dependencies

    Unzip the archive, then run `pnpm install` (or npm / yarn) in the project folder.

  3. 3

    Fill .env.local

    The download includes .env.local placeholders when needed. Add real values for: OPENAI_API_KEY.

  4. 4

    Customize the agent and tool files

    Adapt prompts, tools, and stop conditions in the generated project for your product.

  5. 5

    Run the app and open the pattern route

    Run `pnpm dev`, open the setup/checklist page if present, then navigate to the generated pattern route and verify responses.

Environment variables

Capabilities

AI SDK APIs

streamTextconvertToModelMessagestool

Providers

OpenAI

External services

Upstash

Files added

25 files
  • app/page.tsx
  • app/layout.tsx
  • app/api/artifact/route.ts
  • components/burn-rate-chat.tsx
  • components/expandable-panel.tsx
  • components/burn-rate-analysis-panel.tsx
  • components/burn-rate-chart.tsx
  • components/burn-rate-loading.tsx
  • components/left-panel-chat.tsx
  • components/message-input.tsx
  • components/message-list.tsx
  • components/chat-message-card.tsx
  • components/intro-heading.tsx
  • components/right-panel-artifact.tsx
  • components/right-panel-header.tsx
  • components/status-indicator.tsx
  • components/types.ts
  • hooks/use-artifact-panel-state.tsx
  • hooks/use-burn-rate-artifact.ts
  • lib/error-handler.ts
  • lib/ai/context.ts
  • lib/ai/tools/index.ts
  • lib/ai/tools/burn-rate.ts
  • lib/ai/artifacts/burn-rate.ts
  • README.md

Dependencies

18 total

npm packages

9
AISDKgeistlucide-reactmotionReactrechartssonnerZodreact-resizable-panels

Shadcn IconRegistry components

9
alertbadgebuttoncalendarcardchartprogressresizabletooltip

Critical files

  • artifact/route.ts

    API route for the burn rate chart artifact. Uses runWithContext for AsyncLocalStorage context, streamText with the analyzeBurnRate tool.

  • tools/burn-rate.ts

    Implements the analyzeBurnRateTool with a 4-stage progressive streaming pipeline: loading, processing, analyzing, and complete. Uses BurnRateArtifact.stream() for progressive UI updates.

  • artifacts/burn-rate.ts

    Defines BurnRateArtifact via artifact(). Zod schema captures: title, stage, currency, progress, chartData array, and optional summary with trends and alerts.

  • ai/context.ts

    AsyncLocalStorage-based context management for the chart artifact. Provides runWithContext, getContext, getWriter.

Requirements

Complexity
Intermediate
Setup time
~15 minutes
Node
24+
Memory
512MB
Upstash Redis