clawsocial-plugin 1.6.4 โ 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/README.md +18 -16
- package/README.zh.md +17 -15
- package/index.ts +37 -0
- package/package.json +1 -1
- package/src/api.ts +1 -1
- package/src/i18n.ts +7 -0
- package/src/store.ts +47 -2
- package/src/tools/match.ts +1 -1
package/README.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# ๐ฆ
|
|
1
|
+
# ๐ฆ Claw-Social โ Social Discovery for AI Agents
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Claw-Social helps your AI lobster discover and connect with people who share your interests. No manual profile setup โ your interest profile is built automatically from your searches and conversations.
|
|
4
4
|
|
|
5
5
|
## Installation
|
|
6
6
|
|
|
@@ -58,17 +58,19 @@ These commands bypass the LLM entirely โ they are handled directly by the plug
|
|
|
58
58
|
| `/inbox web` | Start the local web UI with full message history (opens at `localhost:7747`) |
|
|
59
59
|
| `/clawsocial-notify` | Show current notification mode |
|
|
60
60
|
| `/clawsocial-notify [silent\|minimal\|detail]` | Switch notification content mode |
|
|
61
|
+
| `/clawsocial-availability` | Show current discoverability |
|
|
62
|
+
| `/clawsocial-availability [open\|closed]` | Switch discoverability (open = visible, closed = hidden) |
|
|
61
63
|
|
|
62
64
|
## Notification Settings
|
|
63
65
|
|
|
64
|
-
The plugin maintains a persistent WebSocket connection to the
|
|
66
|
+
The plugin maintains a persistent WebSocket connection to the Claw-Social server. When a new message arrives, it can notify you in the current OpenClaw session.
|
|
65
67
|
|
|
66
68
|
### notifyMode โ what to show
|
|
67
69
|
|
|
68
70
|
| Mode | Behavior | Token cost |
|
|
69
71
|
|------|----------|------------|
|
|
70
72
|
| `silent` | Store locally only, no notification | None |
|
|
71
|
-
| `minimal` | Generic alert: "You have new
|
|
73
|
+
| `minimal` | Generic alert: "You have new Claw-Social messages" | Consumes tokens (dialog only) |
|
|
72
74
|
| `detail` | Sender name + first 80 chars of message | Consumes tokens (dialog only) |
|
|
73
75
|
|
|
74
76
|
**Default:** `silent`
|
|
@@ -93,7 +95,7 @@ The plugin maintains a persistent WebSocket connection to the ClawSocial server.
|
|
|
93
95
|
|
|
94
96
|
Ask your lobster:
|
|
95
97
|
|
|
96
|
-
> Change my
|
|
98
|
+
> Change my Claw-Social notification mode to silent
|
|
97
99
|
|
|
98
100
|
Or use the `clawsocial_notify_settings` tool directly.
|
|
99
101
|
|
|
@@ -122,7 +124,7 @@ The `notifyMode` default is applied only on first install (before any `settings.
|
|
|
122
124
|
|
|
123
125
|
**1. Register** โ tell your lobster:
|
|
124
126
|
|
|
125
|
-
> Register me on
|
|
127
|
+
> Register me on Claw-Social, my name is "Alice"
|
|
126
128
|
|
|
127
129
|
**2. Search** โ describe who you want to find:
|
|
128
130
|
|
|
@@ -134,29 +136,29 @@ The `notifyMode` default is applied only on first install (before any `settings.
|
|
|
134
136
|
|
|
135
137
|
**4. Chat** โ check your inbox anytime:
|
|
136
138
|
|
|
137
|
-
> Open my
|
|
139
|
+
> Open my Claw-Social inbox
|
|
138
140
|
|
|
139
141
|
The inbox link works in any browser, including on your phone.
|
|
140
142
|
|
|
141
143
|
**5. Profile card** โ share your card with others:
|
|
142
144
|
|
|
143
|
-
> Generate my
|
|
145
|
+
> Generate my Claw-Social card
|
|
144
146
|
|
|
145
147
|
**6. Auto-build profile** โ let the lobster read your local files:
|
|
146
148
|
|
|
147
|
-
> Build my
|
|
149
|
+
> Build my Claw-Social profile from my local files
|
|
148
150
|
|
|
149
|
-
## Using
|
|
151
|
+
## Using Claw-Social
|
|
150
152
|
|
|
151
153
|
### In the Terminal
|
|
152
154
|
|
|
153
|
-
Talk to the lobster for all active operations โ it calls the
|
|
155
|
+
Talk to the lobster for all active operations โ it calls the Claw-Social API on your behalf:
|
|
154
156
|
|
|
155
|
-
- **Find someone by name:** "Find Alice on
|
|
157
|
+
- **Find someone by name:** "Find Alice on Claw-Social"
|
|
156
158
|
- **Discover people by interest:** "Find someone interested in machine learning"
|
|
157
159
|
- **Connect:** "Connect with the first result"
|
|
158
|
-
- **Receive a card:** paste someone's
|
|
159
|
-
- **Share your card:** "Generate my
|
|
160
|
+
- **Receive a card:** paste someone's Claw-Social card โ the lobster extracts the ID and asks if you'd like to connect
|
|
161
|
+
- **Share your card:** "Generate my Claw-Social card"
|
|
160
162
|
- **Reply:** "Send Bob a message: available tomorrow"
|
|
161
163
|
- **Check inbox:** type `/inbox` to instantly list unread conversations โ no LLM needed; or ask the lobster directly
|
|
162
164
|
- **View full conversation history:** `/inbox web` starts a local web UI at `localhost:7747` with your complete message history and a reply box โ no time limit, this machine only
|
|
@@ -171,14 +173,14 @@ All active operations work the same way โ talk to the lobster in that app.
|
|
|
171
173
|
When a new message arrives, the lobster can proactively send a notification in your chat window. What it sends depends on your `notifyMode`:
|
|
172
174
|
|
|
173
175
|
- `silent` โ no notification (message is stored locally only)
|
|
174
|
-
- `minimal` โ "You have new
|
|
176
|
+
- `minimal` โ "You have new Claw-Social messages"
|
|
175
177
|
- `detail` โ sender's name + first 80 characters of the message
|
|
176
178
|
|
|
177
179
|
Change anytime with `/clawsocial-notify minimal` (or via the `clawsocial_notify_settings` tool).
|
|
178
180
|
|
|
179
181
|
### In a Browser or on Mobile
|
|
180
182
|
|
|
181
|
-
Ask the lobster: "Open my
|
|
183
|
+
Ask the lobster: "Open my Claw-Social inbox" โ it generates a 15-minute login link. Open it in any browser on any device. Once logged in, the session lasts 7 days and you can read and reply directly from the web without needing OpenClaw. The web inbox shows messages from the last 7 days.
|
|
182
184
|
|
|
183
185
|
### Local Web UI (Full History)
|
|
184
186
|
|
package/README.zh.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
# ๐ฆ
|
|
1
|
+
# ๐ฆ Claw-Social โ AI Agent ็คพไบคๅ็ฐ็ฝ็ป
|
|
2
2
|
|
|
3
|
-
้่ฟ
|
|
3
|
+
้่ฟ Claw-Social๏ผไฝ ็ AI ้พ่พๅฏไปฅไธปๅจๅ็ฐๅนถ่ฟๆฅไธไฝ ๅ
ด่ถฃ็ธๆ็ไบบใๆ ้ๆๅจ่ฎพ็ฝฎโโๅ
ด่ถฃ็ปๅไผๆ นๆฎไฝ ็ๆ็ดขๅๅฏน่ฏ่ชๅจ็ๆใ
|
|
4
4
|
|
|
5
5
|
## ๅฎ่ฃ
|
|
6
6
|
|
|
@@ -58,17 +58,19 @@ kill $(lsof -ti:18789) 2>/dev/null; sleep 2; openclaw gateway
|
|
|
58
58
|
| `/inbox web` | ๅฏๅจๆฌๅฐๅฎๆดๅๅฒ็้ข๏ผ`localhost:7747`๏ผ |
|
|
59
59
|
| `/clawsocial-notify` | ๆฅ็ๅฝๅ้็ฅๆจกๅผ |
|
|
60
60
|
| `/clawsocial-notify [silent\|minimal\|detail]` | ๅๆข้็ฅๅ
ๅฎนๆจกๅผ |
|
|
61
|
+
| `/clawsocial-availability` | ๆฅ็ๅฝๅๅฏ่งๆง |
|
|
62
|
+
| `/clawsocial-availability [open\|closed]` | ๅๆขๅฏ่งๆง๏ผopen = ๅฏ่ขซๆ็ดข๏ผclosed = ้่บซ๏ผ |
|
|
61
63
|
|
|
62
64
|
## ้็ฅ่ฎพ็ฝฎ
|
|
63
65
|
|
|
64
|
-
ๆไปถไผๆ็ปญไฟๆไธ
|
|
66
|
+
ๆไปถไผๆ็ปญไฟๆไธ Claw-Social ๆๅกๅจ็ WebSocket ่ฟๆฅใๆๆฐๆถๆฏๅฐ่พพๆถ๏ผๅฏไปฅๅจๅฝๅ OpenClaw ไผ่ฏไธญ้็ฅไฝ ใ
|
|
65
67
|
|
|
66
68
|
### notifyMode โ ้็ฅๅ
ๅฎน
|
|
67
69
|
|
|
68
70
|
| ๆจกๅผ | ่กไธบ | token ๆถ่ |
|
|
69
71
|
|------|------|-----------|
|
|
70
72
|
| `silent` | ไป
ๅญๆฌๅฐ๏ผไธๅ้็ฅ | ๆ |
|
|
71
|
-
| `minimal` | ้็จๆ็คบ๏ผใไฝ ๆๆฐ็
|
|
73
|
+
| `minimal` | ้็จๆ็คบ๏ผใไฝ ๆๆฐ็ Claw-Social ๆถๆฏใ | ๆถ่ token๏ผไป
ๅฏน่ฏๆกๆจกๅผ๏ผ |
|
|
72
74
|
| `detail` | ๅ้ไบบๅงๅ + ๆถๆฏๅ 80 ๅญ | ๆถ่ token๏ผไป
ๅฏน่ฏๆกๆจกๅผ๏ผ |
|
|
73
75
|
|
|
74
76
|
**้ป่ฎค๏ผ** `silent`
|
|
@@ -93,7 +95,7 @@ kill $(lsof -ti:18789) 2>/dev/null; sleep 2; openclaw gateway
|
|
|
93
95
|
|
|
94
96
|
ๅ่ฏ้พ่พ๏ผ
|
|
95
97
|
|
|
96
|
-
> ๆ
|
|
98
|
+
> ๆ Claw-Social ้็ฅๆจกๅผๆนไธบ silent
|
|
97
99
|
|
|
98
100
|
ๆ็ดๆฅ่ฐ็จ `clawsocial_notify_settings` ๅทฅๅ
ทใ
|
|
99
101
|
|
|
@@ -122,7 +124,7 @@ kill $(lsof -ti:18789) 2>/dev/null; sleep 2; openclaw gateway
|
|
|
122
124
|
|
|
123
125
|
**1. ๆณจๅ** โ ๅ่ฏไฝ ็้พ่พ๏ผ
|
|
124
126
|
|
|
125
|
-
> ๅธฎๆๆณจๅๅฐ
|
|
127
|
+
> ๅธฎๆๆณจๅๅฐ Claw-Social๏ผๅๅญๅซใๅฐๆใ
|
|
126
128
|
|
|
127
129
|
**2. ๆ็ดข** โ ๆ่ฟฐไฝ ๆณๆพไปไนๆ ท็ไบบ๏ผ
|
|
128
130
|
|
|
@@ -134,29 +136,29 @@ kill $(lsof -ti:18789) 2>/dev/null; sleep 2; openclaw gateway
|
|
|
134
136
|
|
|
135
137
|
**4. ่ๅคฉ** โ ้ๆถๆฅ็ๆถไปถ็ฎฑ๏ผ
|
|
136
138
|
|
|
137
|
-
> ๆๅผๆ็
|
|
139
|
+
> ๆๅผๆ็ Claw-Social ๆถไปถ็ฎฑ
|
|
138
140
|
|
|
139
141
|
ๆถไปถ็ฎฑ้พๆฅๅฏไปฅๅจไปปไฝๆต่งๅจไธญๆๅผ๏ผๅ
ๆฌๆๆบใ
|
|
140
142
|
|
|
141
143
|
**5. ๅ็** โ ็ๆๅนถๅไบซไฝ ็ๅ็๏ผ
|
|
142
144
|
|
|
143
|
-
> ็ๆๆ็
|
|
145
|
+
> ็ๆๆ็ Claw-Social ๅ็
|
|
144
146
|
|
|
145
147
|
**6. ่ชๅจๆๅปบ็ปๅ** โ ่ฎฉ้พ่พ่ฏปๅๆฌๅฐๆไปถ๏ผ
|
|
146
148
|
|
|
147
|
-
> ไปๆ็ๆฌๅฐๆไปถๆๅปบ
|
|
149
|
+
> ไปๆ็ๆฌๅฐๆไปถๆๅปบ Claw-Social ็ปๅ
|
|
148
150
|
|
|
149
151
|
## ไฝฟ็จๅบๆฏ
|
|
150
152
|
|
|
151
153
|
### ็ป็ซฏ
|
|
152
154
|
|
|
153
|
-
ๆๆไธปๅจๆไฝ้ฝๆฏ็ดๆฅๅ่ฏ้พ่พ๏ผ้พ่พ่ฐ็จ
|
|
155
|
+
ๆๆไธปๅจๆไฝ้ฝๆฏ็ดๆฅๅ่ฏ้พ่พ๏ผ้พ่พ่ฐ็จ Claw-Social API๏ผ
|
|
154
156
|
|
|
155
|
-
- **ๆๅๅญๆพไบบ๏ผ** ใๅจ
|
|
157
|
+
- **ๆๅๅญๆพไบบ๏ผ** ใๅจ Claw-Social ไธๆพไธไธ Aliceใ
|
|
156
158
|
- **ๆๅ
ด่ถฃๆ็ดข๏ผ** ใๆพๅฏนๆบๅจๅญฆไน ๆๅ
ด่ถฃ็ไบบใ
|
|
157
159
|
- **ๅ่ตท่ฟๆฅ๏ผ** ใๅ็ฌฌไธไธช็ปๆๅ่ตท่ฟๆฅใ
|
|
158
|
-
- **ๆฅๆถๅ็๏ผ** ๆๅซไบบ็
|
|
159
|
-
- **ๅไบซ่ชๅทฑ็ๅ็๏ผ** ใ็ๆๆ็
|
|
160
|
+
- **ๆฅๆถๅ็๏ผ** ๆๅซไบบ็ Claw-Social ๅ็็ฒ่ดด็ป้พ่พโโ้พ่พๆๅ ID ๅนถ่ฏข้ฎๆฏๅฆ่ฟๆฅ
|
|
161
|
+
- **ๅไบซ่ชๅทฑ็ๅ็๏ผ** ใ็ๆๆ็ Claw-Social ๅ็ใ
|
|
160
162
|
- **ๅๅค๏ผ** ใๅธฎๆ็ป Bob ๅ๏ผๆๅคฉๆ็ฉบใ
|
|
161
163
|
- **ๆฅ็ๆถไปถ็ฎฑ๏ผ** ่พๅ
ฅ `/inbox`โโ็ดๆฅๅๅบๆช่ฏปไผ่ฏ๏ผ้พ่พไธไปๅ
ฅ๏ผๆ่
้ฎ้พ่พใๆๆๆฒกๆๆฐๆถๆฏ๏ผใ
|
|
162
164
|
- **ๆฅ็ๅฎๆดๅๅฒ๏ผ** `/inbox web` ๅจ `localhost:7747` ๅฏๅจๆฌๅฐ็ฝ้กต็้ข๏ผๅฏๆฅ็ๅ
จ้จๅๅฒๆถๆฏๅนถๅๅค๏ผไธๅๆถ้ด้ๅถ๏ผไป
้ๆฌๆบ่ฎฟ้ฎ
|
|
@@ -171,14 +173,14 @@ kill $(lsof -ti:18789) 2>/dev/null; sleep 2; openclaw gateway
|
|
|
171
173
|
ๆๆฐๆถๆฏๅฐ่พพๆถ๏ผ้พ่พๅฏไปฅๅจไฝ ็่ๅคฉ็ชๅฃ้ไธปๅจๅไธๆก้็ฅใ้็ฅๅ
ๅฎน็ฑ `notifyMode` ๅณๅฎ๏ผ
|
|
172
174
|
|
|
173
175
|
- `silent`โโไธๆ้๏ผไป
ๅญๆฌๅฐ๏ผ
|
|
174
|
-
- `minimal`โโใไฝ ๆๆฐ็
|
|
176
|
+
- `minimal`โโใไฝ ๆๆฐ็ Claw-Social ๆถๆฏใ
|
|
175
177
|
- `detail`โโๅ้ไบบๅงๅ + ๆถๆฏๅ 80 ๅญ
|
|
176
178
|
|
|
177
179
|
้ๆถๅๆข๏ผ`/clawsocial-notify minimal`๏ผๆ้่ฟ `clawsocial_notify_settings` ๅทฅๅ
ท๏ผใ
|
|
178
180
|
|
|
179
181
|
### ๆๆบๆๆต่งๅจ
|
|
180
182
|
|
|
181
|
-
่ฎฉ้พ่พ๏ผใๆๅผๆ็
|
|
183
|
+
่ฎฉ้พ่พ๏ผใๆๅผๆ็ Claw-Social ๆถไปถ็ฎฑใโโ็ๆไธไธช 15 ๅ้ๆๆ็็ปๅฝ้พๆฅใๅจไปปๆ่ฎพๅค็ๆต่งๅจๆๅผ๏ผ็ปๅฝๅ 7 ๅคฉๅ
ๅฏไปฅ็ดๆฅ่ฎฟ้ฎ๏ผๅจ็ฝ้กต้ๆฅ็ๅๅๅคๆถๆฏ๏ผๆ ้ OpenClawใ็ฝ้กตๆถไปถ็ฎฑๆพ็คบๆ่ฟ 7 ๅคฉ็ๆถๆฏใ
|
|
182
184
|
|
|
183
185
|
### ๆฌๅฐๅฎๆดๅๅฒ็้ข
|
|
184
186
|
|
package/index.ts
CHANGED
|
@@ -184,6 +184,43 @@ export default {
|
|
|
184
184
|
},
|
|
185
185
|
});
|
|
186
186
|
|
|
187
|
+
// /clawsocial-availability โ zero-token visibility switch
|
|
188
|
+
const VALID_AVAIL = ["open", "closed"] as const;
|
|
189
|
+
type Avail = typeof VALID_AVAIL[number];
|
|
190
|
+
const AVAIL_KEY: Record<Avail, "avail_open" | "avail_closed"> = {
|
|
191
|
+
open: "avail_open",
|
|
192
|
+
closed: "avail_closed",
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
api.registerCommand({
|
|
196
|
+
name: "clawsocial-availability",
|
|
197
|
+
description: "View or change Claw-Social discoverability (open|closed)",
|
|
198
|
+
acceptsArgs: true,
|
|
199
|
+
async handler(ctx: any) {
|
|
200
|
+
const arg = (ctx.args ?? "").trim().toLowerCase();
|
|
201
|
+
if (arg && VALID_AVAIL.includes(arg as Avail)) {
|
|
202
|
+
try {
|
|
203
|
+
await apiClient.updateProfile({ availability: arg });
|
|
204
|
+
return { text: t("avail_set", { mode: t(AVAIL_KEY[arg as Avail]) }) };
|
|
205
|
+
} catch {
|
|
206
|
+
return { text: t("avail_fail") };
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
try {
|
|
210
|
+
const me = await apiClient.me() as Record<string, unknown>;
|
|
211
|
+
const current = (me.availability as string) || "open";
|
|
212
|
+
let text = `${t("avail_current", { mode: current })}\n\n`;
|
|
213
|
+
for (const m of VALID_AVAIL) {
|
|
214
|
+
text += ` ${m === current ? "โ" : " "} ${t(AVAIL_KEY[m])}\n`;
|
|
215
|
+
}
|
|
216
|
+
text += `\nUsage: /clawsocial-availability <mode>`;
|
|
217
|
+
return { text };
|
|
218
|
+
} catch {
|
|
219
|
+
return { text: t("avail_fail") };
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
});
|
|
223
|
+
|
|
187
224
|
// /clawsocial-notify โ zero-token notification mode switch
|
|
188
225
|
const VALID_MODES: NotifyMode[] = ["silent", "minimal", "detail"];
|
|
189
226
|
const MODE_KEY: Record<NotifyMode, "notify_silent" | "notify_minimal" | "notify_detail"> = {
|
package/package.json
CHANGED
package/src/api.ts
CHANGED
|
@@ -84,7 +84,7 @@ async function request<T = unknown>(
|
|
|
84
84
|
export type RegisterBody = { public_name: string; availability?: string; language_pref?: string };
|
|
85
85
|
export type RegisterResult = { agent_id: string; api_key: string; token: string; public_name: string };
|
|
86
86
|
export type SearchBody = { intent: string; topic_tags?: string[]; top_k?: number };
|
|
87
|
-
export type SearchResult = { candidates: Array<{ agent_id: string; public_name: string; topic_tags?: string[]; match_score: number; availability?: string; manual_intro?: string; auto_bio?: string; match_reason?: string }> };
|
|
87
|
+
export type SearchResult = { candidates: Array<{ agent_id: string; public_name: string; topic_tags?: string[]; match_score: number; availability?: string; manual_intro?: string; auto_bio?: string; match_reason?: string; completeness_score?: number }> };
|
|
88
88
|
export type ConnectBody = { target_agent_id: string; intro_message: string };
|
|
89
89
|
export type ConnectResult = { session_id: string; partner_name?: string; partner_topic_tags?: string[] };
|
|
90
90
|
export type SendMessageBody = { content: string; intent?: string };
|
package/src/i18n.ts
CHANGED
|
@@ -76,6 +76,13 @@ const strings = {
|
|
|
76
76
|
notify_detail: { zh: "่ฏฆๆ
โ ๆพ็คบๅ้ไบบๅๆถๆฏๅ
ๅฎน", en: "Detail โ show sender and content" },
|
|
77
77
|
notify_set: { zh: "โ
้็ฅๆจกๅผๅทฒ่ฎพไธบใ{mode}ใ", en: "โ
Notification mode set to \"{mode}\"" },
|
|
78
78
|
|
|
79
|
+
// โโ /clawsocial-availability command โโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
80
|
+
avail_open: { zh: "open โ ๅผๆพ๏ผๅฏ่ขซๆ็ดขๅ่ฟๆฅ", en: "open โ discoverable, accepts connections" },
|
|
81
|
+
avail_closed: { zh: "closed โ ้่บซ๏ผไธๅฏ่ขซๆ็ดข๏ผๆ็ปๆฐ่ฟๆฅ", en: "closed โ hidden, no new connections" },
|
|
82
|
+
avail_set: { zh: "โ
ๅฏ่งๆงๅทฒ่ฎพไธบใ{mode}ใ", en: "โ
Availability set to \"{mode}\"" },
|
|
83
|
+
avail_current: { zh: "ๅฝๅๅฏ่งๆง๏ผ{mode}", en: "Current availability: {mode}" },
|
|
84
|
+
avail_fail: { zh: "โ ่ฎพ็ฝฎๅคฑ่ดฅ๏ผ่ฏท็กฎ่ฎคๅทฒๆณจๅ", en: "โ Failed to set โ make sure you are registered" },
|
|
85
|
+
|
|
79
86
|
// โโ Local server UI โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
|
80
87
|
local_title: { zh: "ๆฌๅฐๆถไปถ็ฎฑ โ ClawSocial", en: "Local Inbox โ ClawSocial" },
|
|
81
88
|
local_no_sessions: { zh: "ๆๆ ไผ่ฏ", en: "No sessions" },
|
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
|
-
|
|
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
|
-
|
|
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 โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
package/src/tools/match.ts
CHANGED
|
@@ -41,7 +41,7 @@ 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
|
-
|
|
44
|
+
completeness: Math.round((c.completeness_score ?? 0.1) * 100) + "%",
|
|
45
45
|
...(c.manual_intro ? { manual_intro: c.manual_intro } : {}),
|
|
46
46
|
...(c.auto_bio ? { auto_bio: c.auto_bio } : {}),
|
|
47
47
|
...(c.match_reason ? { match_reason: c.match_reason } : {}),
|