Overview
Artifacts is a structured tool return format used to render rich content (HTML, code, diff, charts, etc.) in the Trajectory area instead of displaying raw text. Rendering adopts a VSCode light style with Prism.js syntax highlighting and line numbers.Background
Current tool return results have the following issues:- Inconsistent formats: Different tools return different formats
- Difficult frontend parsing: Relies on regex to detect content types
- Limited rendering: Cannot distinguish renderable content from plain text
- Poor extensibility: Every new type requires modifying frontend detection logic
Data Structure Design
ToolResultContent
Structured representation of tool return content with the following fields:| Field | Type | Description |
|---|---|---|
type | string | Content type (see table below) |
data | string | Content data |
language | string (optional) | Programming language identifier |
title | string (optional) | Title (also used for language detection via file extension) |
meta | object (optional) | Additional metadata (e.g. old_content for diff) |
ToolResult
Standard tool return format:| Field | Type | Description |
|---|---|---|
success | boolean | Whether successful |
message | string | Result message (concise, for LLM consumption) |
content | ToolResultContent (optional) | Structured content (for user display) |
file_path | string (optional) | Associated file path |
files | SandboxFile[] (optional) | List of generated files |
SandboxFile
File metadata returned by sandbox operations:| Field | Type | Description |
|---|---|---|
name | string | File name |
type | string | File type (document, code, image, other) |
sandbox_path | string | File path inside the sandbox |
url | string (optional) | Cloud storage URL (e.g. Supabase Storage) |
content | string (optional) | File content or base64 |
size | number (optional) | File size in bytes |
Content Types
| type | Description | Rendering Method |
|---|---|---|
text | Plain text | <pre> or Markdown renderer (auto-detected) |
html | HTML content | <iframe> sandbox rendering |
markdown | Markdown | Markdown renderer |
code | Code | Prism.js syntax-highlighted CodeBlock with line numbers |
json | JSON data | Prism.js highlighted JSON viewer with line numbers |
image | Image | <img> |
error | Error message | Red error styling |
Diff Rendering
Foredit and write tool results, when meta.old_content is present, the frontend renders a DiffPreview component instead of the standard artifact renderer. This provides a Cursor-like split/unified diff view.
How It Works
- Backend: The
writetool reads the file’s previous content before overwriting, and theedittool captures the original file content before applying changes. Both store the old content incontent.meta.old_content. - Frontend: The
WorkspaceAreacomponent detectsedit/writeresults containingmeta.old_contentand renders aDiffPreviewusingreact-diff-viewer-continued, with Prism.js syntax highlighting based on the file extension. - Fallback: For
editcalls wheremeta.old_contentis unavailable, the frontend falls back to diffingparameters.old_stringvsparameters.new_string(snippet-level diff).
Diff Stats on ToolCallCard
When a tool call completes, theToolCallCard header displays inline diff statistics (+N / -N) computed from the old and new content. This gives users an at-a-glance view of how much code was added or removed.
Frontend Rendering
The frontend selects the corresponding rendering component based on thecontent.type field:
- HTML: Sandbox iframe preview with device-width presets (desktop/tablet/mobile) and deploy capability
- Markdown: Full Markdown renderer
- Code: VSCode-inspired light-themed table layout with line numbers, Prism.js syntax highlighting, and collapsible long files (>20 lines)
- JSON: Same table-based layout as code, with JSON-specific highlighting
- Image: Direct
<img>display - Error: Red error styling
- Diff (edit/write): Unified diff view with added/removed line highlighting
Raw Mode
The workspace area supports toggling between Preview and Raw mode. Raw mode displays parameters and results as Prism.js-highlighted JSON with a copy button on section headers, replacing the previous Monaco Editor-based approach for lighter weight and faster rendering.Backward Compatibility
- The frontend supports both new and old formats
- Old format (plain text) is wrapped as content with
type: "text" - Progressive migration without affecting existing functionality