@molecule/api-ai-moderation-pipeline 1.0.3 → 1.0.5

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/README.md +65 -64
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -3,20 +3,20 @@ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
3
  Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
4
  Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
5
  To change this document, edit the module-level JSDoc in src/index.ts.
6
- Generated: 2026-08-04T01:47:34.367Z
6
+ Generated: 2026-10-26T04:22:02.666Z
7
7
  -->
8
8
 
9
9
  # @molecule/api-ai-moderation-pipeline
10
10
 
11
- > **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
12
- > It is written to be read by coding agents as much as by people, and is generated from this
13
- > package's source — edit `src/index.ts` JSDoc, not this file.
14
-
15
11
  `@molecule/api-ai-moderation-pipeline` — content moderation built on
16
12
  the bonded AI provider. Classify → policy-match → action → audit-log.
17
13
 
18
14
  Extracted from ai-content-moderator flagship.
19
15
 
16
+ > **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
17
+ > It is written to be read by coding agents as much as by people, and is generated from this
18
+ > package's source — edit `src/index.ts` JSDoc, not this file.
19
+
20
20
  ## Quick Start
21
21
 
22
22
  ```ts
@@ -45,42 +45,15 @@ npm install @molecule/api-ai-moderation-pipeline @molecule/api-ai @molecule/api-
45
45
 
46
46
  ### Interfaces
47
47
 
48
- #### `AuditLogRow`
49
-
50
- Database row shape for a single moderation audit-log entry.
51
-
52
- ```typescript
53
- interface AuditLogRow {
54
- id: string
55
- owner_id: string | null
56
- content_excerpt: string
57
- decision: ModerationAction
58
- matched_category: ModerationCategory | null
59
- scores: ModerationScore[]
60
- reasoning: string
61
- resource_type: string | null
62
- resource_id: string | null
63
- created_at: string | Date
64
- }
65
- ```
66
-
67
- #### `ClassificationResult`
48
+ #### `ModerationScore`
68
49
 
69
- Result of a single classification attempt against the bonded AI provider.
50
+ Per-category confidence score produced by a moderation classifier.
70
51
 
71
52
  ```typescript
72
- interface ClassificationResult {
73
- scores: ModerationScore[]
74
- reasoning: string
75
- /**
76
- * Set when the classifier FAILED to produce a usable signal — a provider
77
- * error/timeout, an in-band `error` event, or malformed model output. When
78
- * present, `scores` is empty; the pipeline routes per `policy.onError`
79
- * instead of treating the empty scores as an allow. `moderate()` handles this
80
- * for you; direct `classify()` callers MUST check `error` before trusting an
81
- * empty-scores result.
82
- */
83
- error?: Error
53
+ interface ModerationScore {
54
+ category: ModerationCategory
55
+ /** 0..1 confidence. */
56
+ score: number
84
57
  }
85
58
  ```
86
59
 
@@ -107,6 +80,26 @@ interface ModerationDecision {
107
80
  }
108
81
  ```
109
82
 
83
+ #### `ClassificationResult`
84
+
85
+ Result of a single classification attempt against the bonded AI provider.
86
+
87
+ ```typescript
88
+ interface ClassificationResult {
89
+ scores: ModerationScore[]
90
+ reasoning: string
91
+ /**
92
+ * Set when the classifier FAILED to produce a usable signal — a provider
93
+ * error/timeout, an in-band `error` event, or malformed model output. When
94
+ * present, `scores` is empty; the pipeline routes per `policy.onError`
95
+ * instead of treating the empty scores as an allow. `moderate()` handles this
96
+ * for you; direct `classify()` callers MUST check `error` before trusting an
97
+ * empty-scores result.
98
+ */
99
+ error?: Error
100
+ }
101
+ ```
102
+
110
103
  #### `ModerationPolicy`
111
104
 
112
105
  Per-category thresholds and actions that govern moderation decisions.
@@ -131,28 +124,27 @@ interface ModerationPolicy {
131
124
  }
132
125
  ```
133
126
 
134
- #### `ModerationScore`
127
+ #### `AuditLogRow`
135
128
 
136
- Per-category confidence score produced by a moderation classifier.
129
+ Database row shape for a single moderation audit-log entry.
137
130
 
138
131
  ```typescript
139
- interface ModerationScore {
140
- category: ModerationCategory
141
- /** 0..1 confidence. */
142
- score: number
132
+ interface AuditLogRow {
133
+ id: string
134
+ owner_id: string | null
135
+ content_excerpt: string
136
+ decision: ModerationAction
137
+ matched_category: ModerationCategory | null
138
+ scores: ModerationScore[]
139
+ reasoning: string
140
+ resource_type: string | null
141
+ resource_id: string | null
142
+ created_at: string | Date
143
143
  }
144
144
  ```
145
145
 
146
146
  ### Types
147
147
 
148
- #### `ModerationAction`
149
-
150
- Action the pipeline takes after evaluating content against policy.
151
-
152
- ```typescript
153
- type ModerationAction = 'allow' | 'flag' | 'block' | 'redact'
154
- ```
155
-
156
148
  #### `ModerationCategory`
157
149
 
158
150
  Content category assigned by the moderation pipeline.
@@ -171,6 +163,14 @@ type ModerationCategory =
171
163
  | 'safe'
172
164
  ```
173
165
 
166
+ #### `ModerationAction`
167
+
168
+ Action the pipeline takes after evaluating content against policy.
169
+
170
+ ```typescript
171
+ type ModerationAction = 'allow' | 'flag' | 'block' | 'redact'
172
+ ```
173
+
174
174
  #### `ModerationErrorAction`
175
175
 
176
176
  Action taken when the classifier itself FAILS to produce a usable signal —
@@ -188,18 +188,6 @@ type ModerationErrorAction = 'allow' | 'flag' | 'block'
188
188
 
189
189
  ### Functions
190
190
 
191
- #### `applyPolicy(scores, reasoning, policy?)`
192
-
193
- Apply a policy to classifier scores → moderation decision.
194
-
195
- ```typescript
196
- function applyPolicy(
197
- scores: ModerationScore[],
198
- reasoning: string,
199
- policy?: ModerationPolicy,
200
- ): ModerationDecision
201
- ```
202
-
203
191
  #### `classify(content)`
204
192
 
205
193
  Classify content using the bonded AI provider.
@@ -219,6 +207,18 @@ function classify(content: string): Promise<ClassificationResult>
219
207
 
220
208
  **Returns:** The classification result — scores + reasoning, or `error` on failure.
221
209
 
210
+ #### `applyPolicy(scores, reasoning, policy?)`
211
+
212
+ Apply a policy to classifier scores → moderation decision.
213
+
214
+ ```typescript
215
+ function applyPolicy(
216
+ scores: ModerationScore[],
217
+ reasoning: string,
218
+ policy?: ModerationPolicy,
219
+ ): ModerationDecision
220
+ ```
221
+
222
222
  #### `moderate(opts)`
223
223
 
224
224
  Full pipeline — classify + decide + audit. Returns the decision.
@@ -229,6 +229,7 @@ function moderate(opts: {
229
229
  policy?: ModerationPolicy
230
230
  ownerId?: string | null
231
231
  resource?: { type: string; id: string }
232
+ /** Whether to write the audit log row. Defaults to true. */
232
233
  audit?: boolean
233
234
  }): Promise<ModerationDecision>
234
235
  ```
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/api-ai-moderation-pipeline",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "AI content moderation pipeline — classify, policy-match, action, audit-log",
5
5
  "homepage": "https://www.molecule.dev/packages/api-ai-moderation-pipeline",
6
6
  "type": "module",
@@ -37,10 +37,10 @@
37
37
  "directory": "packages/api/ai/moderation-pipeline"
38
38
  },
39
39
  "devDependencies": {
40
- "@molecule/api-logger": "1.0.2",
41
- "@types/node": "26.1.2",
40
+ "@molecule/api-logger": "1.0.3",
41
+ "@types/node": "26.6.5",
42
42
  "typescript": "6.0.3",
43
- "vitest": "4.1.11"
43
+ "vitest": "4.1.12"
44
44
  },
45
45
  "peerDependencies": {
46
46
  "@molecule/api-bonds-default-express": "^1.0.1",