@yadsh/dsh-prompt-firewall 0.1.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/LICENSE +21 -0
- package/README.md +165 -0
- package/cordis.patch.yml +4 -0
- package/lib/audit.js +121 -0
- package/lib/audit.js.map +1 -0
- package/lib/client/index.js +155 -0
- package/lib/client/index.js.map +1 -0
- package/lib/client/styles.js +7 -0
- package/lib/client/styles.js.map +1 -0
- package/lib/client.js +5857 -0
- package/lib/client.js.map +1 -0
- package/lib/config.js +100 -0
- package/lib/config.js.map +1 -0
- package/lib/firewall.js +88 -0
- package/lib/firewall.js.map +1 -0
- package/lib/index.js +166 -0
- package/lib/index.js.map +1 -0
- package/lib/metrics.js +38 -0
- package/lib/metrics.js.map +1 -0
- package/lib/presets.js +23 -0
- package/lib/presets.js.map +1 -0
- package/lib/rules.js +103 -0
- package/lib/rules.js.map +1 -0
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +258 -0
- package/lib/typert.remote-client.d.ts +24 -0
- package/lib/typert.remote-client.js +141 -0
- package/lib/types/audit.d.ts +17 -0
- package/lib/types/client/index.d.ts +4 -0
- package/lib/types/client/styles.d.ts +1 -0
- package/lib/types/config.d.ts +8 -0
- package/lib/types/firewall.d.ts +17 -0
- package/lib/types/index.d.ts +46 -0
- package/lib/types/metrics.d.ts +16 -0
- package/lib/types/presets.d.ts +4 -0
- package/lib/types/rules.d.ts +25 -0
- package/lib/types/types.d.ts +125 -0
- package/lib/types.js +2 -0
- package/lib/types.js.map +1 -0
- package/package.json +124 -0
|
@@ -0,0 +1,258 @@
|
|
|
1
|
+
/* Generated by @deepseek-ai/dsh-typert-generator from FaceModel — do not edit. */
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
|
|
4
|
+
const _yadsh_dsh_prompt_firewall_promptFirewall_inspect_result$schema = z.object({
|
|
5
|
+
'config': z.object({
|
|
6
|
+
'enabled': z.boolean().readonly(),
|
|
7
|
+
'mode': z.union([z.literal("off"), z.literal("audit"), z.literal("blocklist"), z.literal("allowlist")]).readonly(),
|
|
8
|
+
'preset': z.union([z.literal("clean"), z.literal("strict"), z.literal("audit-only")]).readonly().optional(),
|
|
9
|
+
'blockedSections': z.array(z.string()).readonly(),
|
|
10
|
+
'allowedSections': z.array(z.string()).readonly(),
|
|
11
|
+
'blockedPrefixes': z.array(z.string()).readonly(),
|
|
12
|
+
'allowedPrefixes': z.array(z.string()).readonly(),
|
|
13
|
+
'blockedPatterns': z.array(z.string()).readonly(),
|
|
14
|
+
'allowedPatterns': z.array(z.string()).readonly(),
|
|
15
|
+
'protectedSections': z.array(z.string()).readonly(),
|
|
16
|
+
'protectCoreSections': z.boolean().readonly(),
|
|
17
|
+
'unknownPluginPolicy': z.union([z.literal("allow"), z.literal("block")]).readonly(),
|
|
18
|
+
'audit': z.object({
|
|
19
|
+
'enabled': z.boolean(),
|
|
20
|
+
'logAllowed': z.boolean(),
|
|
21
|
+
'logBlocked': z.boolean(),
|
|
22
|
+
'includePreview': z.boolean(),
|
|
23
|
+
'previewChars': z.number(),
|
|
24
|
+
'historySize': z.number(),
|
|
25
|
+
'highlightNewSections': z.boolean(),
|
|
26
|
+
}).readonly(),
|
|
27
|
+
'metrics': z.object({
|
|
28
|
+
'enabled': z.boolean(),
|
|
29
|
+
}).readonly(),
|
|
30
|
+
}),
|
|
31
|
+
'last': z.union([z.literal(null), z.object({
|
|
32
|
+
'timestamp': z.number(),
|
|
33
|
+
'totalSections': z.number(),
|
|
34
|
+
'allowedSections': z.number(),
|
|
35
|
+
'blockedSections': z.number(),
|
|
36
|
+
'charsBefore': z.number(),
|
|
37
|
+
'charsAfter': z.number(),
|
|
38
|
+
'charsRemoved': z.number(),
|
|
39
|
+
'estimatedTokensBefore': z.number(),
|
|
40
|
+
'estimatedTokensAfter': z.number(),
|
|
41
|
+
'estimatedTokensRemoved': z.number(),
|
|
42
|
+
'sections': z.array(z.object({
|
|
43
|
+
'name': z.string(),
|
|
44
|
+
'decision': z.union([z.literal("allowed"), z.literal("blocked"), z.literal("protected")]),
|
|
45
|
+
'reason': z.string(),
|
|
46
|
+
'chars': z.number(),
|
|
47
|
+
'estimatedTokens': z.number(),
|
|
48
|
+
'preview': z.string().optional(),
|
|
49
|
+
'suspicious': z.boolean().optional(),
|
|
50
|
+
'isNew': z.boolean().optional(),
|
|
51
|
+
})),
|
|
52
|
+
'bypassed': z.boolean().optional(),
|
|
53
|
+
'bypassReason': z.string().optional(),
|
|
54
|
+
})]),
|
|
55
|
+
'knownSections': z.array(z.object({
|
|
56
|
+
'name': z.string(),
|
|
57
|
+
'firstSeenAt': z.number(),
|
|
58
|
+
'lastSeenAt': z.number(),
|
|
59
|
+
'observations': z.number(),
|
|
60
|
+
})),
|
|
61
|
+
'metrics': z.object({
|
|
62
|
+
'requestsTotal': z.number(),
|
|
63
|
+
'sectionsTotal': z.number(),
|
|
64
|
+
'sectionsBlockedTotal': z.number(),
|
|
65
|
+
'charsRemovedTotal': z.number(),
|
|
66
|
+
'estimatedTokensRemovedTotal': z.number(),
|
|
67
|
+
}),
|
|
68
|
+
})
|
|
69
|
+
const _yadsh_dsh_prompt_firewall_promptFirewall_setSectionPolicy_parameter_0$schema = z.string()
|
|
70
|
+
const _yadsh_dsh_prompt_firewall_promptFirewall_setSectionPolicy_parameter_1$schema = z.union([z.literal("allow"), z.literal("block"), z.literal("protect"), z.literal("clear")])
|
|
71
|
+
const _yadsh_dsh_prompt_firewall_promptFirewall_setSectionPolicy_parameter_2$schema = z.union([z.undefined(), z.number()])
|
|
72
|
+
const _yadsh_dsh_prompt_firewall_promptFirewall_setSectionPolicy_result$schema = z.void()
|
|
73
|
+
|
|
74
|
+
export const TYPERT = {
|
|
75
|
+
package: '@yadsh/dsh-prompt-firewall',
|
|
76
|
+
face: 'host',
|
|
77
|
+
schemas: [
|
|
78
|
+
],
|
|
79
|
+
invocations: [
|
|
80
|
+
{
|
|
81
|
+
id: '@yadsh/dsh-prompt-firewall#promptFirewall/inspect',
|
|
82
|
+
service: 'promptFirewall',
|
|
83
|
+
namespace: 'promptFirewall',
|
|
84
|
+
method: 'inspect',
|
|
85
|
+
invocation: { kind: 'direct' },
|
|
86
|
+
parameters: [
|
|
87
|
+
],
|
|
88
|
+
result: {
|
|
89
|
+
mode: 'strict',
|
|
90
|
+
typeSymbol: '@yadsh/dsh-prompt-firewall/types#PromptFirewallInspectorSnapshot',
|
|
91
|
+
schema: _yadsh_dsh_prompt_firewall_promptFirewall_inspect_result$schema,
|
|
92
|
+
},
|
|
93
|
+
sourceLocation: {"file":"packages/dsh-prompt-firewall/src/index.ts","line":120,"column":3},
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
id: '@yadsh/dsh-prompt-firewall#promptFirewall/setSectionPolicy',
|
|
97
|
+
service: 'promptFirewall',
|
|
98
|
+
namespace: 'promptFirewall',
|
|
99
|
+
method: 'setSectionPolicy',
|
|
100
|
+
invocation: { kind: 'direct' },
|
|
101
|
+
parameters: [
|
|
102
|
+
{
|
|
103
|
+
name: 'name',
|
|
104
|
+
wire: 'name',
|
|
105
|
+
source: 'json',
|
|
106
|
+
codec: {
|
|
107
|
+
mode: 'strict',
|
|
108
|
+
typeSymbol: '@yadsh/dsh-prompt-firewall#promptFirewall/setSectionPolicy:name',
|
|
109
|
+
schema: _yadsh_dsh_prompt_firewall_promptFirewall_setSectionPolicy_parameter_0$schema,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
{
|
|
113
|
+
name: 'policy',
|
|
114
|
+
wire: 'policy',
|
|
115
|
+
source: 'json',
|
|
116
|
+
codec: {
|
|
117
|
+
mode: 'strict',
|
|
118
|
+
typeSymbol: '@yadsh/dsh-prompt-firewall/types#SectionPolicy',
|
|
119
|
+
schema: _yadsh_dsh_prompt_firewall_promptFirewall_setSectionPolicy_parameter_1$schema,
|
|
120
|
+
},
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: 'expectedRevision',
|
|
124
|
+
wire: 'expectedRevision',
|
|
125
|
+
source: 'json',
|
|
126
|
+
acceptsUndefined: true,
|
|
127
|
+
codec: {
|
|
128
|
+
mode: 'strict',
|
|
129
|
+
typeSymbol: '@yadsh/dsh-prompt-firewall#promptFirewall/setSectionPolicy:expectedRevision',
|
|
130
|
+
schema: _yadsh_dsh_prompt_firewall_promptFirewall_setSectionPolicy_parameter_2$schema,
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
],
|
|
134
|
+
result: {
|
|
135
|
+
mode: 'strict',
|
|
136
|
+
typeSymbol: '@yadsh/dsh-prompt-firewall#promptFirewall/setSectionPolicy:result',
|
|
137
|
+
schema: _yadsh_dsh_prompt_firewall_promptFirewall_setSectionPolicy_result$schema,
|
|
138
|
+
},
|
|
139
|
+
sourceLocation: {"file":"packages/dsh-prompt-firewall/src/index.ts","line":134,"column":9},
|
|
140
|
+
},
|
|
141
|
+
],
|
|
142
|
+
model: {
|
|
143
|
+
"services": [
|
|
144
|
+
{
|
|
145
|
+
"tags": [],
|
|
146
|
+
"key": "promptFirewall",
|
|
147
|
+
"exportName": "PromptFirewallService",
|
|
148
|
+
"members": [
|
|
149
|
+
{
|
|
150
|
+
"kind": "method",
|
|
151
|
+
"name": "inspect",
|
|
152
|
+
"signature": "inspect(): PromptFirewallInspectorSnapshot"
|
|
153
|
+
},
|
|
154
|
+
{
|
|
155
|
+
"kind": "method",
|
|
156
|
+
"name": "inspectLast",
|
|
157
|
+
"signature": "inspectLast(): PromptAuditResult | null"
|
|
158
|
+
},
|
|
159
|
+
{
|
|
160
|
+
"kind": "method",
|
|
161
|
+
"name": "inspectHistory",
|
|
162
|
+
"signature": "inspectHistory(): PromptAuditResult[]"
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
"kind": "method",
|
|
166
|
+
"name": "getKnownSections",
|
|
167
|
+
"signature": "getKnownSections(): KnownSection[]"
|
|
168
|
+
},
|
|
169
|
+
{
|
|
170
|
+
"kind": "method",
|
|
171
|
+
"name": "getMetrics",
|
|
172
|
+
"signature": "getMetrics(): PromptFirewallMetricsSnapshot"
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
"kind": "method",
|
|
176
|
+
"name": "getConfig",
|
|
177
|
+
"signature": "getConfig(): ResolvedPromptFirewallConfig"
|
|
178
|
+
},
|
|
179
|
+
{
|
|
180
|
+
"kind": "method",
|
|
181
|
+
"name": "evaluateSection",
|
|
182
|
+
"signature": "evaluateSection(section: AssembledSection): FirewallDecision"
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
"kind": "method",
|
|
186
|
+
"name": "setSectionPolicy",
|
|
187
|
+
"signature": "setSectionPolicy(name: string, policy: SectionPolicy, expectedRevision?: number): Promise<void>"
|
|
188
|
+
},
|
|
189
|
+
{
|
|
190
|
+
"kind": "method",
|
|
191
|
+
"name": "reloadRules",
|
|
192
|
+
"signature": "reloadRules(): void"
|
|
193
|
+
}
|
|
194
|
+
],
|
|
195
|
+
"types": [
|
|
196
|
+
{
|
|
197
|
+
"name": "AuditConfig",
|
|
198
|
+
"declaration": "export interface AuditConfig {\n enabled: boolean;\n logAllowed: boolean;\n logBlocked: boolean;\n includePreview: boolean;\n previewChars: number;\n historySize: number;\n highlightNewSections: boolean;\n}"
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
"name": "FirewallAction",
|
|
202
|
+
"declaration": "export type FirewallAction = 'allow' | 'block' | 'protect';"
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
"name": "FirewallDecision",
|
|
206
|
+
"declaration": "export interface FirewallDecision {\n action: FirewallAction;\n reason: string;\n rule?: string;\n}"
|
|
207
|
+
},
|
|
208
|
+
{
|
|
209
|
+
"name": "FirewallMode",
|
|
210
|
+
"declaration": "export type FirewallMode = 'off' | 'audit' | 'blocklist' | 'allowlist';"
|
|
211
|
+
},
|
|
212
|
+
{
|
|
213
|
+
"name": "FirewallPreset",
|
|
214
|
+
"declaration": "export type FirewallPreset = 'clean' | 'strict' | 'audit-only';"
|
|
215
|
+
},
|
|
216
|
+
{
|
|
217
|
+
"name": "KnownSection",
|
|
218
|
+
"declaration": "export interface KnownSection {\n name: string;\n firstSeenAt: number;\n lastSeenAt: number;\n observations: number;\n}"
|
|
219
|
+
},
|
|
220
|
+
{
|
|
221
|
+
"name": "MetricsConfig",
|
|
222
|
+
"declaration": "export interface MetricsConfig {\n enabled: boolean;\n}"
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
"name": "PromptAuditResult",
|
|
226
|
+
"declaration": "export interface PromptAuditResult {\n timestamp: number;\n totalSections: number;\n allowedSections: number;\n blockedSections: number;\n charsBefore: number;\n charsAfter: number;\n charsRemoved: number;\n estimatedTokensBefore: number;\n estimatedTokensAfter: number;\n estimatedTokensRemoved: number;\n sections: PromptSectionAudit[];\n bypassed?: boolean;\n bypassReason?: string;\n}"
|
|
227
|
+
},
|
|
228
|
+
{
|
|
229
|
+
"name": "PromptFirewallInspectorSnapshot",
|
|
230
|
+
"declaration": "export interface PromptFirewallInspectorSnapshot {\n config: ResolvedPromptFirewallConfig;\n last: PromptAuditResult | null;\n knownSections: KnownSection[];\n metrics: PromptFirewallMetricsSnapshot;\n}"
|
|
231
|
+
},
|
|
232
|
+
{
|
|
233
|
+
"name": "PromptFirewallMetricsSnapshot",
|
|
234
|
+
"declaration": "export interface PromptFirewallMetricsSnapshot {\n requestsTotal: number;\n sectionsTotal: number;\n sectionsBlockedTotal: number;\n charsRemovedTotal: number;\n estimatedTokensRemovedTotal: number;\n}"
|
|
235
|
+
},
|
|
236
|
+
{
|
|
237
|
+
"name": "PromptSectionAudit",
|
|
238
|
+
"declaration": "export interface PromptSectionAudit {\n name: string;\n decision: 'allowed' | 'blocked' | 'protected';\n reason: string;\n chars: number;\n estimatedTokens: number;\n preview?: string;\n suspicious?: boolean;\n isNew?: boolean;\n}"
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
"name": "ResolvedPromptFirewallConfig",
|
|
242
|
+
"declaration": "export interface ResolvedPromptFirewallConfig {\n readonly enabled: boolean;\n readonly mode: FirewallMode;\n readonly preset?: FirewallPreset;\n readonly blockedSections: readonly string[];\n readonly allowedSections: readonly string[];\n readonly blockedPrefixes: readonly string[];\n readonly allowedPrefixes: readonly string[];\n readonly blockedPatterns: readonly string[];\n readonly allowedPatterns: readonly string[];\n readonly protectedSections: readonly string[];\n readonly protectCoreSections: boolean;\n readonly unknownPluginPolicy: UnknownPluginPolicy;\n readonly audit: Readonly<AuditConfig>;\n readonly metrics: Readonly<MetricsConfig>;\n}"
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
"name": "SectionPolicy",
|
|
246
|
+
"declaration": "export type SectionPolicy = FirewallAction | 'clear';"
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
"name": "UnknownPluginPolicy",
|
|
250
|
+
"declaration": "export type UnknownPluginPolicy = 'allow' | 'block';"
|
|
251
|
+
}
|
|
252
|
+
]
|
|
253
|
+
}
|
|
254
|
+
],
|
|
255
|
+
"events": [],
|
|
256
|
+
"objects": []
|
|
257
|
+
},
|
|
258
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/* Generated by @deepseek-ai/dsh-typert-generator from the Host FaceModel — do not edit. */
|
|
2
|
+
import type {
|
|
3
|
+
RemoteResult,
|
|
4
|
+
TypertRemoteContribution,
|
|
5
|
+
} from '@deepseek-ai/dsh-typert-protocol'
|
|
6
|
+
import type { PromptFirewallInspectorSnapshot, SectionPolicy } from '@yadsh/dsh-prompt-firewall/types'
|
|
7
|
+
|
|
8
|
+
declare module '@deepseek-ai/dsh-typert-protocol' {
|
|
9
|
+
interface TypertRemoteNamespace$70726f6d70744669726577616c6c {
|
|
10
|
+
inspect: () => Promise<RemoteResult<PromptFirewallInspectorSnapshot>>
|
|
11
|
+
setSectionPolicy: (name: string, policy: SectionPolicy, expectedRevision?: number) => Promise<RemoteResult<void>>
|
|
12
|
+
}
|
|
13
|
+
interface TypertRemoteMap {
|
|
14
|
+
'promptFirewall/inspect': () => Promise<RemoteResult<PromptFirewallInspectorSnapshot>>
|
|
15
|
+
'promptFirewall/setSectionPolicy': (name: string, policy: SectionPolicy, expectedRevision?: number) => Promise<RemoteResult<void>>
|
|
16
|
+
}
|
|
17
|
+
interface TypertRemoteNamespaceMap {
|
|
18
|
+
'promptFirewall': TypertRemoteNamespace$70726f6d70744669726577616c6c
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export declare const TYPERT_REMOTE: TypertRemoteContribution
|
|
23
|
+
export default TYPERT_REMOTE
|
|
24
|
+
//# sourceMappingURL=typert.remote-client.d.ts.map
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
/* Generated by @deepseek-ai/dsh-typert-generator from the Host FaceModel — do not edit. */
|
|
2
|
+
import { z } from 'zod'
|
|
3
|
+
|
|
4
|
+
const _yadsh_dsh_prompt_firewall_promptFirewall_inspect_result$schema = z.object({
|
|
5
|
+
'config': z.object({
|
|
6
|
+
'enabled': z.boolean().readonly(),
|
|
7
|
+
'mode': z.union([z.literal("off"), z.literal("audit"), z.literal("blocklist"), z.literal("allowlist")]).readonly(),
|
|
8
|
+
'preset': z.union([z.literal("clean"), z.literal("strict"), z.literal("audit-only")]).readonly().optional(),
|
|
9
|
+
'blockedSections': z.array(z.string()).readonly(),
|
|
10
|
+
'allowedSections': z.array(z.string()).readonly(),
|
|
11
|
+
'blockedPrefixes': z.array(z.string()).readonly(),
|
|
12
|
+
'allowedPrefixes': z.array(z.string()).readonly(),
|
|
13
|
+
'blockedPatterns': z.array(z.string()).readonly(),
|
|
14
|
+
'allowedPatterns': z.array(z.string()).readonly(),
|
|
15
|
+
'protectedSections': z.array(z.string()).readonly(),
|
|
16
|
+
'protectCoreSections': z.boolean().readonly(),
|
|
17
|
+
'unknownPluginPolicy': z.union([z.literal("allow"), z.literal("block")]).readonly(),
|
|
18
|
+
'audit': z.object({
|
|
19
|
+
'enabled': z.boolean(),
|
|
20
|
+
'logAllowed': z.boolean(),
|
|
21
|
+
'logBlocked': z.boolean(),
|
|
22
|
+
'includePreview': z.boolean(),
|
|
23
|
+
'previewChars': z.number(),
|
|
24
|
+
'historySize': z.number(),
|
|
25
|
+
'highlightNewSections': z.boolean(),
|
|
26
|
+
}).readonly(),
|
|
27
|
+
'metrics': z.object({
|
|
28
|
+
'enabled': z.boolean(),
|
|
29
|
+
}).readonly(),
|
|
30
|
+
}),
|
|
31
|
+
'last': z.union([z.literal(null), z.object({
|
|
32
|
+
'timestamp': z.number(),
|
|
33
|
+
'totalSections': z.number(),
|
|
34
|
+
'allowedSections': z.number(),
|
|
35
|
+
'blockedSections': z.number(),
|
|
36
|
+
'charsBefore': z.number(),
|
|
37
|
+
'charsAfter': z.number(),
|
|
38
|
+
'charsRemoved': z.number(),
|
|
39
|
+
'estimatedTokensBefore': z.number(),
|
|
40
|
+
'estimatedTokensAfter': z.number(),
|
|
41
|
+
'estimatedTokensRemoved': z.number(),
|
|
42
|
+
'sections': z.array(z.object({
|
|
43
|
+
'name': z.string(),
|
|
44
|
+
'decision': z.union([z.literal("allowed"), z.literal("blocked"), z.literal("protected")]),
|
|
45
|
+
'reason': z.string(),
|
|
46
|
+
'chars': z.number(),
|
|
47
|
+
'estimatedTokens': z.number(),
|
|
48
|
+
'preview': z.string().optional(),
|
|
49
|
+
'suspicious': z.boolean().optional(),
|
|
50
|
+
'isNew': z.boolean().optional(),
|
|
51
|
+
})),
|
|
52
|
+
'bypassed': z.boolean().optional(),
|
|
53
|
+
'bypassReason': z.string().optional(),
|
|
54
|
+
})]),
|
|
55
|
+
'knownSections': z.array(z.object({
|
|
56
|
+
'name': z.string(),
|
|
57
|
+
'firstSeenAt': z.number(),
|
|
58
|
+
'lastSeenAt': z.number(),
|
|
59
|
+
'observations': z.number(),
|
|
60
|
+
})),
|
|
61
|
+
'metrics': z.object({
|
|
62
|
+
'requestsTotal': z.number(),
|
|
63
|
+
'sectionsTotal': z.number(),
|
|
64
|
+
'sectionsBlockedTotal': z.number(),
|
|
65
|
+
'charsRemovedTotal': z.number(),
|
|
66
|
+
'estimatedTokensRemovedTotal': z.number(),
|
|
67
|
+
}),
|
|
68
|
+
})
|
|
69
|
+
const _yadsh_dsh_prompt_firewall_promptFirewall_setSectionPolicy_parameter_0$schema = z.string()
|
|
70
|
+
const _yadsh_dsh_prompt_firewall_promptFirewall_setSectionPolicy_parameter_1$schema = z.union([z.literal("allow"), z.literal("block"), z.literal("protect"), z.literal("clear")])
|
|
71
|
+
const _yadsh_dsh_prompt_firewall_promptFirewall_setSectionPolicy_parameter_2$schema = z.union([z.undefined(), z.number()])
|
|
72
|
+
const _yadsh_dsh_prompt_firewall_promptFirewall_setSectionPolicy_result$schema = z.void()
|
|
73
|
+
|
|
74
|
+
export const TYPERT_REMOTE = {
|
|
75
|
+
package: '@yadsh/dsh-prompt-firewall',
|
|
76
|
+
descriptors: [
|
|
77
|
+
{
|
|
78
|
+
id: '@yadsh/dsh-prompt-firewall#promptFirewall/inspect',
|
|
79
|
+
service: 'promptFirewall',
|
|
80
|
+
namespace: 'promptFirewall',
|
|
81
|
+
method: 'inspect',
|
|
82
|
+
invocation: { kind: 'direct' },
|
|
83
|
+
parameters: [
|
|
84
|
+
],
|
|
85
|
+
result: {
|
|
86
|
+
mode: 'strict',
|
|
87
|
+
typeSymbol: '@yadsh/dsh-prompt-firewall/types#PromptFirewallInspectorSnapshot',
|
|
88
|
+
schema: _yadsh_dsh_prompt_firewall_promptFirewall_inspect_result$schema,
|
|
89
|
+
},
|
|
90
|
+
sourceLocation: {"file":"packages/dsh-prompt-firewall/src/index.ts","line":120,"column":3},
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
id: '@yadsh/dsh-prompt-firewall#promptFirewall/setSectionPolicy',
|
|
94
|
+
service: 'promptFirewall',
|
|
95
|
+
namespace: 'promptFirewall',
|
|
96
|
+
method: 'setSectionPolicy',
|
|
97
|
+
invocation: { kind: 'direct' },
|
|
98
|
+
parameters: [
|
|
99
|
+
{
|
|
100
|
+
name: 'name',
|
|
101
|
+
wire: 'name',
|
|
102
|
+
source: 'json',
|
|
103
|
+
codec: {
|
|
104
|
+
mode: 'strict',
|
|
105
|
+
typeSymbol: '@yadsh/dsh-prompt-firewall#promptFirewall/setSectionPolicy:name',
|
|
106
|
+
schema: _yadsh_dsh_prompt_firewall_promptFirewall_setSectionPolicy_parameter_0$schema,
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
{
|
|
110
|
+
name: 'policy',
|
|
111
|
+
wire: 'policy',
|
|
112
|
+
source: 'json',
|
|
113
|
+
codec: {
|
|
114
|
+
mode: 'strict',
|
|
115
|
+
typeSymbol: '@yadsh/dsh-prompt-firewall/types#SectionPolicy',
|
|
116
|
+
schema: _yadsh_dsh_prompt_firewall_promptFirewall_setSectionPolicy_parameter_1$schema,
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
{
|
|
120
|
+
name: 'expectedRevision',
|
|
121
|
+
wire: 'expectedRevision',
|
|
122
|
+
source: 'json',
|
|
123
|
+
acceptsUndefined: true,
|
|
124
|
+
codec: {
|
|
125
|
+
mode: 'strict',
|
|
126
|
+
typeSymbol: '@yadsh/dsh-prompt-firewall#promptFirewall/setSectionPolicy:expectedRevision',
|
|
127
|
+
schema: _yadsh_dsh_prompt_firewall_promptFirewall_setSectionPolicy_parameter_2$schema,
|
|
128
|
+
},
|
|
129
|
+
},
|
|
130
|
+
],
|
|
131
|
+
result: {
|
|
132
|
+
mode: 'strict',
|
|
133
|
+
typeSymbol: '@yadsh/dsh-prompt-firewall#promptFirewall/setSectionPolicy:result',
|
|
134
|
+
schema: _yadsh_dsh_prompt_firewall_promptFirewall_setSectionPolicy_result$schema,
|
|
135
|
+
},
|
|
136
|
+
sourceLocation: {"file":"packages/dsh-prompt-firewall/src/index.ts","line":134,"column":9},
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
export default TYPERT_REMOTE
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { AuditConfig, FirewallDecision, FirewallSection, KnownSection, PromptAuditResult, PromptSectionAudit } from './types.js';
|
|
2
|
+
export declare function estimateTokens(chars: number): number;
|
|
3
|
+
export declare function looksLikeAnnouncement(text: string): boolean;
|
|
4
|
+
export declare function createSectionAudit(section: FirewallSection, decision: FirewallDecision, config: Readonly<AuditConfig>): PromptSectionAudit;
|
|
5
|
+
export declare function createAuditResult(sections: readonly FirewallSection[], decisions: readonly FirewallDecision[], config: Readonly<AuditConfig>, bypassReason?: string): PromptAuditResult;
|
|
6
|
+
export declare class AuditStore {
|
|
7
|
+
private historySize;
|
|
8
|
+
private highlightNewSections;
|
|
9
|
+
private readonly history;
|
|
10
|
+
private readonly known;
|
|
11
|
+
constructor(historySize: number, highlightNewSections: boolean);
|
|
12
|
+
configure(historySize: number, highlightNewSections?: boolean): void;
|
|
13
|
+
record(result: PromptAuditResult): void;
|
|
14
|
+
last(): PromptAuditResult | null;
|
|
15
|
+
entries(): PromptAuditResult[];
|
|
16
|
+
knownSections(): KnownSection[];
|
|
17
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const styles: string;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import z from '@deepseek-ai/schemastery';
|
|
2
|
+
import type { AuditConfig, MetricsConfig, PromptFirewallConfig, ResolvedPromptFirewallConfig } from './types.js';
|
|
3
|
+
export declare const DEFAULT_AUDIT_CONFIG: Readonly<AuditConfig>;
|
|
4
|
+
export declare const DEFAULT_METRICS_CONFIG: Readonly<MetricsConfig>;
|
|
5
|
+
export declare const DEFAULT_CONFIG: ResolvedPromptFirewallConfig;
|
|
6
|
+
/** Runtime schema consumed by the Cordis loader. */
|
|
7
|
+
export declare const ConfigSchema: z<PromptFirewallConfig>;
|
|
8
|
+
export declare function resolveConfig(config?: PromptFirewallConfig): ResolvedPromptFirewallConfig;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { PromptAssembly } from '@deepseek-ai/dsh-system-prompt';
|
|
2
|
+
import { AuditStore } from './audit.js';
|
|
3
|
+
import type { FirewallMetrics } from './metrics.js';
|
|
4
|
+
import type { FirewallDecision, FirewallLogger, FirewallSection, ResolvedPromptFirewallConfig } from './types.js';
|
|
5
|
+
export type SectionEvaluator = (section: FirewallSection) => FirewallDecision;
|
|
6
|
+
export interface ApplyFirewallOptions {
|
|
7
|
+
config: ResolvedPromptFirewallConfig;
|
|
8
|
+
auditStore?: AuditStore;
|
|
9
|
+
metrics?: FirewallMetrics;
|
|
10
|
+
logger?: FirewallLogger;
|
|
11
|
+
evaluate?: SectionEvaluator;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Filter an already assembled DSH prompt. Any internal error is contained and
|
|
15
|
+
* returns the exact original object (fail-open).
|
|
16
|
+
*/
|
|
17
|
+
export declare function applyFirewall(assembly: PromptAssembly, options: ApplyFirewallOptions): PromptAssembly;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { Context } from '@deepseek-ai/cordis';
|
|
2
|
+
import type { AssembledSection } from '@deepseek-ai/dsh-system-prompt';
|
|
3
|
+
import { TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol';
|
|
4
|
+
import type { FirewallDecision, KnownSection, PromptAuditResult, PromptFirewallConfig, PromptFirewallInspectorSnapshot, PromptFirewallMetricsSnapshot, PromptFirewallService, ResolvedPromptFirewallConfig, SectionPolicy } from './types.js';
|
|
5
|
+
export * from './audit.js';
|
|
6
|
+
export * from './config.js';
|
|
7
|
+
export * from './firewall.js';
|
|
8
|
+
export * from './metrics.js';
|
|
9
|
+
export * from './presets.js';
|
|
10
|
+
export * from './rules.js';
|
|
11
|
+
export * from './types.js';
|
|
12
|
+
declare module '@deepseek-ai/cordis' {
|
|
13
|
+
interface Context {
|
|
14
|
+
/** Inspect and evaluate prompt firewall state without accessing internals. */
|
|
15
|
+
promptFirewall: PromptFirewallService;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
/** Cordis plugin ID. */
|
|
19
|
+
export declare const name = "prompt-firewall";
|
|
20
|
+
export declare const inject: string[];
|
|
21
|
+
export declare const PROMPT_FIREWALL_SETTINGS_NAMESPACE: import("@deepseek-ai/dsh-settings").SettingsNamespace;
|
|
22
|
+
export type Config = PromptFirewallConfig;
|
|
23
|
+
export declare const Config: import("@deepseek-ai/schemastery").default<PromptFirewallConfig>;
|
|
24
|
+
/** DSH Host plugin, public firewall service, and browser Remote owner. */
|
|
25
|
+
export declare class PromptFirewall extends TypertRemoteService implements PromptFirewallService {
|
|
26
|
+
static inject: string[];
|
|
27
|
+
static Config: import("@deepseek-ai/schemastery").default<PromptFirewallConfig>;
|
|
28
|
+
private readonly entryConfig;
|
|
29
|
+
private configSource;
|
|
30
|
+
private resolvedConfig;
|
|
31
|
+
private compiledRules;
|
|
32
|
+
private readonly audits;
|
|
33
|
+
private readonly metrics;
|
|
34
|
+
constructor(ctx: Context, config?: PromptFirewallConfig);
|
|
35
|
+
inspectLast(): PromptAuditResult | null;
|
|
36
|
+
inspectHistory(): PromptAuditResult[];
|
|
37
|
+
getKnownSections(): KnownSection[];
|
|
38
|
+
getMetrics(): PromptFirewallMetricsSnapshot;
|
|
39
|
+
getConfig(): ResolvedPromptFirewallConfig;
|
|
40
|
+
/** Return one consistent, content-safe browser inspector projection. */
|
|
41
|
+
inspect(): PromptFirewallInspectorSnapshot;
|
|
42
|
+
evaluateSection(section: AssembledSection): FirewallDecision;
|
|
43
|
+
setSectionPolicy(name: string, policy: SectionPolicy, expectedRevision?: number): Promise<void>;
|
|
44
|
+
reloadRules(): void;
|
|
45
|
+
}
|
|
46
|
+
export default PromptFirewall;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { PromptAuditResult, PromptFirewallMetricsSnapshot } from './types.js';
|
|
2
|
+
export declare const METRIC_NAMES: Readonly<{
|
|
3
|
+
readonly requestsTotal: 'dsh_prompt_firewall_requests_total';
|
|
4
|
+
readonly sectionsTotal: 'dsh_prompt_firewall_sections_total';
|
|
5
|
+
readonly sectionsBlockedTotal: 'dsh_prompt_firewall_sections_blocked_total';
|
|
6
|
+
readonly charsRemovedTotal: 'dsh_prompt_firewall_chars_removed_total';
|
|
7
|
+
readonly estimatedTokensRemovedTotal: 'dsh_prompt_firewall_estimated_tokens_removed_total';
|
|
8
|
+
}>;
|
|
9
|
+
export type PromptFirewallMetricName = typeof METRIC_NAMES[keyof typeof METRIC_NAMES];
|
|
10
|
+
/** Backend-neutral, label-free counters suitable for UI or an OTel adapter. */
|
|
11
|
+
export declare class FirewallMetrics {
|
|
12
|
+
private counters;
|
|
13
|
+
record(result: PromptAuditResult): void;
|
|
14
|
+
snapshot(): PromptFirewallMetricsSnapshot;
|
|
15
|
+
namedSnapshot(): Readonly<Record<PromptFirewallMetricName, number>>;
|
|
16
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { FirewallPreset, PromptFirewallConfig } from './types.js';
|
|
2
|
+
export declare const CLEAN_BLOCKED_SECTIONS: readonly ["plugin:dsh-liangshen", "plugin:dsh-ssh", "plugin:task-board", "plugin:dsh-desktop-launcher"];
|
|
3
|
+
export declare const PRESETS: Readonly<Record<FirewallPreset, Readonly<PromptFirewallConfig>>>;
|
|
4
|
+
export declare function getPreset(name: FirewallPreset | undefined): Readonly<PromptFirewallConfig>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import type { FirewallDecision, FirewallSection, ResolvedPromptFirewallConfig } from './types.js';
|
|
2
|
+
/**
|
|
3
|
+
* Verified against the upstream DSH registry. `harness:` and `deployment:` are
|
|
4
|
+
* emitted by dsh-system-prompt; `tool:` and `tools:` are used for tool guidance.
|
|
5
|
+
* The remaining conservative namespaces are retained for compatible hosts.
|
|
6
|
+
*/
|
|
7
|
+
export declare const CORE_SECTION_PREFIXES: readonly ["harness:", "deployment:", "tool:", "tools:", "runtime:", "system:"];
|
|
8
|
+
interface CompiledPattern {
|
|
9
|
+
readonly source: string;
|
|
10
|
+
readonly expression: RegExp;
|
|
11
|
+
}
|
|
12
|
+
export interface CompiledRules {
|
|
13
|
+
readonly config: ResolvedPromptFirewallConfig;
|
|
14
|
+
readonly protectedSections: ReadonlySet<string>;
|
|
15
|
+
readonly allowedSections: ReadonlySet<string>;
|
|
16
|
+
readonly blockedSections: ReadonlySet<string>;
|
|
17
|
+
readonly allowedPrefixes: readonly string[];
|
|
18
|
+
readonly blockedPrefixes: readonly string[];
|
|
19
|
+
readonly allowedPatterns: readonly CompiledPattern[];
|
|
20
|
+
readonly blockedPatterns: readonly CompiledPattern[];
|
|
21
|
+
}
|
|
22
|
+
export declare function globToRegExp(glob: string): RegExp;
|
|
23
|
+
export declare function compileRules(config: ResolvedPromptFirewallConfig): CompiledRules;
|
|
24
|
+
export declare function evaluateSection(section: FirewallSection, rules: CompiledRules): FirewallDecision;
|
|
25
|
+
export {};
|