@hashgraphonline/standards-sdk 0.0.18 → 0.0.20
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/es/hcs-10/browser.d.ts +3 -3
- package/dist/es/hcs-10/index.d.ts +1 -0
- package/dist/es/standards-sdk.es.js +603 -0
- package/dist/es/standards-sdk.es.js.map +1 -1
- package/dist/umd/hcs-10/browser.d.ts +3 -3
- package/dist/umd/hcs-10/index.d.ts +1 -0
- package/dist/umd/standards-sdk.umd.js +7 -7
- package/dist/umd/standards-sdk.umd.js.map +1 -1
- package/package.json +1 -1
|
@@ -58,7 +58,7 @@ export declare class BrowserHCSClient extends HCS10BaseClient {
|
|
|
58
58
|
result?: TransactionReceipt;
|
|
59
59
|
error?: string;
|
|
60
60
|
}>;
|
|
61
|
-
createAgent(pfpBuffer: Buffer, pfpFileName: string, agentName: string, agentDescription: string, capabilities: number[], metadata: AgentMetadata): Promise<{
|
|
61
|
+
createAgent(pfpBuffer: Buffer, pfpFileName: string, agentName: string, agentDescription: string, capabilities: number[], metadata: AgentMetadata, existingPfpTopicId?: string): Promise<{
|
|
62
62
|
outboundTopicId: string;
|
|
63
63
|
inboundTopicId: string;
|
|
64
64
|
pfpTopicId: string;
|
|
@@ -66,7 +66,7 @@ export declare class BrowserHCSClient extends HCS10BaseClient {
|
|
|
66
66
|
error?: string;
|
|
67
67
|
success: boolean;
|
|
68
68
|
}>;
|
|
69
|
-
createAndRegisterAgent(name: string, description: string, capabilities: number[], metadata: AgentMetadata, pfpBuffer: Buffer, pfpFileName: string, network: NetworkType): Promise<BrowserAgentConfig>;
|
|
69
|
+
createAndRegisterAgent(name: string, description: string, capabilities: number[], metadata: AgentMetadata, pfpBuffer: Buffer, pfpFileName: string, network: NetworkType, existingPfpTopicId?: string): Promise<BrowserAgentConfig>;
|
|
70
70
|
registerAgentWithGuardedRegistry(accountId: string, inboundTopicId: string, network?: string, maxAttempts?: number, delayMs?: number): Promise<{
|
|
71
71
|
error?: string;
|
|
72
72
|
success: boolean;
|
|
@@ -75,7 +75,7 @@ export declare class BrowserHCSClient extends HCS10BaseClient {
|
|
|
75
75
|
confirmed?: boolean;
|
|
76
76
|
validationErrors?: any[];
|
|
77
77
|
}>;
|
|
78
|
-
storeHCS11Profile(agentName: string, agentDescription: string, inboundTopicId: string, outboundTopicId: string, capabilities?: number[], metadata?: Record<string, any>, pfpBuffer?: Buffer, pfpFileName?: string): Promise<{
|
|
78
|
+
storeHCS11Profile(agentName: string, agentDescription: string, inboundTopicId: string, outboundTopicId: string, capabilities?: number[], metadata?: Record<string, any>, pfpBuffer?: Buffer, pfpFileName?: string, existingPfpTopicId?: string): Promise<{
|
|
79
79
|
profileTopicId: string;
|
|
80
80
|
pfpTopicId?: string;
|
|
81
81
|
error?: string;
|
|
@@ -32982,11 +32982,614 @@ class AgentBuilder {
|
|
|
32982
32982
|
return this.config;
|
|
32983
32983
|
}
|
|
32984
32984
|
}
|
|
32985
|
+
class BrowserHCSClient extends HCS10BaseClient {
|
|
32986
|
+
constructor(config) {
|
|
32987
|
+
super({
|
|
32988
|
+
network: config.network,
|
|
32989
|
+
logLevel: config.logLevel
|
|
32990
|
+
});
|
|
32991
|
+
this.guardedRegistryBaseUrl = config.guardedRegistryBaseUrl || "https://moonscape.tech";
|
|
32992
|
+
this.hwc = config.hwc;
|
|
32993
|
+
this.logger = Logger$1.getInstance({
|
|
32994
|
+
level: config.logLevel || "info",
|
|
32995
|
+
module: "HCS-Browser"
|
|
32996
|
+
});
|
|
32997
|
+
const { accountId, signer } = this.getAccountAndSigner();
|
|
32998
|
+
this.hcs11Client = new HCS11Client({
|
|
32999
|
+
network: config.network,
|
|
33000
|
+
auth: {
|
|
33001
|
+
operatorId: accountId,
|
|
33002
|
+
signer
|
|
33003
|
+
},
|
|
33004
|
+
logLevel: config.logLevel
|
|
33005
|
+
});
|
|
33006
|
+
}
|
|
33007
|
+
async sendMessage(connectionTopicId, operatorId, data, memo) {
|
|
33008
|
+
this.logger.info("Sending message");
|
|
33009
|
+
const payload = {
|
|
33010
|
+
p: "hcs-10",
|
|
33011
|
+
op: "message",
|
|
33012
|
+
operator_id: operatorId,
|
|
33013
|
+
data,
|
|
33014
|
+
m: memo
|
|
33015
|
+
};
|
|
33016
|
+
await this.submitPayload(connectionTopicId, payload);
|
|
33017
|
+
}
|
|
33018
|
+
async submitConnectionRequest(inboundTopicId, requestingAccountId, operatorId, memo) {
|
|
33019
|
+
var _a, _b;
|
|
33020
|
+
this.logger.info("Submitting connection request");
|
|
33021
|
+
const connectionRequestMessage = {
|
|
33022
|
+
p: "hcs-10",
|
|
33023
|
+
op: "connection_request",
|
|
33024
|
+
requesting_account_id: requestingAccountId,
|
|
33025
|
+
operator_id: operatorId,
|
|
33026
|
+
m: memo
|
|
33027
|
+
};
|
|
33028
|
+
const response = await this.submitPayload(
|
|
33029
|
+
inboundTopicId,
|
|
33030
|
+
connectionRequestMessage
|
|
33031
|
+
);
|
|
33032
|
+
this.logger.info(
|
|
33033
|
+
`Submitted connection request to topic ID: ${inboundTopicId}`
|
|
33034
|
+
);
|
|
33035
|
+
const outboundTopic = await this.retrieveOutboundConnectTopic(
|
|
33036
|
+
requestingAccountId
|
|
33037
|
+
);
|
|
33038
|
+
if (!(outboundTopic == null ? void 0 : outboundTopic.outboundTopic)) {
|
|
33039
|
+
this.logger.error(
|
|
33040
|
+
`Failed to retrieve outbound topic for account ID: ${requestingAccountId}`
|
|
33041
|
+
);
|
|
33042
|
+
throw new Error(
|
|
33043
|
+
`Failed to retrieve outbound topic for account ID: ${requestingAccountId}`
|
|
33044
|
+
);
|
|
33045
|
+
}
|
|
33046
|
+
this.logger.info(
|
|
33047
|
+
`Retrieved outbound topic ID: ${outboundTopic.outboundTopic} for account ID: ${requestingAccountId}`
|
|
33048
|
+
);
|
|
33049
|
+
const responseSequenceNumber = (_b = (_a = response == null ? void 0 : response.result) == null ? void 0 : _a.topicSequenceNumber) == null ? void 0 : _b.toNumber();
|
|
33050
|
+
if (!responseSequenceNumber) {
|
|
33051
|
+
throw new Error("Failed to get response sequence number");
|
|
33052
|
+
}
|
|
33053
|
+
await this.submitPayload(outboundTopic.outboundTopic, {
|
|
33054
|
+
...connectionRequestMessage,
|
|
33055
|
+
outbound_topic_id: inboundTopicId,
|
|
33056
|
+
connection_request_id: responseSequenceNumber
|
|
33057
|
+
});
|
|
33058
|
+
return response.result;
|
|
33059
|
+
}
|
|
33060
|
+
async recordOutboundConnectionConfirmation({
|
|
33061
|
+
outboundTopicId,
|
|
33062
|
+
connectionRequestId,
|
|
33063
|
+
confirmedRequestId,
|
|
33064
|
+
connectionTopicId,
|
|
33065
|
+
operatorId,
|
|
33066
|
+
memo
|
|
33067
|
+
}) {
|
|
33068
|
+
const payload = {
|
|
33069
|
+
p: "hcs-10",
|
|
33070
|
+
op: "connection_created",
|
|
33071
|
+
connection_topic_id: connectionTopicId,
|
|
33072
|
+
outbound_topic_id: outboundTopicId,
|
|
33073
|
+
confirmed_request_id: confirmedRequestId,
|
|
33074
|
+
connection_request_id: connectionRequestId,
|
|
33075
|
+
operator_id: operatorId,
|
|
33076
|
+
m: memo
|
|
33077
|
+
};
|
|
33078
|
+
return await this.submitPayload(outboundTopicId, payload);
|
|
33079
|
+
}
|
|
33080
|
+
async getPublicKey(accountId) {
|
|
33081
|
+
return await this.mirrorNode.getPublicKey(accountId);
|
|
33082
|
+
}
|
|
33083
|
+
async handleConnectionRequest(inboundTopicId, requestingAccountId, connectionId, connectionMemo = "Connection accepted. Looking forward to collaborating!") {
|
|
33084
|
+
this.logger.info("Handling connection request");
|
|
33085
|
+
const userAccountId = this.hwc.getAccountInfo().accountId;
|
|
33086
|
+
if (!userAccountId) {
|
|
33087
|
+
throw new Error("Failed to retrieve user account ID");
|
|
33088
|
+
}
|
|
33089
|
+
const requesterKey = await this.mirrorNode.getPublicKey(
|
|
33090
|
+
requestingAccountId
|
|
33091
|
+
);
|
|
33092
|
+
const accountKey = await this.mirrorNode.getPublicKey(userAccountId);
|
|
33093
|
+
if (!accountKey) {
|
|
33094
|
+
throw new Error("Failed to retrieve public key");
|
|
33095
|
+
}
|
|
33096
|
+
const thresholdKey = new KeyList([accountKey, requesterKey], 1);
|
|
33097
|
+
const memo = `hcs-10:${inboundTopicId}:${connectionId}`;
|
|
33098
|
+
const transaction = new TopicCreateTransaction().setTopicMemo(memo).setAdminKey(thresholdKey).setSubmitKey(thresholdKey);
|
|
33099
|
+
this.logger.debug("Executing topic creation transaction");
|
|
33100
|
+
const receipt = await this.hwc.executeTransactionWithErrorHandling(
|
|
33101
|
+
transaction,
|
|
33102
|
+
false
|
|
33103
|
+
);
|
|
33104
|
+
if (receipt.error) {
|
|
33105
|
+
this.logger.error(receipt.error);
|
|
33106
|
+
throw new Error(receipt.error);
|
|
33107
|
+
}
|
|
33108
|
+
const result = receipt.result;
|
|
33109
|
+
if (!(result == null ? void 0 : result.topicId)) {
|
|
33110
|
+
this.logger.error("Failed to create topic: topicId is null");
|
|
33111
|
+
throw new Error("Failed to create topic: topicId is null");
|
|
33112
|
+
}
|
|
33113
|
+
const connectionTopicId = result.topicId.toString();
|
|
33114
|
+
const operatorId = `${inboundTopicId}@${userAccountId}`;
|
|
33115
|
+
const confirmedConnectionSequenceNumber = await this.confirmConnection(
|
|
33116
|
+
inboundTopicId,
|
|
33117
|
+
connectionTopicId,
|
|
33118
|
+
requestingAccountId,
|
|
33119
|
+
connectionId,
|
|
33120
|
+
operatorId,
|
|
33121
|
+
connectionMemo
|
|
33122
|
+
);
|
|
33123
|
+
return {
|
|
33124
|
+
connectionTopicId,
|
|
33125
|
+
confirmedConnectionSequenceNumber,
|
|
33126
|
+
operatorId
|
|
33127
|
+
};
|
|
33128
|
+
}
|
|
33129
|
+
async confirmConnection(inboundTopicId, connectionTopicId, connectedAccountId, connectionId, operatorId, memo) {
|
|
33130
|
+
var _a;
|
|
33131
|
+
this.logger.info("Confirming connection");
|
|
33132
|
+
const payload = {
|
|
33133
|
+
p: "hcs-10",
|
|
33134
|
+
op: "connection_created",
|
|
33135
|
+
connection_topic_id: connectionTopicId,
|
|
33136
|
+
connected_account_id: connectedAccountId,
|
|
33137
|
+
operator_id: operatorId,
|
|
33138
|
+
connection_id: connectionId,
|
|
33139
|
+
m: memo
|
|
33140
|
+
};
|
|
33141
|
+
const transactionResponse = await this.submitPayload(
|
|
33142
|
+
inboundTopicId,
|
|
33143
|
+
payload
|
|
33144
|
+
);
|
|
33145
|
+
if (!((_a = transactionResponse == null ? void 0 : transactionResponse.result) == null ? void 0 : _a.topicSequenceNumber)) {
|
|
33146
|
+
this.logger.error(
|
|
33147
|
+
"Failed to confirm connection: sequence number is null"
|
|
33148
|
+
);
|
|
33149
|
+
throw new Error("Failed to confirm connection: sequence number is null");
|
|
33150
|
+
}
|
|
33151
|
+
return transactionResponse.result.topicSequenceNumber.toNumber();
|
|
33152
|
+
}
|
|
33153
|
+
async submitMessage(topicId, content, metadata = {}, memo = "") {
|
|
33154
|
+
this.logger.info("Submitting message");
|
|
33155
|
+
const payload = {
|
|
33156
|
+
p: "hcs-10",
|
|
33157
|
+
op: "message",
|
|
33158
|
+
data: {
|
|
33159
|
+
content,
|
|
33160
|
+
metadata
|
|
33161
|
+
},
|
|
33162
|
+
m: memo
|
|
33163
|
+
};
|
|
33164
|
+
return await this.submitPayload(topicId, payload);
|
|
33165
|
+
}
|
|
33166
|
+
async createAgent(pfpBuffer, pfpFileName, agentName, agentDescription, capabilities, metadata, existingPfpTopicId) {
|
|
33167
|
+
try {
|
|
33168
|
+
const outboundTopicResult = await this.createTopic(
|
|
33169
|
+
"hcs-10:0:60:1",
|
|
33170
|
+
true,
|
|
33171
|
+
true
|
|
33172
|
+
);
|
|
33173
|
+
if (!outboundTopicResult.success || !outboundTopicResult.topicId) {
|
|
33174
|
+
return {
|
|
33175
|
+
outboundTopicId: "",
|
|
33176
|
+
inboundTopicId: "",
|
|
33177
|
+
pfpTopicId: "",
|
|
33178
|
+
profileTopicId: "",
|
|
33179
|
+
error: outboundTopicResult.error || "Failed to create outbound topic",
|
|
33180
|
+
success: false
|
|
33181
|
+
};
|
|
33182
|
+
}
|
|
33183
|
+
const inboundTopicResult = await this.createTopic(
|
|
33184
|
+
`hcs-10:0:60:0:${outboundTopicResult.topicId}`
|
|
33185
|
+
);
|
|
33186
|
+
if (!inboundTopicResult.success || !inboundTopicResult.topicId) {
|
|
33187
|
+
return {
|
|
33188
|
+
outboundTopicId: outboundTopicResult.topicId,
|
|
33189
|
+
inboundTopicId: "",
|
|
33190
|
+
pfpTopicId: "",
|
|
33191
|
+
profileTopicId: "",
|
|
33192
|
+
error: inboundTopicResult.error || "Failed to create inbound topic",
|
|
33193
|
+
success: false
|
|
33194
|
+
};
|
|
33195
|
+
}
|
|
33196
|
+
let pfpTopicId = existingPfpTopicId;
|
|
33197
|
+
if (!pfpTopicId) {
|
|
33198
|
+
const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName);
|
|
33199
|
+
if (!pfpResult.success) {
|
|
33200
|
+
return {
|
|
33201
|
+
outboundTopicId: outboundTopicResult.topicId,
|
|
33202
|
+
inboundTopicId: inboundTopicResult.topicId,
|
|
33203
|
+
pfpTopicId: "",
|
|
33204
|
+
profileTopicId: "",
|
|
33205
|
+
error: pfpResult.error || "Failed to inscribe profile picture",
|
|
33206
|
+
success: false
|
|
33207
|
+
};
|
|
33208
|
+
}
|
|
33209
|
+
pfpTopicId = pfpResult.pfpTopicId;
|
|
33210
|
+
}
|
|
33211
|
+
const profileResult = await this.storeHCS11Profile(
|
|
33212
|
+
agentName,
|
|
33213
|
+
agentDescription,
|
|
33214
|
+
inboundTopicResult.topicId,
|
|
33215
|
+
outboundTopicResult.topicId,
|
|
33216
|
+
capabilities,
|
|
33217
|
+
metadata,
|
|
33218
|
+
pfpBuffer,
|
|
33219
|
+
pfpFileName,
|
|
33220
|
+
pfpTopicId
|
|
33221
|
+
);
|
|
33222
|
+
if (!profileResult.success) {
|
|
33223
|
+
return {
|
|
33224
|
+
outboundTopicId: outboundTopicResult.topicId,
|
|
33225
|
+
inboundTopicId: inboundTopicResult.topicId,
|
|
33226
|
+
pfpTopicId: pfpTopicId || "",
|
|
33227
|
+
profileTopicId: "",
|
|
33228
|
+
error: profileResult.error || "Failed to store profile",
|
|
33229
|
+
success: false
|
|
33230
|
+
};
|
|
33231
|
+
}
|
|
33232
|
+
return {
|
|
33233
|
+
outboundTopicId: outboundTopicResult.topicId,
|
|
33234
|
+
inboundTopicId: inboundTopicResult.topicId,
|
|
33235
|
+
pfpTopicId: pfpTopicId || "",
|
|
33236
|
+
profileTopicId: profileResult.profileTopicId,
|
|
33237
|
+
success: true
|
|
33238
|
+
};
|
|
33239
|
+
} catch (error) {
|
|
33240
|
+
return {
|
|
33241
|
+
outboundTopicId: "",
|
|
33242
|
+
inboundTopicId: "",
|
|
33243
|
+
pfpTopicId: "",
|
|
33244
|
+
profileTopicId: "",
|
|
33245
|
+
error: error.message,
|
|
33246
|
+
success: false
|
|
33247
|
+
};
|
|
33248
|
+
}
|
|
33249
|
+
}
|
|
33250
|
+
async createAndRegisterAgent(name, description, capabilities, metadata, pfpBuffer, pfpFileName, network, existingPfpTopicId) {
|
|
33251
|
+
try {
|
|
33252
|
+
const agentResult = await this.createAgent(
|
|
33253
|
+
pfpBuffer,
|
|
33254
|
+
pfpFileName,
|
|
33255
|
+
name,
|
|
33256
|
+
description,
|
|
33257
|
+
capabilities,
|
|
33258
|
+
metadata,
|
|
33259
|
+
existingPfpTopicId
|
|
33260
|
+
);
|
|
33261
|
+
if (!agentResult.success) {
|
|
33262
|
+
throw new Error(agentResult.error || "Failed to create agent");
|
|
33263
|
+
}
|
|
33264
|
+
const { accountId } = this.getAccountAndSigner();
|
|
33265
|
+
const registrationResult = await this.registerAgentWithGuardedRegistry(
|
|
33266
|
+
accountId,
|
|
33267
|
+
agentResult.inboundTopicId,
|
|
33268
|
+
network
|
|
33269
|
+
);
|
|
33270
|
+
if (!registrationResult.success) {
|
|
33271
|
+
throw new Error(
|
|
33272
|
+
registrationResult.error || "Failed to register agent with registry"
|
|
33273
|
+
);
|
|
33274
|
+
}
|
|
33275
|
+
return {
|
|
33276
|
+
accountId,
|
|
33277
|
+
operatorId: `${agentResult.outboundTopicId}@${accountId}`,
|
|
33278
|
+
inboundTopicId: agentResult.inboundTopicId,
|
|
33279
|
+
outboundTopicId: agentResult.outboundTopicId,
|
|
33280
|
+
profileTopicId: agentResult.profileTopicId,
|
|
33281
|
+
pfpTopicId: agentResult.pfpTopicId,
|
|
33282
|
+
client: this
|
|
33283
|
+
};
|
|
33284
|
+
} catch (error) {
|
|
33285
|
+
throw new Error(`Failed to create and register agent: ${error.message}`);
|
|
33286
|
+
}
|
|
33287
|
+
}
|
|
33288
|
+
async registerAgentWithGuardedRegistry(accountId, inboundTopicId, network = this.network, maxAttempts = 60, delayMs = 2e3) {
|
|
33289
|
+
try {
|
|
33290
|
+
this.logger.info("Registering agent with guarded registry");
|
|
33291
|
+
const registrationResult = await this.executeRegistration(
|
|
33292
|
+
accountId,
|
|
33293
|
+
inboundTopicId,
|
|
33294
|
+
network,
|
|
33295
|
+
this.guardedRegistryBaseUrl,
|
|
33296
|
+
this.logger
|
|
33297
|
+
);
|
|
33298
|
+
if (!registrationResult.success) {
|
|
33299
|
+
return registrationResult;
|
|
33300
|
+
}
|
|
33301
|
+
if (registrationResult.transaction) {
|
|
33302
|
+
const transaction = Transaction.fromBytes(
|
|
33303
|
+
Buffer2.from(registrationResult.transaction, "base64")
|
|
33304
|
+
);
|
|
33305
|
+
this.logger.info(`Processing registration transaction`);
|
|
33306
|
+
const txResult = await this.hwc.executeTransactionWithErrorHandling(
|
|
33307
|
+
transaction,
|
|
33308
|
+
false
|
|
33309
|
+
);
|
|
33310
|
+
if (txResult.error) {
|
|
33311
|
+
return {
|
|
33312
|
+
...registrationResult,
|
|
33313
|
+
error: txResult.error,
|
|
33314
|
+
success: false
|
|
33315
|
+
};
|
|
33316
|
+
}
|
|
33317
|
+
this.logger.info(`Successfully processed registration transaction`);
|
|
33318
|
+
}
|
|
33319
|
+
const confirmed = await this.waitForRegistrationConfirmation(
|
|
33320
|
+
registrationResult.transactionId,
|
|
33321
|
+
network,
|
|
33322
|
+
this.guardedRegistryBaseUrl,
|
|
33323
|
+
maxAttempts,
|
|
33324
|
+
delayMs
|
|
33325
|
+
);
|
|
33326
|
+
return {
|
|
33327
|
+
...registrationResult,
|
|
33328
|
+
confirmed
|
|
33329
|
+
};
|
|
33330
|
+
} catch (error) {
|
|
33331
|
+
return {
|
|
33332
|
+
error: `Error during registration: ${error.message}`,
|
|
33333
|
+
success: false
|
|
33334
|
+
};
|
|
33335
|
+
}
|
|
33336
|
+
}
|
|
33337
|
+
async storeHCS11Profile(agentName, agentDescription, inboundTopicId, outboundTopicId, capabilities = [], metadata = {}, pfpBuffer, pfpFileName, existingPfpTopicId) {
|
|
33338
|
+
try {
|
|
33339
|
+
let pfpTopicId = existingPfpTopicId;
|
|
33340
|
+
if (!pfpTopicId && pfpBuffer && pfpFileName) {
|
|
33341
|
+
const pfpResult = await this.inscribePfp(pfpBuffer, pfpFileName);
|
|
33342
|
+
if (!pfpResult.success) {
|
|
33343
|
+
this.logger.error(
|
|
33344
|
+
"Failed to inscribe profile picture, continuing without PFP"
|
|
33345
|
+
);
|
|
33346
|
+
} else {
|
|
33347
|
+
pfpTopicId = pfpResult.pfpTopicId;
|
|
33348
|
+
}
|
|
33349
|
+
}
|
|
33350
|
+
const agentType = this.hcs11Client.getAgentTypeFromMetadata({
|
|
33351
|
+
type: metadata.type || "autonomous"
|
|
33352
|
+
});
|
|
33353
|
+
const formattedSocials = [];
|
|
33354
|
+
if (metadata.socials) {
|
|
33355
|
+
if (metadata.socials.twitter) {
|
|
33356
|
+
formattedSocials.push({
|
|
33357
|
+
platform: "twitter",
|
|
33358
|
+
handle: metadata.socials.twitter
|
|
33359
|
+
});
|
|
33360
|
+
}
|
|
33361
|
+
if (metadata.socials.discord) {
|
|
33362
|
+
formattedSocials.push({
|
|
33363
|
+
platform: "discord",
|
|
33364
|
+
handle: metadata.socials.discord
|
|
33365
|
+
});
|
|
33366
|
+
}
|
|
33367
|
+
if (metadata.socials.github) {
|
|
33368
|
+
formattedSocials.push({
|
|
33369
|
+
platform: "github",
|
|
33370
|
+
handle: metadata.socials.github
|
|
33371
|
+
});
|
|
33372
|
+
}
|
|
33373
|
+
if (metadata.socials.website) {
|
|
33374
|
+
formattedSocials.push({
|
|
33375
|
+
platform: "website",
|
|
33376
|
+
handle: metadata.socials.website
|
|
33377
|
+
});
|
|
33378
|
+
}
|
|
33379
|
+
if (metadata.socials.x) {
|
|
33380
|
+
formattedSocials.push({
|
|
33381
|
+
platform: "twitter",
|
|
33382
|
+
handle: metadata.socials.x
|
|
33383
|
+
});
|
|
33384
|
+
}
|
|
33385
|
+
if (metadata.socials.linkedin) {
|
|
33386
|
+
formattedSocials.push({
|
|
33387
|
+
platform: "linkedin",
|
|
33388
|
+
handle: metadata.socials.linkedin
|
|
33389
|
+
});
|
|
33390
|
+
}
|
|
33391
|
+
if (metadata.socials.youtube) {
|
|
33392
|
+
formattedSocials.push({
|
|
33393
|
+
platform: "youtube",
|
|
33394
|
+
handle: metadata.socials.youtube
|
|
33395
|
+
});
|
|
33396
|
+
}
|
|
33397
|
+
if (metadata.socials.telegram) {
|
|
33398
|
+
formattedSocials.push({
|
|
33399
|
+
platform: "telegram",
|
|
33400
|
+
handle: metadata.socials.telegram
|
|
33401
|
+
});
|
|
33402
|
+
}
|
|
33403
|
+
}
|
|
33404
|
+
const profile = this.hcs11Client.createAIAgentProfile(
|
|
33405
|
+
agentName,
|
|
33406
|
+
agentType,
|
|
33407
|
+
capabilities,
|
|
33408
|
+
metadata.model || "unknown",
|
|
33409
|
+
{
|
|
33410
|
+
alias: agentName.toLowerCase().replace(/\s+/g, "_"),
|
|
33411
|
+
bio: agentDescription,
|
|
33412
|
+
profileImage: pfpTopicId ? `hcs://1/${pfpTopicId}` : void 0,
|
|
33413
|
+
socials: formattedSocials.length > 0 ? formattedSocials : void 0,
|
|
33414
|
+
properties: {
|
|
33415
|
+
description: agentDescription,
|
|
33416
|
+
version: metadata.version || "1.0.0",
|
|
33417
|
+
creator: metadata.creator || "Unknown",
|
|
33418
|
+
supported_languages: metadata.supported_languages || ["en"],
|
|
33419
|
+
permissions: metadata.permissions || [],
|
|
33420
|
+
model_details: metadata.model_details,
|
|
33421
|
+
training: metadata.training,
|
|
33422
|
+
capabilities_description: metadata.capabilities_description,
|
|
33423
|
+
...metadata
|
|
33424
|
+
},
|
|
33425
|
+
inboundTopicId,
|
|
33426
|
+
outboundTopicId,
|
|
33427
|
+
creator: metadata.creator
|
|
33428
|
+
}
|
|
33429
|
+
);
|
|
33430
|
+
const profileResult = await this.hcs11Client.createAndInscribeProfile(
|
|
33431
|
+
profile,
|
|
33432
|
+
true
|
|
33433
|
+
);
|
|
33434
|
+
if (!profileResult.success) {
|
|
33435
|
+
return {
|
|
33436
|
+
profileTopicId: "",
|
|
33437
|
+
success: false,
|
|
33438
|
+
error: profileResult.error || "Failed to inscribe profile"
|
|
33439
|
+
};
|
|
33440
|
+
}
|
|
33441
|
+
return {
|
|
33442
|
+
profileTopicId: profileResult.profileTopicId,
|
|
33443
|
+
pfpTopicId,
|
|
33444
|
+
success: true
|
|
33445
|
+
};
|
|
33446
|
+
} catch (error) {
|
|
33447
|
+
return {
|
|
33448
|
+
profileTopicId: "",
|
|
33449
|
+
success: false,
|
|
33450
|
+
error: error.message
|
|
33451
|
+
};
|
|
33452
|
+
}
|
|
33453
|
+
}
|
|
33454
|
+
async createTopic(memo, adminKey, submitKey) {
|
|
33455
|
+
this.logger.info("Creating topic");
|
|
33456
|
+
const { accountId, signer } = this.getAccountAndSigner();
|
|
33457
|
+
const transaction = new TopicCreateTransaction().setTopicMemo(memo);
|
|
33458
|
+
const publicKey = await this.mirrorNode.getPublicKey(accountId);
|
|
33459
|
+
if (adminKey && publicKey) {
|
|
33460
|
+
transaction.setAdminKey(publicKey);
|
|
33461
|
+
transaction.setAutoRenewAccountId(accountId);
|
|
33462
|
+
}
|
|
33463
|
+
if (submitKey && publicKey) {
|
|
33464
|
+
transaction.setSubmitKey(publicKey);
|
|
33465
|
+
}
|
|
33466
|
+
const transactionResponse = await this.hwc.executeTransactionWithErrorHandling(
|
|
33467
|
+
transaction,
|
|
33468
|
+
false
|
|
33469
|
+
);
|
|
33470
|
+
const error = transactionResponse.error;
|
|
33471
|
+
if (error) {
|
|
33472
|
+
this.logger.error(error);
|
|
33473
|
+
return {
|
|
33474
|
+
success: false,
|
|
33475
|
+
error
|
|
33476
|
+
};
|
|
33477
|
+
}
|
|
33478
|
+
const result = transactionResponse.result;
|
|
33479
|
+
if (!(result == null ? void 0 : result.topicId)) {
|
|
33480
|
+
this.logger.error("Failed to create topic: topicId is null");
|
|
33481
|
+
return {
|
|
33482
|
+
success: false,
|
|
33483
|
+
error: "Failed to create topic: topicId is null"
|
|
33484
|
+
};
|
|
33485
|
+
}
|
|
33486
|
+
return {
|
|
33487
|
+
success: true,
|
|
33488
|
+
topicId: result.topicId.toString()
|
|
33489
|
+
};
|
|
33490
|
+
}
|
|
33491
|
+
async submitPayload(topicId, payload) {
|
|
33492
|
+
this.logger.debug("Submitting payload");
|
|
33493
|
+
const transaction = new TopicMessageSubmitTransaction().setTopicId(topicId).setMessage(JSON.stringify(payload));
|
|
33494
|
+
return await this.hwc.executeTransactionWithErrorHandling(
|
|
33495
|
+
// @ts-ignore
|
|
33496
|
+
transaction,
|
|
33497
|
+
false
|
|
33498
|
+
);
|
|
33499
|
+
}
|
|
33500
|
+
async inscribeFile(buffer2, fileName) {
|
|
33501
|
+
const { accountId, signer } = this.getAccountAndSigner();
|
|
33502
|
+
const mimeType = mimeTypes.lookup(fileName) || "application/octet-stream";
|
|
33503
|
+
const sdk = await InscriptionSDK.createWithAuth({
|
|
33504
|
+
type: "client",
|
|
33505
|
+
accountId,
|
|
33506
|
+
signer,
|
|
33507
|
+
network: this.network
|
|
33508
|
+
});
|
|
33509
|
+
const result = await sdk.inscribe(
|
|
33510
|
+
{
|
|
33511
|
+
file: {
|
|
33512
|
+
type: "base64",
|
|
33513
|
+
base64: buffer2.toString("base64"),
|
|
33514
|
+
fileName,
|
|
33515
|
+
mimeType
|
|
33516
|
+
},
|
|
33517
|
+
holderId: accountId.toString(),
|
|
33518
|
+
mode: "file",
|
|
33519
|
+
network: this.network
|
|
33520
|
+
},
|
|
33521
|
+
signer
|
|
33522
|
+
);
|
|
33523
|
+
if (!result.transactionId || !result.jobId) {
|
|
33524
|
+
this.logger.error("Failed to inscribe, no transaction ID or job ID.");
|
|
33525
|
+
throw new Error("Failed to inscribe, no transaction ID or job ID.");
|
|
33526
|
+
}
|
|
33527
|
+
if (result.transactionId && result.jobId) {
|
|
33528
|
+
this.logger.info(
|
|
33529
|
+
`Transaction ID: ${result.transactionId}, Job ID: ${result.jobId}`
|
|
33530
|
+
);
|
|
33531
|
+
}
|
|
33532
|
+
const status = await sdk.waitForInscription(result.jobId, 30, 4e3, true);
|
|
33533
|
+
return status;
|
|
33534
|
+
}
|
|
33535
|
+
getAccountAndSigner() {
|
|
33536
|
+
const accountInfo = this.hwc.getAccountInfo();
|
|
33537
|
+
const accountId = accountInfo.accountId.toString();
|
|
33538
|
+
const signer = this.hwc.dAppConnector.signers.find((s) => {
|
|
33539
|
+
return s.getAccountId().toString() === accountId;
|
|
33540
|
+
});
|
|
33541
|
+
if (!signer) {
|
|
33542
|
+
this.logger.error("Failed to find signer");
|
|
33543
|
+
throw new Error("Failed to find signer");
|
|
33544
|
+
}
|
|
33545
|
+
return { accountId, signer };
|
|
33546
|
+
}
|
|
33547
|
+
/**
|
|
33548
|
+
* Inscribes a profile picture file to the Hedera network
|
|
33549
|
+
* @param buffer File buffer to inscribe
|
|
33550
|
+
* @param fileName Filename for the inscription
|
|
33551
|
+
* @returns Object containing the topic ID and success status
|
|
33552
|
+
*/
|
|
33553
|
+
async inscribePfp(buffer2, fileName) {
|
|
33554
|
+
try {
|
|
33555
|
+
this.logger.info("Inscribing profile picture using HCS-11 client");
|
|
33556
|
+
const imageResult = await this.hcs11Client.inscribeImage(
|
|
33557
|
+
buffer2,
|
|
33558
|
+
fileName
|
|
33559
|
+
);
|
|
33560
|
+
if (!imageResult.success) {
|
|
33561
|
+
this.logger.error(
|
|
33562
|
+
`Failed to inscribe profile picture: ${imageResult.error}`
|
|
33563
|
+
);
|
|
33564
|
+
return {
|
|
33565
|
+
pfpTopicId: "",
|
|
33566
|
+
success: false,
|
|
33567
|
+
error: imageResult.error || "Failed to inscribe profile picture"
|
|
33568
|
+
};
|
|
33569
|
+
}
|
|
33570
|
+
this.logger.info(
|
|
33571
|
+
`Successfully inscribed profile picture with topic ID: ${imageResult.imageTopicId}`
|
|
33572
|
+
);
|
|
33573
|
+
return {
|
|
33574
|
+
pfpTopicId: imageResult.imageTopicId,
|
|
33575
|
+
success: true
|
|
33576
|
+
};
|
|
33577
|
+
} catch (error) {
|
|
33578
|
+
this.logger.error(`Error inscribing profile picture: ${error.message}`);
|
|
33579
|
+
return {
|
|
33580
|
+
pfpTopicId: "",
|
|
33581
|
+
success: false,
|
|
33582
|
+
error: error.message
|
|
33583
|
+
};
|
|
33584
|
+
}
|
|
33585
|
+
}
|
|
33586
|
+
}
|
|
32985
33587
|
export {
|
|
32986
33588
|
AIAgentCapability,
|
|
32987
33589
|
AIAgentType,
|
|
32988
33590
|
AccountCreationError,
|
|
32989
33591
|
AgentBuilder,
|
|
33592
|
+
BrowserHCSClient,
|
|
32990
33593
|
ConnectionConfirmationError,
|
|
32991
33594
|
EVMBridge,
|
|
32992
33595
|
EndpointType,
|