@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. https://hol.org
100 lines (99 loc) • 3.73 kB
TypeScript
import { RegisteredAgent, ActiveConnection, IStateManager, AgentPersistenceOptions } from './state-types';
import { HCS10BaseClient, IConnectionsManager } from '@hashgraphonline/standards-sdk';
/**
* Implementation of the IStateManager interface for the OpenConvai system.
* Manages agent state and connection information with thread safety and
* proper timestamp tracking.
*/
export declare class OpenConvaiState implements IStateManager {
private currentAgent;
private connectionMessageTimestamps;
private defaultEnvFilePath?;
private defaultPrefix;
private connectionsManager;
private logger;
/**
* Creates a new OpenConvaiState instance
* @param options - Options for environment variable persistence
*/
constructor(options?: {
defaultEnvFilePath?: string;
defaultPrefix?: string;
baseClient?: HCS10BaseClient;
disableLogging?: boolean;
});
/**
* Initializes the ConnectionsManager
* @param baseClient - HCS10BaseClient instance to use
*/
initializeConnectionsManager(baseClient: HCS10BaseClient): IConnectionsManager;
/**
* Gets the ConnectionsManager instance
* @returns The ConnectionsManager instance, or null if not initialized
*/
getConnectionsManager(): IConnectionsManager | null;
/**
* Sets the current active agent and clears any previous connection data.
* This should be called when switching between agents.
*/
setCurrentAgent(agent: RegisteredAgent | null): void;
/**
* Returns the currently active agent or null if none is set.
*/
getCurrentAgent(): RegisteredAgent | null;
/**
* Adds a new connection to the active connections list.
* Ensures no duplicates are added based on connectionTopicId.
* Initializes timestamp tracking for the connection.
*/
addActiveConnection(connection: ActiveConnection): void;
/**
* Updates an existing connection or adds it if not found.
* Preserves existing properties when updating by merging objects.
*/
updateOrAddConnection(connection: ActiveConnection): void;
/**
* Returns a copy of all active connections.
*/
listConnections(): ActiveConnection[];
/**
* Finds a connection by its identifier, which can be:
* - A 1-based index as displayed in the connection list
* - A target account ID string
* - A connection topic ID string
*/
getConnectionByIdentifier(identifier: string): ActiveConnection | undefined;
/**
* Gets the last processed message timestamp for a connection.
* Returns 0 if no timestamp has been recorded.
*/
getLastTimestamp(connectionTopicId: string): number;
/**
* Updates the last processed message timestamp for a connection,
* but only if the new timestamp is more recent than the existing one.
*/
updateTimestamp(connectionTopicId: string, timestampNanos: number): void;
/**
* Helper method to initialize timestamp tracking for a connection
* if it doesn't already exist.
*/
private initializeTimestampIfNeeded;
/**
* Converts ConnectionStatus to SDK status format
*/
private convertConnectionStatus;
/**
* Converts SDK Connection to ActiveConnection
*/
private convertToActiveConnection;
/**
* Converts SDK status to state status format
*/
private convertToStateStatus;
/**
* Persists agent data to environment variables
* @param agent - The agent data to persist
* @param options - Environment file persistence options
*/
persistAgentData(agent: RegisteredAgent, options?: AgentPersistenceOptions): Promise<void>;
}