@coffeexdev/openclaw-sentinel 0.4.3 → 0.4.4

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.
Files changed (2) hide show
  1. package/dist/tool.js +50 -7
  2. package/package.json +1 -1
package/dist/tool.js CHANGED
@@ -14,6 +14,41 @@ function validateParams(params) {
14
14
  }
15
15
  return candidate;
16
16
  }
17
+ function stringifyPayload(payload) {
18
+ try {
19
+ const serialized = JSON.stringify(payload, null, 2);
20
+ if (typeof serialized !== "string" || serialized.length === 0)
21
+ return undefined;
22
+ return serialized;
23
+ }
24
+ catch {
25
+ return undefined;
26
+ }
27
+ }
28
+ function normalizeToolResultText(payload, fallbackText) {
29
+ const preferredText = fallbackText?.trim();
30
+ const safeText = preferredText && preferredText.length > 0 ? preferredText : (stringifyPayload(payload) ?? "ok");
31
+ const result = jsonResult(payload);
32
+ const currentContent = Array.isArray(result.content)
33
+ ? [...result.content]
34
+ : [];
35
+ let sawTextBlock = false;
36
+ const normalized = currentContent.map((entry) => {
37
+ if (!entry || typeof entry !== "object" || entry.type !== "text")
38
+ return entry;
39
+ sawTextBlock = true;
40
+ if (typeof entry.text === "string" && entry.text.length > 0)
41
+ return entry;
42
+ return { ...entry, text: safeText };
43
+ });
44
+ if (!sawTextBlock) {
45
+ normalized.unshift({ type: "text", text: safeText });
46
+ }
47
+ return {
48
+ ...result,
49
+ content: normalized,
50
+ };
51
+ }
17
52
  function inferDefaultDeliveryTargets(ctx) {
18
53
  const channel = ctx.messageChannel?.trim();
19
54
  if (!channel)
@@ -39,21 +74,29 @@ export function registerSentinelControl(registerTool, manager) {
39
74
  switch (payload.action) {
40
75
  case "create":
41
76
  case "add":
42
- return jsonResult(await manager.create(payload.watcher, {
77
+ return normalizeToolResultText(await manager.create(payload.watcher, {
43
78
  deliveryTargets: inferDefaultDeliveryTargets(ctx),
44
- }));
79
+ }), "Watcher created");
45
80
  case "enable":
46
- return jsonResult(await manager.enable(payload.id));
81
+ await manager.enable(payload.id);
82
+ return normalizeToolResultText(undefined, `Enabled watcher: ${payload.id}`);
47
83
  case "disable":
48
- return jsonResult(await manager.disable(payload.id));
84
+ await manager.disable(payload.id);
85
+ return normalizeToolResultText(undefined, `Disabled watcher: ${payload.id}`);
49
86
  case "remove":
50
87
  case "delete":
51
- return jsonResult(await manager.remove(payload.id));
88
+ try {
89
+ return normalizeToolResultText(await manager.remove(payload.id), `Removed watcher: ${payload.id}`);
90
+ }
91
+ catch (err) {
92
+ const message = String(err?.message ?? err);
93
+ return normalizeToolResultText({ ok: false, id: payload.id, error: message }, `Failed to remove watcher: ${payload.id}`);
94
+ }
52
95
  case "status":
53
96
  case "get":
54
- return jsonResult(manager.status(payload.id));
97
+ return normalizeToolResultText(manager.status(payload.id), `Watcher not found: ${payload.id}`);
55
98
  case "list":
56
- return jsonResult(manager.list());
99
+ return normalizeToolResultText(manager.list(), "[]");
57
100
  }
58
101
  },
59
102
  }));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@coffeexdev/openclaw-sentinel",
3
- "version": "0.4.3",
3
+ "version": "0.4.4",
4
4
  "description": "Secure declarative gateway-native watcher plugin for OpenClaw",
5
5
  "keywords": [
6
6
  "openclaw",