build: PaddedCell-style install.mjs + SDK-aligned packaging
install.mjs (--install/--build-only/--uninstall/--openclaw-profile-path), tsconfig outDir dist/fabric, package.json openclaw file dep + main. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
40
dist/fabric/src/identity.js
vendored
Normal file
40
dist/fabric/src/identity.js
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
import { readFileSync, writeFileSync, existsSync, mkdirSync } from 'node:fs';
|
||||
import { dirname } from 'node:path';
|
||||
export class IdentityRegistry {
|
||||
filePath;
|
||||
entries = new Map();
|
||||
constructor(filePath) {
|
||||
this.filePath = filePath;
|
||||
this.load();
|
||||
}
|
||||
load() {
|
||||
if (!existsSync(this.filePath))
|
||||
return;
|
||||
try {
|
||||
const data = JSON.parse(readFileSync(this.filePath, 'utf8'));
|
||||
for (const e of data.entries ?? []) {
|
||||
if (e.agentId && e.fabricApiKey)
|
||||
this.entries.set(e.agentId, e);
|
||||
}
|
||||
}
|
||||
catch {
|
||||
// corrupt file -> start empty; upsert will rewrite
|
||||
}
|
||||
}
|
||||
persist() {
|
||||
mkdirSync(dirname(this.filePath), { recursive: true });
|
||||
const data = { entries: [...this.entries.values()] };
|
||||
writeFileSync(this.filePath, JSON.stringify(data, null, 2));
|
||||
}
|
||||
list() {
|
||||
return [...this.entries.values()];
|
||||
}
|
||||
findByAgentId(agentId) {
|
||||
return this.entries.get(agentId);
|
||||
}
|
||||
upsert(entry) {
|
||||
const prev = this.entries.get(entry.agentId);
|
||||
this.entries.set(entry.agentId, { ...prev, ...entry });
|
||||
this.persist();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user