@aight-cool/aight-utils 0.1.5 → 0.1.6

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 CHANGED
@@ -13,6 +13,7 @@ import { registerBootstrap } from "./src/bootstrap.js";
13
13
  import { registerPushHook } from "./src/push-hook.js";
14
14
  import { registerHealth } from "./src/health.js";
15
15
  import { registerVersion } from "./src/version.js";
16
+ import { registerGroupRpc } from "./src/groups.js";
16
17
 
17
18
  const aightPlugin = {
18
19
  id: "aight-utils",
@@ -66,6 +67,7 @@ const aightPlugin = {
66
67
  registerPushHook(api);
67
68
  registerHealth(api);
68
69
  registerVersion(api);
70
+ registerGroupRpc(api);
69
71
 
70
72
  api.logger.info("[aight-utils] Plugin loaded");
71
73
  },
@@ -2,7 +2,7 @@
2
2
  "id": "aight-utils",
3
3
  "name": "Aight App Utils",
4
4
  "description": "Aight App: Push notifications, Today items, config RPC, and agent bootstrap",
5
- "version": "0.1.5",
5
+ "version": "0.1.6",
6
6
  "configSchema": {
7
7
  "type": "object",
8
8
  "additionalProperties": false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aight-cool/aight-utils",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "OpenClaw gateway plugin for Aight App: push notifications, Today items, config RPC, and agent bootstrap",
5
5
  "type": "module",
6
6
  "files": [
package/src/groups.ts ADDED
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Group name store — simple mapping of groupId → display name.
3
+ * The app registers group names via RPC so push notifications
4
+ * can show friendly titles instead of raw IDs.
5
+ */
6
+
7
+ import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
8
+ import { readFileSync, writeFileSync, mkdirSync } from "fs";
9
+ import { join } from "path";
10
+
11
+ const FILENAME = "group-names.json";
12
+
13
+ function filePath(api: OpenClawPluginApi): string {
14
+ const dir = (api as any).dataDir ?? join(process.env.HOME ?? "/tmp", ".openclaw", "plugin-data", "aight-utils");
15
+ mkdirSync(dir, { recursive: true });
16
+ return join(dir, FILENAME);
17
+ }
18
+
19
+ function loadAll(api: OpenClawPluginApi): Record<string, string> {
20
+ try {
21
+ return JSON.parse(readFileSync(filePath(api), "utf-8"));
22
+ } catch {
23
+ return {};
24
+ }
25
+ }
26
+
27
+ function saveAll(api: OpenClawPluginApi, data: Record<string, string>): void {
28
+ writeFileSync(filePath(api), JSON.stringify(data), "utf-8");
29
+ }
30
+
31
+ export function loadGroupName(api: OpenClawPluginApi, groupId: string): string | undefined {
32
+ return loadAll(api)[groupId];
33
+ }
34
+
35
+ export function registerGroupName(api: OpenClawPluginApi, groupId: string, name: string): void {
36
+ const data = loadAll(api);
37
+ data[groupId] = name;
38
+ saveAll(api, data);
39
+ }
40
+
41
+ export function removeGroupName(api: OpenClawPluginApi, groupId: string): void {
42
+ const data = loadAll(api);
43
+ delete data[groupId];
44
+ saveAll(api, data);
45
+ }
46
+
47
+ export function registerGroupRpc(api: OpenClawPluginApi): void {
48
+ api.registerGatewayMethod("aight.groups.setName", ({ params, respond }: any) => {
49
+ const { groupId, name } = (params ?? {}) as { groupId?: string; name?: string };
50
+ if (!groupId || !name) {
51
+ respond(false, { error: "groupId and name are required" });
52
+ return;
53
+ }
54
+ registerGroupName(api, groupId, name);
55
+ respond(true, { ok: true });
56
+ });
57
+
58
+ api.registerGatewayMethod("aight.groups.removeName", ({ params, respond }: any) => {
59
+ const { groupId } = (params ?? {}) as { groupId?: string };
60
+ if (!groupId) {
61
+ respond(false, { error: "groupId is required" });
62
+ return;
63
+ }
64
+ removeGroupName(api, groupId);
65
+ respond(true, { ok: true });
66
+ });
67
+
68
+ api.logger.info("[aight-utils] Group name RPC registered");
69
+ }
package/src/push-hook.ts CHANGED
@@ -5,6 +5,7 @@
5
5
  import type { OpenClawPluginApi } from "openclaw/plugin-sdk";
6
6
  import { getPluginConfig } from "./config.js";
7
7
  import { sendPush, loadTokens } from "./push.js";
8
+ import { loadGroupName } from "./groups.js";
8
9
 
9
10
  export function registerPushHook(api: OpenClawPluginApi) {
10
11
  try {
@@ -61,13 +62,30 @@ export function registerPushHook(api: OpenClawPluginApi) {
61
62
  const agent = agents.find((a: any) => a.id === agentId);
62
63
  const displayName = agent?.name ?? agent?.identity?.name ?? agentId;
63
64
 
65
+ // Resolve group chat name for push title
66
+ let pushTitle = displayName;
67
+ const sessionKey = ctx.sessionKey ?? "";
68
+ if (sessionKey.includes(":group-chat:")) {
69
+ const groupId = sessionKey.split(":group-chat:")[1];
70
+ if (groupId) {
71
+ // Look up friendly name from plugin data store
72
+ const groupName = loadGroupName(api, groupId);
73
+ api.logger.info(
74
+ `[aight-utils] Group push title: groupId=${groupId} groupName=${groupName ?? "(not found)"} pushTitle=${groupName ? `${displayName} — ${groupName}` : displayName}`,
75
+ );
76
+ pushTitle = groupName
77
+ ? `${displayName} — ${groupName}`
78
+ : displayName;
79
+ }
80
+ }
81
+
64
82
  for (const device of tokens) {
65
83
  if (!device.sendKey) continue;
66
84
  try {
67
85
  await sendPush(
68
86
  device.deviceId,
69
87
  {
70
- title: displayName,
88
+ title: pushTitle,
71
89
  body: preview,
72
90
  data: { sessionKey: ctx.sessionKey, agentId },
73
91
  },