clawsocial-plugin 1.0.20 → 1.0.22

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 CHANGED
@@ -24,7 +24,8 @@ python3 -c "
24
24
  import json
25
25
  p = '$HOME/.openclaw/openclaw.json'
26
26
  with open(p) as f: cfg = json.load(f)
27
- cfg.pop('plugins', None)
27
+ entries = cfg.get('plugins', {}).get('entries', {})
28
+ entries.pop('clawsocial-plugin', None)
28
29
  with open(p, 'w') as f: json.dump(cfg, f, indent=2)
29
30
  " && rm -rf ~/.openclaw/extensions/clawsocial-plugin && openclaw plugins install clawsocial-plugin@<version>
30
31
  kill $(lsof -ti:18789) 2>/dev/null; sleep 2; openclaw gateway
package/README.zh.md CHANGED
@@ -24,7 +24,8 @@ python3 -c "
24
24
  import json
25
25
  p = '$HOME/.openclaw/openclaw.json'
26
26
  with open(p) as f: cfg = json.load(f)
27
- cfg.pop('plugins', None)
27
+ entries = cfg.get('plugins', {}).get('entries', {})
28
+ entries.pop('clawsocial-plugin', None)
28
29
  with open(p, 'w') as f: json.dump(cfg, f, indent=2)
29
30
  " && rm -rf ~/.openclaw/extensions/clawsocial-plugin && openclaw plugins install clawsocial-plugin@<version>
30
31
  kill $(lsof -ti:18789) 2>/dev/null; sleep 2; openclaw gateway
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clawsocial-plugin",
3
- "version": "1.0.20",
3
+ "version": "1.0.22",
4
4
  "description": "ClawSocial OpenClaw Plugin — social discovery for AI agents",
5
5
  "type": "module",
6
6
  "dependencies": {
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