UNPKG

@hashgraphonline/standards-agent-kit

Version:

A modular SDK for building on-chain autonomous agents using Hashgraph Online Standards, including HCS-10 for agent discovery and communication.

125 lines (124 loc) 4.64 kB
import { HCS10Client } from "./standards-agent-kit.es2.js"; import { RegisterAgentTool } from "./standards-agent-kit.es3.js"; import { SendMessageTool } from "./standards-agent-kit.es4.js"; import { ConnectionTool } from "./standards-agent-kit.es5.js"; import { OpenConvaiState } from "./standards-agent-kit.es16.js"; import { FindRegistrationsTool } from "./standards-agent-kit.es10.js"; import { InitiateConnectionTool } from "./standards-agent-kit.es7.js"; import { ListConnectionsTool } from "./standards-agent-kit.es8.js"; import { SendMessageToConnectionTool } from "./standards-agent-kit.es6.js"; import { CheckMessagesTool } from "./standards-agent-kit.es9.js"; import { ConnectionMonitorTool } from "./standards-agent-kit.es11.js"; import { ManageConnectionRequestsTool } from "./standards-agent-kit.es12.js"; import { AcceptConnectionRequestTool } from "./standards-agent-kit.es13.js"; import { RetrieveProfileTool } from "./standards-agent-kit.es14.js"; import { ListUnapprovedConnectionRequestsTool } from "./standards-agent-kit.es15.js"; import { Logger } from "@hashgraphonline/standards-sdk"; import { ENV_FILE_PATH } from "./standards-agent-kit.es27.js"; const initializeStandardsAgentKit = (options) => { const config = options?.clientConfig || {}; const operatorId = config.operatorId || process.env.HEDERA_OPERATOR_ID; const operatorPrivateKey = config.operatorKey || process.env.HEDERA_OPERATOR_KEY; const networkEnv = config.network || process.env.HEDERA_NETWORK || "testnet"; let network; if (networkEnv === "mainnet") { network = "mainnet"; } else if (networkEnv === "testnet") { network = "testnet"; } else { console.warn( `Unsupported network specified: '${networkEnv}'. Defaulting to 'testnet'.` ); network = "testnet"; } if (!operatorId || !operatorPrivateKey) { throw new Error( "Operator ID and private key must be provided either through options or environment variables." ); } const shouldSilence = process.env.DISABLE_LOGGING === "true"; const logger = Logger.getInstance({ level: config.logLevel || "info", silent: shouldSilence }); const stateManager = options?.stateManager || new OpenConvaiState({ defaultEnvFilePath: ENV_FILE_PATH, defaultPrefix: "TODD" }); logger.info("State manager initialized"); const hcs10Client = new HCS10Client(operatorId, operatorPrivateKey, network, { useEncryption: config.useEncryption, registryUrl: config.registryUrl }); logger.info(`HCS10Client initialized for ${operatorId} on ${network}`); let monitoringClient; if (options?.monitoringClient) { monitoringClient = new HCS10Client( operatorId, operatorPrivateKey, network, { useEncryption: config.useEncryption, registryUrl: config.registryUrl, logLevel: "error" } ); logger.info("Monitoring client initialized"); } const tools = {}; tools.registerAgentTool = new RegisterAgentTool(hcs10Client, stateManager); tools.sendMessageTool = new SendMessageTool(hcs10Client); tools.connectionTool = new ConnectionTool({ client: monitoringClient || hcs10Client, stateManager }); if (options?.createAllTools) { tools.findRegistrationsTool = new FindRegistrationsTool({ hcsClient: hcs10Client }); tools.retrieveProfileTool = new RetrieveProfileTool(hcs10Client); tools.initiateConnectionTool = new InitiateConnectionTool({ hcsClient: hcs10Client, stateManager }); tools.listConnectionsTool = new ListConnectionsTool({ hcsClient: hcs10Client, stateManager }); tools.sendMessageToConnectionTool = new SendMessageToConnectionTool({ hcsClient: hcs10Client, stateManager }); tools.checkMessagesTool = new CheckMessagesTool({ hcsClient: hcs10Client, stateManager }); tools.connectionMonitorTool = new ConnectionMonitorTool({ hcsClient: monitoringClient || hcs10Client, stateManager }); tools.manageConnectionRequestsTool = new ManageConnectionRequestsTool({ hcsClient: hcs10Client, stateManager }); tools.acceptConnectionRequestTool = new AcceptConnectionRequestTool({ hcsClient: hcs10Client, stateManager }); tools.listUnapprovedConnectionRequestsTool = new ListUnapprovedConnectionRequestsTool({ stateManager, hcsClient: hcs10Client }); logger.info("All tools initialized"); } return { hcs10Client, monitoringClient, tools, stateManager }; }; export { initializeStandardsAgentKit }; //# sourceMappingURL=standards-agent-kit.es17.js.map