@agentxin-ai/plugin-sensitive-filter 0.0.3
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/README.md +105 -0
- package/package.json +44 -0
package/README.md
ADDED
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Sensitive Filter Middleware
|
|
2
|
+
|
|
3
|
+
`@agentxin-ai/plugin-sensitive-filter` filters sensitive content for both input and output in two mutually exclusive modes:
|
|
4
|
+
|
|
5
|
+
- `rule`: deterministic rules (`keyword` / `regex`)
|
|
6
|
+
- `llm`: natural-language policy evaluation with rewrite-only enforcement
|
|
7
|
+
|
|
8
|
+
## Lifecycle Hooks
|
|
9
|
+
|
|
10
|
+
- `beforeAgent`: evaluates and optionally rewrites/blocks input
|
|
11
|
+
- `wrapModelCall`: evaluates and optionally rewrites/blocks output
|
|
12
|
+
- `afterAgent`: writes audit snapshot and sends matched alerts to configured WeCom group webhooks
|
|
13
|
+
|
|
14
|
+
## Configuration
|
|
15
|
+
|
|
16
|
+
### Top-level
|
|
17
|
+
|
|
18
|
+
| Field | Type | Required | Default | Description |
|
|
19
|
+
| --- | --- | --- | --- | --- |
|
|
20
|
+
| `mode` | `'rule' \| 'llm'` | Yes | `rule` | Select one mode. |
|
|
21
|
+
| `rules` | `Array<Rule>` | Runtime-required in `rule` mode | `[]` | Business rules for `rule` mode. |
|
|
22
|
+
| `caseSensitive` | `boolean` | No | `false` | Case-sensitive matching in `rule` mode. |
|
|
23
|
+
| `normalize` | `boolean` | No | `true` | Whitespace normalization in `rule` mode. |
|
|
24
|
+
| `llm` | `object` | Runtime-required in `llm` mode | - | LLM mode configuration. |
|
|
25
|
+
| `wecom` | `object` | No | disabled when no groups | WeCom webhook notification config. |
|
|
26
|
+
|
|
27
|
+
### WeCom Notify (`wecom`)
|
|
28
|
+
|
|
29
|
+
| Field | Type | Required | Default | Description |
|
|
30
|
+
| --- | --- | --- | --- | --- |
|
|
31
|
+
| `enabled` | `boolean` | No | `true` | Turn notification on/off. |
|
|
32
|
+
| `groups` | `Array<{webhookUrl}>` | Runtime-required for sending | `[]` | One or more WeCom group webhook targets. |
|
|
33
|
+
| `timeoutMs` | `number` | No | `10000` | Per webhook request timeout (max `120000`). |
|
|
34
|
+
|
|
35
|
+
### Rule Mode (`mode=rule`)
|
|
36
|
+
|
|
37
|
+
`rules[]` fields:
|
|
38
|
+
|
|
39
|
+
| Field | Type | Required | Description |
|
|
40
|
+
| --- | --- | --- | --- |
|
|
41
|
+
| `id` | `string` | No | Auto-generated when empty (`rule-{index+1}`). |
|
|
42
|
+
| `pattern` | `string` | Yes | Match pattern. |
|
|
43
|
+
| `type` | `'keyword' \| 'regex'` | Yes | Match type. |
|
|
44
|
+
| `scope` | `'input' \| 'output' \| 'both'` | Yes | Match phase. |
|
|
45
|
+
| `severity` | `'high' \| 'medium'` | Yes | Conflict priority (`high` > `medium`). |
|
|
46
|
+
| `action` | `'block' \| 'rewrite'` | Yes | Hit action. |
|
|
47
|
+
| `replacementText` | `string` | No | Optional replacement/block message. |
|
|
48
|
+
|
|
49
|
+
Runtime validation requires at least one valid rule with:
|
|
50
|
+
`pattern/type/action/scope/severity`.
|
|
51
|
+
|
|
52
|
+
### LLM Mode (`mode=llm`)
|
|
53
|
+
|
|
54
|
+
| Field | Type | Required (runtime) | Default | Description |
|
|
55
|
+
| --- | --- | --- | --- | --- |
|
|
56
|
+
| `model` | `ICopilotModel` | Yes | - | Policy evaluation model. |
|
|
57
|
+
| `scope` | `'input' \| 'output' \| 'both'` | Yes | - | Evaluation phase scope. |
|
|
58
|
+
| `rulePrompt` | `string` | Yes | - | Natural-language policy description. |
|
|
59
|
+
| `rewriteFallbackText` | `string` | No | `[已过滤]` | Fallback rewrite text. |
|
|
60
|
+
| `timeoutMs` | `number` | No | unlimited | Per-evaluation timeout (max `120000`). |
|
|
61
|
+
|
|
62
|
+
Notes:
|
|
63
|
+
|
|
64
|
+
- The middleware internally enforces rewrite-only behavior for LLM hits.
|
|
65
|
+
- Structured output method is internally adaptive; the UI does not expose method selection.
|
|
66
|
+
- Internal decision traces are muted from chat output.
|
|
67
|
+
- Notifications are sent only when there is at least one matched record.
|
|
68
|
+
|
|
69
|
+
## Backward Compatibility
|
|
70
|
+
|
|
71
|
+
Historical configurations may still include `generalPack`.
|
|
72
|
+
|
|
73
|
+
Current behavior:
|
|
74
|
+
|
|
75
|
+
- The field is ignored.
|
|
76
|
+
- Execution continues.
|
|
77
|
+
- Rule/LLM behavior is driven only by current supported fields.
|
|
78
|
+
|
|
79
|
+
## Minimal LLM Example
|
|
80
|
+
|
|
81
|
+
```json
|
|
82
|
+
{
|
|
83
|
+
"mode": "llm",
|
|
84
|
+
"llm": {
|
|
85
|
+
"model": { "provider": "openai", "model": "gpt-4o-mini" },
|
|
86
|
+
"scope": "both",
|
|
87
|
+
"rulePrompt": "If content contains ID cards, phone numbers, bank cards, or home addresses, rewrite it into a privacy-safe response.",
|
|
88
|
+
"rewriteFallbackText": "[已过滤]",
|
|
89
|
+
"timeoutMs": 3000
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
## Troubleshooting
|
|
95
|
+
|
|
96
|
+
1. No effect in `rule` mode:
|
|
97
|
+
- Ensure at least one valid rule contains `pattern/type/action/scope/severity`.
|
|
98
|
+
|
|
99
|
+
2. No effect in `llm` mode:
|
|
100
|
+
- Ensure `model/scope/rulePrompt` are all present.
|
|
101
|
+
|
|
102
|
+
3. Unexpected rewrites in LLM mode:
|
|
103
|
+
- Check audit records or runtime logs for entries with `source=error-policy` and `reason` starting with `llm-error:`.
|
|
104
|
+
|
|
105
|
+
## Validation Commands
|
package/package.json
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@agentxin-ai/plugin-sensitive-filter",
|
|
3
|
+
"version": "0.0.3",
|
|
4
|
+
"author": {
|
|
5
|
+
"name": "AgentXinAI",
|
|
6
|
+
"url": "https://agentxinai.cn"
|
|
7
|
+
},
|
|
8
|
+
"license": "AGPL-3.0",
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/agentxin-ai/agentxin-plugins.git"
|
|
12
|
+
},
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "https://github.com/agentxin-ai/agentxin-plugins/issues"
|
|
15
|
+
},
|
|
16
|
+
"type": "module",
|
|
17
|
+
"main": "./dist/index.js",
|
|
18
|
+
"module": "./dist/index.js",
|
|
19
|
+
"types": "./dist/index.d.ts",
|
|
20
|
+
"exports": {
|
|
21
|
+
"./package.json": "./package.json",
|
|
22
|
+
".": {
|
|
23
|
+
"@agentxin-plugins-starter/source": "./src/index.ts",
|
|
24
|
+
"types": "./dist/index.d.ts",
|
|
25
|
+
"import": "./dist/index.js",
|
|
26
|
+
"default": "./dist/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"files": [
|
|
30
|
+
"dist",
|
|
31
|
+
"!**/*.tsbuildinfo"
|
|
32
|
+
],
|
|
33
|
+
"dependencies": {
|
|
34
|
+
"tslib": "^2.3.0"
|
|
35
|
+
},
|
|
36
|
+
"peerDependencies": {
|
|
37
|
+
"zod": "3.25.67",
|
|
38
|
+
"@agentxin-ai/plugin-sdk": "^3.8.1",
|
|
39
|
+
"chalk": "4.1.2",
|
|
40
|
+
"@langchain/core": "0.3.72",
|
|
41
|
+
"@nestjs/common": "^11.1.6",
|
|
42
|
+
"@metad/contracts": "^3.8.1"
|
|
43
|
+
}
|
|
44
|
+
}
|