@voltro/plugin-moderation 0.84.0 → 0.86.0
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/CHANGELOG.md +1215 -0
- package/THIRD-PARTY-NOTICES.md +5 -151
- package/dist/errors.d.ts +6 -7
- package/dist/index.d.ts +8 -9
- package/dist/index.js +41 -86
- package/dist/providers.js +51 -0
- package/package.json +5 -5
package/THIRD-PARTY-NOTICES.md
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
# Third-Party Notices — @voltro/plugin-moderation
|
|
2
2
|
|
|
3
|
-
This package
|
|
3
|
+
This package uses the open-source software listed below. Each is the
|
|
4
4
|
property of its respective copyright holders and is used under the terms of
|
|
5
5
|
its license. This file is provided for attribution; it grants no rights in
|
|
6
6
|
@voltro/plugin-moderation itself, which is proprietary (see LICENSE).
|
|
7
7
|
|
|
8
|
-
Generated from the resolved runtime dependency closure (
|
|
8
|
+
Generated from the resolved runtime dependency closure (31 packages).
|
|
9
9
|
|
|
10
10
|
---
|
|
11
11
|
|
|
@@ -75,118 +75,6 @@ License: Apache-2.0
|
|
|
75
75
|
|
|
76
76
|
_(no bundled license text found in the package; see its npm page.)_
|
|
77
77
|
|
|
78
|
-
## @effect/cluster@0.60.2
|
|
79
|
-
|
|
80
|
-
License: MIT
|
|
81
|
-
|
|
82
|
-
```
|
|
83
|
-
MIT License
|
|
84
|
-
|
|
85
|
-
Copyright (c) 2023-present The Contributors
|
|
86
|
-
|
|
87
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
88
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
89
|
-
in the Software without restriction, including without limitation the rights
|
|
90
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
91
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
92
|
-
furnished to do so, subject to the following conditions:
|
|
93
|
-
|
|
94
|
-
The above copyright notice and this permission notice shall be included in all
|
|
95
|
-
copies or substantial portions of the Software.
|
|
96
|
-
|
|
97
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
98
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
99
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
100
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
101
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
102
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
103
|
-
SOFTWARE.
|
|
104
|
-
```
|
|
105
|
-
|
|
106
|
-
## @effect/experimental@0.61.1
|
|
107
|
-
|
|
108
|
-
License: MIT
|
|
109
|
-
|
|
110
|
-
```
|
|
111
|
-
MIT License
|
|
112
|
-
|
|
113
|
-
Copyright (c) 2023-present The Contributors
|
|
114
|
-
|
|
115
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
116
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
117
|
-
in the Software without restriction, including without limitation the rights
|
|
118
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
119
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
120
|
-
furnished to do so, subject to the following conditions:
|
|
121
|
-
|
|
122
|
-
The above copyright notice and this permission notice shall be included in all
|
|
123
|
-
copies or substantial portions of the Software.
|
|
124
|
-
|
|
125
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
126
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
127
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
128
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
129
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
130
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
131
|
-
SOFTWARE.
|
|
132
|
-
```
|
|
133
|
-
|
|
134
|
-
## @effect/sql@0.52.1
|
|
135
|
-
|
|
136
|
-
License: MIT
|
|
137
|
-
|
|
138
|
-
```
|
|
139
|
-
MIT License
|
|
140
|
-
|
|
141
|
-
Copyright (c) 2023-present The Contributors
|
|
142
|
-
|
|
143
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
144
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
145
|
-
in the Software without restriction, including without limitation the rights
|
|
146
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
147
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
148
|
-
furnished to do so, subject to the following conditions:
|
|
149
|
-
|
|
150
|
-
The above copyright notice and this permission notice shall be included in all
|
|
151
|
-
copies or substantial portions of the Software.
|
|
152
|
-
|
|
153
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
154
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
155
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
156
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
157
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
158
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
159
|
-
SOFTWARE.
|
|
160
|
-
```
|
|
161
|
-
|
|
162
|
-
## @effect/workflow@0.19.1
|
|
163
|
-
|
|
164
|
-
License: MIT
|
|
165
|
-
|
|
166
|
-
```
|
|
167
|
-
MIT License
|
|
168
|
-
|
|
169
|
-
Copyright (c) 2023-present The Contributors
|
|
170
|
-
|
|
171
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
172
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
173
|
-
in the Software without restriction, including without limitation the rights
|
|
174
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
175
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
176
|
-
furnished to do so, subject to the following conditions:
|
|
177
|
-
|
|
178
|
-
The above copyright notice and this permission notice shall be included in all
|
|
179
|
-
copies or substantial portions of the Software.
|
|
180
|
-
|
|
181
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
182
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
183
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
184
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
185
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
186
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
187
|
-
SOFTWARE.
|
|
188
|
-
```
|
|
189
|
-
|
|
190
78
|
## @ioredis/commands@1.10.0
|
|
191
79
|
|
|
192
80
|
License: MIT
|
|
@@ -971,40 +859,6 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
971
859
|
SOFTWARE.
|
|
972
860
|
```
|
|
973
861
|
|
|
974
|
-
## kubernetes-types@1.30.0
|
|
975
|
-
|
|
976
|
-
License: Apache-2.0
|
|
977
|
-
|
|
978
|
-
_(no bundled license text found in the package; see its npm page.)_
|
|
979
|
-
|
|
980
|
-
## layerr@3.0.0
|
|
981
|
-
|
|
982
|
-
License: MIT
|
|
983
|
-
|
|
984
|
-
```
|
|
985
|
-
MIT License
|
|
986
|
-
|
|
987
|
-
Copyright (c) 2020 Perry Mitchell
|
|
988
|
-
|
|
989
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
990
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
991
|
-
in the Software without restriction, including without limitation the rights
|
|
992
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
993
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
994
|
-
furnished to do so, subject to the following conditions:
|
|
995
|
-
|
|
996
|
-
The above copyright notice and this permission notice shall be included in all
|
|
997
|
-
copies or substantial portions of the Software.
|
|
998
|
-
|
|
999
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
1000
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
1001
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
1002
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
1003
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
1004
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
1005
|
-
SOFTWARE.
|
|
1006
|
-
```
|
|
1007
|
-
|
|
1008
862
|
## ms@2.1.3
|
|
1009
863
|
|
|
1010
864
|
License: MIT
|
|
@@ -1354,14 +1208,14 @@ Apache License
|
|
|
1354
1208
|
limitations under the License.
|
|
1355
1209
|
```
|
|
1356
1210
|
|
|
1357
|
-
##
|
|
1211
|
+
## ulid@3.0.2
|
|
1358
1212
|
|
|
1359
1213
|
License: MIT
|
|
1360
1214
|
|
|
1361
1215
|
```
|
|
1362
|
-
MIT License
|
|
1216
|
+
The MIT License (MIT)
|
|
1363
1217
|
|
|
1364
|
-
Copyright (c)
|
|
1218
|
+
Copyright (c) 2017 Alizain Feerasta
|
|
1365
1219
|
|
|
1366
1220
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
1367
1221
|
of this software and associated documentation files (the "Software"), to deal
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,18 +1,17 @@
|
|
|
1
1
|
import { Schema } from 'effect';
|
|
2
|
+
import { YieldableError } from 'effect/Cause';
|
|
2
3
|
|
|
3
4
|
/** Raised when a `block`-action rule flags the content — the write never
|
|
4
5
|
* commits. Merged into every procedure's wire-error union (typed on the client). */
|
|
5
6
|
export declare class ContentRejected extends ContentRejected_base {
|
|
6
7
|
}
|
|
7
8
|
|
|
8
|
-
declare const ContentRejected_base: Schema.
|
|
9
|
-
readonly _tag: Schema.tag<"ContentRejected">;
|
|
10
|
-
} & {
|
|
9
|
+
declare const ContentRejected_base: Schema.Class<ContentRejected, Schema.TaggedStruct<"ContentRejected", {
|
|
11
10
|
/** The rpc tag that was moderated. */
|
|
12
|
-
tag:
|
|
11
|
+
readonly tag: Schema.String;
|
|
13
12
|
/** Matched categories / keywords. */
|
|
14
|
-
categories: Schema
|
|
15
|
-
reason:
|
|
16
|
-
}>;
|
|
13
|
+
readonly categories: Schema.$Array<Schema.String>;
|
|
14
|
+
readonly reason: Schema.String;
|
|
15
|
+
}>, YieldableError>;
|
|
17
16
|
|
|
18
17
|
export { }
|
package/dist/index.d.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Effect } from 'effect';
|
|
|
3
3
|
import { generateObject } from '@voltro/ai';
|
|
4
4
|
import { Schema } from 'effect';
|
|
5
5
|
import { VoltroPlugin } from '@voltro/protocol';
|
|
6
|
+
import { YieldableError } from 'effect/Cause';
|
|
6
7
|
|
|
7
8
|
/** AI moderation via @voltro/ai (lazy, OPTIONAL dependency). Uses a structured
|
|
8
9
|
* classification. `threshold` (0..1) decides flagged from the model's max
|
|
@@ -33,15 +34,13 @@ declare interface AiProviderOptions {
|
|
|
33
34
|
export declare class ContentRejected extends ContentRejected_base {
|
|
34
35
|
}
|
|
35
36
|
|
|
36
|
-
declare const ContentRejected_base: Schema.
|
|
37
|
-
readonly _tag: Schema.tag<"ContentRejected">;
|
|
38
|
-
} & {
|
|
37
|
+
declare const ContentRejected_base: Schema.Class<ContentRejected, Schema.TaggedStruct<"ContentRejected", {
|
|
39
38
|
/** The rpc tag that was moderated. */
|
|
40
|
-
tag:
|
|
39
|
+
readonly tag: Schema.String;
|
|
41
40
|
/** Matched categories / keywords. */
|
|
42
|
-
categories: Schema
|
|
43
|
-
reason:
|
|
44
|
-
}>;
|
|
41
|
+
readonly categories: Schema.$Array<Schema.String>;
|
|
42
|
+
readonly reason: Schema.String;
|
|
43
|
+
}>, YieldableError>;
|
|
45
44
|
|
|
46
45
|
/** A flagged-content item awaiting review (the dashboard queue). */
|
|
47
46
|
export declare interface FlaggedItem {
|
|
@@ -107,14 +106,14 @@ export declare interface ModerationRule {
|
|
|
107
106
|
readonly action?: 'block' | 'flag';
|
|
108
107
|
}
|
|
109
108
|
|
|
110
|
-
/** `Context.
|
|
109
|
+
/** `Context.Service` for the moderation service — `yield* ModerationService` in any
|
|
111
110
|
* handler once `moderationPlugin(...)` is wired. The handler depends on the
|
|
112
111
|
* Tag; the plugin owns the provider-backed implementation (no module-level
|
|
113
112
|
* global). Mirrors `@voltro/plugin-mail`'s `MailService`. */
|
|
114
113
|
export declare class ModerationService extends ModerationService_base {
|
|
115
114
|
}
|
|
116
115
|
|
|
117
|
-
declare const ModerationService_base: Context.
|
|
116
|
+
declare const ModerationService_base: Context.ServiceClass<ModerationService, "@voltro/plugin-moderation/ModerationService", ModerationServiceShape>;
|
|
118
117
|
|
|
119
118
|
/** The moderation runtime surface a handler reads to classify arbitrary text.
|
|
120
119
|
* Backed by the configured provider; contributed once per app by
|
package/dist/index.js
CHANGED
|
@@ -1,99 +1,54 @@
|
|
|
1
1
|
import { ContentRejected as e } from "./errors.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
//#region src/
|
|
6
|
-
var
|
|
7
|
-
let t = (e) => e !== void 0 && /[\p{L}\p{N}_]/u.test(e), n = t(e[0]) ? "\\b" : "", r = t(e[e.length - 1]) ? "\\b" : "";
|
|
8
|
-
return RegExp(`${n}${e.replace(l, "\\$&")}${r}`, "u");
|
|
9
|
-
}, d = (e) => {
|
|
10
|
-
let t = e.filter((e) => e.length > 0).map((e) => ({
|
|
11
|
-
term: e.toLowerCase(),
|
|
12
|
-
re: u(e.toLowerCase())
|
|
13
|
-
}));
|
|
14
|
-
return (e) => n.sync(() => {
|
|
15
|
-
let n = e.toLowerCase(), r = t.filter((e) => e.re.test(n)).map((e) => e.term);
|
|
16
|
-
return r.length > 0 ? {
|
|
17
|
-
flagged: !0,
|
|
18
|
-
categories: r,
|
|
19
|
-
reason: `matched denied term(s): ${r.join(", ")}`
|
|
20
|
-
} : c;
|
|
21
|
-
});
|
|
22
|
-
}, f = (e = {}) => {
|
|
23
|
-
let t = e.threshold ?? .7, r = e.categories ?? [
|
|
24
|
-
"hate",
|
|
25
|
-
"harassment",
|
|
26
|
-
"sexual",
|
|
27
|
-
"violence",
|
|
28
|
-
"self-harm",
|
|
29
|
-
"illicit"
|
|
30
|
-
], i = e.load ?? (() => import("@voltro/ai")), a = !1;
|
|
31
|
-
return (e) => n.gen(function* () {
|
|
32
|
-
let o = yield* n.tryPromise(i).pipe(n.catchAll(() => n.succeed(null)));
|
|
33
|
-
return o === null ? (a || (a = !0, s.warn("aiProvider configured but @voltro/ai could not be loaded — content is NOT being moderated; install @voltro/ai")), c) : yield* n.tryPromise(async () => {
|
|
34
|
-
let { Schema: i } = await import("effect"), a = i.Struct({
|
|
35
|
-
flagged: i.Boolean,
|
|
36
|
-
topCategory: i.NullOr(i.String),
|
|
37
|
-
score: i.Number
|
|
38
|
-
}), { object: s } = await n.runPromise(o.generateObject({
|
|
39
|
-
schema: a,
|
|
40
|
-
system: `You are a content moderator. Categories: ${r.join(", ")}. Return whether the content violates policy, the worst category, and a 0..1 severity score.`,
|
|
41
|
-
prompt: e
|
|
42
|
-
})), c = s.flagged || s.score >= t;
|
|
43
|
-
return {
|
|
44
|
-
flagged: c,
|
|
45
|
-
score: s.score,
|
|
46
|
-
...s.topCategory ? { categories: [s.topCategory] } : {},
|
|
47
|
-
...c ? { reason: `ai moderation: ${s.topCategory ?? "policy"} (${s.score.toFixed(2)})` } : {}
|
|
48
|
-
};
|
|
49
|
-
}).pipe(n.catchAll(() => n.succeed(c)));
|
|
50
|
-
});
|
|
51
|
-
}, p = class extends t.Tag("@voltro/plugin-moderation/ModerationService")() {}, m = (e) => n.flatMap(p, (t) => t.moderate(e)), h = (e, t) => {
|
|
2
|
+
import { aiProvider as t, keywordProvider as n } from "./providers.js";
|
|
3
|
+
import { Context as r, Effect as i, Layer as a } from "effect";
|
|
4
|
+
import { definePlugin as o, pluginInstanceName as s } from "@voltro/protocol";
|
|
5
|
+
//#region src/index.ts
|
|
6
|
+
var c = class extends r.Service()("@voltro/plugin-moderation/ModerationService") {}, l = (e) => i.flatMap(c, (t) => t.moderate(e)), u = (e, t) => {
|
|
52
7
|
if (typeof e != "object" || !e) return "";
|
|
53
8
|
let n = e;
|
|
54
9
|
return t.map((e) => n[e]).filter((e) => typeof e == "string").join("\n");
|
|
55
|
-
},
|
|
56
|
-
let
|
|
57
|
-
base:
|
|
10
|
+
}, d = "@voltro/plugin-moderation", f = (t) => {
|
|
11
|
+
let n = s({
|
|
12
|
+
base: d,
|
|
58
13
|
alias: t.alias,
|
|
59
14
|
instance: t.name
|
|
60
|
-
}),
|
|
15
|
+
}), r = t.rules.map((e) => {
|
|
61
16
|
let t = e.match;
|
|
62
17
|
if (typeof t == "string") return (e) => t === e;
|
|
63
18
|
let n = t.global || t.sticky ? new RegExp(t.source, t.flags.replace(/[gy]/g, "")) : t;
|
|
64
19
|
return (e) => n.test(e);
|
|
65
|
-
}),
|
|
66
|
-
|
|
67
|
-
id: `mod_${Date.now().toString(36)}_${
|
|
20
|
+
}), l = (e) => t.rules.filter((t, n) => r[n](e)), f = t.onFlag, p = () => void 0, m = [], h = 0, g = 0, _ = 0, v = (e, t, n) => {
|
|
21
|
+
m.unshift({
|
|
22
|
+
id: `mod_${Date.now().toString(36)}_${h++}`,
|
|
68
23
|
tag: e,
|
|
69
24
|
categories: n.categories ?? [],
|
|
70
25
|
reason: n.reason ?? "content policy violation",
|
|
71
26
|
subjectId: t,
|
|
72
27
|
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
73
28
|
status: "pending"
|
|
74
|
-
}),
|
|
75
|
-
}, y = (
|
|
76
|
-
let a =
|
|
77
|
-
if (a.length === 0) return
|
|
78
|
-
let o =
|
|
79
|
-
return
|
|
80
|
-
for (let
|
|
81
|
-
let a =
|
|
29
|
+
}), m.length > 200 && (m.length = 200);
|
|
30
|
+
}, y = (n, r) => {
|
|
31
|
+
let a = l(r.tag);
|
|
32
|
+
if (a.length === 0) return n;
|
|
33
|
+
let o = r.subject?.id ?? null;
|
|
34
|
+
return i.gen(function* () {
|
|
35
|
+
for (let n of a) {
|
|
36
|
+
let a = u(r.input, n.fields);
|
|
82
37
|
if (a.length === 0) continue;
|
|
83
38
|
let s = yield* t.provider(a);
|
|
84
39
|
if (!s.flagged) continue;
|
|
85
|
-
let c = s.categories ?? [],
|
|
86
|
-
if ((
|
|
87
|
-
tag:
|
|
40
|
+
let c = s.categories ?? [], l = s.reason ?? "content policy violation";
|
|
41
|
+
if ((n.action ?? "block") === "block") return g++, v(r.tag, o, s), yield* i.fail(new e({
|
|
42
|
+
tag: r.tag,
|
|
88
43
|
categories: c,
|
|
89
|
-
reason:
|
|
44
|
+
reason: l
|
|
90
45
|
}));
|
|
91
|
-
_++, v(
|
|
92
|
-
tag:
|
|
46
|
+
_++, v(r.tag, o, s), p(r.tag, s), f?.({
|
|
47
|
+
tag: r.tag,
|
|
93
48
|
verdict: s
|
|
94
49
|
});
|
|
95
50
|
}
|
|
96
|
-
return yield*
|
|
51
|
+
return yield* n;
|
|
97
52
|
});
|
|
98
53
|
}, b = (e) => ({
|
|
99
54
|
kind: "json",
|
|
@@ -107,19 +62,19 @@ var s = o({ scope: "@voltro/plugin-moderation" }), c = { flagged: !1 }, l = /[.*
|
|
|
107
62
|
path: "/flagged",
|
|
108
63
|
scope: "process",
|
|
109
64
|
description: "The content-moderation review queue (newest first).",
|
|
110
|
-
handler: () =>
|
|
111
|
-
items:
|
|
65
|
+
handler: () => i.succeed(b({
|
|
66
|
+
items: m.slice(),
|
|
112
67
|
stats: {
|
|
113
|
-
blocked:
|
|
68
|
+
blocked: g,
|
|
114
69
|
flagged: _,
|
|
115
|
-
pending:
|
|
70
|
+
pending: m.filter((e) => e.status === "pending").length
|
|
116
71
|
}
|
|
117
72
|
}))
|
|
118
73
|
}, {
|
|
119
74
|
method: "POST",
|
|
120
75
|
path: "/resolve",
|
|
121
76
|
description: "Resolve a flagged item — confirm (real violation) or dismiss (false positive).",
|
|
122
|
-
handler: (e) =>
|
|
77
|
+
handler: (e) => i.sync(() => {
|
|
123
78
|
let t;
|
|
124
79
|
try {
|
|
125
80
|
t = JSON.parse(e.body || "{}");
|
|
@@ -128,7 +83,7 @@ var s = o({ scope: "@voltro/plugin-moderation" }), c = { flagged: !1 }, l = /[.*
|
|
|
128
83
|
}
|
|
129
84
|
if (typeof t != "object" || !t || Array.isArray(t)) return x(400, "expected a JSON object");
|
|
130
85
|
if (!("id" in t) || typeof t.id != "string" || !t.id.trim() || !("action" in t) || t.action !== "confirm" && t.action !== "dismiss") return x(400, "id + action (confirm|dismiss) required");
|
|
131
|
-
let n =
|
|
86
|
+
let n = m.find((e) => e.id === t.id);
|
|
132
87
|
return n ? n.status === "pending" ? (n.status = t.action === "confirm" ? "confirmed" : "dismissed", b({
|
|
133
88
|
ok: !0,
|
|
134
89
|
item: n
|
|
@@ -140,10 +95,10 @@ var s = o({ scope: "@voltro/plugin-moderation" }), c = { flagged: !1 }, l = /[.*
|
|
|
140
95
|
"rpc:intercept:workflow",
|
|
141
96
|
"inspect:read",
|
|
142
97
|
"inspect:write"
|
|
143
|
-
], w =
|
|
144
|
-
return
|
|
145
|
-
name:
|
|
146
|
-
baseName:
|
|
98
|
+
], w = a.succeed(c, { moderate: (e) => t.provider(e) });
|
|
99
|
+
return o({
|
|
100
|
+
name: n,
|
|
101
|
+
baseName: d,
|
|
147
102
|
description: "Content moderation — block or flag user-content writes via an AI / keyword / custom check.",
|
|
148
103
|
permissions: C,
|
|
149
104
|
errorSchemas: [{
|
|
@@ -158,14 +113,14 @@ var s = o({ scope: "@voltro/plugin-moderation" }), c = { flagged: !1 }, l = /[.*
|
|
|
158
113
|
interceptWorkflow: y,
|
|
159
114
|
inspectEndpoints: S,
|
|
160
115
|
services: w,
|
|
161
|
-
onActivate: (e) =>
|
|
162
|
-
|
|
116
|
+
onActivate: (e) => i.sync(() => {
|
|
117
|
+
p = (t, n) => e.logger.warn("content flagged", {
|
|
163
118
|
tag: t,
|
|
164
119
|
categories: n.categories,
|
|
165
120
|
score: n.score
|
|
166
|
-
}),
|
|
121
|
+
}), f = t.onFlag, e.logger.info("moderation active", { rules: t.rules.length });
|
|
167
122
|
})
|
|
168
123
|
});
|
|
169
124
|
};
|
|
170
125
|
//#endregion
|
|
171
|
-
export { e as ContentRejected,
|
|
126
|
+
export { e as ContentRejected, c as ModerationService, t as aiProvider, n as keywordProvider, l as moderate, f as moderationPlugin };
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { Effect as e } from "effect";
|
|
2
|
+
import { createLogger as t } from "@voltro/logger";
|
|
3
|
+
//#region src/providers.ts
|
|
4
|
+
var n = t({ scope: "@voltro/plugin-moderation" }), r = { flagged: !1 }, i = /[.*+?^${}()|[\]\\]/g, a = (e) => {
|
|
5
|
+
let t = (e) => e !== void 0 && /[\p{L}\p{N}_]/u.test(e), n = t(e[0]) ? "\\b" : "", r = t(e[e.length - 1]) ? "\\b" : "";
|
|
6
|
+
return RegExp(`${n}${e.replace(i, "\\$&")}${r}`, "u");
|
|
7
|
+
}, o = (t) => {
|
|
8
|
+
let n = t.filter((e) => e.length > 0).map((e) => ({
|
|
9
|
+
term: e.toLowerCase(),
|
|
10
|
+
re: a(e.toLowerCase())
|
|
11
|
+
}));
|
|
12
|
+
return (t) => e.sync(() => {
|
|
13
|
+
let e = t.toLowerCase(), i = n.filter((t) => t.re.test(e)).map((e) => e.term);
|
|
14
|
+
return i.length > 0 ? {
|
|
15
|
+
flagged: !0,
|
|
16
|
+
categories: i,
|
|
17
|
+
reason: `matched denied term(s): ${i.join(", ")}`
|
|
18
|
+
} : r;
|
|
19
|
+
});
|
|
20
|
+
}, s = (t = {}) => {
|
|
21
|
+
let i = t.threshold ?? .7, a = t.categories ?? [
|
|
22
|
+
"hate",
|
|
23
|
+
"harassment",
|
|
24
|
+
"sexual",
|
|
25
|
+
"violence",
|
|
26
|
+
"self-harm",
|
|
27
|
+
"illicit"
|
|
28
|
+
], o = t.load ?? (() => import("@voltro/ai")), s = !1;
|
|
29
|
+
return (t) => e.gen(function* () {
|
|
30
|
+
let c = yield* e.tryPromise(o).pipe(e.catch(() => e.succeed(null)));
|
|
31
|
+
return c === null ? (s || (s = !0, n.warn("aiProvider configured but @voltro/ai could not be loaded — content is NOT being moderated; install @voltro/ai")), r) : yield* e.tryPromise(async () => {
|
|
32
|
+
let { Schema: n } = await import("effect"), r = n.Struct({
|
|
33
|
+
flagged: n.Boolean,
|
|
34
|
+
topCategory: n.NullOr(n.String),
|
|
35
|
+
score: n.Number
|
|
36
|
+
}), { object: o } = await e.runPromise(c.generateObject({
|
|
37
|
+
schema: r,
|
|
38
|
+
system: `You are a content moderator. Categories: ${a.join(", ")}. Return whether the content violates policy, the worst category, and a 0..1 severity score.`,
|
|
39
|
+
prompt: t
|
|
40
|
+
})), s = o.flagged || o.score >= i;
|
|
41
|
+
return {
|
|
42
|
+
flagged: s,
|
|
43
|
+
score: o.score,
|
|
44
|
+
...o.topCategory ? { categories: [o.topCategory] } : {},
|
|
45
|
+
...s ? { reason: `ai moderation: ${o.topCategory ?? "policy"} (${o.score.toFixed(2)})` } : {}
|
|
46
|
+
};
|
|
47
|
+
}).pipe(e.catch(() => e.succeed(r)));
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
//#endregion
|
|
51
|
+
export { s as aiProvider, o as keywordProvider };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@voltro/plugin-moderation",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.86.0",
|
|
4
4
|
"description": "Content moderation — run an AI / keyword / custom check on user-content fields and block or flag a write before it commits. Declarative per-rpc rules + an in-handler moderate() helper for redact/inline control.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"voltro",
|
|
@@ -38,14 +38,14 @@
|
|
|
38
38
|
"node": ">=24.0.0"
|
|
39
39
|
},
|
|
40
40
|
"dependencies": {
|
|
41
|
-
"@voltro/logger": "0.
|
|
42
|
-
"@voltro/protocol": "0.
|
|
41
|
+
"@voltro/logger": "0.86.0",
|
|
42
|
+
"@voltro/protocol": "0.86.0"
|
|
43
43
|
},
|
|
44
44
|
"optionalDependencies": {
|
|
45
|
-
"@voltro/ai": "0.
|
|
45
|
+
"@voltro/ai": "0.86.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"effect": "
|
|
48
|
+
"effect": "4.0.1"
|
|
49
49
|
},
|
|
50
50
|
"publishConfig": {
|
|
51
51
|
"access": "public"
|