CentercodeDitto
DittoPorygonAPI

AIContextEditor

Markdown editor with preview and version history for AI context

Overview

AIContextEditor provides a markdown-based editor for managing AI context instructions. It includes write/preview tabs, version history, file attachments, and token estimation. Use the full editor when space allows, or AIContextEditorLauncher for space-constrained contexts.

Key Features

  • Markdown editing with live preview
  • Token count estimation for context budgeting
  • Version history with restore functionality
  • File attachments with parsing status
  • Auto-save drafts to localStorage

Examples

Full Editor Example

Full featured editor with markdown support, file attachments, and version history

~82 tokens

Attached files are parsed by AI and included in the context.

Content length: 328 characters

Launcher Example

Compact launcher button that opens editor in a dialog

Click the button to open the editor in a dialog. Changes are saved to the state when you submit.

Props Reference

AIContextEditor

PropTypeDefaultDescription
valueAIContextValuerequiredCurrent AI context value (content, attachments, parsed content)
onChange(value: AIContextValue) => voidrequiredCallback when content or attachments change
entityTypeContextEntityTyperequiredType of entity this context belongs to (PROGRAM, PROJECT, TRAIT, etc.)
entityIdstringrequiredID of the entity for draft storage key
entityNamestring-Entity name for placeholder text
showHistorybooleanfalseShow the History tab with version restore
versionsAIContextVersionItem[]-Array of version history items
onRestoreVersion(versionId: string) => Promise<void>-Callback to restore a specific version
allowAttachmentsbooleanfalseEnable file attachment section
disabledbooleanfalseDisable editing
minHeightnumber200Minimum height of the textarea in pixels
maxHeightnumber500Maximum height of the textarea in pixels

AIContextEditorLauncher

PropTypeDefaultDescription
valueAIContextValuerequiredCurrent AI context value for the launcher
onChange(value: AIContextValue) => voidrequiredCallback when content changes in the dialog
entityTypeContextEntityTyperequiredType of entity this context belongs to (PROGRAM, PROJECT, TRAIT, etc.)
entityIdstringrequiredID of the entity for draft storage key
entityNamestring-Entity name shown in dialog title
disabledbooleanfalseDisable editing

Usage

import { AIContextEditor, AIContextEditorLauncher } from '@/ui/components';
import type { AIContextValue } from '@/ui/components/ai-context-editor';

// Basic editor usage
const [value, setValue] = useState<AIContextValue>({
  id: null,
  content: '',
  parsedContent: null,
  attachments: [],
});

<AIContextEditor
  value={value}
  onChange={setValue}
  entityType="PROGRAM"
  entityId={programId}
  entityName={programName}
/>

// Launcher pattern (button + dialog)
<AIContextEditorLauncher
  value={value}
  onChange={setValue}
  entityType="TRAIT"
  entityId={traitId}
  entityName="Bug Reports"
/>

// With version history and attachments
<AIContextEditor
  value={value}
  onChange={setValue}
  entityType="PROJECT"
  entityId={projectId}
  entityName={projectName}
  showHistory
  versions={versionHistory}
  onRestoreVersion={handleRestore}
  allowAttachments
  onAttachmentsAdd={handleFilesAdd}
  onAttachmentRemove={handleFileRemove}
/>