AI SDK Tools
AI SDK Tools

Advanced streaming interfaces for AI applications.

Create structured, type-safe artifacts that stream real-time updates from AI tools to React components. Perfect for dashboards, analytics, documents, and interactive experiences beyond simple chat interfaces.

npm install @ai-sdk-tools/artifacts @ai-sdk-tools/store
Animated Toast Notifications
Live Notifications
● Streaming
Analysis Complete
Q4 burn rate analysis finished successfully
Processing Data
Streaming real-time updates...
Live Panel
● Loading
Document Analysis
65%
Extracting insights from financial reports...
Live Dashboard
● Active
Revenue
$2.4M
+12.5%
Users
1.2K
+8.3%
Recent Activity
New user registered
Payment processed
Report generated

Structured Artifacts

Define typed artifact schemas with Zod validation for consistent, type-safe data structures.

Real-time Streaming

Stream live updates from AI tools to React components with progress tracking and error handling.

Typed Context

Share typed context across all tools with validation and type-safe access patterns.

React Integration

Simple useArtifact hook with callbacks for updates, completion, errors, and progress tracking.

Error Handling

Built-in error handling with custom error types, timeout support, and cancellation methods.

Global State

Built on @ai-sdk-tools/store for global state access - no prop drilling required.

Backend Setup & Hook Usage

Complete example showing backend artifact streaming and frontend useArtifact hook with all event callbacks.

Backend: Define & Stream Artifacts
import { artifact } from '@ai-sdk-tools/artifacts'
import { z } from 'zod'
import { tool } from 'ai'

// Define artifact schema
const Dashboard = artifact('dashboard', z.object({
  title: z.string(),
  metrics: z.object({
    revenue: z.number(),
    users: z.number(),
    conversion: z.number()
  }),
  status: z.enum(['loading', 'streaming', 'complete', 'error']),
  progress: z.number().min(0).max(1).default(0)
}))

// AI tool that streams dashboard data
export const analyzeDashboardTool = tool({
  description: 'Analyze business metrics and create live dashboard',
  parameters: z.object({
    company: z.string()
  }),
  execute: async ({ company }) => {
    const dashboard = Dashboard.stream({
      title: `${company} Analytics Dashboard`,
      status: 'loading',
      progress: 0,
      metrics: { revenue: 0, users: 0, conversion: 0 }
    })

    await dashboard.update({
      status: 'streaming',
      progress: 0.5,
      metrics: { revenue: 2500000, users: 12500, conversion: 3.2 }
    })

    await dashboard.complete({
      status: 'complete',
      progress: 1.0,
      metrics: { revenue: 3000000, users: 15200, conversion: 3.8 }
    })

    return 'Analysis complete'
  }
})
Frontend: useArtifact Hook Events
import { useArtifact } from '@ai-sdk-tools/artifacts'
import { useState } from 'react'

function DashboardComponent() {
  const { 
    data, 
    status, 
    progress, 
    error, 
    isActive 
  } = useArtifact(Dashboard, {
    onUpdate: (newData) => {
      console.log('Data updated:', newData)
    },
    onComplete: (finalData) => {
      console.log('Analysis complete!', finalData)
    },
    onError: (error) => {
      console.error('Analysis failed:', error)
    },
    onProgress: (progress) => {
      console.log('Progress:', Math.round(progress * 100) + '%')
    },
    onStatusChange: (newStatus, prevStatus) => {
      console.log('Status:', prevStatus, '', newStatus)
    }
  })

  if (!data && !isActive) {
    return <div>No data available</div>
  }

  return ...
}

Get started

Artifacts requires the store package to work properly, so make sure to install both.

npm install @ai-sdk-tools/artifacts @ai-sdk-tools/store

Comprehensive artifact handling for AI applications.