@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 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-agent-kit.es16.js","sources":["../../src/tools/ListUnapprovedConnectionRequestsTool.ts"],"sourcesContent":["import { StructuredTool, ToolParams } from '@langchain/core/tools';\nimport { z } from 'zod';\nimport {\n IStateManager,\n} from '../state/state-types';\nimport { HCS10Client } from '../hcs10/HCS10Client';\nimport {\n Logger,\n Connection,\n} from '@hashgraphonline/standards-sdk';\n\n\ntype ListPendingRequestsToolParams = ToolParams & {\n hcsClient: HCS10Client;\n stateManager: IStateManager;\n};\n\nexport class ListUnapprovedConnectionRequestsTool extends StructuredTool {\n name = 'list_unapproved_connection_requests';\n description =\n 'Lists all connection requests that are not fully established, including incoming requests needing approval and outgoing requests waiting for confirmation.';\n schema = z.object({\n sortBy: z\n .enum(['time_asc', 'time_desc', 'name_asc', 'name_desc'])\n .optional()\n .describe(\n 'Optional sorting criteria for the requests list (default: time_desc, newest first)'\n ),\n limit: z\n .number()\n .optional()\n .describe(\n 'Optional limit on the number of requests to return (default: all)'\n ),\n });\n\n private hcsClient: HCS10Client;\n private stateManager: IStateManager;\n private logger: Logger;\n\n constructor({\n hcsClient,\n stateManager,\n ...rest\n }: ListPendingRequestsToolParams) {\n super(rest);\n this.hcsClient = hcsClient;\n this.stateManager = stateManager;\n this.logger = Logger.getInstance({\n module: 'ListPendingRequestsTool',\n level: 'debug',\n });\n }\n\n protected async _call({\n sortBy = 'time_desc',\n limit,\n }: z.infer<this['schema']>): Promise<string> {\n const currentAgent = this.stateManager.getCurrentAgent();\n if (!currentAgent) {\n return 'Error: Cannot list pending requests. No agent is currently active. Please register or select an agent first.';\n }\n\n try {\n const pendingRequests = await this.findAllPendingRequests();\n return this.formatRequestsList(pendingRequests, sortBy, limit);\n } catch (error) {\n this.logger.error(`Error in ${this.name}: ${error}`);\n return `Error listing pending requests: ${\n error instanceof Error ? error.message : String(error)\n }`;\n }\n }\n\n /**\n * Processes the connection connectionMap to find all requests\n * that are not fully established (incoming unapproved and outgoing pending).\n */\n private async findAllPendingRequests(): Promise<Connection[]> {\n const connectionsManager = this.stateManager.getConnectionsManager();\n if (!connectionsManager) {\n return [];\n }\n const currentAgent = this.stateManager.getCurrentAgent();\n if (!currentAgent) {\n return [];\n }\n\n await connectionsManager.fetchConnectionData(currentAgent.accountId);\n const pendingRequests = connectionsManager.getPendingRequests();\n const connectionsNeedingConfirmation = connectionsManager.getConnectionsNeedingConfirmation();\n\n return [...pendingRequests, ...connectionsNeedingConfirmation];\n }\n\n /**\n * Formats the list of pending requests for display.\n */\n private formatRequestsList(\n requests: Connection[],\n sortBy: string,\n limit?: number\n ): string {\n if (requests.length === 0) {\n return 'No pending connection requests found (incoming or outgoing).';\n }\n\n const sortedRequests = this.sortRequests(requests, sortBy);\n const limitedRequests = limit\n ? sortedRequests.slice(0, limit)\n : sortedRequests;\n\n let output = `Found ${requests.length} pending connection request(s):\\n\\n`;\n\n limitedRequests.forEach((request, index) => {\n const statusIndicator =\n request.status === 'needs_confirmation'\n ? '🟠 Incoming'\n : '⚪️ Outgoing';\n output += `${index + 1}. ${statusIndicator} - ID: ${request.uniqueRequestKey}\\n`;\n output += ` ${\n request.status === 'needs_confirmation' ? 'From:' : 'To: '\n } ${request.targetAgentName} (${request.targetAccountId})\\n`;\n output += ` Sent/Rcvd: ${request.created.toLocaleString()}\\n`;\n if (request.memo) {\n output += ` Memo: ${request.memo}\\n`;\n }\n if (request.profileInfo?.bio) {\n output += ` Bio: ${request.profileInfo.bio.substring(0, 100)}${\n request.profileInfo.bio.length > 100 ? '...' : ''\n }\\n`;\n }\n output += '\\n';\n });\n\n output +=\n 'Use related tools (manage_requests, accept_request) to handle these items.';\n return output;\n }\n\n /**\n * Sorts connection requests based on the specified criteria.\n */\n private sortRequests(\n requests: Connection[],\n sortBy: string\n ): Connection[] {\n const requestsCopy = [...requests];\n\n switch (sortBy) {\n case 'time_asc':\n return requestsCopy.sort(\n (a, b) => a.created.getTime() - b.created.getTime()\n );\n case 'time_desc':\n return requestsCopy.sort(\n (a, b) => b.created.getTime() - a.created.getTime()\n );\n case 'name_asc':\n return requestsCopy.sort((a, b) =>\n a.targetAgentName?.localeCompare(b?.targetAgentName || '') || 0\n );\n case 'name_desc':\n return requestsCopy.sort((a, b) =>\n b.targetAgentName?.localeCompare(a?.targetAgentName || '') || 0\n );\n default:\n return requestsCopy.sort(\n (a, b) => b.created.getTime() - a.created.getTime()\n );\n }\n }\n}\n"],"names":[],"mappings":";;;AAiBO,MAAM,6CAA6C,eAAe;AAAA,EAuBvE,YAAY;AAAA,IACV;AAAA,IACA;AAAA,IACA,GAAG;AAAA,EAAA,GAC6B;AAChC,UAAM,IAAI;AA3BL,SAAA,OAAA;AAEL,SAAA,cAAA;AACF,SAAA,SAAS,EAAE,OAAO;AAAA,MAChB,QAAQ,EACL,KAAK,CAAC,YAAY,aAAa,YAAY,WAAW,CAAC,EACvD,SAAA,EACA;AAAA,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AE,iBAAiB,cAAc,GAAG,mBAAmB,EAAE,KAAK;AAAA,QAChE;AAAA,MACF;AACE,eAAO,aAAa;AAAA,UAClB,CAAC,GAAG,MAAM,EAAE,QAAQ,YAAY,EAAE,QAAQ,QAAQ;AAAA,QACpD;AAAA,IAAA;AAAA,EACJ;AAEJ;"}
|
|
1
|
+
{"version":3,"file":"standards-agent-kit.es16.js","sources":["../../src/state/open-convai-state.ts"],"sourcesContent":["import { updateEnvFile } from '../utils/state-tools';\nimport {\n RegisteredAgent,\n ActiveConnection,\n IStateManager,\n AgentPersistenceOptions,\n EnvFilePersistenceOptions,\n ConnectionStatus,\n} from './state-types';\nimport {\n ConnectionsManager,\n HCS10BaseClient,\n Connection,\n Logger,\n IConnectionsManager,\n} from '@hashgraphonline/standards-sdk';\n\n/**\n * Implementation of the IStateManager interface for the OpenConvai system.\n * Manages agent state and connection information with thread safety and\n * proper timestamp tracking.\n */\nexport class OpenConvaiState implements IStateManager {\n private currentAgent: RegisteredAgent | null = null;\n private connectionMessageTimestamps: Record<string, number> = {};\n private defaultEnvFilePath?: string;\n private defaultPrefix: string;\n private connectionsManager: IConnectionsManager | null = null;\n private logger: Logger;\n\n /**\n * Creates a new OpenConvaiState instance\n * @param options - Options for environment variable persistence\n */\n constructor(options?: {\n defaultEnvFilePath?: string;\n defaultPrefix?: string;\n baseClient?: HCS10BaseClient;\n disableLogging?: boolean;\n }) {\n this.defaultEnvFilePath = options?.defaultEnvFilePath;\n this.defaultPrefix = options?.defaultPrefix ?? 'TODD';\n const shouldSilence = options?.disableLogging || process.env.DISABLE_LOGGING === 'true';\n this.logger = new Logger({ module: 'OpenConvaiState', silent: shouldSilence });\n\n // Initialize ConnectionsManager immediately if baseClient is provided\n if (options?.baseClient) {\n this.initializeConnectionsManager(options.baseClient);\n }\n }\n\n /**\n * Initializes the ConnectionsManager\n * @param baseClient - HCS10BaseClient instance to use\n */\n initializeConnectionsManager(\n baseClient: HCS10BaseClient\n ): IConnectionsManager {\n if (!this.connectionsManager) {\n this.logger.debug('Initializing ConnectionsManager');\n this.connectionsManager = new ConnectionsManager({\n baseClient,\n logLevel: 'error',\n });\n } else {\n this.logger.debug('ConnectionsManager already initialized');\n }\n return this.connectionsManager;\n }\n\n /**\n * Gets the ConnectionsManager instance\n * @returns The ConnectionsManager instance, or null if not initialized\n */\n getConnectionsManager(): IConnectionsManager | null {\n return this.connectionsManager;\n }\n\n /**\n * Sets the current active agent and clears any previous connection data.\n * This should be called when switching between agents.\n */\n setCurrentAgent(agent: RegisteredAgent | null): void {\n this.currentAgent = agent;\n this.connectionMessageTimestamps = {};\n\n // Clear connections manager when changing agents\n if (this.connectionsManager) {\n this.connectionsManager.clearAll();\n }\n }\n\n /**\n * Returns the currently active agent or null if none is set.\n */\n getCurrentAgent(): RegisteredAgent | null {\n return this.currentAgent;\n }\n\n /**\n * Adds a new connection to the active connections list.\n * Ensures no duplicates are added based on connectionTopicId.\n * Initializes timestamp tracking for the connection.\n */\n addActiveConnection(connection: ActiveConnection): void {\n if (!this.connectionsManager) {\n this.logger.error(\n 'ConnectionsManager not initialized. Call initializeConnectionsManager before adding connections.'\n );\n throw new Error(\n 'ConnectionsManager not initialized. Call initializeConnectionsManager before adding connections.'\n );\n }\n\n // Convert from ActiveConnection to Connection\n const sdkConnection: Connection = {\n connectionTopicId: connection.connectionTopicId,\n targetAccountId: connection.targetAccountId,\n targetAgentName: connection.targetAgentName,\n targetInboundTopicId: connection.targetInboundTopicId,\n status: this.convertConnectionStatus(connection.status || 'established'),\n isPending: connection.isPending || false,\n needsConfirmation: connection.needsConfirmation || false,\n created: connection.created || new Date(),\n lastActivity: connection.lastActivity,\n profileInfo: connection.profileInfo,\n connectionRequestId: connection.connectionRequestId,\n processed: true,\n };\n\n // Add to ConnectionsManager\n this.connectionsManager.updateOrAddConnection(sdkConnection);\n\n // Initialize timestamp tracking\n this.initializeTimestampIfNeeded(connection.connectionTopicId);\n }\n\n /**\n * Updates an existing connection or adds it if not found.\n * Preserves existing properties when updating by merging objects.\n */\n updateOrAddConnection(connection: ActiveConnection): void {\n this.addActiveConnection(connection);\n }\n\n /**\n * Returns a copy of all active connections.\n */\n listConnections(): ActiveConnection[] {\n if (!this.connectionsManager) {\n this.logger.debug(\n 'ConnectionsManager not initialized, returning empty connections list'\n );\n return [];\n }\n\n // Convert SDK Connections to ActiveConnection\n return this.connectionsManager\n .getAllConnections()\n .map((conn) => this.convertToActiveConnection(conn));\n }\n\n /**\n * Finds a connection by its identifier, which can be:\n * - A 1-based index as displayed in the connection list\n * - A target account ID string\n * - A connection topic ID string\n */\n getConnectionByIdentifier(identifier: string): ActiveConnection | undefined {\n if (!this.connectionsManager) {\n return undefined;\n }\n\n const connections = this.listConnections();\n\n // Check if it's a 1-based index\n const numericIndex = parseInt(identifier) - 1;\n if (\n !isNaN(numericIndex) &&\n numericIndex >= 0 &&\n numericIndex < connections.length\n ) {\n return connections[numericIndex];\n }\n\n // Check if it's a topic ID\n const byTopicId =\n this.connectionsManager.getConnectionByTopicId(identifier);\n if (byTopicId) {\n return this.convertToActiveConnection(byTopicId);\n }\n\n // Check if it's an account ID\n const byAccountId =\n this.connectionsManager.getConnectionByAccountId(identifier);\n if (byAccountId) {\n return this.convertToActiveConnection(byAccountId);\n }\n\n return undefined;\n }\n\n /**\n * Gets the last processed message timestamp for a connection.\n * Returns 0 if no timestamp has been recorded.\n */\n getLastTimestamp(connectionTopicId: string): number {\n return this.connectionMessageTimestamps[connectionTopicId] || 0;\n }\n\n /**\n * Updates the last processed message timestamp for a connection,\n * but only if the new timestamp is more recent than the existing one.\n */\n updateTimestamp(connectionTopicId: string, timestampNanos: number): void {\n // Initialize if this is first update and skip the comparison logic\n if (!(connectionTopicId in this.connectionMessageTimestamps)) {\n this.connectionMessageTimestamps[connectionTopicId] = timestampNanos;\n return;\n }\n\n // Otherwise, only update if newer\n const currentTimestamp =\n this.connectionMessageTimestamps[connectionTopicId];\n if (timestampNanos > currentTimestamp) {\n this.connectionMessageTimestamps[connectionTopicId] = timestampNanos;\n }\n }\n\n /**\n * Helper method to initialize timestamp tracking for a connection\n * if it doesn't already exist.\n */\n private initializeTimestampIfNeeded(connectionTopicId: string): void {\n if (!(connectionTopicId in this.connectionMessageTimestamps)) {\n this.connectionMessageTimestamps[connectionTopicId] =\n Date.now() * 1_000_000;\n }\n }\n\n /**\n * Converts ConnectionStatus to SDK status format\n */\n private convertConnectionStatus(\n status: string\n ): 'pending' | 'established' | 'needs_confirmation' | 'closed' {\n switch (status) {\n case 'pending':\n return 'pending';\n case 'established':\n return 'established';\n case 'needs confirmation':\n return 'needs_confirmation';\n default:\n return 'established';\n }\n }\n\n /**\n * Converts SDK Connection to ActiveConnection\n */\n private convertToActiveConnection(conn: Connection): ActiveConnection {\n return {\n targetAccountId: conn.targetAccountId,\n targetAgentName: conn.targetAgentName || `Agent ${conn.targetAccountId}`,\n targetInboundTopicId: conn.targetInboundTopicId || '',\n connectionTopicId: conn.connectionTopicId,\n status: this.convertToStateStatus(conn.status),\n created: conn.created,\n lastActivity: conn.lastActivity,\n isPending: conn.isPending,\n needsConfirmation: conn.needsConfirmation,\n profileInfo: conn.profileInfo,\n connectionRequestId: conn.connectionRequestId,\n };\n }\n\n /**\n * Converts SDK status to state status format\n */\n private convertToStateStatus(status: string): ConnectionStatus {\n switch (status) {\n case 'pending':\n return 'pending';\n case 'established':\n return 'established';\n case 'needs_confirmation':\n return 'needs confirmation';\n case 'closed':\n return 'established'; // Mapping closed to established for compatibility\n default:\n return 'unknown';\n }\n }\n\n /**\n * Persists agent data to environment variables\n * @param agent - The agent data to persist\n * @param options - Environment file persistence options\n */\n async persistAgentData(\n agent: RegisteredAgent,\n options?: AgentPersistenceOptions\n ): Promise<void> {\n if (options?.type && options.type !== 'env-file') {\n throw new Error(\n `Unsupported persistence type: ${options.type}. Only 'env-file' is supported.`\n );\n }\n\n const envFilePath =\n (options as EnvFilePersistenceOptions)?.envFilePath ||\n this.defaultEnvFilePath ||\n process.env.ENV_FILE_PATH ||\n '.env';\n\n if (!envFilePath) {\n throw new Error(\n 'Environment file path could not be determined for agent data persistence'\n );\n }\n\n const prefix =\n (options as EnvFilePersistenceOptions)?.prefix || this.defaultPrefix;\n\n if (!agent.accountId || !agent.inboundTopicId || !agent.outboundTopicId) {\n throw new Error('Agent data incomplete, cannot persist to environment');\n }\n\n const updates: Record<string, string> = {\n [`${prefix}_ACCOUNT_ID`]: agent.accountId,\n [`${prefix}_INBOUND_TOPIC_ID`]: agent.inboundTopicId,\n [`${prefix}_OUTBOUND_TOPIC_ID`]: agent.outboundTopicId,\n };\n\n if (agent.privateKey) {\n updates[`${prefix}_PRIVATE_KEY`] = agent.privateKey;\n }\n\n if (agent.profileTopicId) {\n updates[`${prefix}_PROFILE_TOPIC_ID`] = agent.profileTopicId;\n }\n\n await updateEnvFile(envFilePath, updates);\n }\n}\n"],"names":[],"mappings":";;AAsBO,MAAM,gBAAyC;AAAA;AAAA;AAAA;AAAA;AAAA,EAYpD,YAAY,SAKT;AAhBH,SAAQ,eAAuC;AAC/C,SAAQ,8BAAsD,CAAC;AAG/D,SAAQ,qBAAiD;AAavD,SAAK,qBAAqB,SAAS;AAC9B,SAAA,gBAAgB,SAAS,iBAAiB;AAC/C,UAAM,gBAAgB,SAAS,kBAAkB,QAAQ,IAAI,oBAAoB;AAC5E,SAAA,SAAS,IAAI,OAAO,EAAE,QAAQ,mBAAmB,QAAQ,eAAe;AAG7E,QAAI,SAAS,YAAY;AAClB,WAAA,6BAA6B,QAAQ,UAAU;AAAA,IAAA;AAAA,EACtD;AAAA;AAAA;AAAA;AAAA;AAAA,EAOF,6BACE,YACqB;AACjB,QAAA,CAAC,KAAK,oBAAoB;AACvB,WAAA,OAAO,MAAM,iCAAiC;AAC9C,WAAA,qBAAqB,IAAI,mBAAmB;AAAA,QAC/C;AAAA,QACA,UAAU;AAAA,MAAA,CACX;AAAA,IAAA,OACI;AACA,WAAA,OAAO,MAAM,wCAAwC;AAAA,IAAA;AAE5D,WAAO,KAAK;AAAA,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MAAM,aAAa,GAAG,MAAM;AAAA,MAChC,CAAC,GAAG,MAAM,mBAAmB,GAAG,MAAM;AAAA,MACtC,CAAC,GAAG,MAAM,oBAAoB,GAAG,MAAM;AAAA,IACzC;AAEA,QAAI,MAAM,YAAY;AACpB,cAAQ,GAAG,MAAM,cAAc,IAAI,MAAM;AAAA,IAAA;AAG3C,QAAI,MAAM,gBAAgB;AACxB,cAAQ,GAAG,MAAM,mBAAmB,IAAI,MAAM;AAAA,IAAA;AAG1C,UAAA,cAAc,aAAa,OAAO;AAAA,EAAA;AAE5C;"}
|
|
@@ -1,249 +1,124 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
1
|
+
import { HCS10Client } from "./standards-agent-kit.es2.js";
|
|
2
|
+
import { RegisterAgentTool } from "./standards-agent-kit.es3.js";
|
|
3
|
+
import { SendMessageTool } from "./standards-agent-kit.es4.js";
|
|
4
|
+
import { ConnectionTool } from "./standards-agent-kit.es5.js";
|
|
5
|
+
import { OpenConvaiState } from "./standards-agent-kit.es16.js";
|
|
6
|
+
import { FindRegistrationsTool } from "./standards-agent-kit.es10.js";
|
|
7
|
+
import { InitiateConnectionTool } from "./standards-agent-kit.es7.js";
|
|
8
|
+
import { ListConnectionsTool } from "./standards-agent-kit.es8.js";
|
|
9
|
+
import { SendMessageToConnectionTool } from "./standards-agent-kit.es6.js";
|
|
10
|
+
import { CheckMessagesTool } from "./standards-agent-kit.es9.js";
|
|
11
|
+
import { ConnectionMonitorTool } from "./standards-agent-kit.es11.js";
|
|
12
|
+
import { ManageConnectionRequestsTool } from "./standards-agent-kit.es12.js";
|
|
13
|
+
import { AcceptConnectionRequestTool } from "./standards-agent-kit.es13.js";
|
|
14
|
+
import { RetrieveProfileTool } from "./standards-agent-kit.es14.js";
|
|
15
|
+
import { ListUnapprovedConnectionRequestsTool } from "./standards-agent-kit.es15.js";
|
|
16
|
+
import { Logger } from "@hashgraphonline/standards-sdk";
|
|
17
|
+
import { ENV_FILE_PATH } from "./standards-agent-kit.es26.js";
|
|
18
|
+
const initializeStandardsAgentKit = (options) => {
|
|
19
|
+
const config = options?.clientConfig || {};
|
|
20
|
+
const operatorId = config.operatorId || process.env.HEDERA_OPERATOR_ID;
|
|
21
|
+
const operatorPrivateKey = config.operatorKey || process.env.HEDERA_OPERATOR_KEY;
|
|
22
|
+
const networkEnv = config.network || process.env.HEDERA_NETWORK || "testnet";
|
|
23
|
+
let network;
|
|
24
|
+
if (networkEnv === "mainnet") {
|
|
25
|
+
network = "mainnet";
|
|
26
|
+
} else if (networkEnv === "testnet") {
|
|
27
|
+
network = "testnet";
|
|
28
|
+
} else {
|
|
29
|
+
console.warn(
|
|
30
|
+
`Unsupported network specified: '${networkEnv}'. Defaulting to 'testnet'.`
|
|
31
|
+
);
|
|
32
|
+
network = "testnet";
|
|
33
|
+
}
|
|
34
|
+
if (!operatorId || !operatorPrivateKey) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
"Operator ID and private key must be provided either through options or environment variables."
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
const shouldSilence = process.env.DISABLE_LOGGING === "true";
|
|
40
|
+
const logger = Logger.getInstance({
|
|
41
|
+
level: config.logLevel || "info",
|
|
42
|
+
silent: shouldSilence
|
|
43
|
+
});
|
|
44
|
+
const stateManager = options?.stateManager || new OpenConvaiState({
|
|
45
|
+
defaultEnvFilePath: ENV_FILE_PATH,
|
|
46
|
+
defaultPrefix: "TODD"
|
|
47
|
+
});
|
|
48
|
+
logger.info("State manager initialized");
|
|
49
|
+
const hcs10Client = new HCS10Client(operatorId, operatorPrivateKey, network, {
|
|
50
|
+
useEncryption: config.useEncryption,
|
|
51
|
+
registryUrl: config.registryUrl
|
|
52
|
+
});
|
|
53
|
+
logger.info(`HCS10Client initialized for ${operatorId} on ${network}`);
|
|
54
|
+
let monitoringClient;
|
|
55
|
+
if (options?.monitoringClient) {
|
|
56
|
+
monitoringClient = new HCS10Client(
|
|
57
|
+
operatorId,
|
|
58
|
+
operatorPrivateKey,
|
|
59
|
+
network,
|
|
60
|
+
{
|
|
61
|
+
useEncryption: config.useEncryption,
|
|
62
|
+
registryUrl: config.registryUrl,
|
|
29
63
|
logLevel: "error"
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
};
|
|
88
|
-
this.connectionsManager.updateOrAddConnection(sdkConnection);
|
|
89
|
-
this.initializeTimestampIfNeeded(connection.connectionTopicId);
|
|
90
|
-
}
|
|
91
|
-
/**
|
|
92
|
-
* Updates an existing connection or adds it if not found.
|
|
93
|
-
* Preserves existing properties when updating by merging objects.
|
|
94
|
-
*/
|
|
95
|
-
updateOrAddConnection(connection) {
|
|
96
|
-
this.addActiveConnection(connection);
|
|
97
|
-
}
|
|
98
|
-
/**
|
|
99
|
-
* Returns a copy of all active connections.
|
|
100
|
-
*/
|
|
101
|
-
listConnections() {
|
|
102
|
-
if (!this.connectionsManager) {
|
|
103
|
-
this.logger.debug(
|
|
104
|
-
"ConnectionsManager not initialized, returning empty connections list"
|
|
105
|
-
);
|
|
106
|
-
return [];
|
|
107
|
-
}
|
|
108
|
-
return this.connectionsManager.getAllConnections().map((conn) => this.convertToActiveConnection(conn));
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Finds a connection by its identifier, which can be:
|
|
112
|
-
* - A 1-based index as displayed in the connection list
|
|
113
|
-
* - A target account ID string
|
|
114
|
-
* - A connection topic ID string
|
|
115
|
-
*/
|
|
116
|
-
getConnectionByIdentifier(identifier) {
|
|
117
|
-
if (!this.connectionsManager) {
|
|
118
|
-
return void 0;
|
|
119
|
-
}
|
|
120
|
-
const connections = this.listConnections();
|
|
121
|
-
const numericIndex = parseInt(identifier) - 1;
|
|
122
|
-
if (!isNaN(numericIndex) && numericIndex >= 0 && numericIndex < connections.length) {
|
|
123
|
-
return connections[numericIndex];
|
|
124
|
-
}
|
|
125
|
-
const byTopicId = this.connectionsManager.getConnectionByTopicId(identifier);
|
|
126
|
-
if (byTopicId) {
|
|
127
|
-
return this.convertToActiveConnection(byTopicId);
|
|
128
|
-
}
|
|
129
|
-
const byAccountId = this.connectionsManager.getConnectionByAccountId(identifier);
|
|
130
|
-
if (byAccountId) {
|
|
131
|
-
return this.convertToActiveConnection(byAccountId);
|
|
132
|
-
}
|
|
133
|
-
return void 0;
|
|
134
|
-
}
|
|
135
|
-
/**
|
|
136
|
-
* Gets the last processed message timestamp for a connection.
|
|
137
|
-
* Returns 0 if no timestamp has been recorded.
|
|
138
|
-
*/
|
|
139
|
-
getLastTimestamp(connectionTopicId) {
|
|
140
|
-
return this.connectionMessageTimestamps[connectionTopicId] || 0;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Updates the last processed message timestamp for a connection,
|
|
144
|
-
* but only if the new timestamp is more recent than the existing one.
|
|
145
|
-
*/
|
|
146
|
-
updateTimestamp(connectionTopicId, timestampNanos) {
|
|
147
|
-
if (!(connectionTopicId in this.connectionMessageTimestamps)) {
|
|
148
|
-
this.connectionMessageTimestamps[connectionTopicId] = timestampNanos;
|
|
149
|
-
return;
|
|
150
|
-
}
|
|
151
|
-
const currentTimestamp = this.connectionMessageTimestamps[connectionTopicId];
|
|
152
|
-
if (timestampNanos > currentTimestamp) {
|
|
153
|
-
this.connectionMessageTimestamps[connectionTopicId] = timestampNanos;
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
/**
|
|
157
|
-
* Helper method to initialize timestamp tracking for a connection
|
|
158
|
-
* if it doesn't already exist.
|
|
159
|
-
*/
|
|
160
|
-
initializeTimestampIfNeeded(connectionTopicId) {
|
|
161
|
-
if (!(connectionTopicId in this.connectionMessageTimestamps)) {
|
|
162
|
-
this.connectionMessageTimestamps[connectionTopicId] = Date.now() * 1e6;
|
|
163
|
-
}
|
|
164
|
-
}
|
|
165
|
-
/**
|
|
166
|
-
* Converts ConnectionStatus to SDK status format
|
|
167
|
-
*/
|
|
168
|
-
convertConnectionStatus(status) {
|
|
169
|
-
switch (status) {
|
|
170
|
-
case "pending":
|
|
171
|
-
return "pending";
|
|
172
|
-
case "established":
|
|
173
|
-
return "established";
|
|
174
|
-
case "needs confirmation":
|
|
175
|
-
return "needs_confirmation";
|
|
176
|
-
default:
|
|
177
|
-
return "established";
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
/**
|
|
181
|
-
* Converts SDK Connection to ActiveConnection
|
|
182
|
-
*/
|
|
183
|
-
convertToActiveConnection(conn) {
|
|
184
|
-
return {
|
|
185
|
-
targetAccountId: conn.targetAccountId,
|
|
186
|
-
targetAgentName: conn.targetAgentName || `Agent ${conn.targetAccountId}`,
|
|
187
|
-
targetInboundTopicId: conn.targetInboundTopicId || "",
|
|
188
|
-
connectionTopicId: conn.connectionTopicId,
|
|
189
|
-
status: this.convertToStateStatus(conn.status),
|
|
190
|
-
created: conn.created,
|
|
191
|
-
lastActivity: conn.lastActivity,
|
|
192
|
-
isPending: conn.isPending,
|
|
193
|
-
needsConfirmation: conn.needsConfirmation,
|
|
194
|
-
profileInfo: conn.profileInfo,
|
|
195
|
-
connectionRequestId: conn.connectionRequestId
|
|
196
|
-
};
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Converts SDK status to state status format
|
|
200
|
-
*/
|
|
201
|
-
convertToStateStatus(status) {
|
|
202
|
-
switch (status) {
|
|
203
|
-
case "pending":
|
|
204
|
-
return "pending";
|
|
205
|
-
case "established":
|
|
206
|
-
return "established";
|
|
207
|
-
case "needs_confirmation":
|
|
208
|
-
return "needs confirmation";
|
|
209
|
-
case "closed":
|
|
210
|
-
return "established";
|
|
211
|
-
// Mapping closed to established for compatibility
|
|
212
|
-
default:
|
|
213
|
-
return "unknown";
|
|
214
|
-
}
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Persists agent data to environment variables
|
|
218
|
-
* @param agent - The agent data to persist
|
|
219
|
-
* @param options - Environment file persistence options
|
|
220
|
-
*/
|
|
221
|
-
async persistAgentData(agent, options) {
|
|
222
|
-
if (options?.type && options.type !== "env-file") {
|
|
223
|
-
throw new Error(
|
|
224
|
-
`Unsupported persistence type: ${options.type}. Only 'env-file' is supported.`
|
|
225
|
-
);
|
|
226
|
-
}
|
|
227
|
-
const envFilePath = options?.envFilePath || this.defaultEnvFilePath || process.env.ENV_FILE_PATH || ".env";
|
|
228
|
-
const prefix = options?.prefix || this.defaultPrefix;
|
|
229
|
-
if (!agent.accountId || !agent.inboundTopicId || !agent.outboundTopicId) {
|
|
230
|
-
throw new Error("Agent data incomplete, cannot persist to environment");
|
|
231
|
-
}
|
|
232
|
-
const updates = {
|
|
233
|
-
[`${prefix}_ACCOUNT_ID`]: agent.accountId,
|
|
234
|
-
[`${prefix}_INBOUND_TOPIC_ID`]: agent.inboundTopicId,
|
|
235
|
-
[`${prefix}_OUTBOUND_TOPIC_ID`]: agent.outboundTopicId
|
|
236
|
-
};
|
|
237
|
-
if (agent.privateKey) {
|
|
238
|
-
updates[`${prefix}_PRIVATE_KEY`] = agent.privateKey;
|
|
239
|
-
}
|
|
240
|
-
if (agent.profileTopicId) {
|
|
241
|
-
updates[`${prefix}_PROFILE_TOPIC_ID`] = agent.profileTopicId;
|
|
242
|
-
}
|
|
243
|
-
await updateEnvFile(envFilePath, updates);
|
|
244
|
-
}
|
|
245
|
-
}
|
|
64
|
+
}
|
|
65
|
+
);
|
|
66
|
+
logger.info("Monitoring client initialized");
|
|
67
|
+
}
|
|
68
|
+
const tools = {};
|
|
69
|
+
tools.registerAgentTool = new RegisterAgentTool(hcs10Client, stateManager);
|
|
70
|
+
tools.sendMessageTool = new SendMessageTool(hcs10Client);
|
|
71
|
+
tools.connectionTool = new ConnectionTool({
|
|
72
|
+
client: monitoringClient || hcs10Client,
|
|
73
|
+
stateManager
|
|
74
|
+
});
|
|
75
|
+
if (options?.createAllTools) {
|
|
76
|
+
tools.findRegistrationsTool = new FindRegistrationsTool({
|
|
77
|
+
hcsClient: hcs10Client
|
|
78
|
+
});
|
|
79
|
+
tools.retrieveProfileTool = new RetrieveProfileTool(hcs10Client);
|
|
80
|
+
tools.initiateConnectionTool = new InitiateConnectionTool({
|
|
81
|
+
hcsClient: hcs10Client,
|
|
82
|
+
stateManager
|
|
83
|
+
});
|
|
84
|
+
tools.listConnectionsTool = new ListConnectionsTool({
|
|
85
|
+
hcsClient: hcs10Client,
|
|
86
|
+
stateManager
|
|
87
|
+
});
|
|
88
|
+
tools.sendMessageToConnectionTool = new SendMessageToConnectionTool({
|
|
89
|
+
hcsClient: hcs10Client,
|
|
90
|
+
stateManager
|
|
91
|
+
});
|
|
92
|
+
tools.checkMessagesTool = new CheckMessagesTool({
|
|
93
|
+
hcsClient: hcs10Client,
|
|
94
|
+
stateManager
|
|
95
|
+
});
|
|
96
|
+
tools.connectionMonitorTool = new ConnectionMonitorTool({
|
|
97
|
+
hcsClient: monitoringClient || hcs10Client,
|
|
98
|
+
stateManager
|
|
99
|
+
});
|
|
100
|
+
tools.manageConnectionRequestsTool = new ManageConnectionRequestsTool({
|
|
101
|
+
hcsClient: hcs10Client,
|
|
102
|
+
stateManager
|
|
103
|
+
});
|
|
104
|
+
tools.acceptConnectionRequestTool = new AcceptConnectionRequestTool({
|
|
105
|
+
hcsClient: hcs10Client,
|
|
106
|
+
stateManager
|
|
107
|
+
});
|
|
108
|
+
tools.listUnapprovedConnectionRequestsTool = new ListUnapprovedConnectionRequestsTool({
|
|
109
|
+
stateManager,
|
|
110
|
+
hcsClient: hcs10Client
|
|
111
|
+
});
|
|
112
|
+
logger.info("All tools initialized");
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
hcs10Client,
|
|
116
|
+
monitoringClient,
|
|
117
|
+
tools,
|
|
118
|
+
stateManager
|
|
119
|
+
};
|
|
120
|
+
};
|
|
246
121
|
export {
|
|
247
|
-
|
|
122
|
+
initializeStandardsAgentKit
|
|
248
123
|
};
|
|
249
124
|
//# sourceMappingURL=standards-agent-kit.es17.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"standards-agent-kit.es17.js","sources":["../../src/state/open-convai-state.ts"],"sourcesContent":["import { updateEnvFile } from '../utils/state-tools';\nimport {\n RegisteredAgent,\n ActiveConnection,\n IStateManager,\n AgentPersistenceOptions,\n EnvFilePersistenceOptions,\n ConnectionStatus,\n} from './state-types';\nimport {\n ConnectionsManager,\n HCS10BaseClient,\n Connection,\n Logger,\n IConnectionsManager,\n} from '@hashgraphonline/standards-sdk';\n\n/**\n * Implementation of the IStateManager interface for the OpenConvai system.\n * Manages agent state and connection information with thread safety and\n * proper timestamp tracking.\n */\nexport class OpenConvaiState implements IStateManager {\n private currentAgent: RegisteredAgent | null = null;\n private connectionMessageTimestamps: Record<string, number> = {};\n private defaultEnvFilePath?: string;\n private defaultPrefix: string;\n private connectionsManager: IConnectionsManager | null = null;\n private logger: Logger;\n\n /**\n * Creates a new OpenConvaiState instance\n * @param options - Options for environment variable persistence\n */\n constructor(options?: {\n defaultEnvFilePath?: string;\n defaultPrefix?: string;\n baseClient?: HCS10BaseClient;\n disableLogging?: boolean;\n }) {\n this.defaultEnvFilePath = options?.defaultEnvFilePath;\n this.defaultPrefix = options?.defaultPrefix ?? 'TODD';\n const shouldSilence = options?.disableLogging || process.env.DISABLE_LOGGING === 'true';\n this.logger = new Logger({ module: 'OpenConvaiState', silent: shouldSilence });\n\n // Initialize ConnectionsManager immediately if baseClient is provided\n if (options?.baseClient) {\n this.initializeConnectionsManager(options.baseClient);\n }\n }\n\n /**\n * Initializes the ConnectionsManager\n * @param baseClient - HCS10BaseClient instance to use\n */\n initializeConnectionsManager(\n baseClient: HCS10BaseClient\n ): IConnectionsManager {\n if (!this.connectionsManager) {\n this.logger.debug('Initializing ConnectionsManager');\n this.connectionsManager = new ConnectionsManager({\n baseClient,\n logLevel: 'error',\n });\n } else {\n this.logger.debug('ConnectionsManager already initialized');\n }\n return this.connectionsManager;\n }\n\n /**\n * Gets the ConnectionsManager instance\n * @returns The ConnectionsManager instance, or null if not initialized\n */\n getConnectionsManager(): IConnectionsManager | null {\n return this.connectionsManager;\n }\n\n /**\n * Sets the current active agent and clears any previous connection data.\n * This should be called when switching between agents.\n */\n setCurrentAgent(agent: RegisteredAgent | null): void {\n this.currentAgent = agent;\n this.connectionMessageTimestamps = {};\n\n // Clear connections manager when changing agents\n if (this.connectionsManager) {\n this.connectionsManager.clearAll();\n }\n }\n\n /**\n * Returns the currently active agent or null if none is set.\n */\n getCurrentAgent(): RegisteredAgent | null {\n return this.currentAgent;\n }\n\n /**\n * Adds a new connection to the active connections list.\n * Ensures no duplicates are added based on connectionTopicId.\n * Initializes timestamp tracking for the connection.\n */\n addActiveConnection(connection: ActiveConnection): void {\n if (!this.connectionsManager) {\n this.logger.error(\n 'ConnectionsManager not initialized. Call initializeConnectionsManager before adding connections.'\n );\n throw new Error(\n 'ConnectionsManager not initialized. Call initializeConnectionsManager before adding connections.'\n );\n }\n\n // Convert from ActiveConnection to Connection\n const sdkConnection: Connection = {\n connectionTopicId: connection.connectionTopicId,\n targetAccountId: connection.targetAccountId,\n targetAgentName: connection.targetAgentName,\n targetInboundTopicId: connection.targetInboundTopicId,\n status: this.convertConnectionStatus(connection.status || 'established'),\n isPending: connection.isPending || false,\n needsConfirmation: connection.needsConfirmation || false,\n created: connection.created || new Date(),\n lastActivity: connection.lastActivity,\n profileInfo: connection.profileInfo,\n connectionRequestId: connection.connectionRequestId,\n processed: true,\n };\n\n // Add to ConnectionsManager\n this.connectionsManager.updateOrAddConnection(sdkConnection);\n\n // Initialize timestamp tracking\n this.initializeTimestampIfNeeded(connection.connectionTopicId);\n }\n\n /**\n * Updates an existing connection or adds it if not found.\n * Preserves existing properties when updating by merging objects.\n */\n updateOrAddConnection(connection: ActiveConnection): void {\n this.addActiveConnection(connection);\n }\n\n /**\n * Returns a copy of all active connections.\n */\n listConnections(): ActiveConnection[] {\n if (!this.connectionsManager) {\n this.logger.debug(\n 'ConnectionsManager not initialized, returning empty connections list'\n );\n return [];\n }\n\n // Convert SDK Connections to ActiveConnection\n return this.connectionsManager\n .getAllConnections()\n .map((conn) => this.convertToActiveConnection(conn));\n }\n\n /**\n * Finds a connection by its identifier, which can be:\n * - A 1-based index as displayed in the connection list\n * - A target account ID string\n * - A connection topic ID string\n */\n getConnectionByIdentifier(identifier: string): ActiveConnection | undefined {\n if (!this.connectionsManager) {\n return undefined;\n }\n\n const connections = this.listConnections();\n\n // Check if it's a 1-based index\n const numericIndex = parseInt(identifier) - 1;\n if (\n !isNaN(numericIndex) &&\n numericIndex >= 0 &&\n numericIndex < connections.length\n ) {\n return connections[numericIndex];\n }\n\n // Check if it's a topic ID\n const byTopicId =\n this.connectionsManager.getConnectionByTopicId(identifier);\n if (byTopicId) {\n return this.convertToActiveConnection(byTopicId);\n }\n\n // Check if it's an account ID\n const byAccountId =\n this.connectionsManager.getConnectionByAccountId(identifier);\n if (byAccountId) {\n return this.convertToActiveConnection(byAccountId);\n }\n\n return undefined;\n }\n\n /**\n * Gets the last processed message timestamp for a connection.\n * Returns 0 if no timestamp has been recorded.\n */\n getLastTimestamp(connectionTopicId: string): number {\n return this.connectionMessageTimestamps[connectionTopicId] || 0;\n }\n\n /**\n * Updates the last processed message timestamp for a connection,\n * but only if the new timestamp is more recent than the existing one.\n */\n updateTimestamp(connectionTopicId: string, timestampNanos: number): void {\n // Initialize if this is first update and skip the comparison logic\n if (!(connectionTopicId in this.connectionMessageTimestamps)) {\n this.connectionMessageTimestamps[connectionTopicId] = timestampNanos;\n return;\n }\n\n // Otherwise, only update if newer\n const currentTimestamp =\n this.connectionMessageTimestamps[connectionTopicId];\n if (timestampNanos > currentTimestamp) {\n this.connectionMessageTimestamps[connectionTopicId] = timestampNanos;\n }\n }\n\n /**\n * Helper method to initialize timestamp tracking for a connection\n * if it doesn't already exist.\n */\n private initializeTimestampIfNeeded(connectionTopicId: string): void {\n if (!(connectionTopicId in this.connectionMessageTimestamps)) {\n this.connectionMessageTimestamps[connectionTopicId] =\n Date.now() * 1_000_000;\n }\n }\n\n /**\n * Converts ConnectionStatus to SDK status format\n */\n private convertConnectionStatus(\n status: string\n ): 'pending' | 'established' | 'needs_confirmation' | 'closed' {\n switch (status) {\n case 'pending':\n return 'pending';\n case 'established':\n return 'established';\n case 'needs confirmation':\n return 'needs_confirmation';\n default:\n return 'established';\n }\n }\n\n /**\n * Converts SDK Connection to ActiveConnection\n */\n private convertToActiveConnection(conn: Connection): ActiveConnection {\n return {\n targetAccountId: conn.targetAccountId,\n targetAgentName: conn.targetAgentName || `Agent ${conn.targetAccountId}`,\n targetInboundTopicId: conn.targetInboundTopicId || '',\n connectionTopicId: conn.connectionTopicId,\n status: this.convertToStateStatus(conn.status),\n created: conn.created,\n lastActivity: conn.lastActivity,\n isPending: conn.isPending,\n needsConfirmation: conn.needsConfirmation,\n profileInfo: conn.profileInfo,\n connectionRequestId: conn.connectionRequestId,\n };\n }\n\n /**\n * Converts SDK status to state status format\n */\n private convertToStateStatus(status: string): ConnectionStatus {\n switch (status) {\n case 'pending':\n return 'pending';\n case 'established':\n return 'established';\n case 'needs_confirmation':\n return 'needs confirmation';\n case 'closed':\n return 'established'; // Mapping closed to established for compatibility\n default:\n return 'unknown';\n }\n }\n\n /**\n * Persists agent data to environment variables\n * @param agent - The agent data to persist\n * @param options - Environment file persistence options\n */\n async persistAgentData(\n agent: RegisteredAgent,\n options?: AgentPersistenceOptions\n ): Promise<void> {\n if (options?.type && options.type !== 'env-file') {\n throw new Error(\n `Unsupported persistence type: ${options.type}. Only 'env-file' is supported.`\n );\n }\n\n const envFilePath =\n (options as EnvFilePersistenceOptions)?.envFilePath ||\n this.defaultEnvFilePath ||\n process.env.ENV_FILE_PATH ||\n '.env';\n\n if (!envFilePath) {\n throw new Error(\n 'Environment file path could not be determined for agent data persistence'\n );\n }\n\n const prefix =\n (options as EnvFilePersistenceOptions)?.prefix || this.defaultPrefix;\n\n if (!agent.accountId || !agent.inboundTopicId || !agent.outboundTopicId) {\n throw new Error('Agent data incomplete, cannot persist to environment');\n }\n\n const updates: Record<string, string> = {\n [`${prefix}_ACCOUNT_ID`]: agent.accountId,\n [`${prefix}_INBOUND_TOPIC_ID`]: agent.inboundTopicId,\n [`${prefix}_OUTBOUND_TOPIC_ID`]: agent.outboundTopicId,\n };\n\n if (agent.privateKey) {\n updates[`${prefix}_PRIVATE_KEY`] = agent.privateKey;\n }\n\n if (agent.profileTopicId) {\n updates[`${prefix}_PROFILE_TOPIC_ID`] = agent.profileTopicId;\n }\n\n await updateEnvFile(envFileP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AAK;AAAA,MAClB,qBAAqB,KAAK;AAAA,IAC5B;AAAA,EAAA;AAAA;AAAA;AAAA;AAAA,EAMM,qBAAqB,QAAkC;AAC7D,YAAQ,QAAQ;AAAA,MACd,KAAK;AACI,eAAA;AAAA,MACT,KAAK;AACI,eAAA;AAAA,MACT,KAAK;AACI,eAAA;AAAA,MACT,KAAK;AACI,eAAA;AAAA;AAAA,MACT;AACS,eAAA;AAAA,IAAA;AAAA,EACX;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAQF,MAAM,iBACJ,OACA,SACe;AACf,QAAI,SAAS,QAAQ,QAAQ,SAAS,YAAY;AAChD,YAAM,IAAI;AAAA,QACR,iCAAiC,QAAQ,IAAI;AAAA,MAC/C;AAAA,IAAA;AAGF,UAAM,cACH,SAAuC,eACxC,KAAK,sBACL,QAAQ,IAAI,iBACZ;AAQI,UAAA,SACH,SAAuC,UAAU,KAAK;AAErD,QAAA,CAAC,MAAM,aAAa,CAAC,MAAM,kBAAkB,CAAC,MAAM,iBAAiB;AACjE,YAAA,IAAI,MAAM,sDAAsD;AAAA,IAAA;AAGxE,UAAM,UAAkC;AAAA,MACtC,CAAC,GAAG,MAAM,aAAa,GAAG,MAAM;AAAA,MAChC,CAAC,GAAG,MAAM,mBAAmB,GAAG,MAAM;AAAA,MACtC,CAAC,GAAG,MAAM,oBAAoB,GAAG,MAAM;AAAA,IACzC;AAEA,QAAI,MAAM,YAAY;AACpB,cAAQ,GAAG,MAAM,cAAc,IAAI,MAAM;AAAA,IAAA;AAG3C,QAAI,MAAM,gBAAgB;AACxB,cAAQ,GAAG,MAAM,mBAAmB,IAAI,MAAM;AAAA,IAAA;AAG1C,UAAA,cAAc,aAAa,OAAO;AAAA,EAAA;AAE5C;"}
|
|
1
|
+
{"version":3,"file":"standards-agent-kit.es17.js","sources":["../../src/init/init.ts"],"sourcesContent":["import { HCS10Client, StandardNetworkType } from '../hcs10/HCS10Client';\nimport { RegisterAgentTool } from '../tools/RegisterAgentTool';\nimport { SendMessageTool } from '../tools/SendMessageTool';\nimport { ConnectionTool } from '../tools/ConnectionTool';\nimport { IStateManager } from '../state/state-types';\nimport { OpenConvaiState } from '../state/open-convai-state';\nimport { FindRegistrationsTool } from '../tools/FindRegistrationsTool';\nimport { InitiateConnectionTool } from '../tools/InitiateConnectionTool';\nimport { ListConnectionsTool } from '../tools/ListConnectionsTool';\nimport { SendMessageToConnectionTool } from '../tools/SendMessageToConnectionTool';\nimport { CheckMessagesTool } from '../tools/CheckMessagesTool';\nimport { ConnectionMonitorTool } from '../tools/ConnectionMonitorTool';\nimport { ManageConnectionRequestsTool } from '../tools/ManageConnectionRequestsTool';\nimport { AcceptConnectionRequestTool } from '../tools/AcceptConnectionRequestTool';\nimport { RetrieveProfileTool } from '../tools/RetrieveProfileTool';\nimport { ListUnapprovedConnectionRequestsTool } from '../tools/ListUnapprovedConnectionRequestsTool';\nimport { Logger } from '@hashgraphonline/standards-sdk';\nimport { ENV_FILE_PATH } from '../utils/state-tools';\n\nexport interface HCS10ClientConfig {\n operatorId?: string;\n operatorKey?: string;\n network?: StandardNetworkType;\n useEncryption?: boolean;\n registryUrl?: string;\n logLevel?: 'debug' | 'info' | 'warn' | 'error';\n}\n\nexport interface HCS10InitializationOptions {\n clientConfig?: HCS10ClientConfig;\n stateManager?: IStateManager;\n createAllTools?: boolean;\n monitoringClient?: boolean;\n}\n\n/**\n * Tool collection containing all available tools from the standards-agent-kit\n */\nexport interface HCS10Tools {\n registerAgentTool: RegisterAgentTool;\n findRegistrationsTool: FindRegistrationsTool;\n retrieveProfileTool: RetrieveProfileTool;\n initiateConnectionTool: InitiateConnectionTool;\n listConnectionsTool: ListConnectionsTool;\n sendMessageToConnectionTool: SendMessageToConnectionTool;\n checkMessagesTool: CheckMessagesTool;\n sendMessageTool: SendMessageTool;\n connectionTool: ConnectionTool;\n connectionMonitorTool: ConnectionMonitorTool;\n manageConnectionRequestsTool: ManageConnectionRequestsTool;\n acceptConnectionRequestTool: AcceptConnectionRequestTool;\n listUnapprovedConnectionRequestsTool: ListUnapprovedConnectionRequestsTool;\n}\n\n/**\n * Initializes the HCS10 client and returns pre-registered LangChain tools.\n *\n * @param options - Initialization options\n * @returns Object containing hcs10Client and requested tools\n */\nexport const initializeStandardsAgentKit = (\n options?: HCS10InitializationOptions\n): {\n hcs10Client: HCS10Client;\n monitoringClient?: HCS10Client;\n tools: Partial<HCS10Tools>;\n stateManager: IStateManager;\n} => {\n const config = options?.clientConfig || {};\n\n const operatorId = config.operatorId || process.env.HEDERA_OPERATOR_ID;\n const operatorPrivateKey =\n config.operatorKey || process.env.HEDERA_OPERATOR_KEY;\n\n const networkEnv = config.network || process.env.HEDERA_NETWORK || 'testnet';\n\n let network: StandardNetworkType;\n if (networkEnv === 'mainnet') {\n network = 'mainnet';\n } else if (networkEnv === 'testnet') {\n network = 'testnet';\n } else {\n console.warn(\n `Unsupported network specified: '${networkEnv}'. Defaulting to 'testnet'.`\n );\n network = 'testnet';\n }\n\n if (!operatorId || !operatorPrivateKey) {\n throw new Error(\n 'Operator ID and private key must be provided either through options or environment variables.'\n );\n }\n\n const shouldSilence = process.env.DISABLE_LOGGING === 'true';\n const logger = Logger.getInstance({\n level: config.logLevel || 'info',\n silent: shouldSilence,\n });\n\n const stateManager =\n options?.stateManager ||\n new OpenConvaiState({\n defaultEnvFilePath: ENV_FILE_PATH,\n defaultPrefix: 'TODD',\n });\n logger.info('State manager initialized');\n\n const hcs10Client = new HCS10Client(operatorId, operatorPrivateKey, network, {\n useEncryption: config.useEncryption,\n registryUrl: config.registryUrl,\n });\n logger.info(`HCS10Client initialized for ${operatorId} on ${network}`);\n\n let monitoringClient: HCS10Client | undefined;\n if (options?.monitoringClient) {\n monitoringClient = new HCS10Client(\n operatorId,\n operatorPrivateKey,\n network,\n {\n useEncryption: config.useEncryption,\n registryUrl: config.registryUrl,\n logLevel: 'error',\n }\n );\n logger.info('Monitoring client initialized');\n }\n\n const tools: Partial<HCS10Tools> = {};\n\n tools.registerAgentTool = new RegisterAgentTool(hcs10Client, stateManager);\n tools.sendMessageTool = new SendMessageTool(hcs10Client);\n tools.connectionTool = new ConnectionTool({\n client: monitoringClient || hcs10Client,\n stateManager,\n });\n\n if (options?.createAllTools) {\n tools.findRegistrationsTool = new FindRegistrationsTool({\n hcsClient: hcs10Client,\n });\n tools.retrieveProfileTool = new RetrieveProfileTool(hcs10Client);\n tools.initiateConnectionTool = new InitiateConnectionTool({\n hcsClient: hcs10Client,\n stateManager,\n });\n tools.listConnectionsTool = new ListConnectionsTool({\n hcsClient: hcs10Client,\n stateManager,\n });\n tools.sendMessageToConnectionTool = new SendMessageToConnectionTool({\n hcsClient: hcs10Client,\n stateManager,\n });\n tools.checkMessagesTool = new CheckMessagesTool({\n hcsClient: hcs10Client,\n stateManager,\n });\n tools.connectionMonitorTool = new ConnectionMonitorTool({\n hcsClient: monitoringClient || hcs10Client,\n stateManager,\n });\n tools.manageConnectionRequestsTool = new ManageConnectionRequestsTool({\n hcsClient: hcs10Client,\n stateManager,\n });\n tools.acceptConnectionRequestTool = new AcceptConnectionRequestTool({\n hcsClient: hcs10Client,\n stateManager,\n });\n tools.listUnapprovedConnectionRequestsTool =\n new ListUnapprovedConnectionRequestsTool({\n stateManager,\n hcsClient: hcs10Client,\n });\n\n logger.info('All tools initialized');\n }\n\n return {\n hcs10Client,\n monitoringClient,\n tools,\n stateManager,\n };\n};\n"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AA4Da,MAAA,8BAA8B,CACzC,YAMG;AACG,QAAA,SAAS,SAAS,gBAAgB,CAAC;AAEzC,QAAM,aAAa,OAAO,cAAc,QAAQ,IAAI;AACpD,QAAM,qBACJ,OAAO,eAAe,QAAQ,IAAI;AAEpC,QAAM,aAAa,OAAO,WAAW,QAAQ,IAAI,kBAAkB;AAE/D,MAAA;AACJ,MAAI,eAAe,WAAW;AAClB,cAAA;AAAA,EAAA,WACD,eAAe,WAAW;AACzB,cAAA;AAAA,EAAA,OACL;AACG,YAAA;AAA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