@hashgraphonline/standards-agent-kit 0.2.112 → 0.2.113
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/dist/cjs/index.d.ts +1 -1
- package/dist/cjs/standards-agent-kit.cjs +1 -1
- package/dist/cjs/standards-agent-kit.cjs.map +1 -1
- package/dist/cjs/tools/hcs6/CreateDynamicRegistryTool.d.ts +44 -0
- package/dist/cjs/tools/hcs6/QueryDynamicRegistryTool.d.ts +50 -0
- package/dist/cjs/tools/hcs6/RegisterDynamicHashinalTool.d.ts +102 -0
- package/dist/cjs/tools/hcs6/UpdateDynamicHashinalTool.d.ts +96 -0
- package/dist/cjs/tools/hcs6/base-hcs6-tools.d.ts +28 -0
- package/dist/cjs/tools/hcs6/hcs6-tool-params.d.ts +18 -0
- package/dist/cjs/tools/hcs6/index.d.ts +6 -0
- package/dist/cjs/tools/index.d.ts +1 -0
- package/dist/cjs/tools/inscriber/InscribeFromBufferTool.d.ts +4 -4
- package/dist/es/index.d.ts +1 -1
- package/dist/es/standards-agent-kit.es.js +44 -31
- package/dist/es/standards-agent-kit.es.js.map +1 -1
- package/dist/es/standards-agent-kit.es10.js +27 -27
- package/dist/es/standards-agent-kit.es10.js.map +1 -1
- package/dist/es/standards-agent-kit.es11.js +20 -30
- package/dist/es/standards-agent-kit.es11.js.map +1 -1
- package/dist/es/standards-agent-kit.es12.js +27 -37
- package/dist/es/standards-agent-kit.es12.js.map +1 -1
- package/dist/es/standards-agent-kit.es13.js +48 -60
- package/dist/es/standards-agent-kit.es13.js.map +1 -1
- package/dist/es/standards-agent-kit.es14.js +60 -23
- package/dist/es/standards-agent-kit.es14.js.map +1 -1
- package/dist/es/standards-agent-kit.es15.js +23 -23
- package/dist/es/standards-agent-kit.es15.js.map +1 -1
- package/dist/es/standards-agent-kit.es16.js +23 -33
- package/dist/es/standards-agent-kit.es16.js.map +1 -1
- package/dist/es/standards-agent-kit.es17.js +34 -10
- package/dist/es/standards-agent-kit.es17.js.map +1 -1
- package/dist/es/standards-agent-kit.es18.js +16 -155
- package/dist/es/standards-agent-kit.es18.js.map +1 -1
- package/dist/es/standards-agent-kit.es19.js +150 -22
- package/dist/es/standards-agent-kit.es19.js.map +1 -1
- package/dist/es/standards-agent-kit.es20.js +25 -39
- package/dist/es/standards-agent-kit.es20.js.map +1 -1
- package/dist/es/standards-agent-kit.es21.js +26 -28
- package/dist/es/standards-agent-kit.es21.js.map +1 -1
- package/dist/es/standards-agent-kit.es22.js +16 -19
- package/dist/es/standards-agent-kit.es22.js.map +1 -1
- package/dist/es/standards-agent-kit.es23.js +21 -15
- package/dist/es/standards-agent-kit.es23.js.map +1 -1
- package/dist/es/standards-agent-kit.es24.js +18 -21
- package/dist/es/standards-agent-kit.es24.js.map +1 -1
- package/dist/es/standards-agent-kit.es25.js +35 -32
- package/dist/es/standards-agent-kit.es25.js.map +1 -1
- package/dist/es/standards-agent-kit.es26.js +38 -25
- package/dist/es/standards-agent-kit.es26.js.map +1 -1
- package/dist/es/standards-agent-kit.es27.js +25 -116
- package/dist/es/standards-agent-kit.es27.js.map +1 -1
- package/dist/es/standards-agent-kit.es28.js +33 -166
- package/dist/es/standards-agent-kit.es28.js.map +1 -1
- package/dist/es/standards-agent-kit.es29.js +42 -121
- package/dist/es/standards-agent-kit.es29.js.map +1 -1
- package/dist/es/standards-agent-kit.es30.js +40 -77
- package/dist/es/standards-agent-kit.es30.js.map +1 -1
- package/dist/es/standards-agent-kit.es31.js +42 -37
- package/dist/es/standards-agent-kit.es31.js.map +1 -1
- package/dist/es/standards-agent-kit.es32.js +20 -237
- package/dist/es/standards-agent-kit.es32.js.map +1 -1
- package/dist/es/standards-agent-kit.es33.js +154 -135
- package/dist/es/standards-agent-kit.es33.js.map +1 -1
- package/dist/es/standards-agent-kit.es34.js +168 -23
- package/dist/es/standards-agent-kit.es34.js.map +1 -1
- package/dist/es/standards-agent-kit.es35.js +126 -21
- package/dist/es/standards-agent-kit.es35.js.map +1 -1
- package/dist/es/standards-agent-kit.es36.js +86 -3
- package/dist/es/standards-agent-kit.es36.js.map +1 -1
- package/dist/es/standards-agent-kit.es37.js +45 -0
- package/dist/es/standards-agent-kit.es37.js.map +1 -0
- package/dist/es/standards-agent-kit.es38.js +249 -0
- package/dist/es/standards-agent-kit.es38.js.map +1 -0
- package/dist/es/standards-agent-kit.es39.js +141 -0
- package/dist/es/standards-agent-kit.es39.js.map +1 -0
- package/dist/es/standards-agent-kit.es4.js +65 -32
- package/dist/es/standards-agent-kit.es4.js.map +1 -1
- package/dist/es/standards-agent-kit.es40.js +33 -0
- package/dist/es/standards-agent-kit.es40.js.map +1 -0
- package/dist/es/standards-agent-kit.es41.js +28 -0
- package/dist/es/standards-agent-kit.es41.js.map +1 -0
- package/dist/es/standards-agent-kit.es42.js +7 -0
- package/dist/es/standards-agent-kit.es42.js.map +1 -0
- package/dist/es/standards-agent-kit.es5.js +35 -311
- package/dist/es/standards-agent-kit.es5.js.map +1 -1
- package/dist/es/standards-agent-kit.es6.js +320 -20
- package/dist/es/standards-agent-kit.es6.js.map +1 -1
- package/dist/es/standards-agent-kit.es7.js +19 -227
- package/dist/es/standards-agent-kit.es7.js.map +1 -1
- package/dist/es/standards-agent-kit.es8.js +216 -65
- package/dist/es/standards-agent-kit.es8.js.map +1 -1
- package/dist/es/standards-agent-kit.es9.js +72 -23
- package/dist/es/standards-agent-kit.es9.js.map +1 -1
- package/dist/es/tools/hcs6/CreateDynamicRegistryTool.d.ts +44 -0
- package/dist/es/tools/hcs6/QueryDynamicRegistryTool.d.ts +50 -0
- package/dist/es/tools/hcs6/RegisterDynamicHashinalTool.d.ts +102 -0
- package/dist/es/tools/hcs6/UpdateDynamicHashinalTool.d.ts +96 -0
- package/dist/es/tools/hcs6/base-hcs6-tools.d.ts +28 -0
- package/dist/es/tools/hcs6/hcs6-tool-params.d.ts +18 -0
- package/dist/es/tools/hcs6/index.d.ts +6 -0
- package/dist/es/tools/index.d.ts +1 -0
- package/dist/es/tools/inscriber/InscribeFromBufferTool.d.ts +4 -4
- package/dist/umd/index.d.ts +1 -1
- package/dist/umd/standards-agent-kit.umd.js +1 -1
- package/dist/umd/standards-agent-kit.umd.js.map +1 -1
- package/dist/umd/tools/hcs6/CreateDynamicRegistryTool.d.ts +44 -0
- package/dist/umd/tools/hcs6/QueryDynamicRegistryTool.d.ts +50 -0
- package/dist/umd/tools/hcs6/RegisterDynamicHashinalTool.d.ts +102 -0
- package/dist/umd/tools/hcs6/UpdateDynamicHashinalTool.d.ts +96 -0
- package/dist/umd/tools/hcs6/base-hcs6-tools.d.ts +28 -0
- package/dist/umd/tools/hcs6/hcs6-tool-params.d.ts +18 -0
- package/dist/umd/tools/hcs6/index.d.ts +6 -0
- package/dist/umd/tools/index.d.ts +1 -0
- package/dist/umd/tools/inscriber/InscribeFromBufferTool.d.ts +4 -4
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/tools/hcs6/CreateDynamicRegistryTool.ts +66 -0
- package/src/tools/hcs6/QueryDynamicRegistryTool.ts +72 -0
- package/src/tools/hcs6/RegisterDynamicHashinalTool.ts +79 -0
- package/src/tools/hcs6/UpdateDynamicHashinalTool.ts +74 -0
- package/src/tools/hcs6/base-hcs6-tools.ts +63 -0
- package/src/tools/hcs6/hcs6-tool-params.ts +21 -0
- package/src/tools/hcs6/index.ts +6 -0
- package/src/tools/index.ts +1 -0
- package/src/tools/inscriber/InscribeFromBufferTool.ts +1 -1
- package/src/tools/inscriber/InscribeFromUrlTool.ts +60 -7
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { BaseInscriberQueryTool } from "./standards-agent-kit.es32.js";
|
|
3
|
+
const retrieveInscriptionSchema = z.object({
|
|
4
|
+
transactionId: z.string().describe("The transaction ID of the inscription to retrieve"),
|
|
5
|
+
apiKey: z.string().optional().describe("API key for inscription service")
|
|
6
|
+
});
|
|
7
|
+
class RetrieveInscriptionTool extends BaseInscriberQueryTool {
|
|
8
|
+
constructor() {
|
|
9
|
+
super(...arguments);
|
|
10
|
+
this.name = "retrieveInscription";
|
|
11
|
+
this.description = "Retrieve details of an existing inscription from the Hedera network";
|
|
12
|
+
}
|
|
13
|
+
get specificInputSchema() {
|
|
14
|
+
return retrieveInscriptionSchema;
|
|
15
|
+
}
|
|
16
|
+
async executeQuery(params, _runManager) {
|
|
17
|
+
const result = await this.inscriberBuilder.retrieveInscription(
|
|
18
|
+
params.transactionId,
|
|
19
|
+
{
|
|
20
|
+
apiKey: params.apiKey,
|
|
21
|
+
network: this.inscriberBuilder["hederaKit"].client.network.toString().includes("mainnet") ? "mainnet" : "testnet"
|
|
22
|
+
}
|
|
23
|
+
);
|
|
24
|
+
return {
|
|
25
|
+
inscriptionId: result.inscriptionId,
|
|
26
|
+
transactionId: result.transactionId,
|
|
27
|
+
topicId: result.topic_id,
|
|
28
|
+
status: result.status,
|
|
29
|
+
holderId: result.holderId,
|
|
30
|
+
metadata: result.metadata,
|
|
31
|
+
tags: result.tags,
|
|
32
|
+
mode: result.mode,
|
|
33
|
+
chunks: result.chunks,
|
|
34
|
+
createdAt: result.createdAt,
|
|
35
|
+
completedAt: result.completed || result.completedAt,
|
|
36
|
+
fileUrl: result.fileUrl,
|
|
37
|
+
mimeType: result.mimeType,
|
|
38
|
+
fileSize: result.fileSize
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
export {
|
|
43
|
+
RetrieveInscriptionTool
|
|
44
|
+
};
|
|
45
|
+
//# sourceMappingURL=standards-agent-kit.es37.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standards-agent-kit.es37.js","sources":["../../src/tools/inscriber/RetrieveInscriptionTool.ts"],"sourcesContent":["import { z } from 'zod';\nimport { BaseInscriberQueryTool } from './base-inscriber-tools';\nimport { CallbackManagerForToolRun } from '@langchain/core/callbacks/manager';\n\n/**\n * Schema for retrieving inscription\n */\nconst retrieveInscriptionSchema = z.object({\n transactionId: z\n .string()\n .describe('The transaction ID of the inscription to retrieve'),\n apiKey: z\n .string()\n .optional()\n .describe('API key for inscription service'),\n});\n\n\n/**\n * Tool for retrieving inscriptions\n */\nexport class RetrieveInscriptionTool extends BaseInscriberQueryTool<typeof retrieveInscriptionSchema> {\n name = 'retrieveInscription';\n description = 'Retrieve details of an existing inscription from the Hedera network';\n\n get specificInputSchema() {\n return retrieveInscriptionSchema;\n }\n\n protected async executeQuery(\n params: z.infer<typeof retrieveInscriptionSchema>,\n _runManager?: CallbackManagerForToolRun\n ): Promise<unknown> {\n const result = await this.inscriberBuilder.retrieveInscription(\n params.transactionId,\n {\n apiKey: params.apiKey,\n network: this.inscriberBuilder['hederaKit'].client.network.toString().includes('mainnet') ? 'mainnet' : 'testnet',\n }\n );\n\n return {\n inscriptionId: (result as any).inscriptionId,\n transactionId: result.transactionId,\n topicId: (result as any).topic_id,\n status: result.status,\n holderId: (result as any).holderId,\n metadata: result.metadata,\n tags: (result as any).tags,\n mode: result.mode,\n chunks: (result as any).chunks,\n createdAt: (result as any).createdAt,\n completedAt: (result as any).completed || (result as any).completedAt,\n fileUrl: result.fileUrl,\n mimeType: (result as any).mimeType,\n fileSize: (result as any).fileSize,\n };\n }\n}"],"names":[],"mappings":";;AAOA,MAAM,4BAA4B,EAAE,OAAO;AAAA,EACzC,eAAe,EACZ,SACA,SAAS,mDAAmD;AAAA,EAC/D,QAAQ,EACL,OAAA,EACA,SAAA,EACA,SAAS,iCAAiC;AAC/C,CAAC;AAMM,MAAM,gCAAgC,uBAAyD;AAAA,EAA/F,cAAA;AAAA,UAAA,GAAA,SAAA;AACL,SAAA,OAAO;AACP,SAAA,cAAc;AAAA,EAAA;AAAA,EAEd,IAAI,sBAAsB;AACxB,WAAO;AAAA,EACT;AAAA,EAEA,MAAgB,aACd,QACA,aACkB;AAClB,UAAM,SAAS,MAAM,KAAK,iBAAiB;AAAA,MACzC,OAAO;AAAA,MACP;AAAA,QACE,QAAQ,OAAO;AAAA,QACf,SAAS,KAAK,iBAAiB,WAAW,EAAE,OAAO,QAAQ,WAAW,SAAS,SAAS,IAAI,YAAY;AAAA,MAAA;AAAA,IAC1G;AAGF,WAAO;AAAA,MACL,eAAgB,OAAe;AAAA,MAC/B,eAAe,OAAO;AAAA,MACtB,SAAU,OAAe;AAAA,MACzB,QAAQ,OAAO;AAAA,MACf,UAAW,OAAe;AAAA,MAC1B,UAAU,OAAO;AAAA,MACjB,MAAO,OAAe;AAAA,MACtB,MAAM,OAAO;AAAA,MACb,QAAS,OAAe;AAAA,MACxB,WAAY,OAAe;AAAA,MAC3B,aAAc,OAAe,aAAc,OAAe;AAAA,MAC1D,SAAS,OAAO;AAAA,MAChB,UAAW,OAAe;AAAA,MAC1B,UAAW,OAAe;AAAA,IAAA;AAAA,EAE9B;AACF;"}
|
|
@@ -0,0 +1,249 @@
|
|
|
1
|
+
import { updateEnvFile } from "./standards-agent-kit.es41.js";
|
|
2
|
+
import { Logger, ConnectionsManager } from "@hashgraphonline/standards-sdk";
|
|
3
|
+
class OpenConvaiState {
|
|
4
|
+
/**
|
|
5
|
+
* Creates a new OpenConvaiState instance
|
|
6
|
+
* @param options - Options for environment variable persistence
|
|
7
|
+
*/
|
|
8
|
+
constructor(options) {
|
|
9
|
+
this.currentAgent = null;
|
|
10
|
+
this.connectionMessageTimestamps = {};
|
|
11
|
+
this.connectionsManager = null;
|
|
12
|
+
this.defaultEnvFilePath = options?.defaultEnvFilePath;
|
|
13
|
+
this.defaultPrefix = options?.defaultPrefix ?? "TODD";
|
|
14
|
+
const shouldSilence = options?.disableLogging || process.env.DISABLE_LOGGING === "true";
|
|
15
|
+
this.logger = new Logger({ module: "OpenConvaiState", silent: shouldSilence });
|
|
16
|
+
if (options?.baseClient) {
|
|
17
|
+
this.initializeConnectionsManager(options.baseClient);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Initializes the ConnectionsManager
|
|
22
|
+
* @param baseClient - HCS10BaseClient instance to use
|
|
23
|
+
*/
|
|
24
|
+
initializeConnectionsManager(baseClient) {
|
|
25
|
+
if (!this.connectionsManager) {
|
|
26
|
+
this.logger.debug("Initializing ConnectionsManager");
|
|
27
|
+
this.connectionsManager = new ConnectionsManager({
|
|
28
|
+
baseClient,
|
|
29
|
+
logLevel: "error"
|
|
30
|
+
});
|
|
31
|
+
} else {
|
|
32
|
+
this.logger.debug("ConnectionsManager already initialized");
|
|
33
|
+
}
|
|
34
|
+
return this.connectionsManager;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Gets the ConnectionsManager instance
|
|
38
|
+
* @returns The ConnectionsManager instance, or null if not initialized
|
|
39
|
+
*/
|
|
40
|
+
getConnectionsManager() {
|
|
41
|
+
return this.connectionsManager;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Sets the current active agent and clears any previous connection data.
|
|
45
|
+
* This should be called when switching between agents.
|
|
46
|
+
*/
|
|
47
|
+
setCurrentAgent(agent) {
|
|
48
|
+
this.currentAgent = agent;
|
|
49
|
+
this.connectionMessageTimestamps = {};
|
|
50
|
+
if (this.connectionsManager) {
|
|
51
|
+
this.connectionsManager.clearAll();
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Returns the currently active agent or null if none is set.
|
|
56
|
+
*/
|
|
57
|
+
getCurrentAgent() {
|
|
58
|
+
return this.currentAgent;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Adds a new connection to the active connections list.
|
|
62
|
+
* Ensures no duplicates are added based on connectionTopicId.
|
|
63
|
+
* Initializes timestamp tracking for the connection.
|
|
64
|
+
*/
|
|
65
|
+
addActiveConnection(connection) {
|
|
66
|
+
if (!this.connectionsManager) {
|
|
67
|
+
this.logger.error(
|
|
68
|
+
"ConnectionsManager not initialized. Call initializeConnectionsManager before adding connections."
|
|
69
|
+
);
|
|
70
|
+
throw new Error(
|
|
71
|
+
"ConnectionsManager not initialized. Call initializeConnectionsManager before adding connections."
|
|
72
|
+
);
|
|
73
|
+
}
|
|
74
|
+
const sdkConnection = {
|
|
75
|
+
connectionTopicId: connection.connectionTopicId,
|
|
76
|
+
targetAccountId: connection.targetAccountId,
|
|
77
|
+
targetAgentName: connection.targetAgentName,
|
|
78
|
+
targetInboundTopicId: connection.targetInboundTopicId,
|
|
79
|
+
status: this.convertConnectionStatus(connection.status || "established"),
|
|
80
|
+
isPending: connection.isPending || false,
|
|
81
|
+
needsConfirmation: connection.needsConfirmation || false,
|
|
82
|
+
created: connection.created || /* @__PURE__ */ new Date(),
|
|
83
|
+
lastActivity: connection.lastActivity,
|
|
84
|
+
profileInfo: connection.profileInfo,
|
|
85
|
+
connectionRequestId: connection.connectionRequestId,
|
|
86
|
+
processed: true
|
|
87
|
+
};
|
|
88
|
+
this.connectionsManager.updateOrAddConnection(sdkConnection);
|
|
89
|
+
this.initializeTimestampIfNeeded(connection.connectionTopicId);
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Updates an existing connection or adds it if not found.
|
|
93
|
+
* Preserves existing properties when updating by merging objects.
|
|
94
|
+
*/
|
|
95
|
+
updateOrAddConnection(connection) {
|
|
96
|
+
this.addActiveConnection(connection);
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Returns a copy of all active connections.
|
|
100
|
+
*/
|
|
101
|
+
listConnections() {
|
|
102
|
+
if (!this.connectionsManager) {
|
|
103
|
+
this.logger.debug(
|
|
104
|
+
"ConnectionsManager not initialized, returning empty connections list"
|
|
105
|
+
);
|
|
106
|
+
return [];
|
|
107
|
+
}
|
|
108
|
+
return this.connectionsManager.getAllConnections().map((conn) => this.convertToActiveConnection(conn));
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Finds a connection by its identifier, which can be:
|
|
112
|
+
* - A 1-based index as displayed in the connection list
|
|
113
|
+
* - A target account ID string
|
|
114
|
+
* - A connection topic ID string
|
|
115
|
+
*/
|
|
116
|
+
getConnectionByIdentifier(identifier) {
|
|
117
|
+
if (!this.connectionsManager) {
|
|
118
|
+
return void 0;
|
|
119
|
+
}
|
|
120
|
+
const connections = this.listConnections();
|
|
121
|
+
const numericIndex = parseInt(identifier) - 1;
|
|
122
|
+
if (!isNaN(numericIndex) && numericIndex >= 0 && numericIndex < connections.length) {
|
|
123
|
+
return connections[numericIndex];
|
|
124
|
+
}
|
|
125
|
+
const byTopicId = this.connectionsManager.getConnectionByTopicId(identifier);
|
|
126
|
+
if (byTopicId) {
|
|
127
|
+
return this.convertToActiveConnection(byTopicId);
|
|
128
|
+
}
|
|
129
|
+
const byAccountId = this.connectionsManager.getConnectionByAccountId(identifier);
|
|
130
|
+
if (byAccountId) {
|
|
131
|
+
return this.convertToActiveConnection(byAccountId);
|
|
132
|
+
}
|
|
133
|
+
return void 0;
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* Gets the last processed message timestamp for a connection.
|
|
137
|
+
* Returns 0 if no timestamp has been recorded.
|
|
138
|
+
*/
|
|
139
|
+
getLastTimestamp(connectionTopicId) {
|
|
140
|
+
return this.connectionMessageTimestamps[connectionTopicId] || 0;
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Updates the last processed message timestamp for a connection,
|
|
144
|
+
* but only if the new timestamp is more recent than the existing one.
|
|
145
|
+
*/
|
|
146
|
+
updateTimestamp(connectionTopicId, timestampNanos) {
|
|
147
|
+
if (!(connectionTopicId in this.connectionMessageTimestamps)) {
|
|
148
|
+
this.connectionMessageTimestamps[connectionTopicId] = timestampNanos;
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const currentTimestamp = this.connectionMessageTimestamps[connectionTopicId];
|
|
152
|
+
if (timestampNanos > currentTimestamp) {
|
|
153
|
+
this.connectionMessageTimestamps[connectionTopicId] = timestampNanos;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Helper method to initialize timestamp tracking for a connection
|
|
158
|
+
* if it doesn't already exist.
|
|
159
|
+
*/
|
|
160
|
+
initializeTimestampIfNeeded(connectionTopicId) {
|
|
161
|
+
if (!(connectionTopicId in this.connectionMessageTimestamps)) {
|
|
162
|
+
this.connectionMessageTimestamps[connectionTopicId] = Date.now() * 1e6;
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Converts ConnectionStatus to SDK status format
|
|
167
|
+
*/
|
|
168
|
+
convertConnectionStatus(status) {
|
|
169
|
+
switch (status) {
|
|
170
|
+
case "pending":
|
|
171
|
+
return "pending";
|
|
172
|
+
case "established":
|
|
173
|
+
return "established";
|
|
174
|
+
case "needs confirmation":
|
|
175
|
+
return "needs_confirmation";
|
|
176
|
+
default:
|
|
177
|
+
return "established";
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
/**
|
|
181
|
+
* Converts SDK Connection to ActiveConnection
|
|
182
|
+
*/
|
|
183
|
+
convertToActiveConnection(conn) {
|
|
184
|
+
return {
|
|
185
|
+
targetAccountId: conn.targetAccountId,
|
|
186
|
+
targetAgentName: conn.targetAgentName || `Agent ${conn.targetAccountId}`,
|
|
187
|
+
targetInboundTopicId: conn.targetInboundTopicId || "",
|
|
188
|
+
connectionTopicId: conn.connectionTopicId,
|
|
189
|
+
status: this.convertToStateStatus(conn.status),
|
|
190
|
+
created: conn.created,
|
|
191
|
+
lastActivity: conn.lastActivity,
|
|
192
|
+
isPending: conn.isPending,
|
|
193
|
+
needsConfirmation: conn.needsConfirmation,
|
|
194
|
+
profileInfo: conn.profileInfo,
|
|
195
|
+
connectionRequestId: conn.connectionRequestId
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Converts SDK status to state status format
|
|
200
|
+
*/
|
|
201
|
+
convertToStateStatus(status) {
|
|
202
|
+
switch (status) {
|
|
203
|
+
case "pending":
|
|
204
|
+
return "pending";
|
|
205
|
+
case "established":
|
|
206
|
+
return "established";
|
|
207
|
+
case "needs_confirmation":
|
|
208
|
+
return "needs confirmation";
|
|
209
|
+
case "closed":
|
|
210
|
+
return "established";
|
|
211
|
+
// Mapping closed to established for compatibility
|
|
212
|
+
default:
|
|
213
|
+
return "unknown";
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Persists agent data to environment variables
|
|
218
|
+
* @param agent - The agent data to persist
|
|
219
|
+
* @param options - Environment file persistence options
|
|
220
|
+
*/
|
|
221
|
+
async persistAgentData(agent, options) {
|
|
222
|
+
if (options?.type && options.type !== "env-file") {
|
|
223
|
+
throw new Error(
|
|
224
|
+
`Unsupported persistence type: ${options.type}. Only 'env-file' is supported.`
|
|
225
|
+
);
|
|
226
|
+
}
|
|
227
|
+
const envFilePath = options?.envFilePath || this.defaultEnvFilePath || process.env.ENV_FILE_PATH || ".env";
|
|
228
|
+
const prefix = options?.prefix || this.defaultPrefix;
|
|
229
|
+
if (!agent.accountId || !agent.inboundTopicId || !agent.outboundTopicId) {
|
|
230
|
+
throw new Error("Agent data incomplete, cannot persist to environment");
|
|
231
|
+
}
|
|
232
|
+
const updates = {
|
|
233
|
+
[`${prefix}_ACCOUNT_ID`]: agent.accountId,
|
|
234
|
+
[`${prefix}_INBOUND_TOPIC_ID`]: agent.inboundTopicId,
|
|
235
|
+
[`${prefix}_OUTBOUND_TOPIC_ID`]: agent.outboundTopicId
|
|
236
|
+
};
|
|
237
|
+
if (agent.privateKey) {
|
|
238
|
+
updates[`${prefix}_PRIVATE_KEY`] = agent.privateKey;
|
|
239
|
+
}
|
|
240
|
+
if (agent.profileTopicId) {
|
|
241
|
+
updates[`${prefix}_PROFILE_TOPIC_ID`] = agent.profileTopicId;
|
|
242
|
+
}
|
|
243
|
+
await updateEnvFile(envFilePath, updates);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
export {
|
|
247
|
+
OpenConvaiState
|
|
248
|
+
};
|
|
249
|
+
//# sourceMappingURL=standards-agent-kit.es38.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standards-agent-kit.es38.js","sources":["../../src/state/open-convai-state.ts"],"sourcesContent":["import { updateEnvFile } from '../utils/state-tools';\nimport {\n RegisteredAgent,\n ActiveConnection,\n IStateManager,\n AgentPersistenceOptions,\n EnvFilePersistenceOptions,\n ConnectionStatus,\n} from './state-types';\nimport {\n ConnectionsManager,\n HCS10BaseClient,\n Connection,\n Logger,\n IConnectionsManager,\n} from '@hashgraphonline/standards-sdk';\n\n/**\n * Implementation of the IStateManager interface for the OpenConvai system.\n * Manages agent state and connection information with thread safety and\n * proper timestamp tracking.\n */\nexport class OpenConvaiState implements IStateManager {\n private currentAgent: RegisteredAgent | null = null;\n private connectionMessageTimestamps: Record<string, number> = {};\n private defaultEnvFilePath?: string;\n private defaultPrefix: string;\n private connectionsManager: IConnectionsManager | null = null;\n private logger: Logger;\n\n /**\n * Creates a new OpenConvaiState instance\n * @param options - Options for environment variable persistence\n */\n constructor(options?: {\n defaultEnvFilePath?: string;\n defaultPrefix?: string;\n baseClient?: HCS10BaseClient;\n disableLogging?: boolean;\n }) {\n this.defaultEnvFilePath = options?.defaultEnvFilePath;\n this.defaultPrefix = options?.defaultPrefix ?? 'TODD';\n const shouldSilence = options?.disableLogging || process.env.DISABLE_LOGGING === 'true';\n this.logger = new Logger({ module: 'OpenConvaiState', silent: shouldSilence });\n\n // Initialize ConnectionsManager immediately if baseClient is provided\n if (options?.baseClient) {\n this.initializeConnectionsManager(options.baseClient);\n }\n }\n\n /**\n * Initializes the ConnectionsManager\n * @param baseClient - HCS10BaseClient instance to use\n */\n initializeConnectionsManager(\n baseClient: HCS10BaseClient\n ): IConnectionsManager {\n if (!this.connectionsManager) {\n this.logger.debug('Initializing ConnectionsManager');\n this.connectionsManager = new ConnectionsManager({\n baseClient,\n logLevel: 'error',\n });\n } else {\n this.logger.debug('ConnectionsManager already initialized');\n }\n return this.connectionsManager;\n }\n\n /**\n * Gets the ConnectionsManager instance\n * @returns The ConnectionsManager instance, or null if not initialized\n */\n getConnectionsManager(): IConnectionsManager | null {\n return this.connectionsManager;\n }\n\n /**\n * Sets the current active agent and clears any previous connection data.\n * This should be called when switching between agents.\n */\n setCurrentAgent(agent: RegisteredAgent | null): void {\n this.currentAgent = agent;\n this.connectionMessageTimestamps = {};\n\n // Clear connections manager when changing agents\n if (this.connectionsManager) {\n this.connectionsManager.clearAll();\n }\n }\n\n /**\n * Returns the currently active agent or null if none is set.\n */\n getCurrentAgent(): RegisteredAgent | null {\n return this.currentAgent;\n }\n\n /**\n * Adds a new connection to the active connections list.\n * Ensures no duplicates are added based on connectionTopicId.\n * Initializes timestamp tracking for the connection.\n */\n addActiveConnection(connection: ActiveConnection): void {\n if (!this.connectionsManager) {\n this.logger.error(\n 'ConnectionsManager not initialized. Call initializeConnectionsManager before adding connections.'\n );\n throw new Error(\n 'ConnectionsManager not initialized. Call initializeConnectionsManager before adding connections.'\n );\n }\n\n // Convert from ActiveConnection to Connection\n const sdkConnection: Connection = {\n connectionTopicId: connection.connectionTopicId,\n targetAccountId: connection.targetAccountId,\n targetAgentName: connection.targetAgentName,\n targetInboundTopicId: connection.targetInboundTopicId,\n status: this.convertConnectionStatus(connection.status || 'established'),\n isPending: connection.isPending || false,\n needsConfirmation: connection.needsConfirmation || false,\n created: connection.created || new Date(),\n lastActivity: connection.lastActivity,\n profileInfo: connection.profileInfo,\n connectionRequestId: connection.connectionRequestId,\n processed: true,\n };\n\n // Add to ConnectionsManager\n this.connectionsManager.updateOrAddConnection(sdkConnection);\n\n // Initialize timestamp tracking\n this.initializeTimestampIfNeeded(connection.connectionTopicId);\n }\n\n /**\n * Updates an existing connection or adds it if not found.\n * Preserves existing properties when updating by merging objects.\n */\n updateOrAddConnection(connection: ActiveConnection): void {\n this.addActiveConnection(connection);\n }\n\n /**\n * Returns a copy of all active connections.\n */\n listConnections(): ActiveConnection[] {\n if (!this.connectionsManager) {\n this.logger.debug(\n 'ConnectionsManager not initialized, returning empty connections list'\n );\n return [];\n }\n\n // Convert SDK Connections to ActiveConnection\n return this.connectionsManager\n .getAllConnections()\n .map((conn) => this.convertToActiveConnection(conn));\n }\n\n /**\n * Finds a connection by its identifier, which can be:\n * - A 1-based index as displayed in the connection list\n * - A target account ID string\n * - A connection topic ID string\n */\n getConnectionByIdentifier(identifier: string): ActiveConnection | undefined {\n if (!this.connectionsManager) {\n return undefined;\n }\n\n const connections = this.listConnections();\n\n // Check if it's a 1-based index\n const numericIndex = parseInt(identifier) - 1;\n if (\n !isNaN(numericIndex) &&\n numericIndex >= 0 &&\n numericIndex < connections.length\n ) {\n return connections[numericIndex];\n }\n\n // Check if it's a topic ID\n const byTopicId =\n this.connectionsManager.getConnectionByTopicId(identifier);\n if (byTopicId) {\n return this.convertToActiveConnection(byTopicId);\n }\n\n // Check if it's an account ID\n const byAccountId =\n this.connectionsManager.getConnectionByAccountId(identifier);\n if (byAccountId) {\n return this.convertToActiveConnection(byAccountId);\n }\n\n return undefined;\n }\n\n /**\n * Gets the last processed message timestamp for a connection.\n * Returns 0 if no timestamp has been recorded.\n */\n getLastTimestamp(connectionTopicId: string): number {\n return this.connectionMessageTimestamps[connectionTopicId] || 0;\n }\n\n /**\n * Updates the last processed message timestamp for a connection,\n * but only if the new timestamp is more recent than the existing one.\n */\n updateTimestamp(connectionTopicId: string, timestampNanos: number): void {\n // Initialize if this is first update and skip the comparison logic\n if (!(connectionTopicId in this.connectionMessageTimestamps)) {\n this.connectionMessageTimestamps[connectionTopicId] = timestampNanos;\n return;\n }\n\n // Otherwise, only update if newer\n const currentTimestamp =\n this.connectionMessageTimestamps[connectionTopicId];\n if (timestampNanos > currentTimestamp) {\n this.connectionMessageTimestamps[connectionTopicId] = timestampNanos;\n }\n }\n\n /**\n * Helper method to initialize timestamp tracking for a connection\n * if it doesn't already exist.\n */\n private initializeTimestampIfNeeded(connectionTopicId: string): void {\n if (!(connectionTopicId in this.connectionMessageTimestamps)) {\n this.connectionMessageTimestamps[connectionTopicId] =\n Date.now() * 1_000_000;\n }\n }\n\n /**\n * Converts ConnectionStatus to SDK status format\n */\n private convertConnectionStatus(\n status: string\n ): 'pending' | 'established' | 'needs_confirmation' | 'closed' {\n switch (status) {\n case 'pending':\n return 'pending';\n case 'established':\n return 'established';\n case 'needs confirmation':\n return 'needs_confirmation';\n default:\n return 'established';\n }\n }\n\n /**\n * Converts SDK Connection to ActiveConnection\n */\n private convertToActiveConnection(conn: Connection): ActiveConnection {\n return {\n targetAccountId: conn.targetAccountId,\n targetAgentName: conn.targetAgentName || `Agent ${conn.targetAccountId}`,\n targetInboundTopicId: conn.targetInboundTopicId || '',\n connectionTopicId: conn.connectionTopicId,\n status: this.convertToStateStatus(conn.status),\n created: conn.created,\n lastActivity: conn.lastActivity,\n isPending: conn.isPending,\n needsConfirmation: conn.needsConfirmation,\n profileInfo: conn.profileInfo,\n connectionRequestId: conn.connectionRequestId,\n };\n }\n\n /**\n * Converts SDK status to state status format\n */\n private convertToStateStatus(status: string): ConnectionStatus {\n switch (status) {\n case 'pending':\n return 'pending';\n case 'established':\n return 'established';\n case 'needs_confirmation':\n return 'needs confirmation';\n case 'closed':\n return 'established'; // Mapping closed to established for compatibility\n default:\n return 'unknown';\n }\n }\n\n /**\n * Persists agent data to environment variables\n * @param agent - The agent data to persist\n * @param options - Environment file persistence options\n */\n async persistAgentData(\n agent: RegisteredAgent,\n options?: AgentPersistenceOptions\n ): Promise<void> {\n if (options?.type && options.type !== 'env-file') {\n throw new Error(\n `Unsupported persistence type: ${options.type}. Only 'env-file' is supported.`\n );\n }\n\n const envFilePath =\n (options as EnvFilePersistenceOptions)?.envFilePath ||\n this.defaultEnvFilePath ||\n process.env.ENV_FILE_PATH ||\n '.env';\n\n if (!envFilePath) {\n throw new Error(\n 'Environment file path could not be determined for agent data persistence'\n );\n }\n\n const prefix =\n (options as EnvFilePersistenceOptions)?.prefix || this.defaultPrefix;\n\n if (!agent.accountId || !agent.inboundTopicId || !agent.outboundTopicId) {\n throw new Error('Agent data incomplete, cannot persist to environment');\n }\n\n const updates: Record<string, string> = {\n [`${prefix}_ACCOUNT_ID`]: agent.accountId,\n [`${prefix}_INBOUND_TOPIC_ID`]: agent.inboundTopicId,\n [`${prefix}_OUTBOUND_TOPIC_ID`]: agent.outboundTopicId,\n };\n\n if (agent.privateKey) {\n updates[`${prefix}_PRIVATE_KEY`] = agent.privateKey;\n }\n\n if (agent.profileTopicId) {\n updates[`${prefix}_PROFILE_TOPIC_ID`] = agent.profileTopicId;\n }\n\n await updateEnvFile(envFilePath, updates);\n }\n}\n"],"names":[],"mappings":";;AAsBO,MAAM,gBAAyC;AAAA;AAAA;AAAA;AAAA;AAAA,EAYpD,YAAY,SAKT;AAhBH,SAAQ,eAAuC;AAC/C,SAAQ,8BAAsD,CAAA;AAG9D,SAAQ,qBAAiD;AAavD,SAAK,qBAAqB,SAAS;AACnC,SAAK,gBAAgB,SAAS,iBAAiB;AAC/C,UAAM,gBAAgB,SAAS,kBAAkB,QAAQ,IAAI,oBAAoB;AACjF,SAAK,SAAS,IAAI,OAAO,EAAE,QAAQ,mBAAmB,QAAQ,eAAe;AAG7E,QAAI,SAAS,YAAY;AACvB,WAAK,6BAA6B,QAAQ,UAAU;AAAA,IACtD;AAAA,EACF;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,6BACE,YACqB;AACrB,QAAI,CAAC,KAAK,oBAAoB;AAC5B,WAAK,OAAO,MAAM,iCAAiC;AACnD,WAAK,qBAAqB,IAAI,mBAAmB;AAAA,QAC/C;AAAA,QACA,UAAU;AAAA,MAAA,CACX;AAAA,IACH,OAAO;AACL,WAAK,OAAO,MAAM,wCAAwC;AAAA,IAC5D;AACA,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,wBAAoD;AAClD,WAAO,KAAK;AAAA,EACd;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,gBAAgB,OAAqC;AACnD,SAAK,eAAe;AACpB,SAAK,8BAA8B,CAAA;AAGnC,QAAI,KAAK,oBAAoB;AAC3B,WAAK,mBAAmB,SAAA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AAgB;AACxB,cAAQ,GAAG,MAAM,mBAAmB,IAAI,MAAM;AAAA,IAChD;AAEA,UAAM,cAAc,aAAa,OAAO;AAAA,EAC1C;AACF;"}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
import { ServerSigner, HederaAgentKit } from "hedera-agent-kit";
|
|
2
|
+
import { HCS10Builder } from "./standards-agent-kit.es2.js";
|
|
3
|
+
import { RegisterAgentTool } from "./standards-agent-kit.es8.js";
|
|
4
|
+
import { FindRegistrationsTool } from "./standards-agent-kit.es13.js";
|
|
5
|
+
import { InitiateConnectionTool } from "./standards-agent-kit.es10.js";
|
|
6
|
+
import { ListConnectionsTool } from "./standards-agent-kit.es11.js";
|
|
7
|
+
import { SendMessageToConnectionTool } from "./standards-agent-kit.es9.js";
|
|
8
|
+
import { CheckMessagesTool } from "./standards-agent-kit.es12.js";
|
|
9
|
+
import { ConnectionMonitorTool } from "./standards-agent-kit.es14.js";
|
|
10
|
+
import { ManageConnectionRequestsTool } from "./standards-agent-kit.es15.js";
|
|
11
|
+
import { AcceptConnectionRequestTool } from "./standards-agent-kit.es16.js";
|
|
12
|
+
import { RetrieveProfileTool } from "./standards-agent-kit.es17.js";
|
|
13
|
+
import { ListUnapprovedConnectionRequestsTool } from "./standards-agent-kit.es18.js";
|
|
14
|
+
import { OpenConvaiState } from "./standards-agent-kit.es38.js";
|
|
15
|
+
import { Logger } from "@hashgraphonline/standards-sdk";
|
|
16
|
+
import { ENV_FILE_PATH } from "./standards-agent-kit.es41.js";
|
|
17
|
+
const initializeStandardsAgentKit = async (options) => {
|
|
18
|
+
const config = options?.clientConfig || {};
|
|
19
|
+
const operatorId = config.operatorId || process.env.HEDERA_OPERATOR_ID;
|
|
20
|
+
const operatorPrivateKey = config.operatorKey || process.env.HEDERA_OPERATOR_KEY;
|
|
21
|
+
const networkEnv = config.network || process.env.HEDERA_NETWORK || "testnet";
|
|
22
|
+
let network;
|
|
23
|
+
if (networkEnv === "mainnet") {
|
|
24
|
+
network = "mainnet";
|
|
25
|
+
} else if (networkEnv === "testnet") {
|
|
26
|
+
network = "testnet";
|
|
27
|
+
} else {
|
|
28
|
+
console.warn(
|
|
29
|
+
`Unsupported network specified: '${networkEnv}'. Defaulting to 'testnet'.`
|
|
30
|
+
);
|
|
31
|
+
network = "testnet";
|
|
32
|
+
}
|
|
33
|
+
if (!operatorId || !operatorPrivateKey) {
|
|
34
|
+
throw new Error(
|
|
35
|
+
"Operator ID and private key must be provided either through options or environment variables."
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
const shouldSilence = process.env.DISABLE_LOGGING === "true";
|
|
39
|
+
const logger = Logger.getInstance({
|
|
40
|
+
level: config.logLevel || "info",
|
|
41
|
+
silent: shouldSilence
|
|
42
|
+
});
|
|
43
|
+
const stateManager = options?.stateManager || new OpenConvaiState({
|
|
44
|
+
defaultEnvFilePath: ENV_FILE_PATH,
|
|
45
|
+
defaultPrefix: "TODD"
|
|
46
|
+
});
|
|
47
|
+
logger.info("State manager initialized");
|
|
48
|
+
const signer = new ServerSigner(operatorId, operatorPrivateKey, network);
|
|
49
|
+
const hederaKit = new HederaAgentKit(signer);
|
|
50
|
+
await hederaKit.initialize();
|
|
51
|
+
logger.info(`HederaAgentKit initialized for ${operatorId} on ${network}`);
|
|
52
|
+
const hcs10Builder = new HCS10Builder(hederaKit, stateManager, {
|
|
53
|
+
useEncryption: config.useEncryption,
|
|
54
|
+
registryUrl: config.registryUrl,
|
|
55
|
+
logLevel: config.logLevel
|
|
56
|
+
});
|
|
57
|
+
let monitoringHederaKit;
|
|
58
|
+
let monitoringHcs10Builder;
|
|
59
|
+
if (options?.monitoringClient) {
|
|
60
|
+
const monitoringSigner = new ServerSigner(operatorId, operatorPrivateKey, network);
|
|
61
|
+
monitoringHederaKit = new HederaAgentKit(monitoringSigner);
|
|
62
|
+
await monitoringHederaKit.initialize();
|
|
63
|
+
monitoringHcs10Builder = new HCS10Builder(monitoringHederaKit, stateManager, {
|
|
64
|
+
useEncryption: config.useEncryption,
|
|
65
|
+
registryUrl: config.registryUrl,
|
|
66
|
+
logLevel: "error"
|
|
67
|
+
});
|
|
68
|
+
logger.info("Monitoring client initialized");
|
|
69
|
+
}
|
|
70
|
+
const tools = {};
|
|
71
|
+
tools.registerAgentTool = new RegisterAgentTool({
|
|
72
|
+
hederaKit,
|
|
73
|
+
hcs10Builder,
|
|
74
|
+
logger: void 0
|
|
75
|
+
});
|
|
76
|
+
if (options?.createAllTools) {
|
|
77
|
+
tools.findRegistrationsTool = new FindRegistrationsTool({
|
|
78
|
+
hederaKit,
|
|
79
|
+
hcs10Builder,
|
|
80
|
+
logger: void 0
|
|
81
|
+
});
|
|
82
|
+
tools.retrieveProfileTool = new RetrieveProfileTool({
|
|
83
|
+
hederaKit,
|
|
84
|
+
hcs10Builder,
|
|
85
|
+
logger: void 0
|
|
86
|
+
});
|
|
87
|
+
tools.initiateConnectionTool = new InitiateConnectionTool({
|
|
88
|
+
hederaKit,
|
|
89
|
+
hcs10Builder,
|
|
90
|
+
logger: void 0
|
|
91
|
+
});
|
|
92
|
+
tools.listConnectionsTool = new ListConnectionsTool({
|
|
93
|
+
hederaKit,
|
|
94
|
+
hcs10Builder,
|
|
95
|
+
logger: void 0
|
|
96
|
+
});
|
|
97
|
+
tools.sendMessageToConnectionTool = new SendMessageToConnectionTool({
|
|
98
|
+
hederaKit,
|
|
99
|
+
hcs10Builder,
|
|
100
|
+
logger: void 0
|
|
101
|
+
});
|
|
102
|
+
tools.checkMessagesTool = new CheckMessagesTool({
|
|
103
|
+
hederaKit,
|
|
104
|
+
hcs10Builder,
|
|
105
|
+
logger: void 0
|
|
106
|
+
});
|
|
107
|
+
tools.connectionMonitorTool = new ConnectionMonitorTool({
|
|
108
|
+
hederaKit: monitoringHederaKit || hederaKit,
|
|
109
|
+
hcs10Builder: monitoringHcs10Builder || hcs10Builder,
|
|
110
|
+
logger: void 0
|
|
111
|
+
});
|
|
112
|
+
tools.manageConnectionRequestsTool = new ManageConnectionRequestsTool({
|
|
113
|
+
hederaKit,
|
|
114
|
+
hcs10Builder,
|
|
115
|
+
logger: void 0
|
|
116
|
+
});
|
|
117
|
+
tools.acceptConnectionRequestTool = new AcceptConnectionRequestTool({
|
|
118
|
+
hederaKit,
|
|
119
|
+
hcs10Builder,
|
|
120
|
+
logger: void 0
|
|
121
|
+
});
|
|
122
|
+
tools.listUnapprovedConnectionRequestsTool = new ListUnapprovedConnectionRequestsTool({
|
|
123
|
+
hederaKit,
|
|
124
|
+
hcs10Builder,
|
|
125
|
+
logger: void 0
|
|
126
|
+
});
|
|
127
|
+
logger.info("All tools initialized");
|
|
128
|
+
}
|
|
129
|
+
return {
|
|
130
|
+
hederaKit,
|
|
131
|
+
hcs10Builder,
|
|
132
|
+
monitoringHederaKit,
|
|
133
|
+
monitoringHcs10Builder,
|
|
134
|
+
tools,
|
|
135
|
+
stateManager
|
|
136
|
+
};
|
|
137
|
+
};
|
|
138
|
+
export {
|
|
139
|
+
initializeStandardsAgentKit
|
|
140
|
+
};
|
|
141
|
+
//# sourceMappingURL=standards-agent-kit.es39.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"standards-agent-kit.es39.js","sources":["../../src/init/init.ts"],"sourcesContent":["import { HederaAgentKit, ServerSigner } from 'hedera-agent-kit';\nimport { HCS10Builder } from '../builders/hcs10/hcs10-builder';\nimport { RegisterAgentTool } from '../tools/hcs10/RegisterAgentTool';\nimport { FindRegistrationsTool } from '../tools/hcs10/FindRegistrationsTool';\nimport { InitiateConnectionTool } from '../tools/hcs10/InitiateConnectionTool';\nimport { ListConnectionsTool } from '../tools/hcs10/ListConnectionsTool';\nimport { SendMessageToConnectionTool } from '../tools/hcs10/SendMessageToConnectionTool';\nimport { CheckMessagesTool } from '../tools/hcs10/CheckMessagesTool';\nimport { ConnectionMonitorTool } from '../tools/hcs10/ConnectionMonitorTool';\nimport { ManageConnectionRequestsTool } from '../tools/hcs10/ManageConnectionRequestsTool';\nimport { AcceptConnectionRequestTool } from '../tools/hcs10/AcceptConnectionRequestTool';\nimport { RetrieveProfileTool } from '../tools/hcs10/RetrieveProfileTool';\nimport { ListUnapprovedConnectionRequestsTool } from '../tools/hcs10/ListUnapprovedConnectionRequestsTool';\nimport { IStateManager } from '../state/state-types';\nimport { OpenConvaiState } from '../state/open-convai-state';\nimport { Logger } from '@hashgraphonline/standards-sdk';\nimport { ENV_FILE_PATH } from '../utils/state-tools';\n\nexport interface HCS10ClientConfig {\n operatorId?: string;\n operatorKey?: string;\n network?: 'mainnet' | 'testnet';\n useEncryption?: boolean;\n registryUrl?: string;\n logLevel?: 'debug' | 'info' | 'warn' | 'error';\n}\n\nexport interface HCS10InitializationOptions {\n clientConfig?: HCS10ClientConfig;\n stateManager?: IStateManager;\n createAllTools?: boolean;\n monitoringClient?: boolean;\n}\n\n/**\n * Tool collection containing all available tools from the standards-agent-kit\n */\nexport interface HCS10Tools {\n registerAgentTool: RegisterAgentTool;\n findRegistrationsTool: FindRegistrationsTool;\n retrieveProfileTool: RetrieveProfileTool;\n initiateConnectionTool: InitiateConnectionTool;\n listConnectionsTool: ListConnectionsTool;\n sendMessageToConnectionTool: SendMessageToConnectionTool;\n checkMessagesTool: CheckMessagesTool;\n connectionMonitorTool: ConnectionMonitorTool;\n manageConnectionRequestsTool: ManageConnectionRequestsTool;\n acceptConnectionRequestTool: AcceptConnectionRequestTool;\n listUnapprovedConnectionRequestsTool: ListUnapprovedConnectionRequestsTool;\n}\n\n/**\n * Initializes the HCS10 client and returns pre-registered LangChain tools.\n *\n * @param options - Initialization options\n * @returns Object containing hederaKit, hcs10Builder and requested tools\n */\nexport const initializeStandardsAgentKit = async (\n options?: HCS10InitializationOptions\n): Promise<{\n hederaKit: HederaAgentKit;\n hcs10Builder: HCS10Builder;\n monitoringHederaKit?: HederaAgentKit;\n monitoringHcs10Builder?: HCS10Builder;\n tools: Partial<HCS10Tools>;\n stateManager: IStateManager;\n}> => {\n const config = options?.clientConfig || {};\n\n const operatorId = config.operatorId || process.env.HEDERA_OPERATOR_ID;\n const operatorPrivateKey =\n config.operatorKey || process.env.HEDERA_OPERATOR_KEY;\n\n const networkEnv = config.network || process.env.HEDERA_NETWORK || 'testnet';\n\n let network: 'mainnet' | 'testnet';\n if (networkEnv === 'mainnet') {\n network = 'mainnet';\n } else if (networkEnv === 'testnet') {\n network = 'testnet';\n } else {\n console.warn(\n `Unsupported network specified: '${networkEnv}'. Defaulting to 'testnet'.`\n );\n network = 'testnet';\n }\n\n if (!operatorId || !operatorPrivateKey) {\n throw new Error(\n 'Operator ID and private key must be provided either through options or environment variables.'\n );\n }\n\n const shouldSilence = process.env.DISABLE_LOGGING === 'true';\n const logger = Logger.getInstance({\n level: config.logLevel || 'info',\n silent: shouldSilence,\n });\n\n const stateManager =\n options?.stateManager ||\n new OpenConvaiState({\n defaultEnvFilePath: ENV_FILE_PATH,\n defaultPrefix: 'TODD',\n });\n logger.info('State manager initialized');\n\n // Create HederaAgentKit\n const signer = new ServerSigner(operatorId, operatorPrivateKey, network);\n const hederaKit = new HederaAgentKit(signer);\n await hederaKit.initialize();\n logger.info(`HederaAgentKit initialized for ${operatorId} on ${network}`);\n\n // Create HCS10Builder\n const hcs10Builder = new HCS10Builder(hederaKit, stateManager, {\n useEncryption: config.useEncryption,\n registryUrl: config.registryUrl,\n logLevel: config.logLevel,\n });\n\n let monitoringHederaKit: HederaAgentKit | undefined;\n let monitoringHcs10Builder: HCS10Builder | undefined;\n\n if (options?.monitoringClient) {\n const monitoringSigner = new ServerSigner(operatorId, operatorPrivateKey, network);\n monitoringHederaKit = new HederaAgentKit(monitoringSigner);\n await monitoringHederaKit.initialize();\n monitoringHcs10Builder = new HCS10Builder(monitoringHederaKit, stateManager, {\n useEncryption: config.useEncryption,\n registryUrl: config.registryUrl,\n logLevel: 'error',\n });\n logger.info('Monitoring client initialized');\n }\n\n const tools: Partial<HCS10Tools> = {};\n\n // Always create RegisterAgentTool\n tools.registerAgentTool = new RegisterAgentTool({\n hederaKit,\n hcs10Builder,\n logger: undefined,\n });\n\n if (options?.createAllTools) {\n tools.findRegistrationsTool = new FindRegistrationsTool({\n hederaKit,\n hcs10Builder,\n logger: undefined,\n });\n tools.retrieveProfileTool = new RetrieveProfileTool({\n hederaKit,\n hcs10Builder,\n logger: undefined,\n });\n tools.initiateConnectionTool = new InitiateConnectionTool({\n hederaKit,\n hcs10Builder,\n logger: undefined,\n });\n tools.listConnectionsTool = new ListConnectionsTool({\n hederaKit,\n hcs10Builder,\n logger: undefined,\n });\n tools.sendMessageToConnectionTool = new SendMessageToConnectionTool({\n hederaKit,\n hcs10Builder,\n logger: undefined,\n });\n tools.checkMessagesTool = new CheckMessagesTool({\n hederaKit,\n hcs10Builder,\n logger: undefined,\n });\n tools.connectionMonitorTool = new ConnectionMonitorTool({\n hederaKit: monitoringHederaKit || hederaKit,\n hcs10Builder: monitoringHcs10Builder || hcs10Builder,\n logger: undefined,\n });\n tools.manageConnectionRequestsTool = new ManageConnectionRequestsTool({\n hederaKit,\n hcs10Builder,\n logger: undefined,\n });\n tools.acceptConnectionRequestTool = new AcceptConnectionRequestTool({\n hederaKit,\n hcs10Builder,\n logger: undefined,\n });\n tools.listUnapprovedConnectionRequestsTool =\n new ListUnapprovedConnectionRequestsTool({\n hederaKit,\n hcs10Builder,\n logger: undefined,\n });\n\n logger.info('All tools initialized');\n }\n\n return {\n hederaKit,\n hcs10Builder,\n monitoringHederaKit,\n monitoringHcs10Builder,\n tools,\n stateManager,\n };\n};"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAyDO,MAAM,8BAA8B,OACzC,YAQI;AACJ,QAAM,SAAS,SAAS,gBAAgB,CAAA;AAExC,QAAM,aAAa,OAAO,cAAc,QAAQ,IAAI;AACpD,QAAM,qBACJ,OAAO,eAAe,QAAQ,IAAI;AAEpC,QAAM,aAAa,OAAO,WAAW,QAAQ,IAAI,kBAAkB;AAEnE,MAAI;AACJ,MAAI,eAAe,WAAW;AAC5B,cAAU;AAAA,EACZ,WAAW,e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,SAAS,gBAAgB;AAC3B,UAAM,wBAAwB,IAAI,sBAAsB;AAAA,MACtD;AAAA,MACA;AAAA,MACA,QAAQ;AAAA,IAAA,CACT;AACD,UAAM,sBAAsB,IAAI,oBAAoB;AAAA,MAClD;AAAA,MACA;AAAA,MACA,QAAQ;AAAA,IAAA,CACT;AACD,UAAM,yBAAyB,IAAI,uBAAuB;AAAA,MACxD;AAAA,MACA;AAAA,MACA,QAAQ;AAAA,IAAA,CACT;AACD,UAAM,sBAAsB,IAAI,oBAAoB;AAAA,MAClD;AAAA,MACA;AAAA,MACA,QAAQ;AAAA,IAAA,CACT;AACD,UAAM,8BAA8B,IAAI,4BAA4B;AAAA,MAClE;AAAA,MACA;AAAA,MACA,QAAQ;AAAA,IAAA,CACT;AACD,UAAM,oBAAoB,IAAI,kBAAkB;AAAA,MAC9C;AAAA,MACA;AAAA,MACA,QAAQ;AAAA,IAAA,CACT;AACD,UAAM,wBAAwB,IAAI,sBAAsB;AAAA,MACtD,WAAW,uBAAuB;AAAA,MAClC,cAAc,0BAA0B;AAAA,MACxC,QAAQ;AAAA,IAAA,CACT;AACD,UAAM,+BAA+B,IAAI,6BAA6B;AAAA,MACpE;AAAA,MACA;AAAA,MACA,QAAQ;AAAA,IAAA,CACT;AACD,UAAM,8BAA8B,IAAI,4BAA4B;AAAA,MAClE;AAAA,MACA;AAAA,MACA,QAAQ;AAAA,IAAA,CACT;AACD,UAAM,uCACJ,IAAI,qCAAqC;AAAA,MACvC;AAAA,MACA;AAAA,MACA,QAAQ;AAAA,IAAA,CACT;AAEH,WAAO,KAAK,uBAAuB;AAAA,EACrC;AAEA,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EAAA;AAEJ;"}
|
|
@@ -1,56 +1,89 @@
|
|
|
1
1
|
import { BaseServiceBuilder } from "hedera-agent-kit";
|
|
2
|
-
import {
|
|
3
|
-
class
|
|
2
|
+
import { HCS6Client } from "@hashgraphonline/standards-sdk";
|
|
3
|
+
class HCS6Builder extends BaseServiceBuilder {
|
|
4
4
|
constructor(hederaKit) {
|
|
5
5
|
super(hederaKit);
|
|
6
6
|
}
|
|
7
7
|
/**
|
|
8
|
-
* Get or create
|
|
8
|
+
* Get or create HCS-6 client
|
|
9
9
|
*/
|
|
10
|
-
async
|
|
11
|
-
|
|
10
|
+
async getHCS6Client() {
|
|
11
|
+
if (!this.hcs6Client) {
|
|
12
|
+
const operatorId = this.hederaKit.signer.getAccountId().toString();
|
|
13
|
+
const operatorPrivateKey = this.hederaKit.signer?.getOperatorPrivateKey() ? this.hederaKit.signer.getOperatorPrivateKey().toStringRaw() : "";
|
|
14
|
+
const network = this.hederaKit.client.network;
|
|
15
|
+
const networkType = network.toString().includes("mainnet") ? "mainnet" : "testnet";
|
|
16
|
+
const config = {
|
|
17
|
+
network: networkType,
|
|
18
|
+
operatorId,
|
|
19
|
+
operatorKey: operatorPrivateKey
|
|
20
|
+
};
|
|
21
|
+
this.hcs6Client = new HCS6Client(config);
|
|
22
|
+
}
|
|
23
|
+
return this.hcs6Client;
|
|
12
24
|
}
|
|
13
25
|
/**
|
|
14
|
-
*
|
|
26
|
+
* Create a new HCS-6 dynamic registry
|
|
27
|
+
* Note: This executes the transaction directly via HCS6Client
|
|
15
28
|
*/
|
|
16
|
-
async
|
|
17
|
-
const
|
|
18
|
-
|
|
19
|
-
const network = this.hederaKit.client.network;
|
|
20
|
-
const networkType = network.toString().includes("mainnet") ? "mainnet" : "testnet";
|
|
21
|
-
const clientConfig = {
|
|
22
|
-
accountId: operatorId,
|
|
23
|
-
privateKey: operatorPrivateKey,
|
|
24
|
-
network: networkType
|
|
25
|
-
};
|
|
26
|
-
return await inscribe(input, clientConfig, options);
|
|
29
|
+
async createRegistry(options = {}) {
|
|
30
|
+
const client = await this.getHCS6Client();
|
|
31
|
+
return await client.createRegistry(options);
|
|
27
32
|
}
|
|
28
33
|
/**
|
|
29
|
-
*
|
|
34
|
+
* Register a new dynamic hashinal entry in an HCS-6 registry
|
|
30
35
|
*/
|
|
31
|
-
async
|
|
32
|
-
|
|
36
|
+
async registerEntry(registryTopicId, options) {
|
|
37
|
+
const client = await this.getHCS6Client();
|
|
38
|
+
return await client.registerEntry(registryTopicId, options);
|
|
33
39
|
}
|
|
34
40
|
/**
|
|
35
|
-
*
|
|
41
|
+
* Query entries from an HCS-6 registry
|
|
36
42
|
*/
|
|
37
|
-
async
|
|
38
|
-
const
|
|
39
|
-
|
|
40
|
-
return await retrieveInscription(transactionId, {
|
|
41
|
-
...options,
|
|
42
|
-
accountId: operatorId,
|
|
43
|
-
privateKey: operatorPrivateKey
|
|
44
|
-
});
|
|
43
|
+
async getRegistry(topicId, options = {}) {
|
|
44
|
+
const client = await this.getHCS6Client();
|
|
45
|
+
return await client.getRegistry(topicId, options);
|
|
45
46
|
}
|
|
46
47
|
/**
|
|
47
|
-
*
|
|
48
|
+
* Create a complete dynamic hashinal with inscription and registry
|
|
49
|
+
*/
|
|
50
|
+
async createHashinal(options) {
|
|
51
|
+
const client = await this.getHCS6Client();
|
|
52
|
+
return await client.createHashinal(options);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Register a dynamic hashinal with combined inscription and registry creation
|
|
56
|
+
* This is the main method for creating and updating dynamic hashinals
|
|
57
|
+
*/
|
|
58
|
+
async register(options) {
|
|
59
|
+
const client = await this.getHCS6Client();
|
|
60
|
+
return await client.register(options);
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Submit a raw message to an HCS-6 topic
|
|
64
|
+
*/
|
|
65
|
+
async submitMessage(topicId, payload) {
|
|
66
|
+
const client = await this.getHCS6Client();
|
|
67
|
+
return await client.submitMessage(topicId, payload);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Get topic info from mirror node
|
|
71
|
+
*/
|
|
72
|
+
async getTopicInfo(topicId) {
|
|
73
|
+
const client = await this.getHCS6Client();
|
|
74
|
+
return await client.getTopicInfo(topicId);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Close the HCS-6 client
|
|
48
78
|
*/
|
|
49
79
|
async close() {
|
|
50
|
-
this.
|
|
80
|
+
if (this.hcs6Client) {
|
|
81
|
+
this.hcs6Client.close();
|
|
82
|
+
this.hcs6Client = void 0;
|
|
83
|
+
}
|
|
51
84
|
}
|
|
52
85
|
}
|
|
53
86
|
export {
|
|
54
|
-
|
|
87
|
+
HCS6Builder
|
|
55
88
|
};
|
|
56
89
|
//# sourceMappingURL=standards-agent-kit.es4.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-agent-kit.es4.js","sources":["../../src/builders/
|
|
1
|
+
{"version":3,"file":"standards-agent-kit.es4.js","sources":["../../src/builders/hcs6/hcs6-builder.ts"],"sourcesContent":["import { BaseServiceBuilder } from 'hedera-agent-kit';\nimport type { HederaAgentKit } from 'hedera-agent-kit';\nimport {\n HCS6Client,\n SDKHCS6ClientConfig,\n HCS6CreateRegistryOptions,\n HCS6RegisterEntryOptions,\n HCS6QueryRegistryOptions,\n HCS6RegisterOptions,\n HCS6CreateHashinalOptions,\n HCS6TopicRegistrationResponse,\n HCS6RegistryOperationResponse,\n HCS6TopicRegistry,\n HCS6CreateHashinalResponse,\n NetworkType,\n} from '@hashgraphonline/standards-sdk';\n\n/**\n * Builder for HCS-6 operations that delegates to HCS6Client\n */\nexport class HCS6Builder extends BaseServiceBuilder {\n protected hcs6Client?: HCS6Client;\n\n constructor(hederaKit: HederaAgentKit) {\n super(hederaKit);\n }\n\n /**\n * Get or create HCS-6 client\n */\n protected async getHCS6Client(): Promise<HCS6Client> {\n if (!this.hcs6Client) {\n const operatorId = this.hederaKit.signer.getAccountId().toString();\n const operatorPrivateKey = this.hederaKit.signer?.getOperatorPrivateKey()\n ? this.hederaKit.signer.getOperatorPrivateKey().toStringRaw()\n : '';\n\n const network = this.hederaKit.client.network;\n const networkType: NetworkType = network.toString().includes('mainnet')\n ? 'mainnet'\n : 'testnet';\n\n const config: SDKHCS6ClientConfig = {\n network: networkType,\n operatorId: operatorId,\n operatorKey: operatorPrivateKey,\n };\n\n this.hcs6Client = new HCS6Client(config);\n }\n return this.hcs6Client;\n }\n\n /**\n * Create a new HCS-6 dynamic registry\n * Note: This executes the transaction directly via HCS6Client\n */\n async createRegistry(\n options: HCS6CreateRegistryOptions = {}\n ): Promise<HCS6TopicRegistrationResponse> {\n const client = await this.getHCS6Client();\n return await client.createRegistry(options);\n }\n\n /**\n * Register a new dynamic hashinal entry in an HCS-6 registry\n */\n async registerEntry(\n registryTopicId: string,\n options: HCS6RegisterEntryOptions\n ): Promise<HCS6RegistryOperationResponse> {\n const client = await this.getHCS6Client();\n return await client.registerEntry(registryTopicId, options);\n }\n\n /**\n * Query entries from an HCS-6 registry\n */\n async getRegistry(\n topicId: string,\n options: HCS6QueryRegistryOptions = {}\n ): Promise<HCS6TopicRegistry> {\n const client = await this.getHCS6Client();\n return await client.getRegistry(topicId, options);\n }\n\n /**\n * Create a complete dynamic hashinal with inscription and registry\n */\n async createHashinal(\n options: HCS6CreateHashinalOptions\n ): Promise<HCS6CreateHashinalResponse> {\n const client = await this.getHCS6Client();\n return await client.createHashinal(options);\n }\n\n /**\n * Register a dynamic hashinal with combined inscription and registry creation\n * This is the main method for creating and updating dynamic hashinals\n */\n async register(\n options: HCS6RegisterOptions\n ): Promise<HCS6CreateHashinalResponse> {\n const client = await this.getHCS6Client();\n return await client.register(options);\n }\n\n /**\n * Submit a raw message to an HCS-6 topic\n */\n async submitMessage(\n topicId: string,\n payload: any\n ): Promise<any> {\n const client = await this.getHCS6Client();\n return await client.submitMessage(topicId, payload);\n }\n\n /**\n * Get topic info from mirror node\n */\n async getTopicInfo(topicId: string): Promise<any> {\n const client = await this.getHCS6Client();\n return await client.getTopicInfo(topicId);\n }\n\n /**\n * Close the HCS-6 client\n */\n async close(): Promise<void> {\n if (this.hcs6Client) {\n this.hcs6Client.close();\n this.hcs6Client = undefined;\n }\n }\n}"],"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