@hashgraphonline/conversational-agent 0.1.217 → 0.1.218
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.
- package/cli/readme.md +181 -0
- package/dist/cjs/constants/entity-references.d.ts +18 -0
- package/dist/cjs/constants/form-priorities.d.ts +24 -0
- package/dist/cjs/constants/index.d.ts +4 -0
- package/dist/cjs/constants/messages.d.ts +19 -0
- package/dist/cjs/constants/test-constants.d.ts +42 -0
- package/dist/cjs/conversational-agent.d.ts +3 -8
- package/dist/cjs/core/{ToolRegistry.d.ts → tool-registry.d.ts} +10 -7
- package/dist/{types/execution/ExecutionPipeline.d.ts → cjs/execution/execution-pipeline.d.ts} +3 -3
- package/dist/cjs/forms/field-guidance-registry.d.ts +108 -0
- package/dist/cjs/forms/form-generator.d.ts +2 -7
- package/dist/cjs/forms/index.d.ts +3 -0
- package/dist/cjs/forms/types.d.ts +9 -1
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +7 -12
- package/dist/cjs/langchain/external-tool-wrapper.d.ts +101 -0
- package/dist/{types/langchain/FormAwareAgentExecutor.d.ts → cjs/langchain/form-aware-agent-executor.d.ts} +19 -12
- package/dist/cjs/langchain/index.d.ts +2 -0
- package/dist/{types → cjs/langchain}/langchain-agent.d.ts +15 -7
- package/dist/cjs/mcp/adapters/index.d.ts +1 -0
- package/dist/cjs/mcp/adapters/langchain.d.ts +1 -1
- package/dist/{types/mcp/ContentProcessor.d.ts → cjs/mcp/content-processor.d.ts} +1 -1
- package/dist/cjs/mcp/index.d.ts +5 -0
- package/dist/{types/mcp/MCPClientManager.d.ts → cjs/mcp/mcp-client-manager.d.ts} +1 -1
- package/dist/cjs/memory/{ContentStorage.d.ts → content-storage.d.ts} +4 -4
- package/dist/cjs/memory/index.d.ts +5 -7
- package/dist/{types/memory/MemoryWindow.d.ts → cjs/memory/memory-window.d.ts} +1 -1
- package/dist/{types/memory/SmartMemoryManager.d.ts → cjs/memory/smart-memory-manager.d.ts} +1 -1
- package/dist/cjs/services/{ContentStoreManager.d.ts → content-store-manager.d.ts} +6 -6
- package/dist/cjs/services/context/resolution-context.d.ts +49 -0
- package/dist/cjs/services/entity-resolver.d.ts +58 -0
- package/dist/cjs/services/formatters/converters/index.d.ts +2 -0
- package/dist/cjs/services/formatters/converters/string-normalization-converter.d.ts +13 -0
- package/dist/cjs/services/formatters/converters/topic-id-to-hrl-converter.d.ts +17 -0
- package/dist/cjs/services/formatters/format-converter-registry.d.ts +66 -0
- package/dist/cjs/services/formatters/index.d.ts +3 -0
- package/dist/cjs/services/formatters/types.d.ts +29 -0
- package/dist/cjs/services/index.d.ts +3 -0
- package/dist/cjs/services/resolution/resolution-pipeline.d.ts +44 -0
- package/dist/cjs/tools/index.d.ts +1 -0
- package/dist/cjs/utils/index.d.ts +1 -0
- package/dist/esm/index.js +40 -16
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index10.js +669 -13
- package/dist/esm/index10.js.map +1 -1
- package/dist/esm/index11.js +310 -95
- package/dist/esm/index11.js.map +1 -1
- package/dist/esm/index12.js +130 -95
- package/dist/esm/index12.js.map +1 -1
- package/dist/esm/index13.js +262 -153
- package/dist/esm/index13.js.map +1 -1
- package/dist/esm/index14.js +100 -664
- package/dist/esm/index14.js.map +1 -1
- package/dist/esm/index15.js +135 -408
- package/dist/esm/index15.js.map +1 -1
- package/dist/esm/index16.js +240 -122
- package/dist/esm/index16.js.map +1 -1
- package/dist/esm/index17.js +147 -135
- package/dist/esm/index17.js.map +1 -1
- package/dist/esm/index18.js +376 -533
- package/dist/esm/index18.js.map +1 -1
- package/dist/esm/index19.js +87 -214
- package/dist/esm/index19.js.map +1 -1
- package/dist/esm/index2.js +21 -4
- package/dist/esm/index2.js.map +1 -1
- package/dist/esm/index20.js +158 -92
- package/dist/esm/index20.js.map +1 -1
- package/dist/esm/index21.js +717 -44
- package/dist/esm/index21.js.map +1 -1
- package/dist/esm/index22.js +58 -96
- package/dist/esm/index22.js.map +1 -1
- package/dist/esm/index23.js +324 -34
- package/dist/esm/index23.js.map +1 -1
- package/dist/esm/index24.js +125 -712
- package/dist/esm/index24.js.map +1 -1
- package/dist/esm/index25.js +113 -133
- package/dist/esm/index25.js.map +1 -1
- package/dist/esm/index26.js +18 -152
- package/dist/esm/index26.js.map +1 -1
- package/dist/esm/index27.js +14 -210
- package/dist/esm/index27.js.map +1 -1
- package/dist/esm/index28.js +70 -173
- package/dist/esm/index28.js.map +1 -1
- package/dist/esm/index29.js +811 -224
- package/dist/esm/index29.js.map +1 -1
- package/dist/esm/index30.js +1245 -122
- package/dist/esm/index30.js.map +1 -1
- package/dist/esm/index31.js +126 -56
- package/dist/esm/index31.js.map +1 -1
- package/dist/esm/index32.js +111 -24
- package/dist/esm/index32.js.map +1 -1
- package/dist/esm/index33.js +41 -87
- package/dist/esm/index33.js.map +1 -1
- package/dist/esm/index34.js +88 -227
- package/dist/esm/index34.js.map +1 -1
- package/dist/esm/index35.js +24 -0
- package/dist/esm/index35.js.map +1 -0
- package/dist/esm/index36.js +15 -0
- package/dist/esm/index36.js.map +1 -0
- package/dist/esm/index37.js +10 -0
- package/dist/esm/index37.js.map +1 -0
- package/dist/esm/index38.js +8 -0
- package/dist/esm/index38.js.map +1 -0
- package/dist/esm/index39.js +227 -0
- package/dist/esm/index39.js.map +1 -0
- package/dist/esm/index40.js +187 -0
- package/dist/esm/index40.js.map +1 -0
- package/dist/esm/index41.js +30 -0
- package/dist/esm/index41.js.map +1 -0
- package/dist/esm/index42.js +95 -0
- package/dist/esm/index42.js.map +1 -0
- package/dist/esm/index5.js +2 -2
- package/dist/esm/index5.js.map +1 -1
- package/dist/esm/index6.js +44 -67
- package/dist/esm/index6.js.map +1 -1
- package/dist/esm/index7.js +9 -0
- package/dist/esm/index7.js.map +1 -1
- package/dist/esm/index8.js +13 -1095
- package/dist/esm/index8.js.map +1 -1
- package/dist/esm/index9.js +17 -13
- package/dist/esm/index9.js.map +1 -1
- package/dist/types/constants/entity-references.d.ts +18 -0
- package/dist/types/constants/form-priorities.d.ts +24 -0
- package/dist/types/constants/index.d.ts +4 -0
- package/dist/types/constants/messages.d.ts +19 -0
- package/dist/types/constants/test-constants.d.ts +42 -0
- package/dist/types/conversational-agent.d.ts +3 -8
- package/dist/types/core/{ToolRegistry.d.ts → tool-registry.d.ts} +10 -7
- package/dist/{cjs/execution/ExecutionPipeline.d.ts → types/execution/execution-pipeline.d.ts} +3 -3
- package/dist/types/forms/field-guidance-registry.d.ts +108 -0
- package/dist/types/forms/form-generator.d.ts +2 -7
- package/dist/types/forms/index.d.ts +3 -0
- package/dist/types/forms/types.d.ts +9 -1
- package/dist/types/index.d.ts +7 -12
- package/dist/types/langchain/external-tool-wrapper.d.ts +101 -0
- package/dist/{cjs/langchain/FormAwareAgentExecutor.d.ts → types/langchain/form-aware-agent-executor.d.ts} +19 -12
- package/dist/types/langchain/index.d.ts +2 -0
- package/dist/{cjs → types/langchain}/langchain-agent.d.ts +15 -7
- package/dist/types/mcp/adapters/index.d.ts +1 -0
- package/dist/types/mcp/adapters/langchain.d.ts +1 -1
- package/dist/{cjs/mcp/ContentProcessor.d.ts → types/mcp/content-processor.d.ts} +1 -1
- package/dist/types/mcp/index.d.ts +5 -0
- package/dist/{cjs/mcp/MCPClientManager.d.ts → types/mcp/mcp-client-manager.d.ts} +1 -1
- package/dist/types/memory/{ContentStorage.d.ts → content-storage.d.ts} +4 -4
- package/dist/types/memory/index.d.ts +5 -7
- package/dist/{cjs/memory/MemoryWindow.d.ts → types/memory/memory-window.d.ts} +1 -1
- package/dist/{cjs/memory/SmartMemoryManager.d.ts → types/memory/smart-memory-manager.d.ts} +1 -1
- package/dist/types/services/{ContentStoreManager.d.ts → content-store-manager.d.ts} +6 -6
- package/dist/types/services/context/resolution-context.d.ts +49 -0
- package/dist/types/services/entity-resolver.d.ts +58 -0
- package/dist/types/services/formatters/converters/index.d.ts +2 -0
- package/dist/types/services/formatters/converters/string-normalization-converter.d.ts +13 -0
- package/dist/types/services/formatters/converters/topic-id-to-hrl-converter.d.ts +17 -0
- package/dist/types/services/formatters/format-converter-registry.d.ts +66 -0
- package/dist/types/services/formatters/index.d.ts +3 -0
- package/dist/types/services/formatters/types.d.ts +29 -0
- package/dist/types/services/index.d.ts +3 -0
- package/dist/types/services/resolution/resolution-pipeline.d.ts +44 -0
- package/dist/types/tools/index.d.ts +1 -0
- package/dist/types/utils/index.d.ts +1 -0
- package/package.json +30 -27
- package/src/agent-factory.ts +1 -1
- package/src/base-agent.ts +9 -0
- package/src/config/system-message.ts +2 -15
- package/src/constants/entity-references.ts +23 -0
- package/src/constants/form-priorities.ts +25 -0
- package/src/constants/index.ts +4 -0
- package/src/constants/messages.ts +20 -0
- package/src/constants/test-constants.ts +49 -0
- package/src/conversational-agent.ts +42 -69
- package/src/core/{ToolRegistry.ts → tool-registry.ts} +70 -44
- package/src/examples/external-tool-wrapper-example.ts +56 -0
- package/src/execution/{ExecutionPipeline.ts → execution-pipeline.ts} +3 -3
- package/src/forms/field-guidance-registry.ts +415 -0
- package/src/forms/field-type-registry.ts +49 -48
- package/src/forms/{FormEngine.ts → form-engine.ts} +66 -43
- package/src/forms/form-generator.ts +91 -17
- package/src/forms/index.ts +4 -1
- package/src/forms/types.ts +9 -1
- package/src/index.ts +7 -37
- package/src/langchain/external-tool-wrapper.ts +90 -0
- package/src/langchain/{FormAwareAgentExecutor.ts → form-aware-agent-executor.ts} +579 -351
- package/src/langchain/index.ts +2 -0
- package/src/{langchain-agent.ts → langchain/langchain-agent.ts} +389 -113
- package/src/mcp/adapters/index.ts +1 -0
- package/src/mcp/adapters/langchain.ts +27 -18
- package/src/mcp/{ContentProcessor.ts → content-processor.ts} +71 -47
- package/src/mcp/index.ts +5 -0
- package/src/mcp/{MCPClientManager.ts → mcp-client-manager.ts} +2 -2
- package/src/memory/{ContentStorage.ts → content-storage.ts} +263 -167
- package/src/memory/index.ts +5 -8
- package/src/memory/{MemoryWindow.ts → memory-window.ts} +47 -24
- package/src/memory/{SmartMemoryManager.ts → smart-memory-manager.ts} +49 -22
- package/src/plugins/hbar/HbarPlugin.ts +1 -1
- package/src/plugins/hcs-10/HCS10Plugin.ts +46 -28
- package/src/scripts/test-external-tool-wrapper.ts +6 -6
- package/src/scripts/test-inscribe-form-generation.ts +22 -21
- package/src/scripts/test-inscribe-wrapper-verification.ts +5 -4
- package/src/services/{ContentStoreManager.ts → content-store-manager.ts} +75 -33
- package/src/services/context/resolution-context.ts +80 -0
- package/src/services/entity-resolver.ts +425 -0
- package/src/services/formatters/converters/index.ts +2 -0
- package/src/services/formatters/converters/string-normalization-converter.ts +106 -0
- package/src/services/formatters/converters/topic-id-to-hrl-converter.ts +25 -0
- package/src/services/formatters/format-converter-registry.ts +229 -0
- package/src/services/formatters/index.ts +3 -0
- package/src/services/formatters/types.ts +31 -0
- package/src/services/index.ts +3 -0
- package/src/services/resolution/resolution-pipeline.ts +106 -0
- package/src/tools/index.ts +1 -0
- package/src/types/content-reference.ts +87 -60
- package/src/utils/index.ts +1 -0
- package/cli/dist/CLIApp.d.ts +0 -9
- package/cli/dist/CLIApp.js +0 -127
- package/cli/dist/LocalConversationalAgent.d.ts +0 -37
- package/cli/dist/LocalConversationalAgent.js +0 -58
- package/cli/dist/app.d.ts +0 -16
- package/cli/dist/app.js +0 -13
- package/cli/dist/cli.d.ts +0 -2
- package/cli/dist/cli.js +0 -51
- package/cli/dist/components/AppContainer.d.ts +0 -16
- package/cli/dist/components/AppContainer.js +0 -24
- package/cli/dist/components/AppScreens.d.ts +0 -2
- package/cli/dist/components/AppScreens.js +0 -259
- package/cli/dist/components/ChatScreen.d.ts +0 -15
- package/cli/dist/components/ChatScreen.js +0 -39
- package/cli/dist/components/DebugLoadingScreen.d.ts +0 -5
- package/cli/dist/components/DebugLoadingScreen.js +0 -31
- package/cli/dist/components/LoadingScreen.d.ts +0 -2
- package/cli/dist/components/LoadingScreen.js +0 -16
- package/cli/dist/components/LoadingScreenDebug.d.ts +0 -5
- package/cli/dist/components/LoadingScreenDebug.js +0 -27
- package/cli/dist/components/MCPConfigScreen.d.ts +0 -28
- package/cli/dist/components/MCPConfigScreen.js +0 -168
- package/cli/dist/components/ScreenRouter.d.ts +0 -12
- package/cli/dist/components/ScreenRouter.js +0 -22
- package/cli/dist/components/SetupScreen.d.ts +0 -15
- package/cli/dist/components/SetupScreen.js +0 -65
- package/cli/dist/components/SingleLoadingScreen.d.ts +0 -5
- package/cli/dist/components/SingleLoadingScreen.js +0 -27
- package/cli/dist/components/StatusBadge.d.ts +0 -7
- package/cli/dist/components/StatusBadge.js +0 -28
- package/cli/dist/components/TerminalWindow.d.ts +0 -8
- package/cli/dist/components/TerminalWindow.js +0 -24
- package/cli/dist/components/WelcomeScreen.d.ts +0 -11
- package/cli/dist/components/WelcomeScreen.js +0 -47
- package/cli/dist/context/AppContext.d.ts +0 -68
- package/cli/dist/context/AppContext.js +0 -363
- package/cli/dist/hooks/useInitializeAgent.d.ts +0 -19
- package/cli/dist/hooks/useInitializeAgent.js +0 -28
- package/cli/dist/hooks/useStableState.d.ts +0 -38
- package/cli/dist/hooks/useStableState.js +0 -68
- package/cli/dist/managers/AgentManager.d.ts +0 -57
- package/cli/dist/managers/AgentManager.js +0 -119
- package/cli/dist/managers/ConfigManager.d.ts +0 -53
- package/cli/dist/managers/ConfigManager.js +0 -173
- package/cli/dist/types.d.ts +0 -31
- package/cli/dist/types.js +0 -19
- package/dist/cjs/context/ReferenceContextManager.d.ts +0 -84
- package/dist/cjs/context/ReferenceResponseProcessor.d.ts +0 -76
- package/dist/cjs/langchain/FormValidatingToolWrapper.d.ts +0 -81
- package/dist/cjs/services/EntityResolver.d.ts +0 -26
- package/dist/types/context/ReferenceContextManager.d.ts +0 -84
- package/dist/types/context/ReferenceResponseProcessor.d.ts +0 -76
- package/dist/types/langchain/FormValidatingToolWrapper.d.ts +0 -81
- package/dist/types/services/EntityResolver.d.ts +0 -26
- package/src/context/ReferenceContextManager.ts +0 -350
- package/src/context/ReferenceResponseProcessor.ts +0 -295
- package/src/langchain/FormValidatingToolWrapper.ts +0 -355
- package/src/scripts/test-hedera-kit-wrapper.ts +0 -265
- package/src/services/EntityResolver.ts +0 -128
- /package/dist/cjs/forms/{FormEngine.d.ts → form-engine.d.ts} +0 -0
- /package/dist/cjs/memory/{ReferenceIdGenerator.d.ts → reference-id-generator.d.ts} +0 -0
- /package/dist/cjs/memory/{TokenCounter.d.ts → token-counter.d.ts} +0 -0
- /package/dist/cjs/tools/{EntityResolverTool.d.ts → entity-resolver-tool.d.ts} +0 -0
- /package/dist/cjs/utils/{ResponseFormatter.d.ts → response-formatter.d.ts} +0 -0
- /package/dist/types/forms/{FormEngine.d.ts → form-engine.d.ts} +0 -0
- /package/dist/types/memory/{ReferenceIdGenerator.d.ts → reference-id-generator.d.ts} +0 -0
- /package/dist/types/memory/{TokenCounter.d.ts → token-counter.d.ts} +0 -0
- /package/dist/types/tools/{EntityResolverTool.d.ts → entity-resolver-tool.d.ts} +0 -0
- /package/dist/types/utils/{ResponseFormatter.d.ts → response-formatter.d.ts} +0 -0
- /package/src/memory/{ReferenceIdGenerator.ts → reference-id-generator.ts} +0 -0
- /package/src/memory/{TokenCounter.ts → token-counter.ts} +0 -0
- /package/src/tools/{EntityResolverTool.ts → entity-resolver-tool.ts} +0 -0
- /package/src/utils/{ResponseFormatter.ts → response-formatter.ts} +0 -0
package/dist/esm/index24.js
CHANGED
|
@@ -1,761 +1,174 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
if ("returnValues" in result) {
|
|
28
|
-
this.formLogger.info("Agent returned finish action, passing through");
|
|
29
|
-
return result;
|
|
30
|
-
}
|
|
31
|
-
const action = result;
|
|
32
|
-
const toolName = action.tool;
|
|
33
|
-
const toolInput = action.toolInput;
|
|
34
|
-
this.formLogger.info(`🎯 INTERCEPTING TOOL CALL: ${toolName}`, {
|
|
35
|
-
toolInput,
|
|
36
|
-
hasInNameToolMap: toolName in nameToolMap,
|
|
37
|
-
toolInputKeys: Object.keys(toolInput || {})
|
|
38
|
-
});
|
|
39
|
-
const tool = nameToolMap[toolName] || this.tools.find((t) => t.name === toolName);
|
|
40
|
-
if (!tool) {
|
|
41
|
-
this.formLogger.error(`Tool ${toolName} not found in registry`);
|
|
42
|
-
throw new Error(`Tool "${toolName}" not found`);
|
|
43
|
-
}
|
|
44
|
-
let shouldGenerateForm = false;
|
|
45
|
-
if (isFormValidatable(tool)) {
|
|
46
|
-
this.formLogger.info(`🔍 Tool ${toolName} implements FormValidatable, checking shouldGenerateForm()`, {
|
|
47
|
-
toolInput
|
|
48
|
-
});
|
|
49
|
-
try {
|
|
50
|
-
shouldGenerateForm = tool.shouldGenerateForm(toolInput);
|
|
51
|
-
this.formLogger.info(`FormValidatable.shouldGenerateForm() result: ${shouldGenerateForm}`, {
|
|
52
|
-
toolName,
|
|
53
|
-
toolInput
|
|
54
|
-
});
|
|
55
|
-
} catch (error) {
|
|
56
|
-
this.formLogger.error(`Error calling shouldGenerateForm() on ${toolName}:`, error);
|
|
57
|
-
shouldGenerateForm = false;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
if (shouldGenerateForm) {
|
|
61
|
-
this.formLogger.info(`🚨 FORM GENERATION TRIGGERED for ${toolName}`);
|
|
62
|
-
try {
|
|
63
|
-
let schemaToUse;
|
|
64
|
-
let isFocusedSchema = false;
|
|
65
|
-
if (isFormValidatable(tool)) {
|
|
66
|
-
this.formLogger.info(`🎯 Tool ${toolName} is FormValidatable, attempting to get focused schema`);
|
|
67
|
-
try {
|
|
68
|
-
const focusedSchema = tool.getFormSchema();
|
|
69
|
-
if (focusedSchema) {
|
|
70
|
-
schemaToUse = focusedSchema;
|
|
71
|
-
isFocusedSchema = true;
|
|
72
|
-
this.formLogger.info(`✅ Successfully obtained focused schema for ${toolName}`);
|
|
73
|
-
} else {
|
|
74
|
-
this.formLogger.warn(`getFormSchema() returned null/undefined for ${toolName}, using default schema`);
|
|
75
|
-
schemaToUse = tool.schema;
|
|
76
|
-
isFocusedSchema = false;
|
|
77
|
-
}
|
|
78
|
-
} catch (error) {
|
|
79
|
-
this.formLogger.error(`Failed to get focused schema from ${toolName}:`, error);
|
|
80
|
-
this.formLogger.info(`Falling back to default schema for ${toolName}`);
|
|
81
|
-
schemaToUse = tool.schema;
|
|
82
|
-
isFocusedSchema = false;
|
|
83
|
-
}
|
|
84
|
-
} else {
|
|
85
|
-
this.formLogger.info(`Tool ${toolName} is not FormValidatable, using default schema`);
|
|
86
|
-
schemaToUse = tool.schema;
|
|
87
|
-
isFocusedSchema = false;
|
|
88
|
-
}
|
|
89
|
-
let schemaFieldCount = "unknown";
|
|
90
|
-
try {
|
|
91
|
-
if (schemaToUse && typeof schemaToUse === "object" && "shape" in schemaToUse) {
|
|
92
|
-
const shape = schemaToUse.shape;
|
|
93
|
-
if (shape && typeof shape === "object") {
|
|
94
|
-
schemaFieldCount = Object.keys(shape).length.toString();
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
} catch {
|
|
98
|
-
}
|
|
99
|
-
this.formLogger.info(`📋 Generating form with ${isFocusedSchema ? "FOCUSED" : "DEFAULT"} schema`, {
|
|
100
|
-
toolName,
|
|
101
|
-
schemaType: schemaToUse?.constructor?.name,
|
|
102
|
-
estimatedFieldCount: schemaFieldCount,
|
|
103
|
-
isFocusedSchema
|
|
104
|
-
});
|
|
105
|
-
let missingFields;
|
|
106
|
-
if (isFocusedSchema) {
|
|
107
|
-
this.formLogger.info(`⭐ Using focused schema - letting FormGenerator determine fields from schema`);
|
|
108
|
-
missingFields = void 0;
|
|
109
|
-
} else {
|
|
110
|
-
missingFields = /* @__PURE__ */ new Set();
|
|
111
|
-
if (this.isZodObject(schemaToUse)) {
|
|
112
|
-
const zodObject = schemaToUse;
|
|
113
|
-
const shape = zodObject.shape || {};
|
|
114
|
-
for (const fieldName of Object.keys(shape)) {
|
|
115
|
-
const value = (toolInput || {})[fieldName];
|
|
116
|
-
const isEmpty = isFormValidatable(tool) && tool.isFieldEmpty ? tool.isFieldEmpty(fieldName, value) : value === void 0 || value === "" || value === null || Array.isArray(value) && value.length === 0;
|
|
117
|
-
const isRequired = this.isFieldRequired(schemaToUse, fieldName);
|
|
118
|
-
const isEssential = isFormValidatable(tool) && tool.getEssentialFields ? tool.getEssentialFields().includes(fieldName) : false;
|
|
119
|
-
this.formLogger.info(`🔍 Field analysis: ${fieldName}`, {
|
|
120
|
-
value,
|
|
121
|
-
isEmpty,
|
|
122
|
-
isRequired,
|
|
123
|
-
isEssential,
|
|
124
|
-
willAddToMissingFields: isEmpty && (isRequired || isEssential)
|
|
125
|
-
});
|
|
126
|
-
if (isEmpty && (isRequired || isEssential)) {
|
|
127
|
-
missingFields.add(fieldName);
|
|
128
|
-
}
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
this.formLogger.info(`📋 Missing fields analysis complete`, {
|
|
132
|
-
totalFields: this.isZodObject(schemaToUse) ? Object.keys(schemaToUse.shape).length : 0,
|
|
133
|
-
missingFieldsCount: missingFields.size,
|
|
134
|
-
missingFields: Array.from(missingFields)
|
|
135
|
-
});
|
|
136
|
-
}
|
|
137
|
-
const formMessage = await this.formGenerator.generateFormFromSchema(
|
|
138
|
-
schemaToUse,
|
|
139
|
-
toolInput,
|
|
140
|
-
{
|
|
141
|
-
toolName,
|
|
142
|
-
toolDescription: tool.description
|
|
1
|
+
import { ContentStorage } from "./index21.js";
|
|
2
|
+
import { Logger, ContentStoreService, ContentResolverRegistry, shouldUseReference, extractReferenceId } from "@hashgraphonline/standards-sdk";
|
|
3
|
+
class ContentStorageAdapter {
|
|
4
|
+
constructor(storage) {
|
|
5
|
+
this.storage = storage;
|
|
6
|
+
}
|
|
7
|
+
async storeContent(content, metadata) {
|
|
8
|
+
const storeMetadata = {
|
|
9
|
+
contentType: "binary",
|
|
10
|
+
sizeBytes: content.length,
|
|
11
|
+
source: "system",
|
|
12
|
+
...metadata
|
|
13
|
+
};
|
|
14
|
+
const contentRef = await this.storage.storeContent(content, storeMetadata);
|
|
15
|
+
return contentRef.referenceId;
|
|
16
|
+
}
|
|
17
|
+
async resolveReference(referenceId) {
|
|
18
|
+
const result = await this.storage.resolveReference(referenceId);
|
|
19
|
+
if (result.success && result.content) {
|
|
20
|
+
const response = {
|
|
21
|
+
content: result.content
|
|
22
|
+
};
|
|
23
|
+
if (result.metadata) {
|
|
24
|
+
response.metadata = {
|
|
25
|
+
...result.metadata.mimeType !== void 0 && {
|
|
26
|
+
mimeType: result.metadata.mimeType
|
|
143
27
|
},
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
try {
|
|
149
|
-
const { jsonSchema, uiSchema } = this.formGenerator.generateJsonSchemaForm(
|
|
150
|
-
schemaToUse,
|
|
151
|
-
toolInput,
|
|
152
|
-
missingFields
|
|
153
|
-
);
|
|
154
|
-
formMessage.jsonSchema = jsonSchema;
|
|
155
|
-
formMessage.uiSchema = uiSchema;
|
|
156
|
-
} catch (error) {
|
|
157
|
-
this.formLogger.warn("Failed to generate JSON Schema for RJSF:", error);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
formMessage.partialInput = toolInput;
|
|
161
|
-
const formData = {
|
|
162
|
-
toolName,
|
|
163
|
-
originalInput: inputs,
|
|
164
|
-
originalToolInput: toolInput,
|
|
165
|
-
schema: schemaToUse,
|
|
166
|
-
toolRef: tool,
|
|
167
|
-
originalToolRef: tool.originalTool
|
|
168
|
-
};
|
|
169
|
-
this.pendingForms.set(formMessage.id, formData);
|
|
170
|
-
globalPendingForms.set(formMessage.id, formData);
|
|
171
|
-
this.formLogger.info(`✅ FORM INTERCEPT SUCCESS for ${toolName}`);
|
|
172
|
-
const formResult = {
|
|
173
|
-
requiresForm: true,
|
|
174
|
-
formMessage
|
|
28
|
+
...result.metadata.fileName !== void 0 && {
|
|
29
|
+
fileName: result.metadata.fileName
|
|
30
|
+
},
|
|
31
|
+
originalSize: result.metadata.sizeBytes
|
|
175
32
|
};
|
|
176
|
-
return [{
|
|
177
|
-
action,
|
|
178
|
-
observation: JSON.stringify(formResult)
|
|
179
|
-
}];
|
|
180
|
-
} catch (error) {
|
|
181
|
-
this.formLogger.error(`Form generation failed for ${toolName}:`, error);
|
|
182
33
|
}
|
|
34
|
+
return response;
|
|
35
|
+
} else {
|
|
36
|
+
throw new Error(result.error || "Reference not found");
|
|
183
37
|
}
|
|
184
|
-
this.formLogger.info(`⚪ Passing through to normal tool execution for ${toolName}`);
|
|
185
|
-
return super._takeNextStep(nameToolMap, inputs, intermediateSteps, runManager, config);
|
|
186
38
|
}
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
*/
|
|
190
|
-
isZodObject(schema) {
|
|
191
|
-
if (!schema || typeof schema !== "object") {
|
|
192
|
-
return false;
|
|
193
|
-
}
|
|
194
|
-
const candidate = schema;
|
|
195
|
-
return Boolean(candidate._def && candidate._def.typeName === "ZodObject");
|
|
39
|
+
async hasReference(referenceId) {
|
|
40
|
+
return await this.storage.hasReference(referenceId);
|
|
196
41
|
}
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
*/
|
|
200
|
-
isFieldRequired(schema, fieldPath) {
|
|
201
|
-
if (!schema || !fieldPath) {
|
|
202
|
-
return false;
|
|
203
|
-
}
|
|
204
|
-
try {
|
|
205
|
-
const obj = schema;
|
|
206
|
-
const def = obj._def;
|
|
207
|
-
if (!def || def.typeName !== "ZodObject") {
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
210
|
-
const rawShape = typeof def.shape === "function" ? def.shape() : def.shape;
|
|
211
|
-
if (!rawShape || typeof rawShape !== "object") {
|
|
212
|
-
return false;
|
|
213
|
-
}
|
|
214
|
-
const shape = rawShape;
|
|
215
|
-
const fieldSchema = shape[fieldPath];
|
|
216
|
-
if (!fieldSchema) {
|
|
217
|
-
return false;
|
|
218
|
-
}
|
|
219
|
-
const unwrapOptional = (s) => {
|
|
220
|
-
const inner = s._def;
|
|
221
|
-
if (inner && inner.typeName === "ZodOptional" && inner.innerType) {
|
|
222
|
-
return inner.innerType;
|
|
223
|
-
}
|
|
224
|
-
return s;
|
|
225
|
-
};
|
|
226
|
-
const unwrapped = unwrapOptional(fieldSchema);
|
|
227
|
-
const fdef = unwrapped._def;
|
|
228
|
-
if (!fdef) {
|
|
229
|
-
return true;
|
|
230
|
-
}
|
|
231
|
-
if (fdef.typeName === "ZodOptional" || fdef.typeName === "ZodDefault") {
|
|
232
|
-
return false;
|
|
233
|
-
}
|
|
234
|
-
if (fdef.defaultValue !== void 0) {
|
|
235
|
-
return false;
|
|
236
|
-
}
|
|
237
|
-
return true;
|
|
238
|
-
} catch (error) {
|
|
239
|
-
this.formLogger.debug(`Could not determine if field ${fieldPath} is required:`, error);
|
|
240
|
-
}
|
|
241
|
-
return false;
|
|
42
|
+
async cleanupReference(referenceId) {
|
|
43
|
+
await this.storage.cleanupReference(referenceId);
|
|
242
44
|
}
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
*/
|
|
246
|
-
async _call(inputs) {
|
|
247
|
-
try {
|
|
248
|
-
const result = await super._call(inputs);
|
|
249
|
-
if (result.intermediateSteps && Array.isArray(result.intermediateSteps)) {
|
|
250
|
-
for (const step of result.intermediateSteps) {
|
|
251
|
-
if (step.observation) {
|
|
252
|
-
try {
|
|
253
|
-
const parsed = typeof step.observation === "string" ? JSON.parse(step.observation) : step.observation;
|
|
254
|
-
if (parsed.requiresForm && parsed.formMessage) {
|
|
255
|
-
this.formLogger.info("Tool requested form generation", {
|
|
256
|
-
toolName: step.action?.tool,
|
|
257
|
-
hasForm: true
|
|
258
|
-
});
|
|
259
|
-
const actionToolName = step.action?.tool || "unknown";
|
|
260
|
-
const toolInstance = this.tools.find((t) => t.name === actionToolName);
|
|
261
|
-
const originalToolCandidate = toolInstance || {};
|
|
262
|
-
const pf = {
|
|
263
|
-
toolName: actionToolName,
|
|
264
|
-
originalInput: inputs,
|
|
265
|
-
originalToolInput: step.action?.toolInput,
|
|
266
|
-
schema: null,
|
|
267
|
-
toolRef: toolInstance,
|
|
268
|
-
originalToolRef: originalToolCandidate?.originalTool
|
|
269
|
-
};
|
|
270
|
-
this.pendingForms.set(parsed.formMessage.id, pf);
|
|
271
|
-
globalPendingForms.set(parsed.formMessage.id, pf);
|
|
272
|
-
return {
|
|
273
|
-
...result,
|
|
274
|
-
requiresForm: true,
|
|
275
|
-
formMessage: parsed.formMessage,
|
|
276
|
-
output: parsed.message || "Please complete the form to continue."
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
if (parsed.hashLinkBlock || parsed.success && parsed.inscription && parsed.hashLinkBlock) {
|
|
280
|
-
this.formLogger.info("Tool returned HashLink blocks", {
|
|
281
|
-
toolName: step.action?.tool,
|
|
282
|
-
hasHashLink: true,
|
|
283
|
-
blockId: parsed.hashLinkBlock?.blockId
|
|
284
|
-
});
|
|
285
|
-
const hashLinkResponse = this.processHashLinkResponse(parsed);
|
|
286
|
-
return {
|
|
287
|
-
...result,
|
|
288
|
-
hasHashLinkBlocks: true,
|
|
289
|
-
hashLinkBlock: hashLinkResponse.hashLinkBlock,
|
|
290
|
-
output: hashLinkResponse.message
|
|
291
|
-
};
|
|
292
|
-
}
|
|
293
|
-
} catch {
|
|
294
|
-
}
|
|
295
|
-
}
|
|
296
|
-
}
|
|
297
|
-
}
|
|
298
|
-
return result;
|
|
299
|
-
} catch (error) {
|
|
300
|
-
if (error instanceof ZodError) {
|
|
301
|
-
this.formLogger.info("Intercepted ZodError during agent execution");
|
|
302
|
-
return this.handleValidationError(error, inputs, []);
|
|
303
|
-
}
|
|
304
|
-
throw error;
|
|
305
|
-
}
|
|
45
|
+
async getStats() {
|
|
46
|
+
return await this.storage.getStats();
|
|
306
47
|
}
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
errorIssues: error.issues.length,
|
|
313
|
-
inputKeys: Object.keys(inputs)
|
|
314
|
-
});
|
|
315
|
-
let toolInfo = this.extractToolInfoFromError(error, inputs, intermediateSteps);
|
|
316
|
-
if (!toolInfo) {
|
|
317
|
-
this.formLogger.warn("Could not extract tool info from validation error, trying fallback detection");
|
|
318
|
-
const fallbackTool = this.detectToolFromErrorContext(error);
|
|
319
|
-
if (!fallbackTool) {
|
|
320
|
-
this.formLogger.error("No tool detected for form generation, rethrowing error");
|
|
321
|
-
throw error;
|
|
322
|
-
}
|
|
323
|
-
toolInfo = fallbackTool;
|
|
324
|
-
}
|
|
325
|
-
this.formLogger.info("Generating form for tool:", {
|
|
326
|
-
toolName: toolInfo.toolName,
|
|
327
|
-
hasSchema: !!toolInfo.schema
|
|
328
|
-
});
|
|
329
|
-
const formMessage = this.formGenerator.generateFormFromError(
|
|
330
|
-
error,
|
|
331
|
-
toolInfo.schema,
|
|
332
|
-
toolInfo.toolName,
|
|
333
|
-
inputs.input || ""
|
|
334
|
-
);
|
|
335
|
-
this.pendingForms.set(formMessage.id, {
|
|
336
|
-
toolName: toolInfo.toolName,
|
|
337
|
-
originalInput: inputs,
|
|
338
|
-
schema: toolInfo.schema
|
|
339
|
-
});
|
|
340
|
-
globalPendingForms.set(formMessage.id, {
|
|
341
|
-
toolName: toolInfo.toolName,
|
|
342
|
-
originalInput: inputs,
|
|
343
|
-
schema: toolInfo.schema
|
|
344
|
-
});
|
|
345
|
-
return {
|
|
346
|
-
output: this.formatFormResponse(formMessage),
|
|
347
|
-
formMessage,
|
|
348
|
-
requiresForm: true,
|
|
349
|
-
intermediateSteps: intermediateSteps || []
|
|
48
|
+
async updateConfig(config) {
|
|
49
|
+
const referenceConfig = {
|
|
50
|
+
sizeThresholdBytes: config.maxSize || 10240,
|
|
51
|
+
enableAutoCleanup: config.enableCompression || true,
|
|
52
|
+
...config
|
|
350
53
|
};
|
|
54
|
+
return await this.storage.updateConfig(referenceConfig);
|
|
351
55
|
}
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
*/
|
|
355
|
-
getPendingForms() {
|
|
356
|
-
return new Map(this.pendingForms);
|
|
56
|
+
async performCleanup() {
|
|
57
|
+
await this.storage.performCleanup();
|
|
357
58
|
}
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
59
|
+
async dispose() {
|
|
60
|
+
return Promise.resolve(this.storage.dispose());
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
class ContentResolver {
|
|
64
|
+
constructor(adapter) {
|
|
65
|
+
this.adapter = adapter;
|
|
66
|
+
}
|
|
67
|
+
async resolveReference(referenceId) {
|
|
68
|
+
return await this.adapter.resolveReference(referenceId);
|
|
69
|
+
}
|
|
70
|
+
shouldUseReference(content) {
|
|
71
|
+
return shouldUseReference(content);
|
|
72
|
+
}
|
|
73
|
+
extractReferenceId(input) {
|
|
74
|
+
return extractReferenceId(input);
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
class ContentStoreManager {
|
|
78
|
+
constructor(maxMessageStorage = 1e3, referenceConfig, logger) {
|
|
79
|
+
this.isRegistered = false;
|
|
80
|
+
this.logger = logger || new Logger({ module: "ContentStoreManager" });
|
|
81
|
+
this.contentStorage = new ContentStorage(
|
|
82
|
+
maxMessageStorage,
|
|
83
|
+
referenceConfig
|
|
84
|
+
);
|
|
85
|
+
this.adapter = new ContentStorageAdapter(this.contentStorage);
|
|
86
|
+
this.resolver = new ContentResolver(this.adapter);
|
|
365
87
|
}
|
|
366
88
|
/**
|
|
367
|
-
*
|
|
89
|
+
* Initialize and register content storage for cross-package access
|
|
368
90
|
*/
|
|
369
|
-
async
|
|
370
|
-
this.
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
});
|
|
374
|
-
if (!submission) {
|
|
375
|
-
throw new Error("Form submission is null or undefined");
|
|
376
|
-
}
|
|
377
|
-
if (!submission.formId) {
|
|
378
|
-
throw new Error("Form submission missing formId");
|
|
379
|
-
}
|
|
380
|
-
if (!submission.parameters || submission.parameters === null || typeof submission.parameters !== "object" || Array.isArray(submission.parameters)) {
|
|
381
|
-
throw new Error(`Form submission parameters are invalid: ${typeof submission.parameters}, isNull: ${submission.parameters === null}, isArray: ${Array.isArray(submission.parameters)}, parameters: ${JSON.stringify(submission.parameters)}`);
|
|
382
|
-
}
|
|
383
|
-
this.formLogger.info("Processing form submission:", {
|
|
384
|
-
formId: submission.formId,
|
|
385
|
-
toolName: submission.toolName,
|
|
386
|
-
parameterKeys: Object.keys(submission.parameters),
|
|
387
|
-
parametersType: typeof submission.parameters,
|
|
388
|
-
parametersIsNull: submission.parameters === null,
|
|
389
|
-
parametersIsUndefined: submission.parameters === void 0,
|
|
390
|
-
hasContext: !!submission.context
|
|
391
|
-
});
|
|
392
|
-
let pendingForm = this.pendingForms.get(submission.formId);
|
|
393
|
-
if (!pendingForm) {
|
|
394
|
-
pendingForm = globalPendingForms.get(submission.formId);
|
|
395
|
-
if (!pendingForm) {
|
|
396
|
-
throw new Error(`No pending form found for ID: ${submission.formId}`);
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
this.pendingForms.delete(submission.formId);
|
|
400
|
-
globalPendingForms.delete(submission.formId);
|
|
401
|
-
const tool = pendingForm.toolRef || this.tools.find((t) => t.name === pendingForm.toolName);
|
|
402
|
-
if (!tool) {
|
|
403
|
-
throw new Error(`Tool not found for form submission: ${pendingForm.toolName}`);
|
|
404
|
-
}
|
|
405
|
-
let baseToolInput = {};
|
|
406
|
-
try {
|
|
407
|
-
if (pendingForm.originalToolInput && typeof pendingForm.originalToolInput === "object") {
|
|
408
|
-
baseToolInput = { ...pendingForm.originalToolInput };
|
|
409
|
-
}
|
|
410
|
-
} catch (error) {
|
|
411
|
-
this.formLogger.warn("Failed to extract base tool input, using empty object:", error);
|
|
412
|
-
baseToolInput = {};
|
|
413
|
-
}
|
|
414
|
-
let submissionData = {};
|
|
415
|
-
try {
|
|
416
|
-
if (submission.parameters && typeof submission.parameters === "object") {
|
|
417
|
-
submissionData = { ...submission.parameters };
|
|
418
|
-
}
|
|
419
|
-
} catch (error) {
|
|
420
|
-
this.formLogger.warn("Failed to extract submission parameters, using empty object:", error);
|
|
421
|
-
submissionData = {};
|
|
91
|
+
async initialize() {
|
|
92
|
+
if (this.isRegistered) {
|
|
93
|
+
this.logger.warn("ContentStoreManager is already initialized");
|
|
94
|
+
return;
|
|
422
95
|
}
|
|
423
|
-
const mergedToolInput = {};
|
|
424
96
|
try {
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
Object.keys(submissionData).forEach((key) => {
|
|
432
|
-
const value = submissionData[key];
|
|
433
|
-
if (value !== void 0 && value !== null) {
|
|
434
|
-
mergedToolInput[key] = value;
|
|
435
|
-
}
|
|
436
|
-
});
|
|
437
|
-
mergedToolInput.renderForm = false;
|
|
438
|
-
mergedToolInput.__fromForm = true;
|
|
439
|
-
this.formLogger.info("Successfully merged tool input:", {
|
|
440
|
-
baseKeys: Object.keys(baseToolInput),
|
|
441
|
-
submissionKeys: Object.keys(submissionData),
|
|
442
|
-
mergedKeys: Object.keys(mergedToolInput)
|
|
443
|
-
});
|
|
97
|
+
await ContentStoreService.setInstance(this.adapter);
|
|
98
|
+
ContentResolverRegistry.register(this.resolver);
|
|
99
|
+
this.isRegistered = true;
|
|
100
|
+
this.logger.info(
|
|
101
|
+
"ContentStoreManager initialized and registered for cross-package access"
|
|
102
|
+
);
|
|
444
103
|
} catch (error) {
|
|
445
|
-
this.
|
|
446
|
-
throw new Error(`Failed to merge tool input data: ${error instanceof Error ? error.message : "Unknown error"}`);
|
|
447
|
-
}
|
|
448
|
-
try {
|
|
449
|
-
const maybeWrapper = tool;
|
|
450
|
-
let toolOutput;
|
|
451
|
-
if (typeof maybeWrapper.executeOriginal === "function") {
|
|
452
|
-
toolOutput = await maybeWrapper.executeOriginal(mergedToolInput);
|
|
453
|
-
} else if (typeof maybeWrapper.getOriginalTool === "function") {
|
|
454
|
-
const ot = maybeWrapper.getOriginalTool();
|
|
455
|
-
const otCall = ot;
|
|
456
|
-
if (ot && typeof otCall._call === "function") {
|
|
457
|
-
toolOutput = await otCall._call(mergedToolInput);
|
|
458
|
-
} else if (ot && typeof otCall.call === "function") {
|
|
459
|
-
toolOutput = await otCall.call(mergedToolInput);
|
|
460
|
-
} else {
|
|
461
|
-
const tcall = tool;
|
|
462
|
-
if (typeof tcall.call === "function") {
|
|
463
|
-
toolOutput = await tcall.call(mergedToolInput);
|
|
464
|
-
} else {
|
|
465
|
-
throw new Error("No callable tool implementation found for form submission");
|
|
466
|
-
}
|
|
467
|
-
}
|
|
468
|
-
} else if (maybeWrapper.originalTool && typeof maybeWrapper.originalTool._call === "function") {
|
|
469
|
-
toolOutput = await maybeWrapper.originalTool._call(mergedToolInput);
|
|
470
|
-
} else if (maybeWrapper.originalTool && typeof maybeWrapper.originalTool.call === "function") {
|
|
471
|
-
toolOutput = await maybeWrapper.originalTool.call(mergedToolInput);
|
|
472
|
-
} else if (typeof tool.call === "function") {
|
|
473
|
-
toolOutput = await tool.call(mergedToolInput);
|
|
474
|
-
} else {
|
|
475
|
-
throw new Error("No callable tool implementation found for form submission");
|
|
476
|
-
}
|
|
477
|
-
let responseMetadata = {};
|
|
478
|
-
let formattedOutput;
|
|
479
|
-
this.formLogger.info("🔍 METADATA EXTRACTION: Analyzing tool output", {
|
|
480
|
-
outputType: typeof toolOutput,
|
|
481
|
-
outputLength: toolOutput?.length || 0,
|
|
482
|
-
isString: typeof toolOutput === "string",
|
|
483
|
-
firstChars: typeof toolOutput === "string" ? toolOutput.substring(0, 100) : "not-string"
|
|
484
|
-
});
|
|
485
|
-
try {
|
|
486
|
-
const parsed = JSON.parse(toolOutput);
|
|
487
|
-
this.formLogger.info("✅ METADATA EXTRACTION: Successfully parsed JSON", {
|
|
488
|
-
jsonKeys: Object.keys(parsed),
|
|
489
|
-
hasHashLinkBlock: !!parsed.hashLinkBlock
|
|
490
|
-
});
|
|
491
|
-
if (parsed && typeof parsed === "object") {
|
|
492
|
-
if (ResponseFormatter.isHashLinkResponse(parsed)) {
|
|
493
|
-
this.formLogger.info("🔗 HASHLINK DETECTED: Processing HashLink response separately to preserve metadata");
|
|
494
|
-
responseMetadata = {
|
|
495
|
-
...responseMetadata,
|
|
496
|
-
hashLinkBlock: parsed.hashLinkBlock
|
|
497
|
-
};
|
|
498
|
-
formattedOutput = ResponseFormatter.formatHashLinkResponse(parsed);
|
|
499
|
-
this.formLogger.info("🔗 METADATA PRESERVED: HashLink metadata extracted for component rendering", {
|
|
500
|
-
blockId: responseMetadata.hashLinkBlock?.blockId,
|
|
501
|
-
hasTemplate: !!responseMetadata.hashLinkBlock?.template
|
|
502
|
-
});
|
|
503
|
-
} else {
|
|
504
|
-
formattedOutput = ResponseFormatter.formatResponse(toolOutput);
|
|
505
|
-
responseMetadata = {
|
|
506
|
-
...responseMetadata,
|
|
507
|
-
hashLinkBlock: parsed.hashLinkBlock
|
|
508
|
-
};
|
|
509
|
-
}
|
|
510
|
-
} else {
|
|
511
|
-
formattedOutput = ResponseFormatter.formatResponse(toolOutput);
|
|
512
|
-
}
|
|
513
|
-
} catch (error) {
|
|
514
|
-
this.formLogger.warn("❌ METADATA EXTRACTION: Tool output is not JSON", {
|
|
515
|
-
error: error instanceof Error ? error.message : "unknown error",
|
|
516
|
-
outputSample: typeof toolOutput === "string" ? toolOutput.substring(0, 200) : "not-string"
|
|
517
|
-
});
|
|
518
|
-
formattedOutput = ResponseFormatter.formatResponse(toolOutput);
|
|
519
|
-
}
|
|
520
|
-
return {
|
|
521
|
-
output: formattedOutput,
|
|
522
|
-
formCompleted: true,
|
|
523
|
-
originalFormId: submission.formId,
|
|
524
|
-
intermediateSteps: [],
|
|
525
|
-
metadata: responseMetadata
|
|
526
|
-
};
|
|
527
|
-
} catch (error) {
|
|
528
|
-
if (error instanceof ZodError) {
|
|
529
|
-
return this.handleValidationError(error, mergedToolInput, []);
|
|
530
|
-
}
|
|
104
|
+
this.logger.error("Failed to initialize ContentStoreManager:", error);
|
|
531
105
|
throw error;
|
|
532
106
|
}
|
|
533
107
|
}
|
|
534
108
|
/**
|
|
535
|
-
*
|
|
109
|
+
* Get the underlying ContentStorage instance
|
|
536
110
|
*/
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
if (intermediateSteps.length > 0) {
|
|
540
|
-
const lastStep = intermediateSteps[intermediateSteps.length - 1];
|
|
541
|
-
if (lastStep.action && lastStep.action.tool) {
|
|
542
|
-
const tool = this.tools.find((t) => t.name === lastStep.action.tool);
|
|
543
|
-
if (tool && "schema" in tool) {
|
|
544
|
-
this.formLogger.info("Found tool from intermediate steps:", lastStep.action.tool);
|
|
545
|
-
return {
|
|
546
|
-
toolName: lastStep.action.tool,
|
|
547
|
-
schema: tool.schema
|
|
548
|
-
};
|
|
549
|
-
}
|
|
550
|
-
}
|
|
551
|
-
}
|
|
552
|
-
const inputSteps = inputs.intermediateSteps || [];
|
|
553
|
-
if (inputSteps.length > 0) {
|
|
554
|
-
const lastStep = inputSteps[inputSteps.length - 1];
|
|
555
|
-
let action;
|
|
556
|
-
if (Array.isArray(lastStep) && lastStep.length > 0) {
|
|
557
|
-
action = lastStep[0];
|
|
558
|
-
} else if (lastStep.action) {
|
|
559
|
-
action = lastStep.action;
|
|
560
|
-
} else {
|
|
561
|
-
action = lastStep;
|
|
562
|
-
}
|
|
563
|
-
if (action && action.tool) {
|
|
564
|
-
const tool = this.tools.find((t) => t.name === action.tool);
|
|
565
|
-
if (tool && "schema" in tool) {
|
|
566
|
-
this.formLogger.info("Found tool from input steps:", action.tool);
|
|
567
|
-
return {
|
|
568
|
-
toolName: action.tool,
|
|
569
|
-
schema: tool.schema
|
|
570
|
-
};
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
const toolFromContext = this.findToolFromContext(inputs);
|
|
575
|
-
if (toolFromContext) {
|
|
576
|
-
this.formLogger.info("Found tool from context:", toolFromContext.toolName);
|
|
577
|
-
return toolFromContext;
|
|
578
|
-
}
|
|
579
|
-
return null;
|
|
580
|
-
} catch (err) {
|
|
581
|
-
this.formLogger.error("Error extracting tool info:", err);
|
|
582
|
-
return null;
|
|
583
|
-
}
|
|
111
|
+
getContentStorage() {
|
|
112
|
+
return this.contentStorage;
|
|
584
113
|
}
|
|
585
114
|
/**
|
|
586
|
-
*
|
|
115
|
+
* Get storage statistics
|
|
587
116
|
*/
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
for (const tool of this.tools) {
|
|
591
|
-
const keywords = this.extractToolKeywords(tool.name);
|
|
592
|
-
if (keywords.some(
|
|
593
|
-
(keyword) => inputText.toLowerCase().includes(keyword.toLowerCase())
|
|
594
|
-
)) {
|
|
595
|
-
if ("schema" in tool) {
|
|
596
|
-
return {
|
|
597
|
-
toolName: tool.name,
|
|
598
|
-
schema: tool.schema
|
|
599
|
-
};
|
|
600
|
-
}
|
|
601
|
-
}
|
|
602
|
-
}
|
|
603
|
-
return null;
|
|
117
|
+
async getStats() {
|
|
118
|
+
return await this.contentStorage.getStats();
|
|
604
119
|
}
|
|
605
120
|
/**
|
|
606
|
-
*
|
|
121
|
+
* Update configuration
|
|
607
122
|
*/
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
for (const tool of this.tools) {
|
|
611
|
-
if ("schema" in tool) {
|
|
612
|
-
const toolSchema = tool.schema;
|
|
613
|
-
if (this.schemaMatchesErrorPaths(toolSchema, errorPaths)) {
|
|
614
|
-
this.formLogger.info("Detected tool from error path analysis:", tool.name);
|
|
615
|
-
return {
|
|
616
|
-
toolName: tool.name,
|
|
617
|
-
schema: toolSchema
|
|
618
|
-
};
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
return null;
|
|
123
|
+
async updateConfig(config) {
|
|
124
|
+
return await this.contentStorage.updateConfig(config);
|
|
623
125
|
}
|
|
624
126
|
/**
|
|
625
|
-
*
|
|
127
|
+
* Perform manual cleanup
|
|
626
128
|
*/
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
if (!schemaRecord || !schemaRecord._def) return false;
|
|
630
|
-
try {
|
|
631
|
-
const def = schemaRecord._def;
|
|
632
|
-
if (def.typeName === "ZodObject") {
|
|
633
|
-
const shape = def.shape;
|
|
634
|
-
const schemaKeys = Object.keys(shape || {});
|
|
635
|
-
return errorPaths.some((path) => {
|
|
636
|
-
const topLevelKey = path.split(".")[0];
|
|
637
|
-
return schemaKeys.includes(topLevelKey);
|
|
638
|
-
});
|
|
639
|
-
}
|
|
640
|
-
} catch (err) {
|
|
641
|
-
this.formLogger.debug("Error analyzing schema structure:", err);
|
|
642
|
-
}
|
|
643
|
-
return false;
|
|
644
|
-
}
|
|
645
|
-
/**
|
|
646
|
-
* Extracts keywords from tool name for matching
|
|
647
|
-
*/
|
|
648
|
-
extractToolKeywords(toolName) {
|
|
649
|
-
const words = toolName.replace(/([A-Z])/g, " $1").toLowerCase().split(/[\s_-]+/).filter((w) => w.length > 2);
|
|
650
|
-
return [...words, toolName.toLowerCase()];
|
|
129
|
+
async performCleanup() {
|
|
130
|
+
return await this.contentStorage.performCleanup();
|
|
651
131
|
}
|
|
652
132
|
/**
|
|
653
|
-
*
|
|
133
|
+
* Check if content should be stored as reference
|
|
654
134
|
*/
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
const fieldList = formMessage.formConfig.fields.slice(0, 3).map((f) => `• ${f.label}`).join("\n");
|
|
658
|
-
return `I need some additional information to complete your request.
|
|
659
|
-
|
|
660
|
-
${formMessage.formConfig.description}
|
|
661
|
-
|
|
662
|
-
Required fields:
|
|
663
|
-
${fieldList}${fieldCount > 3 ? `
|
|
664
|
-
... and ${fieldCount - 3} more` : ""}
|
|
665
|
-
|
|
666
|
-
Please fill out the form below to continue.`;
|
|
135
|
+
shouldUseReference(content) {
|
|
136
|
+
return this.contentStorage.shouldUseReference(content);
|
|
667
137
|
}
|
|
668
138
|
/**
|
|
669
|
-
*
|
|
139
|
+
* Store content if it's large enough
|
|
670
140
|
*/
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
}));
|
|
141
|
+
async storeContentIfLarge(content, metadata) {
|
|
142
|
+
const storeMetadata = {
|
|
143
|
+
source: "system",
|
|
144
|
+
contentType: "binary",
|
|
145
|
+
...metadata
|
|
146
|
+
};
|
|
147
|
+
return await this.contentStorage.storeContentIfLarge(
|
|
148
|
+
content,
|
|
149
|
+
storeMetadata
|
|
150
|
+
);
|
|
682
151
|
}
|
|
683
152
|
/**
|
|
684
|
-
*
|
|
153
|
+
* Cleanup and unregister
|
|
685
154
|
*/
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
}
|
|
694
|
-
if (!hashLinkBlock) {
|
|
695
|
-
throw new Error("HashLink block data not found in response");
|
|
696
|
-
}
|
|
697
|
-
if (!hashLinkBlock.blockId || !hashLinkBlock.hashLink || !hashLinkBlock.attributes) {
|
|
698
|
-
throw new Error("Invalid HashLink block structure - missing required fields");
|
|
699
|
-
}
|
|
700
|
-
let message = "Content processed successfully!";
|
|
701
|
-
if (toolResponse.success && toolResponse.inscription) {
|
|
702
|
-
const inscription = toolResponse.inscription;
|
|
703
|
-
const metadata = toolResponse.metadata || {};
|
|
704
|
-
message = `✅ ${inscription.standard} Hashinal inscription completed!
|
|
705
|
-
|
|
706
|
-
`;
|
|
707
|
-
if (metadata.name) {
|
|
708
|
-
message += `**${metadata.name}**
|
|
709
|
-
`;
|
|
710
|
-
}
|
|
711
|
-
if (metadata.description) {
|
|
712
|
-
message += `${metadata.description}
|
|
713
|
-
|
|
714
|
-
`;
|
|
715
|
-
}
|
|
716
|
-
message += `📍 **Topic ID:** ${inscription.topicId}
|
|
717
|
-
`;
|
|
718
|
-
message += `🔗 **HRL:** ${inscription.hrl}
|
|
719
|
-
`;
|
|
720
|
-
if (inscription.cdnUrl) {
|
|
721
|
-
message += `🌐 **CDN URL:** ${inscription.cdnUrl}
|
|
722
|
-
`;
|
|
723
|
-
}
|
|
724
|
-
if (metadata.creator) {
|
|
725
|
-
message += `👤 **Creator:** ${metadata.creator}
|
|
726
|
-
`;
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
this.formLogger.info("Processed HashLink response", {
|
|
730
|
-
blockId: hashLinkBlock.blockId,
|
|
731
|
-
hashLink: hashLinkBlock.hashLink,
|
|
732
|
-
hasTemplate: !!hashLinkBlock.template,
|
|
733
|
-
attributeCount: Object.keys(hashLinkBlock.attributes || {}).length
|
|
734
|
-
});
|
|
735
|
-
return {
|
|
736
|
-
hasHashLinkBlocks: true,
|
|
737
|
-
hashLinkBlock,
|
|
738
|
-
message
|
|
739
|
-
};
|
|
740
|
-
} catch (error) {
|
|
741
|
-
this.formLogger.error("Error processing HashLink response:", error);
|
|
742
|
-
return {
|
|
743
|
-
hasHashLinkBlocks: false,
|
|
744
|
-
message: "Content processed, but interactive display is not available."
|
|
745
|
-
};
|
|
155
|
+
async dispose() {
|
|
156
|
+
if (this.isRegistered) {
|
|
157
|
+
this.contentStorage.dispose();
|
|
158
|
+
ContentStoreService.dispose();
|
|
159
|
+
ContentResolverRegistry.unregister();
|
|
160
|
+
this.isRegistered = false;
|
|
161
|
+
this.logger.info("ContentStoreManager disposed and unregistered");
|
|
746
162
|
}
|
|
747
163
|
}
|
|
748
164
|
/**
|
|
749
|
-
*
|
|
165
|
+
* Check if the manager is initialized
|
|
750
166
|
*/
|
|
751
|
-
|
|
752
|
-
return
|
|
753
|
-
strategies: this.formEngine.getRegisteredStrategies(),
|
|
754
|
-
middleware: this.formEngine.getRegisteredMiddleware()
|
|
755
|
-
};
|
|
167
|
+
isInitialized() {
|
|
168
|
+
return this.isRegistered;
|
|
756
169
|
}
|
|
757
170
|
}
|
|
758
171
|
export {
|
|
759
|
-
|
|
172
|
+
ContentStoreManager
|
|
760
173
|
};
|
|
761
174
|
//# sourceMappingURL=index24.js.map
|