@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
|
@@ -1,249 +1,32 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
}
|
|
1
|
+
import { BaseHederaTransactionTool, BaseHederaQueryTool } from "hedera-agent-kit";
|
|
2
|
+
class BaseInscriberTransactionTool extends BaseHederaTransactionTool {
|
|
3
|
+
constructor(params) {
|
|
4
|
+
super(params);
|
|
5
|
+
this.namespace = "inscriber";
|
|
6
|
+
this.inscriberBuilder = params.inscriberBuilder;
|
|
53
7
|
}
|
|
54
8
|
/**
|
|
55
|
-
*
|
|
9
|
+
* Override to return the InscriberBuilder
|
|
56
10
|
*/
|
|
57
|
-
|
|
58
|
-
return this.
|
|
11
|
+
getServiceBuilder() {
|
|
12
|
+
return this.inscriberBuilder;
|
|
59
13
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
}
|
|
14
|
+
}
|
|
15
|
+
class BaseInscriberQueryTool extends BaseHederaQueryTool {
|
|
16
|
+
constructor(params) {
|
|
17
|
+
super(params);
|
|
18
|
+
this.namespace = "inscriber";
|
|
19
|
+
this.inscriberBuilder = params.inscriberBuilder;
|
|
215
20
|
}
|
|
216
21
|
/**
|
|
217
|
-
*
|
|
218
|
-
* @param agent - The agent data to persist
|
|
219
|
-
* @param options - Environment file persistence options
|
|
22
|
+
* Override to return the InscriberBuilder
|
|
220
23
|
*/
|
|
221
|
-
|
|
222
|
-
|
|
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);
|
|
24
|
+
getServiceBuilder() {
|
|
25
|
+
return this.inscriberBuilder;
|
|
244
26
|
}
|
|
245
27
|
}
|
|
246
28
|
export {
|
|
247
|
-
|
|
29
|
+
BaseInscriberQueryTool,
|
|
30
|
+
BaseInscriberTransactionTool
|
|
248
31
|
};
|
|
249
32
|
//# sourceMappingURL=standards-agent-kit.es32.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-agent-kit.es32.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,iB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T;AACE,eAAO;AAAA,IAAA;AAAA,EAEb;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOA,MAAM,iBACJ,OACA,SACe;AACf,QAAI,SAAS,QAAQ,QAAQ,SAAS,YAAY;AAChD,YAAM,IAAI;AAAA,QACR,iCAAiC,QAAQ,IAAI;AAAA,MAAA;AAAA,IAEjD;AAEA,UAAM,cACH,SAAuC,eACxC,KAAK,sBACL,QAAQ,IAAI,iBACZ;AAQF,UAAM,SACH,SAAuC,UAAU,KAAK;AAEzD,QAAI,CAAC,MAAM,aAAa,CAAC,MAAM,kBAAkB,CAAC,MAAM,iBAAiB;AACvE,YAAM,IAAI,MAAM,sDAAsD;AAAA,IACxE;AAEA,UAAM,UAAkC;AAAA,MACtC,CAAC,GAAG,MAAM,aAAa,GAAG,MAAM;AAAA,MAChC,CAAC,GAAG,MAAM,mBAAmB,GAAG,MAAM;AAAA,MACtC,CAAC,GAAG,MAAM,oBAAoB,GAAG,MAAM;AAAA,IAAA;AAGzC,QAAI,MAAM,YAAY;AACpB,cAAQ,GAAG,MAAM,cAAc,IAAI,MAAM;AAAA,IAC3C;AAEA,QAAI,MAAM,gBAAgB;AACxB,cAAQ,GAAG,MAAM,mBAAmB,IAAI,MAAM;AAAA,IAChD;AAEA,UAAM,cAAc,aAAa,OAAO;AAAA,EAC1C;AACF;"}
|
|
1
|
+
{"version":3,"file":"standards-agent-kit.es32.js","sources":["../../src/tools/inscriber/base-inscriber-tools.ts"],"sourcesContent":["import {\n BaseHederaTransactionTool,\n BaseHederaQueryTool,\n BaseServiceBuilder,\n} from 'hedera-agent-kit';\nimport { InscriberBuilder } from '../../builders/inscriber/inscriber-builder';\nimport {\n InscriberTransactionToolParams,\n InscriberQueryToolParams,\n} from './inscriber-tool-params';\nimport { z } from 'zod';\n\n/**\n * Base class for Inscriber transaction tools\n */\nexport abstract class BaseInscriberTransactionTool<\n T extends z.ZodObject<\n z.ZodRawShape,\n z.UnknownKeysParam,\n z.ZodTypeAny\n > = z.ZodObject<z.ZodRawShape>\n> extends BaseHederaTransactionTool<T> {\n protected inscriberBuilder: InscriberBuilder;\n namespace = 'inscriber' as const;\n\n constructor(params: InscriberTransactionToolParams) {\n super(params);\n this.inscriberBuilder = params.inscriberBuilder;\n }\n\n /**\n * Override to return the InscriberBuilder\n */\n protected getServiceBuilder(): BaseServiceBuilder {\n return this.inscriberBuilder;\n }\n}\n\n/**\n * Base class for Inscriber query tools\n */\nexport abstract class BaseInscriberQueryTool<\n T extends z.ZodObject<\n z.ZodRawShape,\n z.UnknownKeysParam,\n z.ZodTypeAny\n > = z.ZodObject<z.ZodRawShape>\n> extends BaseHederaQueryTool<T> {\n protected inscriberBuilder: InscriberBuilder;\n namespace = 'inscriber' as const;\n\n constructor(params: InscriberQueryToolParams) {\n super(params);\n this.inscriberBuilder = params.inscriberBuilder;\n }\n\n /**\n * Override to return the InscriberBuilder\n */\n protected getServiceBuilder(): BaseServiceBuilder {\n return this.inscriberBuilder;\n }\n}"],"names":[],"mappings":";AAeO,MAAe,qCAMZ,0BAA6B;AAAA,EAIrC,YAAY,QAAwC;AAClD,UAAM,MAAM;AAHd,SAAA,YAAY;AAIV,SAAK,mBAAmB,OAAO;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA,EAKU,oBAAwC;AAChD,WAAO,KAAK;AAAA,EACd;AACF;AAKO,MAAe,+BAMZ,oBAAuB;AAAA,EAI/B,YAAY,QAAkC;AAC5C,UAAM,MAAM;AAHd,SAAA,YAAY;AAIV,SAAK,mBAAmB,OAAO;AAAA,EACjC;AAAA;AAAA;AAAA;AAAA,EAKU,oBAAwC;AAChD,WAAO,KAAK;AAAA,EACd;AACF;"}
|
|
@@ -1,141 +1,160 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
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";
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { BaseInscriberQueryTool } from "./standards-agent-kit.es32.js";
|
|
3
|
+
const inscribeFromUrlSchema = z.object({
|
|
4
|
+
url: z.string().url().describe("The URL of the content to inscribe"),
|
|
5
|
+
mode: z.enum(["file", "hashinal"]).optional().describe("Inscription mode: file or hashinal NFT"),
|
|
6
|
+
metadata: z.record(z.unknown()).optional().describe("Metadata to attach to the inscription"),
|
|
7
|
+
tags: z.array(z.string()).optional().describe("Tags to categorize the inscription"),
|
|
8
|
+
chunkSize: z.number().int().positive().optional().describe("Chunk size for large files"),
|
|
9
|
+
waitForConfirmation: z.boolean().optional().describe("Whether to wait for inscription confirmation"),
|
|
10
|
+
apiKey: z.string().optional().describe("API key for inscription service")
|
|
11
|
+
});
|
|
12
|
+
class InscribeFromUrlTool extends BaseInscriberQueryTool {
|
|
13
|
+
constructor() {
|
|
14
|
+
super(...arguments);
|
|
15
|
+
this.name = "inscribeFromUrl";
|
|
16
|
+
this.description = "Inscribe content ONLY from URLs that point directly to downloadable files (PDF, image, JSON, ZIP, etc). This tool will FAIL for web pages, news sites, or social media. Examples of VALID URLs: https://example.com/document.pdf, https://cdn.example.com/image.jpg, https://api.example.com/data.json. For web page articles or any content you retrieve via MCP tools, you MUST use inscribeFromBuffer instead after retrieving the content.";
|
|
32
17
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"Operator ID and private key must be provided either through options or environment variables."
|
|
36
|
-
);
|
|
18
|
+
get specificInputSchema() {
|
|
19
|
+
return inscribeFromUrlSchema;
|
|
37
20
|
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
21
|
+
async executeQuery(params, _runManager) {
|
|
22
|
+
console.log(`[DEBUG] InscribeFromUrlTool.executeQuery called with URL: ${params.url}`);
|
|
23
|
+
if (!params.url || params.url.trim() === "") {
|
|
24
|
+
throw new Error("URL cannot be empty. Please provide a valid URL.");
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
const urlObj = new URL(params.url);
|
|
28
|
+
if (!urlObj.protocol || !urlObj.host) {
|
|
29
|
+
throw new Error("Invalid URL format. Please provide a complete URL with protocol (http/https).");
|
|
30
|
+
}
|
|
31
|
+
if (!["http:", "https:"].includes(urlObj.protocol)) {
|
|
32
|
+
throw new Error("Only HTTP and HTTPS URLs are supported for inscription.");
|
|
33
|
+
}
|
|
34
|
+
} catch (error) {
|
|
35
|
+
throw new Error(`Invalid URL: ${params.url}. Please provide a valid URL.`);
|
|
36
|
+
}
|
|
37
|
+
console.log(`[InscribeFromUrlTool] Validating URL content before inscription...`);
|
|
38
|
+
try {
|
|
39
|
+
const controller = new AbortController();
|
|
40
|
+
const timeoutId = setTimeout(() => controller.abort(), 1e4);
|
|
41
|
+
try {
|
|
42
|
+
const headResponse = await fetch(params.url, {
|
|
43
|
+
method: "HEAD",
|
|
44
|
+
signal: controller.signal
|
|
45
|
+
});
|
|
46
|
+
clearTimeout(timeoutId);
|
|
47
|
+
if (!headResponse.ok) {
|
|
48
|
+
throw new Error(`URL returned error status ${headResponse.status}: ${headResponse.statusText}. Cannot inscribe content from inaccessible URLs.`);
|
|
49
|
+
}
|
|
50
|
+
const contentType = headResponse.headers.get("content-type") || "";
|
|
51
|
+
const contentLength = headResponse.headers.get("content-length");
|
|
52
|
+
const webPageContentTypes = [
|
|
53
|
+
"text/html",
|
|
54
|
+
"application/xhtml+xml",
|
|
55
|
+
"text/xml"
|
|
56
|
+
];
|
|
57
|
+
if (webPageContentTypes.some((type) => contentType.toLowerCase().includes(type))) {
|
|
58
|
+
throw new Error(`URL returns HTML/web page content (Content-Type: ${contentType}). This tool only works with direct file URLs (PDFs, images, JSON, etc.). For web page content, first retrieve the content using the appropriate MCP tool or web scraper, then use inscribeFromBuffer to inscribe it.`);
|
|
59
|
+
}
|
|
60
|
+
if (contentLength && parseInt(contentLength) === 0) {
|
|
61
|
+
throw new Error("URL returns empty content (Content-Length: 0). Cannot inscribe empty content.");
|
|
62
|
+
}
|
|
63
|
+
if (contentLength && parseInt(contentLength) < 10) {
|
|
64
|
+
throw new Error(`URL content is too small (${contentLength} bytes). Content must be at least 10 bytes.`);
|
|
65
|
+
}
|
|
66
|
+
if (!contentType || contentType === "application/octet-stream") {
|
|
67
|
+
console.log(`[InscribeFromUrlTool] Content-Type unclear, fetching first 1KB to verify...`);
|
|
68
|
+
const getController = new AbortController();
|
|
69
|
+
const getTimeoutId = setTimeout(() => getController.abort(), 5e3);
|
|
70
|
+
try {
|
|
71
|
+
const getResponse = await fetch(params.url, {
|
|
72
|
+
signal: getController.signal,
|
|
73
|
+
headers: {
|
|
74
|
+
"Range": "bytes=0-1023"
|
|
75
|
+
// Get first 1KB
|
|
76
|
+
}
|
|
77
|
+
});
|
|
78
|
+
clearTimeout(getTimeoutId);
|
|
79
|
+
if (getResponse.ok || getResponse.status === 206) {
|
|
80
|
+
const buffer = await getResponse.arrayBuffer();
|
|
81
|
+
const bytes = new Uint8Array(buffer);
|
|
82
|
+
const text = new TextDecoder("utf-8", { fatal: false }).decode(bytes.slice(0, 512));
|
|
83
|
+
if (text.toLowerCase().includes("<!doctype html") || text.toLowerCase().includes("<html") || text.match(/<meta\s+[^>]*>/i) || text.match(/<title>/i)) {
|
|
84
|
+
throw new Error(`URL returns HTML content. This tool only works with direct file URLs. For web page content, first retrieve it using the appropriate tool, then use inscribeFromBuffer.`);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
} catch (getError) {
|
|
88
|
+
clearTimeout(getTimeoutId);
|
|
89
|
+
if (getError instanceof Error && getError.message.includes("HTML content")) {
|
|
90
|
+
throw getError;
|
|
91
|
+
}
|
|
92
|
+
console.log(`[InscribeFromUrlTool] Could not perform partial GET validation: ${getError instanceof Error ? getError.message : "Unknown error"}`);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
console.log(`[InscribeFromUrlTool] URL validation passed. Content-Type: ${contentType}, Content-Length: ${contentLength || "unknown"}`);
|
|
96
|
+
} catch (fetchError) {
|
|
97
|
+
clearTimeout(timeoutId);
|
|
98
|
+
throw fetchError;
|
|
99
|
+
}
|
|
100
|
+
} catch (error) {
|
|
101
|
+
if (error instanceof Error) {
|
|
102
|
+
if (error.name === "AbortError") {
|
|
103
|
+
console.log(`[InscribeFromUrlTool] Warning: URL validation timed out after 10 seconds. Proceeding with inscription attempt.`);
|
|
104
|
+
} else if (error.message.includes("URL returned error") || error.message.includes("empty content") || error.message.includes("too small") || error.message.includes("HTML")) {
|
|
105
|
+
throw error;
|
|
106
|
+
} else {
|
|
107
|
+
console.log(`[InscribeFromUrlTool] Warning: Could not validate URL with HEAD request: ${error.message}. Proceeding with inscription attempt.`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
const options = {
|
|
112
|
+
mode: params.mode,
|
|
113
|
+
metadata: params.metadata,
|
|
114
|
+
tags: params.tags,
|
|
115
|
+
chunkSize: params.chunkSize,
|
|
116
|
+
waitForConfirmation: params.waitForConfirmation ?? true,
|
|
117
|
+
waitMaxAttempts: 10,
|
|
118
|
+
waitIntervalMs: 3e3,
|
|
119
|
+
apiKey: params.apiKey,
|
|
120
|
+
network: this.inscriberBuilder["hederaKit"].client.network.toString().includes("mainnet") ? "mainnet" : "testnet"
|
|
121
|
+
};
|
|
122
|
+
try {
|
|
123
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
124
|
+
setTimeout(() => reject(new Error("Inscription timed out after 30 seconds")), 3e4);
|
|
125
|
+
});
|
|
126
|
+
const result = await Promise.race([
|
|
127
|
+
this.inscriberBuilder.inscribe(
|
|
128
|
+
{ type: "url", url: params.url },
|
|
129
|
+
options
|
|
130
|
+
),
|
|
131
|
+
timeoutPromise
|
|
132
|
+
]);
|
|
133
|
+
if (result.confirmed) {
|
|
134
|
+
const topicId = result.inscription?.topic_id || result.result.topicId;
|
|
135
|
+
const network = options.network || "testnet";
|
|
136
|
+
const cdnUrl = topicId ? `https://kiloscribe.com/api/inscription-cdn/${topicId}?network=${network}` : null;
|
|
137
|
+
return `Successfully inscribed and confirmed content on the Hedera network!
|
|
138
|
+
|
|
139
|
+
Transaction ID: ${result.result.transactionId}
|
|
140
|
+
Topic ID: ${topicId || "N/A"}${cdnUrl ? `
|
|
141
|
+
View inscription: ${cdnUrl}` : ""}
|
|
142
|
+
|
|
143
|
+
The inscription is now available.`;
|
|
144
|
+
} else {
|
|
145
|
+
return `Successfully submitted inscription to the Hedera network!
|
|
146
|
+
|
|
147
|
+
Transaction ID: ${result.result.transactionId}
|
|
148
|
+
|
|
149
|
+
The inscription is processing and will be confirmed shortly.`;
|
|
150
|
+
}
|
|
151
|
+
} catch (error) {
|
|
152
|
+
const errorMessage = error instanceof Error ? error.message : "Failed to inscribe from URL";
|
|
153
|
+
throw new Error(`Inscription failed: ${errorMessage}`);
|
|
154
|
+
}
|
|
69
155
|
}
|
|
70
|
-
|
|
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
|
-
};
|
|
156
|
+
}
|
|
138
157
|
export {
|
|
139
|
-
|
|
158
|
+
InscribeFromUrlTool
|
|
140
159
|
};
|
|
141
160
|
//# sourceMappingURL=standards-agent-kit.es33.js.map
|