File size: 3,725 Bytes
40d7073
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
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
29
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/**
 * Cluster Wrapper - Distributed coordination for multi-agent systems
 *
 * Wraps @ruvector/cluster for Raft consensus, auto-sharding,
 * and distributed memory across agents.
 */
export declare function isClusterAvailable(): boolean;
export interface ClusterNode {
    id: string;
    address: string;
    role: 'leader' | 'follower' | 'candidate';
    status: 'healthy' | 'unhealthy' | 'unknown';
    lastHeartbeat: number;
}
export interface ShardInfo {
    id: number;
    range: [number, number];
    node: string;
    size: number;
    status: 'active' | 'migrating' | 'offline';
}
export interface ClusterConfig {
    nodeId: string;
    address: string;
    peers?: string[];
    shards?: number;
    replicationFactor?: number;
}
/**
 * Distributed cluster for multi-agent coordination
 */
export declare class RuvectorCluster {
    private inner;
    private nodeId;
    private isLeader;
    constructor(config: ClusterConfig);
    /**
     * Start the cluster node
     */
    start(): Promise<void>;
    /**
     * Stop the cluster node gracefully
     */
    stop(): Promise<void>;
    /**
     * Join an existing cluster
     */
    join(peerAddress: string): Promise<boolean>;
    /**
     * Leave the cluster
     */
    leave(): Promise<void>;
    /**
     * Get current node info
     */
    getNodeInfo(): ClusterNode;
    /**
     * Get all cluster nodes
     */
    getNodes(): ClusterNode[];
    /**
     * Check if this node is the leader
     */
    isClusterLeader(): boolean;
    /**
     * Get the current leader
     */
    getLeader(): ClusterNode | null;
    /**
     * Put a value in distributed storage
     */
    put(key: string, value: any): Promise<boolean>;
    /**
     * Get a value from distributed storage
     */
    get(key: string): Promise<any | null>;
    /**
     * Delete a value from distributed storage
     */
    delete(key: string): Promise<boolean>;
    /**
     * Atomic compare-and-swap
     */
    compareAndSwap(key: string, expected: any, newValue: any): Promise<boolean>;
    /**
     * Get shard information
     */
    getShards(): ShardInfo[];
    /**
     * Get the shard for a key
     */
    getShardForKey(key: string): ShardInfo;
    /**
     * Trigger shard rebalancing
     */
    rebalance(): Promise<void>;
    /**
     * Acquire a distributed lock
     */
    lock(name: string, timeout?: number): Promise<string | null>;
    /**
     * Release a distributed lock
     */
    unlock(name: string, token: string): Promise<boolean>;
    /**
     * Extend a lock's TTL
     */
    extendLock(name: string, token: string, extension?: number): Promise<boolean>;
    /**
     * Subscribe to a channel
     */
    subscribe(channel: string, callback: (message: any) => void): () => void;
    /**
     * Publish to a channel
     */
    publish(channel: string, message: any): Promise<number>;
    /**
     * Register an agent with the cluster
     */
    registerAgent(agentId: string, capabilities: string[]): Promise<boolean>;
    /**
     * Find agents with a capability
     */
    findAgents(capability: string): Promise<string[]>;
    /**
     * Assign a task to an agent
     */
    assignTask(taskId: string, agentId: string, task: any): Promise<boolean>;
    /**
     * Complete a task
     */
    completeTask(taskId: string, result: any): Promise<boolean>;
    /**
     * Get cluster statistics
     */
    stats(): {
        nodes: number;
        shards: number;
        leader: string | null;
        healthy: boolean;
    };
}
/**
 * Create a cluster node for agent coordination
 */
export declare function createCluster(config: ClusterConfig): RuvectorCluster;
export default RuvectorCluster;
//# sourceMappingURL=cluster-wrapper.d.ts.map