@hashgraphonline/conversational-agent
Version:
Hashgraph Online conversational AI agent implementing HCS-10 communication, HCS-2 registries, and content inscription on Hedera. https://hol.org
119 lines (117 loc) • 3.92 kB
TypeScript
import { z, ZodError } from 'zod';
import { FormMessage } from './types';
/**
* Generates forms from Zod validation failures
*/
export declare class FormGenerator {
private logger;
constructor();
/**
* Creates a form message from a Zod validation error
* @param error The Zod validation error
* @param schema The original Zod schema
* @param toolName Name of the tool that failed validation
* @param originalPrompt The user's original request
* @returns FormMessage to send to the chat UI
*/
generateFormFromError(error: ZodError, schema: z.ZodSchema, toolName: string, originalPrompt: string): FormMessage;
/**
* Generates a form from a schema and partial input
* @param schema The Zod schema to generate a form from
* @param partialInput Any partial input already provided
* @param context Additional context about the tool
* @param preCalculatedMissingFields Optional pre-calculated missing fields set. If undefined, includes all fields from schema.
* @returns FormMessage to send to the chat UI
*/
generateFormFromSchema(schema: z.ZodSchema, partialInput: unknown, context: {
toolName: string;
toolDescription?: string;
}, preCalculatedMissingFields?: Set<string>): Promise<FormMessage>;
/**
* Extracts validation errors from ZodError
*/
private extractValidationErrors;
/**
* Identifies which fields are missing or invalid from validation errors
*/
private identifyMissingFields;
/**
* Creates form configuration from schema
*/
private createFormConfig;
/**
* Safely extracts render configs from schema
*/
private extractRenderConfigsSafely;
/**
* Safely generates field ordering from schema
*/
private generateFieldOrderingSafely;
/**
* Determines field priority for progressive disclosure
*/
private getFieldPriority;
/**
* Determines which fields should be included in the form
*/
private determineFieldsToInclude;
/**
* Includes required fields that are missing
*/
private includeRequiredMissingFields;
/**
* Creates form fields from ordered field names
*/
private createOrderedFields;
/**
* Generates form fields from schema and validation errors
*/
private generateFormFields;
/**
* Creates a single form field
*/
private createFormField;
/**
* Maps render config field type to form field type with fallback inference
*/
private mapFieldType;
/**
* Converts field name to human-readable label
*/
private humanizeFieldName;
/**
* Generates a title for the form
*/
private generateFormTitle;
/**
* Safely extracts ZodObject from a schema, returns null if not an object schema
*/
private extractZodObject;
/**
* Extracts field names from Zod schema structure
*/
private extractFieldsFromSchema;
/**
* Infers field type from Zod schema
*/
private inferTypeFromSchema;
/**
* Determines if a field is required based on the Zod schema
*/
private isFieldRequired;
/**
* Generates a description for the form
*/
private generateFormDescription;
/**
* Generates JSON Schema and uiSchema from a Zod schema for use with @rjsf/core
* @param zodSchema The Zod schema to convert
* @param partialInput Existing input data to filter out fields that already have values
* @param missingFields Set of fields that are missing and should be shown
* @returns Object containing jsonSchema and uiSchema
*/
generateJsonSchemaForm(zodSchema: z.ZodObject<z.ZodRawShape>, partialInput?: Record<string, unknown>, missingFields?: Set<string>): {
jsonSchema: Record<string, unknown>;
uiSchema: Record<string, unknown>;
};
}