@hashgraphonline/conversational-agent 0.1.209 → 0.1.210
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/bin/conversational-agent-cli.js +30 -0
- package/cli/readme.md +181 -0
- package/dist/cjs/base-agent.d.ts +3 -1
- package/dist/cjs/conversational-agent.d.ts +14 -22
- package/dist/cjs/index.cjs +1 -1
- package/dist/cjs/index.cjs.map +1 -1
- package/dist/cjs/index.d.ts +5 -3
- package/dist/cjs/langchain-agent.d.ts +6 -3
- package/dist/cjs/memory/SmartMemoryManager.d.ts +7 -1
- package/dist/cjs/memory/TokenCounter.d.ts +1 -1
- package/dist/cjs/plugins/hbar/AirdropToolWrapper.d.ts +43 -0
- package/dist/{types/plugins/hbar-transfer/HbarTransferPlugin.d.ts → cjs/plugins/hbar/HbarPlugin.d.ts} +2 -1
- package/dist/{types/plugins/hbar-transfer → cjs/plugins/hbar}/TransferHbarTool.d.ts +1 -1
- package/dist/cjs/plugins/hbar/index.d.ts +3 -0
- package/dist/cjs/plugins/index.d.ts +2 -1
- package/dist/cjs/services/EntityResolver.d.ts +26 -0
- package/dist/cjs/tools/EntityResolverTool.d.ts +104 -0
- package/dist/cjs/types/inscription.d.ts +37 -0
- package/dist/esm/index.js +8 -2
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/index12.js +1 -4
- package/dist/esm/index12.js.map +1 -1
- package/dist/esm/index13.js +0 -1
- package/dist/esm/index13.js.map +1 -1
- package/dist/esm/index14.js +2 -7
- package/dist/esm/index14.js.map +1 -1
- package/dist/esm/index15.js +31 -69
- package/dist/esm/index15.js.map +1 -1
- package/dist/esm/index16.js +126 -39
- package/dist/esm/index16.js.map +1 -1
- package/dist/esm/index17.js +148 -13
- package/dist/esm/index17.js.map +1 -1
- package/dist/esm/index18.js +44 -146
- package/dist/esm/index18.js.map +1 -1
- package/dist/esm/index19.js +100 -6
- package/dist/esm/index19.js.map +1 -1
- package/dist/esm/index20.js +20 -174
- package/dist/esm/index20.js.map +1 -1
- package/dist/esm/index21.js +7 -151
- package/dist/esm/index21.js.map +1 -1
- package/dist/esm/index22.js +154 -45
- package/dist/esm/index22.js.map +1 -1
- package/dist/esm/index23.js +149 -24
- package/dist/esm/index23.js.map +1 -1
- package/dist/esm/index24.js +56 -83
- package/dist/esm/index24.js.map +1 -1
- package/dist/esm/index25.js +24 -236
- package/dist/esm/index25.js.map +1 -1
- package/dist/esm/index26.js +95 -0
- package/dist/esm/index26.js.map +1 -0
- package/dist/esm/index27.js +242 -0
- package/dist/esm/index27.js.map +1 -0
- package/dist/esm/index5.js +32 -19
- package/dist/esm/index5.js.map +1 -1
- package/dist/esm/index6.js +156 -195
- package/dist/esm/index6.js.map +1 -1
- package/dist/esm/index7.js +2 -2
- package/dist/esm/index7.js.map +1 -1
- package/dist/esm/index8.js +80 -48
- package/dist/esm/index8.js.map +1 -1
- package/dist/types/base-agent.d.ts +3 -1
- package/dist/types/conversational-agent.d.ts +14 -22
- package/dist/types/index.d.ts +5 -3
- package/dist/types/langchain-agent.d.ts +6 -3
- package/dist/types/memory/SmartMemoryManager.d.ts +7 -1
- package/dist/types/memory/TokenCounter.d.ts +1 -1
- package/dist/types/plugins/hbar/AirdropToolWrapper.d.ts +43 -0
- package/dist/{cjs/plugins/hbar-transfer/HbarTransferPlugin.d.ts → types/plugins/hbar/HbarPlugin.d.ts} +2 -1
- package/dist/{cjs/plugins/hbar-transfer → types/plugins/hbar}/TransferHbarTool.d.ts +1 -1
- package/dist/types/plugins/hbar/index.d.ts +3 -0
- package/dist/types/plugins/index.d.ts +2 -1
- package/dist/types/services/EntityResolver.d.ts +26 -0
- package/dist/types/tools/EntityResolverTool.d.ts +104 -0
- package/dist/types/types/inscription.d.ts +37 -0
- package/package.json +13 -4
- package/src/base-agent.ts +14 -9
- package/src/config/system-message.ts +11 -2
- package/src/context/ReferenceContextManager.ts +1 -1
- package/src/conversational-agent.ts +221 -254
- package/src/index.ts +17 -3
- package/src/langchain-agent.ts +130 -78
- package/src/mcp/ContentProcessor.ts +0 -2
- package/src/mcp/adapters/langchain.ts +0 -1
- package/src/memory/ContentStorage.ts +0 -5
- package/src/memory/MemoryWindow.ts +0 -1
- package/src/memory/ReferenceIdGenerator.ts +4 -4
- package/src/memory/SmartMemoryManager.ts +53 -92
- package/src/memory/TokenCounter.ts +4 -7
- package/src/plugins/hbar/AirdropToolWrapper.ts +157 -0
- package/src/plugins/hbar/HbarPlugin.ts +86 -0
- package/src/plugins/{hbar-transfer → hbar}/TransferHbarTool.ts +3 -3
- package/src/plugins/hbar/index.ts +3 -0
- package/src/plugins/index.ts +2 -1
- package/src/services/EntityResolver.ts +135 -0
- package/src/tools/EntityResolverTool.ts +170 -0
- package/src/types/inscription.ts +40 -0
- package/dist/cjs/plugins/hbar-transfer/index.d.ts +0 -1
- package/dist/types/plugins/hbar-transfer/index.d.ts +0 -1
- package/src/plugins/hbar-transfer/HbarTransferPlugin.ts +0 -66
- package/src/plugins/hbar-transfer/index.ts +0 -1
- /package/dist/cjs/plugins/{hbar-transfer → hbar}/AccountBuilder.d.ts +0 -0
- /package/dist/cjs/plugins/{hbar-transfer → hbar}/types.d.ts +0 -0
- /package/dist/types/plugins/{hbar-transfer → hbar}/AccountBuilder.d.ts +0 -0
- /package/dist/types/plugins/{hbar-transfer → hbar}/types.d.ts +0 -0
- /package/src/plugins/{hbar-transfer → hbar}/AccountBuilder.ts +0 -0
- /package/src/plugins/{hbar-transfer → hbar}/types.ts +0 -0
package/dist/esm/index16.js
CHANGED
|
@@ -1,49 +1,136 @@
|
|
|
1
|
+
import { StructuredTool } from "@langchain/core/tools";
|
|
1
2
|
import { z } from "zod";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
import { ChatOpenAI } from "@langchain/openai";
|
|
4
|
+
const ResolveEntitiesSchema = z.object({
|
|
5
|
+
message: z.string().describe("The message containing entity references to resolve"),
|
|
6
|
+
entities: z.array(z.object({
|
|
7
|
+
entityId: z.string(),
|
|
8
|
+
entityName: z.string(),
|
|
9
|
+
entityType: z.string()
|
|
10
|
+
})).describe("Available entities in memory")
|
|
9
11
|
});
|
|
10
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
),
|
|
14
|
-
memo: z.string().optional().describe("Optional. Memo for the transaction.")
|
|
12
|
+
const ExtractEntitiesSchema = z.object({
|
|
13
|
+
response: z.string().describe("Agent response text to extract entities from"),
|
|
14
|
+
userMessage: z.string().describe("Original user message for context")
|
|
15
15
|
});
|
|
16
|
-
class
|
|
17
|
-
constructor() {
|
|
18
|
-
super(
|
|
19
|
-
this.name = "
|
|
20
|
-
this.description = '
|
|
21
|
-
this.
|
|
22
|
-
this.
|
|
16
|
+
class ResolveEntitiesTool extends StructuredTool {
|
|
17
|
+
constructor(apiKey, modelName = "gpt-4o-mini") {
|
|
18
|
+
super();
|
|
19
|
+
this.name = "resolve_entities";
|
|
20
|
+
this.description = 'Resolves entity references like "the topic", "it", "that" to actual entity IDs';
|
|
21
|
+
this.schema = ResolveEntitiesSchema;
|
|
22
|
+
this.llm = new ChatOpenAI({
|
|
23
|
+
apiKey,
|
|
24
|
+
modelName,
|
|
25
|
+
temperature: 0
|
|
26
|
+
});
|
|
23
27
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
async _call(input) {
|
|
29
|
+
const { message, entities } = input;
|
|
30
|
+
if (!entities || entities.length === 0) {
|
|
31
|
+
return message;
|
|
32
|
+
}
|
|
33
|
+
const byType = this.groupEntitiesByType(entities);
|
|
34
|
+
const context = this.buildEntityContext(byType);
|
|
35
|
+
const prompt = `Task: Replace entity references with IDs.
|
|
36
|
+
|
|
37
|
+
${context}
|
|
38
|
+
|
|
39
|
+
Message: "${message}"
|
|
40
|
+
|
|
41
|
+
Rules:
|
|
42
|
+
- "the topic" or "that topic" → replace with most recent topic ID
|
|
43
|
+
- "the token" or "that token" → replace with most recent token ID
|
|
44
|
+
- "it" or "that" after action verb → replace with most recent entity ID
|
|
45
|
+
- "airdrop X" without token ID → add most recent token ID as first parameter
|
|
46
|
+
- Token operations without explicit token → use most recent token ID
|
|
47
|
+
|
|
48
|
+
Examples:
|
|
49
|
+
- "submit on the topic" → "submit on 0.0.6543472"
|
|
50
|
+
- "airdrop the token" → "airdrop 0.0.123456"
|
|
51
|
+
- "airdrop 10 to 0.0.5842697" → "airdrop 0.0.123456 10 to 0.0.5842697"
|
|
52
|
+
- "mint 100" → "mint 0.0.123456 100"
|
|
53
|
+
|
|
54
|
+
Return ONLY the resolved message:`;
|
|
55
|
+
try {
|
|
56
|
+
const response = await this.llm.invoke(prompt);
|
|
57
|
+
return response.content.trim();
|
|
58
|
+
} catch (error) {
|
|
59
|
+
console.error("[ResolveEntitiesTool] Failed:", error);
|
|
60
|
+
return message;
|
|
61
|
+
}
|
|
31
62
|
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
async callBuilderMethod(builder, specificArgs) {
|
|
41
|
-
await builder.transferHbar(
|
|
42
|
-
specificArgs
|
|
43
|
-
);
|
|
63
|
+
groupEntitiesByType(entities) {
|
|
64
|
+
return entities.reduce((acc, entity) => {
|
|
65
|
+
if (!acc[entity.entityType]) {
|
|
66
|
+
acc[entity.entityType] = [];
|
|
67
|
+
}
|
|
68
|
+
acc[entity.entityType].push(entity);
|
|
69
|
+
return acc;
|
|
70
|
+
}, {});
|
|
44
71
|
}
|
|
72
|
+
buildEntityContext(groupedEntities) {
|
|
73
|
+
let context = "Available entities:\n";
|
|
74
|
+
for (const [type, list] of Object.entries(groupedEntities)) {
|
|
75
|
+
const recent = list[0];
|
|
76
|
+
context += `- Most recent ${type}: "${recent.entityName}" = ${recent.entityId}
|
|
77
|
+
`;
|
|
78
|
+
}
|
|
79
|
+
return context;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
class ExtractEntitiesTool extends StructuredTool {
|
|
83
|
+
constructor(apiKey, modelName = "gpt-4o-mini") {
|
|
84
|
+
super();
|
|
85
|
+
this.name = "extract_entities";
|
|
86
|
+
this.description = "Extracts newly created entities from agent responses";
|
|
87
|
+
this.schema = ExtractEntitiesSchema;
|
|
88
|
+
this.llm = new ChatOpenAI({
|
|
89
|
+
apiKey,
|
|
90
|
+
modelName,
|
|
91
|
+
temperature: 0
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
async _call(input) {
|
|
95
|
+
const { response, userMessage } = input;
|
|
96
|
+
const prompt = `Extract ONLY newly created entities from this response.
|
|
97
|
+
|
|
98
|
+
User asked: "${userMessage.substring(0, 200)}"
|
|
99
|
+
Response: ${response.substring(0, 3e3)}
|
|
100
|
+
|
|
101
|
+
Look for:
|
|
102
|
+
- Success messages with new entity IDs
|
|
103
|
+
- Words like "created", "new", "successfully" followed by entity IDs
|
|
104
|
+
|
|
105
|
+
Return JSON array of created entities:
|
|
106
|
+
[{"id": "0.0.XXX", "name": "name", "type": "topic|token|account"}]
|
|
107
|
+
|
|
108
|
+
If none created, return: []
|
|
109
|
+
|
|
110
|
+
JSON:`;
|
|
111
|
+
try {
|
|
112
|
+
const llmResponse = await this.llm.invoke(prompt);
|
|
113
|
+
const content = llmResponse.content;
|
|
114
|
+
const match = content.match(/\[[\s\S]*?\]/);
|
|
115
|
+
if (match) {
|
|
116
|
+
return match[0];
|
|
117
|
+
}
|
|
118
|
+
return "[]";
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.error("[ExtractEntitiesTool] Failed:", error);
|
|
121
|
+
return "[]";
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
function createEntityTools(apiKey, modelName = "gpt-4o-mini") {
|
|
126
|
+
return {
|
|
127
|
+
resolveEntities: new ResolveEntitiesTool(apiKey, modelName),
|
|
128
|
+
extractEntities: new ExtractEntitiesTool(apiKey, modelName)
|
|
129
|
+
};
|
|
45
130
|
}
|
|
46
131
|
export {
|
|
47
|
-
|
|
132
|
+
ExtractEntitiesTool,
|
|
133
|
+
ResolveEntitiesTool,
|
|
134
|
+
createEntityTools
|
|
48
135
|
};
|
|
49
136
|
//# sourceMappingURL=index16.js.map
|
package/dist/esm/index16.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index16.js","sources":["../../src/
|
|
1
|
+
{"version":3,"file":"index16.js","sources":["../../src/tools/EntityResolverTool.ts"],"sourcesContent":["import { StructuredTool } from '@langchain/core/tools';\nimport { z } from 'zod';\nimport { ChatOpenAI } from '@langchain/openai';\nimport type { EntityAssociation } from '../memory/SmartMemoryManager';\n\nconst ResolveEntitiesSchema = z.object({\n message: z.string().describe('The message containing entity references to resolve'),\n entities: z.array(z.object({\n entityId: z.string(),\n entityName: z.string(),\n entityType: z.string(),\n })).describe('Available entities in memory'),\n});\n\nconst ExtractEntitiesSchema = z.object({\n response: z.string().describe('Agent response text to extract entities from'),\n userMessage: z.string().describe('Original user message for context'),\n});\n\nexport class ResolveEntitiesTool extends StructuredTool {\n name = 'resolve_entities';\n description = 'Resolves entity references like \"the topic\", \"it\", \"that\" to actual entity IDs';\n schema = ResolveEntitiesSchema;\n \n private llm: ChatOpenAI;\n \n constructor(apiKey: string, modelName = 'gpt-4o-mini') {\n super();\n this.llm = new ChatOpenAI({\n apiKey,\n modelName,\n temperature: 0,\n });\n }\n \n async _call(input: z.infer<typeof ResolveEntitiesSchema>): Promise<string> {\n const { message, entities } = input;\n \n if (!entities || entities.length === 0) {\n return message;\n }\n \n const byType = this.groupEntitiesByType(entities);\n const context = this.buildEntityContext(byType);\n \n const prompt = `Task: Replace entity references with IDs.\n\n${context}\n\nMessage: \"${message}\"\n\nRules:\n- \"the topic\" or \"that topic\" → replace with most recent topic ID\n- \"the token\" or \"that token\" → replace with most recent token ID\n- \"it\" or \"that\" after action verb → replace with most recent entity ID\n- \"airdrop X\" without token ID → add most recent token ID as first parameter\n- Token operations without explicit token → use most recent token ID\n\nExamples:\n- \"submit on the topic\" → \"submit on 0.0.6543472\"\n- \"airdrop the token\" → \"airdrop 0.0.123456\"\n- \"airdrop 10 to 0.0.5842697\" → \"airdrop 0.0.123456 10 to 0.0.5842697\"\n- \"mint 100\" → \"mint 0.0.123456 100\"\n\nReturn ONLY the resolved message:`;\n \n try {\n const response = await this.llm.invoke(prompt);\n return (response.content as string).trim();\n } catch (error) {\n console.error('[ResolveEntitiesTool] Failed:', error);\n return message;\n }\n }\n \n private groupEntitiesByType(entities: EntityGroup): GroupedEntities {\n return entities.reduce((acc, entity) => {\n if (!acc[entity.entityType]) {\n acc[entity.entityType] = [];\n }\n acc[entity.entityType].push(entity);\n return acc;\n }, {} as GroupedEntities);\n }\n \n private buildEntityContext(groupedEntities: GroupedEntities): string {\n let context = 'Available entities:\\n';\n for (const [type, list] of Object.entries(groupedEntities)) {\n const recent = list[0];\n context += `- Most recent ${type}: \"${recent.entityName}\" = ${recent.entityId}\\n`;\n }\n return context;\n }\n}\n\nexport class ExtractEntitiesTool extends StructuredTool {\n name = 'extract_entities';\n description = 'Extracts newly created entities from agent responses';\n schema = ExtractEntitiesSchema;\n \n private llm: ChatOpenAI;\n \n constructor(apiKey: string, modelName = 'gpt-4o-mini') {\n super();\n this.llm = new ChatOpenAI({\n apiKey,\n modelName,\n temperature: 0,\n });\n }\n \n async _call(input: z.infer<typeof ExtractEntitiesSchema>): Promise<string> {\n const { response, userMessage } = input;\n \n const prompt = `Extract ONLY newly created entities from this response.\n\nUser asked: \"${userMessage.substring(0, 200)}\"\nResponse: ${response.substring(0, 3000)}\n\nLook for:\n- Success messages with new entity IDs\n- Words like \"created\", \"new\", \"successfully\" followed by entity IDs\n\nReturn JSON array of created entities:\n[{\"id\": \"0.0.XXX\", \"name\": \"name\", \"type\": \"topic|token|account\"}]\n\nIf none created, return: []\n\nJSON:`;\n \n try {\n const llmResponse = await this.llm.invoke(prompt);\n const content = llmResponse.content as string;\n const match = content.match(/\\[[\\s\\S]*?\\]/);\n if (match) {\n return match[0];\n }\n return '[]';\n } catch (error) {\n console.error('[ExtractEntitiesTool] Failed:', error);\n return '[]';\n }\n }\n}\n\nexport function createEntityTools(apiKey: string, modelName = 'gpt-4o-mini'): {\n resolveEntities: ResolveEntitiesTool;\n extractEntities: ExtractEntitiesTool;\n} {\n return {\n resolveEntities: new ResolveEntitiesTool(apiKey, modelName),\n extractEntities: new ExtractEntitiesTool(apiKey, modelName),\n };\n}\n\ninterface EntityReference {\n entityId: string;\n entityName: string;\n entityType: string;\n}\n\ntype EntityGroup = EntityReference[];\n\ntype GroupedEntities = Record<string, EntityGroup>;\n\ninterface ExtractedEntity {\n id: string;\n name: string;\n type: string;\n}"],"names":[],"mappings":";;;AAKA,MAAM,wBAAwB,EAAE,OAAO;AAAA,EACrC,SAAS,EAAE,SAAS,SAAS,qDAAqD;AAAA,EAClF,UAAU,EAAE,MAAM,EAAE,OAAO;AAAA,IACzB,UAAU,EAAE,OAAA;AAAA,IACZ,YAAY,EAAE,OAAA;AAAA,IACd,YAAY,EAAE,OAAA;AAAA,EAAO,CACtB,CAAC,EAAE,SAAS,8BAA8B;AAC7C,CAAC;AAED,MAAM,wBAAwB,EAAE,OAAO;AAAA,EACrC,UAAU,EAAE,SAAS,SAAS,8CAA8C;AAAA,EAC5E,aAAa,EAAE,OAAA,EAAS,SAAS,mCAAmC;AACtE,CAAC;AAEM,MAAM,4BAA4B,eAAe;AAAA,EAOtD,YAAY,QAAgB,YAAY,eAAe;AACrD,UAAA;AAPF,SAAA,OAAO;AACP,SAAA,cAAc;AACd,SAAA,SAAS;AAMP,SAAK,MAAM,IAAI,WAAW;AAAA,MACxB;AAAA,MACA;AAAA,MACA,aAAa;AAAA,IAAA,CACd;AAAA,EACH;AAAA,EAEA,MAAM,MAAM,OAA+D;AACzE,UAAM,EAAE,SAAS,SAAA,IAAa;AAE9B,Q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,MAAM,OAA+D;AACzE,UAAM,EAAE,UAAU,YAAA,IAAgB;AAElC,UAAM,SAAS;AAAA;AAAA,eAEJ,YAAY,UAAU,GAAG,GAAG,CAAC;AAAA,YAChC,SAAS,UAAU,GAAG,GAAI,CAAC;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAanC,QAAI;AACF,YAAM,cAAc,MAAM,KAAK,IAAI,OAAO,MAAM;AAChD,YAAM,UAAU,YAAY;AAC5B,YAAM,QAAQ,QAAQ,MAAM,cAAc;AAC1C,UAAI,OAAO;AACT,eAAO,MAAM,CAAC;AAAA,MAChB;AACA,aAAO;AAAA,IACT,SAAS,OAAO;AACd,cAAQ,MAAM,iCAAiC,KAAK;AACpD,aAAO;AAAA,IACT;AAAA,EACF;AACF;AAEO,SAAS,kBAAkB,QAAgB,YAAY,eAG5D;AACA,SAAO;AAAA,IACL,iBAAiB,IAAI,oBAAoB,QAAQ,SAAS;AAAA,IAC1D,iBAAiB,IAAI,oBAAoB,QAAQ,SAAS;AAAA,EAAA;AAE9D;"}
|
package/dist/esm/index17.js
CHANGED
|
@@ -1,16 +1,151 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { ContentStorage } from "./index14.js";
|
|
2
|
+
import { 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 contentRef = await this.storage.storeContent(content, metadata);
|
|
9
|
+
return contentRef.referenceId;
|
|
10
|
+
}
|
|
11
|
+
async resolveReference(referenceId) {
|
|
12
|
+
const result = await this.storage.resolveReference(referenceId);
|
|
13
|
+
if (result.success && result.content) {
|
|
14
|
+
const response = {
|
|
15
|
+
content: result.content
|
|
16
|
+
};
|
|
17
|
+
if (result.metadata) {
|
|
18
|
+
response.metadata = {
|
|
19
|
+
...result.metadata.mimeType !== void 0 && { mimeType: result.metadata.mimeType },
|
|
20
|
+
...result.metadata.fileName !== void 0 && { fileName: result.metadata.fileName },
|
|
21
|
+
originalSize: result.metadata.sizeBytes
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
return response;
|
|
25
|
+
} else {
|
|
26
|
+
throw new Error(result.error || "Reference not found");
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
async hasReference(referenceId) {
|
|
30
|
+
return await this.storage.hasReference(referenceId);
|
|
31
|
+
}
|
|
32
|
+
async cleanupReference(referenceId) {
|
|
33
|
+
await this.storage.cleanupReference(referenceId);
|
|
34
|
+
}
|
|
35
|
+
async getStats() {
|
|
36
|
+
return await this.storage.getStats();
|
|
37
|
+
}
|
|
38
|
+
async updateConfig(config) {
|
|
39
|
+
return await this.storage.updateConfig(config);
|
|
40
|
+
}
|
|
41
|
+
async performCleanup() {
|
|
42
|
+
await this.storage.performCleanup();
|
|
43
|
+
}
|
|
44
|
+
async dispose() {
|
|
45
|
+
return Promise.resolve(this.storage.dispose());
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
class ContentResolver {
|
|
49
|
+
constructor(adapter) {
|
|
50
|
+
this.adapter = adapter;
|
|
51
|
+
}
|
|
52
|
+
async resolveReference(referenceId) {
|
|
53
|
+
return await this.adapter.resolveReference(referenceId);
|
|
54
|
+
}
|
|
55
|
+
shouldUseReference(content) {
|
|
56
|
+
return shouldUseReference(content);
|
|
57
|
+
}
|
|
58
|
+
extractReferenceId(input) {
|
|
59
|
+
return extractReferenceId(input);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
class ContentStoreManager {
|
|
63
|
+
constructor(maxMessageStorage = 1e3, referenceConfig, logger) {
|
|
64
|
+
this.isRegistered = false;
|
|
65
|
+
this.logger = logger || {
|
|
66
|
+
info: console.log,
|
|
67
|
+
debug: console.log,
|
|
68
|
+
warn: console.warn,
|
|
69
|
+
error: console.error
|
|
70
|
+
};
|
|
71
|
+
this.contentStorage = new ContentStorage(maxMessageStorage, referenceConfig);
|
|
72
|
+
this.adapter = new ContentStorageAdapter(this.contentStorage);
|
|
73
|
+
this.resolver = new ContentResolver(this.adapter);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Initialize and register content storage for cross-package access
|
|
77
|
+
*/
|
|
78
|
+
async initialize() {
|
|
79
|
+
if (this.isRegistered) {
|
|
80
|
+
this.logger.warn("ContentStoreManager is already initialized");
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
try {
|
|
84
|
+
await ContentStoreService.setInstance(this.adapter);
|
|
85
|
+
ContentResolverRegistry.register(this.resolver);
|
|
86
|
+
this.isRegistered = true;
|
|
87
|
+
this.logger.info("ContentStoreManager initialized and registered for cross-package access");
|
|
88
|
+
} catch (error) {
|
|
89
|
+
this.logger.error("Failed to initialize ContentStoreManager:", error);
|
|
90
|
+
throw error;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Get the underlying ContentStorage instance
|
|
95
|
+
*/
|
|
96
|
+
getContentStorage() {
|
|
97
|
+
return this.contentStorage;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Get storage statistics
|
|
101
|
+
*/
|
|
102
|
+
async getStats() {
|
|
103
|
+
return await this.contentStorage.getStats();
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Update configuration
|
|
107
|
+
*/
|
|
108
|
+
async updateConfig(config) {
|
|
109
|
+
return await this.contentStorage.updateConfig(config);
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Perform manual cleanup
|
|
113
|
+
*/
|
|
114
|
+
async performCleanup() {
|
|
115
|
+
return await this.contentStorage.performCleanup();
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Check if content should be stored as reference
|
|
119
|
+
*/
|
|
120
|
+
shouldUseReference(content) {
|
|
121
|
+
return this.contentStorage.shouldUseReference(content);
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Store content if it's large enough
|
|
125
|
+
*/
|
|
126
|
+
async storeContentIfLarge(content, metadata) {
|
|
127
|
+
return await this.contentStorage.storeContentIfLarge(content, metadata);
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* Cleanup and unregister
|
|
131
|
+
*/
|
|
132
|
+
async dispose() {
|
|
133
|
+
if (this.isRegistered) {
|
|
134
|
+
this.contentStorage.dispose();
|
|
135
|
+
ContentStoreService.dispose();
|
|
136
|
+
ContentResolverRegistry.unregister();
|
|
137
|
+
this.isRegistered = false;
|
|
138
|
+
this.logger.info("ContentStoreManager disposed and unregistered");
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Check if the manager is initialized
|
|
143
|
+
*/
|
|
144
|
+
isInitialized() {
|
|
145
|
+
return this.isRegistered;
|
|
146
|
+
}
|
|
147
|
+
}
|
|
13
148
|
export {
|
|
14
|
-
|
|
149
|
+
ContentStoreManager
|
|
15
150
|
};
|
|
16
151
|
//# sourceMappingURL=index17.js.map
|
package/dist/esm/index17.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index17.js","sources":["../../src/
|
|
1
|
+
{"version":3,"file":"index17.js","sources":["../../src/services/ContentStoreManager.ts"],"sourcesContent":["import { ContentStorage } from '../memory/ContentStorage';\nimport { \n ContentStoreService, \n extractReferenceId, \n shouldUseReference,\n ContentResolverRegistry,\n type ContentStoreInterface, \n type ContentResolverInterface, \n type ReferenceResolutionResult \n} from '@hashgraphonline/standards-sdk';\nimport type { ContentReferenceConfig } from '../types/content-reference';\nimport { Logger } from '@hashgraphonline/standards-sdk';\n\n/**\n * Adapter to make ContentStorage compatible with ContentStoreInterface\n */\nclass ContentStorageAdapter implements ContentStoreInterface {\n constructor(private storage: ContentStorage) {}\n\n async storeContent(content: Buffer, metadata: any) {\n const contentRef = await this.storage.storeContent(content, metadata);\n return contentRef.referenceId;\n }\n\n async resolveReference(referenceId: string): Promise<ReferenceResolutionResult> {\n const result = await this.storage.resolveReference(referenceId);\n if (result.success && result.content) {\n const response: ReferenceResolutionResult = {\n content: result.content\n };\n if (result.metadata) {\n response.metadata = {\n ...(result.metadata.mimeType !== undefined && { mimeType: result.metadata.mimeType }),\n ...(result.metadata.fileName !== undefined && { fileName: result.metadata.fileName }),\n originalSize: result.metadata.sizeBytes\n };\n }\n return response;\n } else {\n throw new Error(result.error || 'Reference not found');\n }\n }\n\n async hasReference(referenceId: string) {\n return await this.storage.hasReference(referenceId);\n }\n\n async cleanupReference(referenceId: string) {\n await this.storage.cleanupReference(referenceId);\n }\n\n async getStats() {\n return await this.storage.getStats();\n }\n\n async updateConfig(config: any) {\n return await this.storage.updateConfig(config);\n }\n\n async performCleanup() {\n await this.storage.performCleanup();\n }\n\n async dispose() {\n return Promise.resolve(this.storage.dispose());\n }\n}\n\n/**\n * Content resolver implementation for dependency injection\n */\nclass ContentResolver implements ContentResolverInterface {\n constructor(private adapter: ContentStorageAdapter) {}\n\n async resolveReference(referenceId: string): Promise<ReferenceResolutionResult> {\n return await this.adapter.resolveReference(referenceId);\n }\n\n shouldUseReference(content: string | Buffer): boolean {\n return shouldUseReference(content);\n }\n\n extractReferenceId(input: string): string | null {\n return extractReferenceId(input);\n }\n}\n\n/**\n * Manages content store lifecycle and cross-package registration\n */\nexport class ContentStoreManager {\n private contentStorage: ContentStorage;\n private adapter: ContentStorageAdapter;\n private resolver: ContentResolver;\n private logger: Logger;\n private isRegistered = false;\n\n constructor(\n maxMessageStorage: number = 1000,\n referenceConfig?: Partial<ContentReferenceConfig>,\n logger?: Logger\n ) {\n this.logger = logger || {\n info: console.log,\n debug: console.log,\n warn: console.warn,\n error: console.error\n } as Logger;\n\n this.contentStorage = new ContentStorage(maxMessageStorage, referenceConfig);\n this.adapter = new ContentStorageAdapter(this.contentStorage);\n this.resolver = new ContentResolver(this.adapter);\n }\n\n /**\n * Initialize and register content storage for cross-package access\n */\n async initialize(): Promise<void> {\n if (this.isRegistered) {\n this.logger.warn('ContentStoreManager is already initialized');\n return;\n }\n\n try {\n await ContentStoreService.setInstance(this.adapter);\n ContentResolverRegistry.register(this.resolver);\n this.isRegistered = true;\n this.logger.info('ContentStoreManager initialized and registered for cross-package access');\n } catch (error) {\n this.logger.error('Failed to initialize ContentStoreManager:', error);\n throw error;\n }\n }\n\n /**\n * Get the underlying ContentStorage instance\n */\n getContentStorage(): ContentStorage {\n return this.contentStorage;\n }\n\n /**\n * Get storage statistics\n */\n async getStats() {\n return await this.contentStorage.getStats();\n }\n\n /**\n * Update configuration\n */\n async updateConfig(config: Partial<ContentReferenceConfig>) {\n return await this.contentStorage.updateConfig(config);\n }\n\n /**\n * Perform manual cleanup\n */\n async performCleanup() {\n return await this.contentStorage.performCleanup();\n }\n\n /**\n * Check if content should be stored as reference\n */\n shouldUseReference(content: Buffer | string): boolean {\n return this.contentStorage.shouldUseReference(content);\n }\n\n /**\n * Store content if it's large enough\n */\n async storeContentIfLarge(content: Buffer | string, metadata: any) {\n return await this.contentStorage.storeContentIfLarge(content, metadata);\n }\n\n /**\n * Cleanup and unregister\n */\n async dispose(): Promise<void> {\n if (this.isRegistered) {\n this.contentStorage.dispose();\n ContentStoreService.dispose();\n ContentResolverRegistry.unregister();\n this.isRegistered = false;\n this.logger.info('ContentStoreManager disposed and unregistered');\n }\n }\n\n /**\n * Check if the manager is initialized\n */\n isInitialized(): boolean {\n return this.isRegistered;\n }\n}"],"names":[],"mappings":";;AAgBA,MAAM,sBAAuD;AAAA,EAC3D,YAAoB,SAAyB;AAAzB,SAAA,UAAA;AAAA,EAA0B;AAAA,EAE9C,MAAM,aAAa,SAAiB,UAAe;AACjD,UAAM,aAAa,MAAM,KAAK,QAAQ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A,EAKA,mBAAmB,SAAmC;AACpD,WAAO,KAAK,eAAe,mBAAmB,OAAO;AAAA,EACvD;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,oBAAoB,SAA0B,UAAe;AACjE,WAAO,MAAM,KAAK,eAAe,oBAAoB,SAAS,QAAQ;AAAA,EACxE;AAAA;AAAA;AAAA;AAAA,EAKA,MAAM,UAAyB;AAC7B,QAAI,KAAK,cAAc;AACrB,WAAK,eAAe,QAAA;AACpB,0BAAoB,QAAA;AACpB,8BAAwB,WAAA;AACxB,WAAK,eAAe;AACpB,WAAK,OAAO,KAAK,+CAA+C;AAAA,IAClE;AAAA,EACF;AAAA;AAAA;AAAA;AAAA,EAKA,gBAAyB;AACvB,WAAO,KAAK;AAAA,EACd;AACF;"}
|
package/dist/esm/index18.js
CHANGED
|
@@ -1,151 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
return
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
async dispose() {
|
|
45
|
-
return Promise.resolve(this.storage.dispose());
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
class ContentResolver {
|
|
49
|
-
constructor(adapter) {
|
|
50
|
-
this.adapter = adapter;
|
|
51
|
-
}
|
|
52
|
-
async resolveReference(referenceId) {
|
|
53
|
-
return await this.adapter.resolveReference(referenceId);
|
|
54
|
-
}
|
|
55
|
-
shouldUseReference(content) {
|
|
56
|
-
return shouldUseReference(content);
|
|
57
|
-
}
|
|
58
|
-
extractReferenceId(input) {
|
|
59
|
-
return extractReferenceId(input);
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
class ContentStoreManager {
|
|
63
|
-
constructor(maxMessageStorage = 1e3, referenceConfig, logger) {
|
|
64
|
-
this.isRegistered = false;
|
|
65
|
-
this.logger = logger || {
|
|
66
|
-
info: console.log,
|
|
67
|
-
debug: console.log,
|
|
68
|
-
warn: console.warn,
|
|
69
|
-
error: console.error
|
|
70
|
-
};
|
|
71
|
-
this.contentStorage = new ContentStorage(maxMessageStorage, referenceConfig);
|
|
72
|
-
this.adapter = new ContentStorageAdapter(this.contentStorage);
|
|
73
|
-
this.resolver = new ContentResolver(this.adapter);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Initialize and register content storage for cross-package access
|
|
77
|
-
*/
|
|
78
|
-
async initialize() {
|
|
79
|
-
if (this.isRegistered) {
|
|
80
|
-
this.logger.warn("ContentStoreManager is already initialized");
|
|
81
|
-
return;
|
|
82
|
-
}
|
|
83
|
-
try {
|
|
84
|
-
await ContentStoreService.setInstance(this.adapter);
|
|
85
|
-
ContentResolverRegistry.register(this.resolver);
|
|
86
|
-
this.isRegistered = true;
|
|
87
|
-
this.logger.info("ContentStoreManager initialized and registered for cross-package access");
|
|
88
|
-
} catch (error) {
|
|
89
|
-
this.logger.error("Failed to initialize ContentStoreManager:", error);
|
|
90
|
-
throw error;
|
|
91
|
-
}
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Get the underlying ContentStorage instance
|
|
95
|
-
*/
|
|
96
|
-
getContentStorage() {
|
|
97
|
-
return this.contentStorage;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Get storage statistics
|
|
101
|
-
*/
|
|
102
|
-
async getStats() {
|
|
103
|
-
return await this.contentStorage.getStats();
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Update configuration
|
|
107
|
-
*/
|
|
108
|
-
async updateConfig(config) {
|
|
109
|
-
return await this.contentStorage.updateConfig(config);
|
|
110
|
-
}
|
|
111
|
-
/**
|
|
112
|
-
* Perform manual cleanup
|
|
113
|
-
*/
|
|
114
|
-
async performCleanup() {
|
|
115
|
-
return await this.contentStorage.performCleanup();
|
|
116
|
-
}
|
|
117
|
-
/**
|
|
118
|
-
* Check if content should be stored as reference
|
|
119
|
-
*/
|
|
120
|
-
shouldUseReference(content) {
|
|
121
|
-
return this.contentStorage.shouldUseReference(content);
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Store content if it's large enough
|
|
125
|
-
*/
|
|
126
|
-
async storeContentIfLarge(content, metadata) {
|
|
127
|
-
return await this.contentStorage.storeContentIfLarge(content, metadata);
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Cleanup and unregister
|
|
131
|
-
*/
|
|
132
|
-
async dispose() {
|
|
133
|
-
if (this.isRegistered) {
|
|
134
|
-
this.contentStorage.dispose();
|
|
135
|
-
ContentStoreService.dispose();
|
|
136
|
-
ContentResolverRegistry.unregister();
|
|
137
|
-
this.isRegistered = false;
|
|
138
|
-
this.logger.info("ContentStoreManager disposed and unregistered");
|
|
139
|
-
}
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Check if the manager is initialized
|
|
143
|
-
*/
|
|
144
|
-
isInitialized() {
|
|
145
|
-
return this.isRegistered;
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { AccountBuilder } from "./index26.js";
|
|
3
|
+
import { BaseHederaTransactionTool } from "hedera-agent-kit";
|
|
4
|
+
const HbarTransferInputSchema = z.object({
|
|
5
|
+
accountId: z.string().describe('Account ID for the transfer (e.g., "0.0.xxxx").'),
|
|
6
|
+
amount: z.union([z.number(), z.string()]).describe(
|
|
7
|
+
"HBAR amount in decimal format (e.g., 1 for 1 HBAR, 0.5 for 0.5 HBAR). Positive for credit, negative for debit. DO NOT multiply by 10^8 for tinybars - just use the HBAR amount directly."
|
|
8
|
+
)
|
|
9
|
+
});
|
|
10
|
+
const TransferHbarZodSchemaCore = z.object({
|
|
11
|
+
transfers: z.array(HbarTransferInputSchema).min(1).describe(
|
|
12
|
+
'Array of transfers. For simple transfers from your operator account, just include the recipient with positive amount: [{accountId: "0.0.800", amount: 1}]. For complex multi-party transfers, include all parties with negative amounts for senders and positive for receivers.'
|
|
13
|
+
),
|
|
14
|
+
memo: z.string().optional().describe("Optional. Memo for the transaction.")
|
|
15
|
+
});
|
|
16
|
+
class TransferHbarTool extends BaseHederaTransactionTool {
|
|
17
|
+
constructor() {
|
|
18
|
+
super(...arguments);
|
|
19
|
+
this.name = "hedera-account-transfer-hbar-v2";
|
|
20
|
+
this.description = 'PRIMARY TOOL FOR HBAR TRANSFERS: Transfers HBAR between accounts. For simple transfers from the operator account, just specify the recipient with a positive amount (e.g., [{accountId: "0.0.800", amount: 1}] to send 1 HBAR to 0.0.800). The sender will be automatically added. For multi-party transfers (e.g., "A sends 5 HBAR to C and B sends 3 HBAR to C"), include ALL transfers with their amounts (negative for senders, positive for receivers).';
|
|
21
|
+
this.specificInputSchema = TransferHbarZodSchemaCore;
|
|
22
|
+
this.namespace = "account";
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Creates and returns the service builder for account operations.
|
|
26
|
+
*
|
|
27
|
+
* @returns BaseServiceBuilder instance configured for account operations
|
|
28
|
+
*/
|
|
29
|
+
getServiceBuilder() {
|
|
30
|
+
return new AccountBuilder(this.hederaKit);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Executes the HBAR transfer using the provided builder and arguments.
|
|
34
|
+
* Validates that all transfers sum to zero before execution.
|
|
35
|
+
*
|
|
36
|
+
* @param builder - The service builder instance for executing transactions
|
|
37
|
+
* @param specificArgs - The validated transfer parameters including transfers array and optional memo
|
|
38
|
+
* @returns Promise that resolves when the transfer is complete
|
|
39
|
+
*/
|
|
40
|
+
async callBuilderMethod(builder, specificArgs) {
|
|
41
|
+
await builder.transferHbar(
|
|
42
|
+
specificArgs
|
|
43
|
+
);
|
|
146
44
|
}
|
|
147
45
|
}
|
|
148
46
|
export {
|
|
149
|
-
|
|
47
|
+
TransferHbarTool
|
|
150
48
|
};
|
|
151
49
|
//# sourceMappingURL=index18.js.map
|