@hashgraphonline/conversational-agent
Version:
Hashgraph Online conversational AI agent implementing HCS-10 communication, HCS-2 registries, and content inscription on Hedera. https://hol.org
122 lines (120 loc) • 3.21 kB
TypeScript
import { StructuredTool } from '@langchain/core/tools';
import { ZodError, z } from 'zod';
import { Logger } from '@hashgraphonline/standards-sdk';
import { FormMessage, FormSubmission } from './types';
/**
* Tool execution result with optional form requirement
*/
export interface ToolExecutionResult {
success: boolean;
output: string;
metadata?: Record<string, unknown>;
requiresForm?: boolean;
formMessage?: FormMessage;
error?: string;
}
/**
* Context for form generation operations
*/
export interface FormGenerationContext {
tool: StructuredTool;
input: unknown;
sessionId?: string;
userId?: string;
missingFields?: Set<string>;
}
/**
* FormEngine handles all form generation and validation logic
*/
export declare class FormEngine {
private formGenerator;
private logger;
constructor(logger?: Logger);
/**
* Generate a form for a tool with the given input
*/
generateForm(toolName: string, tool: StructuredTool, input: unknown, context?: Partial<FormGenerationContext>): Promise<FormMessage | null>;
/**
* Process a form submission
*/
processSubmission(submission: FormSubmission, context?: {
originalInput?: Record<string, unknown>;
schema?: unknown;
}): Promise<Record<string, unknown>>;
/**
* Check if a tool requires form generation based on input
*/
shouldGenerateForm(tool: StructuredTool, input: unknown): boolean;
/**
* Generate form from error context
*/
generateFormFromError(error: ZodError, toolName: string, toolSchema: z.ZodSchema, originalPrompt: string): Promise<FormMessage>;
/**
* Generate form for FormValidatable tools
*/
private generateFormValidatableForm;
/**
* Generate form based on schema validation
*/
private generateSchemaBasedForm;
/**
* Generate form based on render config
*/
private generateRenderConfigForm;
/**
* Generate form from Zod validation error
*/
private generateErrorBasedForm;
/**
* Validate input against tool schema
*/
private validateInput;
/**
* Check if schema is ZodObject
*/
private isZodObject;
/**
* Check if tool has render configuration
*/
private hasRenderConfig;
/**
* Extract render configuration from tool
*/
private extractRenderConfig;
/**
* Resolve form schema for FormValidatable tools
*/
private resolveFormSchema;
/**
* Determine missing fields for form generation
*/
private determineMissingFields;
/**
* Generate form with resolved schema
*/
private generateFormWithSchema;
/**
* Validate form submission
*/
private validateSubmission;
/**
* Extract base tool input from context
*/
private extractBaseToolInput;
/**
* Extract submission data
*/
private extractSubmissionData;
/**
* Merge input data
*/
private mergeInputData;
/**
* Get registered strategies
*/
getRegisteredStrategies(): string[];
/**
* Get registered middleware
*/
getRegisteredMiddleware(): string[];
}