UNPKG

@llamaindex/ui

Version:

A comprehensive UI component library built with React, TypeScript, and Tailwind CSS for LlamaIndex applications

221 lines (207 loc) 8.42 kB
import * as react_jsx_runtime from 'react/jsx-runtime'; import { JSONSchema } from 'zod/v4/core'; import { ExtractedData, ExtractedFieldMetadata, ExtractedFieldMetadataDict, TypedAgentData, AgentClient } from 'llama-cloud-services/beta/agent'; /** * JSON SCHEMA-BASED RECONCILIATION DESIGN * ======================================= * * PURPOSE: * Uses JSON Schema to reconcile extracted data with schema definitions, * filling missing optional fields for UI display and providing field metadata. * * CORE ALGORITHM: * 1. Parse JSON Schema to identify all defined fields * 2. Extract field metadata (title, required status, type) * 3. Fill missing optional fields with undefined values * 4. Provide field display information for UI rendering * * ADVANTAGES: * - Standard JSON Schema format with title support * - Clear required/optional field distinction * - Rich metadata for UI display (title, description) * - Compatible with existing schema infrastructure */ /** * Field metadata for UI rendering */ interface FieldSchemaMetadata { /** Whether this field is required by schema */ isRequired: boolean; /** Whether this field can be null/undefined */ isOptional: boolean; /** The JSON schema type */ schemaType: string; /** Field title from schema for display */ title?: string; /** Field description from schema */ description?: string; /** Whether this field was missing from original data */ wasMissing: boolean; } /** * UNIFIED FIELD METADATA DESIGN * ============================= * * We use normalized paths with "*" wildcards to represent array item schemas: * - "users.*" - represents the schema for any item in the users array * - "users.*.contact.email" - represents email field of any user's contact * * This eliminates the need for separate itemType field and unifies * list-renderer and table-renderer to use the same lookup mechanism. * * Example: * { * "tags.*": { schemaType: "string", isRequired: false }, * "users.*.name": { schemaType: "string", isRequired: true }, * "users.*.age": { schemaType: "number", isRequired: false } * } */ /** * Validation error for a specific field */ interface ValidationError { /** The field path where error occurred */ path: string[]; /** Error message from zod */ message: string; /** Zod error code */ code: string; } interface ExtractedDataDisplayProps<S extends JsonShape<S>> { extractedData: ExtractedData<S>; title?: string; emptyMessage?: string; onChange?: (updatedData: S) => void; editable?: boolean; jsonSchema?: JSONSchema.ObjectSchema; onClickField?: (args: { value: PrimitiveValue; metadata?: ExtractedFieldMetadata; path: string[]; }) => void; } interface RendererMetadata { schema: Record<string, FieldSchemaMetadata>; extracted?: ExtractedFieldMetadataDict; } type PrimitiveValue = string | number | boolean | null | undefined; type JsonObject = { [k: string]: JsonValue; }; type JsonValue = PrimitiveValue | JsonObject | JsonValue[] | object; type JsonShape<T> = { [K in keyof T]: JsonValue; }; declare function ExtractedDataDisplay<S extends JsonShape<S>>({ extractedData, emptyMessage, onChange, editable, jsonSchema, onClickField, }: ExtractedDataDisplayProps<S>): react_jsx_runtime.JSX.Element; declare function getConfidenceBackgroundClass(threshold: number, confidence?: number): string; /** * Primitive field types for validation and UI rendering */ declare enum PrimitiveType { STRING = "string", NUMBER = "number", BOOLEAN = "boolean" } interface EditableFieldProps<S extends PrimitiveValue> { value: S; onSave: (newValue: S) => void; expectedType?: PrimitiveType; required?: boolean; isChanged?: boolean; showBorder?: boolean; className?: string; editable?: boolean; metadata?: ExtractedFieldMetadata; onClick?: (args: { value: S; metadata?: ExtractedFieldMetadata; }) => void; } declare function EditableField<S extends PrimitiveValue>({ value, onSave, isChanged, showBorder, expectedType, required, className, metadata, onClick, editable, }: EditableFieldProps<S>): react_jsx_runtime.JSX.Element; interface TableRendererProps<Row extends JsonObject> { data: Row[]; onUpdate: (index: number, key: string, value: JsonObject, affectedPaths?: string[]) => void; onAddRow?: (newRow: Row) => void; onDeleteRow?: (index: number) => void; changedPaths?: Set<string>; keyPath?: string[]; metadata?: RendererMetadata; validationErrors?: ValidationError[]; onClickField?: (args: { value: PrimitiveValue; metadata?: ExtractedFieldMetadata; path: string[]; }) => void; editable?: boolean; } declare function TableRenderer<Row extends JsonObject>({ data, onUpdate, onAddRow, onDeleteRow, changedPaths, keyPath, metadata, validationErrors, onClickField, editable, }: TableRendererProps<Row>): react_jsx_runtime.JSX.Element; interface ListRendererProps<S extends PrimitiveValue> { data: S[]; onUpdate: (index: number, value: S) => void; onAdd?: (value: S) => void; onDelete?: (index: number) => void; changedPaths?: Set<string>; keyPath?: string[]; metadata?: RendererMetadata; onClickField?: (args: { value: PrimitiveValue; metadata?: ExtractedFieldMetadata; path: string[]; }) => void; editable?: boolean; } declare function ListRenderer<S extends PrimitiveValue>({ data, onUpdate, onAdd, onDelete, changedPaths, keyPath, metadata, onClickField, editable, }: ListRendererProps<S>): react_jsx_runtime.JSX.Element; interface PropertyRendererProps<S extends JsonShape<S>> { keyPath: string[]; value: JsonValue; onUpdate: (path: string[], newValue: JsonValue, additionalPaths?: string[][]) => void; changedPaths?: Set<string>; metadata?: RendererMetadata; validationErrors?: ValidationError[]; onClickField?: (args: { value: PrimitiveValue; metadata?: ExtractedFieldMetadata; path: string[]; }) => void; editable?: boolean; } declare function PropertyRenderer<S extends JsonShape<S>>({ keyPath, value, onUpdate, changedPaths, metadata, validationErrors, onClickField, editable, }: PropertyRendererProps<S>): react_jsx_runtime.JSX.Element; interface ConfidenceThresholdSettingsProps { onThresholdChange?: (value: number) => void; min?: number; max?: number; step?: number; className?: string; defaultThreshold?: number; } declare function ConfidenceThresholdSettings({ onThresholdChange, defaultThreshold, min, max, step, className, }: ConfidenceThresholdSettingsProps): react_jsx_runtime.JSX.Element; interface ItemHookData<T extends JsonShape<T>> { /** the complete item object from API containing both AI predictions and user corrections */ item: TypedAgentData<ExtractedData<T>> | null; /** the JSON schema used for validation and reconciliation */ jsonSchema: JSONSchema.ObjectSchema; /** AI's original predictions (readonly reference) */ originalData: T | null; /** current user-corrected data (what gets saved) */ data: T | null; /** whether the data is loading from the API */ loading: boolean; /** a load or parse error */ error: string | null; /** updates the user-corrected data */ updateData: (data: T) => void; /** saves the current user-corrected data and any metadata updates */ save: (status: "approved" | "rejected") => Promise<void>; } interface UseItemDataOptions<T extends JsonShape<T>> { jsonSchema: JSONSchema.ObjectSchema; itemId: string; isMock: boolean; client: AgentClient<ExtractedData<T>>; } declare function useItemData<T extends JsonShape<T>>({ jsonSchema, itemId, isMock, client, }: UseItemDataOptions<T>): ItemHookData<T>; declare function AcceptReject<T extends JsonShape<T>>({ itemData, onComplete, }: { itemData: ItemHookData<T>; onComplete?: () => void; }): react_jsx_runtime.JSX.Element; export { AcceptReject, ConfidenceThresholdSettings, EditableField, ExtractedDataDisplay, type ExtractedDataDisplayProps, type ItemHookData, type JsonObject, type JsonShape, type JsonValue, ListRenderer, type PrimitiveValue, PropertyRenderer, type RendererMetadata, TableRenderer, type UseItemDataOptions, getConfidenceBackgroundClass, useItemData };