@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.
- package/dist/tool.js +50 -7
- 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
|
|
77
|
+
return normalizeToolResultText(await manager.create(payload.watcher, {
|
|
43
78
|
deliveryTargets: inferDefaultDeliveryTargets(ctx),
|
|
44
|
-
}));
|
|
79
|
+
}), "Watcher created");
|
|
45
80
|
case "enable":
|
|
46
|
-
|
|
81
|
+
await manager.enable(payload.id);
|
|
82
|
+
return normalizeToolResultText(undefined, `Enabled watcher: ${payload.id}`);
|
|
47
83
|
case "disable":
|
|
48
|
-
|
|
84
|
+
await manager.disable(payload.id);
|
|
85
|
+
return normalizeToolResultText(undefined, `Disabled watcher: ${payload.id}`);
|
|
49
86
|
case "remove":
|
|
50
87
|
case "delete":
|
|
51
|
-
|
|
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
|
|
97
|
+
return normalizeToolResultText(manager.status(payload.id), `Watcher not found: ${payload.id}`);
|
|
55
98
|
case "list":
|
|
56
|
-
return
|
|
99
|
+
return normalizeToolResultText(manager.list(), "[]");
|
|
57
100
|
}
|
|
58
101
|
},
|
|
59
102
|
}));
|