@hashgraphonline/standards-agent-kit 0.0.36 → 0.0.37
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/standards-agent-kit.es2.js +1 -1
- package/dist/es/standards-agent-kit.es25.js +3 -81
- package/dist/es/standards-agent-kit.es25.js.map +1 -1
- package/dist/es/standards-agent-kit.es26.js +81 -3
- package/dist/es/standards-agent-kit.es26.js.map +1 -1
- package/dist/es/standards-agent-kit.es3.js +1 -1
- package/package.json +4 -12
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { HCS10Client as HCS10Client$1, Logger, AgentBuilder, AIAgentCapability, InboundTopicType } from "@hashgraphonline/standards-sdk";
|
|
2
|
-
import { encryptMessage } from "./standards-agent-kit.
|
|
2
|
+
import { encryptMessage } from "./standards-agent-kit.es25.js";
|
|
3
3
|
class HCS10Client {
|
|
4
4
|
constructor(operatorId, operatorPrivateKey, network, options) {
|
|
5
5
|
this.standardClient = new HCS10Client$1({
|
|
@@ -1,85 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const MIN_REQUIRED_USD = 2;
|
|
4
|
-
const MIN_REQUIRED_HBAR_USD = 10;
|
|
5
|
-
async function ensureAgentHasEnoughHbar(logger, baseClient, accountId, agentName) {
|
|
6
|
-
try {
|
|
7
|
-
const account = await baseClient.requestAccount(accountId);
|
|
8
|
-
const balance = account.balance.balance;
|
|
9
|
-
const hbarBalance = balance / 1e8;
|
|
10
|
-
logger.info(`${agentName} account ${accountId} has ${hbarBalance} HBAR`);
|
|
11
|
-
try {
|
|
12
|
-
const mirrorNode = new HederaMirrorNode("testnet", logger);
|
|
13
|
-
const hbarPrice = await mirrorNode.getHBARPrice(/* @__PURE__ */ new Date());
|
|
14
|
-
if (hbarPrice) {
|
|
15
|
-
const balanceInUsd = hbarBalance * hbarPrice;
|
|
16
|
-
logger.info(`${agentName} balance in USD: $${balanceInUsd.toFixed(2)}`);
|
|
17
|
-
if (balanceInUsd < MIN_REQUIRED_USD) {
|
|
18
|
-
logger.warn(
|
|
19
|
-
`${agentName} account ${accountId} has less than $${MIN_REQUIRED_USD} (${balanceInUsd.toFixed(
|
|
20
|
-
2
|
|
21
|
-
)}). Attempting to fund.`
|
|
22
|
-
);
|
|
23
|
-
try {
|
|
24
|
-
const funder = baseClient.getAccountAndSigner();
|
|
25
|
-
const targetHbar = MIN_REQUIRED_HBAR_USD / hbarPrice;
|
|
26
|
-
const amountToTransferHbar = Math.max(0, targetHbar - hbarBalance);
|
|
27
|
-
if (amountToTransferHbar > 0) {
|
|
28
|
-
const transferTx = new TransferTransaction().addHbarTransfer(
|
|
29
|
-
funder.accountId,
|
|
30
|
-
Hbar.fromTinybars(
|
|
31
|
-
Math.round(amountToTransferHbar * -1e8)
|
|
32
|
-
)
|
|
33
|
-
).addHbarTransfer(
|
|
34
|
-
accountId,
|
|
35
|
-
Hbar.fromTinybars(
|
|
36
|
-
Math.round(amountToTransferHbar * 1e8)
|
|
37
|
-
)
|
|
38
|
-
);
|
|
39
|
-
logger.info(
|
|
40
|
-
`Funding ${agentName} account ${accountId} with ${amountToTransferHbar.toFixed(
|
|
41
|
-
2
|
|
42
|
-
)} HBAR from ${funder.accountId}`
|
|
43
|
-
);
|
|
44
|
-
const fundTxResponse = await transferTx.execute(
|
|
45
|
-
baseClient.getClient()
|
|
46
|
-
);
|
|
47
|
-
await fundTxResponse.getReceipt(baseClient.getClient());
|
|
48
|
-
logger.info(
|
|
49
|
-
`Successfully funded ${agentName} account ${accountId}.`
|
|
50
|
-
);
|
|
51
|
-
} else {
|
|
52
|
-
logger.info(
|
|
53
|
-
`${agentName} account ${accountId} does not require additional funding.`
|
|
54
|
-
);
|
|
55
|
-
}
|
|
56
|
-
} catch (fundingError) {
|
|
57
|
-
logger.error(
|
|
58
|
-
`Failed to automatically fund ${agentName} account ${accountId}:`,
|
|
59
|
-
fundingError
|
|
60
|
-
);
|
|
61
|
-
logger.warn(
|
|
62
|
-
`Please fund the account ${accountId} manually with at least ${(MIN_REQUIRED_HBAR_USD / hbarPrice).toFixed(2)} HBAR.`
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
} else {
|
|
67
|
-
logger.warn(
|
|
68
|
-
"Failed to get HBAR price from Mirror Node. Please ensure the account has enough HBAR."
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
} catch (error) {
|
|
72
|
-
logger.warn(
|
|
73
|
-
"Failed to check USD balance. Please ensure the account has enough HBAR."
|
|
74
|
-
);
|
|
75
|
-
}
|
|
76
|
-
} catch (error) {
|
|
77
|
-
logger.error(`Failed to check ${agentName} account balance:`, error);
|
|
78
|
-
}
|
|
1
|
+
function encryptMessage(message) {
|
|
2
|
+
return message;
|
|
79
3
|
}
|
|
80
4
|
export {
|
|
81
|
-
|
|
82
|
-
MIN_REQUIRED_USD,
|
|
83
|
-
ensureAgentHasEnoughHbar
|
|
5
|
+
encryptMessage
|
|
84
6
|
};
|
|
85
7
|
//# sourceMappingURL=standards-agent-kit.es25.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-agent-kit.es25.js","sources":["../../src/utils/
|
|
1
|
+
{"version":3,"file":"standards-agent-kit.es25.js","sources":["../../src/utils/Encryption.ts"],"sourcesContent":["// src/utils/Encryption.ts\n/**\n * Placeholder for encryption functionality.\n * Currently, encryption is disabled. The useEncryption flag is false by default.\n * TODO: Implement actual encryption/decryption logic.\n */\n\nexport function encryptMessage(message: string): string {\n // TODO: Add encryption logic here if useEncryption flag is true.\n return message; // currently returns plaintext.\n}\n\nexport function decryptMessage(encryptedMessage: string): string {\n // TODO: Add decryption logic here.\n return encryptedMessage;\n}\n"],"names":[],"mappings":"AAOO,SAAS,eAAe,SAAyB;AAE7C,SAAA;AACX;"}
|
|
@@ -1,7 +1,85 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
import { TransferTransaction, Hbar } from "@hashgraph/sdk";
|
|
2
|
+
import { HederaMirrorNode } from "@hashgraphonline/standards-sdk";
|
|
3
|
+
const MIN_REQUIRED_USD = 2;
|
|
4
|
+
const MIN_REQUIRED_HBAR_USD = 10;
|
|
5
|
+
async function ensureAgentHasEnoughHbar(logger, baseClient, accountId, agentName) {
|
|
6
|
+
try {
|
|
7
|
+
const account = await baseClient.requestAccount(accountId);
|
|
8
|
+
const balance = account.balance.balance;
|
|
9
|
+
const hbarBalance = balance / 1e8;
|
|
10
|
+
logger.info(`${agentName} account ${accountId} has ${hbarBalance} HBAR`);
|
|
11
|
+
try {
|
|
12
|
+
const mirrorNode = new HederaMirrorNode("testnet", logger);
|
|
13
|
+
const hbarPrice = await mirrorNode.getHBARPrice(/* @__PURE__ */ new Date());
|
|
14
|
+
if (hbarPrice) {
|
|
15
|
+
const balanceInUsd = hbarBalance * hbarPrice;
|
|
16
|
+
logger.info(`${agentName} balance in USD: $${balanceInUsd.toFixed(2)}`);
|
|
17
|
+
if (balanceInUsd < MIN_REQUIRED_USD) {
|
|
18
|
+
logger.warn(
|
|
19
|
+
`${agentName} account ${accountId} has less than $${MIN_REQUIRED_USD} (${balanceInUsd.toFixed(
|
|
20
|
+
2
|
|
21
|
+
)}). Attempting to fund.`
|
|
22
|
+
);
|
|
23
|
+
try {
|
|
24
|
+
const funder = baseClient.getAccountAndSigner();
|
|
25
|
+
const targetHbar = MIN_REQUIRED_HBAR_USD / hbarPrice;
|
|
26
|
+
const amountToTransferHbar = Math.max(0, targetHbar - hbarBalance);
|
|
27
|
+
if (amountToTransferHbar > 0) {
|
|
28
|
+
const transferTx = new TransferTransaction().addHbarTransfer(
|
|
29
|
+
funder.accountId,
|
|
30
|
+
Hbar.fromTinybars(
|
|
31
|
+
Math.round(amountToTransferHbar * -1e8)
|
|
32
|
+
)
|
|
33
|
+
).addHbarTransfer(
|
|
34
|
+
accountId,
|
|
35
|
+
Hbar.fromTinybars(
|
|
36
|
+
Math.round(amountToTransferHbar * 1e8)
|
|
37
|
+
)
|
|
38
|
+
);
|
|
39
|
+
logger.info(
|
|
40
|
+
`Funding ${agentName} account ${accountId} with ${amountToTransferHbar.toFixed(
|
|
41
|
+
2
|
|
42
|
+
)} HBAR from ${funder.accountId}`
|
|
43
|
+
);
|
|
44
|
+
const fundTxResponse = await transferTx.execute(
|
|
45
|
+
baseClient.getClient()
|
|
46
|
+
);
|
|
47
|
+
await fundTxResponse.getReceipt(baseClient.getClient());
|
|
48
|
+
logger.info(
|
|
49
|
+
`Successfully funded ${agentName} account ${accountId}.`
|
|
50
|
+
);
|
|
51
|
+
} else {
|
|
52
|
+
logger.info(
|
|
53
|
+
`${agentName} account ${accountId} does not require additional funding.`
|
|
54
|
+
);
|
|
55
|
+
}
|
|
56
|
+
} catch (fundingError) {
|
|
57
|
+
logger.error(
|
|
58
|
+
`Failed to automatically fund ${agentName} account ${accountId}:`,
|
|
59
|
+
fundingError
|
|
60
|
+
);
|
|
61
|
+
logger.warn(
|
|
62
|
+
`Please fund the account ${accountId} manually with at least ${(MIN_REQUIRED_HBAR_USD / hbarPrice).toFixed(2)} HBAR.`
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
} else {
|
|
67
|
+
logger.warn(
|
|
68
|
+
"Failed to get HBAR price from Mirror Node. Please ensure the account has enough HBAR."
|
|
69
|
+
);
|
|
70
|
+
}
|
|
71
|
+
} catch (error) {
|
|
72
|
+
logger.warn(
|
|
73
|
+
"Failed to check USD balance. Please ensure the account has enough HBAR."
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
} catch (error) {
|
|
77
|
+
logger.error(`Failed to check ${agentName} account balance:`, error);
|
|
78
|
+
}
|
|
3
79
|
}
|
|
4
80
|
export {
|
|
5
|
-
|
|
81
|
+
MIN_REQUIRED_HBAR_USD,
|
|
82
|
+
MIN_REQUIRED_USD,
|
|
83
|
+
ensureAgentHasEnoughHbar
|
|
6
84
|
};
|
|
7
85
|
//# sourceMappingURL=standards-agent-kit.es26.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-agent-kit.es26.js","sources":["../../src/utils/
|
|
1
|
+
{"version":3,"file":"standards-agent-kit.es26.js","sources":["../../src/utils/ensure-agent-has-hbar.ts"],"sourcesContent":["import { Hbar } from \"@hashgraph/sdk\";\nimport { TransferTransaction } from \"@hashgraph/sdk\";\nimport { Logger, HCS10Client, HederaMirrorNode } from \"@hashgraphonline/standards-sdk\";\n\nexport const MIN_REQUIRED_USD = 2.0;\nexport const MIN_REQUIRED_HBAR_USD = 10.0;\n\nexport async function ensureAgentHasEnoughHbar(\n logger: Logger,\n baseClient: HCS10Client,\n accountId: string,\n agentName: string\n): Promise<void> {\n try {\n const account = await baseClient.requestAccount(accountId);\n const balance = account.balance.balance;\n const hbarBalance = balance / 100_000_000;\n\n logger.info(`${agentName} account ${accountId} has ${hbarBalance} HBAR`);\n\n try {\n const mirrorNode = new HederaMirrorNode('testnet', logger);\n const hbarPrice = await mirrorNode.getHBARPrice(new Date());\n\n if (hbarPrice) {\n const balanceInUsd = hbarBalance * hbarPrice;\n logger.info(`${agentName} balance in USD: $${balanceInUsd.toFixed(2)}`);\n\n if (balanceInUsd < MIN_REQUIRED_USD) {\n logger.warn(\n `${agentName} account ${accountId} has less than $${MIN_REQUIRED_USD} (${balanceInUsd.toFixed(\n 2\n )}). Attempting to fund.`\n );\n\n try {\n const funder = baseClient.getAccountAndSigner();\n const targetHbar = MIN_REQUIRED_HBAR_USD / hbarPrice;\n const amountToTransferHbar = Math.max(0, targetHbar - hbarBalance);\n\n if (amountToTransferHbar > 0) {\n const transferTx = new TransferTransaction()\n .addHbarTransfer(\n funder.accountId,\n Hbar.fromTinybars(\n Math.round(amountToTransferHbar * -100_000_000)\n )\n )\n .addHbarTransfer(\n accountId,\n Hbar.fromTinybars(\n Math.round(amountToTransferHbar * 100_000_000)\n )\n );\n\n logger.info(\n `Funding ${agentName} account ${accountId} with ${amountToTransferHbar.toFixed(\n 2\n )} HBAR from ${funder.accountId}`\n );\n\n const fundTxResponse = await transferTx.execute(\n baseClient.getClient() as any\n );\n await fundTxResponse.getReceipt(baseClient.getClient() as any);\n logger.info(\n `Successfully funded ${agentName} account ${accountId}.`\n );\n } else {\n logger.info(\n `${agentName} account ${accountId} does not require additional funding.`\n );\n }\n } catch (fundingError) {\n logger.error(\n `Failed to automatically fund ${agentName} account ${accountId}:`,\n fundingError\n );\n logger.warn(\n `Please fund the account ${accountId} manually with at least ${(\n MIN_REQUIRED_HBAR_USD / hbarPrice\n ).toFixed(2)} HBAR.`\n );\n }\n }\n } else {\n logger.warn(\n 'Failed to get HBAR price from Mirror Node. Please ensure the account has enough HBAR.'\n );\n }\n } catch (error) {\n logger.warn(\n 'Failed to check USD balance. Please ensure the account has enough HBAR.'\n );\n }\n } catch (error) {\n logger.error(`Failed to check ${agentName} account balance:`, error);\n }\n}"],"names":[],"mappings":";;AAIO,MAAM,mBAAmB;AACzB,MAAM,wBAAwB;AAErC,eAAsB,yBACpB,QACA,YACA,WACA,WACe;AACX,MAAA;AACF,UAAM,UAAU,MAAM,WAAW,eAAe,SAAS;AACnD,UAAA,UAAU,QAAQ,QAAQ;AAChC,UAAM,cAAc,UAAU;AAE9B,WAAO,KAAK,GAAG,SAAS,YAAY,SAAS,QAAQ,WAAW,OAAO;AAEnE,QAAA;AACF,YAAM,aAAa,IAAI,iBAAiB,WAAW,MAAM;AACzD,YAAM,YAAY,MAAM,WAAW,aAAa,oBAAI,MAAM;AAE1D,UAAI,WAAW;AACb,cAAM,eAAe,cAAc;AAC5B,eAAA,KAAK,GAAG,SAAS,qBAAqB,aAAa,QAAQ,CAAC,CAAC,EAAE;AAEtE,YAAI,eAAe,kBAAkB;AAC5B,iBAAA;AAAA,YACL,GAAG,SAAS,YAAY,SAAS,mBAAmB,gBAAgB,KAAK,aAAa;AAAA,cACpF;AAAA,YAAA,CACD;AAAA,UACH;AAEI,cAAA;AACI,kBAAA,SAAS,WAAW,oBAAoB;AAC9C,kBAAM,aAAa,w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
|
-
import { ensureAgentHasEnoughHbar } from "./standards-agent-kit.
|
|
2
|
+
import { ensureAgentHasEnoughHbar } from "./standards-agent-kit.es26.js";
|
|
3
3
|
import { StructuredTool } from "@langchain/core/tools";
|
|
4
4
|
import { z } from "zod";
|
|
5
5
|
import fs__default from "fs";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hashgraphonline/standards-agent-kit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.37",
|
|
4
4
|
"description": "A modular SDK for building on-chain autonomous agents using Hashgraph Online Standards, including HCS-10 for agent discovery and communication.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/cjs/standards-agent-kit.cjs",
|
|
@@ -9,18 +9,10 @@
|
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
11
|
"types": "./dist/es/index.d.ts",
|
|
12
|
-
"browser": {
|
|
13
|
-
"import": "./dist/umd/standards-agent-kit.umd.js",
|
|
14
|
-
"require": "./dist/umd/standards-agent-kit.umd.js"
|
|
15
|
-
},
|
|
16
|
-
"node": {
|
|
17
|
-
"import": "./dist/es/standards-agent-kit.es.js",
|
|
18
|
-
"require": "./dist/cjs/standards-agent-kit.cjs"
|
|
19
|
-
},
|
|
20
12
|
"import": "./dist/es/standards-agent-kit.es.js",
|
|
21
|
-
"require": "./dist/cjs/standards-agent-kit.cjs"
|
|
22
|
-
|
|
23
|
-
|
|
13
|
+
"require": "./dist/cjs/standards-agent-kit.cjs",
|
|
14
|
+
"default": "./dist/es/standards-agent-kit.es.js"
|
|
15
|
+
}
|
|
24
16
|
},
|
|
25
17
|
"files": [
|
|
26
18
|
"dist",
|