clawsocial-plugin 1.6.5 → 1.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clawsocial-plugin",
3
- "version": "1.6.5",
3
+ "version": "1.6.6",
4
4
  "description": "ClawSocial OpenClaw Plugin — social discovery for AI agents",
5
5
  "type": "module",
6
6
  "author": "ClawSocial",
package/src/store.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  import fs from "node:fs";
2
+ import os from "node:os";
2
3
  import path from "node:path";
3
4
 
4
5
  let _stateDir: string | null = null;
@@ -137,15 +138,59 @@ export function markRead(sessionId: string): void {
137
138
  }
138
139
  }
139
140
 
141
+ // ── Credential backup (survives plugin/OpenClaw reinstall) ──────────
142
+
143
+ function credentialBackupFile(): string {
144
+ return path.join(os.homedir(), ".clawsocial", "credentials.json");
145
+ }
146
+
147
+ function backupCredentials(state: AgentState): void {
148
+ if (!state.agent_id || !state.api_key) return;
149
+ try {
150
+ const dir = path.dirname(credentialBackupFile());
151
+ fs.mkdirSync(dir, { recursive: true });
152
+ writeJSON(credentialBackupFile(), {
153
+ agent_id: state.agent_id,
154
+ api_key: state.api_key,
155
+ public_name: state.public_name,
156
+ lang: state.lang,
157
+ });
158
+ } catch {
159
+ // best-effort backup, don't fail if write fails
160
+ }
161
+ }
162
+
163
+ function restoreCredentials(): AgentState | null {
164
+ try {
165
+ const backup = readJSON<AgentState>(credentialBackupFile(), {});
166
+ if (backup.agent_id && backup.api_key) return backup;
167
+ } catch {
168
+ // no backup available
169
+ }
170
+ return null;
171
+ }
172
+
140
173
  // ── Agent state ─────────────────────────────────────────────────────
141
174
 
142
175
  export function getState(): AgentState {
143
- return readJSON<AgentState>(stateFile(), {});
176
+ const state = readJSON<AgentState>(stateFile(), {});
177
+ // If state is empty (e.g. after reinstall), try restoring from backup
178
+ if (!state.agent_id || !state.api_key) {
179
+ const backup = restoreCredentials();
180
+ if (backup) {
181
+ writeJSON(stateFile(), backup);
182
+ return backup;
183
+ }
184
+ }
185
+ return state;
144
186
  }
145
187
 
146
188
  export function setState(data: Partial<AgentState>): void {
147
189
  const s = getState();
148
- writeJSON(stateFile(), { ...s, ...data });
190
+ const merged = { ...s, ...data };
191
+ writeJSON(stateFile(), merged);
192
+ // Backup credentials whenever they change
193
+ backupCredentials(merged);
149
194
  }
150
195
 
151
196
  // ── Contacts ─────────────────────────────────────────────────────────
@@ -41,7 +41,6 @@ export function createMatchTool(): AnyAgentTool {
41
41
  public_name: c.public_name,
42
42
  topic_tags: c.topic_tags,
43
43
  match_score: Math.round(c.match_score * 100) + "%",
44
- availability: c.availability,
45
44
  completeness: Math.round((c.completeness_score ?? 0.1) * 100) + "%",
46
45
  ...(c.manual_intro ? { manual_intro: c.manual_intro } : {}),
47
46
  ...(c.auto_bio ? { auto_bio: c.auto_bio } : {}),