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:ToolResult
Standard tool return format:SandboxFile
File metadata returned by sandbox operations:Content Types
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