@framers/agentos-ext-ml-classifiers 0.1.0 → 0.2.1
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 +18 -0
- package/dist/MLClassifierGuardrail.d.ts +88 -117
- package/dist/MLClassifierGuardrail.d.ts.map +1 -1
- package/dist/MLClassifierGuardrail.js +255 -264
- package/dist/MLClassifierGuardrail.js.map +1 -1
- package/dist/classifiers/InjectionClassifier.d.ts +1 -1
- package/dist/classifiers/InjectionClassifier.d.ts.map +1 -1
- package/dist/classifiers/JailbreakClassifier.d.ts +1 -1
- package/dist/classifiers/JailbreakClassifier.d.ts.map +1 -1
- package/dist/classifiers/ToxicityClassifier.d.ts +1 -1
- package/dist/classifiers/ToxicityClassifier.d.ts.map +1 -1
- package/dist/classifiers/WorkerClassifierProxy.d.ts +1 -1
- package/dist/classifiers/WorkerClassifierProxy.d.ts.map +1 -1
- package/dist/index.d.ts +16 -90
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +33 -306
- package/dist/index.js.map +1 -1
- package/dist/keyword-classifier.d.ts +26 -0
- package/dist/keyword-classifier.d.ts.map +1 -0
- package/dist/keyword-classifier.js +113 -0
- package/dist/keyword-classifier.js.map +1 -0
- package/dist/llm-classifier.d.ts +27 -0
- package/dist/llm-classifier.d.ts.map +1 -0
- package/dist/llm-classifier.js +129 -0
- package/dist/llm-classifier.js.map +1 -0
- package/dist/tools/ClassifyContentTool.d.ts +53 -80
- package/dist/tools/ClassifyContentTool.d.ts.map +1 -1
- package/dist/tools/ClassifyContentTool.js +52 -103
- package/dist/tools/ClassifyContentTool.js.map +1 -1
- package/dist/types.d.ts +77 -277
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +9 -55
- package/dist/types.js.map +1 -1
- package/package.json +10 -16
- package/src/MLClassifierGuardrail.ts +279 -316
- package/src/index.ts +35 -339
- package/src/keyword-classifier.ts +130 -0
- package/src/llm-classifier.ts +163 -0
- package/src/tools/ClassifyContentTool.ts +75 -132
- package/src/types.ts +78 -325
- package/test/ClassifierOrchestrator.spec.ts +365 -0
- package/test/ClassifyContentTool.spec.ts +226 -0
- package/test/InjectionClassifier.spec.ts +263 -0
- package/test/JailbreakClassifier.spec.ts +295 -0
- package/test/MLClassifierGuardrail.spec.ts +486 -0
- package/test/SlidingWindowBuffer.spec.ts +391 -0
- package/test/ToxicityClassifier.spec.ts +268 -0
- package/test/WorkerClassifierProxy.spec.ts +303 -0
- package/test/index.spec.ts +431 -0
- package/tsconfig.json +20 -0
- package/vitest.config.ts +24 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MLClassifierGuardrail.js","sourceRoot":"","sources":["../src/MLClassifierGuardrail.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"MLClassifierGuardrail.js","sourceRoot":"","sources":["../src/MLClassifierGuardrail.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AASH,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAO5D,OAAO,EAAE,cAAc,EAAE,MAAM,SAAS,CAAC;AACzC,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AAEjD,8EAA8E;AAC9E,wBAAwB;AACxB,8EAA8E;AAE9E;;;;;GAKG;AACH,MAAM,OAAO,qBAAqB;IAChC,0EAA0E;IAC1E,2BAA2B;IAC3B,0EAA0E;IAE1E;;;;;;;;;OASG;IACM,MAAM,GAAoB;QACjC,WAAW,EAAE,KAAK;QAClB,uBAAuB,EAAE,KAAK;KAC/B,CAAC;IAEF,0EAA0E;IAC1E,gBAAgB;IAChB,0EAA0E;IAE1E,8BAA8B;IACb,UAAU,CAAuB;IAElD,oCAAoC;IACnB,cAAc,CAAqC;IAEpE,qCAAqC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AAM,EAAE,MAAM,CAAC,MAAM;oBACrB,UAAU,EAAE,MAAM,CAAC,UAAU;iBAC9B;aACF,CAAC;QACJ,CAAC;QAED,kCAAkC;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
|
|
@@ -81,7 +81,7 @@ export declare class InjectionClassifier implements IContentClassifier {
|
|
|
81
81
|
* `config.modelId` is provided it overrides the default `modelId` when
|
|
82
82
|
* loading the model.
|
|
83
83
|
*/
|
|
84
|
-
constructor(services: ISharedServiceRegistry, config?: ClassifierConfig
|
|
84
|
+
constructor(services: ISharedServiceRegistry, config?: ClassifierConfig);
|
|
85
85
|
/**
|
|
86
86
|
* Whether the underlying model pipeline has been successfully initialised.
|
|
87
87
|
* The flag is set to `true` after the first successful `classify()` call.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"InjectionClassifier.d.ts","sourceRoot":"","sources":["../../src/classifiers/InjectionClassifier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAsBjD;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,qBAAa,mBAAoB,YAAW,kBAAkB;IAmD1D,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IA/C1B,qDAAqD;IACrD,QAAQ,CAAC,EAAE,sBAAsB;IAEjC,yDAAyD;IACzD,QAAQ,CAAC,WAAW,iCAAiC;IAErD,yDAAyD;IACzD,QAAQ,CAAC,WAAW,SAEsD;IAE1E;;;OAGG;IACH,QAAQ,CAAC,OAAO,oDAAoD;IAMpE;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AAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAS9B;;;;;OAKG;IACH,OAAO,CAAC,UAAU;IAIlB;;;;;;;;OAQG;IACH,OAAO,CAAC,SAAS;CAsBlB"}
|
|
@@ -79,7 +79,7 @@ export declare class JailbreakClassifier implements IContentClassifier {
|
|
|
79
79
|
* `config.modelId` is provided it overrides the default `modelId` when
|
|
80
80
|
* loading the model.
|
|
81
81
|
*/
|
|
82
|
-
constructor(services: ISharedServiceRegistry, config?: ClassifierConfig
|
|
82
|
+
constructor(services: ISharedServiceRegistry, config?: ClassifierConfig);
|
|
83
83
|
/**
|
|
84
84
|
* Whether the underlying model pipeline has been successfully initialised.
|
|
85
85
|
* The flag is set to `true` after the first successful `classify()` call.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"JailbreakClassifier.d.ts","sourceRoot":"","sources":["../../src/classifiers/JailbreakClassifier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAsBjD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,qBAAa,mBAAoB,YAAW,kBAAkB;IAmD1D,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IA/C1B,qDAAqD;IACrD,QAAQ,CAAC,EAAE,eAAe;IAE1B,yDAAyD;IACzD,QAAQ,CAAC,WAAW,0BAA0B;IAE9C,yDAAyD;IACzD,QAAQ,CAAC,WAAW,SAEoC;IAExD;;;OAGG;IACH,QAAQ,CAAC,OAAO,gCAAgC;IAMhD;;;OAGG;IACH,OAAO,CAA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AI,CAAC;IAS9B;;;;;OAKG;IACH,OAAO,CAAC,UAAU;IAIlB;;;;;;;;OAQG;IACH,OAAO,CAAC,SAAS;CAsBlB"}
|
|
@@ -80,7 +80,7 @@ export declare class ToxicityClassifier implements IContentClassifier {
|
|
|
80
80
|
* `config.modelId` is provided it overrides the default `modelId` when
|
|
81
81
|
* loading the model.
|
|
82
82
|
*/
|
|
83
|
-
constructor(services: ISharedServiceRegistry, config?: ClassifierConfig
|
|
83
|
+
constructor(services: ISharedServiceRegistry, config?: ClassifierConfig);
|
|
84
84
|
/**
|
|
85
85
|
* Whether the underlying model pipeline has been successfully initialised.
|
|
86
86
|
* The flag is set to `true` after the first successful `classify()` call.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ToxicityClassifier.d.ts","sourceRoot":"","sources":["../../src/classifiers/ToxicityClassifier.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,kBAAkB,CAAC;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAsBjD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,qBAAa,kBAAmB,YAAW,kBAAkB;IAmDzD,OAAO,CAAC,QAAQ,CAAC,QAAQ;IACzB,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAC;IA/C1B,qDAAqD;IACrD,QAAQ,CAAC,EAAE,cAAc;IAEzB,yDAAyD;IACzD,QAAQ,CAAC,WAAW,yBAAyB;IAE7C,yDAAyD;IACzD,QAAQ,CAAC,WAAW,SAEiD;IAErE;;;OAGG;IACH,QAAQ,CAAC,OAAO,wBAAwB;IAMxC;;;OAGG;IACH,OAAO,CAAC,SAAS,CAAS;IAE1B;;;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AKG;IACH,OAAO,CAAC,UAAU;IAIlB;;;;;;;;OAQG;IACH,OAAO,CAAC,SAAS;CAuBlB"}
|
|
@@ -108,7 +108,7 @@ export declare class WorkerClassifierProxy implements IContentClassifier {
|
|
|
108
108
|
* whether Worker mode is attempted
|
|
109
109
|
* (`useWebWorker`, default `true`).
|
|
110
110
|
*/
|
|
111
|
-
constructor(wrapped: IContentClassifier, browserConfig?: BrowserConfig
|
|
111
|
+
constructor(wrapped: IContentClassifier, browserConfig?: BrowserConfig);
|
|
112
112
|
/**
|
|
113
113
|
* Classify the provided text, routing to a Web Worker when available.
|
|
114
114
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WorkerClassifierProxy.d.ts","sourceRoot":"","sources":["../../src/classifiers/WorkerClassifierProxy.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AAEH,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAoE9C;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,qBAAa,qBAAsB,YAAW,kBAAkB;IAsF5D,OAAO,CAAC,QAAQ,CAAC,OAAO;IACxB,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAC;IAlFjC;;;;OAIG;IACH,IAAI,EAAE,IAAI,MAAM,CAEf;IAED;;;;OAIG;IACH,IAAI,WAAW,IAAI,MAAM,CAExB;IAED;;;OAGG;IACH,IAAI,WAAW,IAAI,MAAM,CAExB;IAED;;;OAGG;IACH,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED;;;;;;OAMG;IACH,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED;;;;OAIG;IACH,IAAI,QAAQ,CAAC,KAAK,EAAE,OAAO,EAE1B;IAMD;;;;OAIG;IACH,OAAO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;IAmB1B;;;;;;;;;;;;OAYG;YACW,gBAAgB;CA8D/B"}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,110 +1,36 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @file index.ts
|
|
3
|
+
* @description Pack factory for the ML Classifiers extension pack.
|
|
3
4
|
*
|
|
4
|
-
* Exports
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* manager.
|
|
5
|
+
* Exports a `createExtensionPack()` factory that assembles the ML classifier
|
|
6
|
+
* guardrail and the `classify_content` tool into a single {@link ExtensionPack}
|
|
7
|
+
* ready for registration with the AgentOS extension manager.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
* the AgentOS manifest factory convention, delegating to
|
|
11
|
-
* `createMLClassifierPack()` with options extracted from the
|
|
12
|
-
* {@link ExtensionPackContext}.
|
|
13
|
-
*
|
|
14
|
-
* ### Default behaviour (zero-config)
|
|
15
|
-
* When called without arguments, all three built-in classifiers (toxicity,
|
|
16
|
-
* prompt-injection, jailbreak) are active using their default model IDs and
|
|
17
|
-
* the default threshold set:
|
|
18
|
-
* - block at 0.90 confidence
|
|
19
|
-
* - flag at 0.70 confidence
|
|
20
|
-
* - warn (sanitize) at 0.40 confidence
|
|
21
|
-
*
|
|
22
|
-
* ### Activation lifecycle
|
|
23
|
-
* Components are built eagerly at pack creation time for direct programmatic
|
|
24
|
-
* use. When the extension manager activates the pack, `onActivate` rebuilds
|
|
25
|
-
* all components with the manager's shared service registry so heavyweight
|
|
26
|
-
* resources (ONNX/WASM model pipelines) are shared across the agent.
|
|
27
|
-
*
|
|
28
|
-
* ### Disabling classifiers
|
|
29
|
-
* Individual classifiers can be disabled by omitting them from the
|
|
30
|
-
* `options.classifiers` array. An empty array or `undefined` activates all
|
|
31
|
-
* three built-in classifiers.
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```typescript
|
|
35
|
-
* import { createMLClassifierPack } from './ml-classifiers';
|
|
36
|
-
*
|
|
37
|
-
* // All built-in classifiers at default thresholds:
|
|
38
|
-
* const pack = createMLClassifierPack();
|
|
39
|
-
*
|
|
40
|
-
* // Toxicity only with custom block threshold:
|
|
41
|
-
* const strictPack = createMLClassifierPack({
|
|
42
|
-
* classifiers: ['toxicity'],
|
|
43
|
-
* thresholds: { blockThreshold: 0.85 },
|
|
44
|
-
* streamingMode: true,
|
|
45
|
-
* guardrailScope: 'both',
|
|
46
|
-
* });
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* @module agentos/extensions/packs/ml-classifiers
|
|
9
|
+
* @module ml-classifiers
|
|
50
10
|
*/
|
|
51
11
|
import type { ExtensionPack, ExtensionPackContext } from '@framers/agentos';
|
|
52
|
-
import type {
|
|
53
|
-
/**
|
|
54
|
-
* Re-export all types from the ML classifier type definitions so consumers
|
|
55
|
-
* can import everything from a single entry point:
|
|
56
|
-
* ```ts
|
|
57
|
-
* import { createMLClassifierPack, DEFAULT_THRESHOLDS } from './ml-classifiers';
|
|
58
|
-
* ```
|
|
59
|
-
*/
|
|
12
|
+
import type { MLClassifierOptions } from './types';
|
|
60
13
|
export * from './types';
|
|
61
14
|
/**
|
|
62
|
-
* Create an
|
|
63
|
-
*
|
|
64
|
-
* - The {@link ClassifyContentTool} `classify_content` tool (on-demand analysis).
|
|
65
|
-
*
|
|
66
|
-
* The built-in classifiers that are instantiated depend on `options.classifiers`:
|
|
67
|
-
* - `'toxicity'` → {@link ToxicityClassifier} (`unitary/toxic-bert`)
|
|
68
|
-
* - `'injection'` → {@link InjectionClassifier} (`protectai/deberta-v3-small-prompt-injection-v2`)
|
|
69
|
-
* - `'jailbreak'` → {@link JailbreakClassifier} (`meta-llama/PromptGuard-86M`)
|
|
70
|
-
*
|
|
71
|
-
* When `options.classifiers` is `undefined` or empty, **all three** are active.
|
|
72
|
-
*
|
|
73
|
-
* Additional classifiers supplied via `options.customClassifiers` are appended
|
|
74
|
-
* to the active list and run in parallel alongside the built-in ones.
|
|
15
|
+
* Create an ExtensionPack that bundles the ML classifier guardrail with
|
|
16
|
+
* the `classify_content` tool.
|
|
75
17
|
*
|
|
76
18
|
* @param options - Optional pack-level configuration. All properties have
|
|
77
|
-
* sensible defaults; see {@link
|
|
78
|
-
* @returns A fully-configured {@link ExtensionPack}
|
|
79
|
-
* descriptor and one tool descriptor.
|
|
19
|
+
* sensible defaults; see {@link MLClassifierOptions}.
|
|
20
|
+
* @returns A fully-configured {@link ExtensionPack}.
|
|
80
21
|
*/
|
|
81
|
-
export declare function
|
|
22
|
+
export declare function createMLClassifierGuardrail(options?: MLClassifierOptions): ExtensionPack;
|
|
82
23
|
/**
|
|
83
24
|
* AgentOS manifest factory function.
|
|
84
25
|
*
|
|
85
26
|
* Conforms to the convention expected by the extension loader when resolving
|
|
86
27
|
* packs from manifests. Extracts `options` from the {@link ExtensionPackContext}
|
|
87
|
-
* and delegates to {@link
|
|
28
|
+
* and delegates to {@link createMLClassifierGuardrail}.
|
|
88
29
|
*
|
|
89
|
-
* @param context - Manifest context containing optional pack options
|
|
90
|
-
* resolver, and shared service registry.
|
|
30
|
+
* @param context - Manifest context containing optional pack options.
|
|
91
31
|
* @returns A fully-configured {@link ExtensionPack}.
|
|
92
|
-
*
|
|
93
|
-
* @example Manifest entry:
|
|
94
|
-
* ```json
|
|
95
|
-
* {
|
|
96
|
-
* "packs": [
|
|
97
|
-
* {
|
|
98
|
-
* "module": "./ml-classifiers",
|
|
99
|
-
* "options": {
|
|
100
|
-
* "classifiers": ["toxicity", "jailbreak"],
|
|
101
|
-
* "thresholds": { "blockThreshold": 0.95 },
|
|
102
|
-
* "streamingMode": true
|
|
103
|
-
* }
|
|
104
|
-
* }
|
|
105
|
-
* ]
|
|
106
|
-
* }
|
|
107
|
-
* ```
|
|
108
32
|
*/
|
|
109
33
|
export declare function createExtensionPack(context: ExtensionPackContext): ExtensionPack;
|
|
34
|
+
/** @deprecated Use createMLClassifierGuardrail instead */
|
|
35
|
+
export declare const createMLClassifierPack: typeof createMLClassifierGuardrail;
|
|
110
36
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAE5E,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,SAAS,CAAC;AAQnD,cAAc,SAAS,CAAC;AAMxB;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,aAAa,CAsBxF;AAMD;;;;;;;;;GASG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,aAAa,CAEhF;AAED,0DAA0D;AAC1D,eAAO,MAAM,sBAAsB,oCAA8B,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,309 +1,51 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* @
|
|
2
|
+
* @file index.ts
|
|
3
|
+
* @description Pack factory for the ML Classifiers extension pack.
|
|
3
4
|
*
|
|
4
|
-
* Exports
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* manager.
|
|
5
|
+
* Exports a `createExtensionPack()` factory that assembles the ML classifier
|
|
6
|
+
* guardrail and the `classify_content` tool into a single {@link ExtensionPack}
|
|
7
|
+
* ready for registration with the AgentOS extension manager.
|
|
8
8
|
*
|
|
9
|
-
*
|
|
10
|
-
* the AgentOS manifest factory convention, delegating to
|
|
11
|
-
* `createMLClassifierPack()` with options extracted from the
|
|
12
|
-
* {@link ExtensionPackContext}.
|
|
13
|
-
*
|
|
14
|
-
* ### Default behaviour (zero-config)
|
|
15
|
-
* When called without arguments, all three built-in classifiers (toxicity,
|
|
16
|
-
* prompt-injection, jailbreak) are active using their default model IDs and
|
|
17
|
-
* the default threshold set:
|
|
18
|
-
* - block at 0.90 confidence
|
|
19
|
-
* - flag at 0.70 confidence
|
|
20
|
-
* - warn (sanitize) at 0.40 confidence
|
|
21
|
-
*
|
|
22
|
-
* ### Activation lifecycle
|
|
23
|
-
* Components are built eagerly at pack creation time for direct programmatic
|
|
24
|
-
* use. When the extension manager activates the pack, `onActivate` rebuilds
|
|
25
|
-
* all components with the manager's shared service registry so heavyweight
|
|
26
|
-
* resources (ONNX/WASM model pipelines) are shared across the agent.
|
|
27
|
-
*
|
|
28
|
-
* ### Disabling classifiers
|
|
29
|
-
* Individual classifiers can be disabled by omitting them from the
|
|
30
|
-
* `options.classifiers` array. An empty array or `undefined` activates all
|
|
31
|
-
* three built-in classifiers.
|
|
32
|
-
*
|
|
33
|
-
* @example
|
|
34
|
-
* ```typescript
|
|
35
|
-
* import { createMLClassifierPack } from './ml-classifiers';
|
|
36
|
-
*
|
|
37
|
-
* // All built-in classifiers at default thresholds:
|
|
38
|
-
* const pack = createMLClassifierPack();
|
|
39
|
-
*
|
|
40
|
-
* // Toxicity only with custom block threshold:
|
|
41
|
-
* const strictPack = createMLClassifierPack({
|
|
42
|
-
* classifiers: ['toxicity'],
|
|
43
|
-
* thresholds: { blockThreshold: 0.85 },
|
|
44
|
-
* streamingMode: true,
|
|
45
|
-
* guardrailScope: 'both',
|
|
46
|
-
* });
|
|
47
|
-
* ```
|
|
48
|
-
*
|
|
49
|
-
* @module agentos/extensions/packs/ml-classifiers
|
|
9
|
+
* @module ml-classifiers
|
|
50
10
|
*/
|
|
51
|
-
import { SharedServiceRegistry } from '@framers/agentos';
|
|
52
11
|
import { EXTENSION_KIND_GUARDRAIL, EXTENSION_KIND_TOOL } from '@framers/agentos';
|
|
53
|
-
import { DEFAULT_THRESHOLDS } from './types';
|
|
54
12
|
import { MLClassifierGuardrail } from './MLClassifierGuardrail';
|
|
55
|
-
import { ClassifierOrchestrator } from './ClassifierOrchestrator';
|
|
56
|
-
import { SlidingWindowBuffer } from './SlidingWindowBuffer';
|
|
57
13
|
import { ClassifyContentTool } from './tools/ClassifyContentTool';
|
|
58
|
-
import { ToxicityClassifier } from './classifiers/ToxicityClassifier';
|
|
59
|
-
import { InjectionClassifier } from './classifiers/InjectionClassifier';
|
|
60
|
-
import { JailbreakClassifier } from './classifiers/JailbreakClassifier';
|
|
61
14
|
// ---------------------------------------------------------------------------
|
|
62
|
-
// Re-exports
|
|
15
|
+
// Re-exports
|
|
63
16
|
// ---------------------------------------------------------------------------
|
|
64
|
-
/**
|
|
65
|
-
* Re-export all types from the ML classifier type definitions so consumers
|
|
66
|
-
* can import everything from a single entry point:
|
|
67
|
-
* ```ts
|
|
68
|
-
* import { createMLClassifierPack, DEFAULT_THRESHOLDS } from './ml-classifiers';
|
|
69
|
-
* ```
|
|
70
|
-
*/
|
|
71
17
|
export * from './types';
|
|
72
18
|
// ---------------------------------------------------------------------------
|
|
73
19
|
// Pack factory
|
|
74
20
|
// ---------------------------------------------------------------------------
|
|
75
21
|
/**
|
|
76
|
-
* Create an
|
|
77
|
-
*
|
|
78
|
-
* - The {@link ClassifyContentTool} `classify_content` tool (on-demand analysis).
|
|
79
|
-
*
|
|
80
|
-
* The built-in classifiers that are instantiated depend on `options.classifiers`:
|
|
81
|
-
* - `'toxicity'` → {@link ToxicityClassifier} (`unitary/toxic-bert`)
|
|
82
|
-
* - `'injection'` → {@link InjectionClassifier} (`protectai/deberta-v3-small-prompt-injection-v2`)
|
|
83
|
-
* - `'jailbreak'` → {@link JailbreakClassifier} (`meta-llama/PromptGuard-86M`)
|
|
84
|
-
*
|
|
85
|
-
* When `options.classifiers` is `undefined` or empty, **all three** are active.
|
|
86
|
-
*
|
|
87
|
-
* Additional classifiers supplied via `options.customClassifiers` are appended
|
|
88
|
-
* to the active list and run in parallel alongside the built-in ones.
|
|
22
|
+
* Create an ExtensionPack that bundles the ML classifier guardrail with
|
|
23
|
+
* the `classify_content` tool.
|
|
89
24
|
*
|
|
90
25
|
* @param options - Optional pack-level configuration. All properties have
|
|
91
|
-
* sensible defaults; see {@link
|
|
92
|
-
* @returns A fully-configured {@link ExtensionPack}
|
|
93
|
-
* descriptor and one tool descriptor.
|
|
26
|
+
* sensible defaults; see {@link MLClassifierOptions}.
|
|
27
|
+
* @returns A fully-configured {@link ExtensionPack}.
|
|
94
28
|
*/
|
|
95
|
-
export function
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
* safely use `opts.foo` without null-guarding the whole `options` reference.
|
|
99
|
-
*/
|
|
100
|
-
const opts = options ?? {};
|
|
101
|
-
// -------------------------------------------------------------------------
|
|
102
|
-
// Mutable state — upgraded by onActivate with the extension manager's
|
|
103
|
-
// shared service registry.
|
|
104
|
-
// -------------------------------------------------------------------------
|
|
105
|
-
const state = {
|
|
106
|
-
/**
|
|
107
|
-
* Service registry — starts as a standalone instance so the pack can be
|
|
108
|
-
* used directly (without activation) in unit tests and scripts.
|
|
109
|
-
* Replaced with the shared registry when `onActivate` is called by the
|
|
110
|
-
* extension manager.
|
|
111
|
-
*/
|
|
112
|
-
services: new SharedServiceRegistry(),
|
|
113
|
-
};
|
|
114
|
-
// -------------------------------------------------------------------------
|
|
115
|
-
// Component instances — rebuilt by buildComponents()
|
|
116
|
-
// -------------------------------------------------------------------------
|
|
117
|
-
/**
|
|
118
|
-
* The guardrail that evaluates user input and/or agent output streams
|
|
119
|
-
* against all active ML classifiers.
|
|
120
|
-
*/
|
|
121
|
-
let guardrail;
|
|
122
|
-
/**
|
|
123
|
-
* The on-demand classification tool exposed to agents and workflows.
|
|
124
|
-
*/
|
|
125
|
-
let tool;
|
|
126
|
-
/**
|
|
127
|
-
* The orchestrator that runs all active classifiers in parallel and folds
|
|
128
|
-
* their results into a single {@link ChunkEvaluation} via worst-wins
|
|
129
|
-
* aggregation.
|
|
130
|
-
*/
|
|
131
|
-
let orchestrator;
|
|
132
|
-
/**
|
|
133
|
-
* The sliding-window buffer used internally by the guardrail to evaluate
|
|
134
|
-
* streamed output tokens incrementally.
|
|
135
|
-
*/
|
|
136
|
-
let buffer;
|
|
137
|
-
// -------------------------------------------------------------------------
|
|
138
|
-
// buildComponents
|
|
139
|
-
// -------------------------------------------------------------------------
|
|
140
|
-
/**
|
|
141
|
-
* (Re)construct all pack components using the current `state.services`.
|
|
142
|
-
*
|
|
143
|
-
* Called once at pack creation for direct programmatic use, and again
|
|
144
|
-
* during `onActivate` to upgrade to the extension manager's shared
|
|
145
|
-
* service registry (so ONNX/WASM pipelines are shared across the agent).
|
|
146
|
-
*
|
|
147
|
-
* ### Classifier selection
|
|
148
|
-
* The active classifiers are determined by `opts.classifiers`:
|
|
149
|
-
* - `undefined` or empty → all three built-in classifiers are created.
|
|
150
|
-
* - Non-empty array → only the named classifiers are created.
|
|
151
|
-
*
|
|
152
|
-
* Any `opts.customClassifiers` are always appended to the list.
|
|
153
|
-
*/
|
|
154
|
-
function buildComponents() {
|
|
155
|
-
// ------------------------------------------------------------------
|
|
156
|
-
// 1. Determine which built-in classifiers to instantiate.
|
|
157
|
-
// ------------------------------------------------------------------
|
|
158
|
-
/**
|
|
159
|
-
* Determine whether a given built-in classifier name is enabled.
|
|
160
|
-
*
|
|
161
|
-
* When `opts.classifiers` is undefined or an empty array every built-in
|
|
162
|
-
* classifier is considered enabled (zero-config default).
|
|
163
|
-
*
|
|
164
|
-
* @param name - One of `'toxicity'`, `'injection'`, or `'jailbreak'`.
|
|
165
|
-
* @returns `true` when the classifier should be included.
|
|
166
|
-
*/
|
|
167
|
-
function isBuiltInEnabled(name) {
|
|
168
|
-
// No explicit list — enable all built-in classifiers.
|
|
169
|
-
if (!opts.classifiers || opts.classifiers.length === 0) {
|
|
170
|
-
return true;
|
|
171
|
-
}
|
|
172
|
-
return opts.classifiers.includes(name);
|
|
173
|
-
}
|
|
174
|
-
/** Array that will be populated with every active IContentClassifier. */
|
|
175
|
-
const activeClassifiers = [];
|
|
176
|
-
// Toxicity classifier — detects hateful, abusive, and toxic language.
|
|
177
|
-
if (isBuiltInEnabled('toxicity')) {
|
|
178
|
-
activeClassifiers.push(new ToxicityClassifier(state.services));
|
|
179
|
-
}
|
|
180
|
-
// Injection classifier — detects prompt-injection payloads.
|
|
181
|
-
if (isBuiltInEnabled('injection')) {
|
|
182
|
-
activeClassifiers.push(new InjectionClassifier(state.services));
|
|
183
|
-
}
|
|
184
|
-
// Jailbreak classifier — detects system-prompt override attempts.
|
|
185
|
-
if (isBuiltInEnabled('jailbreak')) {
|
|
186
|
-
activeClassifiers.push(new JailbreakClassifier(state.services));
|
|
187
|
-
}
|
|
188
|
-
// Append any caller-supplied custom classifiers.
|
|
189
|
-
if (opts.customClassifiers && opts.customClassifiers.length > 0) {
|
|
190
|
-
activeClassifiers.push(...opts.customClassifiers);
|
|
191
|
-
}
|
|
192
|
-
// ------------------------------------------------------------------
|
|
193
|
-
// 2. Resolve pack-level thresholds (merge caller overrides on top of
|
|
194
|
-
// the library defaults).
|
|
195
|
-
// ------------------------------------------------------------------
|
|
196
|
-
const thresholds = {
|
|
197
|
-
...DEFAULT_THRESHOLDS,
|
|
198
|
-
...opts.thresholds,
|
|
199
|
-
};
|
|
200
|
-
// ------------------------------------------------------------------
|
|
201
|
-
// 3. Build the orchestrator with the resolved classifier list and
|
|
202
|
-
// thresholds.
|
|
203
|
-
// ------------------------------------------------------------------
|
|
204
|
-
orchestrator = new ClassifierOrchestrator(activeClassifiers, thresholds);
|
|
205
|
-
// ------------------------------------------------------------------
|
|
206
|
-
// 4. Build the sliding-window buffer for streaming evaluation.
|
|
207
|
-
// ------------------------------------------------------------------
|
|
208
|
-
buffer = new SlidingWindowBuffer({
|
|
209
|
-
chunkSize: opts.chunkSize,
|
|
210
|
-
contextSize: opts.contextSize,
|
|
211
|
-
maxEvaluations: opts.maxEvaluations,
|
|
212
|
-
});
|
|
213
|
-
// ------------------------------------------------------------------
|
|
214
|
-
// 5. Build the guardrail, passing the shared registry and options.
|
|
215
|
-
// The guardrail creates its own orchestrator internally from the
|
|
216
|
-
// `classifiers` option — we pass the pre-built classifier instances
|
|
217
|
-
// via the third constructor argument.
|
|
218
|
-
// ------------------------------------------------------------------
|
|
219
|
-
guardrail = new MLClassifierGuardrail(state.services, opts, activeClassifiers);
|
|
220
|
-
// ------------------------------------------------------------------
|
|
221
|
-
// 6. Build the on-demand classification tool backed by the orchestrator.
|
|
222
|
-
// ------------------------------------------------------------------
|
|
223
|
-
tool = new ClassifyContentTool(orchestrator);
|
|
224
|
-
}
|
|
225
|
-
// Initial build — makes the pack usable immediately without activation.
|
|
226
|
-
buildComponents();
|
|
227
|
-
// -------------------------------------------------------------------------
|
|
228
|
-
// ExtensionPack shape
|
|
229
|
-
// -------------------------------------------------------------------------
|
|
29
|
+
export function createMLClassifierGuardrail(options) {
|
|
30
|
+
const guardrail = new MLClassifierGuardrail(options);
|
|
31
|
+
const tool = new ClassifyContentTool(guardrail);
|
|
230
32
|
return {
|
|
231
|
-
/** Canonical pack name used in manifests and logs. */
|
|
232
33
|
name: 'ml-classifiers',
|
|
233
|
-
/** Semantic version of this pack implementation. */
|
|
234
34
|
version: '1.0.0',
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
*/
|
|
250
|
-
id: 'ml-classifier-guardrail',
|
|
251
|
-
kind: EXTENSION_KIND_GUARDRAIL,
|
|
252
|
-
priority: 5,
|
|
253
|
-
payload: guardrail,
|
|
254
|
-
},
|
|
255
|
-
{
|
|
256
|
-
/**
|
|
257
|
-
* On-demand classification tool descriptor.
|
|
258
|
-
*
|
|
259
|
-
* Priority 0 uses the default ordering — tools are typically
|
|
260
|
-
* ordered by name rather than priority.
|
|
261
|
-
*/
|
|
262
|
-
id: 'classify_content',
|
|
263
|
-
kind: EXTENSION_KIND_TOOL,
|
|
264
|
-
priority: 0,
|
|
265
|
-
payload: tool,
|
|
266
|
-
},
|
|
267
|
-
];
|
|
268
|
-
},
|
|
269
|
-
/**
|
|
270
|
-
* Lifecycle hook called by the extension manager when the pack is
|
|
271
|
-
* activated.
|
|
272
|
-
*
|
|
273
|
-
* Upgrades the internal service registry to the extension manager's
|
|
274
|
-
* shared instance (so ONNX/WASM model weights are shared across all
|
|
275
|
-
* extensions) then rebuilds all components to use the new registry.
|
|
276
|
-
*
|
|
277
|
-
* @param context - Activation context provided by the extension manager.
|
|
278
|
-
*/
|
|
279
|
-
onActivate: (context) => {
|
|
280
|
-
// Upgrade to the shared registry when the manager provides one.
|
|
281
|
-
if (context.services) {
|
|
282
|
-
state.services = context.services;
|
|
283
|
-
}
|
|
284
|
-
// Rebuild all components with the upgraded registry.
|
|
285
|
-
buildComponents();
|
|
286
|
-
},
|
|
287
|
-
/**
|
|
288
|
-
* Lifecycle hook called when the pack is deactivated or the agent shuts
|
|
289
|
-
* down.
|
|
290
|
-
*
|
|
291
|
-
* Disposes the classifier orchestrator (which releases ONNX/WASM
|
|
292
|
-
* resources for every registered classifier) and clears the sliding
|
|
293
|
-
* window buffer to release per-stream state.
|
|
294
|
-
*/
|
|
295
|
-
onDeactivate: async () => {
|
|
296
|
-
// Dispose all classifiers managed by the orchestrator.
|
|
297
|
-
// orchestrator may be undefined if buildComponents() was never called
|
|
298
|
-
// successfully (defensive guard).
|
|
299
|
-
if (orchestrator) {
|
|
300
|
-
await orchestrator.dispose();
|
|
301
|
-
}
|
|
302
|
-
// Clear any in-progress stream buffers.
|
|
303
|
-
if (buffer) {
|
|
304
|
-
buffer.clear();
|
|
305
|
-
}
|
|
306
|
-
},
|
|
35
|
+
descriptors: [
|
|
36
|
+
{
|
|
37
|
+
id: 'ml-classifier-guardrail',
|
|
38
|
+
kind: EXTENSION_KIND_GUARDRAIL,
|
|
39
|
+
priority: 5,
|
|
40
|
+
payload: guardrail,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: 'classify_content',
|
|
44
|
+
kind: EXTENSION_KIND_TOOL,
|
|
45
|
+
priority: 0,
|
|
46
|
+
payload: tool,
|
|
47
|
+
},
|
|
48
|
+
],
|
|
307
49
|
};
|
|
308
50
|
}
|
|
309
51
|
// ---------------------------------------------------------------------------
|
|
@@ -314,29 +56,14 @@ export function createMLClassifierPack(options) {
|
|
|
314
56
|
*
|
|
315
57
|
* Conforms to the convention expected by the extension loader when resolving
|
|
316
58
|
* packs from manifests. Extracts `options` from the {@link ExtensionPackContext}
|
|
317
|
-
* and delegates to {@link
|
|
59
|
+
* and delegates to {@link createMLClassifierGuardrail}.
|
|
318
60
|
*
|
|
319
|
-
* @param context - Manifest context containing optional pack options
|
|
320
|
-
* resolver, and shared service registry.
|
|
61
|
+
* @param context - Manifest context containing optional pack options.
|
|
321
62
|
* @returns A fully-configured {@link ExtensionPack}.
|
|
322
|
-
*
|
|
323
|
-
* @example Manifest entry:
|
|
324
|
-
* ```json
|
|
325
|
-
* {
|
|
326
|
-
* "packs": [
|
|
327
|
-
* {
|
|
328
|
-
* "module": "./ml-classifiers",
|
|
329
|
-
* "options": {
|
|
330
|
-
* "classifiers": ["toxicity", "jailbreak"],
|
|
331
|
-
* "thresholds": { "blockThreshold": 0.95 },
|
|
332
|
-
* "streamingMode": true
|
|
333
|
-
* }
|
|
334
|
-
* }
|
|
335
|
-
* ]
|
|
336
|
-
* }
|
|
337
|
-
* ```
|
|
338
63
|
*/
|
|
339
64
|
export function createExtensionPack(context) {
|
|
340
|
-
return
|
|
65
|
+
return createMLClassifierGuardrail(context.options);
|
|
341
66
|
}
|
|
67
|
+
/** @deprecated Use createMLClassifierGuardrail instead */
|
|
68
|
+
export const createMLClassifierPack = createMLClassifierGuardrail;
|
|
342
69
|
//# sourceMappingURL=index.js.map
|