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.

136 lines (135 loc) 6.33 kB
import { TransactionReceipt, PrivateKey } from '@hashgraph/sdk'; import { HCS10Client as StandardSDKClient, AgentRegistrationResult, WaitForConnectionConfirmationResponse, ProfileResponse as SDKProfileResponse, HCSMessage, LogLevel, Logger, FeeConfigBuilderInterface } from '@hashgraphonline/standards-sdk'; import { AgentMetadata, AgentChannels } from './types'; import { IStateManager } from '../state/state-types'; type StandardHandleConnectionRequest = InstanceType<typeof StandardSDKClient>['handleConnectionRequest']; type HandleConnectionRequestResponse = Awaited<ReturnType<StandardHandleConnectionRequest>>; export type StandardNetworkType = 'mainnet' | 'testnet'; export interface ClientValidationOptions { accountId: string; privateKey: string; network?: StandardNetworkType; stateManager?: IStateManager; } export interface HCSMessageWithTimestamp extends HCSMessage { timestamp: number; data?: string; sequence_number: number; } export interface ExtendedAgentMetadata extends AgentMetadata { pfpBuffer?: Buffer; pfpFileName?: string; feeConfig?: FeeConfigBuilderInterface; } /** * HCS10Client wraps the HCS-10 functionalities using the @hashgraphonline/standards-sdk. * - Creates and registers agents using the standard SDK flow. * - Manages agent communication channels (handled by standard SDK). * - Sends messages on Hedera topics (currently manual, potential for standard SDK integration). */ export declare class HCS10Client { standardClient: StandardSDKClient; private useEncryption; agentChannels?: AgentChannels; guardedRegistryBaseUrl: string; logger: Logger; constructor(operatorId: string, operatorPrivateKey: string, network: StandardNetworkType, options?: { useEncryption?: boolean; registryUrl?: string; logLevel?: LogLevel; }); getOperatorId(): string; getNetwork(): StandardNetworkType; handleConnectionRequest(inboundTopicId: string, requestingAccountId: string, connectionRequestId: number, feeConfig?: FeeConfigBuilderInterface): Promise<HandleConnectionRequestResponse>; /** * Retrieves the profile for a given account ID using the standard SDK. */ getAgentProfile(accountId: string): Promise<SDKProfileResponse>; /** * Exposes the standard SDK's submitConnectionRequest method. */ submitConnectionRequest(inboundTopicId: string, memo: string): Promise<TransactionReceipt>; /** * Exposes the standard SDK's waitForConnectionConfirmation method. */ waitForConnectionConfirmation(outboundTopicId: string, connectionRequestId: number, maxAttempts?: number, delayMs?: number): Promise<WaitForConnectionConfirmationResponse>; /** * Creates and registers an agent using the standard SDK's HCS10Client. * This handles account creation, key generation, topic setup, and registration. * * When metadata includes fee configuration: * 1. The properties.feeConfig will be passed to the AgentBuilder * 2. The properties.inboundTopicType will be set to FEE_BASED * 3. The SDK's createAndRegisterAgent will apply the fees to the agent's inbound topic * * @param metadata - The agent's metadata, potentially including pfpBuffer, pfpFileName, * and fee configuration in properties.feeConfig * @returns The registration result from the standard SDK, containing accountId, keys, topics etc. */ createAndRegisterAgent(metadata: ExtendedAgentMetadata): Promise<AgentRegistrationResult>; /** * Sends a structured HCS-10 message to the specified topic using the standard SDK client. * Handles potential inscription for large messages. * * @param topicId - The target topic ID (likely a connection topic). * @param operatorId - The operator ID string (e.g., "inboundTopic@accountId"). * @param data - The actual message content/data. * @param memo - Optional memo for the message. * @param submitKey - Optional private key for topics requiring specific submit keys. * @returns A confirmation status string from the transaction receipt. */ sendMessage(topicId: string, data: string, memo?: string, submitKey?: PrivateKey): Promise<number | undefined>; /** * Retrieves messages from a topic using the standard SDK client. * * @param topicId - The topic ID to get messages from. * @returns Messages from the topic, mapped to the expected format. */ getMessages(topicId: string): Promise<{ messages: HCSMessageWithTimestamp[]; }>; getMessageStream(topicId: string): Promise<{ messages: HCSMessage[]; }>; /** * Retrieves content from an inscribed message using the standard SDK client. * @param inscriptionIdOrData - The inscription ID (hcs://...) or potentially raw data string. * @returns The resolved message content. */ getMessageContent(inscriptionIdOrData: string): Promise<string>; /** * Retrieves the inbound topic ID associated with the current operator. * This typically involves fetching the operator's own HCS-10 profile. * @returns A promise that resolves to the operator's inbound topic ID. * @throws {Error} If the operator ID cannot be determined or the profile/topic cannot be retrieved. */ getInboundTopicId(): Promise<string>; /** * Retrieves the configured operator account ID and private key. * Required by tools needing to identify the current agent instance. */ getAccountAndSigner(): { accountId: string; signer: PrivateKey; }; /** * Retrieves the outbound topic ID for the current operator. * Fetches the operator's profile if necessary. * @returns The outbound topic ID string. * @throws If the outbound topic cannot be determined. */ getOutboundTopicId(): Promise<string>; setClient(accountId: string, privateKey: string): StandardSDKClient; /** * Validates that the operator account exists and has proper access for agent operations */ private validateOperator; initializeWithValidation(options: ClientValidationOptions): Promise<{ isValid: boolean; operator?: { accountId: string; }; error?: string; }>; } export {};