@hashgraphonline/standards-agent-kit 0.0.32 → 0.0.33
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/src/init/index.d.ts +1 -0
- package/dist/cjs/src/{init.d.ts → init/init.d.ts} +16 -16
- package/dist/cjs/standards-agent-kit.cjs +1 -1
- package/dist/cjs/standards-agent-kit.cjs.map +1 -1
- package/dist/es/src/init/index.d.ts +1 -0
- package/dist/es/src/{init.d.ts → init/init.d.ts} +16 -16
- package/dist/es/standards-agent-kit.es.js +17 -17
- package/dist/es/standards-agent-kit.es10.js +65 -104
- package/dist/es/standards-agent-kit.es10.js.map +1 -1
- package/dist/es/standards-agent-kit.es11.js +371 -66
- package/dist/es/standards-agent-kit.es11.js.map +1 -1
- package/dist/es/standards-agent-kit.es12.js +153 -348
- package/dist/es/standards-agent-kit.es12.js.map +1 -1
- package/dist/es/standards-agent-kit.es13.js +105 -161
- package/dist/es/standards-agent-kit.es13.js.map +1 -1
- package/dist/es/standards-agent-kit.es14.js +48 -126
- package/dist/es/standards-agent-kit.es14.js.map +1 -1
- package/dist/es/standards-agent-kit.es15.js +108 -50
- package/dist/es/standards-agent-kit.es15.js.map +1 -1
- package/dist/es/standards-agent-kit.es16.js +239 -117
- package/dist/es/standards-agent-kit.es16.js.map +1 -1
- package/dist/es/standards-agent-kit.es17.js +120 -245
- package/dist/es/standards-agent-kit.es17.js.map +1 -1
- package/dist/es/standards-agent-kit.es2.js +321 -114
- package/dist/es/standards-agent-kit.es2.js.map +1 -1
- package/dist/es/standards-agent-kit.es23.js +15 -15
- package/dist/es/standards-agent-kit.es24.js +3 -24
- package/dist/es/standards-agent-kit.es24.js.map +1 -1
- package/dist/es/standards-agent-kit.es25.js +81 -3
- package/dist/es/standards-agent-kit.es25.js.map +1 -1
- package/dist/es/standards-agent-kit.es26.js +22 -79
- package/dist/es/standards-agent-kit.es26.js.map +1 -1
- package/dist/es/standards-agent-kit.es3.js +347 -284
- package/dist/es/standards-agent-kit.es3.js.map +1 -1
- package/dist/es/standards-agent-kit.es4.js +56 -366
- package/dist/es/standards-agent-kit.es4.js.map +1 -1
- package/dist/es/standards-agent-kit.es5.js +142 -58
- package/dist/es/standards-agent-kit.es5.js.map +1 -1
- package/dist/es/standards-agent-kit.es6.js +73 -143
- package/dist/es/standards-agent-kit.es6.js.map +1 -1
- package/dist/es/standards-agent-kit.es7.js +65 -64
- package/dist/es/standards-agent-kit.es7.js.map +1 -1
- package/dist/es/standards-agent-kit.es8.js +91 -77
- package/dist/es/standards-agent-kit.es8.js.map +1 -1
- package/dist/es/standards-agent-kit.es9.js +109 -90
- package/dist/es/standards-agent-kit.es9.js.map +1 -1
- package/dist/umd/src/init/index.d.ts +1 -0
- package/dist/umd/src/{init.d.ts → init/init.d.ts} +16 -16
- package/dist/umd/standards-agent-kit.umd.js +2 -2
- package/dist/umd/standards-agent-kit.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +1 -1
- package/src/init/index.ts +1 -0
- package/src/{init.ts → init/init.ts} +22 -20
|
@@ -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.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/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,wBAAwB;AAC3C,kBAAM,uBAAuB,KAAK,IAAI,GAAG,aAAa,WAAW;AAEjE,gBAAI,uBAAuB,GAAG;AACtB,oBAAA,aAAa,IAAI,oBAAA,EACpB;AAAA,gBACC,OAAO;AAAA,gBACP,KAAK;AAAA,kBACH,KAAK,MAAM,uBAAuB,IAAY;AAAA,gBAAA;AAAA,cAChD,EAED;AAAA,gBACC;AAAA,gBACA,KAAK;AAAA,kBACH,KAAK,MAAM,uBAAuB,GAAW;AAAA,gBAAA;AAAA,cAEjD;AAEK,qBAAA;AAAA,gBACL,WAAW,SAAS,YAAY,SAAS,SAAS,qBAAqB;AAAA,kBACrE;AAAA,gBAAA,CACD,cAAc,OAAO,SAAS;AAAA,cACjC;AAEM,oBAAA,iBAAiB,MAAM,WAAW;AAAA,gBACtC,WAAW,UAAU;AAAA,cACvB;AACA,oBAAM,eAAe,WAAW,WAAW,UAAA,CAAkB;AACtD,qBAAA;AAAA,gBACL,uBAAuB,SAAS,YAAY,SAAS;AAAA,cACvD;AAAA,YAAA,OACK;AACE,qBAAA;AAAA,gBACL,GAAG,SAAS,YAAY,SAAS;AAAA,cACnC;AAAA,YAAA;AAAA,mBAEK,cAAc;AACd,mBAAA;AAAA,cACL,gCAAgC,SAAS,YAAY,SAAS;AAAA,cAC9D;AAAA,YACF;AACO,mBAAA;AAAA,cACL,2BAA2B,SAAS,4BAClC,wBAAwB,WACxB,QAAQ,CAAC,CAAC;AAAA,YACd;AAAA,UAAA;AAAA,QACF;AAAA,MACF,OACK;AACE,eAAA;AAAA,UACL;AAAA,QACF;AAAA,MAAA;AAAA,aAEK,OAAO;AACP,aAAA;AAAA,QACL;AAAA,MACF;AAAA,IAAA;AAAA,WAEK,OAAO;AACd,WAAO,MAAM,mBAAmB,SAAS,qBAAqB,KAAK;AAAA,EAAA;AAEvE;"}
|
|
@@ -1,85 +1,28 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
async function
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
);
|
|
1
|
+
import "@hashgraphonline/standards-sdk";
|
|
2
|
+
import fs__default from "fs";
|
|
3
|
+
import path__default from "path";
|
|
4
|
+
const ENV_FILE_PATH = path__default.join(process.cwd(), ".env");
|
|
5
|
+
async function updateEnvFile(envFilePath, variables) {
|
|
6
|
+
let envContent = "";
|
|
7
|
+
if (fs__default.existsSync(envFilePath)) {
|
|
8
|
+
envContent = fs__default.readFileSync(envFilePath, "utf8");
|
|
9
|
+
}
|
|
10
|
+
const envLines = envContent.split("\n");
|
|
11
|
+
const updatedLines = [...envLines];
|
|
12
|
+
for (const [key, value] of Object.entries(variables)) {
|
|
13
|
+
const lineIndex = updatedLines.findIndex(
|
|
14
|
+
(line) => line.startsWith(`${key}=`)
|
|
15
|
+
);
|
|
16
|
+
if (lineIndex !== -1) {
|
|
17
|
+
updatedLines[lineIndex] = `${key}=${value}`;
|
|
18
|
+
} else {
|
|
19
|
+
updatedLines.push(`${key}=${value}`);
|
|
75
20
|
}
|
|
76
|
-
} catch (error) {
|
|
77
|
-
logger.error(`Failed to check ${agentName} account balance:`, error);
|
|
78
21
|
}
|
|
22
|
+
fs__default.writeFileSync(envFilePath, updatedLines.join("\n"));
|
|
79
23
|
}
|
|
80
24
|
export {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
ensureAgentHasEnoughHbar
|
|
25
|
+
ENV_FILE_PATH,
|
|
26
|
+
updateEnvFile
|
|
84
27
|
};
|
|
85
28
|
//# 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/state-tools.ts"],"sourcesContent":["import {\n HCS10Client,\n AgentBuilder,\n Logger,\n} from '@hashgraphonline/standards-sdk';\nimport fs from 'fs';\nimport path from 'path';\nimport { ensureAgentHasEnoughHbar } from './ensure-agent-has-hbar';\n\nexport const ENV_FILE_PATH = path.join(process.cwd(), '.env');\n\nexport interface AgentData {\n accountId: string;\n operatorId: string;\n inboundTopicId: string;\n outboundTopicId: string;\n client: HCS10Client;\n}\n\nexport interface RegistrationProgressData {\n registered: boolean;\n accountId?: string;\n privateKey?: string;\n publicKey?: string;\n inboundTopicId?: string;\n outboundTopicId?: string;\n}\n\nexport async function getAgentFromEnv(\n logger: Logger,\n baseClient: HCS10Client,\n agentName: string,\n envPrefix: string\n): Promise<AgentData | null> {\n const accountIdEnvVar = `${envPrefix}_ACCOUNT_ID`;\n const privateKeyEnvVar = `${envPrefix}_PRIVATE_KEY`;\n const inboundTopicIdEnvVar = `${envPrefix}_INBOUND_TOPIC_ID`;\n const outboundTopicIdEnvVar = `${envPrefix}_OUTBOUND_TOPIC_ID`;\n\n const accountId = process.env[accountIdEnvVar];\n const privateKey = process.env[privateKeyEnvVar];\n const inboundTopicId = process.env[inboundTopicIdEnvVar];\n const outboundTopicId = process.env[outboundTopicIdEnvVar];\n\n if (!accountId || !privateKey || !inboundTopicId || !outboundTopicId) {\n logger.info(`${agentName} agent not found in environment variables`);\n return null;\n }\n\n logger.info(`${agentName} agent found in environment variables`);\n logger.info(`${agentName} account ID: ${accountId}`);\n logger.info(`${agentName} inbound topic ID: ${inboundTopicId}`);\n logger.info(`${agentName} outbound topic ID: ${outboundTopicId}`);\n\n const client = new HCS10Client({\n network: 'testnet',\n operatorId: accountId,\n operatorPrivateKey: privateKey,\n guardedRegistryBaseUrl: process.env.REGISTRY_URL,\n prettyPrint: true,\n logLevel: 'debug',\n });\n\n await ensureAgentHasEnoughHbar(logger, baseClient, accountId, agentName);\n\n return {\n accountId,\n operatorId: `${inboundTopicId}@${accountId}`,\n inboundTopicId,\n outboundTopicId,\n client,\n };\n}\n\nexport async function createAgent(\n logger: Logger,\n baseClient: HCS10Client,\n agentName: string,\n agentBuilder: AgentBuilder,\n envPrefix: string\n): Promise<AgentData | null> {\n try {\n logger.info(`Creating ${agentName} agent...`);\n\n const result = await baseClient.createAndRegisterAgent(agentBuilder);\n\n if (!result.metadata) {\n logger.error(`${agentName} agent creation failed`);\n return null;\n }\n\n logger.info(`${agentName} agent created successfully`);\n logger.info(`${agentName} account ID: ${result.metadata.accountId}`);\n logger.info(`${agentName} private key: ${result.metadata.privateKey}`);\n logger.info(\n `${agentName} inbound topic ID: ${result.metadata.inboundTopicId}`\n );\n logger.info(\n `${agentName} outbound topic ID: ${result.metadata.outboundTopicId}`\n );\n\n const envVars = {\n [`${envPrefix}_ACCOUNT_ID`]: result.metadata.accountId,\n [`${envPrefix}_PRIVATE_KEY`]: result.metadata.privateKey,\n [`${envPrefix}_INBOUND_TOPIC_ID`]: result.metadata.inboundTopicId,\n [`${envPrefix}_OUTBOUND_TOPIC_ID`]: result.metadata.outboundTopicId,\n };\n\n await updateEnvFile(ENV_FILE_PATH, envVars);\n\n const client = new HCS10Client({\n network: 'testnet',\n operatorId: result.metadata.accountId,\n operatorPrivateKey: result.metadata.privateKey,\n guardedRegistryBaseUrl: process.env.REGISTRY_URL,\n prettyPrint: true,\n logLevel: 'debug',\n });\n\n return {\n accountId: result.metadata.accountId,\n operatorId: `${result.metadata.inboundTopicId}@${result.metadata.accountId}`,\n inboundTopicId: result.metadata.inboundTopicId,\n outboundTopicId: result.metadata.outboundTopicId,\n client,\n };\n } catch (error) {\n console.log('error', error, baseClient);\n logger.error(`Error creating ${agentName} agent:`, error);\n return null;\n }\n}\n\nexport async function updateEnvFile(\n envFilePath: string,\n variables: Record<string, string>\n): Promise<void> {\n let envContent = '';\n\n if (fs.existsSync(envFilePath)) {\n envContent = fs.readFileSync(envFilePath, 'utf8');\n }\n\n const envLines = envContent.split('\\n');\n const updatedLines = [...envLines];\n\n for (const [key, value] of Object.entries(variables)) {\n const lineIndex = updatedLines.findIndex((line) =>\n line.startsWith(`${key}=`)\n );\n\n if (lineIndex !== -1) {\n updatedLines[lineIndex] = `${key}=${value}`;\n } else {\n updatedLines.push(`${key}=${value}`);\n }\n }\n\n fs.writeFileSync(envFilePath, updatedLines.join('\\n'));\n}\n"],"names":["path","fs"],"mappings":";;;AASO,MAAM,gBAAgBA,cAAK,KAAK,QAAQ,OAAO,MAAM;AA4HtC,eAAA,cACpB,aACA,WACe;AACf,MAAI,aAAa;AAEb,MAAAC,YAAG,WAAW,WAAW,GAAG;AACjB,iBAAAA,YAAG,aAAa,aAAa,MAAM;AAAA,EAAA;AAG5C,QAAA,WAAW,WAAW,MAAM,IAAI;AAChC,QAAA,eAAe,CAAC,GAAG,QAAQ;AAEjC,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,SAAS,GAAG;AACpD,UAAM,YAAY,aAAa;AAAA,MAAU,CAAC,SACxC,KAAK,WAAW,GAAG,GAAG,GAAG;AAAA,IAC3B;AAEA,QAAI,cAAc,IAAI;AACpB,mBAAa,SAAS,IAAI,GAAG,GAAG,IAAI,KAAK;AAAA,IAAA,OACpC;AACL,mBAAa,KAAK,GAAG,GAAG,IAAI,KAAK,EAAE;AAAA,IAAA;AAAA,EACrC;AAGFA,cAAG,cAAc,aAAa,aAAa,KAAK,IAAI,CAAC;AACvD;"}
|