@hashgraphonline/standards-agent-plugin
Version:
Standards agent plugin for OpenConvAI functionality with HCS-10 tools
3 lines (2 loc) • 4.94 kB
JavaScript
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("hedera-agent-kit"),t=require("@hashgraphonline/standards-agent-kit"),n=require("@hashgraphonline/standards-sdk"),i=require("@hashgraph/sdk");class o extends e.BasePlugin{constructor(){super(...arguments),this.id="openconvai-standards-agent-kit",this.name="OpenConvAI Standards Agent Kit Plugin",this.description="Comprehensive plugin providing all HCS-10 agent tools for registration, connections, and messaging",this.version="1.0.0",this.author="Hashgraph Online",this.namespace="openconvai",this.tools=[]}async initialize(e){await super.initialize(e);if(e.config.hederaKit)try{this.stateManager=e.stateManager||new t.OpenConvaiState,this.initializeTools(),this.context.logger.info("OpenConvAI Standards Agent Kit Plugin initialized successfully")}catch(n){this.context.logger.error("Failed to initialize OpenConvAI plugin:",n)}else this.context.logger.warn("HederaKit not found in context. OpenConvAI tools will not be available.")}initializeTools(){if(!this.stateManager)throw new Error("StateManager must be initialized before creating tools");const e=this.context.config.hederaKit;if(!e)throw new Error("HederaKit not found in context config");const n=new t.HCS10Builder(e,this.stateManager);this.tools=[new t.RegisterAgentTool({hederaKit:e,hcs10Builder:n,logger:this.context.logger}),new t.FindRegistrationsTool({hederaKit:e,hcs10Builder:n,logger:this.context.logger}),new t.RetrieveProfileTool({hederaKit:e,hcs10Builder:n,logger:this.context.logger}),new t.InitiateConnectionTool({hederaKit:e,hcs10Builder:n,logger:this.context.logger}),new t.ListConnectionsTool({hederaKit:e,hcs10Builder:n,logger:this.context.logger}),new t.SendMessageToConnectionTool({hederaKit:e,hcs10Builder:n,logger:this.context.logger}),new t.CheckMessagesTool({hederaKit:e,hcs10Builder:n,logger:this.context.logger}),new t.ConnectionMonitorTool({hederaKit:e,hcs10Builder:n,logger:this.context.logger}),new t.ManageConnectionRequestsTool({hederaKit:e,hcs10Builder:n,logger:this.context.logger}),new t.AcceptConnectionRequestTool({hederaKit:e,hcs10Builder:n,logger:this.context.logger}),new t.ListUnapprovedConnectionRequestsTool({hederaKit:e,hcs10Builder:n,logger:this.context.logger})]}getTools(){return this.tools}getStateManager(){return this.stateManager}async cleanup(){this.tools=[],delete this.stateManager,this.context?.logger&&this.context.logger.info("OpenConvAI Standards Agent Kit Plugin cleaned up")}}exports.OpenConvAIPlugin=o,exports.StandardsKit=class{constructor(e){this.options=e,this.stateManager=e.stateManager||new t.OpenConvaiState,this.plugin=new o,this.logger=new n.Logger({module:"StandardsKit"})}async initialize(){const{accountId:t,privateKey:o,network:s="testnet",openAIApiKey:r,openAIModelName:a="gpt-4o",verbose:g=!1,operationalMode:l="autonomous",userAccountId:c,customSystemMessagePreamble:d,customSystemMessagePostamble:h,additionalPlugins:u=[],scheduleUserTransactionsInBytesMode:p,mirrorNodeConfig:v,disableLogging:w}=this.options;if(!t||!o)throw new Error("Account ID and private key are required");try{const m=new n.HederaMirrorNode(s,this.logger),M=await m.requestAccount(t),f=M?.key?._type||"";let A;A=f?.toLowerCase()?.includes("ecdsa")?i.PrivateKey.fromStringECDSA(o):i.PrivateKey.fromStringED25519(o);const C=new e.ServerSigner(t,A,s),K=`You are a helpful assistant managing Hedera HCS-10 connections and messages.\nYou have access to tools for registering agents, finding registered agents, initiating connections, listing active connections, sending messages over connections, and checking for new messages.\n\n*** IMPORTANT CONTEXT ***\nYou are currently operating as agent: ${t}\nWhen users ask about "my profile", "my account", "my connections", etc., use this account ID: ${t}\n\nRemember the connection numbers when listing connections, as users might refer to them.`,S={pluginConfig:{plugins:[this.plugin,...u,...e.getAllHederaCorePlugins()],appConfig:{stateManager:this.stateManager}},openAIApiKey:r,openAIModelName:a,verbose:g,operationalMode:l,userAccountId:c,customSystemMessagePreamble:d||K,...void 0!==h&&{customSystemMessagePostamble:h},...void 0!==p&&{scheduleUserTransactionsInBytesMode:p},...void 0!==v&&{mirrorNodeConfig:v},...void 0!==w&&{disableLogging:w}};this.conversationalAgent=new e.HederaConversationalAgent(C,S),await this.conversationalAgent.initialize()}catch(m){throw this.logger.error("Failed to initialize StandardsKit:",m),m}}getPlugin(){return this.plugin}getStateManager(){return this.stateManager}getConversationalAgent(){if(!this.conversationalAgent)throw new Error("StandardsKit not initialized. Call initialize() first.");return this.conversationalAgent}async processMessage(e,t=[]){if(!this.conversationalAgent)throw new Error("StandardsKit not initialized. Call initialize() first.");return this.conversationalAgent.processMessage(e,t)}};
//# sourceMappingURL=index.cjs.map