@alfe.ai/openclaw-metrics 0.0.5 → 0.0.7
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/dist/plugin.cjs +17 -47
- package/dist/plugin.js +17 -47
- package/package.json +2 -2
package/dist/plugin.cjs
CHANGED
|
@@ -1,44 +1,5 @@
|
|
|
1
1
|
let _alfe_ai_config = require("@alfe.ai/config");
|
|
2
2
|
let _alfe_ai_agent_api_client = require("@alfe.ai/agent-api-client");
|
|
3
|
-
//#region src/session-keys.ts
|
|
4
|
-
/** Known channel segments in canonical session keys. */
|
|
5
|
-
const KNOWN_CHANNELS = new Set([
|
|
6
|
-
"alfe",
|
|
7
|
-
"discord",
|
|
8
|
-
"slack",
|
|
9
|
-
"telegram",
|
|
10
|
-
"whatsapp",
|
|
11
|
-
"signal",
|
|
12
|
-
"irc",
|
|
13
|
-
"googlechat",
|
|
14
|
-
"msteams",
|
|
15
|
-
"imessage",
|
|
16
|
-
"feishu"
|
|
17
|
-
]);
|
|
18
|
-
/**
|
|
19
|
-
* Parse a session key for userId and channel.
|
|
20
|
-
*
|
|
21
|
-
* Returns empty strings for fields that cannot be determined.
|
|
22
|
-
*/
|
|
23
|
-
function parseSessionKey(key) {
|
|
24
|
-
const canonicalMatch = /^agent:[^:]+:([^:]+):(?:default:)?direct:([^:]+)/.exec(key);
|
|
25
|
-
if (canonicalMatch) {
|
|
26
|
-
const [, channel, userId] = canonicalMatch;
|
|
27
|
-
return {
|
|
28
|
-
userId,
|
|
29
|
-
channel: KNOWN_CHANNELS.has(channel) ? channel : "unknown"
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
if (key.includes("chat-")) return {
|
|
33
|
-
userId: "",
|
|
34
|
-
channel: "alfe"
|
|
35
|
-
};
|
|
36
|
-
return {
|
|
37
|
-
userId: "",
|
|
38
|
-
channel: "unknown"
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
//#endregion
|
|
42
3
|
//#region src/plugin.ts
|
|
43
4
|
/**
|
|
44
5
|
* @alfe.ai/openclaw-metrics — OpenClaw metrics plugin for Alfe.
|
|
@@ -67,16 +28,25 @@ const plugin = {
|
|
|
67
28
|
} catch (err) {
|
|
68
29
|
log.warn(`Failed to resolve Alfe config — metrics will not be reported: ${err instanceof Error ? err.message : String(err)}`);
|
|
69
30
|
}
|
|
70
|
-
api.on("
|
|
31
|
+
api.on("message_received", (...eventArgs) => {
|
|
32
|
+
if (!client) return;
|
|
33
|
+
const event = eventArgs[0];
|
|
34
|
+
const ctx = eventArgs[1];
|
|
35
|
+
if (!event.from) return;
|
|
36
|
+
client.recordActivity({
|
|
37
|
+
userId: event.from,
|
|
38
|
+
channel: ctx.channelId,
|
|
39
|
+
role: "user"
|
|
40
|
+
}).catch((err) => {
|
|
41
|
+
log.debug(`Metrics report failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
api.on("message_sending", (...eventArgs) => {
|
|
71
45
|
if (!client) return;
|
|
72
|
-
const
|
|
73
|
-
if (!sessionKey) return;
|
|
74
|
-
const parsed = parseSessionKey(sessionKey);
|
|
75
|
-
if (!parsed.userId) return;
|
|
46
|
+
const ctx = eventArgs[1];
|
|
76
47
|
client.recordActivity({
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
role
|
|
48
|
+
channel: ctx?.channelId ?? "unknown",
|
|
49
|
+
role: "assistant"
|
|
80
50
|
}).catch((err) => {
|
|
81
51
|
log.debug(`Metrics report failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
82
52
|
});
|
package/dist/plugin.js
CHANGED
|
@@ -1,44 +1,5 @@
|
|
|
1
1
|
import { resolveConfig } from "@alfe.ai/config";
|
|
2
2
|
import { AgentApiClient } from "@alfe.ai/agent-api-client";
|
|
3
|
-
//#region src/session-keys.ts
|
|
4
|
-
/** Known channel segments in canonical session keys. */
|
|
5
|
-
const KNOWN_CHANNELS = new Set([
|
|
6
|
-
"alfe",
|
|
7
|
-
"discord",
|
|
8
|
-
"slack",
|
|
9
|
-
"telegram",
|
|
10
|
-
"whatsapp",
|
|
11
|
-
"signal",
|
|
12
|
-
"irc",
|
|
13
|
-
"googlechat",
|
|
14
|
-
"msteams",
|
|
15
|
-
"imessage",
|
|
16
|
-
"feishu"
|
|
17
|
-
]);
|
|
18
|
-
/**
|
|
19
|
-
* Parse a session key for userId and channel.
|
|
20
|
-
*
|
|
21
|
-
* Returns empty strings for fields that cannot be determined.
|
|
22
|
-
*/
|
|
23
|
-
function parseSessionKey(key) {
|
|
24
|
-
const canonicalMatch = /^agent:[^:]+:([^:]+):(?:default:)?direct:([^:]+)/.exec(key);
|
|
25
|
-
if (canonicalMatch) {
|
|
26
|
-
const [, channel, userId] = canonicalMatch;
|
|
27
|
-
return {
|
|
28
|
-
userId,
|
|
29
|
-
channel: KNOWN_CHANNELS.has(channel) ? channel : "unknown"
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
if (key.includes("chat-")) return {
|
|
33
|
-
userId: "",
|
|
34
|
-
channel: "alfe"
|
|
35
|
-
};
|
|
36
|
-
return {
|
|
37
|
-
userId: "",
|
|
38
|
-
channel: "unknown"
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
//#endregion
|
|
42
3
|
//#region src/plugin.ts
|
|
43
4
|
/**
|
|
44
5
|
* @alfe.ai/openclaw-metrics — OpenClaw metrics plugin for Alfe.
|
|
@@ -67,16 +28,25 @@ const plugin = {
|
|
|
67
28
|
} catch (err) {
|
|
68
29
|
log.warn(`Failed to resolve Alfe config — metrics will not be reported: ${err instanceof Error ? err.message : String(err)}`);
|
|
69
30
|
}
|
|
70
|
-
api.on("
|
|
31
|
+
api.on("message_received", (...eventArgs) => {
|
|
32
|
+
if (!client) return;
|
|
33
|
+
const event = eventArgs[0];
|
|
34
|
+
const ctx = eventArgs[1];
|
|
35
|
+
if (!event.from) return;
|
|
36
|
+
client.recordActivity({
|
|
37
|
+
userId: event.from,
|
|
38
|
+
channel: ctx.channelId,
|
|
39
|
+
role: "user"
|
|
40
|
+
}).catch((err) => {
|
|
41
|
+
log.debug(`Metrics report failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
42
|
+
});
|
|
43
|
+
});
|
|
44
|
+
api.on("message_sending", (...eventArgs) => {
|
|
71
45
|
if (!client) return;
|
|
72
|
-
const
|
|
73
|
-
if (!sessionKey) return;
|
|
74
|
-
const parsed = parseSessionKey(sessionKey);
|
|
75
|
-
if (!parsed.userId) return;
|
|
46
|
+
const ctx = eventArgs[1];
|
|
76
47
|
client.recordActivity({
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
role
|
|
48
|
+
channel: ctx?.channelId ?? "unknown",
|
|
49
|
+
role: "assistant"
|
|
80
50
|
}).catch((err) => {
|
|
81
51
|
log.debug(`Metrics report failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
82
52
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alfe.ai/openclaw-metrics",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.7",
|
|
4
4
|
"description": "OpenClaw metrics plugin for Alfe — per-user activity tracking",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/plugin.js",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@alfe.ai/config": "^0.0.7",
|
|
26
|
-
"@alfe.ai/agent-api-client": "^0.0.
|
|
26
|
+
"@alfe.ai/agent-api-client": "^0.0.7"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"openclaw": ">=2026.3.0"
|