@coffeexdev/openclaw-sentinel 0.4.2 → 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.d.ts +2 -2
- package/dist/tool.js +55 -10
- package/dist/toolSchema.d.ts +45 -1
- package/dist/toolSchema.js +31 -13
- package/package.json +1 -1
package/dist/tool.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { AnyAgentTool } from "openclaw/plugin-sdk";
|
|
2
2
|
import type { Static } from "@sinclair/typebox";
|
|
3
3
|
import { WatcherManager } from "./watcherManager.js";
|
|
4
|
-
import {
|
|
5
|
-
export type SentinelToolParams = Static<typeof
|
|
4
|
+
import { SentinelToolValidationSchema } from "./toolSchema.js";
|
|
5
|
+
export type SentinelToolParams = Static<typeof SentinelToolValidationSchema>;
|
|
6
6
|
type SentinelToolContext = {
|
|
7
7
|
messageChannel?: string;
|
|
8
8
|
requesterSenderId?: string;
|
package/dist/tool.js
CHANGED
|
@@ -1,17 +1,54 @@
|
|
|
1
1
|
import { jsonResult } from "openclaw/plugin-sdk";
|
|
2
2
|
import { Value } from "@sinclair/typebox/value";
|
|
3
|
-
import { SentinelToolSchema } from "./toolSchema.js";
|
|
3
|
+
import { SentinelToolSchema, SentinelToolValidationSchema } from "./toolSchema.js";
|
|
4
4
|
import { TemplateValueSchema } from "./templateValueSchema.js";
|
|
5
5
|
function validateParams(params) {
|
|
6
6
|
const candidate = (params ?? {});
|
|
7
|
-
if (!Value.Check(
|
|
8
|
-
const first = [
|
|
7
|
+
if (!Value.Check(SentinelToolValidationSchema, [TemplateValueSchema], candidate)) {
|
|
8
|
+
const first = [
|
|
9
|
+
...Value.Errors(SentinelToolValidationSchema, [TemplateValueSchema], candidate),
|
|
10
|
+
][0];
|
|
9
11
|
const where = first?.path || "(root)";
|
|
10
12
|
const why = first?.message || "Invalid parameters";
|
|
11
13
|
throw new Error(`Invalid sentinel_control parameters at ${where}: ${why}`);
|
|
12
14
|
}
|
|
13
15
|
return candidate;
|
|
14
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
|
+
}
|
|
15
52
|
function inferDefaultDeliveryTargets(ctx) {
|
|
16
53
|
const channel = ctx.messageChannel?.trim();
|
|
17
54
|
if (!channel)
|
|
@@ -37,21 +74,29 @@ export function registerSentinelControl(registerTool, manager) {
|
|
|
37
74
|
switch (payload.action) {
|
|
38
75
|
case "create":
|
|
39
76
|
case "add":
|
|
40
|
-
return
|
|
77
|
+
return normalizeToolResultText(await manager.create(payload.watcher, {
|
|
41
78
|
deliveryTargets: inferDefaultDeliveryTargets(ctx),
|
|
42
|
-
}));
|
|
79
|
+
}), "Watcher created");
|
|
43
80
|
case "enable":
|
|
44
|
-
|
|
81
|
+
await manager.enable(payload.id);
|
|
82
|
+
return normalizeToolResultText(undefined, `Enabled watcher: ${payload.id}`);
|
|
45
83
|
case "disable":
|
|
46
|
-
|
|
84
|
+
await manager.disable(payload.id);
|
|
85
|
+
return normalizeToolResultText(undefined, `Disabled watcher: ${payload.id}`);
|
|
47
86
|
case "remove":
|
|
48
87
|
case "delete":
|
|
49
|
-
|
|
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
|
+
}
|
|
50
95
|
case "status":
|
|
51
96
|
case "get":
|
|
52
|
-
return
|
|
97
|
+
return normalizeToolResultText(manager.status(payload.id), `Watcher not found: ${payload.id}`);
|
|
53
98
|
case "list":
|
|
54
|
-
return
|
|
99
|
+
return normalizeToolResultText(manager.list(), "[]");
|
|
55
100
|
}
|
|
56
101
|
},
|
|
57
102
|
}));
|
package/dist/toolSchema.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export declare const
|
|
1
|
+
export declare const SentinelToolValidationSchema: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TObject<{
|
|
2
2
|
action: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"create">, import("@sinclair/typebox").TLiteral<"add">]>;
|
|
3
3
|
watcher: import("@sinclair/typebox").TObject<{
|
|
4
4
|
id: import("@sinclair/typebox").TString;
|
|
@@ -46,3 +46,47 @@ export declare const SentinelToolSchema: import("@sinclair/typebox").TUnion<[imp
|
|
|
46
46
|
}>, import("@sinclair/typebox").TObject<{
|
|
47
47
|
action: import("@sinclair/typebox").TLiteral<"list">;
|
|
48
48
|
}>]>;
|
|
49
|
+
export declare const SentinelToolSchema: import("@sinclair/typebox").TObject<{
|
|
50
|
+
action: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"create">, import("@sinclair/typebox").TLiteral<"add">]>, import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"enable">, import("@sinclair/typebox").TLiteral<"disable">, import("@sinclair/typebox").TLiteral<"remove">, import("@sinclair/typebox").TLiteral<"delete">, import("@sinclair/typebox").TLiteral<"status">, import("@sinclair/typebox").TLiteral<"get">]>, import("@sinclair/typebox").TLiteral<"list">]>;
|
|
51
|
+
watcher: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TObject<{
|
|
52
|
+
id: import("@sinclair/typebox").TString;
|
|
53
|
+
skillId: import("@sinclair/typebox").TString;
|
|
54
|
+
enabled: import("@sinclair/typebox").TBoolean;
|
|
55
|
+
strategy: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"http-poll">, import("@sinclair/typebox").TLiteral<"websocket">, import("@sinclair/typebox").TLiteral<"sse">, import("@sinclair/typebox").TLiteral<"http-long-poll">]>;
|
|
56
|
+
endpoint: import("@sinclair/typebox").TString;
|
|
57
|
+
method: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"GET">, import("@sinclair/typebox").TLiteral<"POST">]>>;
|
|
58
|
+
headers: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TString>>;
|
|
59
|
+
body: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
60
|
+
intervalMs: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
61
|
+
timeoutMs: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TNumber>;
|
|
62
|
+
match: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"all">, import("@sinclair/typebox").TLiteral<"any">]>;
|
|
63
|
+
conditions: import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
64
|
+
path: import("@sinclair/typebox").TString;
|
|
65
|
+
op: import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"eq">, import("@sinclair/typebox").TLiteral<"neq">, import("@sinclair/typebox").TLiteral<"gt">, import("@sinclair/typebox").TLiteral<"gte">, import("@sinclair/typebox").TLiteral<"lt">, import("@sinclair/typebox").TLiteral<"lte">, import("@sinclair/typebox").TLiteral<"exists">, import("@sinclair/typebox").TLiteral<"absent">, import("@sinclair/typebox").TLiteral<"contains">, import("@sinclair/typebox").TLiteral<"matches">, import("@sinclair/typebox").TLiteral<"changed">]>;
|
|
66
|
+
value: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnknown>;
|
|
67
|
+
}>>;
|
|
68
|
+
fire: import("@sinclair/typebox").TObject<{
|
|
69
|
+
webhookPath: import("@sinclair/typebox").TString;
|
|
70
|
+
eventName: import("@sinclair/typebox").TString;
|
|
71
|
+
payloadTemplate: import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TRef<any>>;
|
|
72
|
+
intent: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
73
|
+
contextTemplate: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TRef<any>>>;
|
|
74
|
+
priority: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TUnion<[import("@sinclair/typebox").TLiteral<"low">, import("@sinclair/typebox").TLiteral<"normal">, import("@sinclair/typebox").TLiteral<"high">, import("@sinclair/typebox").TLiteral<"critical">]>>;
|
|
75
|
+
deadlineTemplate: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
76
|
+
dedupeKeyTemplate: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
77
|
+
}>;
|
|
78
|
+
retry: import("@sinclair/typebox").TObject<{
|
|
79
|
+
maxRetries: import("@sinclair/typebox").TNumber;
|
|
80
|
+
baseMs: import("@sinclair/typebox").TNumber;
|
|
81
|
+
maxMs: import("@sinclair/typebox").TNumber;
|
|
82
|
+
}>;
|
|
83
|
+
fireOnce: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TBoolean>;
|
|
84
|
+
deliveryTargets: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TArray<import("@sinclair/typebox").TObject<{
|
|
85
|
+
channel: import("@sinclair/typebox").TString;
|
|
86
|
+
to: import("@sinclair/typebox").TString;
|
|
87
|
+
accountId: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
88
|
+
}>>>;
|
|
89
|
+
metadata: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TRecord<import("@sinclair/typebox").TString, import("@sinclair/typebox").TString>>;
|
|
90
|
+
}>>;
|
|
91
|
+
id: import("@sinclair/typebox").TOptional<import("@sinclair/typebox").TString>;
|
|
92
|
+
}>;
|
package/dist/toolSchema.js
CHANGED
|
@@ -80,27 +80,45 @@ const WatcherSchema = Type.Object({
|
|
|
80
80
|
})),
|
|
81
81
|
metadata: Type.Optional(Type.Record(Type.String(), Type.String(), { description: "Arbitrary key-value metadata" })),
|
|
82
82
|
}, { description: "Full watcher definition" });
|
|
83
|
+
const CreateActionNameSchema = Type.Union([Type.Literal("create"), Type.Literal("add")], {
|
|
84
|
+
description: "Create action (alias: add)",
|
|
85
|
+
});
|
|
86
|
+
const IdActionNameSchema = Type.Union([
|
|
87
|
+
Type.Literal("enable"),
|
|
88
|
+
Type.Literal("disable"),
|
|
89
|
+
Type.Literal("remove"),
|
|
90
|
+
Type.Literal("delete"),
|
|
91
|
+
Type.Literal("status"),
|
|
92
|
+
Type.Literal("get"),
|
|
93
|
+
], { description: "ID-targeting action aliases: delete/remove and get/status" });
|
|
94
|
+
const ListActionNameSchema = Type.Literal("list", { description: "List all watchers" });
|
|
95
|
+
const AnyActionNameSchema = Type.Union([
|
|
96
|
+
CreateActionNameSchema,
|
|
97
|
+
IdActionNameSchema,
|
|
98
|
+
ListActionNameSchema,
|
|
99
|
+
]);
|
|
83
100
|
const CreateActionSchema = Type.Object({
|
|
84
|
-
action:
|
|
85
|
-
description: "Create action (alias: add)",
|
|
86
|
-
}),
|
|
101
|
+
action: CreateActionNameSchema,
|
|
87
102
|
watcher: WatcherSchema,
|
|
88
103
|
}, { additionalProperties: false });
|
|
89
104
|
const IdActionSchema = Type.Object({
|
|
90
|
-
action:
|
|
91
|
-
Type.Literal("enable"),
|
|
92
|
-
Type.Literal("disable"),
|
|
93
|
-
Type.Literal("remove"),
|
|
94
|
-
Type.Literal("delete"),
|
|
95
|
-
Type.Literal("status"),
|
|
96
|
-
Type.Literal("get"),
|
|
97
|
-
], { description: "ID-targeting action aliases: delete/remove and get/status" }),
|
|
105
|
+
action: IdActionNameSchema,
|
|
98
106
|
id: Type.String({ description: "Watcher ID for action target" }),
|
|
99
107
|
}, { additionalProperties: false });
|
|
100
108
|
const ListActionSchema = Type.Object({
|
|
101
|
-
action:
|
|
109
|
+
action: ListActionNameSchema,
|
|
102
110
|
}, { additionalProperties: false });
|
|
103
|
-
export const
|
|
111
|
+
export const SentinelToolValidationSchema = Type.Union([CreateActionSchema, IdActionSchema, ListActionSchema], {
|
|
112
|
+
$defs: {
|
|
113
|
+
templateValue: TemplateValueSchema,
|
|
114
|
+
},
|
|
115
|
+
});
|
|
116
|
+
export const SentinelToolSchema = Type.Object({
|
|
117
|
+
action: AnyActionNameSchema,
|
|
118
|
+
watcher: Type.Optional(WatcherSchema),
|
|
119
|
+
id: Type.Optional(Type.String({ description: "Watcher ID for action target" })),
|
|
120
|
+
}, {
|
|
121
|
+
additionalProperties: false,
|
|
104
122
|
$defs: {
|
|
105
123
|
templateValue: TemplateValueSchema,
|
|
106
124
|
},
|