CosmicAC Autobase Connection
Create and run the autobase connection script to register writers and establish communication links between CosmicAC components.
CosmicAC Autobase Connection
After all workers are running, establish the autobase connection.
Create autobase-connect.js
Create a file named ~/autobase-connect.js with the contents below:
'use strict';
const fs = require('fs/promises');
const path = require('path');
const { exec } = require('child_process');
const { promisify } = require('util');
const execAsync = promisify(exec);
const loadStatusField = async (file, key) => {
try {
const content = await fs.readFile(file, 'utf-8');
return JSON.parse(content)?.[key];
} catch (err) {
if (err.code !== 'ENOENT') {
console.error('Failed to read:', file, err.message);
}
return null;
}
};
const runRegisterCommand = async (autobase, rpcPublicKey) => {
if (!autobase?.writer) return;
const command = `npx hp-rpc-cli -s ${rpcPublicKey} -m registerAutobaseWriter -d '${JSON.stringify({
key: autobase.writer,
})}'`;
console.log('▶ Running:', command);
try {
const { stdout, stderr } = await execAsync(command);
if (stderr) {
console.warn('⚠️ Stderr:', stderr);
}
if (stdout) {
console.log('✅ Output:', stdout);
}
} catch (err) {
console.error('❌ Command failed:', err.message);
}
};
const processStatusDir = async (baseDir, rpcPublicKey, skipFile) => {
const statusDir = path.join(baseDir, 'status');
try {
const files = await fs.readdir(statusDir);
for (const file of files) {
if (file === skipFile) continue;
const autobase = await loadStatusField(
path.join(statusDir, file),
'autobase'
);
await runRegisterCommand(autobase, rpcPublicKey);
}
} catch (err) {
if (err.code !== 'ENOENT') {
console.error('Failed to process dir:', statusDir, err.message);
}
}
};
(async () => {
const appCwd = path.join(__dirname, 'cosmicac-app-node');
const proxyInferenceCwd = path.join(__dirname, 'cosmicac-proxy-inference');
const mainRpcPublicKey = await loadStatusField(
path.join(appCwd, 'status', 'wrk-node-http-3000.json'),
'rpcPublicKey'
);
if (!mainRpcPublicKey) {
console.error('❌ rpcPublicKey not found');
return;
}
await processStatusDir(appCwd, mainRpcPublicKey, 'wrk-node-http-3000.json');
await processStatusDir(proxyInferenceCwd, mainRpcPublicKey);
})();Run the Autobase Connection
cd ~
# Run the autobase connection script
node autobase-connect.jsThis script:
- Reads the
rpcPublicKeyfromcosmicac-app-node/status/wrk-node-http-3000.json - Registers autobase writers from both
cosmicac-app-nodeandcosmicac-proxy-inference - Creates the communication link between the components
Verify Connection
Check for success messages:
- ✅ indicates successful registration
- ❌ indicates a failure (check logs for details)