@hashgraphonline/conversational-agent 0.1.214 → 0.1.217

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (170) hide show
  1. package/cli/dist/CLIApp.d.ts +9 -0
  2. package/cli/dist/CLIApp.js +127 -0
  3. package/cli/dist/LocalConversationalAgent.d.ts +37 -0
  4. package/cli/dist/LocalConversationalAgent.js +58 -0
  5. package/cli/dist/app.d.ts +16 -0
  6. package/cli/dist/app.js +13 -0
  7. package/cli/dist/cli.d.ts +2 -0
  8. package/cli/dist/cli.js +51 -0
  9. package/cli/dist/components/AppContainer.d.ts +16 -0
  10. package/cli/dist/components/AppContainer.js +24 -0
  11. package/cli/dist/components/AppScreens.d.ts +2 -0
  12. package/cli/dist/components/AppScreens.js +259 -0
  13. package/cli/dist/components/ChatScreen.d.ts +15 -0
  14. package/cli/dist/components/ChatScreen.js +39 -0
  15. package/cli/dist/components/DebugLoadingScreen.d.ts +5 -0
  16. package/cli/dist/components/DebugLoadingScreen.js +31 -0
  17. package/cli/dist/components/LoadingScreen.d.ts +2 -0
  18. package/cli/dist/components/LoadingScreen.js +16 -0
  19. package/cli/dist/components/LoadingScreenDebug.d.ts +5 -0
  20. package/cli/dist/components/LoadingScreenDebug.js +27 -0
  21. package/cli/dist/components/MCPConfigScreen.d.ts +28 -0
  22. package/cli/dist/components/MCPConfigScreen.js +168 -0
  23. package/cli/dist/components/ScreenRouter.d.ts +12 -0
  24. package/cli/dist/components/ScreenRouter.js +22 -0
  25. package/cli/dist/components/SetupScreen.d.ts +15 -0
  26. package/cli/dist/components/SetupScreen.js +65 -0
  27. package/cli/dist/components/SingleLoadingScreen.d.ts +5 -0
  28. package/cli/dist/components/SingleLoadingScreen.js +27 -0
  29. package/cli/dist/components/StatusBadge.d.ts +7 -0
  30. package/cli/dist/components/StatusBadge.js +28 -0
  31. package/cli/dist/components/TerminalWindow.d.ts +8 -0
  32. package/cli/dist/components/TerminalWindow.js +24 -0
  33. package/cli/dist/components/WelcomeScreen.d.ts +11 -0
  34. package/cli/dist/components/WelcomeScreen.js +47 -0
  35. package/cli/dist/context/AppContext.d.ts +68 -0
  36. package/cli/dist/context/AppContext.js +363 -0
  37. package/cli/dist/hooks/useInitializeAgent.d.ts +19 -0
  38. package/cli/dist/hooks/useInitializeAgent.js +28 -0
  39. package/cli/dist/hooks/useStableState.d.ts +38 -0
  40. package/cli/dist/hooks/useStableState.js +68 -0
  41. package/cli/dist/managers/AgentManager.d.ts +57 -0
  42. package/cli/dist/managers/AgentManager.js +119 -0
  43. package/cli/dist/managers/ConfigManager.d.ts +53 -0
  44. package/cli/dist/managers/ConfigManager.js +173 -0
  45. package/cli/dist/types.d.ts +31 -0
  46. package/cli/dist/types.js +19 -0
  47. package/dist/cjs/base-agent.d.ts +2 -0
  48. package/dist/cjs/conversational-agent.d.ts +8 -0
  49. package/dist/cjs/core/ToolRegistry.d.ts +130 -0
  50. package/dist/cjs/execution/ExecutionPipeline.d.ts +81 -0
  51. package/dist/cjs/forms/FormEngine.d.ts +121 -0
  52. package/dist/cjs/forms/field-type-registry.d.ts +51 -0
  53. package/dist/cjs/forms/form-generator.d.ts +123 -0
  54. package/dist/cjs/forms/index.d.ts +2 -0
  55. package/dist/cjs/forms/types.d.ts +108 -0
  56. package/dist/cjs/index.cjs +1 -1
  57. package/dist/cjs/index.cjs.map +1 -1
  58. package/dist/cjs/index.d.ts +5 -0
  59. package/dist/cjs/langchain/FormAwareAgentExecutor.d.ts +108 -0
  60. package/dist/cjs/langchain/FormValidatingToolWrapper.d.ts +81 -0
  61. package/dist/cjs/langchain-agent.d.ts +65 -0
  62. package/dist/cjs/memory/ContentStorage.d.ts +7 -0
  63. package/dist/cjs/memory/SmartMemoryManager.d.ts +1 -0
  64. package/dist/cjs/services/ContentStoreManager.d.ts +11 -1
  65. package/dist/cjs/utils/ResponseFormatter.d.ts +26 -0
  66. package/dist/esm/index.js +8 -1
  67. package/dist/esm/index.js.map +1 -1
  68. package/dist/esm/index12.js +1 -1
  69. package/dist/esm/index12.js.map +1 -1
  70. package/dist/esm/index14.js +23 -5
  71. package/dist/esm/index14.js.map +1 -1
  72. package/dist/esm/index15.js +25 -4
  73. package/dist/esm/index15.js.map +1 -1
  74. package/dist/esm/index16.js +4 -2
  75. package/dist/esm/index16.js.map +1 -1
  76. package/dist/esm/index17.js +2 -7
  77. package/dist/esm/index17.js.map +1 -1
  78. package/dist/esm/index18.js +609 -36
  79. package/dist/esm/index18.js.map +1 -1
  80. package/dist/esm/index19.js +229 -84
  81. package/dist/esm/index19.js.map +1 -1
  82. package/dist/esm/index20.js +111 -17
  83. package/dist/esm/index20.js.map +1 -1
  84. package/dist/esm/index21.js +44 -7
  85. package/dist/esm/index21.js.map +1 -1
  86. package/dist/esm/index22.js +86 -157
  87. package/dist/esm/index22.js.map +1 -1
  88. package/dist/esm/index23.js +32 -150
  89. package/dist/esm/index23.js.map +1 -1
  90. package/dist/esm/index24.js +746 -80
  91. package/dist/esm/index24.js.map +1 -1
  92. package/dist/esm/index25.js +154 -45
  93. package/dist/esm/index25.js.map +1 -1
  94. package/dist/esm/index26.js +149 -24
  95. package/dist/esm/index26.js.map +1 -1
  96. package/dist/esm/index27.js +196 -217
  97. package/dist/esm/index27.js.map +1 -1
  98. package/dist/esm/index28.js +187 -0
  99. package/dist/esm/index28.js.map +1 -0
  100. package/dist/esm/index29.js +308 -0
  101. package/dist/esm/index29.js.map +1 -0
  102. package/dist/esm/index30.js +159 -0
  103. package/dist/esm/index30.js.map +1 -0
  104. package/dist/esm/index31.js +68 -0
  105. package/dist/esm/index31.js.map +1 -0
  106. package/dist/esm/index32.js +30 -0
  107. package/dist/esm/index32.js.map +1 -0
  108. package/dist/esm/index33.js +95 -0
  109. package/dist/esm/index33.js.map +1 -0
  110. package/dist/esm/index34.js +245 -0
  111. package/dist/esm/index34.js.map +1 -0
  112. package/dist/esm/index5.js +2 -2
  113. package/dist/esm/index5.js.map +1 -1
  114. package/dist/esm/index6.js +68 -25
  115. package/dist/esm/index6.js.map +1 -1
  116. package/dist/esm/index7.js.map +1 -1
  117. package/dist/esm/index8.js +744 -70
  118. package/dist/esm/index8.js.map +1 -1
  119. package/dist/types/base-agent.d.ts +2 -0
  120. package/dist/types/conversational-agent.d.ts +8 -0
  121. package/dist/types/core/ToolRegistry.d.ts +130 -0
  122. package/dist/types/execution/ExecutionPipeline.d.ts +81 -0
  123. package/dist/types/forms/FormEngine.d.ts +121 -0
  124. package/dist/types/forms/field-type-registry.d.ts +51 -0
  125. package/dist/types/forms/form-generator.d.ts +123 -0
  126. package/dist/types/forms/index.d.ts +2 -0
  127. package/dist/types/forms/types.d.ts +108 -0
  128. package/dist/types/index.d.ts +5 -0
  129. package/dist/types/langchain/FormAwareAgentExecutor.d.ts +108 -0
  130. package/dist/types/langchain/FormValidatingToolWrapper.d.ts +81 -0
  131. package/dist/types/langchain-agent.d.ts +65 -0
  132. package/dist/types/memory/ContentStorage.d.ts +7 -0
  133. package/dist/types/memory/SmartMemoryManager.d.ts +1 -0
  134. package/dist/types/services/ContentStoreManager.d.ts +11 -1
  135. package/dist/types/utils/ResponseFormatter.d.ts +26 -0
  136. package/package.json +35 -34
  137. package/src/base-agent.ts +2 -0
  138. package/src/config/system-message.ts +14 -0
  139. package/src/context/ReferenceContextManager.ts +1 -1
  140. package/src/conversational-agent.ts +95 -38
  141. package/src/core/ToolRegistry.ts +358 -0
  142. package/src/execution/ExecutionPipeline.ts +301 -0
  143. package/src/forms/FormEngine.ts +443 -0
  144. package/src/forms/field-type-registry.ts +203 -0
  145. package/src/forms/form-generator.ts +841 -0
  146. package/src/forms/index.ts +2 -0
  147. package/src/forms/types.ts +125 -0
  148. package/src/index.ts +9 -0
  149. package/src/langchain/FormAwareAgentExecutor.ts +971 -0
  150. package/src/langchain/FormValidatingToolWrapper.ts +355 -0
  151. package/src/langchain-agent.ts +1034 -87
  152. package/src/mcp/ContentProcessor.ts +20 -4
  153. package/src/mcp/MCPClientManager.ts +1 -1
  154. package/src/mcp/adapters/langchain.ts +1 -1
  155. package/src/memory/ContentStorage.ts +25 -5
  156. package/src/memory/SmartMemoryManager.ts +27 -4
  157. package/src/memory/TokenCounter.ts +1 -1
  158. package/src/plugins/hbar/HbarPlugin.ts +0 -1
  159. package/src/scripts/test-external-tool-wrapper.ts +103 -0
  160. package/src/scripts/test-hedera-kit-wrapper.ts +265 -0
  161. package/src/scripts/test-inscribe-form-generation.ts +494 -0
  162. package/src/scripts/test-inscribe-wrapper-verification.ts +220 -0
  163. package/src/services/ContentStoreManager.ts +23 -9
  164. package/src/services/EntityResolver.ts +2 -9
  165. package/src/tools/EntityResolverTool.ts +5 -8
  166. package/src/utils/ResponseFormatter.ts +146 -0
  167. package/cli/readme.md +0 -181
  168. package/dist/cjs/langchain/ContentAwareAgentExecutor.d.ts +0 -14
  169. package/dist/types/langchain/ContentAwareAgentExecutor.d.ts +0 -14
  170. package/src/langchain/ContentAwareAgentExecutor.ts +0 -19
@@ -0,0 +1,121 @@
1
+ import { StructuredTool } from '@langchain/core/tools';
2
+ import { ZodError, z } from 'zod';
3
+ import { Logger } from '@hashgraphonline/standards-sdk';
4
+ import { FormMessage, FormSubmission } from './types';
5
+
6
+ /**
7
+ * Tool execution result with optional form requirement
8
+ */
9
+ export interface ToolExecutionResult {
10
+ success: boolean;
11
+ output: string;
12
+ metadata?: Record<string, unknown>;
13
+ requiresForm?: boolean;
14
+ formMessage?: FormMessage;
15
+ error?: string;
16
+ }
17
+ /**
18
+ * Context for form generation operations
19
+ */
20
+ export interface FormGenerationContext {
21
+ tool: StructuredTool;
22
+ input: unknown;
23
+ sessionId?: string;
24
+ userId?: string;
25
+ missingFields?: Set<string>;
26
+ }
27
+ /**
28
+ * FormEngine handles all form generation and validation logic
29
+ */
30
+ export declare class FormEngine {
31
+ private formGenerator;
32
+ private logger;
33
+ constructor(logger?: Logger);
34
+ /**
35
+ * Generate a form for a tool with the given input
36
+ */
37
+ generateForm(toolName: string, tool: StructuredTool, input: unknown, context?: Partial<FormGenerationContext>): Promise<FormMessage | null>;
38
+ /**
39
+ * Process a form submission
40
+ */
41
+ processSubmission(submission: FormSubmission, context?: {
42
+ originalInput?: Record<string, unknown>;
43
+ schema?: unknown;
44
+ }): Promise<Record<string, unknown>>;
45
+ /**
46
+ * Check if a tool requires form generation based on input
47
+ */
48
+ shouldGenerateForm(tool: StructuredTool, input: unknown): boolean;
49
+ /**
50
+ * Generate form from error context
51
+ */
52
+ generateFormFromError(error: ZodError, toolName: string, toolSchema: z.ZodSchema, originalPrompt: string): Promise<FormMessage>;
53
+ /**
54
+ * Generate form for FormValidatable tools
55
+ */
56
+ private generateFormValidatableForm;
57
+ /**
58
+ * Generate form based on schema validation
59
+ */
60
+ private generateSchemaBasedForm;
61
+ /**
62
+ * Generate form based on render config
63
+ */
64
+ private generateRenderConfigForm;
65
+ /**
66
+ * Generate form from Zod validation error
67
+ */
68
+ private generateErrorBasedForm;
69
+ /**
70
+ * Validate input against tool schema
71
+ */
72
+ private validateInput;
73
+ /**
74
+ * Check if schema is ZodObject
75
+ */
76
+ private isZodObject;
77
+ /**
78
+ * Check if tool has render configuration
79
+ */
80
+ private hasRenderConfig;
81
+ /**
82
+ * Extract render configuration from tool
83
+ */
84
+ private extractRenderConfig;
85
+ /**
86
+ * Resolve form schema for FormValidatable tools
87
+ */
88
+ private resolveFormSchema;
89
+ /**
90
+ * Determine missing fields for form generation
91
+ */
92
+ private determineMissingFields;
93
+ /**
94
+ * Generate form with resolved schema
95
+ */
96
+ private generateFormWithSchema;
97
+ /**
98
+ * Validate form submission
99
+ */
100
+ private validateSubmission;
101
+ /**
102
+ * Extract base tool input from context
103
+ */
104
+ private extractBaseToolInput;
105
+ /**
106
+ * Extract submission data
107
+ */
108
+ private extractSubmissionData;
109
+ /**
110
+ * Merge input data
111
+ */
112
+ private mergeInputData;
113
+ /**
114
+ * Get registered strategies
115
+ */
116
+ getRegisteredStrategies(): string[];
117
+ /**
118
+ * Get registered middleware
119
+ */
120
+ getRegisteredMiddleware(): string[];
121
+ }
@@ -0,0 +1,51 @@
1
+ import { FormFieldType } from './types';
2
+
3
+ /**
4
+ * Pattern-based field type detection rule
5
+ */
6
+ export interface FieldTypePattern {
7
+ pattern: RegExp | string[];
8
+ type: FormFieldType;
9
+ priority?: number;
10
+ }
11
+ /**
12
+ * Registry for managing field type detection patterns
13
+ */
14
+ export declare class FieldTypeRegistry {
15
+ private static instance;
16
+ private patterns;
17
+ private constructor();
18
+ /**
19
+ * Get singleton instance
20
+ */
21
+ static getInstance(): FieldTypeRegistry;
22
+ /**
23
+ * Initialize default field type patterns
24
+ */
25
+ private initializeDefaultPatterns;
26
+ /**
27
+ * Register a field type pattern
28
+ */
29
+ register(key: string, pattern: FieldTypePattern): void;
30
+ /**
31
+ * Unregister a field type pattern
32
+ */
33
+ unregister(key: string): boolean;
34
+ /**
35
+ * Detect field type based on field name
36
+ */
37
+ detectType(fieldName: string): FormFieldType | null;
38
+ /**
39
+ * Get all registered patterns
40
+ */
41
+ getPatterns(): Map<string, FieldTypePattern>;
42
+ /**
43
+ * Clear all patterns
44
+ */
45
+ clear(): void;
46
+ /**
47
+ * Reset to default patterns
48
+ */
49
+ reset(): void;
50
+ }
51
+ export declare const fieldTypeRegistry: FieldTypeRegistry;
@@ -0,0 +1,123 @@
1
+ import { z, ZodError } from 'zod';
2
+ import { FormMessage } from './types';
3
+
4
+ /**
5
+ * Generates forms from Zod validation failures
6
+ */
7
+ export declare class FormGenerator {
8
+ private logger;
9
+ constructor();
10
+ /**
11
+ * Creates a form message from a Zod validation error
12
+ * @param error The Zod validation error
13
+ * @param schema The original Zod schema
14
+ * @param toolName Name of the tool that failed validation
15
+ * @param originalPrompt The user's original request
16
+ * @returns FormMessage to send to the chat UI
17
+ */
18
+ generateFormFromError(error: ZodError, schema: z.ZodSchema, toolName: string, originalPrompt: string): FormMessage;
19
+ /**
20
+ * Generates a form from a schema and partial input
21
+ * @param schema The Zod schema to generate a form from
22
+ * @param partialInput Any partial input already provided
23
+ * @param context Additional context about the tool
24
+ * @param preCalculatedMissingFields Optional pre-calculated missing fields set. If undefined, includes all fields from schema.
25
+ * @returns FormMessage to send to the chat UI
26
+ */
27
+ generateFormFromSchema(schema: z.ZodSchema, partialInput: unknown, context: {
28
+ toolName: string;
29
+ toolDescription?: string;
30
+ }, preCalculatedMissingFields?: Set<string>): Promise<FormMessage>;
31
+ /**
32
+ * Extracts validation errors from ZodError
33
+ */
34
+ private extractValidationErrors;
35
+ /**
36
+ * Identifies which fields are missing or invalid from validation errors
37
+ */
38
+ private identifyMissingFields;
39
+ /**
40
+ * Creates form configuration from schema
41
+ */
42
+ private createFormConfig;
43
+ /**
44
+ * Safely extracts render configs from schema
45
+ */
46
+ private extractRenderConfigsSafely;
47
+ /**
48
+ * Safely generates field ordering from schema
49
+ */
50
+ private generateFieldOrderingSafely;
51
+ /**
52
+ * Determines field priority for progressive disclosure
53
+ */
54
+ private getFieldPriority;
55
+ /**
56
+ * Determines which fields should be included in the form
57
+ */
58
+ private determineFieldsToInclude;
59
+ /**
60
+ * Includes required fields that are missing
61
+ */
62
+ private includeRequiredMissingFields;
63
+ /**
64
+ * Creates form fields from ordered field names
65
+ */
66
+ private createOrderedFields;
67
+ /**
68
+ * Generates form fields from schema and validation errors
69
+ */
70
+ private generateFormFields;
71
+ /**
72
+ * Creates a single form field
73
+ */
74
+ private createFormField;
75
+ /**
76
+ * Maps render config field type to form field type with fallback inference
77
+ */
78
+ private mapFieldType;
79
+ /**
80
+ * Converts field name to human-readable label
81
+ */
82
+ private humanizeFieldName;
83
+ /**
84
+ * Generates a title for the form
85
+ */
86
+ private generateFormTitle;
87
+ /**
88
+ * Safely extracts ZodObject from a schema, returns null if not an object schema
89
+ */
90
+ private extractZodObject;
91
+ /**
92
+ * Extracts field names from Zod schema structure
93
+ */
94
+ private extractFieldsFromSchema;
95
+ /**
96
+ * Infers field type from Zod schema
97
+ */
98
+ private inferTypeFromSchema;
99
+ /**
100
+ * Determines if a field is required based on the Zod schema
101
+ */
102
+ private isFieldRequired;
103
+ /**
104
+ * Generates a description for the form
105
+ */
106
+ private generateFormDescription;
107
+ /**
108
+ * Generates JSON Schema and uiSchema from a Zod schema for use with @rjsf/core
109
+ * @param zodSchema The Zod schema to convert
110
+ * @param partialInput Existing input data to filter out fields that already have values
111
+ * @param missingFields Set of fields that are missing and should be shown
112
+ * @returns Object containing jsonSchema and uiSchema
113
+ */
114
+ generateJsonSchemaForm(zodSchema: z.ZodObject<z.ZodRawShape>, partialInput?: Record<string, unknown>, missingFields?: Set<string>): {
115
+ jsonSchema: import('zod-to-json-schema').JsonSchema7Type & {
116
+ $schema?: string | undefined;
117
+ definitions?: {
118
+ [key: string]: import('zod-to-json-schema').JsonSchema7Type;
119
+ } | undefined;
120
+ };
121
+ uiSchema: Record<string, Record<string, unknown>>;
122
+ };
123
+ }
@@ -0,0 +1,2 @@
1
+ export * from './types';
2
+ export * from './form-generator';
@@ -0,0 +1,108 @@
1
+ import { RenderConfigSchema } from '@hashgraphonline/standards-agent-kit';
2
+
3
+ /**
4
+ * JSON Schema definition for form rendering
5
+ */
6
+ export type JSONSchemaDefinition = Record<string, unknown>;
7
+ /**
8
+ * UI Schema configuration for form rendering customization
9
+ */
10
+ export type UISchemaDefinition = Record<string, unknown>;
11
+ /**
12
+ * Represents a form message that can be sent to the chat UI
13
+ */
14
+ export interface FormMessage {
15
+ type: 'form';
16
+ id: string;
17
+ formConfig: FormConfig;
18
+ originalPrompt: string;
19
+ toolName: string;
20
+ validationErrors?: ValidationError[];
21
+ partialInput?: unknown;
22
+ jsonSchema?: JSONSchemaDefinition;
23
+ uiSchema?: UISchemaDefinition;
24
+ }
25
+ /**
26
+ * Configuration for generating a form from Zod schema
27
+ */
28
+ export interface FormConfig {
29
+ title: string;
30
+ description?: string;
31
+ fields: FormField[];
32
+ submitLabel?: string;
33
+ cancelLabel?: string;
34
+ metadata?: Record<string, unknown>;
35
+ }
36
+ /**
37
+ * Individual form field configuration
38
+ */
39
+ export interface FormField {
40
+ name: string;
41
+ label: string;
42
+ type: FormFieldType;
43
+ required: boolean;
44
+ placeholder?: string;
45
+ helpText?: string;
46
+ defaultValue?: unknown;
47
+ validation?: FieldValidation;
48
+ options?: FieldOption[];
49
+ renderConfig?: RenderConfigSchema;
50
+ priority?: 'essential' | 'common' | 'advanced' | 'expert';
51
+ }
52
+ /**
53
+ * Form field types supported by the UI
54
+ */
55
+ export type FormFieldType = 'text' | 'number' | 'select' | 'checkbox' | 'textarea' | 'file' | 'array' | 'object' | 'currency' | 'percentage';
56
+ /**
57
+ * Field validation rules
58
+ */
59
+ export interface FieldValidation {
60
+ min?: number;
61
+ max?: number;
62
+ minLength?: number;
63
+ maxLength?: number;
64
+ pattern?: string;
65
+ custom?: string;
66
+ }
67
+ /**
68
+ * Option for select/radio fields
69
+ */
70
+ export interface FieldOption {
71
+ value: string;
72
+ label: string;
73
+ description?: string;
74
+ }
75
+ /**
76
+ * Validation error from Zod
77
+ */
78
+ export interface ValidationError {
79
+ path: string[];
80
+ message: string;
81
+ code: string;
82
+ }
83
+ /**
84
+ * Form submission data
85
+ */
86
+ export interface FormSubmission {
87
+ formId: string;
88
+ toolName: string;
89
+ parameters: Record<string, unknown>;
90
+ timestamp: number;
91
+ context?: {
92
+ originalPrompt?: string;
93
+ partialInput?: Record<string, unknown>;
94
+ chatHistory?: Array<{
95
+ type: 'human' | 'ai';
96
+ content: string;
97
+ }>;
98
+ };
99
+ }
100
+ /**
101
+ * Response after form submission
102
+ */
103
+ export interface FormResponse {
104
+ success: boolean;
105
+ message?: string;
106
+ data?: unknown;
107
+ error?: string;
108
+ }