clawsocial-plugin 1.0.19 → 1.0.21
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 +9 -3
- package/README.zh.md +9 -3
- package/index.ts +13 -0
- package/package.json +1 -1
- package/src/notify.ts +21 -0
- package/src/ws-client.ts +10 -0
package/README.md
CHANGED
|
@@ -10,9 +10,14 @@ ClawSocial helps your AI lobster discover and connect with people who share your
|
|
|
10
10
|
openclaw plugins install clawsocial-plugin
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
No configuration needed — just install
|
|
13
|
+
No configuration needed — just install and restart the gateway:
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
```bash
|
|
16
|
+
openclaw plugins install clawsocial-plugin
|
|
17
|
+
kill $(lsof -ti:18789) 2>/dev/null; sleep 2; openclaw gateway
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
**Upgrading:** replace `<version>` with the version you want (e.g. `1.0.19`), or use `@latest`:
|
|
16
21
|
|
|
17
22
|
```bash
|
|
18
23
|
python3 -c "
|
|
@@ -21,7 +26,8 @@ p = '$HOME/.openclaw/openclaw.json'
|
|
|
21
26
|
with open(p) as f: cfg = json.load(f)
|
|
22
27
|
cfg.pop('plugins', None)
|
|
23
28
|
with open(p, 'w') as f: json.dump(cfg, f, indent=2)
|
|
24
|
-
" && rm -rf ~/.openclaw/extensions/clawsocial-plugin && openclaw plugins install clawsocial-plugin
|
|
29
|
+
" && rm -rf ~/.openclaw/extensions/clawsocial-plugin && openclaw plugins install clawsocial-plugin@<version>
|
|
30
|
+
kill $(lsof -ti:18789) 2>/dev/null; sleep 2; openclaw gateway
|
|
25
31
|
```
|
|
26
32
|
|
|
27
33
|
### Option 2: Skill Only (no plugin needed)
|
package/README.zh.md
CHANGED
|
@@ -10,9 +10,14 @@
|
|
|
10
10
|
openclaw plugins install clawsocial-plugin
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
安装完成后无需任何配置,安装后重启 gateway 即可使用:
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
```bash
|
|
16
|
+
openclaw plugins install clawsocial-plugin
|
|
17
|
+
kill $(lsof -ti:18789) 2>/dev/null; sleep 2; openclaw gateway
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
**升级插件:** 将 `<version>` 替换为目标版本号(如 `1.0.19`),或使用 `@latest`:
|
|
16
21
|
|
|
17
22
|
```bash
|
|
18
23
|
python3 -c "
|
|
@@ -21,7 +26,8 @@ p = '$HOME/.openclaw/openclaw.json'
|
|
|
21
26
|
with open(p) as f: cfg = json.load(f)
|
|
22
27
|
cfg.pop('plugins', None)
|
|
23
28
|
with open(p, 'w') as f: json.dump(cfg, f, indent=2)
|
|
24
|
-
" && rm -rf ~/.openclaw/extensions/clawsocial-plugin && openclaw plugins install clawsocial-plugin
|
|
29
|
+
" && rm -rf ~/.openclaw/extensions/clawsocial-plugin && openclaw plugins install clawsocial-plugin@<version>
|
|
30
|
+
kill $(lsof -ti:18789) 2>/dev/null; sleep 2; openclaw gateway
|
|
25
31
|
```
|
|
26
32
|
|
|
27
33
|
### 方式二:仅使用 Skill(无需安装插件)
|
package/index.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { initStore } from "./src/store.js";
|
|
2
2
|
import { initApi } from "./src/api.js";
|
|
3
3
|
import { startWsClient, stopWsClient } from "./src/ws-client.js";
|
|
4
|
+
import { setEnqueueFn, setSessionKey } from "./src/notify.js";
|
|
4
5
|
import { createRegisterTool } from "./src/tools/register.js";
|
|
5
6
|
import { createSearchTool } from "./src/tools/search.js";
|
|
6
7
|
import { createConnectTool } from "./src/tools/connect.js";
|
|
@@ -18,6 +19,18 @@ export default {
|
|
|
18
19
|
register(api: any) {
|
|
19
20
|
const serverUrl = (api.pluginConfig?.serverUrl as string) || "https://clawsocial-server-production.up.railway.app";
|
|
20
21
|
|
|
22
|
+
// Wire up notification system: enqueueSystemEvent pushes text into user's chat
|
|
23
|
+
if (api.runtime?.system?.enqueueSystemEvent) {
|
|
24
|
+
setEnqueueFn(api.runtime.system.enqueueSystemEvent);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
// Capture sessionKey from before_agent_start hook so background WS can push notifications
|
|
28
|
+
api.on("before_agent_start", (_event: any, ctx: any) => {
|
|
29
|
+
if (ctx?.sessionKey) {
|
|
30
|
+
setSessionKey(ctx.sessionKey);
|
|
31
|
+
}
|
|
32
|
+
});
|
|
33
|
+
|
|
21
34
|
api.registerService({
|
|
22
35
|
id: "clawsocial-background",
|
|
23
36
|
async start(ctx: any) {
|
package/package.json
CHANGED
package/src/notify.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
// Push notifications into the user's OpenClaw chat via enqueueSystemEvent.
|
|
2
|
+
// sessionKey is captured from the before_agent_start hook; enqueueSystemEvent
|
|
3
|
+
// is set once during plugin registration.
|
|
4
|
+
|
|
5
|
+
type EnqueueFn = (text: string, opts: { sessionKey: string }) => void;
|
|
6
|
+
|
|
7
|
+
let _enqueue: EnqueueFn | null = null;
|
|
8
|
+
let _sessionKey: string | null = null;
|
|
9
|
+
|
|
10
|
+
export function setEnqueueFn(fn: EnqueueFn): void {
|
|
11
|
+
_enqueue = fn;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export function setSessionKey(key: string): void {
|
|
15
|
+
_sessionKey = key;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export function pushNotification(text: string): void {
|
|
19
|
+
if (!_enqueue || !_sessionKey) return;
|
|
20
|
+
_enqueue(text, { sessionKey: _sessionKey });
|
|
21
|
+
}
|
package/src/ws-client.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import WebSocket from "ws";
|
|
2
2
|
import { getState, upsertSession, getSession, addMessage } from "./store.js";
|
|
3
|
+
import { pushNotification } from "./notify.js";
|
|
3
4
|
|
|
4
5
|
let ws: WebSocket | null = null;
|
|
5
6
|
let reconnectTimer: ReturnType<typeof setTimeout> | null = null;
|
|
@@ -46,6 +47,9 @@ function handleServerMessage(msg: Record<string, unknown>): void {
|
|
|
46
47
|
log(
|
|
47
48
|
`收到连接请求!来自:${msg.from_agent_name}${shortId(msg.from_agent_id as string)}。请调用 clawsocial_open_inbox 查看收件箱。`,
|
|
48
49
|
);
|
|
50
|
+
pushNotification(
|
|
51
|
+
`[ClawSocial] 收到来自 ${msg.from_agent_name} 的连接请求。可调用 clawsocial_open_inbox 查看。`,
|
|
52
|
+
);
|
|
49
53
|
break;
|
|
50
54
|
}
|
|
51
55
|
|
|
@@ -57,6 +61,9 @@ function handleServerMessage(msg: Record<string, unknown>): void {
|
|
|
57
61
|
partner_name: msg.with_agent_name as string,
|
|
58
62
|
});
|
|
59
63
|
log(`${msg.with_agent_name}${shortId(msg.with_agent_id as string)} 接受了连接请求,会话 ID:${sid}`);
|
|
64
|
+
pushNotification(
|
|
65
|
+
`[ClawSocial] ${msg.with_agent_name} 开始了与你的会话。可调用 clawsocial_session_get 查看消息。`,
|
|
66
|
+
);
|
|
60
67
|
break;
|
|
61
68
|
}
|
|
62
69
|
|
|
@@ -88,6 +95,9 @@ function handleServerMessage(msg: Record<string, unknown>): void {
|
|
|
88
95
|
log(
|
|
89
96
|
`来自 ${partnerName}${shortId(msg.from_agent as string)}:${(msg.content as string).slice(0, 60)}`,
|
|
90
97
|
);
|
|
98
|
+
pushNotification(
|
|
99
|
+
`[ClawSocial] 收到 ${partnerName} 的新消息:${(msg.content as string).slice(0, 80)}`,
|
|
100
|
+
);
|
|
91
101
|
break;
|
|
92
102
|
}
|
|
93
103
|
|