clawsocial-plugin 1.0.22 → 1.0.24
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/index.ts +6 -3
- package/package.json +1 -1
- package/src/notify.ts +10 -5
package/index.ts
CHANGED
|
@@ -1,7 +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 {
|
|
4
|
+
import { setRuntimeFns, setSessionKey } from "./src/notify.js";
|
|
5
5
|
import { createRegisterTool } from "./src/tools/register.js";
|
|
6
6
|
import { createSearchTool } from "./src/tools/search.js";
|
|
7
7
|
import { createConnectTool } from "./src/tools/connect.js";
|
|
@@ -19,9 +19,12 @@ export default {
|
|
|
19
19
|
register(api: any) {
|
|
20
20
|
const serverUrl = (api.pluginConfig?.serverUrl as string) || "https://clawsocial-server-production.up.railway.app";
|
|
21
21
|
|
|
22
|
-
// Wire up notification system: enqueueSystemEvent
|
|
22
|
+
// Wire up notification system: enqueueSystemEvent + requestHeartbeatNow
|
|
23
23
|
if (api.runtime?.system?.enqueueSystemEvent) {
|
|
24
|
-
|
|
24
|
+
setRuntimeFns(
|
|
25
|
+
api.runtime.system.enqueueSystemEvent,
|
|
26
|
+
api.runtime.system.requestHeartbeatNow,
|
|
27
|
+
);
|
|
25
28
|
}
|
|
26
29
|
|
|
27
30
|
// Capture sessionKey from before_agent_start hook so background WS can push notifications
|
package/package.json
CHANGED
package/src/notify.ts
CHANGED
|
@@ -1,14 +1,17 @@
|
|
|
1
|
-
// Push notifications into the user's OpenClaw chat via enqueueSystemEvent
|
|
2
|
-
// sessionKey is captured from the before_agent_start hook;
|
|
3
|
-
//
|
|
1
|
+
// Push notifications into the user's OpenClaw chat via enqueueSystemEvent +
|
|
2
|
+
// requestHeartbeatNow. sessionKey is captured from the before_agent_start hook;
|
|
3
|
+
// runtime functions are set once during plugin registration.
|
|
4
4
|
|
|
5
5
|
type EnqueueFn = (text: string, opts: { sessionKey: string }) => void;
|
|
6
|
+
type HeartbeatFn = () => void;
|
|
6
7
|
|
|
7
8
|
let _enqueue: EnqueueFn | null = null;
|
|
9
|
+
let _heartbeat: HeartbeatFn | null = null;
|
|
8
10
|
let _sessionKey: string | null = null;
|
|
9
11
|
|
|
10
|
-
export function
|
|
11
|
-
_enqueue =
|
|
12
|
+
export function setRuntimeFns(enqueue: EnqueueFn, heartbeat?: HeartbeatFn): void {
|
|
13
|
+
_enqueue = enqueue;
|
|
14
|
+
_heartbeat = heartbeat ?? null;
|
|
12
15
|
}
|
|
13
16
|
|
|
14
17
|
export function setSessionKey(key: string): void {
|
|
@@ -18,4 +21,6 @@ export function setSessionKey(key: string): void {
|
|
|
18
21
|
export function pushNotification(text: string): void {
|
|
19
22
|
if (!_enqueue || !_sessionKey) return;
|
|
20
23
|
_enqueue(text, { sessionKey: _sessionKey });
|
|
24
|
+
// Trigger immediate AI response so the user sees the notification right away
|
|
25
|
+
if (_heartbeat) _heartbeat();
|
|
21
26
|
}
|