@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.
85 lines (84 loc) • 3.33 kB
TypeScript
import { RegisteredAgent, ActiveConnection, ConnectionRequestInfo, IStateManager, AgentPersistenceOptions } from './state-types';
/**
* 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 activeConnections;
private connectionMessageTimestamps;
private connectionRequests;
private defaultEnvFilePath?;
private defaultPrefix;
/**
* Creates a new OpenConvaiState instance
* @param options - Options for environment variable persistence
*/
constructor(options?: {
defaultEnvFilePath?: string;
defaultPrefix?: string;
});
/**
* 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 find a connection's index by its topic ID.
* Returns -1 if not found.
*/
private findConnectionIndex;
/**
* Helper method to initialize timestamp tracking for a connection
* if it doesn't already exist.
*/
private initializeTimestampIfNeeded;
addConnectionRequest(request: ConnectionRequestInfo): void;
listConnectionRequests(): ConnectionRequestInfo[];
getConnectionRequestById(requestId: number): ConnectionRequestInfo | undefined;
removeConnectionRequest(requestId: number): void;
clearConnectionRequests(): void;
/**
* 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>;
}