@coffeexdev/openclaw-sentinel 0.1.7 → 0.1.8
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/configSchema.js +70 -15
- package/package.json +1 -1
package/dist/configSchema.js
CHANGED
|
@@ -1,22 +1,77 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
})
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { Type } from "@sinclair/typebox";
|
|
2
|
+
import { Value } from "@sinclair/typebox/value";
|
|
3
|
+
const LimitsSchema = Type.Object({
|
|
4
|
+
maxWatchersTotal: Type.Integer({ minimum: 1 }),
|
|
5
|
+
maxWatchersPerSkill: Type.Integer({ minimum: 1 }),
|
|
6
|
+
maxConditionsPerWatcher: Type.Integer({ minimum: 1 }),
|
|
7
|
+
maxIntervalMsFloor: Type.Integer({ minimum: 1 }),
|
|
8
|
+
}, { additionalProperties: false });
|
|
9
|
+
const ConfigSchema = Type.Object({
|
|
10
|
+
allowedHosts: Type.Array(Type.String()),
|
|
11
|
+
localDispatchBase: Type.String({ minLength: 1 }),
|
|
12
|
+
dispatchAuthToken: Type.Optional(Type.String()),
|
|
13
|
+
stateFilePath: Type.Optional(Type.String()),
|
|
14
|
+
limits: Type.Optional(LimitsSchema),
|
|
15
|
+
}, { additionalProperties: false });
|
|
16
|
+
function withDefaults(value) {
|
|
17
|
+
const limitsIn = value.limits ?? {};
|
|
18
|
+
return {
|
|
19
|
+
allowedHosts: Array.isArray(value.allowedHosts) ? value.allowedHosts : [],
|
|
20
|
+
localDispatchBase: typeof value.localDispatchBase === "string" && value.localDispatchBase.length > 0
|
|
21
|
+
? value.localDispatchBase
|
|
22
|
+
: "http://127.0.0.1:18789",
|
|
23
|
+
dispatchAuthToken: typeof value.dispatchAuthToken === "string" ? value.dispatchAuthToken : undefined,
|
|
24
|
+
stateFilePath: typeof value.stateFilePath === "string" ? value.stateFilePath : undefined,
|
|
25
|
+
limits: {
|
|
26
|
+
maxWatchersTotal: typeof limitsIn.maxWatchersTotal === "number" ? limitsIn.maxWatchersTotal : 200,
|
|
27
|
+
maxWatchersPerSkill: typeof limitsIn.maxWatchersPerSkill === "number" ? limitsIn.maxWatchersPerSkill : 20,
|
|
28
|
+
maxConditionsPerWatcher: typeof limitsIn.maxConditionsPerWatcher === "number"
|
|
29
|
+
? limitsIn.maxConditionsPerWatcher
|
|
30
|
+
: 25,
|
|
31
|
+
maxIntervalMsFloor: typeof limitsIn.maxIntervalMsFloor === "number" ? limitsIn.maxIntervalMsFloor : 1000,
|
|
32
|
+
},
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function issue(path, message) {
|
|
36
|
+
const segments = path.replace(/^\//, "").split("/").filter(Boolean);
|
|
37
|
+
return {
|
|
38
|
+
path: segments,
|
|
39
|
+
message,
|
|
40
|
+
};
|
|
41
|
+
}
|
|
15
42
|
export const sentinelConfigSchema = {
|
|
16
43
|
safeParse: (value) => {
|
|
17
44
|
if (value === undefined)
|
|
18
45
|
return { success: true, data: undefined };
|
|
19
|
-
|
|
46
|
+
if (value === null || typeof value !== "object" || Array.isArray(value)) {
|
|
47
|
+
return {
|
|
48
|
+
success: false,
|
|
49
|
+
error: { issues: [issue("/", "Config must be an object")] },
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
const candidate = withDefaults(value);
|
|
53
|
+
if (!Value.Check(ConfigSchema, candidate)) {
|
|
54
|
+
const first = [...Value.Errors(ConfigSchema, candidate)][0];
|
|
55
|
+
return {
|
|
56
|
+
success: false,
|
|
57
|
+
error: {
|
|
58
|
+
issues: [issue(String(first?.path || "/"), String(first?.message || "Invalid config"))],
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
// explicit URL validation (TypeBox format validators are not enabled by default)
|
|
63
|
+
try {
|
|
64
|
+
new URL(candidate.localDispatchBase);
|
|
65
|
+
}
|
|
66
|
+
catch {
|
|
67
|
+
return {
|
|
68
|
+
success: false,
|
|
69
|
+
error: {
|
|
70
|
+
issues: [issue("/localDispatchBase", "Invalid URL")],
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
return { success: true, data: candidate };
|
|
20
75
|
},
|
|
21
76
|
jsonSchema: {
|
|
22
77
|
type: "object",
|