What is an artifact?
An artifact is a TypeScript object that implements theArtifact interface:
- id: Unique identifier for tracking and debugging
- type: One of
"text","image","pdf", or"file" - raw: Function that returns the original buffer (for caching/debugging)
- contents: Array of content slices with text and/or media
- metadata: Optional key-value metadata
- tokens: Optional pre-computed token count
Artifact contents
Thecontents array contains ArtifactContent objects that represent slices of the artifact:
- page: Optional page number (useful for PDFs)
- text: Text content for this slice
- media: Array of embedded images with position/size data
Creating artifacts
Struktur provides several helper functions to create artifacts from different sources.From JSON URLs
Load pre-serialized artifacts from a URL:raw function and with images as URLs or base64).
From files
Convert files to artifacts using MIME type detection:Using providers
For custom file types (like PDFs), register an artifact provider:From text
Create a simple text artifact:Common use cases
Single-page document
Single-page document
For simple text documents, create a single artifact with one content entry:
Multi-page PDF
Multi-page PDF
For PDFs, create one content entry per page:
Document with images
Document with images
Embed images in content slices where they appear:
Validation
Struktur validates serialized artifacts against a JSON schema before hydration:Design philosophy
Artifacts are designed to be:- Format-agnostic: The same structure works for text, PDFs, images, and custom formats
- Serializable: Can be saved to JSON and loaded via
urlToArtifact - Normalized: All content is pre-parsed into consistent text/media slices
- Extensible: Use providers to add support for any format