Skip to main content
Normalized for Mintlify from knowledge-base/neurigraph-memory-architecture/neurigraph-tool-references/09-Artifact-Panel-Starter-Template.mdx.

Clean-Room Specification: Artifact Panel Starter Template

Purpose of This Document

This document specifies the architecture for an artifact panel system that displays AI-generated content alongside a chat interface. When an AI assistant produces code, HTML, documents, diagrams, or other structured output, that content appears in a dedicated resizable side panel with live preview, code editing, and version navigation. The artifact system integrates with the chat primitives (Spec 07) and app shell (Spec 08) through tool calls. This specification enables independent implementation from scratch.

1. Architecture Overview

1.1 Panel Layout

1.2 Component Architecture


2. Artifact Data Model

2.1 Core Types

2.2 Artifact Reference (In-Chat Display)

When the AI creates or updates an artifact, a reference card appears inline in the chat message:

3. State Management

3.1 Artifact Context

3.2 Reducer Actions


4. Tool Integration

4.1 Artifact-Creating Tools

Artifacts are created and updated through AI tool calls. Define tools that the model can invoke:

4.2 Tool Call → Artifact Flow

4.3 Client-Side Tool Result Processing

When the tool result streams back to the client, the artifact context is updated:

5. Content Renderers

5.1 Renderer Selection

5.2 HTML Preview (Sandboxed iframe)

Alternative: Sandpack for richer HTML/JS/CSS previews:

5.3 React Preview (Live Component Rendering)

5.4 Code Editor (Monaco)

5.5 Mermaid Preview


6. Version Navigation

6.1 Version Timeline Component

6.2 Version Content Display

When viewing a non-latest version, the editor shows that version’s content in read-only mode:

7. Resizable Panel

7.1 Resize Handle Implementation

7.2 Panel Width Management


8. Export Functionality


9. Streaming Artifact Content

When the AI generates long artifacts, content streams in progressively:

10. Behavioral Test Cases

Panel Visibility

  1. Hidden by default: Artifact panel is not rendered when no artifact is active.
  2. Opens on creation: When AI creates an artifact via tool call, panel opens automatically.
  3. Opens on click: Clicking an artifact reference card in chat opens the panel.
  4. Closes on X: Clicking close button sets activeArtifactId to null, hiding panel.
  5. Persists across messages: Panel stays open while user sends new messages.

Content Rendering

  1. HTML preview: HTML artifacts render in sandboxed iframe with scripts executing.
  2. React preview: JSX artifacts are transpiled and rendered as live React components.
  3. Markdown preview: Markdown renders with GFM tables, code blocks, and LaTeX.
  4. SVG preview: SVG content renders inline with correct dimensions.
  5. Mermaid preview: Mermaid diagrams render as SVG via mermaid.js.
  6. Code preview: Code artifacts show syntax-highlighted read-only view.
  7. Fallback: Unknown kinds render as plain preformatted text.

Code Editor

  1. Syntax highlighting: Monaco editor applies language-appropriate highlighting.
  2. Auto-language detection: Editor language inferred from artifact kind/language.
  3. Live editing: Changes in the editor update artifact content (debounced 500ms).
  4. Read-only for old versions: Non-latest versions show editor in read-only mode.

Version Navigation

  1. Version dots: Each version shows as a dot; active version is highlighted.
  2. Forward/back arrows: Navigate between versions sequentially.
  3. Version content: Navigating to version N shows that version’s content.
  4. Latest auto-select: New versions auto-select as active (scroll to latest).
  5. Version description: Tooltip on each dot shows version description and timestamp.

Tab Switching

  1. Code tab: Shows Monaco editor with raw source code.
  2. Preview tab: Shows rendered output for the artifact kind.
  3. Tab persistence: Switching artifacts preserves tab preference.
  4. Default to preview: Opening an artifact defaults to preview tab.

Resize

  1. Drag resize: Dragging the handle adjusts panel width in real-time.
  2. Min/max bounds: Panel width clamps between 320px and 800px.
  3. Chat panel flex: Chat panel fills remaining space as artifact panel resizes.

Tool Integration

  1. create_artifact tool: Produces new artifact, adds to registry, opens panel.
  2. update_artifact tool: Adds new version to existing artifact, opens panel.
  3. Inline reference: Tool results render as clickable artifact cards in messages.
  4. Streaming preview: During content generation, partial content is displayed live.

Export

  1. Download file: Export produces a file download with correct name and extension.
  2. MIME types: Exported files have correct content types.
  3. Current version: Export always uses the currently displayed version’s content.