createCard
Creates a new card in Teak. The card type can be auto-detected based on content, or explicitly specified. All cards go through an AI processing pipeline for metadata extraction, categorization, and enhancement.Arguments
The main content of the card. For text cards, this is the primary text. For links, this can include the URL or description. For quotes, quotation marks are automatically normalized.
The type of card to create. If omitted, Teak will automatically detect the type based on content analysis.Supported types:
text- Plain text noteslink- Web links with automatic metadata extractionimage- Image files with AI vision analysisvideo- Video files with thumbnail generationaudio- Audio recordings with transcriptiondocument- PDF and document filespalette- Color palettes with hex codesquote- Quoted text with automatic formatting
URL associated with the card. Automatically extracted from content if not provided. Required for link cards to enable metadata extraction.
Storage ID of the uploaded file. Use
ctx.storage.store() to upload files first, then pass the returned ID here.Required for: image, video, audio, document card types.Storage ID of a custom thumbnail image. If not provided, thumbnails are auto-generated for supported media types.
User-defined tags for organizing and filtering cards. These are separate from AI-generated tags.
Additional notes or context about the card. Searchable and indexed separately from main content.
Custom metadata object. File-related fields (fileName, fileSize, mimeType, duration, width, height) are automatically extracted to
fileMetadata.Array of color objects for palette cards. If creating a palette card without colors, Teak will attempt to extract colors from the content, notes, or tags.
Returns
The unique identifier of the newly created card. Use this to query the card or perform updates.
Behavior
Auto-detection Logic
Auto-detection Logic
When
type is not provided, Teak uses the following rules:- Quote detection: If content contains quotation marks that are removed during normalization, type is set to
"quote" - URL extraction: URLs are automatically extracted from content and set in the
urlfield - Default fallback: If no specific type is detected, defaults to
"text" - Classification pipeline: Auto-detected cards enter the classification stage for AI-based type detection
Processing Pipeline
Processing Pipeline
After creation, cards automatically enter a multi-stage processing workflow:
- Classification (if type auto-detected)
- AI determines the most appropriate card type
- Extracts palette colors for visual content
- Categorization (for link cards)
- Waits for metadata extraction to complete
- Assigns category based on link content
- Metadata Extraction
- Links: Fetches page title, description, preview images
- Media: Generates AI tags and summaries
- Audio: Creates transcripts
- Renderables Generation
- Creates thumbnails for images and videos
- Skips if original file is already small
Rate Limiting
Rate Limiting
The
ensureCardCreationAllowed() function checks:- User authentication
- Rate limits (prevents spam)
- Card count limits (subscription-based)
Quote Formatting
Quote Formatting
For quote cards, content is automatically normalized:
- Removes leading/trailing quotation marks
- Preserves internal quotes
- Stores normalized version in database
Palette Color Extraction
Palette Color Extraction
When creating a palette card without explicit colors:
- Combines content, notes, and tags into analysis text
- Extracts up to 12 colors using
extractPaletteColors() - Builds color facets (hex codes and hue categories)
- Enables color-based search and filtering
Error Handling
Thrown when no authenticated user session is found.
Thrown by
ensureCardCreationAllowed() when rate limits are hit.Thrown when user has reached their subscription’s card limit.
Source Reference
Implemented inpackages/convex/card/createCard.ts:192