refactor(hub): rename Device ID to Hub ID in console layer

Rename the business-layer concept from "Device ID" to "Hub ID" for
better user comprehension. The underlying network transport layer
still uses deviceId — Hub ID is passed as the deviceId value.

- Rename device.ts → hub-identity.ts, getDeviceId → getHubId
- Storage file: ~/.super-multica/device-id → ~/.super-multica/hub-id
- Hub property: deviceId → hubId
- API response field: deviceId → hubId
- Console UI label: "Device ID" → "Hub ID"

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
yushen 2026-01-30 16:02:00 +08:00
parent b66bbdde06
commit eb4ce85602
5 changed files with 14 additions and 14 deletions

View file

@ -17,7 +17,7 @@ export class AppController {
@Get("hub")
getHub() {
return {
deviceId: this.hub.deviceId,
hubId: this.hub.hubId,
url: this.hub.url,
connectionState: this.hub.connectionState,
agentCount: this.hub.listAgents().length,

View file

@ -335,7 +335,7 @@
<!-- Stats -->
<div class="stats" id="stats">
<div class="stat-card">
<div class="stat-label">Device ID</div>
<div class="stat-label">Hub ID</div>
<div class="stat-value" id="stat-device"></div>
</div>
<div class="stat-card">
@ -425,7 +425,7 @@
]);
// Stats
const deviceId = hubRes.deviceId || '—';
const deviceId = hubRes.hubId || '—';
document.getElementById('stat-device').innerHTML =
`<span title="${deviceId}">${truncateId(deviceId)}</span>` +
(deviceId !== '—' ? `<button class="copy-btn" onclick="copyText('${deviceId}', this)">${copyIcon()}</button>` : '');

View file

@ -3,20 +3,20 @@ import { join } from "node:path";
import { v7 as uuidv7 } from "uuid";
import { DATA_DIR } from "../shared/index.js";
const DEVICE_ID_FILE = join(DATA_DIR, "device-id");
const HUB_ID_FILE = join(DATA_DIR, "hub-id");
/**
* ID
* UUIDv7 ~/.multica/device-id
* Hub ID
* UUIDv7 ~/.super-multica/hub-id
*
*/
export function getDeviceId(): string {
export function getHubId(): string {
try {
return readFileSync(DEVICE_ID_FILE, "utf-8").trim();
return readFileSync(HUB_ID_FILE, "utf-8").trim();
} catch {
const id = uuidv7();
mkdirSync(DATA_DIR, { recursive: true });
writeFileSync(DEVICE_ID_FILE, id, "utf-8");
writeFileSync(HUB_ID_FILE, id, "utf-8");
return id;
}
}

View file

@ -1,7 +1,7 @@
import type { HubOptions } from "./types.js";
import type { ConnectionState } from "../shared/gateway-sdk/types.js";
import { AsyncAgent } from "../agent/async-agent.js";
import { getDeviceId } from "./device.js";
import { getHubId } from "./hub-identity.js";
import { GatewayClient } from "../shared/gateway-sdk/client.js";
import { loadAgentRecords, addAgentRecord, removeAgentRecord } from "./agent-store.js";
@ -11,7 +11,7 @@ export class Hub {
private client: GatewayClient;
url: string;
readonly path: string;
readonly deviceId: string;
readonly hubId: string;
/** Current Gateway connection state */
get connectionState(): ConnectionState {
@ -21,7 +21,7 @@ export class Hub {
constructor(url: string, path?: string) {
this.url = url;
this.path = path ?? "/ws";
this.deviceId = getDeviceId();
this.hubId = getHubId();
this.client = this.createClient(this.url);
this.client.connect();
this.restoreAgents();
@ -42,7 +42,7 @@ export class Hub {
const client = new GatewayClient({
url,
path: this.path,
deviceId: this.deviceId,
deviceId: this.hubId,
deviceType: "client",
autoReconnect: true,
reconnectDelay: 1000,

View file

@ -1,3 +1,3 @@
export { Hub } from "./hub.js";
export { getDeviceId } from "./device.js";
export { getHubId } from "./hub-identity.js";
export type { HubOptions } from "./types.js";