@framers/agentos-ext-ml-classifiers 0.2.1 → 0.3.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.
Files changed (69) hide show
  1. package/.github/workflows/ci.yml +20 -0
  2. package/.github/workflows/release.yml +37 -0
  3. package/.releaserc.json +9 -0
  4. package/LICENSE +96 -21
  5. package/README.md +72 -0
  6. package/dist/MLClassifierGuardrail.d.ts.map +1 -1
  7. package/dist/MLClassifierGuardrail.js +14 -6
  8. package/dist/MLClassifierGuardrail.js.map +1 -1
  9. package/dist/index.js +3 -3
  10. package/dist/keyword-classifier.js +1 -1
  11. package/dist/llm-classifier.js +1 -1
  12. package/package.json +5 -13
  13. package/scripts/fix-esm-imports.mjs +181 -0
  14. package/src/MLClassifierGuardrail.ts +38 -5
  15. package/test/llm-tier.spec.ts +267 -0
  16. package/test/ml-classifiers.spec.ts +57 -0
  17. package/test/onnx-tier.spec.ts +255 -0
  18. package/test/tier-fallthrough.spec.ts +185 -0
  19. package/vitest.config.ts +18 -7
  20. package/CHANGELOG.md +0 -18
  21. package/dist/ClassifierOrchestrator.d.ts +0 -126
  22. package/dist/ClassifierOrchestrator.d.ts.map +0 -1
  23. package/dist/ClassifierOrchestrator.js +0 -239
  24. package/dist/ClassifierOrchestrator.js.map +0 -1
  25. package/dist/IContentClassifier.d.ts +0 -117
  26. package/dist/IContentClassifier.d.ts.map +0 -1
  27. package/dist/IContentClassifier.js +0 -22
  28. package/dist/IContentClassifier.js.map +0 -1
  29. package/dist/SlidingWindowBuffer.d.ts +0 -213
  30. package/dist/SlidingWindowBuffer.d.ts.map +0 -1
  31. package/dist/SlidingWindowBuffer.js +0 -246
  32. package/dist/SlidingWindowBuffer.js.map +0 -1
  33. package/dist/classifiers/InjectionClassifier.d.ts +0 -126
  34. package/dist/classifiers/InjectionClassifier.d.ts.map +0 -1
  35. package/dist/classifiers/InjectionClassifier.js +0 -210
  36. package/dist/classifiers/InjectionClassifier.js.map +0 -1
  37. package/dist/classifiers/JailbreakClassifier.d.ts +0 -124
  38. package/dist/classifiers/JailbreakClassifier.d.ts.map +0 -1
  39. package/dist/classifiers/JailbreakClassifier.js +0 -208
  40. package/dist/classifiers/JailbreakClassifier.js.map +0 -1
  41. package/dist/classifiers/ToxicityClassifier.d.ts +0 -125
  42. package/dist/classifiers/ToxicityClassifier.d.ts.map +0 -1
  43. package/dist/classifiers/ToxicityClassifier.js +0 -212
  44. package/dist/classifiers/ToxicityClassifier.js.map +0 -1
  45. package/dist/classifiers/WorkerClassifierProxy.d.ts +0 -158
  46. package/dist/classifiers/WorkerClassifierProxy.d.ts.map +0 -1
  47. package/dist/classifiers/WorkerClassifierProxy.js +0 -268
  48. package/dist/classifiers/WorkerClassifierProxy.js.map +0 -1
  49. package/dist/worker/classifier-worker.d.ts +0 -49
  50. package/dist/worker/classifier-worker.d.ts.map +0 -1
  51. package/dist/worker/classifier-worker.js +0 -180
  52. package/dist/worker/classifier-worker.js.map +0 -1
  53. package/src/ClassifierOrchestrator.ts +0 -290
  54. package/src/IContentClassifier.ts +0 -124
  55. package/src/SlidingWindowBuffer.ts +0 -384
  56. package/src/classifiers/InjectionClassifier.ts +0 -261
  57. package/src/classifiers/JailbreakClassifier.ts +0 -259
  58. package/src/classifiers/ToxicityClassifier.ts +0 -263
  59. package/src/classifiers/WorkerClassifierProxy.ts +0 -366
  60. package/src/worker/classifier-worker.ts +0 -267
  61. package/test/ClassifierOrchestrator.spec.ts +0 -365
  62. package/test/ClassifyContentTool.spec.ts +0 -226
  63. package/test/InjectionClassifier.spec.ts +0 -263
  64. package/test/JailbreakClassifier.spec.ts +0 -295
  65. package/test/MLClassifierGuardrail.spec.ts +0 -486
  66. package/test/SlidingWindowBuffer.spec.ts +0 -391
  67. package/test/ToxicityClassifier.spec.ts +0 -268
  68. package/test/WorkerClassifierProxy.spec.ts +0 -303
  69. package/test/index.spec.ts +0 -431
@@ -0,0 +1,20 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+ pull_request:
7
+
8
+ jobs:
9
+ build:
10
+ runs-on: ubuntu-latest
11
+ steps:
12
+ - uses: actions/checkout@v4
13
+ - uses: pnpm/action-setup@v4
14
+ with:
15
+ version: 10
16
+ - uses: actions/setup-node@v4
17
+ with:
18
+ node-version: 20
19
+ - run: pnpm install --no-frozen-lockfile
20
+ - run: pnpm build
@@ -0,0 +1,37 @@
1
+ name: Release
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+ workflow_dispatch:
7
+
8
+ permissions:
9
+ contents: write
10
+ issues: write
11
+ pull-requests: write
12
+ id-token: write
13
+
14
+ jobs:
15
+ release:
16
+ runs-on: ubuntu-latest
17
+ if: "!contains(github.event.head_commit.message, '[skip ci]')"
18
+ steps:
19
+ - uses: actions/checkout@v4
20
+ with:
21
+ fetch-depth: 0
22
+ persist-credentials: false
23
+ - uses: pnpm/action-setup@v4
24
+ with:
25
+ version: 10
26
+ - uses: actions/setup-node@v4
27
+ with:
28
+ node-version: '20'
29
+ registry-url: 'https://registry.npmjs.org'
30
+ - run: pnpm install --no-frozen-lockfile
31
+ - run: pnpm build
32
+ - name: Semantic Release
33
+ env:
34
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
35
+ NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
36
+ NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
37
+ run: npx semantic-release
@@ -0,0 +1,9 @@
1
+ {
2
+ "branches": ["master"],
3
+ "plugins": [
4
+ "@semantic-release/commit-analyzer",
5
+ "@semantic-release/release-notes-generator",
6
+ "@semantic-release/npm",
7
+ "@semantic-release/github"
8
+ ]
9
+ }
package/LICENSE CHANGED
@@ -1,23 +1,98 @@
1
- MIT License
2
-
3
- Copyright (c) 2025 Framers
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document.
10
+
11
+ "Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License.
12
+
13
+ "Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity.
14
+
15
+ "You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License.
16
+
17
+ "Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files.
18
+
19
+ "Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types.
20
+
21
+ "Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below).
22
+
23
+ "Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof.
24
+
25
+ "Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution."
26
+
27
+ "Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work.
28
+
29
+ 2. Grant of Copyright License.
30
+
31
+ Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form.
32
+
33
+ 3. Grant of Patent License.
34
+
35
+ Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed.
36
+
37
+ 4. Redistribution.
38
+
39
+ You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions:
40
+
41
+ (a) You must give any other recipients of the Work or Derivative Works a copy of this License; and
42
+
43
+ (b) You must cause any modified files to carry prominent notices stating that You changed the files; and
44
+
45
+ (c) You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and
46
+
47
+ (d) If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License.
48
+
49
+ You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License.
50
+
51
+ 5. Submission of Contributions.
52
+
53
+ Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions.
54
+
55
+ 6. Trademarks.
56
+
57
+ This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file.
58
+
59
+ 7. Disclaimer of Warranty.
60
+
61
+ Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License.
62
+
63
+ 8. Limitation of Liability.
64
+
65
+ In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages.
66
+
67
+ 9. Accepting Warranty or Additional Liability.
68
+
69
+ While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability.
70
+
71
+ END OF TERMS AND CONDITIONS
72
+
73
+ APPENDIX: How to apply the Apache License to your work.
74
+
75
+ To apply the Apache License to your work, attach the following
76
+ boilerplate notice, with the fields enclosed by brackets "[]"
77
+ replaced with your own identifying information. (Don't include
78
+ the brackets!) The text should be enclosed in the appropriate
79
+ comment syntax for the file format. We also recommend that a
80
+ file or class name and description of purpose be included on the
81
+ same "printed page" as the copyright notice for easier
82
+ identification within third-party archives.
83
+
84
+ Copyright (c) 2025 Framers
85
+
86
+ Licensed under the Apache License, Version 2.0 (the "License");
87
+ you may not use this file except in compliance with the License.
88
+ You may obtain a copy of the License at
89
+
90
+ http://www.apache.org/licenses/LICENSE-2.0
91
+
92
+ Unless required by applicable law or agreed to in writing, software
93
+ distributed under the License is distributed on an "AS IS" BASIS,
94
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
95
+ See the License for the specific language governing permissions and
96
+ limitations under the License.
22
97
 
23
98
 
package/README.md ADDED
@@ -0,0 +1,72 @@
1
+ # @framers/agentos-ext-ml-classifiers
2
+
3
+ ML-based content classifiers for [`@framers/agentos`](https://github.com/framersai/agentos): toxicity, prompt-injection, and NSFW detection via local ONNX models with optional LLM fallback for low-confidence cases.
4
+
5
+ ## What it does
6
+
7
+ Runs incoming user messages and agent outputs through a chain of small classifiers. Each classifier returns a score; configurable thresholds gate downstream behavior. Local ONNX inference is fast and offline-friendly; the LLM fallback handles ambiguous cases when confidence is low.
8
+
9
+ Built-in classifiers:
10
+
11
+ - Toxicity (insults, threats, harassment)
12
+ - Prompt injection (jailbreak attempts, instruction-override patterns)
13
+ - NSFW content
14
+ - Keyword-based prefilter (zero-cost coarse triage)
15
+ - LLM-as-judge fallback (configurable model)
16
+
17
+ ## Install
18
+
19
+ ```bash
20
+ npm install @framers/agentos-ext-ml-classifiers
21
+ ```
22
+
23
+ Peer dependency: [`@framers/agentos`](https://github.com/framersai/agentos).
24
+
25
+ ## Quickstart
26
+
27
+ ```ts
28
+ import { AgentOS } from '@framers/agentos';
29
+ import { createMLClassifierGuardrail } from '@framers/agentos-ext-ml-classifiers';
30
+
31
+ const agentos = new AgentOS();
32
+ await agentos.initialize({
33
+ extensionManifest: {
34
+ packs: [
35
+ {
36
+ factory: () =>
37
+ createMLClassifierGuardrail({
38
+ classifiers: ['toxicity', 'prompt-injection', 'nsfw'],
39
+ llmFallback: { enabled: true, threshold: 0.6 },
40
+ }),
41
+ enabled: true,
42
+ },
43
+ ],
44
+ },
45
+ });
46
+ ```
47
+
48
+ ## Public API
49
+
50
+ - `createMLClassifierGuardrail(options?)` — factory returning an `ExtensionPack`
51
+ - `createExtensionPack(context)` — auto-discoverable factory used by AgentOS extension auto-pickup
52
+ - `createMLClassifierPack` — alias for `createMLClassifierGuardrail`
53
+
54
+ See [`src/types.ts`](src/types.ts) for `MLClassifierOptions`.
55
+
56
+ ## Examples
57
+
58
+ - `test/` — fixtures and threshold-tuning tests
59
+
60
+ ## Lazy loading and optional install
61
+
62
+ This package is an optional dependency of `@framers/agentos-extensions-registry`. The registry ships catalog metadata; `createCuratedManifest()` calls `import.meta.resolve()` per entry and silently skips anything not installed. `npm install @framers/agentos-ext-ml-classifiers` is the gate.
63
+
64
+ The ONNX BERT classifiers (toxicity, prompt-injection, NSFW) do not load at activation. The pack registers a factory under the `ml:classifier-orchestrator` key in `SharedServiceRegistry`, and each model file enters the module graph only on the first classification that needs it. The keyword prefilter runs first at zero cost; the LLM fallback uses a separate factory gated by an optional `requiredSecrets` entry, so the descriptor is skipped if no provider key is configured.
65
+
66
+ The guardrail registers with `config.evaluateStreamingChunks = true` and runs in Phase 2 of the two-phase dispatcher (parallel classifiers). Worst-action aggregation (`BLOCK > FLAG > ALLOW`) resolves conflicts when multiple classifiers fire on the same chunk.
67
+
68
+ For the full DI model and end-to-end walkthrough, see [How extensions stay optional and lazy](https://docs.agentos.sh/extensions#how-extensions-stay-optional-and-lazy) and the [auto-loading guide](https://docs.agentos.sh/extensions/auto-loading).
69
+
70
+ ## License
71
+
72
+ Apache 2.0 — see the repo root [LICENSE](../../LICENSE).
@@ -1 +1 @@
1
- {"version":3,"file":"MLClassifierGuardrail.d.ts","sourceRoot":"","sources":["../src/MLClassifierGuardrail.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAEH,OAAO,KAAK,EACV,iBAAiB,EACjB,eAAe,EACf,qBAAqB,EACrB,sBAAsB,EACtB,yBAAyB,EAC1B,MAAM,kBAAkB,CAAC;AAG1B,OAAO,KAAK,EACV,mBAAmB,EAEnB,gBAAgB,EAEjB,MAAM,SAAS,CAAC;AASjB;;;;;GAKG;AACH,qBAAa,qBAAsB,YAAW,iBAAiB;IAK7D;;;;;;;;;OASG;IACH,QAAQ,CAAC,MAAM,EAAE,eAAe,CAG9B;IAMF,8BAA8B;IAC9B,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAuB;IAElD,oCAAoC;IACpC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAqC;IAEpE,qCAAqC;IACrC,OA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;IACrC,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAqC;IAErE,+DAA+D;IAC/D,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoC;IAE/D;;;;OAIG;IACH,OAAO,CAAC,YAAY,CAAgE;IAMpF;;;;;OAKG;gBACS,OAAO,CAAC,EAAE,mBAAmB;IAuBzC;;;;;OAKG;IACG,aAAa,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC;IAY9F;;;;;;OAMG;IACG,cAAc,CAAC,OAAO,EAAE,sBAAsB,GAAG,OAAO,CAAC,yBAAyB,GAAG,IAAI,CAAC;IAoBhG;;;;;OAKG;IACG,QAAQ,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAwBvD;;;;;;;;;;;;OAYG;YACW,qBAAqB;IA+CnC;;;;;;;;;;;;OAYG;IACH,OAAO,CAAC,aAAa;IAsCrB;;;;;;;OAOG;YACW,oBAAoB;IAuBlC;;;;;;;;OAQG;IACH,OAAO,CAAC,WAAW;CAsCpB"}
@@ -22,9 +22,9 @@
22
22
  */
23
23
  import { GuardrailAction } from '@framers/agentos';
24
24
  import { AgentOSResponseChunkType } from '@framers/agentos';
25
- import { ALL_CATEGORIES } from './types';
26
- import { classifyByKeywords } from './keyword-classifier';
27
- import { classifyByLlm } from './llm-classifier';
25
+ import { ALL_CATEGORIES } from './types.js';
26
+ import { classifyByKeywords } from './keyword-classifier.js';
27
+ import { classifyByLlm } from './llm-classifier.js';
28
28
  // ---------------------------------------------------------------------------
29
29
  // MLClassifierGuardrail
30
30
  // ---------------------------------------------------------------------------
@@ -124,7 +124,8 @@ export class MLClassifierGuardrail {
124
124
  if (chunk.type !== AgentOSResponseChunkType.FINAL_RESPONSE) {
125
125
  return null;
126
126
  }
127
- const text = chunk.text ?? chunk.content ?? '';
127
+ const finalChunk = chunk;
128
+ const text = finalChunk.finalResponseText ?? '';
128
129
  if (typeof text !== 'string' || text.length === 0)
129
130
  return null;
130
131
  const result = await this.classify(text);
@@ -183,7 +184,14 @@ export class MLClassifierGuardrail {
183
184
  try {
184
185
  // Dynamic import so the optional dependency does not fail at boot.
185
186
  const transformers = await import('@huggingface/transformers');
186
- this.onnxPipeline = await transformers.pipeline('text-classification', 'Xenova/toxic-bert', { device: 'cpu' });
187
+ const pipelineInstance = await transformers.pipeline('text-classification', 'Xenova/toxic-bert', { device: 'cpu' });
188
+ // The HuggingFace pipeline is callable as a function. We always
189
+ // request all labels (top_k higher than any model's label count
190
+ // causes HF to return every label, matching `top_k: null`).
191
+ // Cast through unknown because the Pipeline union type is too
192
+ // wide for the inferred call signature here.
193
+ const callable = pipelineInstance;
194
+ this.onnxPipeline = (text) => callable(text, { top_k: 9999 });
187
195
  }
188
196
  catch {
189
197
  // Module not installed or model load failed — mark as unavailable.
@@ -192,7 +200,7 @@ export class MLClassifierGuardrail {
192
200
  }
193
201
  }
194
202
  try {
195
- const raw = await this.onnxPipeline(text, { topk: null });
203
+ const raw = await this.onnxPipeline(text);
196
204
  // Map ONNX labels to our categories.
197
205
  const scores = this.mapOnnxScores(raw);
198
206
  return {
@@ -1 +1 @@
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,0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,IAAI,CAAC,IAAI,CAAC,EAAE;gBACnH,UAAU,EAAE,iBAAiB,KAAK,CAAC,IAAI,CAAC,WAAW,EAAE,EAAE;gBACvD,QAAQ,EAAE;oBACR,MAAM,EAAE,MAAM,CAAC,MAAM;oBACrB,UAAU,EAAE,MAAM,CAAC,UAAU;iBAC9B;aACF,CAAC;QACJ,CAAC;QAED,kCAAkC;QAClC,OAAO,IAAI,CAAC;IACd,CAAC;CACF"}
package/dist/index.js CHANGED
@@ -9,12 +9,12 @@
9
9
  * @module ml-classifiers
10
10
  */
11
11
  import { EXTENSION_KIND_GUARDRAIL, EXTENSION_KIND_TOOL } from '@framers/agentos';
12
- import { MLClassifierGuardrail } from './MLClassifierGuardrail';
13
- import { ClassifyContentTool } from './tools/ClassifyContentTool';
12
+ import { MLClassifierGuardrail } from './MLClassifierGuardrail.js';
13
+ import { ClassifyContentTool } from './tools/ClassifyContentTool.js';
14
14
  // ---------------------------------------------------------------------------
15
15
  // Re-exports
16
16
  // ---------------------------------------------------------------------------
17
- export * from './types';
17
+ export * from './types.js';
18
18
  // ---------------------------------------------------------------------------
19
19
  // Pack factory
20
20
  // ---------------------------------------------------------------------------
@@ -9,7 +9,7 @@
9
9
  *
10
10
  * @module ml-classifiers/keyword-classifier
11
11
  */
12
- import { ALL_CATEGORIES } from './types';
12
+ import { ALL_CATEGORIES } from './types.js';
13
13
  // ---------------------------------------------------------------------------
14
14
  // Pattern dictionaries
15
15
  // ---------------------------------------------------------------------------
@@ -8,7 +8,7 @@
8
8
  *
9
9
  * @module ml-classifiers/llm-classifier
10
10
  */
11
- import { ALL_CATEGORIES } from './types';
11
+ import { ALL_CATEGORIES } from './types.js';
12
12
  // ---------------------------------------------------------------------------
13
13
  // Prompt template
14
14
  // ---------------------------------------------------------------------------
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@framers/agentos-ext-ml-classifiers",
3
- "version": "0.2.1",
3
+ "version": "0.3.1",
4
4
  "description": "ML-based content classifiers for AgentOS — toxicity, prompt injection, and NSFW detection via ONNX models or LLM fallback",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -12,27 +12,19 @@
12
12
  }
13
13
  },
14
14
  "peerDependencies": {
15
- "@framers/agentos": ">=0.1.0"
15
+ "@framers/agentos": ">=0.7.0"
16
16
  },
17
17
  "optionalDependencies": {
18
18
  "@huggingface/transformers": "^3.0.0"
19
19
  },
20
- "license": "MIT",
21
- "author": "Frame.dev",
22
- "repository": {
23
- "type": "git",
24
- "url": "https://github.com/framersai/agentos-extensions.git",
25
- "directory": "registry/curated/safety/ml-classifiers"
26
- },
27
- "publishConfig": {
28
- "access": "public"
29
- },
20
+ "license": "Apache-2.0",
30
21
  "devDependencies": {
31
22
  "semantic-release": "^24.0.0",
32
23
  "@semantic-release/github": "^11.0.0"
33
24
  },
25
+ "homepage": "https://agentos.sh",
34
26
  "scripts": {
35
- "build": "tsc",
27
+ "build": "tsc && node scripts/fix-esm-imports.mjs",
36
28
  "clean": "rm -rf dist",
37
29
  "typecheck": "tsc --noEmit"
38
30
  }
@@ -0,0 +1,181 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from 'node:fs';
4
+ import path from 'node:path';
5
+ import { fileURLToPath } from 'node:url';
6
+
7
+ const __filename = fileURLToPath(import.meta.url);
8
+ const __dirname = path.dirname(__filename);
9
+ const distDir = path.resolve(__dirname, '..', 'dist');
10
+ const SELF_PACKAGE_NAME = '@framers/agentos-ext-ml-classifiers';
11
+
12
+ function collectJsFiles(dirPath) {
13
+ const entries = fs.readdirSync(dirPath, { withFileTypes: true });
14
+ const files = [];
15
+ for (const entry of entries) {
16
+ const fullPath = path.join(dirPath, entry.name);
17
+ if (entry.isDirectory()) {
18
+ files.push(...collectJsFiles(fullPath));
19
+ } else if (entry.isFile() && fullPath.endsWith('.js')) {
20
+ files.push(fullPath);
21
+ }
22
+ }
23
+ return files;
24
+ }
25
+
26
+ function resolveSpecifier(filePath, specifier) {
27
+ if (specifier === SELF_PACKAGE_NAME || specifier.startsWith(`${SELF_PACKAGE_NAME}/`)) {
28
+ const relativeExportPath =
29
+ specifier === SELF_PACKAGE_NAME ? 'index' : specifier.slice(SELF_PACKAGE_NAME.length + 1);
30
+ const targetCandidates = [
31
+ path.resolve(distDir, `${relativeExportPath}.js`),
32
+ path.resolve(distDir, relativeExportPath, 'index.js'),
33
+ ];
34
+ const targetPath = targetCandidates.find((candidate) => fs.existsSync(candidate));
35
+ if (!targetPath) {
36
+ return specifier;
37
+ }
38
+
39
+ let relativePath = path.relative(path.dirname(filePath), targetPath).replace(/\\/g, '/');
40
+ if (!relativePath.startsWith('.')) {
41
+ relativePath = `./${relativePath}`;
42
+ }
43
+ return relativePath;
44
+ }
45
+
46
+ if (!specifier.startsWith('.')) {
47
+ return specifier;
48
+ }
49
+
50
+ const hasKnownExtension = /\.(?:[cm]?js|json|node)$/i.test(specifier);
51
+ if (hasKnownExtension) {
52
+ return specifier;
53
+ }
54
+
55
+ const baseDir = path.dirname(filePath);
56
+ const asJs = path.resolve(baseDir, `${specifier}.js`);
57
+ if (fs.existsSync(asJs)) {
58
+ return `${specifier}.js`;
59
+ }
60
+
61
+ const asIndex = path.resolve(baseDir, specifier, 'index.js');
62
+ if (fs.existsSync(asIndex)) {
63
+ return `${specifier}/index.js`;
64
+ }
65
+
66
+ return specifier;
67
+ }
68
+
69
+ function rewriteSpecifiers(filePath) {
70
+ const original = fs.readFileSync(filePath, 'utf8');
71
+ let modified = original;
72
+ let changed = false;
73
+
74
+ const patterns = [
75
+ // Multi-line aware: `[\s\S]*?` matches anything including newlines, non-greedy, so
76
+ // imports with destructuring across multiple lines (e.g. `import { A,\n B\n} from './X'`)
77
+ // are caught. Anchored to start-of-line by `^` + `m` flag and terminated by the `from`
78
+ // keyword before a quote.
79
+ /(^\s*(?:import|export)\s[\s\S]*?from\s+['"])([^'"]+)(['"])/gm,
80
+ /(import\(\s*['"])([^'"]+)(['"]\s*\))/g
81
+ ];
82
+
83
+ for (const pattern of patterns) {
84
+ modified = modified.replace(pattern, (match, prefix, specifier, suffix) => {
85
+ const rewritten = resolveSpecifier(filePath, specifier);
86
+ if (rewritten !== specifier) {
87
+ changed = true;
88
+ return `${prefix}${rewritten}${suffix}`;
89
+ }
90
+ return match;
91
+ });
92
+ }
93
+
94
+ if (changed) {
95
+ fs.writeFileSync(filePath, modified, 'utf8');
96
+ }
97
+ }
98
+
99
+ function copyIfPresent(sourcePath, targetPath) {
100
+ if (!fs.existsSync(sourcePath)) {
101
+ return false;
102
+ }
103
+
104
+ fs.mkdirSync(path.dirname(targetPath), { recursive: true });
105
+ fs.copyFileSync(sourcePath, targetPath);
106
+ return true;
107
+ }
108
+
109
+ /**
110
+ * Walk the dist tree after rewriting and verify every static/dynamic relative
111
+ * import has a resolvable extension. Catches the case where a previous build
112
+ * left partial dist state (e.g. rimraf failed because another process held
113
+ * files open) and the rewriter's regex didn't reach a stale file.
114
+ *
115
+ * Returns an array of {file, specifier, line} for each unfixed import.
116
+ */
117
+ export function findUnfixedRelativeImports(distDir) {
118
+ const issues = [];
119
+ const jsFiles = collectJsFiles(distDir);
120
+ const patterns = [
121
+ /(^\s*(?:import|export)\s[\s\S]*?from\s+['"])([^'"]+)(['"])/gm,
122
+ /(import\(\s*['"])([^'"]+)(['"]\s*\))/g,
123
+ ];
124
+ for (const file of jsFiles) {
125
+ const contents = fs.readFileSync(file, 'utf8');
126
+ for (const pattern of patterns) {
127
+ pattern.lastIndex = 0;
128
+ let m;
129
+ while ((m = pattern.exec(contents)) !== null) {
130
+ const specifier = m[2];
131
+ if (!specifier.startsWith('.')) continue;
132
+ if (/\.(?:[cm]?js|json|node)$/i.test(specifier)) continue;
133
+ // Look up the file's line number for a useful error message.
134
+ const lineNumber = contents.slice(0, m.index).split('\n').length;
135
+ issues.push({ file, specifier, line: lineNumber });
136
+ }
137
+ }
138
+ }
139
+ return issues;
140
+ }
141
+
142
+ // Only run the main pipeline when invoked directly, not when this module is
143
+ // imported from a test or another script.
144
+ if (process.argv[1] && fileURLToPath(import.meta.url) === path.resolve(process.argv[1])) {
145
+ if (!fs.existsSync(distDir)) {
146
+ console.log('[agentos fix-esm-imports] dist directory missing; nothing to do.');
147
+ process.exit(0);
148
+ }
149
+
150
+ const jsFiles = collectJsFiles(distDir);
151
+ for (const file of jsFiles) {
152
+ rewriteSpecifiers(file);
153
+ }
154
+
155
+ const copiedExtensionSecrets = copyIfPresent(
156
+ path.resolve(distDir, 'core', 'config', 'extension-secrets.json'),
157
+ path.resolve(distDir, 'config', 'extension-secrets.json'),
158
+ );
159
+
160
+ console.log(`[agentos fix-esm-imports] Processed ${jsFiles.length} files under ${distDir}.`);
161
+ if (copiedExtensionSecrets) {
162
+ console.log('[agentos fix-esm-imports] Mirrored extension-secrets.json into dist/config for public package exports.');
163
+ }
164
+
165
+ const unfixed = findUnfixedRelativeImports(distDir);
166
+ if (unfixed.length > 0) {
167
+ console.error(
168
+ `[agentos fix-esm-imports] FAIL: ${unfixed.length} relative import${unfixed.length === 1 ? '' : 's'} ` +
169
+ `in dist still missing a file extension. This usually means a previous build ` +
170
+ `left partial state — try \`rm -rf dist && pnpm build\`.`,
171
+ );
172
+ for (const issue of unfixed.slice(0, 20)) {
173
+ const rel = path.relative(distDir, issue.file);
174
+ console.error(` ${rel}:${issue.line} -> ${issue.specifier}`);
175
+ }
176
+ if (unfixed.length > 20) {
177
+ console.error(` …and ${unfixed.length - 20} more.`);
178
+ }
179
+ process.exit(1);
180
+ }
181
+ }