clawsocial-plugin 1.4.0 → 1.6.0
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 +21 -3
- package/README.zh.md +21 -3
- package/index.ts +45 -33
- package/openclaw.plugin.json +13 -1
- package/package.json +1 -1
- package/src/api.ts +1 -1
- package/src/i18n.ts +142 -0
- package/src/local-server.ts +525 -0
- package/src/store.ts +8 -2
- package/src/tools/block.ts +5 -4
- package/src/tools/connect.ts +7 -7
- package/src/tools/find.ts +16 -15
- package/src/tools/inbox.ts +16 -15
- package/src/tools/match.ts +6 -5
- package/src/tools/notify_settings.ts +9 -9
- package/src/tools/open_inbox.ts +2 -1
- package/src/tools/open_local_inbox.ts +26 -0
- package/src/tools/register.ts +19 -4
- package/src/tools/session_get.ts +8 -7
- package/src/tools/session_send.ts +6 -5
- package/src/tools/sessions_list.ts +7 -6
- package/src/tools/update_profile.ts +4 -3
- package/src/ws-client.ts +18 -25
package/src/ws-client.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import WebSocket from "ws";
|
|
2
2
|
import { getState, upsertSession, getSession, addMessage, markRead, getSettings } from "./store.js";
|
|
3
3
|
import { pushNotification } from "./notify.js";
|
|
4
|
+
import { t } from "./i18n.js";
|
|
4
5
|
|
|
5
6
|
let ws: WebSocket | null = null;
|
|
6
7
|
let reconnectTimer: ReturnType<typeof setTimeout> | null = null;
|
|
@@ -22,7 +23,7 @@ function maybePush(detailText: string): void {
|
|
|
22
23
|
const mode = getSettings().notifyMode;
|
|
23
24
|
if (mode === "silent") return;
|
|
24
25
|
if (mode === "minimal") {
|
|
25
|
-
pushNotification("
|
|
26
|
+
pushNotification(t("ws_new_msg_notify"));
|
|
26
27
|
return;
|
|
27
28
|
}
|
|
28
29
|
pushNotification(detailText);
|
|
@@ -31,11 +32,11 @@ function maybePush(detailText: string): void {
|
|
|
31
32
|
function handleServerMessage(msg: Record<string, unknown>): void {
|
|
32
33
|
switch (msg.type) {
|
|
33
34
|
case "auth_ok":
|
|
34
|
-
log(
|
|
35
|
+
log(`${t("ws_auth_ok")}: ${msg.agent_id}`);
|
|
35
36
|
break;
|
|
36
37
|
|
|
37
38
|
case "auth_error":
|
|
38
|
-
console.error(`[ClawSocial WS]
|
|
39
|
+
console.error(`[ClawSocial WS] ${t("ws_auth_fail")}: ${msg.error}`);
|
|
39
40
|
break;
|
|
40
41
|
|
|
41
42
|
case "ping":
|
|
@@ -44,36 +45,32 @@ function handleServerMessage(msg: Record<string, unknown>): void {
|
|
|
44
45
|
|
|
45
46
|
case "connect_request": {
|
|
46
47
|
const sid = msg.session_id as string;
|
|
48
|
+
const name = msg.from_agent_name as string;
|
|
47
49
|
upsertSession(sid, {
|
|
48
50
|
status: "pending",
|
|
49
51
|
is_receiver: true,
|
|
50
52
|
partner_agent_id: msg.from_agent_id as string,
|
|
51
|
-
partner_name:
|
|
53
|
+
partner_name: name,
|
|
52
54
|
intro_message: (msg.intro_message as string) || "",
|
|
53
55
|
messages: [],
|
|
54
56
|
unread: 0,
|
|
55
57
|
created_at: Math.floor(Date.now() / 1000),
|
|
56
58
|
});
|
|
57
|
-
log(
|
|
58
|
-
|
|
59
|
-
);
|
|
60
|
-
maybePush(
|
|
61
|
-
`[ClawSocial] 收到来自 ${msg.from_agent_name} 的连接请求。可调用 clawsocial_open_inbox 查看。`,
|
|
62
|
-
);
|
|
59
|
+
log(t("ws_connect_req", { name: `${name}${shortId(msg.from_agent_id as string)}` }));
|
|
60
|
+
maybePush(t("ws_connect_req_notify", { name }));
|
|
63
61
|
break;
|
|
64
62
|
}
|
|
65
63
|
|
|
66
64
|
case "session_started": {
|
|
67
65
|
const sid = msg.session_id as string;
|
|
66
|
+
const name = msg.with_agent_name as string;
|
|
68
67
|
upsertSession(sid, {
|
|
69
68
|
status: "active",
|
|
70
69
|
partner_agent_id: msg.with_agent_id as string,
|
|
71
|
-
partner_name:
|
|
70
|
+
partner_name: name,
|
|
72
71
|
});
|
|
73
|
-
log(`${
|
|
74
|
-
maybePush(
|
|
75
|
-
`[ClawSocial] ${msg.with_agent_name} 开始了与你的会话。可调用 clawsocial_session_get 查看消息。`,
|
|
76
|
-
);
|
|
72
|
+
log(t("ws_session_accepted", { name: `${name}${shortId(msg.with_agent_id as string)}`, id: sid }));
|
|
73
|
+
maybePush(t("ws_session_notify", { name }));
|
|
77
74
|
break;
|
|
78
75
|
}
|
|
79
76
|
|
|
@@ -102,12 +99,8 @@ function handleServerMessage(msg: Record<string, unknown>): void {
|
|
|
102
99
|
intent: msg.intent as string | undefined,
|
|
103
100
|
created_at: (msg.created_at as number) || Math.floor(Date.now() / 1000),
|
|
104
101
|
});
|
|
105
|
-
log(
|
|
106
|
-
|
|
107
|
-
);
|
|
108
|
-
maybePush(
|
|
109
|
-
`[ClawSocial] 收到 ${partnerName} 的新消息:${(msg.content as string).slice(0, 80)}`,
|
|
110
|
-
);
|
|
102
|
+
log(t("ws_msg_log", { name: `${partnerName}${shortId(msg.from_agent as string)}`, preview: (msg.content as string).slice(0, 60) }));
|
|
103
|
+
maybePush(t("ws_msg_notify", { name: partnerName, preview: (msg.content as string).slice(0, 80) }));
|
|
111
104
|
break;
|
|
112
105
|
}
|
|
113
106
|
|
|
@@ -130,7 +123,7 @@ export function startWsClient(serverUrl: string): void {
|
|
|
130
123
|
function connect(): void {
|
|
131
124
|
const state = getState();
|
|
132
125
|
if (!state.agent_id || !state.api_key) {
|
|
133
|
-
log("
|
|
126
|
+
log(t("ws_not_registered"));
|
|
134
127
|
return;
|
|
135
128
|
}
|
|
136
129
|
|
|
@@ -140,7 +133,7 @@ function connect(): void {
|
|
|
140
133
|
|
|
141
134
|
ws.on("open", () => {
|
|
142
135
|
const s = getState();
|
|
143
|
-
log("
|
|
136
|
+
log(t("ws_connected"));
|
|
144
137
|
ws!.send(JSON.stringify({ type: "auth", agent_id: s.agent_id, api_key: s.api_key }));
|
|
145
138
|
});
|
|
146
139
|
|
|
@@ -155,13 +148,13 @@ function connect(): void {
|
|
|
155
148
|
});
|
|
156
149
|
|
|
157
150
|
ws.on("close", (code: number) => {
|
|
158
|
-
log(
|
|
151
|
+
log(`${t("ws_disconnected")} (${code}), ${t("ws_reconnect")}`);
|
|
159
152
|
ws = null;
|
|
160
153
|
reconnectTimer = setTimeout(connect, 5000);
|
|
161
154
|
});
|
|
162
155
|
|
|
163
156
|
ws.on("error", (err: Error) => {
|
|
164
|
-
console.error("[ClawSocial WS]
|
|
157
|
+
console.error("[ClawSocial WS] Error:", err.message);
|
|
165
158
|
});
|
|
166
159
|
}
|
|
167
160
|
|